feat: new raw pipeline (2)
This commit is contained in:
1 parent
2f02f2ff1b
commit
3ec82126d3
35 files changed
+717
-288
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -11,6 +11,7 @@ import androidx.datastore.preferences.core.stringPreferencesKey
|
||||
import androidx.datastore.preferences.preferencesDataStore
|
||||
import com.hinnka.mycamera.raw.ColorSpace
|
||||
import com.hinnka.mycamera.raw.LogCurve
|
||||
import com.hinnka.mycamera.raw.RawProfile
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import com.hinnka.mycamera.utils.DeviceUtil
|
||||
@@ -73,7 +74,7 @@ data class UserPreferences(
|
||||
val applyUltraHDR: Boolean = false, // 是否应用 Ultra HDR 策略
|
||||
val colorSpace: ColorSpace = ColorSpace.BT2020, // 默认 F-Gamut
|
||||
val logCurve: LogCurve = LogCurve.FLOG2, // 默认 F-Log2
|
||||
val rawLuts: Map<String, String> = emptyMap(),
|
||||
val rawLuts: Map<String, String> = mapOf(LogCurve.FLOG2.name to RawProfile.FUJI_PROVIA.rawLut),
|
||||
val useP010: Boolean = false,
|
||||
val useP3ColorSpace: Boolean = false,
|
||||
val autoEnableHdrForHdrCapture: Boolean = false,
|
||||
@@ -617,6 +618,14 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun saveRawProfile(rawProfile: RawProfile) {
|
||||
context.dataStore.edit { preferences ->
|
||||
preferences[COLOR_SPACE] = rawProfile.colorSpace.name
|
||||
preferences[LOG_CURVE] = rawProfile.logCurve.name
|
||||
preferences[stringPreferencesKey("${rawProfile.logCurve.name}_raw_lut")] = rawProfile.rawLut
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存是否启用 P010
|
||||
*/
|
||||
|
||||
@@ -2030,13 +2030,14 @@ object PhotoManager {
|
||||
|
||||
// 3. 处理 RAW 以生成 JPEG 预览
|
||||
var updatedMetadata = metadata
|
||||
val processedBitmap = RawDemosaicProcessor.getInstance().process(
|
||||
context,
|
||||
dngFile.absolutePath, null, null, 0,
|
||||
sharpeningValue = 0.4f,
|
||||
onMetadata = { raw ->
|
||||
updatedMetadata = updatedMetadata.merge(raw)
|
||||
}
|
||||
val processedBitmap = RawDemosaicProcessor.getInstance().process(
|
||||
context,
|
||||
dngFile.absolutePath, null, null, 0,
|
||||
sharpeningValue = 0.4f,
|
||||
denoiseValue = updatedMetadata.rawDenoiseValue,
|
||||
onMetadata = { raw ->
|
||||
updatedMetadata = updatedMetadata.merge(raw)
|
||||
}
|
||||
)
|
||||
|
||||
if (processedBitmap != null) {
|
||||
@@ -2139,6 +2140,7 @@ object PhotoManager {
|
||||
context,
|
||||
dngFile.absolutePath, metadata?.ratio, metadata?.cropRegion, 0,
|
||||
sharpeningValue = 0.4f,
|
||||
denoiseValue = (updatedMetadata ?: PhotoMetadata()).rawDenoiseValue,
|
||||
onMetadata = { raw ->
|
||||
updatedMetadata = updatedMetadata?.merge(raw) ?: PhotoMetadata().merge(raw)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import com.hinnka.mycamera.camera.AspectRatio
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import com.hinnka.mycamera.utils.PLog
|
||||
import org.json.JSONObject
|
||||
import android.util.Log
|
||||
import com.hinnka.mycamera.raw.RawMetadata
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
@@ -31,6 +30,7 @@ data class PhotoMetadata(
|
||||
val sharpening: Float? = null,
|
||||
val noiseReduction: Float? = null,
|
||||
val chromaNoiseReduction: Float? = null,
|
||||
val rawDenoiseValue: Float? = null,
|
||||
// 边框水印配置
|
||||
val frameId: String? = null,
|
||||
// 图片尺寸
|
||||
@@ -198,6 +198,7 @@ data class PhotoMetadata(
|
||||
put("sharpening", sharpening?.toDouble() ?: JSONObject.NULL)
|
||||
put("noiseReduction", noiseReduction?.toDouble() ?: JSONObject.NULL)
|
||||
put("chromaNoiseReduction", chromaNoiseReduction?.toDouble() ?: JSONObject.NULL)
|
||||
put("denoiseValue", rawDenoiseValue?.toDouble() ?: JSONObject.NULL)
|
||||
|
||||
put("frameId", frameId ?: JSONObject.NULL)
|
||||
put("width", width)
|
||||
@@ -383,6 +384,7 @@ data class PhotoMetadata(
|
||||
.toFloat(),
|
||||
chromaNoiseReduction = if (obj.isNull("chromaNoiseReduction")) null else obj.optDouble("chromaNoiseReduction")
|
||||
.toFloat(),
|
||||
rawDenoiseValue = if (obj.isNull("denoiseValue")) null else obj.optDouble("denoiseValue").toFloat(),
|
||||
frameId = if (obj.isNull("frameId")) null else obj.optString("frameId"),
|
||||
width = obj.optInt("width", 0),
|
||||
height = obj.optInt("height", 0),
|
||||
|
||||
@@ -327,7 +327,8 @@ class PhotoProcessor(
|
||||
cropRegion = metadata.cropRegion,
|
||||
rotation = metadata.rotation,
|
||||
exposureBias = metadata.exposureBias ?: 0f,
|
||||
sharpeningValue = 0.4f
|
||||
sharpeningValue = 0.4f,
|
||||
denoiseValue = metadata.rawDenoiseValue ?: 0.2f
|
||||
) ?: return@withContext null
|
||||
prepareUltraHdrSourceFromRawResult(
|
||||
context = context,
|
||||
@@ -379,7 +380,8 @@ class PhotoProcessor(
|
||||
metadata.ratio ?: AspectRatio.RATIO_4_3,
|
||||
cropRegion,
|
||||
metadata.rotation,
|
||||
metadata.exposureBias ?: 0f
|
||||
metadata.exposureBias ?: 0f,
|
||||
denoiseValue = metadata.rawDenoiseValue ?: 0.2f
|
||||
)
|
||||
|
||||
result = bitmap?.let {
|
||||
|
||||
@@ -13,6 +13,7 @@ import kotlin.math.roundToInt
|
||||
object DefaultToneCurve {
|
||||
private const val TAG = "DefaultToneCurve"
|
||||
private const val LUT_SIZE = 256
|
||||
private const val MIN_X_STEP = 1e-4f
|
||||
|
||||
fun analyze(
|
||||
neutralBuffer: FloatBuffer,
|
||||
@@ -37,7 +38,7 @@ object DefaultToneCurve {
|
||||
val midOut = (p50 + midLift).coerceAtMost((p99 - 0.08f).coerceAtLeast(p50 + 0.03f))
|
||||
val highOut = (p99 + shoulderPush).coerceIn(midOut + 0.08f, 0.985f)
|
||||
|
||||
val x = floatArrayOf(
|
||||
val rawX = floatArrayOf(
|
||||
0f,
|
||||
(p01 * 0.5f).coerceIn(0f, 0.08f),
|
||||
p01,
|
||||
@@ -45,7 +46,7 @@ object DefaultToneCurve {
|
||||
p99,
|
||||
1f
|
||||
)
|
||||
val y = floatArrayOf(
|
||||
val rawY = floatArrayOf(
|
||||
0f,
|
||||
logCurve.logToLinear(shadowToe * 0.28f).coerceAtLeast(0f),
|
||||
logCurve.logToLinear(shadowToe).coerceAtLeast(0f),
|
||||
@@ -53,15 +54,60 @@ object DefaultToneCurve {
|
||||
logCurve.logToLinear(highOut).coerceAtLeast(0f),
|
||||
logCurve.logToLinear(1f).coerceAtLeast(0f)
|
||||
)
|
||||
val (x, y) = buildStrictControlPoints(rawX, rawY)
|
||||
val pointsDescription = x.joinToString(prefix = "[", postfix = "]")
|
||||
|
||||
PLog.d(
|
||||
TAG,
|
||||
"analyze: p01=$p01 p50=$p50 p99=$p99 dr=$dynamicRange headroom=$headroom midOut=$midOut highOut=$highOut"
|
||||
"analyze: p01=$p01 p50=$p50 p99=$p99 dr=$dynamicRange headroom=$headroom midOut=$midOut highOut=$highOut points=$pointsDescription"
|
||||
)
|
||||
|
||||
return SplineInterpolator(x, y).generateLut(LUT_SIZE)
|
||||
}
|
||||
|
||||
private fun buildStrictControlPoints(
|
||||
x: FloatArray,
|
||||
y: FloatArray
|
||||
): Pair<FloatArray, FloatArray> {
|
||||
require(x.size == y.size) { "Control point arrays must have the same size" }
|
||||
|
||||
val strictX = ArrayList<Float>(x.size)
|
||||
val strictY = ArrayList<Float>(y.size)
|
||||
|
||||
for (i in x.indices) {
|
||||
val nextX = x[i].coerceIn(0f, 1f)
|
||||
val nextY = y[i].coerceAtLeast(0f)
|
||||
val lastIndex = strictX.lastIndex
|
||||
|
||||
if (lastIndex >= 0 && nextX <= strictX[lastIndex] + MIN_X_STEP) {
|
||||
strictX[lastIndex] = nextX.coerceAtLeast(strictX[lastIndex])
|
||||
strictY[lastIndex] = maxOf(strictY[lastIndex], nextY)
|
||||
continue
|
||||
}
|
||||
|
||||
strictX.add(nextX)
|
||||
strictY.add(nextY)
|
||||
}
|
||||
|
||||
if (strictX.size < 2) {
|
||||
val fallbackEndY = strictY.lastOrNull() ?: 1f
|
||||
strictX.clear()
|
||||
strictY.clear()
|
||||
strictX.add(0f)
|
||||
strictY.add(0f)
|
||||
strictX.add(1f)
|
||||
strictY.add(fallbackEndY)
|
||||
PLog.w(TAG, "buildStrictControlPoints: fell back to linear endpoints")
|
||||
} else if (strictX.size != x.size) {
|
||||
PLog.w(
|
||||
TAG,
|
||||
"buildStrictControlPoints: collapsed duplicate x values from ${x.size} to ${strictX.size}"
|
||||
)
|
||||
}
|
||||
|
||||
return strictX.toFloatArray() to strictY.toFloatArray()
|
||||
}
|
||||
|
||||
private fun buildHistogramFromNeutral(
|
||||
neutralBuffer: FloatBuffer,
|
||||
width: Int,
|
||||
|
||||
@@ -27,11 +27,6 @@ object ExposureNormalization {
|
||||
if (metadata.baselineExposure.isFinite() && metadata.baselineExposure != 0f) {
|
||||
gain *= 2.0f.pow(metadata.baselineExposure)
|
||||
}
|
||||
|
||||
PLog.d(
|
||||
TAG,
|
||||
"compute: gain=$gain preMul=${preMul.joinToString()} wb=${wb.joinToString()} black=${black.joinToString()} white=${metadata.whiteLevel} baseline=${metadata.baselineExposure}"
|
||||
)
|
||||
return gain.coerceIn(1f, 8f)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,17 +10,23 @@ import kotlin.math.pow
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* RawTherapee-style histogram matching:
|
||||
* use an embedded preview/JPEG as source and a neutral RAW rendering as target,
|
||||
* then build a monotonic tone curve by matching both luminance CDFs.
|
||||
* Histogram matching tuned for RAW tone shaping.
|
||||
*
|
||||
* Instead of fitting a dense 256-point mapping directly from the JPEG preview,
|
||||
* we extract only low-frequency percentile landmarks and build a smooth,
|
||||
* monotonic curve. This avoids baking JPEG quantization/highlight clipping
|
||||
* artifacts into the luminance gain curve, which can otherwise show up as
|
||||
* bright speckling on smooth highlights.
|
||||
*/
|
||||
object HistogramMatching {
|
||||
private const val TAG = "HistogramMatching"
|
||||
private const val LUT_SIZE = 256
|
||||
private const val MIN_REFERENCE_PIXELS = 19_200
|
||||
private const val MIN_X_STEP = 1e-4f
|
||||
private const val MIN_CURVE_STEP = 1e-5f
|
||||
|
||||
data class AnalysisResult(
|
||||
val curveLut: FloatArray?
|
||||
private val PERCENTILES = floatArrayOf(
|
||||
0f, 0.12f, 0.25f, 0.5f, 0.75f, 1f
|
||||
)
|
||||
|
||||
fun analyze(
|
||||
@@ -29,23 +35,22 @@ object HistogramMatching {
|
||||
height: Int,
|
||||
logCurve: LogCurve,
|
||||
referenceBitmap: Bitmap?
|
||||
): AnalysisResult {
|
||||
): FloatArray {
|
||||
if (referenceBitmap == null) {
|
||||
PLog.d(TAG, "No embedded preview found, using neutral curve")
|
||||
return AnalysisResult(null)
|
||||
PLog.d(TAG, "No embedded preview found, using default ACR3 S-curve")
|
||||
return buildDefaultStandardCurve(logCurve)
|
||||
}
|
||||
|
||||
val reference = prepareReference(referenceBitmap, width, height) ?: run {
|
||||
PLog.d(TAG, "Embedded preview too small or invalid, using neutral curve")
|
||||
return AnalysisResult(null)
|
||||
PLog.d(TAG, "Embedded preview too small or invalid, using default ACR3 S-curve")
|
||||
return buildDefaultStandardCurve(logCurve)
|
||||
}
|
||||
|
||||
val targetHistogram = buildHistogramFromNeutral(neutralBuffer, width, height, logCurve)
|
||||
val sourceHistogram = buildHistogramFromBitmap(reference, logCurve)
|
||||
val mapping = buildMapping(targetHistogram, sourceHistogram)
|
||||
val curve = mappingToCurve(mapping, logCurve)
|
||||
val targetHistogram = smoothHistogram(buildHistogramFromNeutral(neutralBuffer, width, height, logCurve))
|
||||
val sourceHistogram = smoothHistogram(buildHistogramFromBitmap(reference, logCurve))
|
||||
val curve = buildPercentileCurve(targetHistogram, sourceHistogram, logCurve)
|
||||
|
||||
return AnalysisResult(curve)
|
||||
return curve
|
||||
}
|
||||
|
||||
private fun prepareReference(bitmap: Bitmap, targetWidth: Int, targetHeight: Int): Bitmap? {
|
||||
@@ -109,6 +114,26 @@ object HistogramMatching {
|
||||
return histogram
|
||||
}
|
||||
|
||||
private fun buildDefaultStandardCurve(logCurve: LogCurve): FloatArray {
|
||||
val curve = FloatArray(LUT_SIZE)
|
||||
for (i in curve.indices) {
|
||||
val inputLog = i.toFloat() / (curve.size - 1)
|
||||
val inputLinear = logCurve.logToLinear(inputLog).coerceAtLeast(0f)
|
||||
curve[i] = interpolateAcr3DefaultCurve(inputLinear.coerceIn(0f, 1f))
|
||||
}
|
||||
curve[0] = 0f
|
||||
curve[curve.lastIndex] = 1f
|
||||
return curve
|
||||
}
|
||||
|
||||
private fun interpolateAcr3DefaultCurve(x: Float): Float {
|
||||
val clampedX = x.coerceIn(0f, 1f)
|
||||
val y = clampedX * (ACR3_DEFAULT_CURVE.size - 1)
|
||||
val index = y.toInt().coerceIn(0, ACR3_DEFAULT_CURVE.lastIndex - 1)
|
||||
val fraction = y - index
|
||||
return ACR3_DEFAULT_CURVE[index] * (1f - fraction) + ACR3_DEFAULT_CURVE[index + 1] * fraction
|
||||
}
|
||||
|
||||
private fun buildHistogramFromBitmap(bitmap: Bitmap, logCurve: LogCurve): IntArray {
|
||||
val histogram = IntArray(LUT_SIZE)
|
||||
val pixels = IntArray(bitmap.width * bitmap.height)
|
||||
@@ -128,20 +153,57 @@ object HistogramMatching {
|
||||
return histogram
|
||||
}
|
||||
|
||||
private fun buildMapping(targetHistogram: IntArray, sourceHistogram: IntArray): IntArray {
|
||||
private fun smoothHistogram(histogram: IntArray): IntArray {
|
||||
var current = histogram.copyOf()
|
||||
repeat(3) {
|
||||
val next = IntArray(current.size)
|
||||
for (i in current.indices) {
|
||||
val left = current[(i - 1).coerceAtLeast(0)]
|
||||
val center = current[i]
|
||||
val right = current[(i + 1).coerceAtMost(current.lastIndex)]
|
||||
next[i] = (left + center * 2 + right + 2) / 4
|
||||
}
|
||||
current = next
|
||||
}
|
||||
return current
|
||||
}
|
||||
|
||||
private fun buildPercentileCurve(
|
||||
targetHistogram: IntArray,
|
||||
sourceHistogram: IntArray,
|
||||
logCurve: LogCurve
|
||||
): FloatArray {
|
||||
val targetCdf = buildCdf(targetHistogram)
|
||||
val sourceCdf = buildCdf(sourceHistogram)
|
||||
val mapping = IntArray(LUT_SIZE)
|
||||
var j = 0
|
||||
|
||||
for (i in 0 until LUT_SIZE) {
|
||||
val targetValue = targetCdf[i]
|
||||
while (j < LUT_SIZE - 1 && sourceCdf[j] < targetValue) {
|
||||
j++
|
||||
}
|
||||
mapping[i] = j
|
||||
val rawX = FloatArray(PERCENTILES.size + 1)
|
||||
val rawY = FloatArray(PERCENTILES.size + 1)
|
||||
|
||||
for (i in PERCENTILES.indices) {
|
||||
val percentile = PERCENTILES[i]
|
||||
val targetBin = findPercentileBin(targetCdf, percentile)
|
||||
val sourceBin = findPercentileBin(sourceCdf, percentile)
|
||||
|
||||
val inputLog = targetBin.toFloat() / (LUT_SIZE - 1)
|
||||
val outputLog = sourceBin.toFloat() / (LUT_SIZE - 1)
|
||||
|
||||
rawX[i] = inputLog
|
||||
rawY[i] = logCurve.logToLinear(outputLog).coerceAtLeast(0f)
|
||||
}
|
||||
return mapping
|
||||
|
||||
rawX[rawX.lastIndex] = 1f
|
||||
rawY[rawY.lastIndex] = logCurve.logToLinear(1f).coerceAtLeast(0f)
|
||||
|
||||
val (x, y) = buildStrictControlPoints(rawX, rawY)
|
||||
val curve = SplineInterpolator(x, y).generateLut(LUT_SIZE)
|
||||
val smoothedCurve = smoothCurve(curve)
|
||||
val stabilizedCurve = stabilizeHighlights(smoothedCurve, logCurve)
|
||||
|
||||
val xDescription = x.joinToString(prefix = "[", postfix = "]")
|
||||
val yDescription = y.joinToString(prefix = "[", postfix = "]")
|
||||
PLog.d(TAG, "buildPercentileCurve: x=$xDescription y=$yDescription")
|
||||
|
||||
return stabilizedCurve
|
||||
}
|
||||
|
||||
private fun buildCdf(histogram: IntArray): FloatArray {
|
||||
@@ -155,17 +217,97 @@ object HistogramMatching {
|
||||
return cdf
|
||||
}
|
||||
|
||||
private fun mappingToCurve(mapping: IntArray, logCurve: LogCurve): FloatArray {
|
||||
val x = FloatArray(LUT_SIZE)
|
||||
val y = FloatArray(LUT_SIZE)
|
||||
for (i in 0 until LUT_SIZE) {
|
||||
val input = i.toFloat() / (LUT_SIZE - 1)
|
||||
val mapped = mapping[i].toFloat() / (LUT_SIZE - 1)
|
||||
x[i] = input
|
||||
y[i] = logCurve.logToLinear(mapped).coerceAtLeast(0f)
|
||||
private fun findPercentileBin(cdf: FloatArray, percentile: Float): Int {
|
||||
val target = percentile.coerceIn(0f, 1f)
|
||||
for (i in cdf.indices) {
|
||||
if (cdf[i] >= target) return i
|
||||
}
|
||||
val interpolator = SplineInterpolator(x, y)
|
||||
return interpolator.generateLut(LUT_SIZE)
|
||||
return cdf.lastIndex
|
||||
}
|
||||
|
||||
private fun buildStrictControlPoints(
|
||||
x: FloatArray,
|
||||
y: FloatArray
|
||||
): Pair<FloatArray, FloatArray> {
|
||||
val strictX = ArrayList<Float>(x.size)
|
||||
val strictY = ArrayList<Float>(y.size)
|
||||
|
||||
for (i in x.indices) {
|
||||
val nextX = x[i].coerceIn(0f, 1f)
|
||||
val nextY = y[i].coerceAtLeast(0f)
|
||||
val lastIndex = strictX.lastIndex
|
||||
|
||||
if (lastIndex >= 0 && nextX <= strictX[lastIndex] + MIN_X_STEP) {
|
||||
strictX[lastIndex] = nextX.coerceAtLeast(strictX[lastIndex])
|
||||
strictY[lastIndex] = max(strictY[lastIndex], nextY)
|
||||
continue
|
||||
}
|
||||
|
||||
strictX.add(nextX)
|
||||
strictY.add(nextY)
|
||||
}
|
||||
|
||||
if (strictX.size < 2) {
|
||||
return floatArrayOf(0f, 1f) to floatArrayOf(0f, y.lastOrNull() ?: 1f)
|
||||
}
|
||||
|
||||
return strictX.toFloatArray() to strictY.toFloatArray()
|
||||
}
|
||||
|
||||
private fun smoothCurve(curve: FloatArray): FloatArray {
|
||||
var current = curve.copyOf()
|
||||
repeat(2) {
|
||||
val next = FloatArray(current.size)
|
||||
for (i in current.indices) {
|
||||
val left2 = current[(i - 2).coerceAtLeast(0)]
|
||||
val left1 = current[(i - 1).coerceAtLeast(0)]
|
||||
val center = current[i]
|
||||
val right1 = current[(i + 1).coerceAtMost(current.lastIndex)]
|
||||
val right2 = current[(i + 2).coerceAtMost(current.lastIndex)]
|
||||
next[i] = (
|
||||
left2 +
|
||||
left1 * 2f +
|
||||
center * 4f +
|
||||
right1 * 2f +
|
||||
right2
|
||||
) / 10f
|
||||
}
|
||||
current = next
|
||||
}
|
||||
return current
|
||||
}
|
||||
|
||||
private fun stabilizeHighlights(curve: FloatArray, logCurve: LogCurve): FloatArray {
|
||||
val result = FloatArray(curve.size)
|
||||
var previous = 0f
|
||||
|
||||
for (i in curve.indices) {
|
||||
val x = i.toFloat() / (curve.size - 1)
|
||||
val identity = logCurve.logToLinear(x).coerceAtLeast(0f)
|
||||
val blendToIdentity = smoothStep(0.90f, 1f, x) * 0.85f
|
||||
val gainLimit = lerp(1.18f, 1.0f, smoothStep(0.82f, 1f, x))
|
||||
|
||||
var value = lerp(curve[i], identity, blendToIdentity)
|
||||
value = minOf(value, identity * gainLimit)
|
||||
value = max(value, previous + MIN_CURVE_STEP)
|
||||
|
||||
result[i] = value
|
||||
previous = value
|
||||
}
|
||||
|
||||
result[0] = 0f
|
||||
result[result.lastIndex] = logCurve.logToLinear(1f).coerceAtLeast(result[result.lastIndex])
|
||||
return result
|
||||
}
|
||||
|
||||
private fun smoothStep(edge0: Float, edge1: Float, x: Float): Float {
|
||||
if (edge0 == edge1) return if (x >= edge1) 1f else 0f
|
||||
val t = ((x - edge0) / (edge1 - edge0)).coerceIn(0f, 1f)
|
||||
return t * t * (3f - 2f * t)
|
||||
}
|
||||
|
||||
private fun lerp(a: Float, b: Float, t: Float): Float {
|
||||
return a + (b - a) * t
|
||||
}
|
||||
|
||||
private fun srgbToLinear(v: Float): Float {
|
||||
@@ -175,4 +317,264 @@ object HistogramMatching {
|
||||
((v + 0.055f) / 1.055f).toDouble().pow(2.4).toFloat()
|
||||
}
|
||||
}
|
||||
|
||||
private val ACR3_DEFAULT_CURVE = floatArrayOf(
|
||||
0.00000f, 0.00078f, 0.00160f, 0.00242f,
|
||||
0.00314f, 0.00385f, 0.00460f, 0.00539f,
|
||||
0.00623f, 0.00712f, 0.00806f, 0.00906f,
|
||||
0.01012f, 0.01122f, 0.01238f, 0.01359f,
|
||||
0.01485f, 0.01616f, 0.01751f, 0.01890f,
|
||||
0.02033f, 0.02180f, 0.02331f, 0.02485f,
|
||||
0.02643f, 0.02804f, 0.02967f, 0.03134f,
|
||||
0.03303f, 0.03475f, 0.03648f, 0.03824f,
|
||||
0.04002f, 0.04181f, 0.04362f, 0.04545f,
|
||||
0.04730f, 0.04916f, 0.05103f, 0.05292f,
|
||||
0.05483f, 0.05675f, 0.05868f, 0.06063f,
|
||||
0.06259f, 0.06457f, 0.06655f, 0.06856f,
|
||||
0.07057f, 0.07259f, 0.07463f, 0.07668f,
|
||||
0.07874f, 0.08081f, 0.08290f, 0.08499f,
|
||||
0.08710f, 0.08921f, 0.09134f, 0.09348f,
|
||||
0.09563f, 0.09779f, 0.09996f, 0.10214f,
|
||||
0.10433f, 0.10652f, 0.10873f, 0.11095f,
|
||||
0.11318f, 0.11541f, 0.11766f, 0.11991f,
|
||||
0.12218f, 0.12445f, 0.12673f, 0.12902f,
|
||||
0.13132f, 0.13363f, 0.13595f, 0.13827f,
|
||||
0.14061f, 0.14295f, 0.14530f, 0.14765f,
|
||||
0.15002f, 0.15239f, 0.15477f, 0.15716f,
|
||||
0.15956f, 0.16197f, 0.16438f, 0.16680f,
|
||||
0.16923f, 0.17166f, 0.17410f, 0.17655f,
|
||||
0.17901f, 0.18148f, 0.18395f, 0.18643f,
|
||||
0.18891f, 0.19141f, 0.19391f, 0.19641f,
|
||||
0.19893f, 0.20145f, 0.20398f, 0.20651f,
|
||||
0.20905f, 0.21160f, 0.21416f, 0.21672f,
|
||||
0.21929f, 0.22185f, 0.22440f, 0.22696f,
|
||||
0.22950f, 0.23204f, 0.23458f, 0.23711f,
|
||||
0.23963f, 0.24215f, 0.24466f, 0.24717f,
|
||||
0.24967f, 0.25216f, 0.25465f, 0.25713f,
|
||||
0.25961f, 0.26208f, 0.26454f, 0.26700f,
|
||||
0.26945f, 0.27189f, 0.27433f, 0.27676f,
|
||||
0.27918f, 0.28160f, 0.28401f, 0.28641f,
|
||||
0.28881f, 0.29120f, 0.29358f, 0.29596f,
|
||||
0.29833f, 0.30069f, 0.30305f, 0.30540f,
|
||||
0.30774f, 0.31008f, 0.31241f, 0.31473f,
|
||||
0.31704f, 0.31935f, 0.32165f, 0.32395f,
|
||||
0.32623f, 0.32851f, 0.33079f, 0.33305f,
|
||||
0.33531f, 0.33756f, 0.33981f, 0.34205f,
|
||||
0.34428f, 0.34650f, 0.34872f, 0.35093f,
|
||||
0.35313f, 0.35532f, 0.35751f, 0.35969f,
|
||||
0.36187f, 0.36404f, 0.36620f, 0.36835f,
|
||||
0.37050f, 0.37264f, 0.37477f, 0.37689f,
|
||||
0.37901f, 0.38112f, 0.38323f, 0.38533f,
|
||||
0.38742f, 0.38950f, 0.39158f, 0.39365f,
|
||||
0.39571f, 0.39777f, 0.39982f, 0.40186f,
|
||||
0.40389f, 0.40592f, 0.40794f, 0.40996f,
|
||||
0.41197f, 0.41397f, 0.41596f, 0.41795f,
|
||||
0.41993f, 0.42191f, 0.42388f, 0.42584f,
|
||||
0.42779f, 0.42974f, 0.43168f, 0.43362f,
|
||||
0.43554f, 0.43747f, 0.43938f, 0.44129f,
|
||||
0.44319f, 0.44509f, 0.44698f, 0.44886f,
|
||||
0.45073f, 0.45260f, 0.45447f, 0.45632f,
|
||||
0.45817f, 0.46002f, 0.46186f, 0.46369f,
|
||||
0.46551f, 0.46733f, 0.46914f, 0.47095f,
|
||||
0.47275f, 0.47454f, 0.47633f, 0.47811f,
|
||||
0.47989f, 0.48166f, 0.48342f, 0.48518f,
|
||||
0.48693f, 0.48867f, 0.49041f, 0.49214f,
|
||||
0.49387f, 0.49559f, 0.49730f, 0.49901f,
|
||||
0.50072f, 0.50241f, 0.50410f, 0.50579f,
|
||||
0.50747f, 0.50914f, 0.51081f, 0.51247f,
|
||||
0.51413f, 0.51578f, 0.51742f, 0.51906f,
|
||||
0.52069f, 0.52232f, 0.52394f, 0.52556f,
|
||||
0.52717f, 0.52878f, 0.53038f, 0.53197f,
|
||||
0.53356f, 0.53514f, 0.53672f, 0.53829f,
|
||||
0.53986f, 0.54142f, 0.54297f, 0.54452f,
|
||||
0.54607f, 0.54761f, 0.54914f, 0.55067f,
|
||||
0.55220f, 0.55371f, 0.55523f, 0.55673f,
|
||||
0.55824f, 0.55973f, 0.56123f, 0.56271f,
|
||||
0.56420f, 0.56567f, 0.56715f, 0.56861f,
|
||||
0.57007f, 0.57153f, 0.57298f, 0.57443f,
|
||||
0.57587f, 0.57731f, 0.57874f, 0.58017f,
|
||||
0.58159f, 0.58301f, 0.58443f, 0.58583f,
|
||||
0.58724f, 0.58864f, 0.59003f, 0.59142f,
|
||||
0.59281f, 0.59419f, 0.59556f, 0.59694f,
|
||||
0.59830f, 0.59966f, 0.60102f, 0.60238f,
|
||||
0.60373f, 0.60507f, 0.60641f, 0.60775f,
|
||||
0.60908f, 0.61040f, 0.61173f, 0.61305f,
|
||||
0.61436f, 0.61567f, 0.61698f, 0.61828f,
|
||||
0.61957f, 0.62087f, 0.62216f, 0.62344f,
|
||||
0.62472f, 0.62600f, 0.62727f, 0.62854f,
|
||||
0.62980f, 0.63106f, 0.63232f, 0.63357f,
|
||||
0.63482f, 0.63606f, 0.63730f, 0.63854f,
|
||||
0.63977f, 0.64100f, 0.64222f, 0.64344f,
|
||||
0.64466f, 0.64587f, 0.64708f, 0.64829f,
|
||||
0.64949f, 0.65069f, 0.65188f, 0.65307f,
|
||||
0.65426f, 0.65544f, 0.65662f, 0.65779f,
|
||||
0.65897f, 0.66013f, 0.66130f, 0.66246f,
|
||||
0.66362f, 0.66477f, 0.66592f, 0.66707f,
|
||||
0.66821f, 0.66935f, 0.67048f, 0.67162f,
|
||||
0.67275f, 0.67387f, 0.67499f, 0.67611f,
|
||||
0.67723f, 0.67834f, 0.67945f, 0.68055f,
|
||||
0.68165f, 0.68275f, 0.68385f, 0.68494f,
|
||||
0.68603f, 0.68711f, 0.68819f, 0.68927f,
|
||||
0.69035f, 0.69142f, 0.69249f, 0.69355f,
|
||||
0.69461f, 0.69567f, 0.69673f, 0.69778f,
|
||||
0.69883f, 0.69988f, 0.70092f, 0.70196f,
|
||||
0.70300f, 0.70403f, 0.70506f, 0.70609f,
|
||||
0.70711f, 0.70813f, 0.70915f, 0.71017f,
|
||||
0.71118f, 0.71219f, 0.71319f, 0.71420f,
|
||||
0.71520f, 0.71620f, 0.71719f, 0.71818f,
|
||||
0.71917f, 0.72016f, 0.72114f, 0.72212f,
|
||||
0.72309f, 0.72407f, 0.72504f, 0.72601f,
|
||||
0.72697f, 0.72794f, 0.72890f, 0.72985f,
|
||||
0.73081f, 0.73176f, 0.73271f, 0.73365f,
|
||||
0.73460f, 0.73554f, 0.73647f, 0.73741f,
|
||||
0.73834f, 0.73927f, 0.74020f, 0.74112f,
|
||||
0.74204f, 0.74296f, 0.74388f, 0.74479f,
|
||||
0.74570f, 0.74661f, 0.74751f, 0.74842f,
|
||||
0.74932f, 0.75021f, 0.75111f, 0.75200f,
|
||||
0.75289f, 0.75378f, 0.75466f, 0.75555f,
|
||||
0.75643f, 0.75730f, 0.75818f, 0.75905f,
|
||||
0.75992f, 0.76079f, 0.76165f, 0.76251f,
|
||||
0.76337f, 0.76423f, 0.76508f, 0.76594f,
|
||||
0.76679f, 0.76763f, 0.76848f, 0.76932f,
|
||||
0.77016f, 0.77100f, 0.77183f, 0.77267f,
|
||||
0.77350f, 0.77432f, 0.77515f, 0.77597f,
|
||||
0.77680f, 0.77761f, 0.77843f, 0.77924f,
|
||||
0.78006f, 0.78087f, 0.78167f, 0.78248f,
|
||||
0.78328f, 0.78408f, 0.78488f, 0.78568f,
|
||||
0.78647f, 0.78726f, 0.78805f, 0.78884f,
|
||||
0.78962f, 0.79040f, 0.79118f, 0.79196f,
|
||||
0.79274f, 0.79351f, 0.79428f, 0.79505f,
|
||||
0.79582f, 0.79658f, 0.79735f, 0.79811f,
|
||||
0.79887f, 0.79962f, 0.80038f, 0.80113f,
|
||||
0.80188f, 0.80263f, 0.80337f, 0.80412f,
|
||||
0.80486f, 0.80560f, 0.80634f, 0.80707f,
|
||||
0.80780f, 0.80854f, 0.80926f, 0.80999f,
|
||||
0.81072f, 0.81144f, 0.81216f, 0.81288f,
|
||||
0.81360f, 0.81431f, 0.81503f, 0.81574f,
|
||||
0.81645f, 0.81715f, 0.81786f, 0.81856f,
|
||||
0.81926f, 0.81996f, 0.82066f, 0.82135f,
|
||||
0.82205f, 0.82274f, 0.82343f, 0.82412f,
|
||||
0.82480f, 0.82549f, 0.82617f, 0.82685f,
|
||||
0.82753f, 0.82820f, 0.82888f, 0.82955f,
|
||||
0.83022f, 0.83089f, 0.83155f, 0.83222f,
|
||||
0.83288f, 0.83354f, 0.83420f, 0.83486f,
|
||||
0.83552f, 0.83617f, 0.83682f, 0.83747f,
|
||||
0.83812f, 0.83877f, 0.83941f, 0.84005f,
|
||||
0.84069f, 0.84133f, 0.84197f, 0.84261f,
|
||||
0.84324f, 0.84387f, 0.84450f, 0.84513f,
|
||||
0.84576f, 0.84639f, 0.84701f, 0.84763f,
|
||||
0.84825f, 0.84887f, 0.84949f, 0.85010f,
|
||||
0.85071f, 0.85132f, 0.85193f, 0.85254f,
|
||||
0.85315f, 0.85375f, 0.85436f, 0.85496f,
|
||||
0.85556f, 0.85615f, 0.85675f, 0.85735f,
|
||||
0.85794f, 0.85853f, 0.85912f, 0.85971f,
|
||||
0.86029f, 0.86088f, 0.86146f, 0.86204f,
|
||||
0.86262f, 0.86320f, 0.86378f, 0.86435f,
|
||||
0.86493f, 0.86550f, 0.86607f, 0.86664f,
|
||||
0.86720f, 0.86777f, 0.86833f, 0.86889f,
|
||||
0.86945f, 0.87001f, 0.87057f, 0.87113f,
|
||||
0.87168f, 0.87223f, 0.87278f, 0.87333f,
|
||||
0.87388f, 0.87443f, 0.87497f, 0.87552f,
|
||||
0.87606f, 0.87660f, 0.87714f, 0.87768f,
|
||||
0.87821f, 0.87875f, 0.87928f, 0.87981f,
|
||||
0.88034f, 0.88087f, 0.88140f, 0.88192f,
|
||||
0.88244f, 0.88297f, 0.88349f, 0.88401f,
|
||||
0.88453f, 0.88504f, 0.88556f, 0.88607f,
|
||||
0.88658f, 0.88709f, 0.88760f, 0.88811f,
|
||||
0.88862f, 0.88912f, 0.88963f, 0.89013f,
|
||||
0.89063f, 0.89113f, 0.89163f, 0.89212f,
|
||||
0.89262f, 0.89311f, 0.89360f, 0.89409f,
|
||||
0.89458f, 0.89507f, 0.89556f, 0.89604f,
|
||||
0.89653f, 0.89701f, 0.89749f, 0.89797f,
|
||||
0.89845f, 0.89892f, 0.89940f, 0.89987f,
|
||||
0.90035f, 0.90082f, 0.90129f, 0.90176f,
|
||||
0.90222f, 0.90269f, 0.90316f, 0.90362f,
|
||||
0.90408f, 0.90454f, 0.90500f, 0.90546f,
|
||||
0.90592f, 0.90637f, 0.90683f, 0.90728f,
|
||||
0.90773f, 0.90818f, 0.90863f, 0.90908f,
|
||||
0.90952f, 0.90997f, 0.91041f, 0.91085f,
|
||||
0.91130f, 0.91173f, 0.91217f, 0.91261f,
|
||||
0.91305f, 0.91348f, 0.91392f, 0.91435f,
|
||||
0.91478f, 0.91521f, 0.91564f, 0.91606f,
|
||||
0.91649f, 0.91691f, 0.91734f, 0.91776f,
|
||||
0.91818f, 0.91860f, 0.91902f, 0.91944f,
|
||||
0.91985f, 0.92027f, 0.92068f, 0.92109f,
|
||||
0.92150f, 0.92191f, 0.92232f, 0.92273f,
|
||||
0.92314f, 0.92354f, 0.92395f, 0.92435f,
|
||||
0.92475f, 0.92515f, 0.92555f, 0.92595f,
|
||||
0.92634f, 0.92674f, 0.92713f, 0.92753f,
|
||||
0.92792f, 0.92831f, 0.92870f, 0.92909f,
|
||||
0.92947f, 0.92986f, 0.93025f, 0.93063f,
|
||||
0.93101f, 0.93139f, 0.93177f, 0.93215f,
|
||||
0.93253f, 0.93291f, 0.93328f, 0.93366f,
|
||||
0.93403f, 0.93440f, 0.93478f, 0.93515f,
|
||||
0.93551f, 0.93588f, 0.93625f, 0.93661f,
|
||||
0.93698f, 0.93734f, 0.93770f, 0.93807f,
|
||||
0.93843f, 0.93878f, 0.93914f, 0.93950f,
|
||||
0.93986f, 0.94021f, 0.94056f, 0.94092f,
|
||||
0.94127f, 0.94162f, 0.94197f, 0.94231f,
|
||||
0.94266f, 0.94301f, 0.94335f, 0.94369f,
|
||||
0.94404f, 0.94438f, 0.94472f, 0.94506f,
|
||||
0.94540f, 0.94573f, 0.94607f, 0.94641f,
|
||||
0.94674f, 0.94707f, 0.94740f, 0.94774f,
|
||||
0.94807f, 0.94839f, 0.94872f, 0.94905f,
|
||||
0.94937f, 0.94970f, 0.95002f, 0.95035f,
|
||||
0.95067f, 0.95099f, 0.95131f, 0.95163f,
|
||||
0.95194f, 0.95226f, 0.95257f, 0.95289f,
|
||||
0.95320f, 0.95351f, 0.95383f, 0.95414f,
|
||||
0.95445f, 0.95475f, 0.95506f, 0.95537f,
|
||||
0.95567f, 0.95598f, 0.95628f, 0.95658f,
|
||||
0.95688f, 0.95718f, 0.95748f, 0.95778f,
|
||||
0.95808f, 0.95838f, 0.95867f, 0.95897f,
|
||||
0.95926f, 0.95955f, 0.95984f, 0.96013f,
|
||||
0.96042f, 0.96071f, 0.96100f, 0.96129f,
|
||||
0.96157f, 0.96186f, 0.96214f, 0.96242f,
|
||||
0.96271f, 0.96299f, 0.96327f, 0.96355f,
|
||||
0.96382f, 0.96410f, 0.96438f, 0.96465f,
|
||||
0.96493f, 0.96520f, 0.96547f, 0.96574f,
|
||||
0.96602f, 0.96629f, 0.96655f, 0.96682f,
|
||||
0.96709f, 0.96735f, 0.96762f, 0.96788f,
|
||||
0.96815f, 0.96841f, 0.96867f, 0.96893f,
|
||||
0.96919f, 0.96945f, 0.96971f, 0.96996f,
|
||||
0.97022f, 0.97047f, 0.97073f, 0.97098f,
|
||||
0.97123f, 0.97149f, 0.97174f, 0.97199f,
|
||||
0.97223f, 0.97248f, 0.97273f, 0.97297f,
|
||||
0.97322f, 0.97346f, 0.97371f, 0.97395f,
|
||||
0.97419f, 0.97443f, 0.97467f, 0.97491f,
|
||||
0.97515f, 0.97539f, 0.97562f, 0.97586f,
|
||||
0.97609f, 0.97633f, 0.97656f, 0.97679f,
|
||||
0.97702f, 0.97725f, 0.97748f, 0.97771f,
|
||||
0.97794f, 0.97817f, 0.97839f, 0.97862f,
|
||||
0.97884f, 0.97907f, 0.97929f, 0.97951f,
|
||||
0.97973f, 0.97995f, 0.98017f, 0.98039f,
|
||||
0.98061f, 0.98082f, 0.98104f, 0.98125f,
|
||||
0.98147f, 0.98168f, 0.98189f, 0.98211f,
|
||||
0.98232f, 0.98253f, 0.98274f, 0.98295f,
|
||||
0.98315f, 0.98336f, 0.98357f, 0.98377f,
|
||||
0.98398f, 0.98418f, 0.98438f, 0.98458f,
|
||||
0.98478f, 0.98498f, 0.98518f, 0.98538f,
|
||||
0.98558f, 0.98578f, 0.98597f, 0.98617f,
|
||||
0.98636f, 0.98656f, 0.98675f, 0.98694f,
|
||||
0.98714f, 0.98733f, 0.98752f, 0.98771f,
|
||||
0.98789f, 0.98808f, 0.98827f, 0.98845f,
|
||||
0.98864f, 0.98882f, 0.98901f, 0.98919f,
|
||||
0.98937f, 0.98955f, 0.98973f, 0.98991f,
|
||||
0.99009f, 0.99027f, 0.99045f, 0.99063f,
|
||||
0.99080f, 0.99098f, 0.99115f, 0.99133f,
|
||||
0.99150f, 0.99167f, 0.99184f, 0.99201f,
|
||||
0.99218f, 0.99235f, 0.99252f, 0.99269f,
|
||||
0.99285f, 0.99302f, 0.99319f, 0.99335f,
|
||||
0.99351f, 0.99368f, 0.99384f, 0.99400f,
|
||||
0.99416f, 0.99432f, 0.99448f, 0.99464f,
|
||||
0.99480f, 0.99495f, 0.99511f, 0.99527f,
|
||||
0.99542f, 0.99558f, 0.99573f, 0.99588f,
|
||||
0.99603f, 0.99619f, 0.99634f, 0.99649f,
|
||||
0.99664f, 0.99678f, 0.99693f, 0.99708f,
|
||||
0.99722f, 0.99737f, 0.99751f, 0.99766f,
|
||||
0.99780f, 0.99794f, 0.99809f, 0.99823f,
|
||||
0.99837f, 0.99851f, 0.99865f, 0.99879f,
|
||||
0.99892f, 0.99906f, 0.99920f, 0.99933f,
|
||||
0.99947f, 0.99960f, 0.99974f, 0.99987f,
|
||||
1.00000f
|
||||
)
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import android.graphics.Bitmap
|
||||
import android.graphics.Rect
|
||||
import android.media.Image
|
||||
import android.opengl.*
|
||||
import android.util.Log
|
||||
import com.hinnka.mycamera.camera.AspectRatio
|
||||
import com.hinnka.mycamera.lut.LutConfig
|
||||
import com.hinnka.mycamera.lut.LutParser
|
||||
@@ -315,6 +314,7 @@ class RawDemosaicProcessor {
|
||||
rotation: Int,
|
||||
exposureBias: Float = 0f,
|
||||
sharpeningValue: Float = 0f,
|
||||
denoiseValue: Float? = null,
|
||||
onMetadata: ((RawMetadata) -> Unit)? = null
|
||||
): Bitmap? = withContext(glDispatcher) {
|
||||
val dngFile = File(dngFilePath)
|
||||
@@ -331,6 +331,7 @@ class RawDemosaicProcessor {
|
||||
rotation = rotation,
|
||||
exposureBias = exposureBias,
|
||||
sharpeningValue = sharpeningValue,
|
||||
denoiseValue = denoiseValue,
|
||||
dngFile = dngFile,
|
||||
onMetadata = onMetadata
|
||||
)?.sdrBitmap
|
||||
@@ -354,6 +355,7 @@ class RawDemosaicProcessor {
|
||||
cropRegion: Rect?,
|
||||
rotation: Int,
|
||||
sharpeningValue: Float = 0f,
|
||||
denoiseValue: Float? = null,
|
||||
): Bitmap? = withContext(glDispatcher) {
|
||||
try {
|
||||
if (!isInitialized) {
|
||||
@@ -374,6 +376,7 @@ class RawDemosaicProcessor {
|
||||
cropRegion = cropRegion,
|
||||
rotation = rotation,
|
||||
sharpeningValue = sharpeningValue,
|
||||
denoiseValue = denoiseValue,
|
||||
)?.sdrBitmap
|
||||
} catch (e: Exception) {
|
||||
PLog.e(TAG, "Failed to process RAW buffer", e)
|
||||
@@ -389,6 +392,7 @@ class RawDemosaicProcessor {
|
||||
rotation: Int,
|
||||
exposureBias: Float = 0f,
|
||||
sharpeningValue: Float = 0f,
|
||||
denoiseValue: Float? = null,
|
||||
onMetadata: ((RawMetadata) -> Unit)? = null
|
||||
): RawHdrRenderResult? = withContext(glDispatcher) {
|
||||
val dngFile = File(dngFilePath)
|
||||
@@ -405,6 +409,7 @@ class RawDemosaicProcessor {
|
||||
rotation = rotation,
|
||||
exposureBias = exposureBias,
|
||||
sharpeningValue = sharpeningValue,
|
||||
denoiseValue = denoiseValue,
|
||||
dngFile = dngFile,
|
||||
onMetadata = onMetadata,
|
||||
includeHdrReference = true
|
||||
@@ -430,6 +435,7 @@ class RawDemosaicProcessor {
|
||||
rotation: Int,
|
||||
exposureBias: Float = 0f,
|
||||
sharpeningValue: Float = 0f,
|
||||
denoiseValue: Float? = null,
|
||||
dngFile: File? = null,
|
||||
onMetadata: ((RawMetadata) -> Unit)? = null,
|
||||
includeHdrReference: Boolean = false
|
||||
@@ -455,7 +461,6 @@ class RawDemosaicProcessor {
|
||||
RawHdrRenderResult(
|
||||
sdrBitmap = it,
|
||||
hdrReferenceBitmap = null,
|
||||
renderPlan = RawRenderPlan(sceneNormalizationGain = 1.0f)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -561,36 +566,36 @@ class RawDemosaicProcessor {
|
||||
// RT-style histogram matching uses the embedded preview as source and
|
||||
// our neutral RAW render as target. When no preview is available, it
|
||||
// falls back to a neutral curve.
|
||||
val sceneStats =
|
||||
val curveLut =
|
||||
analyzeFromGpuTexture(
|
||||
demosaicTextureId,
|
||||
actualWidth,
|
||||
actualHeight,
|
||||
logCurve,
|
||||
actualMetadata,
|
||||
dngRawDataCleanup?.embeddedPreview
|
||||
)
|
||||
val renderPlan = sceneStats.toRenderPlan()
|
||||
val workingColorSpace = resolveWorkingColorSpace()
|
||||
|
||||
// NLM 降噪 (Combined 之后)
|
||||
val denoiseStart = System.currentTimeMillis()
|
||||
renderNLMPass(
|
||||
sourceTextureId = demosaicTextureId,
|
||||
width = actualWidth,
|
||||
height = actualHeight,
|
||||
metadata = actualMetadata,
|
||||
sceneStats = sceneStats
|
||||
)
|
||||
val denoiseOutputTexture = gfTexId[1]
|
||||
PLog.d(TAG, "NLM Denoise took: ${System.currentTimeMillis() - denoiseStart}ms")
|
||||
val denoiseValue = denoiseValue ?: 0.2f
|
||||
val outputTexture = if (denoiseValue > 0f) {
|
||||
// NLM 降噪
|
||||
renderNLMPass(
|
||||
sourceTextureId = demosaicTextureId,
|
||||
width = actualWidth,
|
||||
height = actualHeight,
|
||||
metadata = actualMetadata,
|
||||
denoiseValue = denoiseValue
|
||||
)
|
||||
gfTexId[1]
|
||||
} else {
|
||||
demosaicTextureId
|
||||
}
|
||||
|
||||
val hdrReferenceBitmap = if (includeHdrReference) {
|
||||
setupHdrReferenceFramebuffer(actualWidth, actualHeight)
|
||||
renderHdrReferencePass(
|
||||
metadata = actualMetadata,
|
||||
renderPlan = renderPlan,
|
||||
inputTextureId = denoiseOutputTexture
|
||||
inputTextureId = outputTexture
|
||||
)
|
||||
setupOutputFramebuffer(finalWidth, finalHeight)
|
||||
renderOutputPass(
|
||||
@@ -608,7 +613,7 @@ class RawDemosaicProcessor {
|
||||
// 5. 第二步:Combined Pass (HDR Linear -> LDR sRGB + LUT)
|
||||
setupCombinedFramebuffer(actualWidth, actualHeight)
|
||||
val combinedStart = System.currentTimeMillis()
|
||||
renderCombinedPass(actualMetadata, sceneStats, baseLut, logCurve, inputTextureId = denoiseOutputTexture)
|
||||
renderCombinedPass(actualMetadata, curveLut, baseLut, logCurve, inputTextureId = outputTexture)
|
||||
PLog.d(TAG, "Combined Pass took: ${System.currentTimeMillis() - combinedStart}ms")
|
||||
|
||||
// 6. 第三步:锐化 (Sharpen Pass)
|
||||
@@ -641,7 +646,6 @@ class RawDemosaicProcessor {
|
||||
RawHdrRenderResult(
|
||||
sdrBitmap = it,
|
||||
hdrReferenceBitmap = hdrReferenceBitmap,
|
||||
renderPlan = renderPlan
|
||||
)
|
||||
}
|
||||
} finally {
|
||||
@@ -1062,7 +1066,7 @@ class RawDemosaicProcessor {
|
||||
width: Int,
|
||||
height: Int,
|
||||
metadata: RawMetadata,
|
||||
sceneStats: SceneStats
|
||||
denoiseValue: Float
|
||||
) {
|
||||
setupNLMFramebuffers(width, height)
|
||||
|
||||
@@ -1078,23 +1082,25 @@ class RawDemosaicProcessor {
|
||||
// 增益由三部分组成:传感器 ISO、ISP 数字增益、后期 Tonemap 增益
|
||||
val isoGain = metadata.iso / 100.0f
|
||||
val digitalGain = metadata.postRawSensitivityBoost
|
||||
val postGain = sceneStats.exposureGain
|
||||
val postGain = ExposureNormalization.compute(metadata)
|
||||
val totalGain = (isoGain * digitalGain * postGain).coerceAtLeast(0f)
|
||||
|
||||
// 基于噪声特性的基础强度
|
||||
val s = metadata.noiseProfile[0]
|
||||
val o = metadata.noiseProfile[1]
|
||||
// 估算标准差,映射到一个易用的量级 (使用 1e-3 作为中等 RAW 亮度的估算)
|
||||
val noiseBase = sqrt((s * 1e-3f + o * 1e-6f).toDouble()).toFloat() * 100.0f
|
||||
val noiseBase = (sqrt((s * 1e-3f + o * 1e-6f).toDouble()).toFloat() * 100.0f)
|
||||
|
||||
// 动态计算 h 值 (衰减系数)
|
||||
// 规则:基础强度 + 增益强度系数 + 传感器噪声水平系数
|
||||
// 使用 sqrt(totalGain) 是因为噪声标准差随增益的平方根增加(近似)
|
||||
val baseH = 0.003f
|
||||
val dynamicH = 0.003f * sqrt(totalGain.toDouble()).toFloat()
|
||||
val noiseCorrection = (noiseBase * 0.1f).coerceIn(0f, 0.02f)
|
||||
val noise = if (noiseBase > 0f) {
|
||||
noiseBase * denoiseValue * 0.5f + 0.002f * sqrt(totalGain.toDouble()).toFloat()
|
||||
} else {
|
||||
denoiseValue * 0.008f * sqrt(totalGain.toDouble()).toFloat()
|
||||
}
|
||||
|
||||
val h = (baseH + dynamicH + noiseCorrection).coerceIn(0.01f, 0.1f)
|
||||
val h = noise.coerceIn(0.001f, 0.1f)
|
||||
PLog.d(
|
||||
TAG,
|
||||
"Dynamic NLM: totalGain=${"%.2f".format(totalGain)} (ISO=$isoGain, Boost=$digitalGain, Post=$postGain), noiseBase=$noiseBase, h=$h"
|
||||
@@ -1695,9 +1701,8 @@ class RawDemosaicProcessor {
|
||||
width: Int,
|
||||
height: Int,
|
||||
logCurve: LogCurve,
|
||||
metadata: RawMetadata,
|
||||
referencePreview: Bitmap? = null
|
||||
): SceneStats {
|
||||
): FloatArray? {
|
||||
// 1. 生成 mipmap
|
||||
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, textureId)
|
||||
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_LINEAR_MIPMAP_NEAREST)
|
||||
@@ -1735,7 +1740,7 @@ class RawDemosaicProcessor {
|
||||
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, textureId)
|
||||
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_LINEAR)
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0)
|
||||
return SceneStats(1.0f)
|
||||
return null
|
||||
}
|
||||
|
||||
// 4. 读取整个 mip 的像素数据 (RGBA float)
|
||||
@@ -1752,22 +1757,13 @@ class RawDemosaicProcessor {
|
||||
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_LINEAR)
|
||||
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0)
|
||||
|
||||
val analysis = HistogramMatching.analyze(
|
||||
return HistogramMatching.analyze(
|
||||
neutralBuffer = floatBuffer,
|
||||
width = mipWidth,
|
||||
height = mipHeight,
|
||||
logCurve = logCurve,
|
||||
referenceBitmap = referencePreview
|
||||
)
|
||||
|
||||
val normalizationGain = ExposureNormalization.compute(metadata)
|
||||
val curveLut = analysis.curveLut ?: DefaultToneCurve.analyze(
|
||||
neutralBuffer = floatBuffer,
|
||||
width = mipWidth,
|
||||
height = mipHeight,
|
||||
logCurve = logCurve
|
||||
)
|
||||
return SceneStats(normalizationGain, curveLut)
|
||||
}
|
||||
|
||||
// 辅助函数: 3x3 矩阵转置 (行主序 -> 列主序)
|
||||
@@ -1848,7 +1844,7 @@ class RawDemosaicProcessor {
|
||||
*/
|
||||
private fun renderCombinedPass(
|
||||
metadata: RawMetadata,
|
||||
sceneStats: SceneStats,
|
||||
curveLut: FloatArray?,
|
||||
lutConfig: LutConfig?,
|
||||
logCurve: LogCurve,
|
||||
inputTextureId: Int = demosaicTextureId
|
||||
@@ -1875,14 +1871,10 @@ class RawDemosaicProcessor {
|
||||
GLES30.glGetUniformLocation(combinedProgram, "uLutEnabled"),
|
||||
if (lutConfig != null) 1 else 0
|
||||
)
|
||||
GLES30.glUniform1f(
|
||||
GLES30.glGetUniformLocation(combinedProgram, "uExposureGain"),
|
||||
sceneStats.exposureGain
|
||||
)
|
||||
|
||||
// S-Curve LUT
|
||||
if (sceneStats.curveLut != null) {
|
||||
uploadCurveTexture(sceneStats.curveLut)
|
||||
if (curveLut != null) {
|
||||
uploadCurveTexture(curveLut)
|
||||
GLES30.glActiveTexture(GLES30.GL_TEXTURE2)
|
||||
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, curveTextureId)
|
||||
GLES30.glUniform1i(GLES30.glGetUniformLocation(combinedProgram, "uCurveTexture"), 2)
|
||||
@@ -1915,7 +1907,6 @@ class RawDemosaicProcessor {
|
||||
|
||||
private fun renderHdrReferencePass(
|
||||
metadata: RawMetadata,
|
||||
renderPlan: RawRenderPlan,
|
||||
inputTextureId: Int
|
||||
) {
|
||||
GLES30.glUseProgram(hdrReferenceProgram)
|
||||
@@ -1926,10 +1917,6 @@ class RawDemosaicProcessor {
|
||||
GLES30.glActiveTexture(GLES30.GL_TEXTURE0)
|
||||
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, inputTextureId)
|
||||
GLES30.glUniform1i(GLES30.glGetUniformLocation(hdrReferenceProgram, "uInputTexture"), 0)
|
||||
GLES30.glUniform1f(
|
||||
GLES30.glGetUniformLocation(hdrReferenceProgram, "uExposureGain"),
|
||||
renderPlan.sceneNormalizationGain
|
||||
)
|
||||
|
||||
val identityMatrix = FloatArray(16)
|
||||
GlMatrix.setIdentityM(identityMatrix, 0)
|
||||
@@ -2003,6 +1990,12 @@ class RawDemosaicProcessor {
|
||||
GLES30.glGetUniformLocation(linearProgram, "uTexMatrix"),
|
||||
1, false, identity, 0
|
||||
)
|
||||
val normalizationGain = ExposureNormalization.compute(metadata)
|
||||
PLog.d(
|
||||
TAG,
|
||||
"compute: normalizationGain=$normalizationGain baseline=${metadata.baselineExposure}"
|
||||
)
|
||||
GLES30.glUniform1f(GLES30.glGetUniformLocation(linearProgram, "uExposureGain"), normalizationGain)
|
||||
drawQuad(linearProgram)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,5 +10,4 @@ data class RawRenderPlan(
|
||||
data class RawHdrRenderResult(
|
||||
val sdrBitmap: Bitmap,
|
||||
val hdrReferenceBitmap: Bitmap? = null,
|
||||
val renderPlan: RawRenderPlan,
|
||||
)
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.hinnka.mycamera.raw
|
||||
|
||||
enum class RawProfile(
|
||||
val colorSpace: ColorSpace,
|
||||
val logCurve: LogCurve,
|
||||
val rawLut: String
|
||||
) {
|
||||
ACES_CINE(
|
||||
colorSpace = ColorSpace.ACES_AP1,
|
||||
logCurve = LogCurve.ACES_CCT,
|
||||
rawLut = "P3.plut"
|
||||
),
|
||||
FUJI_PROVIA(
|
||||
colorSpace = ColorSpace.BT2020,
|
||||
logCurve = LogCurve.FLOG2,
|
||||
rawLut = "PROVIA.plut"
|
||||
),
|
||||
STANDARD_SRGB(
|
||||
colorSpace = ColorSpace.SRGB,
|
||||
logCurve = LogCurve.SRGB,
|
||||
rawLut = "none"
|
||||
);
|
||||
|
||||
companion object {
|
||||
val default = FUJI_PROVIA
|
||||
|
||||
fun fromComponents(
|
||||
colorSpace: ColorSpace,
|
||||
logCurve: LogCurve,
|
||||
rawLut: String?
|
||||
): RawProfile {
|
||||
return entries.firstOrNull { profile ->
|
||||
profile.colorSpace == colorSpace &&
|
||||
profile.logCurve == logCurve &&
|
||||
profile.rawLut == (rawLut ?: defaultLutFor(colorSpace, logCurve))
|
||||
} ?: entries.firstOrNull { profile ->
|
||||
profile.colorSpace == colorSpace && profile.logCurve == logCurve
|
||||
} ?: default
|
||||
}
|
||||
|
||||
fun defaultLutFor(colorSpace: ColorSpace, logCurve: LogCurve): String {
|
||||
return entries.firstOrNull { it.colorSpace == colorSpace && it.logCurve == logCurve }?.rawLut
|
||||
?: default.rawLut
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,8 @@ object RawShaders {
|
||||
|
||||
// 1. CCM
|
||||
rgb = uColorCorrectionMatrix * rgb;
|
||||
|
||||
rgb = rgb * uExposureGain;
|
||||
|
||||
// Output Linear (由下一步 ToneMap Pass 处理)
|
||||
fragColor = vec4(rgb, 1.0);
|
||||
@@ -128,7 +130,6 @@ object RawShaders {
|
||||
uniform mediump sampler3D uLutTexture;
|
||||
uniform float uLutSize;
|
||||
uniform bool uLutEnabled;
|
||||
uniform float uExposureGain;
|
||||
|
||||
uniform sampler2D uCurveTexture;
|
||||
uniform bool uCurveEnabled;
|
||||
@@ -177,7 +178,7 @@ object RawShaders {
|
||||
vec3 rawColor = texture(uInputTexture, vTexCoord).rgb;
|
||||
|
||||
// 1. Exposure
|
||||
vec3 color = rawColor * uExposureGain;
|
||||
vec3 color = rawColor;
|
||||
|
||||
// 2. 线性空间曲线应用 (Tonemapping)
|
||||
if (uCurveEnabled) {
|
||||
@@ -249,10 +250,9 @@ object RawShaders {
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform sampler2D uInputTexture;
|
||||
uniform float uExposureGain;
|
||||
|
||||
void main() {
|
||||
vec3 color = texture(uInputTexture, vTexCoord).rgb * uExposureGain;
|
||||
vec3 color = texture(uInputTexture, vTexCoord).rgb;
|
||||
fragColor = vec4(max(color, vec3(0.0)), 1.0);
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
@@ -31,7 +31,6 @@ import com.hinnka.mycamera.ui.common.WatermarkEditSheet
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.input.pointer.*
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
@@ -47,23 +46,15 @@ import me.saket.telephoto.zoomable.coil.ZoomableAsyncImage
|
||||
import me.saket.telephoto.zoomable.rememberZoomableImageState
|
||||
import me.saket.telephoto.zoomable.rememberZoomableState
|
||||
import com.hinnka.mycamera.frame.TextType
|
||||
import com.hinnka.mycamera.gallery.PhotoData
|
||||
import com.hinnka.mycamera.gallery.PhotoMetadata
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import com.hinnka.mycamera.raw.ColorSpace
|
||||
import com.hinnka.mycamera.raw.LogCurve
|
||||
import com.hinnka.mycamera.raw.RawProcessingPreferences
|
||||
import com.hinnka.mycamera.raw.RawProfile
|
||||
import com.hinnka.mycamera.ui.camera.LutEditBottomSheet
|
||||
import com.hinnka.mycamera.ui.components.*
|
||||
import com.hinnka.mycamera.ui.theme.AccentOrange
|
||||
import com.hinnka.mycamera.utils.PLog
|
||||
import com.hinnka.mycamera.viewmodel.CameraViewModel
|
||||
import com.hinnka.mycamera.viewmodel.GalleryViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
import me.saket.telephoto.zoomable.ZoomSpec
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
@@ -113,6 +104,7 @@ fun PhotoEditScreen(
|
||||
val editSharpening by viewModel.editSharpening.collectAsState()
|
||||
val editNoiseReduction by viewModel.editNoiseReduction.collectAsState()
|
||||
val editChromaNoiseReduction by viewModel.editChromaNoiseReduction.collectAsState()
|
||||
val editRawNlmNoiseFactor by viewModel.editRawDenoise.collectAsState()
|
||||
|
||||
val editComputationalAperture by viewModel.editComputationalAperture.collectAsState()
|
||||
val editFocusX by viewModel.editFocusPointX.collectAsState()
|
||||
@@ -121,10 +113,7 @@ fun PhotoEditScreen(
|
||||
val editCropRect by viewModel.editCropRect.collectAsState()
|
||||
val editCropAspectOption by viewModel.editCropAspectOption.collectAsState()
|
||||
|
||||
val droMode by cameraViewModel.droMode.collectAsState()
|
||||
val colorSpace by cameraViewModel.colorSpace.collectAsState()
|
||||
val logCurve by cameraViewModel.logCurve.collectAsState()
|
||||
val rawLut by cameraViewModel.rawLut.collectAsState()
|
||||
val rawProfile by cameraViewModel.rawProfile.collectAsState()
|
||||
|
||||
val isRaw = currentPhoto?.let { viewModel.isRaw(it.id) } ?: false
|
||||
|
||||
@@ -681,10 +670,9 @@ fun PhotoEditScreen(
|
||||
} else if (editTab == 2) {
|
||||
RawEditPanel(
|
||||
viewModel = cameraViewModel,
|
||||
editDroMode = RawProcessingPreferences.DROMode.valueOf(droMode),
|
||||
editColorSpace = colorSpace,
|
||||
editLogCurve = logCurve,
|
||||
editRawLut = rawLut,
|
||||
rawProfile = rawProfile,
|
||||
rawNlmNoiseFactor = editRawNlmNoiseFactor,
|
||||
onRawNlmNoiseFactorChange = viewModel::setRawDenoiseValue,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
} else if (editTab == 3) {
|
||||
@@ -974,71 +962,40 @@ private fun ZoomableEditImage(
|
||||
@Composable
|
||||
private fun RawEditPanel(
|
||||
viewModel: CameraViewModel,
|
||||
editDroMode: RawProcessingPreferences.DROMode,
|
||||
editColorSpace: ColorSpace,
|
||||
editLogCurve: LogCurve,
|
||||
editRawLut: String?,
|
||||
rawProfile: RawProfile,
|
||||
rawNlmNoiseFactor: Float,
|
||||
onRawNlmNoiseFactorChange: (Float) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
var availableRawLuts by remember { mutableStateOf(listOf<String>()) }
|
||||
|
||||
LaunchedEffect(editLogCurve) {
|
||||
availableRawLuts = listOf("none") + viewModel.getAvailableRawLutList(context, editLogCurve)
|
||||
}
|
||||
|
||||
val droOff = stringResource(R.string.settings_dro_off)
|
||||
val droLow = stringResource(R.string.settings_dro_low)
|
||||
val droHigh = stringResource(R.string.settings_dro_high)
|
||||
val none = stringResource(R.string.none)
|
||||
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
// DRO Mode
|
||||
SegmentedControl(
|
||||
title = stringResource(R.string.settings_dro_mode),
|
||||
items = RawProcessingPreferences.DROMode.entries,
|
||||
selectedItem = editDroMode,
|
||||
onItemSelected = { viewModel.setDroMode(it.name) },
|
||||
itemLabel = {
|
||||
when (it) {
|
||||
RawProcessingPreferences.DROMode.OFF -> droOff
|
||||
RawProcessingPreferences.DROMode.LOW -> droLow
|
||||
RawProcessingPreferences.DROMode.HIGH -> droHigh
|
||||
}
|
||||
}
|
||||
title = stringResource(R.string.settings_raw_profile),
|
||||
items = RawProfile.entries.toList(),
|
||||
selectedItem = rawProfile,
|
||||
onItemSelected = { viewModel.setRawProfile(it) },
|
||||
itemLabel = { rawProfileLabel(it) }
|
||||
)
|
||||
|
||||
// Color Space
|
||||
SegmentedControl(
|
||||
title = stringResource(R.string.settings_color_space),
|
||||
items = ColorSpace.values().toList(),
|
||||
selectedItem = editColorSpace,
|
||||
onItemSelected = { viewModel.setColorSpace(it) },
|
||||
itemLabel = { it.name }
|
||||
SliderSettingItem(
|
||||
title = stringResource(R.string.settings_raw_nlm_noise_factor),
|
||||
value = rawNlmNoiseFactor,
|
||||
valueRange = 0f..1f,
|
||||
onValueChange = onRawNlmNoiseFactorChange
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Log Curve
|
||||
SegmentedControl(
|
||||
title = stringResource(R.string.settings_log_curve),
|
||||
items = LogCurve.values().toList(),
|
||||
selectedItem = editLogCurve,
|
||||
onItemSelected = { viewModel.setLogCurve(it) },
|
||||
itemLabel = { it.name }
|
||||
)
|
||||
|
||||
// RAW LUT
|
||||
SegmentedControl(
|
||||
title = stringResource(R.string.settings_raw_restore_lut),
|
||||
items = availableRawLuts,
|
||||
selectedItem = editRawLut ?: "none",
|
||||
onItemSelected = { viewModel.setRawLut(editLogCurve, it) },
|
||||
itemLabel = { if (it == "none") none else it.substringBeforeLast(".") }
|
||||
)
|
||||
@Composable
|
||||
private fun rawProfileLabel(rawProfile: RawProfile): String {
|
||||
return when (rawProfile) {
|
||||
RawProfile.ACES_CINE -> stringResource(R.string.raw_profile_aces_cine)
|
||||
RawProfile.FUJI_PROVIA -> stringResource(R.string.raw_profile_fuji_provia)
|
||||
RawProfile.STANDARD_SRGB -> stringResource(R.string.raw_profile_standard_srgb)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1048,7 +1005,7 @@ private fun <T> SegmentedControl(
|
||||
items: List<T>,
|
||||
selectedItem: T,
|
||||
onItemSelected: (T) -> Unit,
|
||||
itemLabel: (T) -> String
|
||||
itemLabel: @Composable (T) -> String
|
||||
) {
|
||||
Column(modifier = Modifier.fillMaxWidth()) {
|
||||
Text(
|
||||
|
||||
@@ -90,8 +90,7 @@ import androidx.lifecycle.compose.LifecycleEventEffect
|
||||
import com.hinnka.mycamera.R
|
||||
import com.hinnka.mycamera.data.VolumeKeyAction
|
||||
import com.hinnka.mycamera.frame.FrameInfo
|
||||
import com.hinnka.mycamera.raw.ColorSpace
|
||||
import com.hinnka.mycamera.raw.LogCurve
|
||||
import com.hinnka.mycamera.raw.RawProfile
|
||||
import com.hinnka.mycamera.ui.camera.autoRotate
|
||||
import com.hinnka.mycamera.ui.components.LogViewerDialog
|
||||
import com.hinnka.mycamera.ui.components.PaymentDialog
|
||||
@@ -138,11 +137,7 @@ fun SettingsScreen(
|
||||
val useLivePhoto by viewModel.useLivePhoto.collectAsState()
|
||||
val photoQuality by viewModel.photoQuality.collectAsState(initial = 95)
|
||||
val useGpuAcceleration by viewModel.useGpuAcceleration.collectAsState()
|
||||
val droMode by viewModel.droMode.collectAsState()
|
||||
val applyUltraHDR by viewModel.applyUltraHDR.collectAsState()
|
||||
val colorSpace by viewModel.colorSpace.collectAsState()
|
||||
val logCurve by viewModel.logCurve.collectAsState()
|
||||
val rawLut by viewModel.rawLut.collectAsState()
|
||||
val rawProfile by viewModel.rawProfile.collectAsState()
|
||||
val useP010 by viewModel.useP010.collectAsState()
|
||||
val useP3ColorSpace by viewModel.useP3ColorSpace.collectAsState()
|
||||
val autoEnableHdrForHdrCapture by viewModel.autoEnableHdrForHdrCapture.collectAsState()
|
||||
@@ -156,8 +151,6 @@ fun SettingsScreen(
|
||||
val saveLocation by viewModel.saveLocationEnabled.collectAsState(initial = false)
|
||||
val useBuiltInAiService by viewModel.useBuiltInAiService.collectAsState()
|
||||
val openAIApiKey by viewModel.openAIApiKey.collectAsState()
|
||||
val openAIUrl by viewModel.openAIUrl.collectAsState()
|
||||
val openAIModel by viewModel.openAIModel.collectAsState()
|
||||
val availableOpenAIModels by viewModel.availableOpenAIModels.collectAsState()
|
||||
val isFetchingAIModels by viewModel.isFetchingAIModels.collectAsState()
|
||||
val phantomSaveAsNew by viewModel.phantomSaveAsNew.collectAsState()
|
||||
@@ -212,12 +205,9 @@ fun SettingsScreen(
|
||||
var showLogViewerDialog by remember { mutableStateOf(false) }
|
||||
var softwareProcessingExpanded by remember { mutableStateOf(false) }
|
||||
var calibrationExpanded by remember { mutableStateOf(false) }
|
||||
var availableRawLutMap by remember { mutableStateOf(listOf<Pair<String, String>>()) }
|
||||
var showGhostPermissionDialog by remember { mutableStateOf(false) }
|
||||
var isGhostPermissionFlowActive by remember { mutableStateOf(false) }
|
||||
|
||||
val noneStr = stringResource(R.string.none)
|
||||
|
||||
val ghostLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.StartActivityForResult(),
|
||||
onResult = { _ ->
|
||||
@@ -225,13 +215,6 @@ fun SettingsScreen(
|
||||
}
|
||||
)
|
||||
|
||||
LaunchedEffect(logCurve) {
|
||||
availableRawLutMap = listOf("none" to noneStr) + viewModel.getAvailableRawLutList(context, logCurve)
|
||||
.map {
|
||||
it to it.substringBeforeLast(".")
|
||||
}
|
||||
}
|
||||
|
||||
LifecycleEventEffect(Lifecycle.Event.ON_RESUME) {
|
||||
if (isGhostPermissionFlowActive) {
|
||||
val hasOverlay = Settings.canDrawOverlays(context)
|
||||
@@ -652,42 +635,11 @@ fun SettingsScreen(
|
||||
SettingsTab.IMAGING -> {
|
||||
// AI 服务设置
|
||||
SettingsSection(title = stringResource(R.string.lut_creator_title)) {
|
||||
SwitchSettingItem(
|
||||
title = stringResource(R.string.settings_use_built_in_ai),
|
||||
description = stringResource(R.string.settings_use_built_in_ai_desc),
|
||||
checked = useBuiltInAiService,
|
||||
onCheckedChange = { viewModel.setUseBuiltInAiService(it) }
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
color = Color.White.copy(alpha = 0.1f),
|
||||
modifier = Modifier.padding(vertical = 8.dp)
|
||||
)
|
||||
|
||||
if (!useBuiltInAiService) {
|
||||
TextInputSettingItem(
|
||||
title = stringResource(R.string.settings_openai_api_key),
|
||||
description = stringResource(R.string.settings_openai_api_key_desc),
|
||||
value = openAIApiKey ?: "",
|
||||
onValueChange = { viewModel.setOpenAIApiKey(it) }
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
color = Color.White.copy(alpha = 0.1f),
|
||||
modifier = Modifier.padding(vertical = 8.dp)
|
||||
)
|
||||
}
|
||||
|
||||
DropdownSettingItem(
|
||||
title = stringResource(R.string.settings_ai_model),
|
||||
description = stringResource(R.string.settings_ai_model_desc),
|
||||
value = if (useBuiltInAiService) com.hinnka.mycamera.lut.creator.OpenAIApiClient.BUILT_IN_IMAGE_MODEL else openAIModel
|
||||
?: "",
|
||||
options = if (useBuiltInAiService) listOf(com.hinnka.mycamera.lut.creator.OpenAIApiClient.BUILT_IN_IMAGE_MODEL) else availableOpenAIModels,
|
||||
isLoading = isFetchingAIModels,
|
||||
enabled = !useBuiltInAiService,
|
||||
onExpanded = { viewModel.fetchAvailableAIModels() },
|
||||
onOptionSelected = { viewModel.setOpenAIModel(it) }
|
||||
TextInputSettingItem(
|
||||
title = stringResource(R.string.settings_openai_api_key),
|
||||
description = stringResource(R.string.settings_openai_api_key_desc),
|
||||
value = openAIApiKey ?: "",
|
||||
onValueChange = { viewModel.setOpenAIApiKey(it) }
|
||||
)
|
||||
}
|
||||
|
||||
@@ -823,54 +775,11 @@ fun SettingsScreen(
|
||||
)
|
||||
|
||||
QualityLevelSetting(
|
||||
title = stringResource(R.string.settings_dro_mode),
|
||||
description = stringResource(R.string.settings_dro_mode_description),
|
||||
levels = listOf(
|
||||
"OFF" to stringResource(R.string.settings_dro_off),
|
||||
"LOW" to stringResource(R.string.settings_dro_low),
|
||||
"HIGH" to stringResource(R.string.settings_dro_high)
|
||||
),
|
||||
currentLevel = droMode,
|
||||
onLevelSelected = { viewModel.setDroMode(it) }
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
color = Color.White.copy(alpha = 0.1f),
|
||||
modifier = Modifier.padding(vertical = 12.dp)
|
||||
)
|
||||
|
||||
QualityLevelSetting(
|
||||
title = stringResource(R.string.settings_color_space),
|
||||
description = stringResource(R.string.settings_color_space_description),
|
||||
levels = ColorSpace.entries.map { it to it.name },
|
||||
currentLevel = colorSpace,
|
||||
onLevelSelected = { viewModel.setColorSpace(it) }
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
color = Color.White.copy(alpha = 0.1f),
|
||||
modifier = Modifier.padding(vertical = 12.dp)
|
||||
)
|
||||
|
||||
QualityLevelSetting(
|
||||
title = stringResource(R.string.settings_log_curve),
|
||||
description = stringResource(R.string.settings_log_curve_description),
|
||||
levels = LogCurve.entries.map { it to it.name },
|
||||
currentLevel = logCurve,
|
||||
onLevelSelected = { viewModel.setLogCurve(it) }
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
color = Color.White.copy(alpha = 0.1f),
|
||||
modifier = Modifier.padding(vertical = 12.dp)
|
||||
)
|
||||
|
||||
QualityLevelSetting(
|
||||
title = stringResource(R.string.settings_raw_restore_lut),
|
||||
description = stringResource(R.string.settings_raw_restore_lut_description),
|
||||
levels = availableRawLutMap,
|
||||
currentLevel = rawLut,
|
||||
onLevelSelected = { viewModel.setRawLut(logCurve, it) }
|
||||
title = stringResource(R.string.settings_raw_profile),
|
||||
description = stringResource(R.string.settings_raw_profile_description),
|
||||
levels = RawProfile.entries.map { it to rawProfileLabel(it) },
|
||||
currentLevel = rawProfile,
|
||||
onLevelSelected = { viewModel.setRawProfile(it) }
|
||||
)
|
||||
|
||||
/*HorizontalDivider(
|
||||
@@ -1859,6 +1768,15 @@ fun <T> QualityLevelSetting(
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun rawProfileLabel(rawProfile: RawProfile): String {
|
||||
return when (rawProfile) {
|
||||
RawProfile.ACES_CINE -> stringResource(R.string.raw_profile_aces_cine)
|
||||
RawProfile.FUJI_PROVIA -> stringResource(R.string.raw_profile_fuji_provia)
|
||||
RawProfile.STANDARD_SRGB -> stringResource(R.string.raw_profile_standard_srgb)
|
||||
}
|
||||
}
|
||||
|
||||
private fun android.content.Context.findActivity(): android.app.Activity? {
|
||||
var context = this
|
||||
while (context is android.content.ContextWrapper) {
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.hinnka.mycamera.phantom.PhantomWidgetProvider
|
||||
import com.hinnka.mycamera.raw.ColorSpace
|
||||
import com.hinnka.mycamera.raw.LogCurve
|
||||
import com.hinnka.mycamera.raw.RawDemosaicProcessor
|
||||
import com.hinnka.mycamera.raw.RawProfile
|
||||
import com.hinnka.mycamera.raw.rawFolder
|
||||
import com.hinnka.mycamera.ui.camera.CameraGLSurfaceView
|
||||
import com.hinnka.mycamera.utils.*
|
||||
@@ -202,8 +203,19 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
.stateIn(viewModelScope, SharingStarted.Eagerly, LogCurve.FLOG2)
|
||||
|
||||
val rawLut: StateFlow<String> = userPreferencesRepository.userPreferences
|
||||
.map { it.rawLuts[it.logCurve.name] ?: "sRGB.plut" }
|
||||
.stateIn(viewModelScope, SharingStarted.Eagerly, "sRGB.plut")
|
||||
.map { prefs ->
|
||||
prefs.rawLuts[prefs.logCurve.name] ?: RawProfile.defaultLutFor(prefs.colorSpace, prefs.logCurve)
|
||||
}
|
||||
.stateIn(viewModelScope, SharingStarted.Eagerly, RawProfile.default.rawLut)
|
||||
val rawProfile: StateFlow<RawProfile> = userPreferencesRepository.userPreferences
|
||||
.map { prefs ->
|
||||
RawProfile.fromComponents(
|
||||
colorSpace = prefs.colorSpace,
|
||||
logCurve = prefs.logCurve,
|
||||
rawLut = prefs.rawLuts[prefs.logCurve.name]
|
||||
)
|
||||
}
|
||||
.stateIn(viewModelScope, SharingStarted.Eagerly, RawProfile.default)
|
||||
|
||||
val useP010: StateFlow<Boolean> = userPreferencesRepository.userPreferences
|
||||
.map { it.useP010 }
|
||||
@@ -361,7 +373,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
RawDemosaicProcessor.getInstance().setRawColorSpace(it.colorSpace)
|
||||
RawDemosaicProcessor.getInstance().setRawLogCurve(it.logCurve)
|
||||
// 同步当前 Log 曲线对应的 RAW LUT
|
||||
val currentRawLut = it.rawLuts[it.logCurve.name] ?: "Default.plut"
|
||||
val currentRawLut = it.rawLuts[it.logCurve.name]
|
||||
?: RawProfile.defaultLutFor(it.colorSpace, it.logCurve)
|
||||
RawDemosaicProcessor.getInstance().setRawLut(application, currentRawLut)
|
||||
// 同步 P010 设置到相机控制器
|
||||
cameraController.setUseP010(it.useP010)
|
||||
@@ -1763,6 +1776,12 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
fun setRawProfile(rawProfile: RawProfile) {
|
||||
viewModelScope.launch {
|
||||
userPreferencesRepository.saveRawProfile(rawProfile)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置降噪等级
|
||||
*/
|
||||
|
||||
@@ -248,6 +248,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
private set
|
||||
var editChromaNoiseReduction = MutableStateFlow(0f)
|
||||
private set
|
||||
var editRawDenoise = MutableStateFlow(0.2f)
|
||||
private set
|
||||
|
||||
// Computational Bokeh editing state
|
||||
var editComputationalAperture = MutableStateFlow<Float?>(null)
|
||||
@@ -747,6 +749,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editSharpening.value = m.sharpening ?: 0f
|
||||
editNoiseReduction.value = m.noiseReduction ?: 0f
|
||||
editChromaNoiseReduction.value = m.chromaNoiseReduction ?: 0f
|
||||
editRawDenoise.value = m.rawDenoiseValue ?: 0.2f
|
||||
restoreCropEditState(photo, m)
|
||||
|
||||
// 加载 LUT 配置
|
||||
@@ -1263,6 +1266,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editChromaNoiseReduction.value =
|
||||
metadata.chromaNoiseReduction
|
||||
?: (if (metadata.isImported) 0f else chromaNoiseReduction.value)
|
||||
editRawDenoise.value = metadata.rawDenoiseValue ?: 0.2f
|
||||
|
||||
editComputationalAperture.value = metadata.computationalAperture
|
||||
editFocusPointX.value = metadata.focusPointX
|
||||
@@ -1275,6 +1279,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editSharpening.value = sharpening.value
|
||||
editNoiseReduction.value = noiseReduction.value
|
||||
editChromaNoiseReduction.value = chromaNoiseReduction.value
|
||||
editRawDenoise.value = 0.2f
|
||||
editComputationalAperture.value = null
|
||||
editFocusPointX.value = null
|
||||
editFocusPointY.value = null
|
||||
@@ -1301,6 +1306,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editFrameId.value = null
|
||||
editCropRect.value = null
|
||||
editCropAspectOption.value = CropAspectOption.Free
|
||||
editRawDenoise.value = 0.2f
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1386,6 +1392,10 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
editChromaNoiseReduction.value = value
|
||||
}
|
||||
|
||||
fun setRawDenoiseValue(value: Float) {
|
||||
editRawDenoise.value = value
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置裁剪矩形(归一化坐标 0-1)
|
||||
*/
|
||||
@@ -1517,6 +1527,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
sharpening = editSharpening.value,
|
||||
noiseReduction = editNoiseReduction.value,
|
||||
chromaNoiseReduction = editChromaNoiseReduction.value,
|
||||
rawDenoiseValue = editRawDenoise.value,
|
||||
computationalAperture = editComputationalAperture.value,
|
||||
focusPointX = editFocusPointX.value,
|
||||
focusPointY = editFocusPointY.value,
|
||||
@@ -1736,6 +1747,7 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
sharpening = editSharpening.value,
|
||||
noiseReduction = editNoiseReduction.value,
|
||||
chromaNoiseReduction = editChromaNoiseReduction.value,
|
||||
rawDenoiseValue = editRawDenoise.value,
|
||||
computationalAperture = editComputationalAperture.value,
|
||||
focusPointX = editFocusPointX.value,
|
||||
focusPointY = editFocusPointY.value,
|
||||
|
||||
@@ -381,12 +381,19 @@
|
||||
<string name="settings_default_focal_length_description">设置启动 App 时自动切换到的焦段</string>
|
||||
<string name="settings_raw_restore_lut">RAW 还原 LUT</string>
|
||||
<string name="settings_raw_restore_lut_description">选择用于 RAW 色彩还原的 LUT。选择“无”以获得 Log 风格输出。</string>
|
||||
<string name="settings_raw_profile">RAW 风格方案</string>
|
||||
<string name="settings_raw_profile_description">统一设置 RAW 的色彩空间、Log 曲线和还原 LUT。</string>
|
||||
<string name="settings_dro_mode">RAW动态范围优化 (DRO)</string>
|
||||
<string name="settings_dro_mode_description">通过利用 Log 曲线高光冗余,在不牺牲高光的前提下提升阴影细节。</string>
|
||||
<string name="settings_dro_off">关闭</string>
|
||||
<string name="settings_dro_low">中等</string>
|
||||
<string name="settings_dro_high">最高</string>
|
||||
<string name="settings_log_curve_description">选择 RAW 处理的传输函数 (Log 曲线)。</string>
|
||||
<string name="raw_profile_aces_cine">ACES 电影</string>
|
||||
<string name="raw_profile_apple_cinema">Apple 电影</string>
|
||||
<string name="raw_profile_arri_master">ARRI 大师</string>
|
||||
<string name="raw_profile_fuji_provia">富士 PROVIA</string>
|
||||
<string name="raw_profile_standard_srgb">标准 sRGB</string>
|
||||
<string name="settings_use_p010">P010 (10位 YUV)</string>
|
||||
<string name="settings_use_p010_description">启用 10位 YUV 输出以获得更好的图像数据精度。仅在支持的设备上且 RAW 关闭时生效。</string>
|
||||
<string name="settings_use_p3_color_space">P3 色域</string>
|
||||
@@ -411,6 +418,9 @@
|
||||
<string name="settings_color_space">RAW 色彩空间</string>
|
||||
<string name="settings_color_space_description">选择 RAW 处理的目标色彩空间。</string>
|
||||
<string name="settings_log_curve">RAW 伽马</string>
|
||||
<string name="settings_raw_nlm_base_h">RAW NLM 基础强度</string>
|
||||
<string name="settings_raw_nlm_gain_factor">RAW NLM 增益响应</string>
|
||||
<string name="settings_raw_nlm_noise_factor">RAW 降噪</string>
|
||||
<string name="ghost_mode">幻影模式</string>
|
||||
<string name="close_ghost_mode">关闭幻影模式</string>
|
||||
<string name="ghost_mode_dialog_title">开启幻影模式</string>
|
||||
|
||||
@@ -380,12 +380,19 @@
|
||||
<string name="settings_default_focal_length_description">設定啟動 App 時自動切換到的焦段</string>
|
||||
<string name="settings_raw_restore_lut">RAW 還原 LUT</string>
|
||||
<string name="settings_raw_restore_lut_description">選擇用於 RAW 色彩還原的 LUT。選擇「無」以獲得 Log 風格輸出。</string>
|
||||
<string name="settings_raw_profile">RAW 風格方案</string>
|
||||
<string name="settings_raw_profile_description">統一設定 RAW 的色彩空間、Log 曲線與還原 LUT。</string>
|
||||
<string name="settings_dro_mode">RAW 動態範圍最佳化 (DRO)</string>
|
||||
<string name="settings_dro_mode_description">透過利用 Log 曲線高光冗餘,在不犧牲高光的前提下提升陰影細節。</string>
|
||||
<string name="settings_dro_off">關閉</string>
|
||||
<string name="settings_dro_low">中等</string>
|
||||
<string name="settings_dro_high">最高</string>
|
||||
<string name="settings_log_curve_description">選擇 RAW 處理的傳輸函數 (Log 曲線)。</string>
|
||||
<string name="raw_profile_aces_cine">ACES 電影</string>
|
||||
<string name="raw_profile_apple_cinema">Apple 電影</string>
|
||||
<string name="raw_profile_arri_master">ARRI 大師</string>
|
||||
<string name="raw_profile_fuji_provia">富士 PROVIA</string>
|
||||
<string name="raw_profile_standard_srgb">標準 sRGB</string>
|
||||
<string name="settings_use_p010">P010 (10 位 YUV)</string>
|
||||
<string name="settings_use_p010_description">啟用 10 位 YUV 輸出以獲得更好的影像資料精度。僅在支援的裝置上且 RAW 關閉時生效。</string>
|
||||
<string name="refresh">重新整理</string>
|
||||
|
||||
@@ -390,6 +390,8 @@
|
||||
<string name="settings_default_focal_length_description">Set the focal length to automatically switch to when the app starts.</string>
|
||||
<string name="settings_raw_restore_lut">RAW Restore LUT</string>
|
||||
<string name="settings_raw_restore_lut_description">Choose the LUT used for RAW color restoration. Use \"None\" for log output.</string>
|
||||
<string name="settings_raw_profile">RAW Look</string>
|
||||
<string name="settings_raw_profile_description">Choose a unified RAW rendering profile that sets the color space, log curve, and restore LUT together.</string>
|
||||
<string name="settings_dro_mode">RAW Dynamic Range Optimizer (DRO)</string>
|
||||
<string name="settings_dro_mode_description">Optimizes shadow detail and highlight compression by utilizing Log curve headroom. Higher values preserve more highlights but may require more light.</string>
|
||||
<string name="settings_dro_off">Off</string>
|
||||
@@ -401,6 +403,14 @@
|
||||
<string name="settings_color_space_description">Choose the target color space for RAW processing.</string>
|
||||
<string name="settings_log_curve">RAW Gamma</string>
|
||||
<string name="settings_log_curve_description">Choose the transfer function for RAW processing (Log Curve).</string>
|
||||
<string name="raw_profile_aces_cine">ACES Cine</string>
|
||||
<string name="raw_profile_apple_cinema">Apple Cinema</string>
|
||||
<string name="raw_profile_arri_master">ARRI Master</string>
|
||||
<string name="raw_profile_fuji_provia">Fuji Provia</string>
|
||||
<string name="raw_profile_standard_srgb">Standard sRGB</string>
|
||||
<string name="settings_raw_nlm_base_h">RAW NLM Base Strength</string>
|
||||
<string name="settings_raw_nlm_gain_factor">RAW NLM Gain Response</string>
|
||||
<string name="settings_raw_nlm_noise_factor">RAW Denoise</string>
|
||||
<string name="settings_use_p010">P010 (10-bit YUV)</string>
|
||||
<string name="settings_use_p010_description">Enable 10-bit YUV output for better image data precision. Effective on supported devices when RAW is disabled.</string>
|
||||
<string name="settings_use_p3_color_space">P3 Color Space</string>
|
||||
|
||||
Reference in new issue
Block a user