Skip to content

Commit a18e629

Browse files
committed
Allow to specify the white-balance (default to auto)
1 parent 1250ad7 commit a18e629

File tree

10 files changed

+71
-10
lines changed

10 files changed

+71
-10
lines changed

.idea/compiler.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ android {
2525
applicationId "com.dan.simplerawcamera"
2626
minSdkVersion 28
2727
targetSdkVersion 30
28-
versionCode 11
29-
versionName '2.11'
28+
versionCode 14
29+
versionName '2.14'
3030

3131
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3232
}

app/src/main/java/com/dan/simplerawcamera/CameraActivity.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,9 @@ class CameraActivity : AppCompatActivity() {
16091609

16101610
captureRequestBuilder.set(CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE, CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE_ON)
16111611
captureRequestBuilder.set(CaptureRequest.CONTROL_AWB_LOCK, false)
1612-
captureRequestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest.CONTROL_AWB_MODE_AUTO)
1612+
1613+
val wbMode = settings.getWBMode(mCameraInfo.wbModes)
1614+
captureRequestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, wbMode)
16131615

16141616
if (photoMode) {
16151617
captureRequestBuilder.set(CaptureRequest.JPEG_QUALITY, 90)

app/src/main/java/com/dan/simplerawcamera/CameraInfo.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class CameraInfo(
3030
val hasFlash: Boolean,
3131
val sensorOrientation: Int,
3232
val streamConfigurationMap: StreamConfigurationMap,
33-
val supportLensStabilisation: Boolean
33+
val supportLensStabilisation: Boolean,
34+
val wbModes: IntArray
3435
) {
3536

3637
companion object {
@@ -85,6 +86,8 @@ class CameraInfo(
8586
val jpegSize = streamConfigurationMap.getOutputSizes(ImageFormat.JPEG)[0]
8687
val rawSize = Size(resolutionRect.width(), resolutionRect.height())
8788

89+
val wbModes = characteristics.get(CameraCharacteristics.CONTROL_AWB_AVAILABLE_MODES) as IntArray
90+
8891
return CameraInfo(
8992
cameraId,
9093
physicalId,
@@ -101,7 +104,8 @@ class CameraInfo(
101104
hasFlash,
102105
sensorOrientation,
103106
streamConfigurationMap,
104-
supportLensStabilisation
107+
supportLensStabilisation,
108+
wbModes
105109
)
106110
}
107111

app/src/main/java/com/dan/simplerawcamera/Settings.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ class Settings( private val activity: Activity) {
5454
val MACRO_NUMBER_OF_PHOTOS_OPTIONS = arrayOf(3, 4, 5, 6, 7, 8, 9, 10)
5555

5656
val FLASH_MODES = arrayOf("OFF", "ON", "Torch")
57+
58+
val WB_MODES = arrayOf(
59+
android.hardware.camera2.CaptureResult.CONTROL_AWB_MODE_AUTO,
60+
android.hardware.camera2.CaptureResult.CONTROL_AWB_MODE_INCANDESCENT,
61+
android.hardware.camera2.CaptureResult.CONTROL_AWB_MODE_FLUORESCENT,
62+
android.hardware.camera2.CaptureResult.CONTROL_AWB_MODE_WARM_FLUORESCENT,
63+
android.hardware.camera2.CaptureResult.CONTROL_AWB_MODE_DAYLIGHT,
64+
android.hardware.camera2.CaptureResult.CONTROL_AWB_MODE_CLOUDY_DAYLIGHT,
65+
android.hardware.camera2.CaptureResult.CONTROL_AWB_MODE_TWILIGHT,
66+
android.hardware.camera2.CaptureResult.CONTROL_AWB_MODE_SHADE
67+
)
5768
}
5869

5970
var saveUri: String = ""
@@ -80,6 +91,7 @@ class Settings( private val activity: Activity) {
8091
var flashMode: Int = FLASH_MODE_OFF
8192
var enableHapticFeedback = true
8293
var useLocation = true
94+
var whiteBalance = 0
8395

8496
init {
8597
loadProperties()
@@ -172,4 +184,10 @@ class Settings( private val activity: Activity) {
172184

173185
return array[index]
174186
}
187+
188+
fun getWBMode(availableModes: IntArray): Int {
189+
val whiteBalance = this.whiteBalance;
190+
val mode = if (whiteBalance < WB_MODES.size) WB_MODES[whiteBalance] else WB_MODES[0]
191+
return if (availableModes.contains(mode)) mode else WB_MODES[0]
192+
}
175193
}

app/src/main/java/com/dan/simplerawcamera/SettingsDialog.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class SettingsDialog(private val cameraActivity: CameraActivity, private val lis
4646
binding.switchShowDebugInfo.isChecked = cameraActivity.settings.showDebugInfo
4747
binding.switchLocation.isChecked = cameraActivity.settings.useLocation
4848
binding.switchHapticFeedback.isChecked = cameraActivity.settings.enableHapticFeedback
49+
binding.spinnerWhiteBallance.setSelection(cameraActivity.settings.whiteBalance)
4950

5051
binding.btnSelectFolder.setOnClickListener {
5152
cameraActivity.startSelectFolder()
@@ -65,6 +66,7 @@ class SettingsDialog(private val cameraActivity: CameraActivity, private val lis
6566
cameraActivity.settings.showDebugInfo = binding.switchShowDebugInfo.isChecked
6667
cameraActivity.settings.useLocation = binding.switchLocation.isChecked
6768
cameraActivity.settings.enableHapticFeedback = binding.switchHapticFeedback.isChecked
69+
cameraActivity.settings.whiteBalance = binding.spinnerWhiteBallance.selectedItemPosition
6870

6971
cameraActivity.settings.saveProperties()
7072

app/src/main/res/layout/settings.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,31 @@
114114

115115
</LinearLayout>
116116

117+
<LinearLayout
118+
android:layout_width="match_parent"
119+
android:layout_height="wrap_content"
120+
android:gravity="center_vertical"
121+
android:orientation="horizontal"
122+
android:paddingTop="10dp">
123+
124+
<TextView
125+
android:id="@+id/textView6"
126+
android:layout_width="wrap_content"
127+
android:layout_height="wrap_content"
128+
android:layout_marginRight="16dp"
129+
android:layout_weight="0"
130+
android:text="White ballance:"
131+
android:textColor="@color/black" />
132+
133+
<Spinner
134+
android:id="@+id/spinnerWhiteBallance"
135+
android:layout_width="wrap_content"
136+
android:layout_height="wrap_content"
137+
android:layout_weight="1"
138+
android:entries="@array/white_balance_modes"
139+
android:spinnerMode="dropdown" />
140+
</LinearLayout>
141+
117142
<LinearLayout
118143
android:layout_width="match_parent"
119144
android:layout_height="wrap_content"

app/src/main/res/values/strings.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,15 @@
1515
<item>JPEG &amp; DNG</item>
1616
</string-array>
1717

18+
<string-array name="white_balance_modes">
19+
<item>Auto</item>
20+
<item>Incandescent</item>
21+
<item>Fluorescent</item>
22+
<item>Warm Fluorescent</item>
23+
<item>Daylight</item>
24+
<item>Cloudy Daylight</item>
25+
<item>Twilight</item>
26+
<item>Shade</item>
27+
</string-array>
28+
1829
</resources>

0 commit comments

Comments
 (0)