From 2746c637eb71715a30d292732c986a6cbe48b98a Mon Sep 17 00:00:00 2001 From: jinwu Date: Fri, 21 Sep 2018 18:21:50 +0800 Subject: SnapdragonCamera: Completed the function of Manual WB Completed the function of Manual WB gains and cct. CRs-Fixed: 2297603 Change-Id: Ia161307fe4b305e86953560b802d749b86f848b3 --- src/com/android/camera/CaptureModule.java | 39 ++++++ src/com/android/camera/SettingsActivity.java | 185 +++++++++++++++++++++++++ src/com/android/camera/SettingsManager.java | 42 ++++++ src/com/android/camera/util/VendorTagUtil.java | 49 ++++++- 4 files changed, 314 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java index 7bfee3041..253945e0d 100755 --- a/src/com/android/camera/CaptureModule.java +++ b/src/com/android/camera/CaptureModule.java @@ -269,6 +269,12 @@ public class CaptureModule implements CameraModule, PhotoController, public static CameraCharacteristics.Key EXPOSURE_RANGE = new CameraCharacteristics.Key<>("org.codeaurora.qcamera3.iso_exp_priority.exposure_time_range", long[].class); + // manual WB color temperature and gains + public static CameraCharacteristics.Key WB_COLOR_TEMPERATURE_RANGE = + new CameraCharacteristics.Key<>("org.codeaurora.qcamera3.manualWB.color_temperature_range", int[].class); + public static CameraCharacteristics.Key WB_RGB_GAINS_RANGE = + new CameraCharacteristics.Key<>("org.codeaurora.qcamera3.manualWB.gains_range", float[].class); + public static CameraCharacteristics.Key buckets = new CameraCharacteristics.Key<>("org.codeaurora.qcamera3.histogram.buckets", Integer.class); public static CameraCharacteristics.Key maxCount = @@ -2797,6 +2803,7 @@ public class CaptureModule implements CameraModule, PhotoController, applyAWBCCTAndAgain(builder); applyBGStats(builder); applyBEStats(builder); + applyWbColorTemperature(builder); } /** @@ -5378,6 +5385,38 @@ public class CaptureModule implements CameraModule, PhotoController, updateBEStatsVisibility(View.GONE); } + private void applyWbColorTemperature(CaptureRequest.Builder request) { + final SharedPreferences pref = mActivity.getSharedPreferences( + ComboPreferences.getLocalSharedPreferencesName(mActivity, getMainCameraId()), + Context.MODE_PRIVATE); + String manualWBMode = mSettingsManager.getValue(SettingsManager.KEY_MANUAL_WB); + String cctMode = mActivity.getString( + R.string.pref_camera_manual_wb_value_color_temperature); + String gainMode = mActivity.getString( + R.string.pref_camera_manual_wb_value_rbgb_gains); + Log.v("daming", " >>> 5362 >>> cctMode :" + cctMode); + if (manualWBMode.equals(cctMode)) { + int colorTempValue = Integer.parseInt(pref.getString( + SettingsManager.KEY_MANUAL_WB_TEMPERATURE_VALUE, "-1")); + Log.v("daming", " >>> 5366 >>> colorTempValue :" + colorTempValue); + if (colorTempValue != -1) { + VendorTagUtil.setWbColorTemperatureValue(request, colorTempValue); + } + } else if (manualWBMode.equals(gainMode)) { + float rGain = pref.getFloat(SettingsManager.KEY_MANUAL_WB_R_GAIN, -1.0f); + float gGain = pref.getFloat(SettingsManager.KEY_MANUAL_WB_G_GAIN, -1.0f); + float bGain = pref.getFloat(SettingsManager.KEY_MANUAL_WB_B_GAIN, -1.0f); + if (rGain != -1.0 && gGain != -1.0 && bGain != -1.0f) { + request.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest.CONTROL_AWB_MODE_OFF); + float[] gains = {rGain, gGain, bGain}; + Log.v("daming", " >>> 5375 >>> rGain :" + rGain + ", gGain :" + gGain + ", bGain :" + bGain); + VendorTagUtil.setMWBGainsValue(request, gains); + } + } else { + VendorTagUtil.setMWBDisableMode(request); + } + } + private void updateGraghViewVisibility(final int visibility) { mActivity.runOnUiThread(new Runnable() { public void run() { diff --git a/src/com/android/camera/SettingsActivity.java b/src/com/android/camera/SettingsActivity.java index e413090a4..f858e3646 100755 --- a/src/com/android/camera/SettingsActivity.java +++ b/src/com/android/camera/SettingsActivity.java @@ -66,6 +66,7 @@ public class SettingsActivity extends PreferenceActivity { private static final String TAG = "SettingsActivity"; private SettingsManager mSettingsManager; private SharedPreferences mSharedPreferences; + private SharedPreferences mLocalSharedPref; private boolean mDeveloperMenuEnabled; private int privateCounter = 0; private final int DEVELOPER_MENU_TOUCH_COUNT = 10; @@ -134,6 +135,10 @@ public class SettingsActivity extends PreferenceActivity { autoHdrPref.setEnabled(true); } } + + if ( (pref.getKey().equals(SettingsManager.KEY_MANUAL_WB)) ) { + updateManualWBSettings(); + } } } }; @@ -338,6 +343,181 @@ public class SettingsActivity extends PreferenceActivity { alert.show(); } + private void showManualWBGainDialog(final LinearLayout linear, + final AlertDialog.Builder alert) { + SharedPreferences.Editor editor = mLocalSharedPref.edit(); + final TextView rGainTtext = new TextView(SettingsActivity.this); + final TextView rGainValue = new TextView(SettingsActivity.this); + final EditText rGainInput = new EditText(SettingsActivity.this); + final TextView gGainTtext = new TextView(SettingsActivity.this); + final TextView gGainValue = new TextView(SettingsActivity.this); + final EditText gGainInput = new EditText(SettingsActivity.this); + final TextView bGainTtext = new TextView(SettingsActivity.this); + final TextView bGainValue = new TextView(SettingsActivity.this); + final EditText bGainInput = new EditText(SettingsActivity.this); + int floatType = InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER; + rGainInput.setInputType(floatType); + gGainInput.setInputType(floatType); + bGainInput.setInputType(floatType); + + float rGain = mLocalSharedPref.getFloat(SettingsManager.KEY_MANUAL_WB_R_GAIN, -1.0f); + float gGain = mLocalSharedPref.getFloat(SettingsManager.KEY_MANUAL_WB_G_GAIN, -1.0f); + float bGain = mLocalSharedPref.getFloat(SettingsManager.KEY_MANUAL_WB_B_GAIN, -1.0f); + + if (rGain == -1.0) { + rGainValue.setText(" Current rGain is " ); + } else { + rGainValue.setText(" Current rGain is " + rGain); + } + if (rGain == -1.0) { + gGainValue.setText(" Current gGain is " ); + } else { + gGainValue.setText(" Current gGain is " + gGain); + } + if (rGain == -1.0) { + bGainValue.setText(" Current bGain is "); + } else { + bGainValue.setText(" Current bGain is " + bGain); + } + int cameraId = mSettingsManager.getCurrentCameraId(); + final float[] gainsRange = mSettingsManager.getWBGainsRangeValues(cameraId); + //refresh camera parameters to get latest CCT value + if (gainsRange == null) { + alert.setMessage("Enter gains value in the range get is NULL "); + } else { + alert.setMessage("Enter gains value in the range of " + gainsRange[0]+ " to " + gainsRange[1]); + } + linear.addView(rGainTtext); + linear.addView(rGainInput); + linear.addView(rGainValue); + linear.addView(gGainTtext); + linear.addView(gGainInput); + linear.addView(gGainValue); + linear.addView(bGainTtext); + linear.addView(bGainInput); + linear.addView(bGainValue); + alert.setView(linear); + alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + float rGain = -1.0f; + float gGain = -1.0f; + float bGain = -1.0f; + String rgainStr = rGainInput.getText().toString(); + String ggainStr = gGainInput.getText().toString(); + String bgainStr = bGainInput.getText().toString(); + if (rgainStr.length() > 0) { + rGain = Float.parseFloat(rgainStr); + } + if (ggainStr.length() > 0) { + gGain = Float.parseFloat(ggainStr); + } + if (bgainStr.length() > 0) { + bGain = Float.parseFloat(bgainStr); + } + if (gainsRange == null) { + RotateTextToast.makeText(SettingsActivity.this, "Gains Range is NULL, " + + "Invalid gains", Toast.LENGTH_SHORT).show(); + return; + } + if (rGain <= gainsRange[1] && rGain >= gainsRange[0]) { + Log.v(TAG, "Setting rGain value : " + rGain); + editor.putFloat(SettingsManager.KEY_MANUAL_WB_R_GAIN, rGain); + } else { + RotateTextToast.makeText(SettingsActivity.this, "Invalid rGain value:", + Toast.LENGTH_SHORT).show(); + } + if (gGain <= gainsRange[1] && gGain >= gainsRange[0]) { + Log.v(TAG, "Setting gGain value : " + gGain); + editor.putFloat(SettingsManager.KEY_MANUAL_WB_G_GAIN, gGain); + } else { + RotateTextToast.makeText(SettingsActivity.this, "Invalid gGain value:", + Toast.LENGTH_SHORT).show(); + } + if (bGain <= gainsRange[1] && bGain >= gainsRange[0]) { + Log.v(TAG, "Setting bGain value : " + bGain); + editor.putFloat(SettingsManager.KEY_MANUAL_WB_B_GAIN, bGain); + } else { + RotateTextToast.makeText(SettingsActivity.this, "Invalid bGain value:", + Toast.LENGTH_SHORT).show(); + } + editor.apply(); + } + }); + alert.show(); + } + + private void updateManualWBSettings() { + int cameraId = mSettingsManager.getCurrentCameraId(); + SharedPreferences.Editor editor = mLocalSharedPref.edit(); + final AlertDialog.Builder alert = new AlertDialog.Builder(SettingsActivity.this); + LinearLayout linear = new LinearLayout(SettingsActivity.this); + linear.setOrientation(1); + alert.setTitle("Manual White Balance Settings"); + alert.setNegativeButton("Cancel",new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog,int id) { + dialog.cancel(); + } + }); + + String cctMode = this.getString( + R.string.pref_camera_manual_wb_value_color_temperature); + String rgbGainMode = this.getString( + R.string.pref_camera_manual_wb_value_rbgb_gains); + String currentWBTemp = mLocalSharedPref.getString( + SettingsManager.KEY_MANUAL_WB_TEMPERATURE_VALUE, "-1"); + final String manualWBMode = mSettingsManager.getValue(SettingsManager.KEY_MANUAL_WB); + Log.v(TAG, "manualWBMode selected = " + manualWBMode); + final int[] wbRange = mSettingsManager.getWBColorTemperatureRangeValues(cameraId); + if (manualWBMode.equals(cctMode)) { + final TextView CCTtext = new TextView(SettingsActivity.this); + final EditText CCTinput = new EditText(SettingsActivity.this); + CCTinput.setInputType(InputType.TYPE_CLASS_NUMBER); + + //refresh camera parameters to get latest CCT value + if (currentWBTemp.equals("-1")) { + CCTtext.setText(" Current CCT is "); + } else { + CCTtext.setText(" Current CCT is " + currentWBTemp); + } + if (wbRange == null) { + alert.setMessage("Enter CCT value is get NULL "); + } else { + alert.setMessage("Enter CCT value in the range of " + wbRange[0]+ " to " + wbRange[1]); + } + linear.addView(CCTinput); + linear.addView(CCTtext); + alert.setView(linear); + alert.setPositiveButton("Ok",new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog,int id) { + int newCCT = -1; + String cct = CCTinput.getText().toString(); + if (cct.length() > 0) { + newCCT = Integer.parseInt(cct); + } + if (wbRange == null) { + RotateTextToast.makeText(SettingsActivity.this, "CCT Range is NULL, " + + "Invalid CCT", Toast.LENGTH_SHORT).show(); + return; + } + if (newCCT <= wbRange[1] && newCCT >= wbRange[0]) { + Log.v(TAG, "Setting CCT value : " + newCCT); + //0 corresponds to manual CCT mode + editor.putString(SettingsManager.KEY_MANUAL_WB_TEMPERATURE_VALUE, cct); + editor.apply(); + } else { + RotateTextToast.makeText(SettingsActivity.this, "Invalid CCT", + Toast.LENGTH_SHORT).show(); + } + } + }); + alert.show(); + } else if (manualWBMode.equals(rgbGainMode)) { + showManualWBGainDialog(linear, alert); + } else { + // user select off, nothing to do. + } + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -359,6 +539,11 @@ public class SettingsActivity extends PreferenceActivity { finish(); return; } + + int cameraId = mSettingsManager.getCurrentCameraId(); + mLocalSharedPref = this.getSharedPreferences( + ComboPreferences.getLocalSharedPreferencesName(this, cameraId), + Context.MODE_PRIVATE); mSettingsManager.registerListener(mListener); addPreferencesFromResource(R.xml.setting_menu_preferences); mSharedPreferences = getPreferenceManager().getSharedPreferences(); diff --git a/src/com/android/camera/SettingsManager.java b/src/com/android/camera/SettingsManager.java index 7640cb53b..5ccf8002b 100755 --- a/src/com/android/camera/SettingsManager.java +++ b/src/com/android/camera/SettingsManager.java @@ -159,10 +159,20 @@ public class SettingsManager implements ListMenu.SettingsListener { public static final String KEY_SHARPNESS_CONTROL_MODE = "pref_camera2_sharpness_control_key"; public static final String KEY_AF_MODE = "pref_camera2_afmode_key"; public static final String KEY_EXPOSURE_METERING_MODE = "pref_camera2_exposure_metering_key"; + + //manual 3A keys and parameter strings public static final String KEY_MANUAL_EXPOSURE = "pref_camera2_manual_exp_key"; public static final String KEY_MANUAL_ISO_VALUE = "pref_camera2_manual_iso_key"; public static final String KEY_MANUAL_GAINS_VALUE = "pref_camera2_manual_gains_key"; public static final String KEY_MANUAL_EXPOSURE_VALUE = "pref_camera2_manual_exposure_key"; + + public static final String KEY_MANUAL_WB = "pref_camera2_manual_wb_key"; + public static final String KEY_MANUAL_WB_TEMPERATURE_VALUE = + "pref_camera2_manual_temperature_key"; + public static final String KEY_MANUAL_WB_R_GAIN = "pref_camera2_manual_wb_r_gain"; + public static final String KEY_MANUAL_WB_G_GAIN = "pref_camera2_manual_wb_g_gain"; + public static final String KEY_MANUAL_WB_B_GAIN = "pref_camera2_manual_wb_b_gain"; + public static final String KEY_QCFA = "pref_camera2_qcfa_key"; public static final String KEY_EIS_VALUE = "pref_camera2_eis_key"; public static final String KEY_FOVC_VALUE = "pref_camera2_fovc_key"; @@ -939,6 +949,38 @@ public class SettingsManager implements ListMenu.SettingsListener { return pref.getEntryValues(); } + public int[] getWBColorTemperatureRangeValues(int cameraId) { + int[] wbRange = null; + try { + wbRange = mCharacteristics.get(cameraId).get(CaptureModule.WB_COLOR_TEMPERATURE_RANGE); + if (wbRange == null) { + Log.w(TAG, "Supported exposure range get null."); + return null; + } + } catch(NullPointerException e) { + Log.w(TAG, "Supported exposure range modes is null."); + } catch(IllegalArgumentException e) { + Log.w(TAG, "Supported exposure range modes occur IllegalArgumentException."); + } + return wbRange; + } + + public float[] getWBGainsRangeValues(int cameraId) { + float[] rgbRange = null; + try { + rgbRange = mCharacteristics.get(cameraId).get(CaptureModule.WB_RGB_GAINS_RANGE); + if (rgbRange == null) { + Log.w(TAG, "Supported gains range get null."); + return null; + } + } catch(NullPointerException e) { + Log.w(TAG, "Supported gains range modes is null."); + } catch(IllegalArgumentException e) { + Log.w(TAG, "Supported gains range modes occur IllegalArgumentException."); + } + return rgbRange; + } + public long[] getExposureRangeValues(int cameraId) { long[] exposureRange = null; try { diff --git a/src/com/android/camera/util/VendorTagUtil.java b/src/com/android/camera/util/VendorTagUtil.java index 2842b62cf..b2efbfa54 100755 --- a/src/com/android/camera/util/VendorTagUtil.java +++ b/src/com/android/camera/util/VendorTagUtil.java @@ -57,9 +57,20 @@ public class VendorTagUtil { private static CaptureRequest.Key USE_ISO_VALUE = new CaptureRequest.Key<>("org.codeaurora.qcamera3.iso_exp_priority.use_iso_value", Integer.class); - private static final CaptureRequest.Key HDRVideoMode = + private static CaptureRequest.Key WB_COLOR_TEMPERATURE = + new CaptureRequest.Key<>("org.codeaurora.qcamera3.manualWB.color_temperature", + Integer.class); + private static CaptureRequest.Key MANUAL_WB_GAINS = + new CaptureRequest.Key<>("org.codeaurora.qcamera3.manualWB.gains", float[].class); + private static CaptureRequest.Key PARTIAL_MANUAL_WB_MODE = + new CaptureRequest.Key<>("org.codeaurora.qcamera3.manualWB.partial_mwb_mode", Integer.class); + private static CaptureRequest.Key HDRVideoMode = new CaptureRequest.Key<>("org.quic.camera2.streamconfigs.HDRVideoMode", Byte.class); + private static final int MANUAL_WB_DISABLE_MODE = 0; + private static final int MANUAL_WB_CCT_MODE = 1; + private static final int MANUAL_WB_GAINS_MODE = 2; + private static boolean isSupported(CaptureRequest.Builder builder, CaptureRequest.Key key) { boolean supported = true; @@ -147,6 +158,42 @@ public class VendorTagUtil { return isSupported(builder, USE_ISO_VALUE); } + private static boolean isPartialWBModeSupported(CaptureRequest.Builder builder) { + return isSupported(builder, PARTIAL_MANUAL_WB_MODE); + } + + private static boolean isWBTemperatureSupported(CaptureRequest.Builder builder) { + return isSupported(builder, WB_COLOR_TEMPERATURE); + } + + private static boolean isMWBGainsSupported(CaptureRequest.Builder builder) { + return isSupported(builder, MANUAL_WB_GAINS); + } + + public static void setWbColorTemperatureValue(CaptureRequest.Builder builder, Integer value) { + if (isPartialWBModeSupported(builder)) { + builder.set(PARTIAL_MANUAL_WB_MODE, MANUAL_WB_CCT_MODE); + if (isWBTemperatureSupported(builder)) { + builder.set(WB_COLOR_TEMPERATURE, value); + } + } + } + + public static void setMWBGainsValue(CaptureRequest.Builder builder, float[] gains) { + if (isPartialWBModeSupported(builder)) { + builder.set(PARTIAL_MANUAL_WB_MODE, MANUAL_WB_GAINS_MODE); + if (isMWBGainsSupported(builder)) { + builder.set(MANUAL_WB_GAINS, gains); + } + } + } + + public static void setMWBDisableMode(CaptureRequest.Builder builder) { + if (isPartialWBModeSupported(builder)) { + builder.set(PARTIAL_MANUAL_WB_MODE, MANUAL_WB_DISABLE_MODE); + } + } + public static void setHDRVideoMode(CaptureRequest.Builder builder, byte mode) { if ( isHDRVideoModeSupported(builder) ) { builder.set(HDRVideoMode, mode); -- cgit v1.2.3