diff options
author | Weijie Wang <weijiew@codeaurora.org> | 2017-07-12 19:56:25 +0800 |
---|---|---|
committer | Weijie Wang <weijiew@codeaurora.org> | 2017-09-04 18:25:58 +0800 |
commit | 454d5b45b6b08e9213dc590fa0ebd084b50408fe (patch) | |
tree | 9305ca35cf4b783c9f67b10ef55c0dec5cb6412c /src | |
parent | 278267a43e560e7146ae842e393329501ab7dc9b (diff) | |
download | android_packages_apps_Snap-454d5b45b6b08e9213dc590fa0ebd084b50408fe.tar.gz android_packages_apps_Snap-454d5b45b6b08e9213dc590fa0ebd084b50408fe.tar.bz2 android_packages_apps_Snap-454d5b45b6b08e9213dc590fa0ebd084b50408fe.zip |
SnapdragonCamera: refactor captureStillPicture
1. Split captureStillPicture into multiple smaller methods
2. Add some logs
3. Delete hack code
Change-Id: I0ebc9625be880539f7c0c1d68350c093616205ad
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/camera/CaptureModule.java | 505 | ||||
-rw-r--r--[-rwxr-xr-x] | src/com/android/camera/CaptureUI.java | 24 | ||||
-rw-r--r-- | src/com/android/camera/imageprocessor/PostProcessor.java | 15 |
3 files changed, 215 insertions, 329 deletions
diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java index dee81d566..5b029df86 100644 --- a/src/com/android/camera/CaptureModule.java +++ b/src/com/android/camera/CaptureModule.java @@ -89,7 +89,6 @@ import android.graphics.Canvas; import android.graphics.Color; import android.util.AttributeSet; import android.graphics.Bitmap; -import android.graphics.YuvImage; import com.android.camera.exif.ExifInterface; import com.android.camera.imageprocessor.filter.BlurbusterFilter; @@ -1028,7 +1027,6 @@ public class CaptureModule implements CameraModule, PhotoController, if(id == getMainCameraId()) { mCurrentSession = cameraCaptureSession; } - initializePreviewConfiguration(id); setDisplayOrientation(); updateFaceDetection(); @@ -1047,17 +1045,18 @@ public class CaptureModule implements CameraModule, PhotoController, mCaptureSession[id].setRepeatingRequest(mPreviewRequestBuilder[id] .build(), mCaptureCallback, mCameraHandler); } + if (isClearSightOn()) { ClearSightImageProcessor.getInstance().onCaptureSessionConfigured(id == BAYER_ID, cameraCaptureSession); } else if (mChosenImageFormat == ImageFormat.PRIVATE && id == getMainCameraId()) { mPostProcessor.onSessionConfigured(mCameraDevice[id], mCaptureSession[id]); } + } catch (CameraAccessException e) { e.printStackTrace(); } catch(IllegalStateException e) { e.printStackTrace(); } - } @Override @@ -1271,12 +1270,11 @@ public class CaptureModule implements CameraModule, PhotoController, mJpegImageData = data; } - public void showCapturedReview(final byte[] jpegData, final int orientation, - final boolean mirror) { + public void showCapturedReview(final byte[] jpegData, final int orientation) { mActivity.runOnUiThread(new Runnable() { @Override public void run() { - mUI.showCapturedImageForReview(jpegData, orientation, mirror); + mUI.showCapturedImageForReview(jpegData, orientation); } }); } @@ -1309,11 +1307,7 @@ public class CaptureModule implements CameraModule, PhotoController, if (takeZSLPicture(BAYER_ID)) { return; } -/* take picture directly for now*/ - captureStillPicture(BAYER_ID); - mState[BAYER_ID] = STATE_PICTURE_TAKEN; - -//todo lockFocus(BAYER_ID); + lockFocus(BAYER_ID); break; case MONO_MODE: lockFocus(MONO_ID); @@ -1323,11 +1317,7 @@ public class CaptureModule implements CameraModule, PhotoController, if (takeZSLPicture(FRONT_ID)) { return; } -/* take picture directly for now*/ - captureStillPicture(FRONT_ID); - mState[FRONT_ID] = STATE_PICTURE_TAKEN; - -//todo lockFocus(FRONT_ID); + lockFocus(FRONT_ID); } } } @@ -1480,173 +1470,175 @@ public class CaptureModule implements CameraModule, PhotoController, Log.d(TAG, "captureStillPicture " + id); mJpegImageData = null; mIsRefocus = false; - CameraCaptureSession.CaptureCallback captureCallback = new CameraCaptureSession.CaptureCallback() { - - @Override - public void onCaptureCompleted(CameraCaptureSession session, - CaptureRequest request, - TotalCaptureResult result) { - Log.d(TAG, "captureStillPicture onCaptureCompleted: " + id); - } - - @Override - public void onCaptureFailed(CameraCaptureSession session, - CaptureRequest request, - CaptureFailure result) { - Log.d(TAG, "captureStillPicture onCaptureFailed: " + id); - } - - @Override - public void onCaptureSequenceCompleted(CameraCaptureSession session, int - sequenceId, long frameNumber) { - Log.d(TAG, "captureStillPicture onCaptureSequenceCompleted: " + id); - unlockFocus(id); - } - }; try { if (null == mActivity || null == mCameraDevice[id]) { warningToast("Camera is not ready yet to take a picture."); return; } - final boolean csEnabled = isClearSightOn(); - CaptureRequest.Builder captureBuilder; + CaptureRequest.Builder captureBuilder = + mCameraDevice[id].createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE); - if(csEnabled) { - captureBuilder = ClearSightImageProcessor.getInstance().createCaptureRequest(mCameraDevice[id]); - } else { - captureBuilder = mCameraDevice[id].createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE); - } if(mSettingsManager.isZSLInHALEnabled()) { - Log.d(TAG, "CONTROL_ENABLE_ZSL is enabled."); captureBuilder.set(CaptureRequest.CONTROL_ENABLE_ZSL, true); - } else { - Log.d(TAG, "CONTROL_ENABLE_ZSL is disabled."); + }else{ captureBuilder.set(CaptureRequest.CONTROL_ENABLE_ZSL, false); } -/*todo Location location = mLocationManager.getCurrentLocation(); - if(location != null) { - // make copy so that we don't alter the saved location since we may re-use it - location = new Location(location); - // workaround for Google bug. Need to convert timestamp from ms -> sec - location.setTime(location.getTime()/1000); - captureBuilder.set(CaptureRequest.JPEG_GPS_LOCATION, location); - Log.d(TAG, "captureStillPicture gps: " + location.toString()); - } else { - Log.d(TAG, "captureStillPicture no location - getRecordLocation: " + getRecordLocation()); - } - captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, CameraUtil.getJpegRotation(id, mOrientation)); - captureBuilder.set(CaptureRequest.JPEG_THUMBNAIL_SIZE, mPictureThumbSize); - captureBuilder.set(CaptureRequest.JPEG_THUMBNAIL_QUALITY, (byte)80); -*/ - captureBuilder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO); + applySettingsForJpegInformation(captureBuilder, id); addPreviewSurface(captureBuilder, null, id); - captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, mControlAFMode); - captureBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_IDLE); - VendorTagUtil.setCdsMode(captureBuilder, 2); // CDS 0-OFF, 1-ON, 2-AUTO + VendorTagUtil.setCdsMode(captureBuilder, 2);// CDS 0-OFF, 1-ON, 2-AUTO applySettingsForCapture(captureBuilder, id); - if(csEnabled) { - applySettingsForLockExposure(captureBuilder, id); - checkAndPlayShutterSound(id); - ClearSightImageProcessor.getInstance().capture( - id==BAYER_ID, mCaptureSession[id], captureBuilder, mCaptureCallbackHandler); + if(isClearSightOn()) { + captureStillPictureForClearSight(id); } else if(id == getMainCameraId() && mPostProcessor.isFilterOn()) { // Case of post filtering - applySettingsForLockExposure(captureBuilder, id); - checkAndPlayShutterSound(id); - mCaptureSession[id].stopRepeating(); - captureBuilder.addTarget(mImageReader[id].getSurface()); - if (mSaveRaw) { - captureBuilder.addTarget(mRawImageReader[id].getSurface()); - } - mPostProcessor.onStartCapturing(); - if(mPostProcessor.isManualMode()) { - mPostProcessor.manualCapture(captureBuilder, mCaptureSession[id], mCaptureCallbackHandler); - } else { - List<CaptureRequest> captureList = mPostProcessor.setRequiredImages(captureBuilder); - mCaptureSession[id].captureBurst(captureList, mPostProcessor.getCaptureCallback(), mCaptureCallbackHandler); - } + captureStillPictureForFilter(captureBuilder, id); } else { captureBuilder.addTarget(mImageReader[id].getSurface()); if (mSaveRaw) { captureBuilder.addTarget(mRawImageReader[id].getSurface()); } mCaptureSession[id].stopRepeating(); - if (mLongshotActive) { - Log.d(TAG, "captureStillPicture capture longshot " + id); - List<CaptureRequest> burstList = new ArrayList<>(); - for (int i = 0; i < PersistUtil.getLongshotShotLimit(); i++) { - burstList.add(captureBuilder.build()); - } - mCaptureSession[id].captureBurst(burstList, new - CameraCaptureSession.CaptureCallback() { + captureStillPictureForLongshot(captureBuilder, id); + } else { + captureStillPictureForCommon(captureBuilder, id); + } + } + } catch (CameraAccessException e) { + Log.d(TAG, "Capture still picture has failed"); + e.printStackTrace(); + } + } - @Override - public void onCaptureCompleted(CameraCaptureSession session, - CaptureRequest request, - TotalCaptureResult result) { - Log.d(TAG, "captureStillPicture Longshot onCaptureCompleted: " + id); - if (mLongshotActive) { - checkAndPlayShutterSound(id); - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - mUI.doShutterAnimation(); - } - }); - } - } + private void captureStillPictureForClearSight(int id) throws CameraAccessException{ + CaptureRequest.Builder captureBuilder = + ClearSightImageProcessor.getInstance().createCaptureRequest(mCameraDevice[id]); + if(mSettingsManager.isZSLInHALEnabled()) { + captureBuilder.set(CaptureRequest.CONTROL_ENABLE_ZSL, true); + }else{ + captureBuilder.set(CaptureRequest.CONTROL_ENABLE_ZSL, false); + } + + applySettingsForJpegInformation(captureBuilder, id); + addPreviewSurface(captureBuilder, null, id); + VendorTagUtil.setCdsMode(captureBuilder, 2); // CDS 0-OFF, 1-ON, 2-AUTO + applySettingsForCapture(captureBuilder, id); + applySettingsForLockExposure(captureBuilder, id); + checkAndPlayShutterSound(id); + ClearSightImageProcessor.getInstance().capture( + id==BAYER_ID, mCaptureSession[id], captureBuilder, mCaptureCallbackHandler); + } + + private void captureStillPictureForFilter(CaptureRequest.Builder captureBuilder, int id) throws CameraAccessException{ + applySettingsForLockExposure(captureBuilder, id); + checkAndPlayShutterSound(id); + mCaptureSession[id].stopRepeating(); + captureBuilder.addTarget(mImageReader[id].getSurface()); + if (mSaveRaw) { + captureBuilder.addTarget(mRawImageReader[id].getSurface()); + } + mPostProcessor.onStartCapturing(); + if(mPostProcessor.isManualMode()) { + mPostProcessor.manualCapture(captureBuilder, mCaptureSession[id], mCaptureCallbackHandler); + } else { + List<CaptureRequest> captureList = mPostProcessor.setRequiredImages(captureBuilder); + mCaptureSession[id].captureBurst(captureList, mPostProcessor.getCaptureCallback(), mCaptureCallbackHandler); + } + } + + private void captureStillPictureForLongshot(CaptureRequest.Builder captureBuilder, int id) throws CameraAccessException{ + Log.d(TAG, "captureStillPictureForLongshot " + id); + List<CaptureRequest> burstList = new ArrayList<>(); + for (int i = 0; i < PersistUtil.getLongshotShotLimit(); i++) { + burstList.add(captureBuilder.build()); + } + mCaptureSession[id].captureBurst(burstList, new + CameraCaptureSession.CaptureCallback() { + + @Override + public void onCaptureCompleted(CameraCaptureSession session, + CaptureRequest request, + TotalCaptureResult result) { + Log.d(TAG, "captureStillPictureForLongshot onCaptureCompleted: " + id); + if (mLongshotActive) { + checkAndPlayShutterSound(id); + mActivity.runOnUiThread(new Runnable() { @Override - public void onCaptureFailed(CameraCaptureSession session, - CaptureRequest request, - CaptureFailure result) { - Log.d(TAG, "captureStillPicture Longshot onCaptureFailed: " + id); - if (mLongshotActive) { - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - mUI.doShutterAnimation(); - } - }); - } + public void run() { + mUI.doShutterAnimation(); } + }); + } + } + @Override + public void onCaptureFailed(CameraCaptureSession session, + CaptureRequest request, + CaptureFailure result) { + Log.d(TAG, "captureStillPictureForLongshot onCaptureFailed: " + id); + if (mLongshotActive) { + mActivity.runOnUiThread(new Runnable() { @Override - public void onCaptureSequenceCompleted(CameraCaptureSession session, int - sequenceId, long frameNumber) { - Log.d(TAG, "captureStillPicture Longshot onCaptureSequenceCompleted: " + id); - mLongshotActive = false; - unlockFocus(id); + public void run() { + mUI.doShutterAnimation(); } - }, mCaptureCallbackHandler); - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - mUI.enableVideo(false); + }); } - }); - - } else { - checkAndPlayShutterSound(id); - if(isMpoOn()) { - mCaptureStartTime = System.currentTimeMillis(); - mMpoSaveHandler.obtainMessage(MpoSaveHandler.MSG_CONFIGURE, - Long.valueOf(mCaptureStartTime)).sendToTarget(); } -/*todo if(mChosenImageFormat == ImageFormat.YUV_420_888 || mChosenImageFormat == ImageFormat.PRIVATE) { // Case of ZSL, FrameFilter, SelfieMirror - mPostProcessor.onStartCapturing(); - mCaptureSession[id].capture(captureBuilder.build(), mPostProcessor.getCaptureCallback(), mCaptureCallbackHandler); - } else*/ { - mCaptureSession[id].capture(captureBuilder.build(), captureCallback, mCaptureCallbackHandler); + + @Override + public void onCaptureSequenceCompleted(CameraCaptureSession session, int + sequenceId, long frameNumber) { + Log.d(TAG, "captureStillPictureForLongshot onCaptureSequenceCompleted: " + id); + mLongshotActive = false; + unlockFocus(id); } - } + }, mCaptureCallbackHandler); + mActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + mUI.enableVideo(false); } - } catch (CameraAccessException e) { - Log.d(TAG, "Capture still picture has failed"); - e.printStackTrace(); + }); + } + + private void captureStillPictureForCommon(CaptureRequest.Builder captureBuilder, int id) throws CameraAccessException{ + checkAndPlayShutterSound(id); + if(isMpoOn()) { + mCaptureStartTime = System.currentTimeMillis(); + mMpoSaveHandler.obtainMessage(MpoSaveHandler.MSG_CONFIGURE, + Long.valueOf(mCaptureStartTime)).sendToTarget(); + } + if(mChosenImageFormat == ImageFormat.YUV_420_888 || mChosenImageFormat == ImageFormat.PRIVATE) { // Case of ZSL, FrameFilter, SelfieMirror + mPostProcessor.onStartCapturing(); + mCaptureSession[id].capture(captureBuilder.build(), mPostProcessor.getCaptureCallback(), mCaptureCallbackHandler); + } else { + mCaptureSession[id].capture(captureBuilder.build(), new CameraCaptureSession.CaptureCallback() { + + @Override + public void onCaptureCompleted(CameraCaptureSession session, + CaptureRequest request, + TotalCaptureResult result) { + Log.d(TAG, "captureStillPictureForCommon onCaptureCompleted: " + id); + } + + @Override + public void onCaptureFailed(CameraCaptureSession session, + CaptureRequest request, + CaptureFailure result) { + Log.d(TAG, "captureStillPictureForCommon onCaptureFailed: " + id); + } + + @Override + public void onCaptureSequenceCompleted(CameraCaptureSession session, int + sequenceId, long frameNumber) { + Log.d(TAG, "captureStillPictureForCommon onCaptureSequenceCompleted: " + id); + unlockFocus(id); + } + }, mCaptureCallbackHandler); } } @@ -1661,12 +1653,12 @@ public class CaptureModule implements CameraModule, PhotoController, CaptureRequest.Builder captureBuilder = mCameraDevice[id].createCaptureRequest(CameraDevice.TEMPLATE_VIDEO_SNAPSHOT); - /* todo captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, CameraUtil.getJpegRotation(id, mOrientation)); + captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, CameraUtil.getJpegRotation(id, mOrientation)); captureBuilder.set(CaptureRequest.JPEG_THUMBNAIL_SIZE, mVideoSnapshotThumbSize); captureBuilder.set(CaptureRequest.JPEG_THUMBNAIL_QUALITY, (byte)80); applyVideoSnapshot(captureBuilder, id); applyZoom(captureBuilder, id); - */ + captureBuilder.addTarget(mVideoSnapshotImageReader.getSurface()); mCurrentSession.capture(captureBuilder.build(), @@ -1764,8 +1756,7 @@ public class CaptureModule implements CameraModule, PhotoController, ClearSightImageProcessor.getInstance().setCallback(this); } } else { -//todo if ((imageFormat == ImageFormat.YUV_420_888 || imageFormat == ImageFormat.PRIVATE) - if ((imageFormat == ImageFormat.PRIVATE) + if ((imageFormat == ImageFormat.YUV_420_888 || imageFormat == ImageFormat.PRIVATE) && i == getMainCameraId()) { if(mPostProcessor.isZSLEnabled()) { mImageReader[i] = ImageReader.newInstance(mSupportedMaxPictureSize.getWidth(), @@ -1801,38 +1792,19 @@ public class CaptureModule implements CameraModule, PhotoController, String title = (name == null) ? null : name.title; long date = (name == null) ? -1 : name.date; + byte[] bytes = getJpegData(image); + if (image.getFormat() == ImageFormat.RAW10) { - byte[] bytes = getJpegData(image); mActivity.getMediaSaveService().addRawImage(bytes, title, "raw"); - } else if (image.getFormat() == ImageFormat.YUV_420_888) { - Log.d(TAG, "Bring up picture of YUV is taken and ready to process"); - int width = image.getWidth(); - int height = image.getHeight(); - int stride = image.getPlanes()[0].getRowStride(); - ByteBuffer yuvBuf = ByteBuffer.allocateDirect(stride * height*3/2); - - ByteBuffer yBuf = image.getPlanes()[0].getBuffer(); - ByteBuffer vuBuf = image.getPlanes()[2].getBuffer(); - yBuf.get(yuvBuf.array(), 0, yBuf.remaining()); - vuBuf.get(yuvBuf.array(), stride*height, vuBuf.remaining()); - byte[] bytes = nv21ToJpeg(yuvBuf, width, height, stride); - mActivity.getMediaSaveService().addImage(bytes, title, date, - null, width, height, 90, null, - mOnMediaSavedListener, mContentResolver, "jpeg"); - mActivity.updateThumbnail(bytes); - image.close(); } else { - byte[] bytes = getJpegData(image); - ExifInterface exif = Exif.getExif(bytes); int orientation = Exif.getOrientation(exif); if (mIntentMode != CaptureModule.INTENT_MODE_NORMAL) { mJpegImageData = bytes; if (!mQuickCapture) { - showCapturedReview(bytes, orientation, - mPostProcessor.isSelfieMirrorOn()); + showCapturedReview(bytes, orientation); } else { onCaptureDone(); } @@ -1870,30 +1842,16 @@ public class CaptureModule implements CameraModule, PhotoController, } } - private byte[] nv21ToJpeg(ByteBuffer byteBuffer, int width, int height, int stride) { - PostProcessor.BitmapOutputStream bos = new PostProcessor.BitmapOutputStream(1024); - YuvImage im = new YuvImage(byteBuffer.array(), ImageFormat.NV21, - width, height, new int[]{stride, stride}); - im.compressToJpeg(new Rect(0,0, width, height), 50, bos); - byte[] bytes = bos.getArray(); - return bytes; - } - private void createVideoSnapshotImageReader() { if (mVideoSnapshotImageReader != null) { mVideoSnapshotImageReader.close(); } -/*Todo mVideoSnapshotImageReader = ImageReader.newInstance(mVideoSnapshotSize.getWidth(), - mVideoSnapshotSize.getHeight(), ImageFormat.JPEG, 2);*/ - - mVideoSnapshotImageReader = ImageReader.newInstance(3840, 2160, mChosenImageFormat, 2); - Log.e(TAG, "Image="+mChosenImageFormat); + mVideoSnapshotImageReader = ImageReader.newInstance(mVideoSnapshotSize.getWidth(), + mVideoSnapshotSize.getHeight(), ImageFormat.JPEG, 2); mVideoSnapshotImageReader.setOnImageAvailableListener( new ImageReader.OnImageAvailableListener() { @Override public void onImageAvailable(ImageReader reader) { - Log.d(TAG, "Video Snapshot Image Available."); - Image image = reader.acquireNextImage(); mCaptureStartTime = System.currentTimeMillis(); mNamedImages.nameNewImage(mCaptureStartTime); @@ -1901,39 +1859,19 @@ public class CaptureModule implements CameraModule, PhotoController, String title = (name == null) ? null : name.title; long date = (name == null) ? -1 : name.date; - if (image.getFormat() == ImageFormat.YUV_420_888) { - Log.d(TAG, "Bring up picture of YUV is taken and ready to process"); - int width = image.getWidth(); - int height = image.getHeight(); - int stride = image.getPlanes()[0].getRowStride(); - ByteBuffer yuvBuf = ByteBuffer.allocateDirect(stride * height*3/2); - - ByteBuffer yBuf = image.getPlanes()[0].getBuffer(); - ByteBuffer vuBuf = image.getPlanes()[2].getBuffer(); - yBuf.get(yuvBuf.array(), 0, yBuf.remaining()); - vuBuf.get(yuvBuf.array(), stride*height, vuBuf.remaining()); - byte[] bytes = nv21ToJpeg(yuvBuf, width, height, stride); - mActivity.getMediaSaveService().addImage(bytes, title, date, - null, width, height, 90, null, - mOnMediaSavedListener, mContentResolver, "jpeg"); - mActivity.updateThumbnail(bytes); - image.close(); - } else { - - ByteBuffer buffer = image.getPlanes()[0].getBuffer(); - byte[] bytes = new byte[buffer.remaining()]; - buffer.get(bytes); + ByteBuffer buffer = image.getPlanes()[0].getBuffer(); + byte[] bytes = new byte[buffer.remaining()]; + buffer.get(bytes); - ExifInterface exif = Exif.getExif(bytes); - int orientation = Exif.getOrientation(exif); + ExifInterface exif = Exif.getExif(bytes); + int orientation = Exif.getOrientation(exif); - mActivity.getMediaSaveService().addImage(bytes, title, date, + mActivity.getMediaSaveService().addImage(bytes, title, date, null, image.getWidth(), image.getHeight(), orientation, null, mOnMediaSavedListener, mContentResolver, "jpeg"); - mActivity.updateThumbnail(bytes); - image.close(); - } + mActivity.updateThumbnail(bytes); + image.close(); } }, mImageAvailableHandler); } @@ -2151,6 +2089,23 @@ public class CaptureModule implements CameraModule, PhotoController, applyCommonSettings(builder, id); } + private void applySettingsForJpegInformation(CaptureRequest.Builder builder, int id) { + Location location = mLocationManager.getCurrentLocation(); + if(location != null) { + // make copy so that we don't alter the saved location since we may re-use it + location = new Location(location); + // workaround for Google bug. Need to convert timestamp from ms -> sec + location.setTime(location.getTime()/1000); + builder.set(CaptureRequest.JPEG_GPS_LOCATION, location); + Log.d(TAG, "gps: " + location.toString()); + } else { + Log.d(TAG, "no location - getRecordLocation: " + getRecordLocation()); + } + builder.set(CaptureRequest.JPEG_ORIENTATION, CameraUtil.getJpegRotation(id, mOrientation)); + builder.set(CaptureRequest.JPEG_THUMBNAIL_SIZE, mPictureThumbSize); + builder.set(CaptureRequest.JPEG_THUMBNAIL_QUALITY, (byte)80); + } + private void applyVideoSnapshot(CaptureRequest.Builder builder, int id) { builder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO); applyColorEffect(builder); @@ -2447,7 +2402,7 @@ public class CaptureModule implements CameraModule, PhotoController, } else if(mPostProcessor.isFilterOn() || getFrameFilters().size() != 0 || mPostProcessor.isSelfieMirrorOn()) { mChosenImageFormat = ImageFormat.YUV_420_888; } else { - mChosenImageFormat = ImageFormat.YUV_420_888; //todo ImageFormat.JPEG; + mChosenImageFormat = ImageFormat.JPEG; } setUpCameraOutputs(mChosenImageFormat); @@ -3087,11 +3042,9 @@ public class CaptureModule implements CameraModule, PhotoController, Size[] prevSizes = mSettingsManager.getSupportedOutputSize(getMainCameraId(), SurfaceHolder.class); mSupportedMaxPictureSize = prevSizes[0]; - if (mSaveRaw == true) { - Size[] rawSize = mSettingsManager.getSupportedOutputSize(getMainCameraId(), + Size[] rawSize = mSettingsManager.getSupportedOutputSize(getMainCameraId(), ImageFormat.RAW10); - mSupportedRawPictureSize = rawSize[0]; - } + mSupportedRawPictureSize = rawSize[0]; mPreviewSize = getOptimalPreviewSize(mPictureSize, prevSizes); Size[] thumbSizes = mSettingsManager.getSupportedThumbnailSizes(getMainCameraId()); mPictureThumbSize = getOptimalPreviewSize(mPictureSize, thumbSizes); // get largest thumb size @@ -3133,12 +3086,9 @@ public class CaptureModule implements CameraModule, PhotoController, } private void updateVideoSnapshotSize() { - updateHFRSetting(); - mVideoSnapshotSize = mPictureSize; - mVideoSnapshotSize = getMaxPictureSizeForLiveShot(); - // if video High FrameRate > 60fps, the mVideoSnapshotSize = mVideoSize - if (mHighSpeedCapture && ((int)mHighSpeedFPSRange.getUpper() > NORMAL_SESSION_MAX_FPS)) { - mVideoSnapshotSize = mVideoSize; + mVideoSnapshotSize = mVideoSize; + if (is4kSize(mVideoSize) && is4kSize(mVideoSnapshotSize)) { + mVideoSnapshotSize = getMaxPictureSizeLessThan4k(); } Size[] thumbSizes = mSettingsManager.getSupportedThumbnailSizes(getMainCameraId()); mVideoSnapshotThumbSize = getOptimalPreviewSize(mVideoSnapshotSize, thumbSizes); // get largest thumb size @@ -3178,7 +3128,6 @@ public class CaptureModule implements CameraModule, PhotoController, mStartRecPending = true; mIsRecordingVideo = true; mMediaRecorderPausing = false; - mUI.hideUIwhileRecording(); mActivity.updateStorageSpaceAndHint(); if (mActivity.getStorageSpaceBytes() <= Storage.LOW_STORAGE_THRESHOLD_BYTES) { @@ -3190,6 +3139,17 @@ public class CaptureModule implements CameraModule, PhotoController, try { setUpMediaRecorder(cameraId); + try { + mMediaRecorder.start(); // Recording is now started + } catch (RuntimeException e) { + Toast.makeText(mActivity,"Could not start media recorder.\n " + + "Can't start video recording.", Toast.LENGTH_LONG).show(); + releaseMediaRecorder(); + releaseAudioFocus(); + mStartRecPending = false; + mIsRecordingVideo = false; + return false; + } if (mUnsupportedResolution == true ) { Log.v(TAG, "Unsupported Resolution according to target"); mStartRecPending = false; @@ -3205,6 +3165,7 @@ public class CaptureModule implements CameraModule, PhotoController, requestAudioFocus(); mUI.clearFocus(); + mUI.hideUIwhileRecording(); mCameraHandler.removeMessages(CANCEL_TOUCH_FOCUS, mCameraId[cameraId]); mState[cameraId] = STATE_PREVIEW; mControlAFMode = CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE; @@ -3272,17 +3233,6 @@ public class CaptureModule implements CameraModule, PhotoController, + e.getMessage()); e.printStackTrace(); } - try { - mMediaRecorder.start(); // Recording is now started - } catch (RuntimeException e) { - Toast.makeText(mActivity,"Could not start media recorder.\n " + - "Can't start video recording.", Toast.LENGTH_LONG).show(); - releaseMediaRecorder(); - releaseAudioFocus(); - mStartRecPending = false; - mIsRecordingVideo = false; - return; - } mUI.clearFocus(); mUI.resetPauseButton(); mRecordingTotalTime = 0L; @@ -3317,17 +3267,6 @@ public class CaptureModule implements CameraModule, PhotoController, } catch (IllegalStateException e) { e.printStackTrace(); } - try { - mMediaRecorder.start(); // Recording is now started - } catch (RuntimeException e) { - Toast.makeText(mActivity,"Could not start media recorder.\n " + - "Can't start video recording.", Toast.LENGTH_LONG).show(); - releaseMediaRecorder(); - releaseAudioFocus(); - mStartRecPending = false; - mIsRecordingVideo = false; - return; - } mUI.clearFocus(); mUI.resetPauseButton(); mRecordingTotalTime = 0L; @@ -3373,9 +3312,6 @@ public class CaptureModule implements CameraModule, PhotoController, mHighSpeedRecordingMode = mode.equals("hsr"); mHighSpeedCaptureRate = Integer.parseInt(value.substring(3)); } - if (mHighSpeedCapture) { - mHighSpeedFPSRange = new Range(mHighSpeedCaptureRate, mHighSpeedCaptureRate); - } } private void setUpVideoCaptureRequestBuilder(CaptureRequest.Builder builder,int cameraId) { @@ -4037,14 +3973,14 @@ public class CaptureModule implements CameraModule, PhotoController, if (value == null || value.equals("0")) return; int intValue = Integer.parseInt(value); - //todo request.set(CaptureModule.INSTANT_AEC_MODE, intValue); + request.set(CaptureModule.INSTANT_AEC_MODE, intValue); } private void applySaturationLevel(CaptureRequest.Builder request) { String value = mSettingsManager.getValue(SettingsManager.KEY_SATURATION_LEVEL); if (value != null) { int intValue = Integer.parseInt(value); - //todo request.set(CaptureModule.SATURATION, intValue); + request.set(CaptureModule.SATURATION, intValue); } } @@ -4349,7 +4285,7 @@ public class CaptureModule implements CameraModule, PhotoController, } } - private Surface getPreviewSurfaceForSession(int id) { + public Surface getPreviewSurfaceForSession(int id) { if (isBackCamera()) { if (getCameraMode() == DUAL_MODE && id == MONO_ID) { return mUI.getMonoDummySurface(); @@ -4647,57 +4583,6 @@ public class CaptureModule implements CameraModule, PhotoController, return (optimalPickIndex == -1) ? null : prevSizes[optimalPickIndex]; } - private Size getMaxPictureSizeForLiveShot() { - Size[] sizes = mSettingsManager.getSupportedOutputSize(getMainCameraId(), ImageFormat.JPEG); - float ratio = (float) mVideoSize.getWidth() / mVideoSize.getHeight(); - Size optimalSize = null; - double minDiff = Double.MAX_VALUE; - for (Size size : sizes) { - // if video quality set 1080p, the mVideoSnapshotSize is biggest is 16M(16:9 and 4:3) - if (mVideoSize.getHeight() == 1080 && mVideoSize.getWidth() == 1920) { - if (size.getHeight() > 3456 || size.getWidth() > 5312) continue; - // if video quality set 4K dci or UHD, the mVideoSnapshotSize is biggest is 12M - } else if ((mVideoSize.getHeight() == 2160 && mVideoSize.getWidth() == 4096) || - (mVideoSize.getHeight() == 2160 && mVideoSize.getWidth() == 3840)){ - if (size.getHeight() > 3000 || size.getWidth() > 4000) continue; - } - - float pictureRatio = (float) size.getWidth() / size.getHeight(); - if (Math.abs(pictureRatio - ratio) > 0.01) continue; - - double heightDiff = Math.abs(size.getHeight() - mPictureSize.getHeight()); - if (heightDiff < minDiff) { - optimalSize = size; - minDiff = Math.abs(size.getHeight() - mPictureSize.getHeight()); - } else if (heightDiff == minDiff) { - // Prefer resolutions smaller-than-display when an equally close - // larger-than-display resolution is available - if (size.getHeight() < mPictureSize.getHeight()) { - optimalSize = size; - minDiff = heightDiff; - } - } - } - - // Cannot find one that matches the aspect ratio. This should not happen. - // Ignore the requirement. - if (optimalSize == null) { - Log.w(TAG, "No picture size match the aspect ratio"); - for (Size size : sizes) { - if (mVideoSize.getHeight() == 1080 && mVideoSize.getWidth() == 1920) { - if (size.getHeight() >= 3456 || size.getWidth() >= 4608) continue; - } else if ((mVideoSize.getHeight() == 2160 && mVideoSize.getWidth() == 4096) || - (mVideoSize.getHeight() == 2160 && mVideoSize.getWidth() == 3840)) { - if (size.getHeight() >= 3000 || size.getWidth() >= 4000) continue; - } - if (optimalSize == null || size.getWidth() > optimalSize.getWidth()) { - optimalSize = size; - } - } - } - return optimalSize; - } - private Size getMaxPictureSizeLessThan4k() { Size[] sizes = mSettingsManager.getSupportedOutputSize(getMainCameraId(), ImageFormat.JPEG); float ratio = (float) mVideoSize.getWidth() / mVideoSize.getHeight(); diff --git a/src/com/android/camera/CaptureUI.java b/src/com/android/camera/CaptureUI.java index 6ec09effd..d0b129ad9 100755..100644 --- a/src/com/android/camera/CaptureUI.java +++ b/src/com/android/camera/CaptureUI.java @@ -306,8 +306,10 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, mMakeupSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) { - int value = progresValue/10*10; - mSettingsManager.setValue(SettingsManager.KEY_MAKEUP, value+""); + if ( progresValue != 0 ) { + int value = 10 + 9 * progresValue / 10; + mSettingsManager.setValue(SettingsManager.KEY_MAKEUP, value + ""); + } } @Override public void onStartTrackingTouch(SeekBar seekBar) { @@ -484,8 +486,8 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, showFirstTimeHelp(); } - protected void showCapturedImageForReview(byte[] jpegData, int orientation, boolean mirror) { - mDecodeTaskForReview = new CaptureUI.DecodeImageForReview(jpegData, orientation, mirror); + protected void showCapturedImageForReview(byte[] jpegData, int orientation) { + mDecodeTaskForReview = new CaptureUI.DecodeImageForReview(jpegData, orientation); mDecodeTaskForReview.execute(); if (getCurrentIntentMode() != CaptureModule.INTENT_MODE_NORMAL) { if (mFilterMenuStatus == FILTER_MENU_ON) { @@ -1737,24 +1739,18 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, private class DecodeTask extends AsyncTask<Void, Void, Bitmap> { private final byte [] mData; private int mOrientation; - private boolean mMirror; - public DecodeTask(byte[] data, int orientation, boolean mirror) { + public DecodeTask(byte[] data, int orientation) { mData = data; mOrientation = orientation; - mMirror = mirror; } @Override protected Bitmap doInBackground(Void... params) { Bitmap bitmap = CameraUtil.downSample(mData, mDownSampleFactor); // Decode image in background. - if ((mOrientation != 0 || mMirror) && (bitmap != null)) { + if ((mOrientation != 0) && (bitmap != null)) { Matrix m = new Matrix(); - if (mMirror) { - // Flip horizontally - m.setScale(-1f, 1f); - } m.preRotate(mOrientation); return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, false); @@ -1768,8 +1764,8 @@ public class CaptureUI implements FocusOverlayManager.FocusUI, } private class DecodeImageForReview extends CaptureUI.DecodeTask { - public DecodeImageForReview(byte[] data, int orientation, boolean mirror) { - super(data, orientation, mirror); + public DecodeImageForReview(byte[] data, int orientation) { + super(data, orientation); } @Override diff --git a/src/com/android/camera/imageprocessor/PostProcessor.java b/src/com/android/camera/imageprocessor/PostProcessor.java index 6e34de96d..d70743be9 100644 --- a/src/com/android/camera/imageprocessor/PostProcessor.java +++ b/src/com/android/camera/imageprocessor/PostProcessor.java @@ -391,6 +391,7 @@ public class PostProcessor{ public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) { + Log.d(TAG, "onCaptureCompleted"); if(mTotalCaptureResultList.size() <= PostProcessor.MAX_REQUIRED_IMAGE_NUM) { mTotalCaptureResultList.add(result); } @@ -405,11 +406,13 @@ public class PostProcessor{ public void onCaptureFailed(CameraCaptureSession session, CaptureRequest request, CaptureFailure result) { + Log.d(TAG, "onCaptureFailed"); } @Override public void onCaptureSequenceCompleted(CameraCaptureSession session, int sequenceId, long frameNumber) { + Log.d(TAG, "onCaptureSequenceCompleted"); if(!isFilterOn()) { mController.unlockFocus(mController.getMainCameraId()); } @@ -561,17 +564,20 @@ public class PostProcessor{ public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) { + Log.d(TAG, "reprocessImage onCaptureCompleted"); } @Override public void onCaptureFailed(CameraCaptureSession session, CaptureRequest request, CaptureFailure result) { + Log.d(TAG, "reprocessImage onCaptureFailed"); } @Override public void onCaptureSequenceCompleted(CameraCaptureSession session, int sequenceId, long frameNumber) { + Log.d(TAG, "reprocessImage onCaptureSequenceCompleted"); } }, mHandler); } catch (CameraAccessException e) { @@ -672,6 +678,7 @@ public class PostProcessor{ mImageHandlerTask = new ImageHandlerTask(); mSaveRaw = isSaveRaw; if(setFilter(postFilterId) || isFlashModeOn || isTrackingFocusOn || isMakeupOn || isSelfieMirrorOn + || PersistUtil.getCameraZSLDisabled() || !SettingsManager.getInstance().isZSLInAppEnabled() || "enable".equals( SettingsManager.getInstance().getValue(SettingsManager.KEY_AUTO_HDR)) @@ -1091,8 +1098,7 @@ public class PostProcessor{ if (mController.isQuickCapture()) { mController.onCaptureDone(); } else { - mController.showCapturedReview( - bytes, mOrientation, isSelfieMirrorOn()); + mController.showCapturedReview(bytes, mOrientation); } } mActivity.getMediaSaveService().addImage( @@ -1166,8 +1172,7 @@ public class PostProcessor{ if (mController.isQuickCapture()) { mController.onCaptureDone(); } else { - mController.showCapturedReview(bytes, - orientation, isSelfieMirrorOn()); + mController.showCapturedReview(bytes, orientation); } } else { mActivity.getMediaSaveService().addImage( @@ -1204,7 +1209,7 @@ public class PostProcessor{ return quality; } - public static class BitmapOutputStream extends ByteArrayOutputStream { + private class BitmapOutputStream extends ByteArrayOutputStream { public BitmapOutputStream(int size) { super(size); } |