From de5dd90a48875ed84371da6eb4354826a3b429e2 Mon Sep 17 00:00:00 2001 From: Emilian Peev Date: Mon, 17 Mar 2014 16:34:20 -0700 Subject: Camera: Initial Refocus support Refocus mode is enabled which expects 7 snapshots in burst from the camera. The captured images are stored with custom names. Change-Id: I7c1f9ef15d710118f7089c2fc584da450ab0984c --- res/values/qcomarrays.xml | 2 ++ res/values/qcomstrings.xml | 3 ++ src/com/android/camera/CameraSettings.java | 13 +++++++++ src/com/android/camera/PhotoModule.java | 41 +++++++++++++++++++++++++-- src/com/android/camera/util/CameraUtil.java | 43 +++++++++++++++++++++++------ 5 files changed, 90 insertions(+), 12 deletions(-) diff --git a/res/values/qcomarrays.xml b/res/values/qcomarrays.xml index bd808fed3..a87977d66 100644 --- a/res/values/qcomarrays.xml +++ b/res/values/qcomarrays.xml @@ -568,6 +568,7 @@ @string/pref_camera_advanced_feature_entry_none @string/pref_camera_advanced_feature_entry_ubifocus + @string/pref_camera_advanced_feature_entry_refocus @string/pref_camera_advanced_feature_entry_chromaflash @string/pref_camera_advanced_feature_entry_optizoom @@ -575,6 +576,7 @@ @string/pref_camera_advanced_feature_value_none @string/pref_camera_advanced_feature_value_ubifocus_on + @string/pref_camera_advanced_feature_value_refocus_on @string/pref_camera_advanced_feature_value_chromaflash_on @string/pref_camera_advanced_feature_value_optizoom_on diff --git a/res/values/qcomstrings.xml b/res/values/qcomstrings.xml index 5314b70f0..f3617aaa8 100644 --- a/res/values/qcomstrings.xml +++ b/res/values/qcomstrings.xml @@ -141,15 +141,18 @@ None Ubi Focus + Refocus Chroma Flash Opti Zoom none af-bracket-on + re-focus-on chroma-flash-on opti-zoom-on af-bracket-off + re-focus-off chroma-flash-off opti-zoom-off diff --git a/src/com/android/camera/CameraSettings.java b/src/com/android/camera/CameraSettings.java index 481677cc6..5e24ced13 100644 --- a/src/com/android/camera/CameraSettings.java +++ b/src/com/android/camera/CameraSettings.java @@ -110,12 +110,16 @@ public class CameraSettings { private static final String KEY_QC_SUPPORTED_AE_BRACKETING_MODES = "ae-bracket-hdr-values"; private static final String KEY_QC_SUPPORTED_AF_BRACKETING_MODES = "af-bracket-values"; + private static final String KEY_QC_SUPPORTED_RE_FOCUS_MODES = "re-focus-values"; private static final String KEY_QC_SUPPORTED_CF_MODES = "chroma-flash-values"; private static final String KEY_QC_SUPPORTED_OZ_MODES = "opti-zoom-values"; private static final String KEY_QC_SUPPORTED_FACE_RECOGNITION_MODES = "face-recognition-values"; private static final String KEY_QC_SUPPORTED_DIS_MODES = "dis-values"; public static final String KEY_QC_AE_BRACKETING = "ae-bracket-hdr"; public static final String KEY_QC_AF_BRACKETING = "af-bracket"; + public static final String KEY_QC_RE_FOCUS = "re-focus"; + public static final int KEY_QC_RE_FOCUS_COUNT = 7; + public static final String KEY_QC_LEGACY_BURST = "snapshot-burst-num"; public static final String KEY_QC_CHROMA_FLASH = "chroma-flash"; public static final String KEY_QC_OPTI_ZOOM = "opti-zoom"; public static final String KEY_QC_FACE_RECOGNITION = "face-recognition"; @@ -269,6 +273,7 @@ public class CameraSettings { str += ',' + params.get(KEY_QC_SUPPORTED_CF_MODES); str += ',' + params.get(KEY_QC_SUPPORTED_OZ_MODES); str += ',' + mContext.getString(R.string.pref_camera_advanced_feature_default); + str += ',' + params.get(KEY_QC_SUPPORTED_RE_FOCUS_MODES); return split(str); } @@ -296,6 +301,14 @@ public class CameraSettings { return split(str); } + public static List getSupportedRefocusModes(Parameters params) { + String str = params.get(KEY_QC_SUPPORTED_RE_FOCUS_MODES); + if (str == null) { + return null; + } + return split(str); + } + // Splits a comma delimited string to an ArrayList of String. // Return null if the passing string is null or the size is 0. diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java index 1b0531089..743ea4806 100644 --- a/src/com/android/camera/PhotoModule.java +++ b/src/com/android/camera/PhotoModule.java @@ -185,6 +185,7 @@ public class PhotoModule private boolean mContinuousFocusSupported; private boolean mTouchAfAecFlag; private boolean mLongshotSave = false; + private boolean mRefocus = false; // The degrees of the device rotated clockwise from its natural orientation. private int mOrientation = OrientationEventListener.ORIENTATION_UNKNOWN; @@ -1123,7 +1124,7 @@ public class PhotoModule if (!mIsImageCaptureIntent) { // Burst snapshot. Generate new image name. if (mReceivedSnapNum > 1) - mNamedImages.nameNewImage(mCaptureStartTime); + mNamedImages.nameNewImage(mCaptureStartTime, mRefocus); // Calculate the width and the height of the jpeg. Size s = mParameters.getPictureSize(); @@ -1326,6 +1327,13 @@ public class PhotoModule mQueue.add(r); } + public void nameNewImage(long date, boolean refocus) { + NamedEntity r = new NamedEntity(); + r.title = CameraUtil.createJpegName(date, refocus); + r.date = date; + mQueue.add(r); + } + public NamedEntity getNextNameEntity() { synchronized(mQueue) { if (!mQueue.isEmpty()) { @@ -1415,6 +1423,14 @@ public class PhotoModule loc = mLocationManager.getCurrentLocation(); } CameraUtil.setGpsParameters(mParameters, loc); + + if (mRefocus) { + mParameters.set(CameraSettings.KEY_QC_LEGACY_BURST, + CameraSettings.KEY_QC_RE_FOCUS_COUNT); + } else { + mParameters.remove(CameraSettings.KEY_QC_LEGACY_BURST); + } + mCameraDevice.setParameters(mParameters); mParameters = mCameraDevice.getParameters(); @@ -1452,7 +1468,7 @@ public class PhotoModule setCameraState(SNAPSHOT_IN_PROGRESS); } - mNamedImages.nameNewImage(mCaptureStartTime); + mNamedImages.nameNewImage(mCaptureStartTime, mRefocus); if (mSnapshotMode != CameraInfo.CAMERA_SUPPORT_MODE_ZSL) { mFaceDetectionStarted = false; @@ -2415,6 +2431,7 @@ public class PhotoModule private void qcomUpdateAdvancedFeatures(String ubiFocus, String chromaFlash, + String reFocus, String optiZoom) { if (CameraUtil.isSupported(ubiFocus, CameraSettings.getSupportedAFBracketingModes(mParameters))) { @@ -2428,6 +2445,10 @@ public class PhotoModule CameraSettings.getSupportedOptiZoomModes(mParameters))) { mParameters.set(CameraSettings.KEY_QC_OPTI_ZOOM, optiZoom); } + if (CameraUtil.isSupported(reFocus, + CameraSettings.getSupportedRefocusModes(mParameters))) { + mParameters.set(CameraSettings.KEY_QC_RE_FOCUS, reFocus); + } } private void qcomUpdateCameraParametersPreference() { //qcom Related Parameter update @@ -2586,8 +2607,9 @@ public class PhotoModule String advancedFeature = mPreferences.getString( CameraSettings.KEY_ADVANCED_FEATURES, mActivity.getString(R.string.pref_camera_advanced_feature_default)); - Log.v(TAG, " advancedFeature value =" + advancedFeature); + Log.e(TAG, " advancedFeature value =" + advancedFeature); + mRefocus = false; if(advancedFeature != null) { String ubiFocusOff = mActivity.getString(R.string. pref_camera_advanced_feature_value_ubifocus_off); @@ -2595,25 +2617,38 @@ public class PhotoModule pref_camera_advanced_feature_value_chromaflash_off); String optiZoomOff = mActivity.getString(R.string. pref_camera_advanced_feature_value_optizoom_off); + String reFocusOff = mActivity.getString(R.string. + pref_camera_advanced_feature_value_refocus_off); if (advancedFeature.equals(mActivity.getString(R.string. pref_camera_advanced_feature_value_ubifocus_on))) { qcomUpdateAdvancedFeatures(advancedFeature, chromaFlashOff, + reFocusOff, optiZoomOff); } else if (advancedFeature.equals(mActivity.getString(R.string. pref_camera_advanced_feature_value_chromaflash_on))) { qcomUpdateAdvancedFeatures(ubiFocusOff, + advancedFeature, + reFocusOff, + optiZoomOff); + } else if (advancedFeature.equals(mActivity.getString(R.string. + pref_camera_advanced_feature_value_refocus_on))) { + qcomUpdateAdvancedFeatures(ubiFocusOff, + chromaFlashOff, advancedFeature, optiZoomOff); + mRefocus = true; } else if (advancedFeature.equals(mActivity.getString(R.string. pref_camera_advanced_feature_value_optizoom_on))) { qcomUpdateAdvancedFeatures(ubiFocusOff, chromaFlashOff, + reFocusOff, advancedFeature); } else { qcomUpdateAdvancedFeatures(ubiFocusOff, chromaFlashOff, + reFocusOff, optiZoomOff); } } diff --git a/src/com/android/camera/util/CameraUtil.java b/src/com/android/camera/util/CameraUtil.java index d90b52552..bb7639f9f 100644 --- a/src/com/android/camera/util/CameraUtil.java +++ b/src/com/android/camera/util/CameraUtil.java @@ -720,9 +720,15 @@ public class CameraUtil { matrix.setConcat(mapping, matrix); } + public static String createJpegName(long dateTaken, boolean refocus) { + synchronized (sImageFileNamer) { + return sImageFileNamer.generateName(dateTaken, refocus); + } + } + public static String createJpegName(long dateTaken) { synchronized (sImageFileNamer) { - return sImageFileNamer.generateName(dateTaken); + return sImageFileNamer.generateName(dateTaken, false); } } @@ -903,6 +909,12 @@ public class CameraUtil { private static class ImageFileNamer { private final SimpleDateFormat mFormat; + private final int REFOCUS_DEPTHMAP_IDX = 5; + private final String REFOCUS_DEPTHMAP_SUFFIX = "DepthMap"; + private final int REFOCUS_ALLFOCUS_IDX = 6; + private final String REFOCUS_ALLFOCUS_SUFFIX = "Allfocus"; + private int mRefocusIdx = 0; + // The date (in milliseconds) used to generate the last name. private long mLastDate; @@ -913,18 +925,31 @@ public class CameraUtil { mFormat = new SimpleDateFormat(format); } - public String generateName(long dateTaken) { + public String generateName(long dateTaken, boolean refocus) { Date date = new Date(dateTaken); String result = mFormat.format(date); - // If the last name was generated for the same second, - // we append _1, _2, etc to the name. - if (dateTaken / 1000 == mLastDate / 1000) { - mSameSecondCount++; - result += "_" + mSameSecondCount; + if (refocus) { + if (mRefocusIdx == REFOCUS_DEPTHMAP_IDX) { + result += "_" + REFOCUS_DEPTHMAP_SUFFIX; + mRefocusIdx++; + } else if (mRefocusIdx == REFOCUS_ALLFOCUS_IDX) { + result += "_" + REFOCUS_ALLFOCUS_SUFFIX; + mRefocusIdx = 0; + } else { + result += "_" + mRefocusIdx; + mRefocusIdx++; + } } else { - mLastDate = dateTaken; - mSameSecondCount = 0; + // If the last name was generated for the same second, + // we append _1, _2, etc to the name. + if (dateTaken / 1000 == mLastDate / 1000) { + mSameSecondCount++; + result += "_" + mSameSecondCount; + } else { + mLastDate = dateTaken; + mSameSecondCount = 0; + } } return result; -- cgit v1.2.3