1
0
mirror of https://github.com/danog/termux-api.git synced 2024-11-26 20:04:42 +01:00

Minor formatting changes only

This commit is contained in:
Fredrik Fornwall 2015-09-04 14:40:00 +02:00
parent 749e68b6f2
commit 20252cf9a7

View File

@ -57,15 +57,23 @@ public class PhotoAPI {
out.println("No such camera: " + cameraId); out.println("No such camera: " + cameraId);
return; return;
} }
StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
// For still image captures, we use the largest available size. // Use largest available size:
Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)), Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)), new Comparator<Size>() {
new CompareSizesByArea()); @Override
final ImageReader mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), public int compare(Size lhs, Size rhs) {
ImageFormat.JPEG, 2); // Cast to ensure multiplications won't overflow:
return Long.signum((long) lhs.getWidth() * lhs.getHeight() - (long) rhs.getWidth() * rhs.getHeight());
}
});
final ImageReader mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG, 2);
Looper.prepare(); Looper.prepare();
final Looper looper = Looper.myLooper(); final Looper looper = Looper.myLooper();
mImageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() { mImageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
@Override @Override
public void onImageAvailable(final ImageReader reader) { public void onImageAvailable(final ImageReader reader) {
@ -94,15 +102,12 @@ public class PhotoAPI {
@Override @Override
public void onOpened(final CameraDevice camera) { public void onOpened(final CameraDevice camera) {
try { try {
final CaptureRequest.Builder captureBuilder = camera final CaptureRequest.Builder captureBuilder = camera.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
captureBuilder.addTarget(mImageReader.getSurface()); captureBuilder.addTarget(mImageReader.getSurface());
// Use the same AE and AF modes as the preview. // Configure auto-focus (AF) and auto-exposure (AE) modes:
captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CameraMetadata.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
CameraMetadata.CONTROL_AF_MODE_CONTINUOUS_PICTURE); captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON_AUTO_FLASH);
captureBuilder
.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON_AUTO_FLASH);
// Orientation jpeg fix, from the Camera2BasicFragment example: // Orientation jpeg fix, from the Camera2BasicFragment example:
int cameraJpegOrientation; int cameraJpegOrientation;
@ -125,8 +130,7 @@ public class PhotoAPI {
} }
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, cameraJpegOrientation); captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, cameraJpegOrientation);
List<Surface> outputSurfaces = Collections.singletonList(mImageReader.getSurface()); camera.createCaptureSession(Collections.singletonList(mImageReader.getSurface()), new CameraCaptureSession.StateCallback() {
camera.createCaptureSession(outputSurfaces, new CameraCaptureSession.StateCallback() {
@Override @Override
public void onConfigured(CameraCaptureSession session) { public void onConfigured(CameraCaptureSession session) {
try { try {
@ -170,18 +174,11 @@ public class PhotoAPI {
} }
}, null); }, null);
Looper.loop(); Looper.loop();
} catch (Exception e) { } catch (Exception e) {
TermuxApiLogger.error("Error getting camera", e); TermuxApiLogger.error("Error getting camera", e);
} }
} }
static class CompareSizesByArea implements Comparator<Size> {
@Override
public int compare(Size lhs, Size rhs) {
// We cast here to ensure the multiplications won't overflow
return Long.signum((long) lhs.getWidth() * lhs.getHeight() - (long) rhs.getWidth() * rhs.getHeight());
}
}
} }