feat: photon pgtm
This commit is contained in:
1 parent
a9b078e3a4
commit
436aace1dc
28 files changed
+855
-73
No files matched your search
@@ -296,6 +296,7 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
private val RAW_FILMIC_WHITE_RELATIVE_EXPOSURE_KEY = floatPreferencesKey("raw_filmic_white_relative_exposure")
|
||||
private val RAW_GOOGLE_PIXEL_TONE_MAP_KEY = booleanPreferencesKey("raw_google_pixel_tone_map")
|
||||
private val RAW_OPPO_MASTER_TONE_MAP_KEY = booleanPreferencesKey("raw_oppo_master_tone_map")
|
||||
private val RAW_PHOTON_PGTM_TONE_MAP_KEY = booleanPreferencesKey("raw_photon_pgtm_tone_map")
|
||||
private val RAW_NLM_NOISE_FACTOR_KEY = floatPreferencesKey("raw_nlm_noise_factor")
|
||||
private val RAW_EXPOSURE_COMPENSATION_KEY = floatPreferencesKey("raw_exposure_compensation")
|
||||
private val RAW_AUTO_EXPOSURE_KEY = booleanPreferencesKey("raw_auto_exposure")
|
||||
@@ -470,7 +471,8 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
filmicWhiteRelativeExposure = preferences[RAW_FILMIC_WHITE_RELATIVE_EXPOSURE_KEY]
|
||||
?: RawToneMappingParameters.FILMIC_WHITE_RELATIVE_EXPOSURE_DEFAULT,
|
||||
useGooglePixelToneMap = preferences[RAW_GOOGLE_PIXEL_TONE_MAP_KEY] ?: false,
|
||||
useOppoMasterToneMap = preferences[RAW_OPPO_MASTER_TONE_MAP_KEY] ?: false
|
||||
useOppoMasterToneMap = preferences[RAW_OPPO_MASTER_TONE_MAP_KEY] ?: false,
|
||||
usePhotonPgtmToneMap = preferences[RAW_PHOTON_PGTM_TONE_MAP_KEY] ?: false
|
||||
).normalized(),
|
||||
rawNlmNoiseFactor = preferences[RAW_NLM_NOISE_FACTOR_KEY] ?: 0f,
|
||||
rawExposureCompensation = preferences[RAW_EXPOSURE_COMPENSATION_KEY] ?: 0f,
|
||||
@@ -972,6 +974,7 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
preferences[RAW_FILMIC_WHITE_RELATIVE_EXPOSURE_KEY] = normalized.filmicWhiteRelativeExposure
|
||||
preferences[RAW_GOOGLE_PIXEL_TONE_MAP_KEY] = normalized.useGooglePixelToneMap
|
||||
preferences[RAW_OPPO_MASTER_TONE_MAP_KEY] = normalized.useOppoMasterToneMap
|
||||
preferences[RAW_PHOTON_PGTM_TONE_MAP_KEY] = normalized.usePhotonPgtmToneMap
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2025,6 +2028,7 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
preferences[RAW_FILMIC_WHITE_RELATIVE_EXPOSURE_KEY] = normalized.filmicWhiteRelativeExposure
|
||||
preferences[RAW_GOOGLE_PIXEL_TONE_MAP_KEY] = normalized.useGooglePixelToneMap
|
||||
preferences[RAW_OPPO_MASTER_TONE_MAP_KEY] = normalized.useOppoMasterToneMap
|
||||
preferences[RAW_PHOTON_PGTM_TONE_MAP_KEY] = normalized.usePhotonPgtmToneMap
|
||||
}
|
||||
update.rawSpectralFilmStock?.let {
|
||||
if (it.value != null) {
|
||||
|
||||
@@ -38,9 +38,11 @@ import com.hinnka.mycamera.processor.YuvHdrStackFrame
|
||||
import com.hinnka.mycamera.processor.YuvHdrStackFrameRole
|
||||
import com.hinnka.mycamera.raw.DngEmbeddedProfile
|
||||
import com.hinnka.mycamera.raw.DngProfileGainTableMap
|
||||
import com.hinnka.mycamera.raw.DngProfileToneCurve
|
||||
import com.hinnka.mycamera.raw.RawDefaultCropOverride
|
||||
import com.hinnka.mycamera.raw.RawDemosaicProcessor
|
||||
import com.hinnka.mycamera.raw.RawMetadata
|
||||
import com.hinnka.mycamera.raw.RawProfileToneMapMode
|
||||
import com.hinnka.mycamera.raw.RawSharpeningDefaults
|
||||
import com.hinnka.mycamera.raw.SpectralFilmTuning
|
||||
import com.hinnka.mycamera.utils.BitmapUtils
|
||||
@@ -3015,6 +3017,7 @@ object GalleryManager {
|
||||
applyLensShadingCorrection = resolveRawLensShadingCorrectionEnabled(context, metadata),
|
||||
colorCorrectionMatrix = rawMetadata.colorCorrectionMatrix,
|
||||
pgtmStatsBounds = rawHdrPgtmStatsBounds,
|
||||
profileToneMapMode = rawHdrPgtmModeForMetadata(metadata),
|
||||
)
|
||||
closeImagesNow(images)
|
||||
|
||||
@@ -3061,6 +3064,7 @@ object GalleryManager {
|
||||
exportDngWithRawExport = exportDngWithRawExport,
|
||||
baselineExposureEv = rawHdrBaselineExposureEv,
|
||||
profileGainTableMap = rawHdrProfileGainTableMap,
|
||||
profileToneMapMode = rawHdrPgtmModeForMetadata(stackedMetadata),
|
||||
)
|
||||
} finally {
|
||||
stackResult.fusedBayerBuffer = null
|
||||
@@ -3329,6 +3333,7 @@ object GalleryManager {
|
||||
exportDngWithRawExport: Boolean,
|
||||
baselineExposureEv: Float = 0f,
|
||||
profileGainTableMap: DngProfileGainTableMap? = null,
|
||||
profileToneMapMode: RawProfileToneMapMode = RawProfileToneMapMode.GooglePixel,
|
||||
imageLayout: SuperResolutionDngWriter.ImageLayout = SuperResolutionDngWriter.ImageLayout.CFA,
|
||||
compression: SuperResolutionDngWriter.Compression = SuperResolutionDngWriter.Compression.UNCOMPRESSED,
|
||||
inputRowStepSamples: Int? = null,
|
||||
@@ -3360,6 +3365,8 @@ object GalleryManager {
|
||||
cfaCorrectionMode = metadata.rawCfaCorrectionMode,
|
||||
baselineExposureEv = baselineExposureEv,
|
||||
profileGainTableMap = profileGainTableMap,
|
||||
profileName = profileNameForPgtmMode(profileToneMapMode),
|
||||
profileToneCurve = profileToneCurveForPgtmMode(profileToneMapMode),
|
||||
imageLayout = imageLayout,
|
||||
compression = compression,
|
||||
inputRowStepSamples = inputRowStepSamples,
|
||||
@@ -3510,6 +3517,27 @@ object GalleryManager {
|
||||
}
|
||||
}
|
||||
|
||||
private fun rawHdrPgtmModeForMetadata(metadata: MediaMetadata): RawProfileToneMapMode {
|
||||
return when (metadata.rawToneMappingParameters.normalized().profileToneMapMode) {
|
||||
RawProfileToneMapMode.PhotonPgtm -> RawProfileToneMapMode.PhotonPgtm
|
||||
else -> RawProfileToneMapMode.GooglePixel
|
||||
}
|
||||
}
|
||||
|
||||
private fun profileNameForPgtmMode(mode: RawProfileToneMapMode): String {
|
||||
return when (mode) {
|
||||
RawProfileToneMapMode.PhotonPgtm -> DngProfileToneCurve.PHOTON_PGTM_PROFILE_NAME
|
||||
else -> DngProfileToneCurve.GOOGLE_HDR_PROFILE_NAME
|
||||
}
|
||||
}
|
||||
|
||||
private fun profileToneCurveForPgtmMode(mode: RawProfileToneMapMode): FloatArray {
|
||||
return when (mode) {
|
||||
RawProfileToneMapMode.PhotonPgtm -> DngProfileToneCurve.photonPgtmToneCurvePoints()
|
||||
else -> DngProfileToneCurve.googleHdrToneCurvePoints()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存连拍照片
|
||||
*/
|
||||
@@ -4219,10 +4247,24 @@ object GalleryManager {
|
||||
dngFile: File
|
||||
): MediaMetadata {
|
||||
val hasProfileGainTableMap = DngProfileGainTableMap.readFrom(dngFile)?.isValid == true
|
||||
if (!hasProfileGainTableMap || !DngEmbeddedProfile.hasGoogleToneMapProfile(dngFile)) return this
|
||||
val toneMappingParameters = rawToneMappingParameters.withGooglePixelToneMap(true)
|
||||
if (!hasProfileGainTableMap) return this
|
||||
val toneMappingParameters = when {
|
||||
DngEmbeddedProfile.hasPhotonPgtmProfile(dngFile) -> {
|
||||
rawToneMappingParameters.withPhotonPgtmToneMap(true)
|
||||
}
|
||||
|
||||
DngEmbeddedProfile.hasGoogleToneMapProfile(dngFile) -> {
|
||||
rawToneMappingParameters.withGooglePixelToneMap(true)
|
||||
}
|
||||
|
||||
else -> return this
|
||||
}
|
||||
if (toneMappingParameters == rawToneMappingParameters && manualHdrEffectEnabled) return this
|
||||
PLog.d(TAG, "DNG contains PGTM + Google ProfileToneCurve; enabling Pixel-style tone map and HDR gainmap for this photo")
|
||||
PLog.d(
|
||||
TAG,
|
||||
"DNG contains PGTM + ${toneMappingParameters.profileToneMapMode} ProfileToneCurve; " +
|
||||
"enabling profile tone map and HDR gainmap for this photo"
|
||||
)
|
||||
return copy(
|
||||
rawToneMappingParameters = toneMappingParameters,
|
||||
manualHdrEffectEnabled = true
|
||||
|
||||
@@ -340,7 +340,8 @@ data class MediaMetadata(
|
||||
obj.optDouble("rawFilmicWhiteRelativeExposure").toFloat()
|
||||
},
|
||||
useGooglePixelToneMap = obj.optBoolean("rawGooglePixelToneMap", false),
|
||||
useOppoMasterToneMap = obj.optBoolean("rawOppoMasterToneMap", false)
|
||||
useOppoMasterToneMap = obj.optBoolean("rawOppoMasterToneMap", false),
|
||||
usePhotonPgtmToneMap = obj.optBoolean("rawPhotonPgtmToneMap", false)
|
||||
).normalized(),
|
||||
rawBlackLevelMode = if (obj.isNull("rawBlackLevelMode")) null else obj.optString("rawBlackLevelMode"),
|
||||
rawCustomBlackLevel = if (obj.isNull("rawCustomBlackLevel")) null else obj.optDouble("rawCustomBlackLevel").toFloat(),
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.hinnka.mycamera.raw.RawToneMappingParameters
|
||||
|
||||
@Database(
|
||||
entities = [GalleryMediaEntity::class],
|
||||
version = 22,
|
||||
version = 23,
|
||||
exportSchema = false
|
||||
)
|
||||
@androidx.room.TypeConverters(GalleryConverters::class)
|
||||
@@ -178,6 +178,12 @@ abstract class GalleryDatabase : RoomDatabase() {
|
||||
}
|
||||
}
|
||||
|
||||
private val MIGRATION_22_23 = object : androidx.room.migration.Migration(22, 23) {
|
||||
override fun migrate(db: androidx.sqlite.db.SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE gallery_media ADD COLUMN rawPhotonPgtmToneMap INTEGER NOT NULL DEFAULT 0")
|
||||
}
|
||||
}
|
||||
|
||||
private fun rebuildGalleryMediaWithoutLegacyGoogleToneMapFlag(
|
||||
db: androidx.sqlite.db.SupportSQLiteDatabase
|
||||
) {
|
||||
@@ -531,7 +537,8 @@ abstract class GalleryDatabase : RoomDatabase() {
|
||||
MIGRATION_18_19,
|
||||
MIGRATION_19_20,
|
||||
MIGRATION_20_21,
|
||||
MIGRATION_21_22
|
||||
MIGRATION_21_22,
|
||||
MIGRATION_22_23
|
||||
)
|
||||
.fallbackToDestructiveMigrationOnDowngrade(false)
|
||||
.fallbackToDestructiveMigration(false)
|
||||
|
||||
@@ -63,6 +63,7 @@ data class GalleryMediaEntity(
|
||||
val rawFilmicWhiteRelativeExposure: Float,
|
||||
val rawGooglePixelToneMap: Boolean,
|
||||
val rawOppoMasterToneMap: Boolean,
|
||||
val rawPhotonPgtmToneMap: Boolean,
|
||||
val rawAppleProRawToneMap: Boolean,
|
||||
val frameId: String?,
|
||||
val width: Int,
|
||||
|
||||
@@ -237,6 +237,7 @@ object GalleryMediaStore {
|
||||
rawFilmicWhiteRelativeExposure = metadata.rawToneMappingParameters.filmicWhiteRelativeExposure,
|
||||
rawGooglePixelToneMap = metadata.rawToneMappingParameters.useGooglePixelToneMap,
|
||||
rawOppoMasterToneMap = metadata.rawToneMappingParameters.useOppoMasterToneMap,
|
||||
rawPhotonPgtmToneMap = metadata.rawToneMappingParameters.usePhotonPgtmToneMap,
|
||||
rawAppleProRawToneMap = false,
|
||||
frameId = metadata.frameId,
|
||||
width = metadata.width,
|
||||
@@ -418,7 +419,8 @@ object GalleryMediaStore {
|
||||
filmicBlackRelativeExposure = rawFilmicBlackRelativeExposure,
|
||||
filmicWhiteRelativeExposure = rawFilmicWhiteRelativeExposure,
|
||||
useGooglePixelToneMap = rawGooglePixelToneMap,
|
||||
useOppoMasterToneMap = rawOppoMasterToneMap
|
||||
useOppoMasterToneMap = rawOppoMasterToneMap,
|
||||
usePhotonPgtmToneMap = rawPhotonPgtmToneMap
|
||||
).normalized(),
|
||||
frameId = frameId,
|
||||
width = width,
|
||||
|
||||
@@ -27,6 +27,7 @@ data class CameraPreset(
|
||||
val rawRenderingEngine: String = RawRenderingEngine.AdobeCurve.name,
|
||||
val rawGooglePixelToneMap: Boolean = false,
|
||||
val rawOppoMasterToneMap: Boolean = false,
|
||||
val rawPhotonPgtmToneMap: Boolean = false,
|
||||
val rawSpectralFilmStock: String? = null,
|
||||
val rawSpectralFilmPrint: String? = null,
|
||||
val rawDROMode: String = "OFF",
|
||||
@@ -73,8 +74,9 @@ data class CameraPreset(
|
||||
.withoutLegacyHdf()
|
||||
.copy(
|
||||
rawDcpIdsByLens = normalizeRawDcpIdsByLens(rawDcpIdsByLens),
|
||||
rawGooglePixelToneMap = rawGooglePixelToneMap && !rawOppoMasterToneMap,
|
||||
rawOppoMasterToneMap = rawOppoMasterToneMap
|
||||
rawGooglePixelToneMap = rawGooglePixelToneMap && !rawOppoMasterToneMap && !rawPhotonPgtmToneMap,
|
||||
rawOppoMasterToneMap = rawOppoMasterToneMap,
|
||||
rawPhotonPgtmToneMap = rawPhotonPgtmToneMap && !rawOppoMasterToneMap
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ internal object CameraPresetJsonCodec {
|
||||
),
|
||||
rawGooglePixelToneMap = obj.boolean("rawGooglePixelToneMap", false),
|
||||
rawOppoMasterToneMap = obj.boolean("rawOppoMasterToneMap", false),
|
||||
rawPhotonPgtmToneMap = obj.boolean("rawPhotonPgtmToneMap", false),
|
||||
rawSpectralFilmStock = obj.stringOrNull("rawSpectralFilmStock"),
|
||||
rawSpectralFilmPrint = obj.stringOrNull("rawSpectralFilmPrint"),
|
||||
rawDROMode = parseDroMode(obj.stringOrNull("rawDROMode")),
|
||||
|
||||
@@ -11,7 +11,9 @@ import android.opengl.GLES30
|
||||
import android.opengl.GLES31
|
||||
import com.hinnka.mycamera.model.SafeImage
|
||||
import com.hinnka.mycamera.raw.DngHdrProfileGainTableGenerator
|
||||
import com.hinnka.mycamera.raw.DngPhotonProfileGainTableGenerator
|
||||
import com.hinnka.mycamera.raw.DngPgtmDiagnostic
|
||||
import com.hinnka.mycamera.raw.RawProfileToneMapMode
|
||||
import com.hinnka.mycamera.utils.LargeDirectBuffer
|
||||
import com.hinnka.mycamera.utils.PLog
|
||||
import java.nio.ByteBuffer
|
||||
@@ -35,6 +37,7 @@ class GlesRawStacker(
|
||||
private val lensShadingHeight: Int,
|
||||
colorCorrectionMatrix: FloatArray? = null,
|
||||
pgtmStatsBounds: Rect? = null,
|
||||
private val profileToneMapMode: RawProfileToneMapMode = RawProfileToneMapMode.GooglePixel,
|
||||
private val tuning: RawStackTuningProfile = RawStackTuningResolver.resolve(RawStackMode.MFNR),
|
||||
debugConfig: RawStackDebugConfig = RawStackDebugConfig.Disabled,
|
||||
) {
|
||||
@@ -527,6 +530,11 @@ class GlesRawStacker(
|
||||
blackLevel = normalizedBlackLevel.copyOf(),
|
||||
fusedBayerUsesNativeAllocator = true,
|
||||
profileGainTableMap = profileGainTableMap,
|
||||
profileToneMapMode = if (profileGainTableMap != null) {
|
||||
profileToneMapMode
|
||||
} else {
|
||||
RawProfileToneMapMode.Default
|
||||
},
|
||||
diagnostics = diagnostics,
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
@@ -854,6 +862,11 @@ class GlesRawStacker(
|
||||
if (!baselineExposureEv.isFinite() || baselineExposureEv <= 0.05f || pgtmStatsProgram == 0) {
|
||||
return null
|
||||
}
|
||||
if (profileToneMapMode != RawProfileToneMapMode.GooglePixel &&
|
||||
profileToneMapMode != RawProfileToneMapMode.PhotonPgtm
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val grid = DngHdrProfileGainTableGenerator.gridSizeFor(width, height)
|
||||
val pgtmGridWidth = grid.getOrElse(0) { 0 }
|
||||
val pgtmGridHeight = grid.getOrElse(1) { 0 }
|
||||
@@ -924,13 +937,24 @@ class GlesRawStacker(
|
||||
} finally {
|
||||
GLES31.glUnmapBuffer(GLES31.GL_SHADER_STORAGE_BUFFER)
|
||||
}
|
||||
DngHdrProfileGainTableGenerator.forCellStats(
|
||||
width = width,
|
||||
height = height,
|
||||
baselineExposureEv = baselineExposureEv,
|
||||
packedCellStats = stats,
|
||||
diagnosticBand = DngPgtmDiagnostic.activeBandForSource("$TAG GPU stacker")
|
||||
)
|
||||
val diagnosticBand = DngPgtmDiagnostic.activeBandForSource("$TAG GPU stacker")
|
||||
when (profileToneMapMode) {
|
||||
RawProfileToneMapMode.PhotonPgtm -> DngPhotonProfileGainTableGenerator.forCellStats(
|
||||
width = width,
|
||||
height = height,
|
||||
baselineExposureEv = baselineExposureEv,
|
||||
packedCellStats = stats,
|
||||
diagnosticBand = diagnosticBand
|
||||
)
|
||||
|
||||
else -> DngHdrProfileGainTableGenerator.forCellStats(
|
||||
width = width,
|
||||
height = height,
|
||||
baselineExposureEv = baselineExposureEv,
|
||||
packedCellStats = stats,
|
||||
diagnosticBand = diagnosticBand
|
||||
)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
PLog.w(TAG, "Failed to compute GPU HDR PGTM stats", e)
|
||||
null
|
||||
|
||||
@@ -9,6 +9,7 @@ import androidx.core.graphics.createBitmap
|
||||
import com.hinnka.mycamera.camera.AspectRatio
|
||||
import com.hinnka.mycamera.model.SafeImage
|
||||
import com.hinnka.mycamera.raw.DngProfileGainTableMap
|
||||
import com.hinnka.mycamera.raw.RawProfileToneMapMode
|
||||
import com.hinnka.mycamera.utils.BitmapUtils
|
||||
import com.hinnka.mycamera.utils.LargeDirectBuffer
|
||||
|
||||
@@ -20,6 +21,7 @@ data class RawStackResult(
|
||||
val blackLevel: FloatArray = floatArrayOf(0f, 0f, 0f, 0f),
|
||||
val fusedBayerUsesNativeAllocator: Boolean = false,
|
||||
val profileGainTableMap: DngProfileGainTableMap? = null,
|
||||
val profileToneMapMode: RawProfileToneMapMode = RawProfileToneMapMode.Default,
|
||||
val diagnostics: RawStackDiagnostics? = null,
|
||||
)
|
||||
|
||||
@@ -233,6 +235,7 @@ object MultiFrameStacker {
|
||||
applyLensShadingCorrection: Boolean = true,
|
||||
colorCorrectionMatrix: FloatArray? = null,
|
||||
pgtmStatsBounds: Rect? = null,
|
||||
profileToneMapMode: RawProfileToneMapMode = RawProfileToneMapMode.GooglePixel,
|
||||
): RawStackResult? {
|
||||
if (normalFrames.isEmpty()) {
|
||||
shortFrame.image.close()
|
||||
@@ -271,6 +274,7 @@ object MultiFrameStacker {
|
||||
lensShadingHeight = if (stackLensShading != null) lensShadingHeight else 0,
|
||||
colorCorrectionMatrix = colorCorrectionMatrix,
|
||||
pgtmStatsBounds = pgtmStatsBounds,
|
||||
profileToneMapMode = profileToneMapMode,
|
||||
tuning = tuning,
|
||||
debugConfig = RawStackRuntimeDebug.debugConfig,
|
||||
).processHdr(
|
||||
|
||||
@@ -95,6 +95,12 @@ internal object DngEmbeddedProfile {
|
||||
return isGoogleProfileName(profile.profileName) && profile.toneCurve?.isValid == true
|
||||
}
|
||||
|
||||
fun hasPhotonPgtmProfile(file: File): Boolean {
|
||||
val profile = readFrom(file) ?: return false
|
||||
return isPhotonPgtmProfileName(profile.profileName) &&
|
||||
DngProfileToneCurve.isLinearToneCurve(profile.toneCurve)
|
||||
}
|
||||
|
||||
fun hasGoogleHdrToneCurve(file: File): Boolean {
|
||||
val profile = readFrom(file) ?: return false
|
||||
return DngProfileToneCurve.isGoogleHdrToneCurve(profile.toneCurve)
|
||||
@@ -104,6 +110,11 @@ internal object DngEmbeddedProfile {
|
||||
return profileName?.contains("google", ignoreCase = true) == true
|
||||
}
|
||||
|
||||
fun isPhotonPgtmProfileName(profileName: String?): Boolean {
|
||||
return profileName?.contains("photon", ignoreCase = true) == true &&
|
||||
profileName.contains("pgtm", ignoreCase = true)
|
||||
}
|
||||
|
||||
private fun decodeProfile(
|
||||
raf: RandomAccessFile,
|
||||
ifd: Map<Int, TiffEntry>,
|
||||
|
||||
@@ -15,26 +15,30 @@ 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_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_PROFILE_GAIN_TABLE_MAP_2 = DngProfileGainTableMap.TAG_PROFILE_GAIN_TABLE_MAP2
|
||||
|
||||
fun rewriteGeneratedPgtmOnRawRefreshIfEnabled(
|
||||
dngFile: File?,
|
||||
profileGainTableMap: DngProfileGainTableMap?,
|
||||
profileToneMapMode: RawProfileToneMapMode = RawProfileToneMapMode.GooglePixel,
|
||||
): Boolean {
|
||||
if (!BuildConfig.DEBUG || !REWRITE_GENERATED_PGTM_ON_RAW_REFRESH) return false
|
||||
val file = dngFile ?: return false
|
||||
val map = profileGainTableMap?.takeIf { it.isValid } ?: return false
|
||||
return rewriteProfileGainTableMap2(file, map)
|
||||
return rewriteProfileGainTableMap2(file, map, profileToneMapMode)
|
||||
}
|
||||
|
||||
fun rewriteProfileGainTableMap2(
|
||||
dngFile: File,
|
||||
profileGainTableMap: DngProfileGainTableMap,
|
||||
profileToneMapMode: RawProfileToneMapMode = RawProfileToneMapMode.GooglePixel,
|
||||
): Boolean {
|
||||
if (!BuildConfig.DEBUG) return false
|
||||
if (!profileGainTableMap.isValid || !dngFile.exists() || dngFile.length() < 16L) {
|
||||
@@ -50,7 +54,9 @@ internal object DngPgtmDebugRewriter {
|
||||
}
|
||||
val ifd0Offset = raf.readUnsignedInt(byteOrder)
|
||||
val ifd0 = readIfd(raf, ifd0Offset, byteOrder) ?: return@use false
|
||||
val toneCurvePoints = DngProfileToneCurve.googleHdrToneCurvePoints()
|
||||
val profileName = profileNameForToneMapMode(profileToneMapMode)
|
||||
val profileNameBytes = asciiBytes(profileName)
|
||||
val toneCurvePoints = profileToneCurveForToneMapMode(profileToneMapMode)
|
||||
val pgtmPayload = profileGainTableMap.encodeProfileGainTableMap2(byteOrder)
|
||||
val replacements = listOf(
|
||||
TiffValue(
|
||||
@@ -59,6 +65,12 @@ internal object DngPgtmDebugRewriter {
|
||||
count = 4,
|
||||
bytes = byteArrayOf(1, 7, 0, 0)
|
||||
),
|
||||
TiffValue(
|
||||
tag = TAG_PROFILE_NAME,
|
||||
type = TYPE_ASCII,
|
||||
count = profileNameBytes.size.toLong(),
|
||||
bytes = profileNameBytes
|
||||
),
|
||||
TiffValue(
|
||||
tag = TAG_PROFILE_TONE_CURVE,
|
||||
type = TYPE_FLOAT,
|
||||
@@ -85,6 +97,7 @@ internal object DngPgtmDebugRewriter {
|
||||
raf.writeUInt(newIfdOffset, byteOrder)
|
||||
logInfo(
|
||||
"Rewrote debug DNG PGTM: file=${dngFile.name} " +
|
||||
"profile=$profileName " +
|
||||
"grid=${profileGainTableMap.mapPointsH}x${profileGainTableMap.mapPointsV}x" +
|
||||
"${profileGainTableMap.mapPointsN} ifd0=$ifd0Offset->$newIfdOffset"
|
||||
)
|
||||
@@ -109,6 +122,24 @@ internal object DngPgtmDebugRewriter {
|
||||
}
|
||||
}
|
||||
|
||||
private fun profileNameForToneMapMode(mode: RawProfileToneMapMode): String {
|
||||
return when (mode) {
|
||||
RawProfileToneMapMode.PhotonPgtm -> DngProfileToneCurve.PHOTON_PGTM_PROFILE_NAME
|
||||
else -> DngProfileToneCurve.GOOGLE_HDR_PROFILE_NAME
|
||||
}
|
||||
}
|
||||
|
||||
private fun profileToneCurveForToneMapMode(mode: RawProfileToneMapMode): FloatArray {
|
||||
return when (mode) {
|
||||
RawProfileToneMapMode.PhotonPgtm -> DngProfileToneCurve.photonPgtmToneCurvePoints()
|
||||
else -> DngProfileToneCurve.googleHdrToneCurvePoints()
|
||||
}
|
||||
}
|
||||
|
||||
private fun asciiBytes(value: String): ByteArray {
|
||||
return (value + "\u0000").toByteArray(Charsets.US_ASCII)
|
||||
}
|
||||
|
||||
private fun appendIfd0WithReplacements(
|
||||
raf: RandomAccessFile,
|
||||
original: TiffIfd,
|
||||
|
||||
@@ -0,0 +1,456 @@
|
||||
package com.hinnka.mycamera.raw
|
||||
|
||||
import com.hinnka.mycamera.utils.PLog
|
||||
import kotlin.math.ln
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
import kotlin.math.pow
|
||||
|
||||
internal object DngPhotonProfileGainTableGenerator {
|
||||
private const val TAG = "DngPhotonProfileGainTableGenerator"
|
||||
|
||||
private const val DEFAULT_TABLE_POINTS = 257
|
||||
private const val MIN_TABLE_POINTS = 257
|
||||
private const val MAX_TABLE_POINTS = 257
|
||||
private const val MIN_BASELINE_EV = 0f
|
||||
private const val MAX_BASELINE_EV = 8f
|
||||
private const val MIN_CURVE_INPUT = 1e-6f
|
||||
private const val MIN_SCENE_MAX = 1f
|
||||
private const val MAX_SCENE_MAX = 4.80f
|
||||
private const val MAX_GAIN_VALUE = 5.40f
|
||||
private const val MAP_INPUT_WEIGHT_COUNT = 5
|
||||
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 val BASE_INPUT_WEIGHTS = floatArrayOf(
|
||||
DngHdrProfileGainTableGenerator.BASE_INPUT_WEIGHT_RED,
|
||||
DngHdrProfileGainTableGenerator.BASE_INPUT_WEIGHT_GREEN,
|
||||
DngHdrProfileGainTableGenerator.BASE_INPUT_WEIGHT_BLUE,
|
||||
DngHdrProfileGainTableGenerator.BASE_INPUT_WEIGHT_MIN,
|
||||
DngHdrProfileGainTableGenerator.BASE_INPUT_WEIGHT_MAX
|
||||
)
|
||||
|
||||
fun forCellStats(
|
||||
width: Int,
|
||||
height: Int,
|
||||
baselineExposureEv: Float,
|
||||
packedCellStats: FloatArray,
|
||||
tablePointCount: Int = DEFAULT_TABLE_POINTS,
|
||||
diagnosticBand: DngHdrProfileGainTableGenerator.DiagnosticBand? = null,
|
||||
): DngProfileGainTableMap? {
|
||||
if (width <= 0 || height <= 0 || !baselineExposureEv.isFinite() || baselineExposureEv < MIN_BASELINE_EV) {
|
||||
return null
|
||||
}
|
||||
val gridSize = DngHdrProfileGainTableGenerator.gridSizeFor(width, height)
|
||||
val gridWidth = gridSize.getOrElse(0) { 0 }
|
||||
val gridHeight = gridSize.getOrElse(1) { 0 }
|
||||
if (gridWidth <= 0 || gridHeight <= 0) return null
|
||||
val cellCount = gridWidth * gridHeight
|
||||
if (packedCellStats.size < cellCount * DngHdrProfileGainTableGenerator.CELL_STATS_FLOAT_STRIDE) {
|
||||
PLog.w(
|
||||
TAG,
|
||||
"Photon PGTM stats too small: ${packedCellStats.size}, " +
|
||||
"expected=${cellCount * DngHdrProfileGainTableGenerator.CELL_STATS_FLOAT_STRIDE}"
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
val cells = Array<PhotonPgtmCellStats?>(cellCount) { index ->
|
||||
val offset = index * DngHdrProfileGainTableGenerator.CELL_STATS_FLOAT_STRIDE
|
||||
val sampleWeight = packedCellStats[offset + 5].takeIf { it.isFinite() && it > 0f } ?: 0f
|
||||
if (sampleWeight <= 0f) {
|
||||
null
|
||||
} else {
|
||||
packedStatsAt(packedCellStats, offset, sampleWeight)
|
||||
}
|
||||
}
|
||||
val global = weightedGlobalStats(cells)
|
||||
val safeBaselineEv = baselineExposureEv.coerceIn(0f, MAX_BASELINE_EV)
|
||||
val safePointCount = tablePointCount.coerceIn(MIN_TABLE_POINTS, MAX_TABLE_POINTS)
|
||||
val sceneMax = photonSceneMaxForStats(global)
|
||||
// Stats collection and the render shader both apply DNG baseline gain before
|
||||
// table lookup, so table input 1.0 corresponds to raw linear 1 / baselineGain.
|
||||
val inputScale = sanitizeInputScale(1f / sceneMax)
|
||||
val gains = FloatArray(cellCount * safePointCount)
|
||||
for (cellIndex in 0 until cellCount) {
|
||||
writePhotonCurve(
|
||||
output = gains,
|
||||
outputOffset = cellIndex * safePointCount,
|
||||
pointCount = safePointCount,
|
||||
inputScale = inputScale,
|
||||
global = global,
|
||||
local = cells[cellIndex] ?: global
|
||||
)
|
||||
}
|
||||
|
||||
val map = DngProfileGainTableMap(
|
||||
mapPointsV = gridHeight,
|
||||
mapPointsH = gridWidth,
|
||||
mapSpacingV = if (gridHeight > 1) 1.0 / (gridHeight - 1).toDouble() else 1.0,
|
||||
mapSpacingH = if (gridWidth > 1) 1.0 / (gridWidth - 1).toDouble() else 1.0,
|
||||
mapOriginV = 0.0,
|
||||
mapOriginH = 0.0,
|
||||
mapPointsN = safePointCount,
|
||||
mapInputWeights = photonPgtmInputWeights(inputScale),
|
||||
gamma = 1f,
|
||||
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}"
|
||||
)
|
||||
return DngHdrProfileGainTableGenerator.withDiagnosticBand(map, diagnosticBand)
|
||||
}
|
||||
|
||||
private fun packedStatsAt(stats: FloatArray, offset: Int, sampleWeight: Float): PhotonPgtmCellStats {
|
||||
val p10 = safe01(stats[offset])
|
||||
val p50 = max(p10, safe01(stats[offset + 1]))
|
||||
val p90 = max(p50, safe01(stats[offset + 2]))
|
||||
val p98 = max(p90, safe01(stats[offset + 3]))
|
||||
val tailP95 = max(p98, safePositive(stats[offset + 6], p98))
|
||||
val tailP99 = max(tailP95, safePositive(stats[offset + 7], tailP95))
|
||||
return PhotonPgtmCellStats(
|
||||
p10 = p10,
|
||||
p50 = p50,
|
||||
p90 = p90,
|
||||
p98 = p98,
|
||||
highlightFraction = safe01(stats[offset + 4]),
|
||||
tailP95 = tailP95,
|
||||
tailP99 = tailP99,
|
||||
maxInput = tailP99,
|
||||
sampleWeight = sampleWeight
|
||||
)
|
||||
}
|
||||
|
||||
private fun weightedGlobalStats(cells: Array<PhotonPgtmCellStats?>): PhotonPgtmCellStats {
|
||||
var weightSum = 0f
|
||||
var p10 = 0f
|
||||
var p50 = 0f
|
||||
var p90 = 0f
|
||||
var p98 = 0f
|
||||
var highlightFraction = 0f
|
||||
val validCells = ArrayList<PhotonPgtmCellStats>(cells.size)
|
||||
cells.forEach { cell ->
|
||||
if (cell != null && cell.sampleWeight > 0f) {
|
||||
validCells += cell
|
||||
weightSum += cell.sampleWeight
|
||||
p10 += cell.p10 * cell.sampleWeight
|
||||
p50 += cell.p50 * cell.sampleWeight
|
||||
p90 += cell.p90 * cell.sampleWeight
|
||||
p98 += cell.p98 * cell.sampleWeight
|
||||
highlightFraction += cell.highlightFraction * cell.sampleWeight
|
||||
}
|
||||
}
|
||||
if (weightSum <= 0f) {
|
||||
return PhotonPgtmCellStats(
|
||||
p10 = 0.02f,
|
||||
p50 = 0.18f,
|
||||
p90 = 0.55f,
|
||||
p98 = 0.82f,
|
||||
highlightFraction = 0f,
|
||||
tailP95 = 0.82f,
|
||||
tailP99 = 0.82f,
|
||||
maxInput = 0.82f,
|
||||
sampleWeight = 1f
|
||||
)
|
||||
}
|
||||
val tailP95 = weightedPercentile(validCells, 0.95f) { it.tailP95 }
|
||||
val tailP99 = weightedPercentile(validCells, 0.99f) { it.tailP99 }
|
||||
val maxInput = validCells.maxOfOrNull { it.maxInput } ?: tailP99
|
||||
return PhotonPgtmCellStats(
|
||||
p10 = p10 / weightSum,
|
||||
p50 = p50 / weightSum,
|
||||
p90 = p90 / weightSum,
|
||||
p98 = p98 / weightSum,
|
||||
highlightFraction = highlightFraction / weightSum,
|
||||
tailP95 = tailP95,
|
||||
tailP99 = tailP99,
|
||||
maxInput = maxInput,
|
||||
sampleWeight = weightSum
|
||||
)
|
||||
}
|
||||
|
||||
private fun weightedPercentile(
|
||||
cells: List<PhotonPgtmCellStats>,
|
||||
percentile: Float,
|
||||
selector: (PhotonPgtmCellStats) -> Float,
|
||||
): Float {
|
||||
if (cells.isEmpty()) return 0f
|
||||
val sorted = cells
|
||||
.mapNotNull { cell ->
|
||||
val value = selector(cell)
|
||||
if (value.isFinite() && cell.sampleWeight > 0f) {
|
||||
value to cell.sampleWeight
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
.sortedBy { it.first }
|
||||
if (sorted.isEmpty()) return 0f
|
||||
val totalWeight = sorted.sumOf { it.second.toDouble() }.toFloat()
|
||||
val target = totalWeight * percentile.coerceIn(0f, 1f)
|
||||
var cumulative = 0f
|
||||
sorted.forEach { (value, weight) ->
|
||||
cumulative += weight
|
||||
if (cumulative >= target) return value
|
||||
}
|
||||
return sorted.last().first
|
||||
}
|
||||
|
||||
private fun photonSceneMaxForStats(global: PhotonPgtmCellStats): Float {
|
||||
val tailP95 = max(global.tailP95, global.p98)
|
||||
val tailP99 = max(global.tailP99, tailP95)
|
||||
val maxInput = max(global.maxInput, tailP99)
|
||||
val tailRangeEv = log2((tailP99 + 0.04f) / (global.p50 + 0.04f)).coerceIn(0f, 8f)
|
||||
val highlightDensity = global.highlightFraction.coerceIn(0f, 1f)
|
||||
val hdrStrength = max(
|
||||
max(smoothStep(1.02f, 1.55f, tailP95), smoothStep(1.8f, 4.2f, tailRangeEv)),
|
||||
smoothStep(0.08f, 0.24f, highlightDensity) * smoothStep(0.86f, 1.18f, tailP95)
|
||||
)
|
||||
val outlierGapEv = log2((maxInput + 0.04f) / (tailP99 + 0.04f)).coerceIn(0f, 6f)
|
||||
val sparseOutlier = smoothStep(0.45f, 1.25f, outlierGapEv) *
|
||||
(1f - smoothStep(0.16f, 0.32f, highlightDensity))
|
||||
val denseHighlight = smoothStep(0.12f, 0.30f, highlightDensity)
|
||||
val percentileTarget = max(
|
||||
1f,
|
||||
lerp(tailP95 * 1.03f, tailP99 * 0.96f, 0.45f + 0.35f * denseHighlight)
|
||||
)
|
||||
val outlierTarget = lerp(
|
||||
percentileTarget,
|
||||
min(maxInput, max(percentileTarget, tailP99 * 1.24f)),
|
||||
sparseOutlier * 0.42f
|
||||
)
|
||||
return lerp(MIN_SCENE_MAX, outlierTarget, hdrStrength)
|
||||
.coerceIn(MIN_SCENE_MAX, MAX_SCENE_MAX)
|
||||
}
|
||||
|
||||
private fun writePhotonCurve(
|
||||
output: FloatArray,
|
||||
outputOffset: Int,
|
||||
pointCount: Int,
|
||||
inputScale: Float,
|
||||
global: PhotonPgtmCellStats,
|
||||
local: PhotonPgtmCellStats,
|
||||
) {
|
||||
val safeInputScale = sanitizeInputScale(inputScale)
|
||||
val sceneMax = (1f / safeInputScale).coerceIn(MIN_SCENE_MAX, MAX_SCENE_MAX)
|
||||
var previousOutput = 0f
|
||||
val lowTableInput = 1f / max(pointCount - 1, 1).toFloat()
|
||||
val lowSceneLinear = lowTableInput / safeInputScale
|
||||
val lowGain = (photonToneOutput(lowSceneLinear, sceneMax, global, local) / lowSceneLinear)
|
||||
.coerceIn(0.05f, MAX_GAIN_VALUE)
|
||||
for (index in 0 until pointCount) {
|
||||
val tableInput = tableInputForIndex(index, pointCount)
|
||||
if (tableInput <= MIN_CURVE_INPUT) {
|
||||
output[outputOffset + index] = lowGain
|
||||
continue
|
||||
}
|
||||
val sceneLinear = tableInput / safeInputScale
|
||||
val targetOutput = photonToneOutput(sceneLinear, sceneMax, global, local)
|
||||
val monotonicOutput = max(previousOutput, targetOutput)
|
||||
output[outputOffset + index] = (monotonicOutput / max(sceneLinear, MIN_CURVE_INPUT))
|
||||
.coerceIn(0.05f, MAX_GAIN_VALUE)
|
||||
previousOutput = monotonicOutput
|
||||
}
|
||||
}
|
||||
|
||||
private fun photonToneOutput(
|
||||
sceneLinear: Float,
|
||||
sceneMax: Float,
|
||||
global: PhotonPgtmCellStats,
|
||||
local: PhotonPgtmCellStats,
|
||||
): Float {
|
||||
if (sceneLinear <= 0f) return 0f
|
||||
val midGrayGain = photonMidGrayGain(global, local, sceneMax)
|
||||
val midGrayOutput = (MID_GRAY_INPUT * midGrayGain).coerceIn(0.20f, 0.72f)
|
||||
val baseOutput = if (sceneLinear <= MID_GRAY_INPUT) {
|
||||
photonAdaptiveShadowOutput(
|
||||
baseOutput = sceneLinear * midGrayGain,
|
||||
sceneLinear = sceneLinear,
|
||||
sceneMax = sceneMax,
|
||||
global = global,
|
||||
local = local
|
||||
)
|
||||
} else {
|
||||
// sceneMax is baseline-normalized. Its output 1 maps to raw 1 / baselineGain.
|
||||
val inputRange = max(sceneMax - MID_GRAY_INPUT, 1e-4f)
|
||||
val outputRange = max(1f - midGrayOutput, 1e-4f)
|
||||
val t = ((sceneLinear - MID_GRAY_INPUT) / inputRange).coerceIn(0f, 1f)
|
||||
val initialSlope = min(midGrayGain * inputRange, 2.4f * outputRange)
|
||||
val finalSlope = 0.22f * outputRange
|
||||
cubicHermite(
|
||||
start = midGrayOutput,
|
||||
end = 1f,
|
||||
startSlope = initialSlope,
|
||||
endSlope = finalSlope,
|
||||
t = t
|
||||
)
|
||||
}
|
||||
return photonLocalMicroContrastOutput(
|
||||
baseOutput = baseOutput,
|
||||
sceneLinear = sceneLinear,
|
||||
global = global,
|
||||
local = local
|
||||
)
|
||||
}
|
||||
|
||||
private fun photonMidGrayGain(
|
||||
global: PhotonPgtmCellStats,
|
||||
local: PhotonPgtmCellStats,
|
||||
sceneMax: Float,
|
||||
): Float {
|
||||
val rangeEv = log2((global.p98 + 0.008f) / (global.p10 + 0.008f)).coerceIn(0f, 10f)
|
||||
val highContrast = smoothStep(3.6f, 6.2f, rangeEv) *
|
||||
smoothStep(1.10f, 1.80f, sceneMax)
|
||||
val lowContrast = 1f - smoothStep(1.6f, 3.0f, rangeEv)
|
||||
val darkScene = 1f - smoothStep(0.14f, 0.30f, global.p50)
|
||||
val darkCell = 1f - smoothStep(0.12f, 0.28f, local.p50)
|
||||
val liftEv = DEFAULT_MID_GRAY_LIFT_EV +
|
||||
0.22f * highContrast * darkScene +
|
||||
0.08f * highContrast * darkCell -
|
||||
0.16f * highContrast * (1f - darkScene) -
|
||||
0.12f * lowContrast
|
||||
return 2.0f.pow(liftEv.coerceIn(0.82f, 1.38f))
|
||||
}
|
||||
|
||||
private fun cubicHermite(
|
||||
start: Float,
|
||||
end: Float,
|
||||
startSlope: Float,
|
||||
endSlope: Float,
|
||||
t: Float,
|
||||
): Float {
|
||||
val u = t.coerceIn(0f, 1f)
|
||||
val u2 = u * u
|
||||
val u3 = u2 * u
|
||||
val h00 = 2f * u3 - 3f * u2 + 1f
|
||||
val h10 = u3 - 2f * u2 + u
|
||||
val h01 = -2f * u3 + 3f * u2
|
||||
val h11 = u3 - u2
|
||||
return (h00 * start + h10 * startSlope + h01 * end + h11 * endSlope)
|
||||
.coerceIn(start, end)
|
||||
}
|
||||
|
||||
/**
|
||||
* The fixed profile curve owns only the base S shape. PGTM adds local shadow
|
||||
* gain when the scene is both high contrast and globally dark.
|
||||
*/
|
||||
private fun photonAdaptiveShadowOutput(
|
||||
baseOutput: Float,
|
||||
sceneLinear: Float,
|
||||
sceneMax: Float,
|
||||
global: PhotonPgtmCellStats,
|
||||
local: PhotonPgtmCellStats,
|
||||
): 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)
|
||||
}
|
||||
|
||||
private fun photonLocalMicroContrastOutput(
|
||||
baseOutput: Float,
|
||||
sceneLinear: Float,
|
||||
global: PhotonPgtmCellStats,
|
||||
local: PhotonPgtmCellStats,
|
||||
): Float {
|
||||
val localRangeEv = log2((local.p90 + 0.008f) / (local.p10 + 0.008f))
|
||||
.coerceIn(0f, 8f)
|
||||
val localDetail = smoothStep(1.15f, 3.20f, localRangeEv)
|
||||
val highlightDamping = 1f - smoothStep(0.10f, 0.34f, global.highlightFraction)
|
||||
val strength = MAX_LOCAL_MICRO_CONTRAST * localDetail * highlightDamping
|
||||
if (strength <= 1e-4f) return baseOutput
|
||||
|
||||
val pivot = local.p50.coerceIn(0.065f, 0.28f)
|
||||
val signedDistance = (log2((sceneLinear + 0.010f) / (pivot + 0.010f)) / 1.35f)
|
||||
.coerceIn(-1f, 1f)
|
||||
val tonalWindow = smoothStep(0.020f, 0.065f, sceneLinear) *
|
||||
(1f - smoothStep(0.55f, 0.85f, sceneLinear))
|
||||
val adjusted = baseOutput * (1f + strength * signedDistance * tonalWindow)
|
||||
return adjusted.coerceIn(0f, 1f)
|
||||
}
|
||||
|
||||
private fun photonAdaptiveShadowLiftStrength(
|
||||
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)
|
||||
val globalDarkArea = max(
|
||||
1f - smoothStep(0.075f, 0.165f, global.p50),
|
||||
0.75f * (1f - smoothStep(0.24f, 0.50f, global.p90))
|
||||
)
|
||||
val localDarkArea = max(
|
||||
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)
|
||||
}
|
||||
|
||||
private fun photonPgtmInputWeights(inputScale: Float): FloatArray {
|
||||
val scale = sanitizeInputScale(inputScale)
|
||||
return FloatArray(MAP_INPUT_WEIGHT_COUNT) { index ->
|
||||
BASE_INPUT_WEIGHTS[index] * scale
|
||||
}
|
||||
}
|
||||
|
||||
private fun tableInputForIndex(index: Int, pointCount: Int): Float {
|
||||
if (pointCount <= 1) return 0f
|
||||
return if (index == pointCount - 1) {
|
||||
1f
|
||||
} else {
|
||||
index.toFloat() / pointCount.toFloat()
|
||||
}
|
||||
}
|
||||
|
||||
private fun sanitizeInputScale(inputScale: Float): Float {
|
||||
return inputScale.takeIf { it.isFinite() }
|
||||
?.coerceIn(1f / MAX_SCENE_MAX, 1.0f)
|
||||
?: 1.0f
|
||||
}
|
||||
|
||||
private fun smoothStep(edge0: Float, edge1: Float, x: Float): Float {
|
||||
val t = ((x - edge0) / max(edge1 - edge0, 1e-6f)).coerceIn(0f, 1f)
|
||||
return t * t * (3f - 2f * t)
|
||||
}
|
||||
|
||||
private fun lerp(a: Float, b: Float, t: Float): Float {
|
||||
return a + (b - a) * min(max(t, 0f), 1f)
|
||||
}
|
||||
|
||||
private fun log2(value: Float): Float {
|
||||
return (ln(max(value, 1e-6f).toDouble()) / ln(2.0)).toFloat()
|
||||
}
|
||||
|
||||
private fun safe01(value: Float): Float {
|
||||
return value.takeIf { it.isFinite() }?.coerceIn(0f, 1f) ?: 0f
|
||||
}
|
||||
|
||||
private fun safePositive(value: Float, fallback: Float): Float {
|
||||
return value.takeIf { it.isFinite() && it > 0f } ?: fallback
|
||||
}
|
||||
|
||||
private data class PhotonPgtmCellStats(
|
||||
val p10: Float,
|
||||
val p50: Float,
|
||||
val p90: Float,
|
||||
val p98: Float,
|
||||
val highlightFraction: Float,
|
||||
val tailP95: Float,
|
||||
val tailP99: Float,
|
||||
val maxInput: Float,
|
||||
val sampleWeight: Float,
|
||||
)
|
||||
}
|
||||
@@ -1,9 +1,14 @@
|
||||
package com.hinnka.mycamera.raw
|
||||
|
||||
internal object DngProfileToneCurve {
|
||||
const val GOOGLE_HDR_PROFILE_NAME = "Google Pixel HDR Tone Map"
|
||||
const val PHOTON_PGTM_PROFILE_NAME = "Photon PGTM"
|
||||
|
||||
private const val POINT_TOLERANCE = 2e-4f
|
||||
private const val LUT_TOLERANCE = 2e-3f
|
||||
|
||||
private val LINEAR_TONE_CURVE_POINTS = floatArrayOf(0f, 0f, 1f, 1f)
|
||||
|
||||
private val GOOGLE_HDR_TONE_CURVE_Y = floatArrayOf(
|
||||
0f, 0.000817775668f, 0.00170822139f, 0.00267076469f, 0.0037048338f, 0.00480985641f, 0.00598525954f, 0.00723047229f,
|
||||
0.00854492188f, 0.00992803555f, 0.0113792419f, 0.0128979683f, 0.0144836418f, 0.0161356926f, 0.017853545f, 0.019636631f,
|
||||
@@ -75,6 +80,31 @@ internal object DngProfileToneCurve {
|
||||
0.97638f, 0.99517f, 0.98425f, 0.99686f, 0.99213f, 0.99845f, 1f, 1f
|
||||
)
|
||||
|
||||
// Fixed neutral base curve. Scene-dependent contrast and exposure belong to PGTM.
|
||||
private val PHOTON_PGTM_TONE_CURVE_POINTS = floatArrayOf(
|
||||
0.00000000f, 0.000000000f,
|
||||
0.00390625f, 0.000012401f,
|
||||
0.00781250f, 0.000072635f,
|
||||
0.01171875f, 0.000206685f,
|
||||
0.01562500f, 0.000553325f,
|
||||
0.01953125f, 0.001360578f,
|
||||
0.02343750f, 0.002622200f,
|
||||
0.02734375f, 0.004144829f,
|
||||
0.03125000f, 0.005831674f,
|
||||
0.04687500f, 0.013821328f,
|
||||
0.06250000f, 0.023228984f,
|
||||
0.09375000f, 0.045079457f,
|
||||
0.12500000f, 0.069945026f,
|
||||
0.17968750f, 0.118763626f,
|
||||
0.25000000f, 0.188884780f,
|
||||
0.37500000f, 0.327727005f,
|
||||
0.50000000f, 0.479043320f,
|
||||
0.62500000f, 0.636591673f,
|
||||
0.75000000f, 0.779041231f,
|
||||
0.87500000f, 0.896886647f,
|
||||
1.00000000f, 1.000000000f
|
||||
)
|
||||
|
||||
fun googleHdrToneCurvePoints(): FloatArray {
|
||||
return FloatArray(GOOGLE_HDR_TONE_CURVE_Y.size * 2) { index ->
|
||||
val pointIndex = index / 2
|
||||
@@ -90,6 +120,22 @@ internal object DngProfileToneCurve {
|
||||
return DcpToneCurve(googleHdrToneCurvePoints()).toLut(sampleCount)
|
||||
}
|
||||
|
||||
fun linearToneCurvePoints(): FloatArray {
|
||||
return LINEAR_TONE_CURVE_POINTS.copyOf()
|
||||
}
|
||||
|
||||
fun linearToneCurveLut(sampleCount: Int = 256): FloatArray {
|
||||
return DcpToneCurve(linearToneCurvePoints()).toLut(sampleCount)
|
||||
}
|
||||
|
||||
fun photonPgtmToneCurvePoints(): FloatArray {
|
||||
return PHOTON_PGTM_TONE_CURVE_POINTS.copyOf()
|
||||
}
|
||||
|
||||
fun photonPgtmToneCurveLut(sampleCount: Int = 256): FloatArray {
|
||||
return DcpToneCurve(photonPgtmToneCurvePoints()).toLut(sampleCount)
|
||||
}
|
||||
|
||||
fun oppoEmbeddedToneCurvePoints(): FloatArray {
|
||||
return OPPO_EMBEDDED_TONE_CURVE_POINTS.copyOf()
|
||||
}
|
||||
@@ -120,6 +166,28 @@ internal object DngProfileToneCurve {
|
||||
return isOppoEmbeddedToneCurveLut(toneCurve.toLut())
|
||||
}
|
||||
|
||||
fun isLinearToneCurve(toneCurve: DcpToneCurve?): Boolean {
|
||||
if (toneCurve?.isValid != true) return false
|
||||
val linearPoints = LINEAR_TONE_CURVE_POINTS
|
||||
if (toneCurve.points.size == linearPoints.size) {
|
||||
return toneCurve.points.indices.all { index ->
|
||||
kotlin.math.abs(toneCurve.points[index] - linearPoints[index]) <= POINT_TOLERANCE
|
||||
}
|
||||
}
|
||||
return isLinearToneCurveLut(toneCurve.toLut())
|
||||
}
|
||||
|
||||
fun isPhotonPgtmToneCurve(toneCurve: DcpToneCurve?): Boolean {
|
||||
if (toneCurve?.isValid != true) return false
|
||||
val photonPoints = photonPgtmToneCurvePoints()
|
||||
if (toneCurve.points.size == photonPoints.size) {
|
||||
return toneCurve.points.indices.all { index ->
|
||||
kotlin.math.abs(toneCurve.points[index] - photonPoints[index]) <= POINT_TOLERANCE
|
||||
}
|
||||
}
|
||||
return isPhotonPgtmToneCurveLut(toneCurve.toLut())
|
||||
}
|
||||
|
||||
fun isGoogleHdrToneCurveLut(lut: FloatArray?): Boolean {
|
||||
if (lut == null || lut.isEmpty()) return false
|
||||
val googleLut = googleHdrToneCurveLut(lut.size)
|
||||
@@ -136,4 +204,20 @@ internal object DngProfileToneCurve {
|
||||
}
|
||||
}
|
||||
|
||||
fun isLinearToneCurveLut(lut: FloatArray?): Boolean {
|
||||
if (lut == null || lut.isEmpty()) return false
|
||||
val linearLut = linearToneCurveLut(lut.size)
|
||||
return lut.indices.all { index ->
|
||||
kotlin.math.abs(lut[index] - linearLut[index]) <= LUT_TOLERANCE
|
||||
}
|
||||
}
|
||||
|
||||
fun isPhotonPgtmToneCurveLut(lut: FloatArray?): Boolean {
|
||||
if (lut == null || lut.isEmpty()) return false
|
||||
val photonLut = photonPgtmToneCurveLut(lut.size)
|
||||
return lut.indices.all { index ->
|
||||
kotlin.math.abs(lut[index] - photonLut[index]) <= LUT_TOLERANCE
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1410,35 +1410,59 @@ class RawDemosaicProcessor {
|
||||
thumbnail = capturePreviewThumbnail
|
||||
)
|
||||
val embeddedDngProfileName = embeddedDngRenderPlan?.profileName
|
||||
val embeddedGoogleToneCurveLut = embeddedDngRenderPlan?.toneCurveLut
|
||||
?.takeIf {
|
||||
DngProfileToneCurve.isGoogleHdrToneCurveLut(it) ||
|
||||
DngEmbeddedProfile.isGoogleProfileName(embeddedDngProfileName)
|
||||
val embeddedProfileToneCurveLut = embeddedDngRenderPlan?.toneCurveLut
|
||||
val embeddedProfileToneMapMode = when {
|
||||
embeddedProfileToneCurveLut != null &&
|
||||
(DngProfileToneCurve.isGoogleHdrToneCurveLut(embeddedProfileToneCurveLut) ||
|
||||
DngEmbeddedProfile.isGoogleProfileName(embeddedDngProfileName)) -> {
|
||||
RawProfileToneMapMode.GooglePixel
|
||||
}
|
||||
|
||||
embeddedProfileToneCurveLut != null &&
|
||||
DngProfileToneCurve.isPhotonPgtmToneCurveLut(embeddedProfileToneCurveLut) &&
|
||||
DngEmbeddedProfile.isPhotonPgtmProfileName(embeddedDngProfileName) -> {
|
||||
RawProfileToneMapMode.PhotonPgtm
|
||||
}
|
||||
|
||||
else -> RawProfileToneMapMode.Default
|
||||
}
|
||||
val embeddedProfileGainTableMap = actualMetadata.profileGainTableMap?.takeIf { it.isValid }
|
||||
val embeddedDngHdrToneMapAvailable = embeddedGoogleToneCurveLut != null &&
|
||||
val embeddedDngHdrToneMapAvailable = embeddedProfileToneMapMode != RawProfileToneMapMode.Default &&
|
||||
embeddedProfileGainTableMap != null
|
||||
val inactiveEmbeddedProfileGainTableMapAvailable = embeddedProfileGainTableMap != null &&
|
||||
!embeddedDngHdrToneMapAvailable
|
||||
val normalizedToneMappingParameters = rawToneMappingParameters.normalized()
|
||||
val googlePixelToneMapRequested = useAdobeProfilePipeline &&
|
||||
normalizedToneMappingParameters.useGooglePixelToneMap
|
||||
val photonPgtmToneMapRequested = useAdobeProfilePipeline &&
|
||||
normalizedToneMappingParameters.usePhotonPgtmToneMap
|
||||
val oppoMasterToneMapRequested = useAdobeProfilePipeline &&
|
||||
normalizedToneMappingParameters.useOppoMasterToneMap
|
||||
val requestedProfileToneMapMode = when {
|
||||
googlePixelToneMapRequested -> RawProfileToneMapMode.GooglePixel
|
||||
photonPgtmToneMapRequested -> RawProfileToneMapMode.PhotonPgtm
|
||||
else -> RawProfileToneMapMode.Default
|
||||
}
|
||||
val profileGainToneMapRequested = requestedProfileToneMapMode == RawProfileToneMapMode.GooglePixel ||
|
||||
requestedProfileToneMapMode == RawProfileToneMapMode.PhotonPgtm
|
||||
val embeddedDngHdrToneMapDisabledByUser = embeddedDngHdrToneMapAvailable &&
|
||||
useAdobeProfilePipeline &&
|
||||
!oppoMasterToneMapRequested &&
|
||||
!googlePixelToneMapRequested
|
||||
requestedProfileToneMapMode == RawProfileToneMapMode.Default
|
||||
val embeddedDngHdrToneMapDisabledByOppo = embeddedDngHdrToneMapAvailable &&
|
||||
oppoMasterToneMapRequested
|
||||
val embeddedDngHdrToneMapModeMismatch = embeddedDngHdrToneMapAvailable &&
|
||||
profileGainToneMapRequested &&
|
||||
requestedProfileToneMapMode != embeddedProfileToneMapMode
|
||||
if (embeddedDngHdrToneMapAvailable) {
|
||||
PLog.d(
|
||||
TAG,
|
||||
"Embedded DNG PGTM/ProfileToneCurve available: " +
|
||||
"mode=$embeddedProfileToneMapMode " +
|
||||
"tag=${embeddedProfileGainTableMap.sourceTag} " +
|
||||
"grid=${embeddedProfileGainTableMap.mapPointsH}x" +
|
||||
"${embeddedProfileGainTableMap.mapPointsV}x${embeddedProfileGainTableMap.mapPointsN} " +
|
||||
"googleTone=${normalizedToneMappingParameters.useGooglePixelToneMap}"
|
||||
"requested=${normalizedToneMappingParameters.profileToneMapMode}"
|
||||
)
|
||||
}
|
||||
val embeddedDngHdrToneMapOverriddenByDcp = embeddedDngHdrToneMapAvailable &&
|
||||
@@ -1447,14 +1471,15 @@ class RawDemosaicProcessor {
|
||||
resolvedDcpRenderPlan?.toneCurveLut != null
|
||||
val embeddedDngHdrToneMapRenderable = embeddedDngHdrToneMapAvailable &&
|
||||
useAdobeProfilePipeline &&
|
||||
googlePixelToneMapRequested &&
|
||||
requestedProfileToneMapMode == embeddedProfileToneMapMode &&
|
||||
!embeddedDngHdrToneMapOverriddenByDcp &&
|
||||
!embeddedDngHdrToneMapDisabledByUser &&
|
||||
!embeddedDngHdrToneMapDisabledByOppo
|
||||
if (embeddedDngHdrToneMapAvailable && !embeddedDngHdrToneMapRenderable) {
|
||||
val reason = when {
|
||||
embeddedDngHdrToneMapDisabledByUser -> "Pixel-style tone map disabled for this photo"
|
||||
embeddedDngHdrToneMapDisabledByUser -> "profile tone map disabled for this photo"
|
||||
embeddedDngHdrToneMapDisabledByOppo -> "OPPO master tone map requested"
|
||||
embeddedDngHdrToneMapModeMismatch -> "requested profile tone map $requestedProfileToneMapMode"
|
||||
!useAdobeProfilePipeline -> "color engine $colorEngine does not use Adobe/DNG profile tone map"
|
||||
embeddedDngHdrToneMapOverriddenByDcp -> "selected DCP has tone curve: ${resolvedDcpRenderPlan.profileName}"
|
||||
else -> "current render pipeline does not use embedded DNG HDR tone map"
|
||||
@@ -1472,24 +1497,24 @@ class RawDemosaicProcessor {
|
||||
"Embedded DNG ProfileGainTableMap ignored: profile=$embeddedDngProfileName"
|
||||
)
|
||||
}
|
||||
val requestedGeneratedPixelToneMap = googlePixelToneMapRequested &&
|
||||
!embeddedDngHdrToneMapAvailable
|
||||
val generatedPixelToneMapOverriddenByDcp = requestedGeneratedPixelToneMap &&
|
||||
val requestedGeneratedProfileGainToneMap = profileGainToneMapRequested &&
|
||||
(!embeddedDngHdrToneMapAvailable || embeddedProfileToneMapMode != requestedProfileToneMapMode)
|
||||
val generatedProfileGainToneMapOverriddenByDcp = requestedGeneratedProfileGainToneMap &&
|
||||
hasDcpSelection &&
|
||||
resolvedDcpRenderPlan?.toneCurveLut != null
|
||||
val generatePixelToneMap = requestedGeneratedPixelToneMap &&
|
||||
!generatedPixelToneMapOverriddenByDcp
|
||||
if (generatedPixelToneMapOverriddenByDcp) {
|
||||
val generateProfileGainToneMap = requestedGeneratedProfileGainToneMap &&
|
||||
!generatedProfileGainToneMapOverriddenByDcp
|
||||
if (generatedProfileGainToneMapOverriddenByDcp) {
|
||||
PLog.d(
|
||||
TAG,
|
||||
"Generated Pixel-style PGTM/ProfileToneCurve not rendered because selected DCP has tone curve: " +
|
||||
"Generated $requestedProfileToneMapMode PGTM/ProfileToneCurve not rendered because selected DCP has tone curve: " +
|
||||
"profile=${resolvedDcpRenderPlan.profileName}"
|
||||
)
|
||||
}
|
||||
if (embeddedDngHdrToneMapRenderable) {
|
||||
PLog.d(TAG, "Using embedded Pixel-style DNG PGTM/ProfileToneCurve")
|
||||
PLog.d(TAG, "Using embedded $embeddedProfileToneMapMode DNG PGTM/ProfileToneCurve")
|
||||
}
|
||||
if (generatePixelToneMap) {
|
||||
if (generateProfileGainToneMap) {
|
||||
val generatedProfileGainTableMap = RawProfileGainTableMapBuilder.build(
|
||||
rawData = actualRawData,
|
||||
width = actualWidth,
|
||||
@@ -1497,26 +1522,28 @@ class RawDemosaicProcessor {
|
||||
rowStride = actualRowStride,
|
||||
metadata = actualMetadata,
|
||||
samplesPerPixel = actualSamplesPerPixel,
|
||||
statsBounds = outputSourceBounds
|
||||
statsBounds = outputSourceBounds,
|
||||
profileToneMapMode = requestedProfileToneMapMode
|
||||
)
|
||||
if (generatedProfileGainTableMap?.isValid == true) {
|
||||
actualMetadata = actualMetadata.copy(profileGainTableMap = generatedProfileGainTableMap)
|
||||
PLog.d(
|
||||
TAG,
|
||||
"Generated Google Pixel tone map PGTM for RAW: " +
|
||||
"Generated $requestedProfileToneMapMode PGTM for RAW: " +
|
||||
"grid=${generatedProfileGainTableMap.mapPointsH}x" +
|
||||
"${generatedProfileGainTableMap.mapPointsV}x" +
|
||||
"${generatedProfileGainTableMap.mapPointsN}"
|
||||
)
|
||||
DngPgtmDebugRewriter.rewriteGeneratedPgtmOnRawRefreshIfEnabled(
|
||||
dngFile = dngFile,
|
||||
profileGainTableMap = generatedProfileGainTableMap
|
||||
profileGainTableMap = generatedProfileGainTableMap,
|
||||
profileToneMapMode = requestedProfileToneMapMode
|
||||
)
|
||||
} else {
|
||||
PLog.w(TAG, "Google Pixel tone map requested but PGTM stats generation failed")
|
||||
PLog.w(TAG, "$requestedProfileToneMapMode requested but PGTM stats generation failed")
|
||||
}
|
||||
}
|
||||
val googlePixelToneMapActive = (embeddedDngHdrToneMapRenderable || generatePixelToneMap) &&
|
||||
val profileGainToneMapActive = (embeddedDngHdrToneMapRenderable || generateProfileGainToneMap) &&
|
||||
actualMetadata.profileGainTableMap?.isValid == true
|
||||
val oppoMasterToneMapActive = oppoMasterToneMapRequested
|
||||
val embeddedProfileToneCurveDisabled = (
|
||||
@@ -1532,19 +1559,21 @@ class RawDemosaicProcessor {
|
||||
resolvedDcpRenderPlan,
|
||||
reason = when {
|
||||
embeddedDngHdrToneMapDisabledByOppo -> "OPPO master tone map requested"
|
||||
else -> "Pixel-style tone map disabled for this photo"
|
||||
else -> "profile tone map disabled for this photo"
|
||||
}
|
||||
)
|
||||
} else {
|
||||
resolvedDcpRenderPlan
|
||||
}
|
||||
val activeDcpRenderPlan = when {
|
||||
googlePixelToneMapActive -> {
|
||||
googlePixelToneMapRenderPlan(
|
||||
profileGainToneMapActive -> {
|
||||
profileGainToneMapRenderPlan(
|
||||
basePlan = profileBaseDcpRenderPlan,
|
||||
metadata = actualMetadata,
|
||||
workingColorSpace = profileWorkingColorSpace,
|
||||
preferredToneCurveLut = embeddedGoogleToneCurveLut.takeIf { embeddedDngHdrToneMapRenderable }
|
||||
mode = requestedProfileToneMapMode.takeIf { generateProfileGainToneMap }
|
||||
?: embeddedProfileToneMapMode,
|
||||
preferredToneCurveLut = embeddedProfileToneCurveLut.takeIf { embeddedDngHdrToneMapRenderable }
|
||||
)
|
||||
}
|
||||
oppoMasterToneMapActive -> {
|
||||
@@ -1557,11 +1586,11 @@ class RawDemosaicProcessor {
|
||||
else -> profileBaseDcpRenderPlan
|
||||
}
|
||||
val profilePlanSource = when {
|
||||
googlePixelToneMapActive -> when {
|
||||
dcpRenderPlan != null -> "provided+google-pixel-tone-map"
|
||||
rawDcpId != null -> "$rawDcpId+google-pixel-tone-map"
|
||||
!hasDcpSelection && embeddedDngRenderPlan != null -> "embedded-dng+google-pixel-tone-map"
|
||||
else -> "google-pixel-tone-map"
|
||||
profileGainToneMapActive -> when {
|
||||
dcpRenderPlan != null -> "provided+${requestedProfileToneMapMode.name.lowercase()}-tone-map"
|
||||
rawDcpId != null -> "$rawDcpId+${requestedProfileToneMapMode.name.lowercase()}-tone-map"
|
||||
!hasDcpSelection && embeddedDngRenderPlan != null -> "embedded-dng+${requestedProfileToneMapMode.name.lowercase()}-tone-map"
|
||||
else -> "${requestedProfileToneMapMode.name.lowercase()}-tone-map"
|
||||
}
|
||||
oppoMasterToneMapActive -> when {
|
||||
dcpRenderPlan != null -> "provided+oppo-master-tone-map"
|
||||
@@ -6951,16 +6980,23 @@ class RawDemosaicProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private fun googlePixelToneMapRenderPlan(
|
||||
private fun profileGainToneMapRenderPlan(
|
||||
basePlan: DcpRenderPlan?,
|
||||
metadata: RawMetadata,
|
||||
workingColorSpace: ColorSpace,
|
||||
mode: RawProfileToneMapMode,
|
||||
preferredToneCurveLut: FloatArray? = null,
|
||||
): DcpRenderPlan {
|
||||
val googleToneCurve = preferredToneCurveLut?.copyOf() ?: DngProfileToneCurve.googleHdrToneCurveLut()
|
||||
val toneCurve = preferredToneCurveLut?.copyOf() ?: when (mode) {
|
||||
RawProfileToneMapMode.PhotonPgtm -> DngProfileToneCurve.photonPgtmToneCurveLut()
|
||||
else -> DngProfileToneCurve.googleHdrToneCurveLut()
|
||||
}
|
||||
val modeName = when (mode) {
|
||||
RawProfileToneMapMode.PhotonPgtm -> DngProfileToneCurve.PHOTON_PGTM_PROFILE_NAME
|
||||
else -> "Google Pixel Tone Map"
|
||||
}
|
||||
return DcpRenderPlan(
|
||||
profileName = basePlan?.profileName?.let { "$it + Google Pixel Tone Map" }
|
||||
?: "Google Pixel Tone Map",
|
||||
profileName = basePlan?.profileName?.let { "$it + $modeName" } ?: modeName,
|
||||
workingColorSpace = basePlan?.workingColorSpace ?: workingColorSpace,
|
||||
baselineExposureOffset = basePlan?.baselineExposureOffset ?: 0f,
|
||||
defaultBlackRender = DcpDefaultBlackRender.None,
|
||||
@@ -6968,7 +7004,7 @@ class RawDemosaicProcessor {
|
||||
cameraWhite = basePlan?.cameraWhite ?: metadata.cameraWhite,
|
||||
hueSatMap = basePlan?.hueSatMap,
|
||||
lookTable = basePlan?.lookTable,
|
||||
toneCurveLut = googleToneCurve
|
||||
toneCurveLut = toneCurve
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ internal object RawProfileGainTableMapBuilder {
|
||||
metadata: RawMetadata,
|
||||
samplesPerPixel: Int = 1,
|
||||
statsBounds: Rect? = null,
|
||||
profileToneMapMode: RawProfileToneMapMode = RawProfileToneMapMode.GooglePixel,
|
||||
): DngProfileGainTableMap? {
|
||||
val stats = buildPackedCellStats(
|
||||
rawData = rawData,
|
||||
@@ -32,13 +33,27 @@ internal object RawProfileGainTableMapBuilder {
|
||||
statsBounds = statsBounds
|
||||
) ?: return null
|
||||
val diagnosticBand = DngPgtmDiagnostic.activeBandForSource(TAG)
|
||||
return DngHdrProfileGainTableGenerator.forCellStats(
|
||||
width = width,
|
||||
height = height,
|
||||
baselineExposureEv = DngBaselineExposure.sanitize(metadata.baselineExposure),
|
||||
packedCellStats = stats,
|
||||
diagnosticBand = diagnosticBand
|
||||
)
|
||||
val baselineExposureEv = DngBaselineExposure.sanitize(metadata.baselineExposure)
|
||||
return when (profileToneMapMode) {
|
||||
RawProfileToneMapMode.GooglePixel -> DngHdrProfileGainTableGenerator.forCellStats(
|
||||
width = width,
|
||||
height = height,
|
||||
baselineExposureEv = baselineExposureEv,
|
||||
packedCellStats = stats,
|
||||
diagnosticBand = diagnosticBand
|
||||
)
|
||||
|
||||
RawProfileToneMapMode.PhotonPgtm -> DngPhotonProfileGainTableGenerator.forCellStats(
|
||||
width = width,
|
||||
height = height,
|
||||
baselineExposureEv = baselineExposureEv,
|
||||
packedCellStats = stats,
|
||||
diagnosticBand = diagnosticBand
|
||||
)
|
||||
|
||||
RawProfileToneMapMode.Default,
|
||||
RawProfileToneMapMode.OppoMaster -> null
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildPackedCellStats(
|
||||
|
||||
@@ -8,11 +8,13 @@ data class RawToneMappingParameters(
|
||||
val filmicBlackRelativeExposure: Float = FILMIC_BLACK_RELATIVE_EXPOSURE_DEFAULT,
|
||||
val filmicWhiteRelativeExposure: Float = FILMIC_WHITE_RELATIVE_EXPOSURE_DEFAULT,
|
||||
val useGooglePixelToneMap: Boolean = false,
|
||||
val useOppoMasterToneMap: Boolean = false
|
||||
val useOppoMasterToneMap: Boolean = false,
|
||||
val usePhotonPgtmToneMap: Boolean = false
|
||||
) {
|
||||
val profileToneMapMode: RawProfileToneMapMode
|
||||
get() = when {
|
||||
useOppoMasterToneMap -> RawProfileToneMapMode.OppoMaster
|
||||
usePhotonPgtmToneMap -> RawProfileToneMapMode.PhotonPgtm
|
||||
useGooglePixelToneMap -> RawProfileToneMapMode.GooglePixel
|
||||
else -> RawProfileToneMapMode.Default
|
||||
}
|
||||
@@ -35,7 +37,8 @@ data class RawToneMappingParameters(
|
||||
FILMIC_WHITE_RELATIVE_EXPOSURE_MAX
|
||||
)
|
||||
val oppoTone = useOppoMasterToneMap
|
||||
val googleTone = useGooglePixelToneMap && !oppoTone
|
||||
val photonTone = usePhotonPgtmToneMap && !oppoTone
|
||||
val googleTone = useGooglePixelToneMap && !oppoTone && !photonTone
|
||||
return copy(
|
||||
agxBlackRelativeExposure = minOf(blackAgx, whiteAgx - MIN_DYNAMIC_RANGE_EV),
|
||||
agxWhiteRelativeExposure = maxOf(whiteAgx, blackAgx + MIN_DYNAMIC_RANGE_EV),
|
||||
@@ -44,28 +47,40 @@ data class RawToneMappingParameters(
|
||||
filmicBlackRelativeExposure = minOf(blackFilmic, whiteFilmic - MIN_DYNAMIC_RANGE_EV),
|
||||
filmicWhiteRelativeExposure = maxOf(whiteFilmic, blackFilmic + MIN_DYNAMIC_RANGE_EV),
|
||||
useGooglePixelToneMap = googleTone,
|
||||
useOppoMasterToneMap = oppoTone
|
||||
useOppoMasterToneMap = oppoTone,
|
||||
usePhotonPgtmToneMap = photonTone
|
||||
)
|
||||
}
|
||||
|
||||
fun withGooglePixelToneMap(enabled: Boolean): RawToneMappingParameters {
|
||||
return copy(
|
||||
useGooglePixelToneMap = enabled,
|
||||
useOppoMasterToneMap = if (enabled) false else useOppoMasterToneMap
|
||||
useOppoMasterToneMap = if (enabled) false else useOppoMasterToneMap,
|
||||
usePhotonPgtmToneMap = if (enabled) false else usePhotonPgtmToneMap
|
||||
).normalized()
|
||||
}
|
||||
|
||||
fun withOppoMasterToneMap(enabled: Boolean): RawToneMappingParameters {
|
||||
return copy(
|
||||
useOppoMasterToneMap = enabled,
|
||||
useGooglePixelToneMap = if (enabled) false else useGooglePixelToneMap
|
||||
useGooglePixelToneMap = if (enabled) false else useGooglePixelToneMap,
|
||||
usePhotonPgtmToneMap = if (enabled) false else usePhotonPgtmToneMap
|
||||
).normalized()
|
||||
}
|
||||
|
||||
fun withPhotonPgtmToneMap(enabled: Boolean): RawToneMappingParameters {
|
||||
return copy(
|
||||
usePhotonPgtmToneMap = enabled,
|
||||
useGooglePixelToneMap = if (enabled) false else useGooglePixelToneMap,
|
||||
useOppoMasterToneMap = if (enabled) false else useOppoMasterToneMap
|
||||
).normalized()
|
||||
}
|
||||
|
||||
fun withProfileToneMapMode(mode: RawProfileToneMapMode): RawToneMappingParameters {
|
||||
return copy(
|
||||
useGooglePixelToneMap = mode == RawProfileToneMapMode.GooglePixel,
|
||||
useOppoMasterToneMap = mode == RawProfileToneMapMode.OppoMaster
|
||||
useOppoMasterToneMap = mode == RawProfileToneMapMode.OppoMaster,
|
||||
usePhotonPgtmToneMap = mode == RawProfileToneMapMode.PhotonPgtm
|
||||
).normalized()
|
||||
}
|
||||
|
||||
@@ -100,4 +115,5 @@ enum class RawProfileToneMapMode {
|
||||
Default,
|
||||
OppoMaster,
|
||||
GooglePixel,
|
||||
PhotonPgtm,
|
||||
}
|
||||
@@ -444,6 +444,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.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),
|
||||
),
|
||||
|
||||
@@ -108,6 +108,7 @@ fun PresetEditorScreen(
|
||||
}
|
||||
var rawGooglePixelToneMap by remember { mutableStateOf(sourcePreset?.rawGooglePixelToneMap ?: false) }
|
||||
var rawOppoMasterToneMap by remember { mutableStateOf(sourcePreset?.rawOppoMasterToneMap ?: false) }
|
||||
var rawPhotonPgtmToneMap by remember { mutableStateOf(sourcePreset?.rawPhotonPgtmToneMap ?: false) }
|
||||
var rawSpectralFilmStock by remember { mutableStateOf(sourcePreset?.rawSpectralFilmStock ?: "kodak_portra_400") }
|
||||
var rawSpectralFilmPrint by remember { mutableStateOf(sourcePreset?.rawSpectralFilmPrint ?: "kodak_2383") }
|
||||
var rawDROMode by remember { mutableStateOf(sourcePreset?.rawDROMode ?: "OFF") }
|
||||
@@ -147,6 +148,7 @@ fun PresetEditorScreen(
|
||||
rawRenderingEngine = rawRenderingEngine.name,
|
||||
rawGooglePixelToneMap = rawGooglePixelToneMap,
|
||||
rawOppoMasterToneMap = rawOppoMasterToneMap,
|
||||
rawPhotonPgtmToneMap = rawPhotonPgtmToneMap,
|
||||
rawSpectralFilmStock = rawSpectralFilmStock,
|
||||
rawSpectralFilmPrint = rawSpectralFilmPrint,
|
||||
rawDROMode = rawDROMode,
|
||||
@@ -442,11 +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.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
|
||||
rawGooglePixelToneMap -> RawProfileToneMapMode.GooglePixel
|
||||
else -> RawProfileToneMapMode.Default
|
||||
}
|
||||
@@ -464,6 +468,7 @@ fun PresetEditorScreen(
|
||||
?: RawProfileToneMapMode.Default
|
||||
rawGooglePixelToneMap = selectedMode == RawProfileToneMapMode.GooglePixel
|
||||
rawOppoMasterToneMap = selectedMode == RawProfileToneMapMode.OppoMaster
|
||||
rawPhotonPgtmToneMap = selectedMode == RawProfileToneMapMode.PhotonPgtm
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -273,6 +273,8 @@ object RawProcessor {
|
||||
cfaCorrectionMode: String? = null,
|
||||
baselineExposureEv: Float = 0f,
|
||||
profileGainTableMap: DngProfileGainTableMap? = null,
|
||||
profileName: String? = null,
|
||||
profileToneCurve: FloatArray? = null,
|
||||
imageLayout: SuperResolutionDngWriter.ImageLayout = SuperResolutionDngWriter.ImageLayout.CFA,
|
||||
compression: SuperResolutionDngWriter.Compression = SuperResolutionDngWriter.Compression.UNCOMPRESSED,
|
||||
inputRowStepSamples: Int? = null,
|
||||
@@ -317,6 +319,8 @@ object RawProcessor {
|
||||
customWhiteLevel = customWhiteLevel,
|
||||
baselineExposureEv = baselineExposureEv,
|
||||
profileGainTableMap = profileGainTableMap,
|
||||
profileName = profileName,
|
||||
profileToneCurve = profileToneCurve,
|
||||
imageLayout = imageLayout,
|
||||
compression = compression,
|
||||
inputRowStepSamples = inputRowStepSamples,
|
||||
|
||||
@@ -93,6 +93,7 @@ object SuperResolutionDngWriter {
|
||||
private const val TAG_DEFAULT_CROP_SIZE = 50720
|
||||
private const val TAG_COLOR_MATRIX_1 = 50721
|
||||
private const val TAG_COLOR_MATRIX_2 = 50722
|
||||
private const val TAG_PROFILE_NAME = 50936
|
||||
private const val TAG_PROFILE_TONE_CURVE = 50940
|
||||
private const val TAG_AS_SHOT_NEUTRAL = 50728
|
||||
private const val TAG_BASELINE_EXPOSURE = 50730
|
||||
@@ -136,6 +137,8 @@ object SuperResolutionDngWriter {
|
||||
customWhiteLevel: Float? = null,
|
||||
baselineExposureEv: Float = 0f,
|
||||
profileGainTableMap: DngProfileGainTableMap? = null,
|
||||
profileName: String? = null,
|
||||
profileToneCurve: FloatArray? = null,
|
||||
imageLayout: ImageLayout = ImageLayout.CFA,
|
||||
compression: Compression = Compression.UNCOMPRESSED,
|
||||
inputRowStepSamples: Int? = null,
|
||||
@@ -230,6 +233,8 @@ object SuperResolutionDngWriter {
|
||||
imageByteCount = imageByteCount,
|
||||
baselineExposureEv = baselineExposureEv,
|
||||
profileGainTableMap = profileGainTableMap?.takeIf { it.isValid },
|
||||
profileName = profileName,
|
||||
profileToneCurve = profileToneCurve,
|
||||
imageLayout = imageLayout,
|
||||
compression = compression,
|
||||
valueDomain = valueDomain,
|
||||
@@ -269,6 +274,8 @@ object SuperResolutionDngWriter {
|
||||
imageByteCount: Long,
|
||||
baselineExposureEv: Float,
|
||||
profileGainTableMap: DngProfileGainTableMap?,
|
||||
profileName: String?,
|
||||
profileToneCurve: FloatArray?,
|
||||
imageLayout: ImageLayout,
|
||||
compression: Compression,
|
||||
valueDomain: RawProcessor.RawBufferValueDomain,
|
||||
@@ -386,7 +393,10 @@ object SuperResolutionDngWriter {
|
||||
}
|
||||
add(sRationalArray(TAG_BASELINE_EXPOSURE, listOf(baselineExposureEv.toDouble())))
|
||||
if (profileGainTableMap != null) {
|
||||
add(floatArray(TAG_PROFILE_TONE_CURVE, DngProfileToneCurve.googleHdrToneCurvePoints()))
|
||||
add(ascii(TAG_PROFILE_NAME, profileName?.takeIf { it.isNotBlank() }
|
||||
?: DngProfileToneCurve.GOOGLE_HDR_PROFILE_NAME))
|
||||
add(floatArray(TAG_PROFILE_TONE_CURVE, profileToneCurve?.takeIf { it.size >= 4 }
|
||||
?: DngProfileToneCurve.googleHdrToneCurvePoints()))
|
||||
}
|
||||
add(short(TAG_CALIBRATION_ILLUMINANT_1, illuminant1))
|
||||
if (illuminant2 != null && colorMatrix2 != null) {
|
||||
|
||||
@@ -155,6 +155,7 @@ private data class PresetMatchSnapshot(
|
||||
val rawRenderingEngine: RawRenderingEngine,
|
||||
val rawGooglePixelToneMap: Boolean,
|
||||
val rawOppoMasterToneMap: Boolean,
|
||||
val rawPhotonPgtmToneMap: Boolean,
|
||||
val rawSpectralFilmStock: String?,
|
||||
val rawSpectralFilmPrint: String?,
|
||||
val rawDROMode: String,
|
||||
@@ -179,6 +180,7 @@ private data class PresetMatchSnapshot(
|
||||
rawRenderingEngine == RawRenderingEngine.fromPersistedName(preset.rawRenderingEngine) &&
|
||||
rawGooglePixelToneMap == preset.rawGooglePixelToneMap &&
|
||||
rawOppoMasterToneMap == preset.rawOppoMasterToneMap &&
|
||||
rawPhotonPgtmToneMap == preset.rawPhotonPgtmToneMap &&
|
||||
rawSpectralFilmStock == preset.rawSpectralFilmStock &&
|
||||
rawSpectralFilmPrint == preset.rawSpectralFilmPrint &&
|
||||
rawDROMode == preset.rawDROMode &&
|
||||
@@ -220,6 +222,12 @@ private data class PresetMatchSnapshot(
|
||||
"preset=${preset.rawOppoMasterToneMap}"
|
||||
)
|
||||
}
|
||||
if (rawPhotonPgtmToneMap != preset.rawPhotonPgtmToneMap) {
|
||||
add(
|
||||
"rawPhotonPgtmToneMap current=$rawPhotonPgtmToneMap " +
|
||||
"preset=${preset.rawPhotonPgtmToneMap}"
|
||||
)
|
||||
}
|
||||
if (rawSpectralFilmStock != preset.rawSpectralFilmStock) {
|
||||
add("rawSpectralFilmStock current=$rawSpectralFilmStock preset=${preset.rawSpectralFilmStock}")
|
||||
}
|
||||
@@ -267,6 +275,7 @@ private data class CameraFeatureUpdate(
|
||||
val rawRenderingEngine: SettingValue<RawRenderingEngine>? = null,
|
||||
val rawGooglePixelToneMap: SettingValue<Boolean>? = null,
|
||||
val rawOppoMasterToneMap: SettingValue<Boolean>? = null,
|
||||
val rawPhotonPgtmToneMap: SettingValue<Boolean>? = null,
|
||||
val rawSpectralFilmStock: SettingValue<String?>? = null,
|
||||
val rawSpectralFilmPrint: SettingValue<String?>? = null,
|
||||
val droMode: SettingValue<String>? = null,
|
||||
@@ -391,6 +400,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
rawRenderingEngine = saved.rawRenderingEngine,
|
||||
rawGooglePixelToneMap = saved.rawGooglePixelToneMap,
|
||||
rawOppoMasterToneMap = saved.rawOppoMasterToneMap,
|
||||
rawPhotonPgtmToneMap = saved.rawPhotonPgtmToneMap,
|
||||
rawSpectralFilmStock = saved.rawSpectralFilmStock,
|
||||
rawSpectralFilmPrint = saved.rawSpectralFilmPrint,
|
||||
rawDROMode = saved.rawDROMode,
|
||||
@@ -454,6 +464,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
rawRenderingEngine = rawRenderingEngine.value.name,
|
||||
rawGooglePixelToneMap = rawToneMappingParameters.value.useGooglePixelToneMap,
|
||||
rawOppoMasterToneMap = rawToneMappingParameters.value.useOppoMasterToneMap,
|
||||
rawPhotonPgtmToneMap = rawToneMappingParameters.value.usePhotonPgtmToneMap,
|
||||
rawSpectralFilmStock = rawSpectralFilmStock.value,
|
||||
rawSpectralFilmPrint = rawSpectralFilmPrint.value,
|
||||
rawDROMode = droMode.value,
|
||||
@@ -528,6 +539,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
rawRenderingEngine = SettingValue(RawRenderingEngine.fromPersistedName(this?.rawRenderingEngine)),
|
||||
rawGooglePixelToneMap = SettingValue(this?.rawGooglePixelToneMap ?: false),
|
||||
rawOppoMasterToneMap = SettingValue(this?.rawOppoMasterToneMap ?: false),
|
||||
rawPhotonPgtmToneMap = SettingValue(this?.rawPhotonPgtmToneMap ?: false),
|
||||
rawSpectralFilmStock = SettingValue(this?.rawSpectralFilmStock),
|
||||
rawSpectralFilmPrint = SettingValue(this?.rawSpectralFilmPrint),
|
||||
droMode = SettingValue(this?.rawDROMode ?: RawProcessingPreferences.DROMode.OFF.name),
|
||||
@@ -657,7 +669,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
|
||||
val rawToneMappingUpdate = if (
|
||||
update.rawGooglePixelToneMap != null ||
|
||||
update.rawOppoMasterToneMap != null
|
||||
update.rawOppoMasterToneMap != null ||
|
||||
update.rawPhotonPgtmToneMap != null
|
||||
) {
|
||||
var toneMappingParameters = prefs.rawToneMappingParameters
|
||||
update.rawGooglePixelToneMap?.let {
|
||||
@@ -666,6 +679,9 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
update.rawOppoMasterToneMap?.let {
|
||||
toneMappingParameters = toneMappingParameters.withOppoMasterToneMap(it.value)
|
||||
}
|
||||
update.rawPhotonPgtmToneMap?.let {
|
||||
toneMappingParameters = toneMappingParameters.withPhotonPgtmToneMap(it.value)
|
||||
}
|
||||
PreferenceUpdateValue(toneMappingParameters)
|
||||
} else {
|
||||
null
|
||||
@@ -927,6 +943,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
rawRenderingEngine = rawRenderingEngine.value,
|
||||
rawGooglePixelToneMap = rawToneMappingParameters.value.useGooglePixelToneMap,
|
||||
rawOppoMasterToneMap = rawToneMappingParameters.value.useOppoMasterToneMap,
|
||||
rawPhotonPgtmToneMap = rawToneMappingParameters.value.usePhotonPgtmToneMap,
|
||||
rawSpectralFilmStock = rawSpectralFilmStock.value,
|
||||
rawSpectralFilmPrint = rawSpectralFilmPrint.value,
|
||||
rawDROMode = droMode.value,
|
||||
@@ -952,6 +969,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
rawRenderingEngine = prefs.rawRenderingEngine,
|
||||
rawGooglePixelToneMap = prefs.rawToneMappingParameters.useGooglePixelToneMap,
|
||||
rawOppoMasterToneMap = prefs.rawToneMappingParameters.useOppoMasterToneMap,
|
||||
rawPhotonPgtmToneMap = prefs.rawToneMappingParameters.usePhotonPgtmToneMap,
|
||||
rawSpectralFilmStock = prefs.rawSpectralFilmStock,
|
||||
rawSpectralFilmPrint = prefs.rawSpectralFilmPrint,
|
||||
rawDROMode = prefs.droMode,
|
||||
|
||||
@@ -2201,7 +2201,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
PLog.d(
|
||||
TAG,
|
||||
"persist RAW edit metadata: ${mediaData.id}, dro=$droMode, noise=$noiseReduction, " +
|
||||
"chromaNoise=$chromaNoiseReduction, googlePixelToneMap=${rawToneMappingParameters.useGooglePixelToneMap}"
|
||||
"chromaNoise=$chromaNoiseReduction, profileToneMap=${rawToneMappingParameters.profileToneMapMode}"
|
||||
)
|
||||
val updated = GalleryManager.updateMetadata(context, mediaData.id) { current ->
|
||||
current.copy(
|
||||
@@ -2270,7 +2270,9 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
) {
|
||||
val previous = editRawToneMappingParameters.value.normalized()
|
||||
val updated = value.normalized()
|
||||
val shouldEnableHdrGainmap = !previous.useGooglePixelToneMap && updated.useGooglePixelToneMap
|
||||
val shouldEnableHdrGainmap =
|
||||
previous.profileToneMapMode != updated.profileToneMapMode &&
|
||||
(updated.useGooglePixelToneMap || updated.usePhotonPgtmToneMap)
|
||||
editRawToneMappingParameters.value = updated
|
||||
persistRawEditMetadata(
|
||||
mediaData = mediaData,
|
||||
|
||||
@@ -751,6 +751,7 @@
|
||||
<string name="settings_raw_profile_tone_map_default">預設</string>
|
||||
<string name="settings_raw_profile_tone_map_google_pixel">Google Pixel</string>
|
||||
<string name="settings_raw_profile_tone_map_oppo_master">OPPO 大師</string>
|
||||
<string name="settings_raw_profile_tone_map_photon_pgtm">光子影調</string>
|
||||
<string name="settings_raw_agx_white_relative_exposure">AgX 白色相對曝光</string>
|
||||
<string name="settings_raw_agx_black_relative_exposure">AgX 黑色相對曝光</string>
|
||||
<string name="settings_raw_agx_shoulder">AgX 肩部</string>
|
||||
|
||||
@@ -756,6 +756,7 @@
|
||||
<string name="settings_raw_profile_tone_map_default">默认</string>
|
||||
<string name="settings_raw_profile_tone_map_google_pixel">Google Pixel</string>
|
||||
<string name="settings_raw_profile_tone_map_oppo_master">OPPO 大师</string>
|
||||
<string name="settings_raw_profile_tone_map_photon_pgtm">光子影调</string>
|
||||
<string name="settings_raw_agx_white_relative_exposure">AgX 白色相对曝光</string>
|
||||
<string name="settings_raw_agx_black_relative_exposure">AgX 黑色相对曝光</string>
|
||||
<string name="settings_raw_agx_shoulder">AgX 肩部</string>
|
||||
|
||||
@@ -756,6 +756,7 @@
|
||||
<string name="settings_raw_profile_tone_map_default">預設</string>
|
||||
<string name="settings_raw_profile_tone_map_google_pixel">Google Pixel</string>
|
||||
<string name="settings_raw_profile_tone_map_oppo_master">OPPO 大師</string>
|
||||
<string name="settings_raw_profile_tone_map_photon_pgtm">光子影調</string>
|
||||
<string name="settings_raw_agx_white_relative_exposure">AgX 白色相對曝光</string>
|
||||
<string name="settings_raw_agx_black_relative_exposure">AgX 黑色相對曝光</string>
|
||||
<string name="settings_raw_agx_shoulder">AgX 肩部</string>
|
||||
|
||||
@@ -751,6 +751,7 @@
|
||||
<string name="settings_raw_profile_tone_map_default">預設</string>
|
||||
<string name="settings_raw_profile_tone_map_google_pixel">Google Pixel</string>
|
||||
<string name="settings_raw_profile_tone_map_oppo_master">OPPO 大師</string>
|
||||
<string name="settings_raw_profile_tone_map_photon_pgtm">光子影調</string>
|
||||
<string name="settings_raw_agx_white_relative_exposure">AgX 白色相對曝光</string>
|
||||
<string name="settings_raw_agx_black_relative_exposure">AgX 黑色相對曝光</string>
|
||||
<string name="settings_raw_agx_shoulder">AgX 肩部</string>
|
||||
|
||||
@@ -740,6 +740,7 @@
|
||||
<string name="settings_raw_profile_tone_map_default">Default</string>
|
||||
<string name="settings_raw_profile_tone_map_google_pixel">Google Pixel</string>
|
||||
<string name="settings_raw_profile_tone_map_oppo_master">OPPO Master</string>
|
||||
<string name="settings_raw_profile_tone_map_photon_pgtm">Photon</string>
|
||||
<string name="settings_raw_agx_white_relative_exposure">AgX White Relative Exposure</string>
|
||||
<string name="settings_raw_agx_black_relative_exposure">AgX Black Relative Exposure</string>
|
||||
<string name="settings_raw_agx_shoulder">AgX Shoulder</string>
|
||||
|
||||
Reference in new issue
Block a user