fix: default black render
This commit is contained in:
1 parent
41d3096f40
commit
71c3d512de
8 files changed
+136
-43
No files matched your search
@@ -2,8 +2,9 @@ package com.hinnka.mycamera.camera
|
||||
|
||||
import com.hinnka.mycamera.raw.RawCfaCorrection
|
||||
import com.hinnka.mycamera.raw.RawWhiteLevelCorrection
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonObject
|
||||
import com.google.gson.JsonParser
|
||||
import java.util.Locale
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.roundToInt
|
||||
@@ -18,19 +19,19 @@ data class IszLensConfig(
|
||||
val virtualCameraId: String
|
||||
get() = createVirtualCameraId(baseCameraId, iszZoomRatio, vendorCaptureProfileId)
|
||||
|
||||
fun toJsonObject(): JSONObject {
|
||||
return JSONObject().apply {
|
||||
put(KEY_BASE_CAMERA_ID, baseCameraId)
|
||||
put(KEY_ISZ_ZOOM_RATIO, iszZoomRatio)
|
||||
put(KEY_IS_MACRO, isMacro)
|
||||
fun toJsonObject(): JsonObject {
|
||||
return JsonObject().apply {
|
||||
addProperty(KEY_BASE_CAMERA_ID, baseCameraId)
|
||||
addProperty(KEY_ISZ_ZOOM_RATIO, iszZoomRatio)
|
||||
addProperty(KEY_IS_MACRO, isMacro)
|
||||
sanitizeVendorCaptureProfileId(vendorCaptureProfileId)?.let {
|
||||
put(KEY_VENDOR_CAPTURE_PROFILE_ID, it)
|
||||
addProperty(KEY_VENDOR_CAPTURE_PROFILE_ID, it)
|
||||
}
|
||||
val sanitizedCrop = sanitizeRawBlackBorderCrop(rawBlackBorderCrop)
|
||||
put(KEY_RAW_BLACK_BORDER_CROP_LEFT_PX, sanitizedCrop.leftPx)
|
||||
put(KEY_RAW_BLACK_BORDER_CROP_TOP_PX, sanitizedCrop.topPx)
|
||||
put(KEY_RAW_BLACK_BORDER_CROP_RIGHT_PX, sanitizedCrop.rightPx)
|
||||
put(KEY_RAW_BLACK_BORDER_CROP_BOTTOM_PX, sanitizedCrop.bottomPx)
|
||||
addProperty(KEY_RAW_BLACK_BORDER_CROP_LEFT_PX, sanitizedCrop.leftPx)
|
||||
addProperty(KEY_RAW_BLACK_BORDER_CROP_TOP_PX, sanitizedCrop.topPx)
|
||||
addProperty(KEY_RAW_BLACK_BORDER_CROP_RIGHT_PX, sanitizedCrop.rightPx)
|
||||
addProperty(KEY_RAW_BLACK_BORDER_CROP_BOTTOM_PX, sanitizedCrop.bottomPx)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,23 +60,30 @@ data class IszLensConfig(
|
||||
|
||||
fun deserializeList(value: String?): List<IszLensConfig> {
|
||||
if (value.isNullOrBlank()) return emptyList()
|
||||
val array = runCatching { JSONArray(value) }.getOrNull() ?: return emptyList()
|
||||
val array = runCatching {
|
||||
JsonParser.parseString(value)
|
||||
.takeIf { it.isJsonArray }
|
||||
?.asJsonArray
|
||||
}.getOrNull() ?: return emptyList()
|
||||
return buildList {
|
||||
for (index in 0 until array.length()) {
|
||||
val obj = array.optJSONObject(index) ?: continue
|
||||
val baseCameraId = obj.optString(KEY_BASE_CAMERA_ID).trim()
|
||||
val iszZoomRatio = obj.optDouble(KEY_ISZ_ZOOM_RATIO, 0.0).toFloat()
|
||||
val isMacro = obj.optBoolean(KEY_IS_MACRO, false)
|
||||
for (index in 0 until array.size()) {
|
||||
val obj = array[index].takeIf { it.isJsonObject }?.asJsonObject ?: continue
|
||||
val baseCameraId = obj.stringOrDefault(KEY_BASE_CAMERA_ID).trim()
|
||||
val iszZoomRatio = obj.doubleOrDefault(KEY_ISZ_ZOOM_RATIO, 0.0).toFloat()
|
||||
val isMacro = obj.booleanOrDefault(KEY_IS_MACRO, false)
|
||||
val vendorCaptureProfileId = sanitizeVendorCaptureProfileId(
|
||||
obj.optString(KEY_VENDOR_CAPTURE_PROFILE_ID, "")
|
||||
obj.stringOrDefault(KEY_VENDOR_CAPTURE_PROFILE_ID)
|
||||
)
|
||||
val legacyLeftCropPx = obj.optInt(KEY_RAW_BLACK_BORDER_CROP_PX, 0)
|
||||
val legacyLeftCropPx = obj.intOrDefault(KEY_RAW_BLACK_BORDER_CROP_PX, 0)
|
||||
val rawBlackBorderCrop = sanitizeRawBlackBorderCrop(
|
||||
RawBlackBorderCrop(
|
||||
leftPx = obj.optInt(KEY_RAW_BLACK_BORDER_CROP_LEFT_PX, legacyLeftCropPx),
|
||||
topPx = obj.optInt(KEY_RAW_BLACK_BORDER_CROP_TOP_PX, 0),
|
||||
rightPx = obj.optInt(KEY_RAW_BLACK_BORDER_CROP_RIGHT_PX, 0),
|
||||
bottomPx = obj.optInt(KEY_RAW_BLACK_BORDER_CROP_BOTTOM_PX, 0)
|
||||
leftPx = obj.intOrDefault(
|
||||
KEY_RAW_BLACK_BORDER_CROP_LEFT_PX,
|
||||
legacyLeftCropPx
|
||||
),
|
||||
topPx = obj.intOrDefault(KEY_RAW_BLACK_BORDER_CROP_TOP_PX, 0),
|
||||
rightPx = obj.intOrDefault(KEY_RAW_BLACK_BORDER_CROP_RIGHT_PX, 0),
|
||||
bottomPx = obj.intOrDefault(KEY_RAW_BLACK_BORDER_CROP_BOTTOM_PX, 0)
|
||||
)
|
||||
)
|
||||
if (baseCameraId.isNotEmpty() && iszZoomRatio >= 1f) {
|
||||
@@ -94,11 +102,11 @@ data class IszLensConfig(
|
||||
}
|
||||
|
||||
fun serializeList(configs: List<IszLensConfig>): String {
|
||||
return JSONArray().apply {
|
||||
return JsonArray().apply {
|
||||
configs
|
||||
.filter { it.baseCameraId.isNotBlank() && it.iszZoomRatio >= 1f }
|
||||
.distinctBy { it.virtualCameraId }
|
||||
.forEach { put(it.toJsonObject()) }
|
||||
.forEach { add(it.toJsonObject()) }
|
||||
}.toString()
|
||||
}
|
||||
|
||||
@@ -142,6 +150,30 @@ data class IszLensConfig(
|
||||
bottomPx = sanitizeRawBlackBorderCropPx(crop.bottomPx)
|
||||
)
|
||||
}
|
||||
|
||||
private fun JsonObject.stringOrDefault(key: String, defaultValue: String = ""): String {
|
||||
return runCatching { get(key)?.takeUnless { it.isJsonNull }?.asString }
|
||||
.getOrNull()
|
||||
?: defaultValue
|
||||
}
|
||||
|
||||
private fun JsonObject.doubleOrDefault(key: String, defaultValue: Double): Double {
|
||||
return runCatching { get(key)?.takeUnless { it.isJsonNull }?.asDouble }
|
||||
.getOrNull()
|
||||
?: defaultValue
|
||||
}
|
||||
|
||||
private fun JsonObject.booleanOrDefault(key: String, defaultValue: Boolean): Boolean {
|
||||
return runCatching { get(key)?.takeUnless { it.isJsonNull }?.asBoolean }
|
||||
.getOrNull()
|
||||
?: defaultValue
|
||||
}
|
||||
|
||||
private fun JsonObject.intOrDefault(key: String, defaultValue: Int): Int {
|
||||
return runCatching { get(key)?.takeUnless { it.isJsonNull }?.asInt }
|
||||
.getOrNull()
|
||||
?: defaultValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1421,6 +1421,11 @@ class GlesRawStacker(
|
||||
baselineExposureEv = baselineExposureEv,
|
||||
packedCellStats = packedCellStats,
|
||||
diagnosticBand = diagnosticBand,
|
||||
fusionParameters = if (profileToneMapMode == RawProfileToneMapMode.Photon) {
|
||||
DngHdrProfileGainTableGenerator.PHOTON_FUSION_PARAMETERS
|
||||
} else {
|
||||
DngHdrProfileGainTableGenerator.GOOGLE_FUSION_PARAMETERS
|
||||
},
|
||||
)
|
||||
val completeNs = System.nanoTime()
|
||||
PLog.d(
|
||||
|
||||
@@ -46,7 +46,7 @@ internal object DngHdrLtmSpatialModel {
|
||||
1.20f,
|
||||
log2((global.inputTailP99 + TAIL_EPS) / (global.inputTailP95 + TAIL_EPS))
|
||||
)
|
||||
val residualScale = 1f + 1.50f * saturatedScene + 1.00f * sparseSeparatedTail
|
||||
val residualScale = 1f + 2.20f * saturatedScene + 1.00f * sparseSeparatedTail
|
||||
return Array(cells.size) { index ->
|
||||
val cell = cells[index]
|
||||
if (cell == null || cell.sampleWeight <= 0f) {
|
||||
|
||||
@@ -6962,7 +6962,7 @@ class RawDemosaicProcessor {
|
||||
profileName = basePlan?.profileName?.let { "$it + $modeName" } ?: modeName,
|
||||
workingColorSpace = basePlan?.workingColorSpace ?: workingColorSpace,
|
||||
baselineExposureOffset = basePlan?.baselineExposureOffset ?: 0f,
|
||||
defaultBlackRender = DcpDefaultBlackRender.Auto,
|
||||
defaultBlackRender = basePlan?.defaultBlackRender ?: DcpDefaultBlackRender.None,
|
||||
supportsOverrange = basePlan?.supportsOverrange ?: false,
|
||||
colorCorrectionMatrix = basePlan?.colorCorrectionMatrix ?: metadata.colorCorrectionMatrix,
|
||||
cameraWhite = basePlan?.cameraWhite ?: metadata.cameraWhite,
|
||||
|
||||
@@ -35,7 +35,7 @@ class CameraPresetJsonCodecTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fromJson_resolvesRawAndMfsrConflict() {
|
||||
fun fromJson_keepsRawAndMfsrCombination() {
|
||||
val preset = CameraPreset.fromJson(
|
||||
"""
|
||||
{
|
||||
@@ -53,7 +53,7 @@ class CameraPresetJsonCodecTest {
|
||||
|
||||
requireNotNull(preset)
|
||||
assertTrue(preset.useRaw)
|
||||
assertFalse(preset.useMFSR)
|
||||
assertTrue(preset.useMFSR)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+3
-3
@@ -17,9 +17,9 @@ class RawSuperResolutionStripePlannerTest {
|
||||
rawHeight = 3000,
|
||||
)
|
||||
|
||||
assertTrue(band.firstRow <= 255)
|
||||
assertTrue(band.endExclusive >= 384)
|
||||
assertTrue(band.rowCount < 150)
|
||||
assertEquals(242, band.firstRow)
|
||||
assertEquals(397, band.endExclusive)
|
||||
assertEquals(155, band.rowCount)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,7 +16,10 @@ class DngHdrProfileGainTableGeneratorTest {
|
||||
@Test
|
||||
fun bimodalPhotonCaptureKeepsAUsableBrightSyntheticExposure() {
|
||||
val fixture = loadFixture(BIMODAL_CAPTURE_RESOURCE)
|
||||
val map = generateMap(fixture)
|
||||
val map = generateMap(
|
||||
fixture = fixture,
|
||||
fusionParameters = DngHdrProfileGainTableGenerator.PHOTON_FUSION_PARAMETERS,
|
||||
)
|
||||
val blackGains = actualAnchorGains(fixture, map, ToneAnchor.BLACK)
|
||||
val medianGains = actualAnchorGains(fixture, map, ToneAnchor.MEDIAN)
|
||||
val medianOutputs = FloatArray(fixture.cellCount) { cell ->
|
||||
@@ -112,6 +115,7 @@ class DngHdrProfileGainTableGeneratorTest {
|
||||
height = fixture.height,
|
||||
baselineExposureEv = fixture.baselineExposureEv,
|
||||
packedCellStats = fixture.packedStats,
|
||||
fusionParameters = DngHdrProfileGainTableGenerator.GOOGLE_FUSION_PARAMETERS,
|
||||
) ?: error("Expected Google PGTM for ${case.name}")
|
||||
listOf(0.25f, 0.50f, 0.75f).mapIndexed { index, tableInput ->
|
||||
val actual = percentile(
|
||||
@@ -167,8 +171,9 @@ class DngHdrProfileGainTableGeneratorTest {
|
||||
else -> MAX_SPATIAL_QUANTILE_GAIN_ERROR_EV
|
||||
}
|
||||
if (errorEv > tolerance) {
|
||||
failures += "${fixture.sourceName} ${anchor.label} p${(percentile * 100).toInt()} " +
|
||||
"expected=$expectedGain actual=$actualGain errorEv=$errorEv toleranceEv=$tolerance"
|
||||
failures += "${fixture.sourceName} ${anchor.label} " +
|
||||
"p${(percentile * 100).toInt()} expected=$expectedGain " +
|
||||
"actual=$actualGain errorEv=$errorEv toleranceEv=$tolerance"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,20 +197,25 @@ class DngHdrProfileGainTableGeneratorTest {
|
||||
val actual = actualAnchorGains(fixture, map, anchor)
|
||||
val rmseEv = logGainRmseEv(actual, expected)
|
||||
if (rmseEv > MAX_PER_CELL_GAIN_RMSE_EV) {
|
||||
failures += "${fixture.sourceName} ${anchor.label} perCellRmseEv=$rmseEv " +
|
||||
"toleranceEv=$MAX_PER_CELL_GAIN_RMSE_EV"
|
||||
failures += "${fixture.sourceName} ${anchor.label} " +
|
||||
"perCellRmseEv=$rmseEv toleranceEv=$MAX_PER_CELL_GAIN_RMSE_EV"
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue(failures.joinToString(separator = "\n"), failures.isEmpty())
|
||||
}
|
||||
|
||||
private fun generateMap(fixture: PgtmFixture): DngProfileGainTableMap {
|
||||
private fun generateMap(
|
||||
fixture: PgtmFixture,
|
||||
fusionParameters: HdrExposureFusionParameters =
|
||||
DngHdrProfileGainTableGenerator.GOOGLE_FUSION_PARAMETERS,
|
||||
): DngProfileGainTableMap {
|
||||
return DngHdrProfileGainTableGenerator.forCellStats(
|
||||
width = fixture.width,
|
||||
height = fixture.height,
|
||||
baselineExposureEv = fixture.baselineExposureEv,
|
||||
packedCellStats = fixture.packedStats
|
||||
packedCellStats = fixture.packedStats,
|
||||
fusionParameters = fusionParameters,
|
||||
) ?: error("Expected PGTM for ${fixture.sourceName}")
|
||||
}
|
||||
|
||||
@@ -344,7 +354,10 @@ class DngHdrProfileGainTableGeneratorTest {
|
||||
private fun logGainRmseEv(actual: FloatArray, expected: FloatArray): Float {
|
||||
require(actual.size == expected.size)
|
||||
val meanSquare = actual.indices.sumOf { index ->
|
||||
val error = log2(actual[index].coerceAtLeast(1e-6f) / expected[index].coerceAtLeast(1e-6f))
|
||||
val error = log2(
|
||||
actual[index].coerceAtLeast(1e-6f) /
|
||||
expected[index].coerceAtLeast(1e-6f)
|
||||
)
|
||||
(error * error).toDouble()
|
||||
} / actual.size.coerceAtLeast(1).toDouble()
|
||||
return sqrt(meanSquare).toFloat()
|
||||
@@ -468,11 +481,11 @@ class DngHdrProfileGainTableGeneratorTest {
|
||||
private const val MAX_MEDIAN_GAIN_ERROR_EV = 0.22f
|
||||
private const val MAX_SPATIAL_QUANTILE_GAIN_ERROR_EV = 0.38f
|
||||
private const val MAX_PER_CELL_GAIN_RMSE_EV = 0.48f
|
||||
|
||||
private val FIXTURE_MAGIC = "PGTFIX2\u0000".toByteArray(Charsets.US_ASCII)
|
||||
private const val BIMODAL_CAPTURE_RESOURCE =
|
||||
"/pgtm/captures/PhotonCamera_20260715_173013.pgtfixture"
|
||||
private val DISTRIBUTION_PERCENTILES = floatArrayOf(0.10f, 0.50f, 0.90f)
|
||||
private val DISTRIBUTION_PERCENTILES =
|
||||
floatArrayOf(0.10f, 0.25f, 0.50f, 0.75f, 0.90f, 0.98f)
|
||||
private val OFFICIAL_INPUT_WEIGHTS = floatArrayOf(0.1495f, 0.2935f, 0.0570f, 0.1250f, 0.3750f)
|
||||
private val FIXTURE_RESOURCES = listOf(
|
||||
"/pgtm/skyyking/Skyyking_20260711_184627.RAW-02.ORIGINAL.pgtfixture",
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.hinnka.mycamera.raw
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import kotlin.math.pow
|
||||
|
||||
class RawProfileExposureGlTest {
|
||||
@Test
|
||||
fun profileGainToneMapKeepsLargeBaselineExposureNormalizationLinear() {
|
||||
val baselineExposureEv = 6.588512f
|
||||
val baselineGain = 2.0f.pow(baselineExposureEv)
|
||||
val sceneInput = 0.5500106f
|
||||
val profileGain = 0.75050706f
|
||||
val preRampValue = sceneInput * profileGain / baselineGain
|
||||
|
||||
val profileGainToneMapRamp = RawProfileExposureGl.compute(
|
||||
profileExposureCompensation = 0f,
|
||||
dngBaselineExposure = baselineExposureEv,
|
||||
defaultBlackRender = DcpDefaultBlackRender.None,
|
||||
useRamp = true,
|
||||
)
|
||||
val autoBlackRamp = RawProfileExposureGl.compute(
|
||||
profileExposureCompensation = 0f,
|
||||
dngBaselineExposure = baselineExposureEv,
|
||||
defaultBlackRender = DcpDefaultBlackRender.Auto,
|
||||
useRamp = true,
|
||||
)
|
||||
|
||||
assertEquals(0f, profileGainToneMapRamp.rampBlack, 0f)
|
||||
assertEquals(
|
||||
sceneInput * profileGain,
|
||||
preRampValue * profileGainToneMapRamp.rampSlope,
|
||||
1e-5f,
|
||||
)
|
||||
assertTrue(
|
||||
"preRampValue=$preRampValue autoBlack=${autoBlackRamp.rampBlack} " +
|
||||
"autoRadius=${autoBlackRamp.rampRadius}",
|
||||
preRampValue <= autoBlackRamp.rampBlack - autoBlackRamp.rampRadius,
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user