feat: photon tone curve optimize
This commit is contained in:
1 parent
4af8ce15bb
commit
e1efd648d3
15 files changed
+169
-58
No files matched your search
@@ -15,7 +15,6 @@ import android.provider.DocumentsContract
|
||||
import android.provider.MediaStore
|
||||
import androidx.core.graphics.createBitmap
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
import com.hinnka.mycamera.BuildConfig
|
||||
import com.hinnka.mycamera.camera.AspectRatio
|
||||
import com.hinnka.mycamera.camera.HdrBracketConfig
|
||||
import com.hinnka.mycamera.data.ContentRepository
|
||||
@@ -3355,7 +3354,7 @@ object GalleryManager {
|
||||
exportDngWithRawExport: Boolean,
|
||||
baselineExposureEv: Float? = null,
|
||||
profileGainTableMap: DngProfileGainTableMap? = null,
|
||||
profileToneMapMode: RawProfileToneMapMode = RawProfileToneMapMode.GooglePixel,
|
||||
profileToneMapMode: RawProfileToneMapMode = RawProfileToneMapMode.Photon,
|
||||
imageLayout: SuperResolutionDngWriter.ImageLayout = SuperResolutionDngWriter.ImageLayout.CFA,
|
||||
compression: SuperResolutionDngWriter.Compression = SuperResolutionDngWriter.Compression.UNCOMPRESSED,
|
||||
inputRowStepSamples: Int? = null,
|
||||
@@ -3550,22 +3549,19 @@ object GalleryManager {
|
||||
}
|
||||
|
||||
private fun rawHdrPgtmModeForMetadata(metadata: MediaMetadata): RawProfileToneMapMode {
|
||||
return when (metadata.rawToneMappingParameters.normalized().profileToneMapMode) {
|
||||
RawProfileToneMapMode.PhotonPgtm -> RawProfileToneMapMode.PhotonPgtm
|
||||
else -> RawProfileToneMapMode.GooglePixel
|
||||
}
|
||||
return RawProfileToneMapMode.Photon
|
||||
}
|
||||
|
||||
private fun profileNameForPgtmMode(mode: RawProfileToneMapMode): String {
|
||||
return when (mode) {
|
||||
RawProfileToneMapMode.PhotonPgtm -> DngProfileToneCurve.PHOTON_PGTM_PROFILE_NAME
|
||||
RawProfileToneMapMode.Photon -> DngProfileToneCurve.PHOTON_PGTM_PROFILE_NAME
|
||||
else -> DngProfileToneCurve.GOOGLE_HDR_PROFILE_NAME
|
||||
}
|
||||
}
|
||||
|
||||
private fun profileToneCurveForPgtmMode(mode: RawProfileToneMapMode): FloatArray {
|
||||
return when (mode) {
|
||||
RawProfileToneMapMode.PhotonPgtm -> DngProfileToneCurve.photonPgtmToneCurvePoints()
|
||||
RawProfileToneMapMode.Photon -> DngProfileToneCurve.photonPgtmToneCurvePoints()
|
||||
else -> DngProfileToneCurve.googleHdrToneCurvePoints()
|
||||
}
|
||||
}
|
||||
@@ -4641,6 +4637,7 @@ object GalleryManager {
|
||||
rawRenderingEngine = updatedMetadata?.rawRenderingEngine ?: MediaMetadata().rawRenderingEngine,
|
||||
rawToneMappingParameters = updatedMetadata?.rawToneMappingParameters ?: MediaMetadata().rawToneMappingParameters,
|
||||
rawCfaCorrectionMode = updatedMetadata?.rawCfaCorrectionMode,
|
||||
useEmbeddedPreviewForAutoExposure = false,
|
||||
rawBlackBorderCrop = rawMetadata.rawBlackBorderCrop,
|
||||
spectralFilmStock = updatedMetadata?.spectralFilmStock,
|
||||
spectralFilmPrint = updatedMetadata?.spectralFilmPrint,
|
||||
|
||||
@@ -38,7 +38,7 @@ class GlesRawStacker(
|
||||
private val lensShadingHeight: Int,
|
||||
colorCorrectionMatrix: FloatArray? = null,
|
||||
pgtmStatsBounds: Rect? = null,
|
||||
private val profileToneMapMode: RawProfileToneMapMode = RawProfileToneMapMode.GooglePixel,
|
||||
private val profileToneMapMode: RawProfileToneMapMode = RawProfileToneMapMode.Photon,
|
||||
private val tuning: RawStackTuningProfile = RawStackTuningResolver.resolve(RawStackMode.MFNR),
|
||||
debugConfig: RawStackDebugConfig = RawStackDebugConfig.Disabled,
|
||||
) {
|
||||
@@ -1125,7 +1125,7 @@ class GlesRawStacker(
|
||||
return null
|
||||
}
|
||||
if (profileToneMapMode != RawProfileToneMapMode.GooglePixel &&
|
||||
profileToneMapMode != RawProfileToneMapMode.PhotonPgtm
|
||||
profileToneMapMode != RawProfileToneMapMode.Photon
|
||||
) {
|
||||
return null
|
||||
}
|
||||
@@ -1201,7 +1201,7 @@ class GlesRawStacker(
|
||||
}
|
||||
val diagnosticBand = DngPgtmDiagnostic.activeBandForSource("$TAG GPU stacker")
|
||||
when (profileToneMapMode) {
|
||||
RawProfileToneMapMode.PhotonPgtm -> DngPhotonProfileGainTableGenerator.forCellStats(
|
||||
RawProfileToneMapMode.Photon -> DngPhotonProfileGainTableGenerator.forCellStats(
|
||||
width = width,
|
||||
height = height,
|
||||
baselineExposureEv = baselineExposureEv,
|
||||
|
||||
@@ -235,7 +235,7 @@ object MultiFrameStacker {
|
||||
applyLensShadingCorrection: Boolean = true,
|
||||
colorCorrectionMatrix: FloatArray? = null,
|
||||
pgtmStatsBounds: Rect? = null,
|
||||
profileToneMapMode: RawProfileToneMapMode = RawProfileToneMapMode.GooglePixel,
|
||||
profileToneMapMode: RawProfileToneMapMode = RawProfileToneMapMode.Photon,
|
||||
): RawStackResult? {
|
||||
if (normalFrames.isEmpty()) {
|
||||
shortFrame.image.close()
|
||||
|
||||
@@ -98,7 +98,7 @@ internal object DngEmbeddedProfile {
|
||||
fun hasPhotonPgtmProfile(file: File): Boolean {
|
||||
val profile = readFrom(file) ?: return false
|
||||
return isPhotonPgtmProfileName(profile.profileName) &&
|
||||
DngProfileToneCurve.isLinearToneCurve(profile.toneCurve)
|
||||
DngProfileToneCurve.isPhotonPgtmToneCurve(profile.toneCurve)
|
||||
}
|
||||
|
||||
fun hasGoogleHdrToneCurve(file: File): Boolean {
|
||||
@@ -111,8 +111,14 @@ internal object DngEmbeddedProfile {
|
||||
}
|
||||
|
||||
fun isPhotonPgtmProfileName(profileName: String?): Boolean {
|
||||
return profileName?.contains("photon", ignoreCase = true) == true &&
|
||||
profileName.contains("pgtm", ignoreCase = true)
|
||||
val normalizedName = profileName?.trim()?.takeIf { it.isNotEmpty() } ?: return false
|
||||
return normalizedName.equals(
|
||||
DngProfileToneCurve.PHOTON_PGTM_PROFILE_NAME,
|
||||
ignoreCase = true
|
||||
) || (
|
||||
normalizedName.contains("photon", ignoreCase = true) &&
|
||||
normalizedName.contains("pgtm", ignoreCase = true)
|
||||
)
|
||||
}
|
||||
|
||||
private fun decodeProfile(
|
||||
|
||||
@@ -16,18 +16,20 @@ internal object DngPgtmDebugRewriter {
|
||||
private const val TIFF_CLASSIC_MAGIC = 42
|
||||
private const val TYPE_BYTE = 1
|
||||
private const val TYPE_ASCII = 2
|
||||
private const val TYPE_LONG = 4
|
||||
private const val TYPE_FLOAT = 11
|
||||
private const val TYPE_UNDEFINED = 7
|
||||
|
||||
private const val TAG_DNG_VERSION = 50706
|
||||
private const val TAG_PROFILE_NAME = 50936
|
||||
private const val TAG_PROFILE_TONE_CURVE = 50940
|
||||
private const val TAG_DEFAULT_BLACK_RENDER = 51110
|
||||
private const val TAG_PROFILE_GAIN_TABLE_MAP_2 = DngProfileGainTableMap.TAG_PROFILE_GAIN_TABLE_MAP2
|
||||
|
||||
fun rewriteGeneratedPgtmOnRawRefreshIfEnabled(
|
||||
dngFile: File?,
|
||||
profileGainTableMap: DngProfileGainTableMap?,
|
||||
profileToneMapMode: RawProfileToneMapMode = RawProfileToneMapMode.GooglePixel,
|
||||
profileToneMapMode: RawProfileToneMapMode = RawProfileToneMapMode.Photon,
|
||||
): Boolean {
|
||||
if (!BuildConfig.DEBUG || !REWRITE_GENERATED_PGTM_ON_RAW_REFRESH) return false
|
||||
val file = dngFile ?: return false
|
||||
@@ -38,7 +40,7 @@ internal object DngPgtmDebugRewriter {
|
||||
fun rewriteProfileGainTableMap2(
|
||||
dngFile: File,
|
||||
profileGainTableMap: DngProfileGainTableMap,
|
||||
profileToneMapMode: RawProfileToneMapMode = RawProfileToneMapMode.GooglePixel,
|
||||
profileToneMapMode: RawProfileToneMapMode = RawProfileToneMapMode.Photon,
|
||||
): Boolean {
|
||||
if (!BuildConfig.DEBUG) return false
|
||||
if (!profileGainTableMap.isValid || !dngFile.exists() || dngFile.length() < 16L) {
|
||||
@@ -80,6 +82,12 @@ internal object DngPgtmDebugRewriter {
|
||||
byteOrder = byteOrder
|
||||
)
|
||||
),
|
||||
TiffValue(
|
||||
tag = TAG_DEFAULT_BLACK_RENDER,
|
||||
type = TYPE_LONG,
|
||||
count = 1,
|
||||
bytes = uintBytes(0, byteOrder)
|
||||
),
|
||||
TiffValue(
|
||||
tag = TAG_PROFILE_GAIN_TABLE_MAP_2,
|
||||
type = TYPE_UNDEFINED,
|
||||
@@ -124,14 +132,14 @@ internal object DngPgtmDebugRewriter {
|
||||
|
||||
private fun profileNameForToneMapMode(mode: RawProfileToneMapMode): String {
|
||||
return when (mode) {
|
||||
RawProfileToneMapMode.PhotonPgtm -> DngProfileToneCurve.PHOTON_PGTM_PROFILE_NAME
|
||||
RawProfileToneMapMode.Photon -> DngProfileToneCurve.PHOTON_PGTM_PROFILE_NAME
|
||||
else -> DngProfileToneCurve.GOOGLE_HDR_PROFILE_NAME
|
||||
}
|
||||
}
|
||||
|
||||
private fun profileToneCurveForToneMapMode(mode: RawProfileToneMapMode): FloatArray {
|
||||
return when (mode) {
|
||||
RawProfileToneMapMode.PhotonPgtm -> DngProfileToneCurve.photonPgtmToneCurvePoints()
|
||||
RawProfileToneMapMode.Photon -> DngProfileToneCurve.photonPgtmToneCurvePoints()
|
||||
else -> DngProfileToneCurve.googleHdrToneCurvePoints()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ internal object DngPhotonProfileGainTableGenerator {
|
||||
private const val MID_GRAY_INPUT = 0.18f
|
||||
private const val DEFAULT_MID_GRAY_LIFT_EV = 1.10f
|
||||
private const val MAX_LOCAL_MICRO_CONTRAST = 0.045f
|
||||
private const val MAX_ADAPTIVE_SHADOW_LIFT_EV = 1.05f
|
||||
|
||||
private val BASE_INPUT_WEIGHTS = floatArrayOf(
|
||||
DngHdrProfileGainTableGenerator.BASE_INPUT_WEIGHT_RED,
|
||||
@@ -38,6 +39,7 @@ internal object DngPhotonProfileGainTableGenerator {
|
||||
packedCellStats: FloatArray,
|
||||
tablePointCount: Int = DEFAULT_TABLE_POINTS,
|
||||
diagnosticBand: DngHdrProfileGainTableGenerator.DiagnosticBand? = null,
|
||||
emitDiagnostics: Boolean = true,
|
||||
): DngProfileGainTableMap? {
|
||||
if (width <= 0 || height <= 0 || !baselineExposureEv.isFinite() || baselineExposureEv < MIN_BASELINE_EV) {
|
||||
return null
|
||||
@@ -97,12 +99,14 @@ internal object DngPhotonProfileGainTableGenerator {
|
||||
gains = gains,
|
||||
sourceTag = DngProfileGainTableMap.TAG_PROFILE_GAIN_TABLE_MAP2
|
||||
)
|
||||
PLog.d(
|
||||
TAG,
|
||||
"Built Photon PGTM: grid=${gridWidth}x${gridHeight}x$safePointCount " +
|
||||
"baselineEv=$safeBaselineEv sceneMax=$sceneMax inputScale=$inputScale " +
|
||||
"p98=${global.p98} tail99=${global.tailP99} max=${global.maxInput}"
|
||||
)
|
||||
if (emitDiagnostics) {
|
||||
PLog.d(
|
||||
TAG,
|
||||
"Built Photon PGTM: grid=${gridWidth}x${gridHeight}x$safePointCount " +
|
||||
"baselineEv=$safeBaselineEv sceneMax=$sceneMax inputScale=$inputScale " +
|
||||
"p98=${global.p98} tail99=${global.tailP99} max=${global.maxInput}"
|
||||
)
|
||||
}
|
||||
return DngHdrProfileGainTableGenerator.withDiagnosticBand(map, diagnosticBand)
|
||||
}
|
||||
|
||||
@@ -215,16 +219,21 @@ internal object DngPhotonProfileGainTableGenerator {
|
||||
val sparseOutlier = smoothStep(0.45f, 1.25f, outlierGapEv) *
|
||||
(1f - smoothStep(0.16f, 0.32f, highlightDensity))
|
||||
val denseHighlight = smoothStep(0.12f, 0.30f, highlightDensity)
|
||||
// The upper percentile is not the desired white point. Leaving roughly half
|
||||
// a stop above it is important in HDR scenes: otherwise most of the curve is
|
||||
// spent compressing ordinary highlights and the shoulder becomes needlessly flat.
|
||||
val percentileHeadroom = lerp(1.62f, 1.38f, denseHighlight)
|
||||
val percentileTarget = max(
|
||||
1f,
|
||||
lerp(tailP95 * 1.03f, tailP99 * 0.96f, 0.45f + 0.35f * denseHighlight)
|
||||
lerp(tailP95, tailP99, 0.68f + 0.20f * denseHighlight) * percentileHeadroom
|
||||
)
|
||||
val outlierTarget = lerp(
|
||||
percentileTarget,
|
||||
min(maxInput, max(percentileTarget, tailP99 * 1.24f)),
|
||||
sparseOutlier * 0.42f
|
||||
)
|
||||
return lerp(MIN_SCENE_MAX, outlierTarget, hdrStrength)
|
||||
val headroomStrength = smoothStep(0.15f, 0.65f, hdrStrength)
|
||||
return lerp(MIN_SCENE_MAX, outlierTarget, headroomStrength)
|
||||
.coerceIn(MIN_SCENE_MAX, MAX_SCENE_MAX)
|
||||
}
|
||||
|
||||
@@ -348,10 +357,12 @@ internal object DngPhotonProfileGainTableGenerator {
|
||||
): Float {
|
||||
val x = sceneLinear.coerceIn(0f, MID_GRAY_INPUT)
|
||||
if (x <= 0f || x >= MID_GRAY_INPUT) return baseOutput
|
||||
val shadowWindow = smoothStep(0.010f, 0.036f, x) *
|
||||
(1f - smoothStep(0.135f, MID_GRAY_INPUT, x))
|
||||
val adaptiveLift = photonAdaptiveShadowLiftStrength(sceneMax, global, local)
|
||||
return baseOutput * (1f + adaptiveLift * shadowWindow)
|
||||
// Keep a finite toe gain all the way to black. A lower smooth-step here used
|
||||
// to turn the lift off for the darkest (and most numerous) samples. Fade the
|
||||
// extra exposure into the mid-gray slope instead of adding a small gain bump.
|
||||
val shadowWindow = 1f - smoothStep(0.045f, MID_GRAY_INPUT, x)
|
||||
val adaptiveLiftEv = photonAdaptiveShadowLiftEv(sceneMax, global, local)
|
||||
return baseOutput * 2.0f.pow(adaptiveLiftEv * shadowWindow)
|
||||
}
|
||||
|
||||
private fun photonLocalMicroContrastOutput(
|
||||
@@ -376,15 +387,21 @@ internal object DngPhotonProfileGainTableGenerator {
|
||||
return adjusted.coerceIn(0f, 1f)
|
||||
}
|
||||
|
||||
private fun photonAdaptiveShadowLiftStrength(
|
||||
private fun photonAdaptiveShadowLiftEv(
|
||||
sceneMax: Float,
|
||||
global: PhotonPgtmCellStats,
|
||||
local: PhotonPgtmCellStats,
|
||||
): Float {
|
||||
val globalRangeEv = log2((global.p98 + 0.008f) / (global.p10 + 0.008f))
|
||||
.coerceIn(0f, 10f)
|
||||
val highDynamicRange = smoothStep(3.2f, 5.8f, globalRangeEv) *
|
||||
smoothStep(1.10f, 1.80f, sceneMax)
|
||||
// p98 is histogram-clamped and can substantially under-report a sparse HDR
|
||||
// tail. Include the unclamped tail percentile used to choose sceneMax.
|
||||
val tailRangeEv = log2((global.tailP99 + 0.04f) / (global.p50 + 0.04f))
|
||||
.coerceIn(0f, 8f)
|
||||
val highDynamicRange = max(
|
||||
smoothStep(2.5f, 5.2f, globalRangeEv),
|
||||
smoothStep(1.8f, 3.8f, tailRangeEv)
|
||||
) * smoothStep(1.15f, 2.10f, sceneMax)
|
||||
val globalDarkArea = max(
|
||||
1f - smoothStep(0.075f, 0.165f, global.p50),
|
||||
0.75f * (1f - smoothStep(0.24f, 0.50f, global.p90))
|
||||
@@ -393,10 +410,10 @@ internal object DngPhotonProfileGainTableGenerator {
|
||||
1f - smoothStep(0.060f, 0.150f, local.p50),
|
||||
0.60f * (1f - smoothStep(0.20f, 0.45f, local.p90))
|
||||
)
|
||||
val darkSceneLift = highDynamicRange * globalDarkArea.coerceIn(0f, 1f)
|
||||
val darkCellLift = darkSceneLift * localDarkArea.coerceIn(0f, 1f)
|
||||
return (0.068f * darkSceneLift + 0.022f * darkCellLift)
|
||||
.coerceIn(0f, 0.090f)
|
||||
val globalDarkness = globalDarkArea.coerceIn(0f, 1f)
|
||||
val localDarkness = localDarkArea.coerceIn(0f, 1f)
|
||||
return (highDynamicRange * (0.62f + 0.28f * globalDarkness + 0.18f * localDarkness))
|
||||
.coerceIn(0f, MAX_ADAPTIVE_SHADOW_LIFT_EV)
|
||||
}
|
||||
|
||||
private fun photonPgtmInputWeights(inputScale: Float): FloatArray {
|
||||
|
||||
@@ -914,6 +914,7 @@ class RawDemosaicProcessor {
|
||||
rawToneMappingParameters: RawToneMappingParameters = RawToneMappingParameters.DEFAULT,
|
||||
rawCfaCorrectionMode: String? = null,
|
||||
capturePreviewThumbnail: Bitmap? = null,
|
||||
useEmbeddedPreviewForAutoExposure: Boolean = true,
|
||||
rawBlackBorderCrop: RawBlackBorderCrop = RawBlackBorderCrop(),
|
||||
onRawAutoAdjustments: ((RawAutoAdjustments) -> Unit)? = null,
|
||||
onMetadata: ((RawMetadata) -> Unit)? = null
|
||||
@@ -955,6 +956,7 @@ class RawDemosaicProcessor {
|
||||
rawToneMappingParameters = rawToneMappingParameters,
|
||||
rawCfaCorrectionMode = rawCfaCorrectionMode,
|
||||
capturePreviewThumbnail = capturePreviewThumbnail,
|
||||
useEmbeddedPreviewForAutoExposure = useEmbeddedPreviewForAutoExposure,
|
||||
rawBlackBorderCrop = rawBlackBorderCrop,
|
||||
dngFile = dngFile,
|
||||
onRawAutoAdjustments = onRawAutoAdjustments,
|
||||
@@ -1167,6 +1169,7 @@ class RawDemosaicProcessor {
|
||||
rawToneMappingParameters: RawToneMappingParameters = RawToneMappingParameters.DEFAULT,
|
||||
rawCfaCorrectionMode: String? = null,
|
||||
capturePreviewThumbnail: Bitmap? = null,
|
||||
useEmbeddedPreviewForAutoExposure: Boolean = true,
|
||||
rawBlackBorderCrop: RawBlackBorderCrop = RawBlackBorderCrop(),
|
||||
onRawAutoAdjustments: ((RawAutoAdjustments) -> Unit)? = null,
|
||||
onMetadata: ((RawMetadata) -> Unit)? = null
|
||||
@@ -1208,6 +1211,7 @@ class RawDemosaicProcessor {
|
||||
rawToneMappingParameters = rawToneMappingParameters,
|
||||
rawCfaCorrectionMode = rawCfaCorrectionMode,
|
||||
capturePreviewThumbnail = capturePreviewThumbnail,
|
||||
useEmbeddedPreviewForAutoExposure = useEmbeddedPreviewForAutoExposure,
|
||||
rawBlackBorderCrop = rawBlackBorderCrop,
|
||||
dngFile = dngFile,
|
||||
onRawAutoAdjustments = onRawAutoAdjustments,
|
||||
@@ -1258,6 +1262,7 @@ class RawDemosaicProcessor {
|
||||
rawToneMappingParameters: RawToneMappingParameters = RawToneMappingParameters.DEFAULT,
|
||||
rawCfaCorrectionMode: String? = null,
|
||||
capturePreviewThumbnail: Bitmap? = null,
|
||||
useEmbeddedPreviewForAutoExposure: Boolean = true,
|
||||
rawBlackBorderCrop: RawBlackBorderCrop = RawBlackBorderCrop(),
|
||||
dngFile: File? = null,
|
||||
onRawAutoAdjustments: ((RawAutoAdjustments) -> Unit)? = null,
|
||||
@@ -1419,8 +1424,9 @@ class RawDemosaicProcessor {
|
||||
metadataDefaultCrop = effectiveDefaultCrop
|
||||
)
|
||||
val rawOutputBounds = outputSourceBounds.toOutputBounds(actualRotation)
|
||||
val autoExposurePreview = capturePreviewThumbnail ?: embeddedDngJpegPreview
|
||||
if (capturePreviewThumbnail == null && embeddedDngJpegPreview != null) {
|
||||
val autoExposurePreview = capturePreviewThumbnail
|
||||
?: embeddedDngJpegPreview.takeIf { useEmbeddedPreviewForAutoExposure }
|
||||
if (capturePreviewThumbnail == null && autoExposurePreview != null) {
|
||||
PLog.d(TAG, "Using embedded DNG JPEG preview for RAW auto exposure")
|
||||
}
|
||||
val rawAeContentBounds = resolveRawAeContentBounds(
|
||||
@@ -1440,7 +1446,7 @@ class RawDemosaicProcessor {
|
||||
embeddedProfileToneCurveLut != null &&
|
||||
DngProfileToneCurve.isPhotonPgtmToneCurveLut(embeddedProfileToneCurveLut) &&
|
||||
DngEmbeddedProfile.isPhotonPgtmProfileName(embeddedDngProfileName) -> {
|
||||
RawProfileToneMapMode.PhotonPgtm
|
||||
RawProfileToneMapMode.Photon
|
||||
}
|
||||
|
||||
else -> RawProfileToneMapMode.Default
|
||||
@@ -1459,11 +1465,11 @@ class RawDemosaicProcessor {
|
||||
normalizedToneMappingParameters.useOppoMasterToneMap
|
||||
val requestedProfileToneMapMode = when {
|
||||
googlePixelToneMapRequested -> RawProfileToneMapMode.GooglePixel
|
||||
photonPgtmToneMapRequested -> RawProfileToneMapMode.PhotonPgtm
|
||||
photonPgtmToneMapRequested -> RawProfileToneMapMode.Photon
|
||||
else -> RawProfileToneMapMode.Default
|
||||
}
|
||||
val profileGainToneMapRequested = requestedProfileToneMapMode == RawProfileToneMapMode.GooglePixel ||
|
||||
requestedProfileToneMapMode == RawProfileToneMapMode.PhotonPgtm
|
||||
requestedProfileToneMapMode == RawProfileToneMapMode.Photon
|
||||
val embeddedDngHdrToneMapDisabledByUser = embeddedDngHdrToneMapAvailable &&
|
||||
useAdobeProfilePipeline &&
|
||||
!oppoMasterToneMapRequested &&
|
||||
@@ -7209,18 +7215,18 @@ class RawDemosaicProcessor {
|
||||
preferredToneCurveLut: FloatArray? = null,
|
||||
): DcpRenderPlan {
|
||||
val toneCurve = preferredToneCurveLut?.copyOf() ?: when (mode) {
|
||||
RawProfileToneMapMode.PhotonPgtm -> DngProfileToneCurve.photonPgtmToneCurveLut()
|
||||
RawProfileToneMapMode.Photon -> DngProfileToneCurve.photonPgtmToneCurveLut()
|
||||
else -> DngProfileToneCurve.googleHdrToneCurveLut()
|
||||
}
|
||||
val modeName = when (mode) {
|
||||
RawProfileToneMapMode.PhotonPgtm -> DngProfileToneCurve.PHOTON_PGTM_PROFILE_NAME
|
||||
RawProfileToneMapMode.Photon -> DngProfileToneCurve.PHOTON_PGTM_PROFILE_NAME
|
||||
else -> "Google Pixel Tone Map"
|
||||
}
|
||||
return DcpRenderPlan(
|
||||
profileName = basePlan?.profileName?.let { "$it + $modeName" } ?: modeName,
|
||||
workingColorSpace = basePlan?.workingColorSpace ?: workingColorSpace,
|
||||
baselineExposureOffset = basePlan?.baselineExposureOffset ?: 0f,
|
||||
defaultBlackRender = DcpDefaultBlackRender.None,
|
||||
defaultBlackRender = DcpDefaultBlackRender.Auto,
|
||||
colorCorrectionMatrix = basePlan?.colorCorrectionMatrix ?: metadata.colorCorrectionMatrix,
|
||||
cameraWhite = basePlan?.cameraWhite ?: metadata.cameraWhite,
|
||||
hueSatMap = basePlan?.hueSatMap,
|
||||
|
||||
@@ -6,7 +6,6 @@ import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import kotlin.math.ceil
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
internal object RawProfileGainTableMapBuilder {
|
||||
private const val TAG = "RawProfileGainTableMapBuilder"
|
||||
@@ -21,7 +20,7 @@ internal object RawProfileGainTableMapBuilder {
|
||||
metadata: RawMetadata,
|
||||
samplesPerPixel: Int = 1,
|
||||
statsBounds: Rect? = null,
|
||||
profileToneMapMode: RawProfileToneMapMode = RawProfileToneMapMode.GooglePixel,
|
||||
profileToneMapMode: RawProfileToneMapMode = RawProfileToneMapMode.Photon,
|
||||
): DngProfileGainTableMap? {
|
||||
val stats = buildPackedCellStats(
|
||||
rawData = rawData,
|
||||
@@ -43,7 +42,7 @@ internal object RawProfileGainTableMapBuilder {
|
||||
diagnosticBand = diagnosticBand
|
||||
)
|
||||
|
||||
RawProfileToneMapMode.PhotonPgtm -> DngPhotonProfileGainTableGenerator.forCellStats(
|
||||
RawProfileToneMapMode.Photon -> DngPhotonProfileGainTableGenerator.forCellStats(
|
||||
width = width,
|
||||
height = height,
|
||||
baselineExposureEv = baselineExposureEv,
|
||||
|
||||
@@ -14,7 +14,7 @@ data class RawToneMappingParameters(
|
||||
val profileToneMapMode: RawProfileToneMapMode
|
||||
get() = when {
|
||||
useOppoMasterToneMap -> RawProfileToneMapMode.OppoMaster
|
||||
usePhotonPgtmToneMap -> RawProfileToneMapMode.PhotonPgtm
|
||||
usePhotonPgtmToneMap -> RawProfileToneMapMode.Photon
|
||||
useGooglePixelToneMap -> RawProfileToneMapMode.GooglePixel
|
||||
else -> RawProfileToneMapMode.Default
|
||||
}
|
||||
@@ -80,7 +80,7 @@ data class RawToneMappingParameters(
|
||||
return copy(
|
||||
useGooglePixelToneMap = mode == RawProfileToneMapMode.GooglePixel,
|
||||
useOppoMasterToneMap = mode == RawProfileToneMapMode.OppoMaster,
|
||||
usePhotonPgtmToneMap = mode == RawProfileToneMapMode.PhotonPgtm
|
||||
usePhotonPgtmToneMap = mode == RawProfileToneMapMode.Photon
|
||||
).normalized()
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ data class RawToneMappingParameters(
|
||||
|
||||
enum class RawProfileToneMapMode {
|
||||
Default,
|
||||
Photon,
|
||||
OppoMaster,
|
||||
GooglePixel,
|
||||
PhotonPgtm,
|
||||
}
|
||||
@@ -475,7 +475,7 @@ private fun RawProfileToneMapSwitches(
|
||||
description = stringResource(R.string.settings_raw_profile_tone_map_description),
|
||||
levels = listOf(
|
||||
RawProfileToneMapMode.Default.name to stringResource(R.string.settings_raw_profile_tone_map_default),
|
||||
RawProfileToneMapMode.PhotonPgtm.name to stringResource(R.string.settings_raw_profile_tone_map_photon_pgtm),
|
||||
RawProfileToneMapMode.Photon.name to stringResource(R.string.settings_raw_profile_tone_map_photon_pgtm),
|
||||
RawProfileToneMapMode.OppoMaster.name to stringResource(R.string.settings_raw_profile_tone_map_oppo_master),
|
||||
RawProfileToneMapMode.GooglePixel.name to stringResource(R.string.settings_raw_profile_tone_map_google_pixel),
|
||||
),
|
||||
|
||||
@@ -444,13 +444,13 @@ fun PresetEditorScreen(
|
||||
|
||||
val toneMapLabels = mapOf(
|
||||
RawProfileToneMapMode.Default to stringResource(R.string.settings_raw_profile_tone_map_default),
|
||||
RawProfileToneMapMode.PhotonPgtm to stringResource(R.string.settings_raw_profile_tone_map_photon_pgtm),
|
||||
RawProfileToneMapMode.Photon to stringResource(R.string.settings_raw_profile_tone_map_photon_pgtm),
|
||||
RawProfileToneMapMode.OppoMaster to stringResource(R.string.settings_raw_profile_tone_map_oppo_master),
|
||||
RawProfileToneMapMode.GooglePixel to stringResource(R.string.settings_raw_profile_tone_map_google_pixel),
|
||||
)
|
||||
val selectedToneMapMode = when {
|
||||
rawOppoMasterToneMap -> RawProfileToneMapMode.OppoMaster
|
||||
rawPhotonPgtmToneMap -> RawProfileToneMapMode.PhotonPgtm
|
||||
rawPhotonPgtmToneMap -> RawProfileToneMapMode.Photon
|
||||
rawGooglePixelToneMap -> RawProfileToneMapMode.GooglePixel
|
||||
else -> RawProfileToneMapMode.Default
|
||||
}
|
||||
@@ -468,7 +468,7 @@ fun PresetEditorScreen(
|
||||
?: RawProfileToneMapMode.Default
|
||||
rawGooglePixelToneMap = selectedMode == RawProfileToneMapMode.GooglePixel
|
||||
rawOppoMasterToneMap = selectedMode == RawProfileToneMapMode.OppoMaster
|
||||
rawPhotonPgtmToneMap = selectedMode == RawProfileToneMapMode.PhotonPgtm
|
||||
rawPhotonPgtmToneMap = selectedMode == RawProfileToneMapMode.Photon
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -410,7 +410,9 @@ object SuperResolutionDngWriter {
|
||||
calibrationMatrix2?.let { add(sRationalArray(TAG_CAMERA_CALIBRATION_2, colorTransformToExactDngMatrix(it))) }
|
||||
}
|
||||
add(rationalArray(TAG_AS_SHOT_NEUTRAL, asShotNeutral(captureResult)))
|
||||
if (!isCfa) {
|
||||
if (profileGainTableMap != null) {
|
||||
add(long(TAG_DEFAULT_BLACK_RENDER, 0))
|
||||
} else if (!isCfa) {
|
||||
add(long(TAG_DEFAULT_BLACK_RENDER, 1))
|
||||
}
|
||||
add(sRationalArray(TAG_BASELINE_EXPOSURE, listOf(resolvedBaselineExposureEv.toDouble())))
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.hinnka.mycamera.raw
|
||||
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class DngEmbeddedProfileTest {
|
||||
@Test
|
||||
fun canonicalPhotonHdrProfileNameIsRecognized() {
|
||||
assertTrue(
|
||||
DngEmbeddedProfile.isPhotonPgtmProfileName(
|
||||
DngProfileToneCurve.PHOTON_PGTM_PROFILE_NAME
|
||||
)
|
||||
)
|
||||
assertTrue(DngEmbeddedProfile.isPhotonPgtmProfileName("Photon PGTM"))
|
||||
assertFalse(DngEmbeddedProfile.isPhotonPgtmProfileName("Google Embedded Camera Profile"))
|
||||
assertFalse(DngEmbeddedProfile.isPhotonPgtmProfileName(null))
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ class DngPgtmDebugRewriterTest {
|
||||
assertEquals(map.mapPointsN, decoded?.mapPointsN)
|
||||
assertEquals(map.gains[0], decoded?.gains?.get(0) ?: 0f, 0f)
|
||||
assertEquals(map.gains[1], decoded?.gains?.get(1) ?: 0f, 0f)
|
||||
assertTrue(DngEmbeddedProfile.hasGoogleHdrToneCurve(file))
|
||||
assertTrue(DngEmbeddedProfile.hasPhotonPgtmProfile(file))
|
||||
} finally {
|
||||
file.delete()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.hinnka.mycamera.raw
|
||||
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import kotlin.math.floor
|
||||
|
||||
class DngPhotonProfileGainTableGeneratorTest {
|
||||
@Test
|
||||
fun sparseHdrTailKeepsHeadroomAndOpensDeepShadows() {
|
||||
val width = 2800
|
||||
val height = 2102
|
||||
val grid = DngHdrProfileGainTableGenerator.gridSizeFor(width, height)
|
||||
val cellCount = grid[0] * grid[1]
|
||||
val stats = FloatArray(cellCount * DngHdrProfileGainTableGenerator.CELL_STATS_FLOAT_STRIDE)
|
||||
repeat(cellCount) { cell ->
|
||||
val offset = cell * DngHdrProfileGainTableGenerator.CELL_STATS_FLOAT_STRIDE
|
||||
stats[offset] = 0.045098f
|
||||
stats[offset + 1] = 0.113744f
|
||||
stats[offset + 2] = 0.243189f
|
||||
stats[offset + 3] = 0.277654f
|
||||
stats[offset + 4] = 0.023916f
|
||||
stats[offset + 5] = 64f
|
||||
stats[offset + 6] = 1.290788f
|
||||
stats[offset + 7] = 1.469952f
|
||||
}
|
||||
|
||||
val map = DngPhotonProfileGainTableGenerator.forCellStats(
|
||||
width = width,
|
||||
height = height,
|
||||
baselineExposureEv = 0.64f,
|
||||
packedCellStats = stats,
|
||||
emitDiagnostics = false
|
||||
) ?: error("Expected Photon PGTM")
|
||||
|
||||
val inputScale = map.mapInputWeights.sum()
|
||||
val deepShadowGain = medianGain(map, tableInput = 0.01f)
|
||||
val upperShadowGain = medianGain(map, tableInput = 0.08f)
|
||||
|
||||
assertTrue("inputScale=$inputScale", inputScale in 0.40f..0.50f)
|
||||
assertTrue("deepShadowGain=$deepShadowGain", deepShadowGain in 3.45f..4.55f)
|
||||
assertTrue("upperShadowGain=$upperShadowGain", upperShadowGain in 2.05f..3.15f)
|
||||
assertTrue("shadow curve must taper", deepShadowGain > upperShadowGain * 1.25f)
|
||||
}
|
||||
|
||||
private fun medianGain(map: DngProfileGainTableMap, tableInput: Float): Float {
|
||||
val values = FloatArray(map.mapPointsH * map.mapPointsV) { cell ->
|
||||
val position = tableInput.coerceIn(0f, 1f) * map.mapPointsN
|
||||
val i0 = floor(position).toInt().coerceIn(0, map.mapPointsN - 1)
|
||||
val i1 = (i0 + 1).coerceAtMost(map.mapPointsN - 1)
|
||||
val fraction = position - i0
|
||||
val offset = cell * map.mapPointsN
|
||||
map.gains[offset + i0] * (1f - fraction) + map.gains[offset + i1] * fraction
|
||||
}
|
||||
values.sort()
|
||||
return values[values.size / 2]
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user