feat: color graing
This commit is contained in:
1 parent
763b9ff097
commit
f7b41e69ff
26 files changed
+922
-6
No files matched your search
@@ -8,7 +8,7 @@ import com.hinnka.mycamera.raw.RawToneMappingParameters
|
||||
|
||||
@Database(
|
||||
entities = [GalleryMediaEntity::class],
|
||||
version = 30,
|
||||
version = 31,
|
||||
exportSchema = false
|
||||
)
|
||||
@androidx.room.TypeConverters(GalleryConverters::class)
|
||||
@@ -249,6 +249,33 @@ abstract class GalleryDatabase : RoomDatabase() {
|
||||
}
|
||||
}
|
||||
|
||||
private val MIGRATION_30_31 = object : androidx.room.migration.Migration(30, 31) {
|
||||
override fun migrate(db: androidx.sqlite.db.SupportSQLiteDatabase) {
|
||||
val gradingColumns = listOf(
|
||||
"gradingShadowHue",
|
||||
"gradingShadowAmount",
|
||||
"gradingMidtoneHue",
|
||||
"gradingMidtoneAmount",
|
||||
"gradingHighlightHue",
|
||||
"gradingHighlightAmount",
|
||||
"gradingBalance",
|
||||
"gradingBlending"
|
||||
)
|
||||
gradingColumns.forEach { column ->
|
||||
db.execSQL("ALTER TABLE gallery_media ADD COLUMN recipe_$column REAL")
|
||||
db.execSQL("ALTER TABLE gallery_media ADD COLUMN baseline_recipe_$column REAL")
|
||||
}
|
||||
db.execSQL(
|
||||
"UPDATE gallery_media SET recipe_gradingBlending = 0.5 " +
|
||||
"WHERE recipe_exposure IS NOT NULL"
|
||||
)
|
||||
db.execSQL(
|
||||
"UPDATE gallery_media SET baseline_recipe_gradingBlending = 0.5 " +
|
||||
"WHERE baseline_recipe_exposure IS NOT NULL"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun rebuildGalleryMediaWithoutLegacyGoogleToneMapFlag(
|
||||
db: androidx.sqlite.db.SupportSQLiteDatabase
|
||||
) {
|
||||
@@ -610,7 +637,8 @@ abstract class GalleryDatabase : RoomDatabase() {
|
||||
MIGRATION_26_27,
|
||||
MIGRATION_27_28,
|
||||
MIGRATION_28_29,
|
||||
MIGRATION_29_30
|
||||
MIGRATION_29_30,
|
||||
MIGRATION_30_31
|
||||
)
|
||||
.fallbackToDestructiveMigrationOnDowngrade(false)
|
||||
.fallbackToDestructiveMigration(false)
|
||||
|
||||
@@ -43,6 +43,10 @@ internal data class ColorPassLocations(
|
||||
val uNoiseSeedLocation: Int,
|
||||
val uLowResLocation: Int,
|
||||
val uAspectRatioLocation: Int,
|
||||
val uGradingHuesLocation: Int,
|
||||
val uGradingAmountsLocation: Int,
|
||||
val uGradingBalanceLocation: Int,
|
||||
val uGradingBlendingLocation: Int,
|
||||
val uLchHueAdjustmentsLocation: Int,
|
||||
val uLchChromaAdjustmentsLocation: Int,
|
||||
val uLchLightnessAdjustmentsLocation: Int,
|
||||
@@ -140,6 +144,10 @@ internal class PreviewColorProgramCache {
|
||||
uNoiseSeedLocation = GLES30.glGetUniformLocation(program, "uNoiseSeed"),
|
||||
uLowResLocation = GLES30.glGetUniformLocation(program, "uLowRes"),
|
||||
uAspectRatioLocation = GLES30.glGetUniformLocation(program, "uAspectRatio"),
|
||||
uGradingHuesLocation = GLES30.glGetUniformLocation(program, "uGradingHues"),
|
||||
uGradingAmountsLocation = GLES30.glGetUniformLocation(program, "uGradingAmounts"),
|
||||
uGradingBalanceLocation = GLES30.glGetUniformLocation(program, "uGradingBalance"),
|
||||
uGradingBlendingLocation = GLES30.glGetUniformLocation(program, "uGradingBlending"),
|
||||
uLchHueAdjustmentsLocation = GLES30.glGetUniformLocation(program, "uLchHueAdjustments"),
|
||||
uLchChromaAdjustmentsLocation = GLES30.glGetUniformLocation(program, "uLchChromaAdjustments"),
|
||||
uLchLightnessAdjustmentsLocation = GLES30.glGetUniformLocation(program, "uLchLightnessAdjustments"),
|
||||
|
||||
@@ -1101,6 +1101,26 @@ class LutImageProcessor(context: Context? = null) {
|
||||
GLES30.glGetUniformLocation(program, "uAspectRatio"),
|
||||
width.toFloat() / Math.max(1, height).toFloat()
|
||||
)
|
||||
GLES30.glUniform3f(
|
||||
GLES30.glGetUniformLocation(program, "uGradingHues"),
|
||||
effectiveRecipeParams.gradingShadowHue,
|
||||
effectiveRecipeParams.gradingMidtoneHue,
|
||||
effectiveRecipeParams.gradingHighlightHue
|
||||
)
|
||||
GLES30.glUniform3f(
|
||||
GLES30.glGetUniformLocation(program, "uGradingAmounts"),
|
||||
effectiveRecipeParams.gradingShadowAmount,
|
||||
effectiveRecipeParams.gradingMidtoneAmount,
|
||||
effectiveRecipeParams.gradingHighlightAmount
|
||||
)
|
||||
GLES30.glUniform1f(
|
||||
GLES30.glGetUniformLocation(program, "uGradingBalance"),
|
||||
effectiveRecipeParams.gradingBalance
|
||||
)
|
||||
GLES30.glUniform1f(
|
||||
GLES30.glGetUniformLocation(program, "uGradingBlending"),
|
||||
effectiveRecipeParams.gradingBlending
|
||||
)
|
||||
ColorRecipeGl.bindLchAdjustments(
|
||||
uLchHueAdjustmentsLoc,
|
||||
uLchChromaAdjustmentsLoc,
|
||||
@@ -3559,6 +3579,10 @@ class LutImageProcessor(context: Context? = null) {
|
||||
uniform float uNoiseSeed; // 噪点随机种子
|
||||
uniform float uLowRes; // 0.0 ~ 1.0 (低像素强度)
|
||||
uniform float uAspectRatio; // 图像长宽比
|
||||
uniform vec3 uGradingHues;
|
||||
uniform vec3 uGradingAmounts;
|
||||
uniform float uGradingBalance;
|
||||
uniform float uGradingBlending;
|
||||
|
||||
// Primary Calibration
|
||||
uniform mat3 uPrimaryCalibrationMatrix;
|
||||
@@ -3590,6 +3614,7 @@ class LutImageProcessor(context: Context? = null) {
|
||||
${PreviewColorShaderModules.HLG_TO_LINEAR}
|
||||
${PreviewColorShaderModules.EXPOSURE}
|
||||
${DirectFlashShader.GLSL}
|
||||
${ThreeWayColorGradingShader.GLSL}
|
||||
${PreviewColorShaderModules.SANITIZE}
|
||||
${BasicToneLutShader.GLSL}
|
||||
|
||||
@@ -3789,6 +3814,18 @@ class LutImageProcessor(context: Context? = null) {
|
||||
color.rgb = applyLchColorMixer(color.rgb);
|
||||
color.rgb = sanitizeColor(color.rgb);
|
||||
|
||||
color.rgb = applyThreeWayColorGrading(
|
||||
color.rgb,
|
||||
uGradingHues,
|
||||
uGradingAmounts,
|
||||
uGradingBalance,
|
||||
uGradingBlending,
|
||||
(uInputColorSpace == 1)
|
||||
? vec3(0.2290, 0.6917, 0.0793)
|
||||
: vec3(0.2126, 0.7152, 0.0722)
|
||||
);
|
||||
color.rgb = sanitizeColor(color.rgb);
|
||||
|
||||
// 7. 褪色效果
|
||||
if (uFade > 0.0) {
|
||||
float fadeAmount = uFade * 0.3;
|
||||
|
||||
@@ -58,6 +58,10 @@ class LutManager(private val context: Context) {
|
||||
"blueHue", "blueChroma", "blueLightness",
|
||||
"purpleHue", "purpleChroma", "purpleLightness",
|
||||
"magentaHue", "magentaChroma", "magentaLightness",
|
||||
"gradingShadowHue", "gradingShadowAmount",
|
||||
"gradingMidtoneHue", "gradingMidtoneAmount",
|
||||
"gradingHighlightHue", "gradingHighlightAmount",
|
||||
"gradingBalance", "gradingBlending",
|
||||
"lutIntensity"
|
||||
)
|
||||
|
||||
@@ -120,6 +124,14 @@ class LutManager(private val context: Context) {
|
||||
magentaHue = f("magentaHue"),
|
||||
magentaChroma = f("magentaChroma"),
|
||||
magentaLightness = f("magentaLightness"),
|
||||
gradingShadowHue = f("gradingShadowHue"),
|
||||
gradingShadowAmount = f("gradingShadowAmount"),
|
||||
gradingMidtoneHue = f("gradingMidtoneHue"),
|
||||
gradingMidtoneAmount = f("gradingMidtoneAmount"),
|
||||
gradingHighlightHue = f("gradingHighlightHue"),
|
||||
gradingHighlightAmount = f("gradingHighlightAmount"),
|
||||
gradingBalance = f("gradingBalance"),
|
||||
gradingBlending = f("gradingBlending", 0.5f),
|
||||
lutIntensity = f("lutIntensity", 1f),
|
||||
remarks = s("remarks"),
|
||||
)
|
||||
|
||||
@@ -454,6 +454,14 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer {
|
||||
@Volatile var primaryBlueHue: Float = 0f
|
||||
@Volatile var primaryBlueSaturation: Float = 0f
|
||||
@Volatile var primaryBlueLightness: Float = 0f
|
||||
@Volatile var gradingShadowHue: Float = 0f
|
||||
@Volatile var gradingShadowAmount: Float = 0f
|
||||
@Volatile var gradingMidtoneHue: Float = 0f
|
||||
@Volatile var gradingMidtoneAmount: Float = 0f
|
||||
@Volatile var gradingHighlightHue: Float = 0f
|
||||
@Volatile var gradingHighlightAmount: Float = 0f
|
||||
@Volatile var gradingBalance: Float = 0f
|
||||
@Volatile var gradingBlending: Float = 0.5f
|
||||
|
||||
private val lchHueAdjustments = FloatArray(LCH_COLOR_BAND_COUNT)
|
||||
private val lchChromaAdjustments = FloatArray(LCH_COLOR_BAND_COUNT)
|
||||
@@ -1457,6 +1465,20 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer {
|
||||
GLES30.glUniform1f(locations.uNoiseSeedLocation, (System.currentTimeMillis() % 10000) / 1000f)
|
||||
GLES30.glUniform1f(locations.uLowResLocation, params.lowRes)
|
||||
GLES30.glUniform1f(locations.uAspectRatioLocation, width.toFloat() / maxOf(1, height).toFloat())
|
||||
GLES30.glUniform3f(
|
||||
locations.uGradingHuesLocation,
|
||||
params.gradingShadowHue,
|
||||
params.gradingMidtoneHue,
|
||||
params.gradingHighlightHue
|
||||
)
|
||||
GLES30.glUniform3f(
|
||||
locations.uGradingAmountsLocation,
|
||||
params.gradingShadowAmount,
|
||||
params.gradingMidtoneAmount,
|
||||
params.gradingHighlightAmount
|
||||
)
|
||||
GLES30.glUniform1f(locations.uGradingBalanceLocation, params.gradingBalance)
|
||||
GLES30.glUniform1f(locations.uGradingBlendingLocation, params.gradingBlending)
|
||||
val lch = ColorRecipeGl.lchAdjustments(params)
|
||||
val primaryCalibrationMatrix = CameraRawCalibrationMatrix.build(params)
|
||||
ColorRecipeGl.bindLchAdjustments(
|
||||
@@ -3953,6 +3975,14 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer {
|
||||
primaryBlueHue = primaryBlueHue,
|
||||
primaryBlueSaturation = primaryBlueSaturation,
|
||||
primaryBlueLightness = primaryBlueLightness,
|
||||
gradingShadowHue = gradingShadowHue,
|
||||
gradingShadowAmount = gradingShadowAmount,
|
||||
gradingMidtoneHue = gradingMidtoneHue,
|
||||
gradingMidtoneAmount = gradingMidtoneAmount,
|
||||
gradingHighlightHue = gradingHighlightHue,
|
||||
gradingHighlightAmount = gradingHighlightAmount,
|
||||
gradingBalance = gradingBalance,
|
||||
gradingBlending = gradingBlending,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4004,6 +4034,14 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer {
|
||||
primaryBlueHue = params.primaryBlueHue
|
||||
primaryBlueSaturation = params.primaryBlueSaturation
|
||||
primaryBlueLightness = params.primaryBlueLightness
|
||||
gradingShadowHue = params.gradingShadowHue
|
||||
gradingShadowAmount = params.gradingShadowAmount
|
||||
gradingMidtoneHue = params.gradingMidtoneHue
|
||||
gradingMidtoneAmount = params.gradingMidtoneAmount
|
||||
gradingHighlightHue = params.gradingHighlightHue
|
||||
gradingHighlightAmount = params.gradingHighlightAmount
|
||||
gradingBalance = params.gradingBalance
|
||||
gradingBlending = params.gradingBlending
|
||||
val lch = ColorRecipeGl.lchAdjustments(params)
|
||||
setLchAdjustments(lch.hue, lch.chroma, lch.lightness)
|
||||
// 更新曲线纹理
|
||||
|
||||
@@ -61,6 +61,10 @@ internal object PreviewColorShader {
|
||||
uniform float uNoiseSeed;
|
||||
uniform float uLowRes;
|
||||
uniform float uAspectRatio;
|
||||
uniform vec3 uGradingHues;
|
||||
uniform vec3 uGradingAmounts;
|
||||
uniform float uGradingBalance;
|
||||
uniform float uGradingBlending;
|
||||
uniform mat3 uPrimaryCalibrationMatrix;
|
||||
uniform float uAperture;
|
||||
uniform vec2 uFocusPoint;
|
||||
@@ -75,6 +79,7 @@ internal object PreviewColorShader {
|
||||
${if (variant.includeHlgInput) PreviewColorShaderModules.HLG_TO_LINEAR else PreviewColorShaderModules.HLG_TO_LINEAR_STUB}
|
||||
${PreviewColorShaderModules.EXPOSURE}
|
||||
${DirectFlashShader.GLSL}
|
||||
${ThreeWayColorGradingShader.GLSL}
|
||||
${PreviewColorShaderModules.SANITIZE}
|
||||
${BasicToneLutShader.GLSL}
|
||||
|
||||
@@ -209,6 +214,16 @@ internal object PreviewColorShader {
|
||||
color.rgb = applyLchColorMixer(color.rgb);
|
||||
color.rgb = sanitizeColor(color.rgb);
|
||||
|
||||
color.rgb = applyThreeWayColorGrading(
|
||||
color.rgb,
|
||||
uGradingHues,
|
||||
uGradingAmounts,
|
||||
uGradingBalance,
|
||||
uGradingBlending,
|
||||
W
|
||||
);
|
||||
color.rgb = sanitizeColor(color.rgb);
|
||||
|
||||
if (uFade > 0.001) {
|
||||
float fadeAmount = uFade * 0.3;
|
||||
color.rgb = mix(color.rgb, vec3(0.5), fadeAmount) + fadeAmount * 0.1;
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.hinnka.mycamera.lut
|
||||
|
||||
/**
|
||||
* 阴影、中间调和高光三向色彩分级。
|
||||
*
|
||||
* 着色向量移除自身亮度分量,避免色相调整隐式改变画面曝光。
|
||||
*/
|
||||
internal object ThreeWayColorGradingShader {
|
||||
val GLSL = """
|
||||
vec3 gradingHueColor(float hue) {
|
||||
vec3 phase = abs(
|
||||
fract(vec3(hue) + vec3(0.0, 2.0 / 3.0, 1.0 / 3.0)) * 6.0 - 3.0
|
||||
);
|
||||
vec3 pureHue = clamp(phase - 1.0, 0.0, 1.0);
|
||||
return mix(vec3(1.0), pureHue, 0.72);
|
||||
}
|
||||
|
||||
vec3 gradingChromaAxis(float hue, vec3 lumaWeights) {
|
||||
vec3 hueColor = gradingHueColor(fract(hue));
|
||||
return hueColor - vec3(dot(hueColor, lumaWeights));
|
||||
}
|
||||
|
||||
vec3 applyThreeWayColorGrading(
|
||||
vec3 color,
|
||||
vec3 hues,
|
||||
vec3 amounts,
|
||||
float balance,
|
||||
float blending,
|
||||
vec3 lumaWeights
|
||||
) {
|
||||
vec3 safeAmounts = clamp(amounts, 0.0, 1.0);
|
||||
if (max(safeAmounts.x, max(safeAmounts.y, safeAmounts.z)) <= 0.0001) {
|
||||
return color;
|
||||
}
|
||||
|
||||
vec3 nonNegativeColor = max(color, vec3(0.0));
|
||||
float luma = clamp(dot(nonNegativeColor, lumaWeights), 0.0, 1.0);
|
||||
float tonalCenter = clamp(0.5 - clamp(balance, -1.0, 1.0) * 0.22, 0.28, 0.72);
|
||||
float transition = mix(0.025, 0.18, clamp(blending, 0.0, 1.0));
|
||||
float shadowEdge = tonalCenter - 0.18;
|
||||
float highlightEdge = tonalCenter + 0.18;
|
||||
|
||||
float shadowWeight = 1.0 - smoothstep(
|
||||
shadowEdge - transition,
|
||||
shadowEdge + transition,
|
||||
luma
|
||||
);
|
||||
float highlightWeight = smoothstep(
|
||||
highlightEdge - transition,
|
||||
highlightEdge + transition,
|
||||
luma
|
||||
);
|
||||
float midtoneWeight = max(0.0, 1.0 - shadowWeight - highlightWeight);
|
||||
float weightSum = max(shadowWeight + midtoneWeight + highlightWeight, 0.0001);
|
||||
vec3 tonalWeights = vec3(
|
||||
shadowWeight,
|
||||
midtoneWeight,
|
||||
highlightWeight
|
||||
) / weightSum;
|
||||
|
||||
vec3 chromaShift =
|
||||
gradingChromaAxis(hues.x, lumaWeights) * safeAmounts.x * tonalWeights.x +
|
||||
gradingChromaAxis(hues.y, lumaWeights) * safeAmounts.y * tonalWeights.y +
|
||||
gradingChromaAxis(hues.z, lumaWeights) * safeAmounts.z * tonalWeights.z;
|
||||
|
||||
return color + luma * chromaShift * 0.62;
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
@@ -114,6 +114,10 @@ private class VideoLutShaderProgram(
|
||||
uniform float uNoiseSeed; // 噪点随机种子
|
||||
uniform float uLowRes; // 0.0 ~ 1.0
|
||||
uniform float uAspectRatio; // 图像长宽比
|
||||
uniform vec3 uGradingHues;
|
||||
uniform vec3 uGradingAmounts;
|
||||
uniform float uGradingBalance;
|
||||
uniform float uGradingBlending;
|
||||
|
||||
uniform vec3 uPrimaryCalibrationRow0;
|
||||
uniform vec3 uPrimaryCalibrationRow1;
|
||||
@@ -175,6 +179,7 @@ private class VideoLutShaderProgram(
|
||||
}
|
||||
|
||||
${DirectFlashShader.GLSL}
|
||||
${ThreeWayColorGradingShader.GLSL}
|
||||
|
||||
float sanitizeFloat(float value) {
|
||||
if (value != value) return 0.0;
|
||||
@@ -582,6 +587,18 @@ private class VideoLutShaderProgram(
|
||||
color.rgb = applyLchColorMixer(color.rgb);
|
||||
color.rgb = sanitizeColor(color.rgb);
|
||||
|
||||
color.rgb = applyThreeWayColorGrading(
|
||||
color.rgb,
|
||||
uGradingHues,
|
||||
uGradingAmounts,
|
||||
uGradingBalance,
|
||||
uGradingBlending,
|
||||
(uInputColorSpace == 1)
|
||||
? vec3(0.2290, 0.6917, 0.0793)
|
||||
: vec3(0.2126, 0.7152, 0.0722)
|
||||
);
|
||||
color.rgb = sanitizeColor(color.rgb);
|
||||
|
||||
if (uFade > 0.0) {
|
||||
float fadeAmount = uFade * 0.3;
|
||||
color.rgb = mix(color.rgb, vec3(0.5), fadeAmount);
|
||||
@@ -889,6 +906,26 @@ private class VideoLutShaderProgram(
|
||||
GLES30.glGetUniformLocation(programId, "uAspectRatio"),
|
||||
inputWidth.toFloat() / inputHeight.toFloat()
|
||||
)
|
||||
GLES30.glUniform3f(
|
||||
GLES30.glGetUniformLocation(programId, "uGradingHues"),
|
||||
currentRecipeParams.gradingShadowHue,
|
||||
currentRecipeParams.gradingMidtoneHue,
|
||||
currentRecipeParams.gradingHighlightHue
|
||||
)
|
||||
GLES30.glUniform3f(
|
||||
GLES30.glGetUniformLocation(programId, "uGradingAmounts"),
|
||||
currentRecipeParams.gradingShadowAmount,
|
||||
currentRecipeParams.gradingMidtoneAmount,
|
||||
currentRecipeParams.gradingHighlightAmount
|
||||
)
|
||||
GLES30.glUniform1f(
|
||||
GLES30.glGetUniformLocation(programId, "uGradingBalance"),
|
||||
currentRecipeParams.gradingBalance
|
||||
)
|
||||
GLES30.glUniform1f(
|
||||
GLES30.glGetUniformLocation(programId, "uGradingBlending"),
|
||||
currentRecipeParams.gradingBlending
|
||||
)
|
||||
|
||||
// LCH 配方数组
|
||||
val lchHue = floatArrayOf(
|
||||
|
||||
@@ -179,6 +179,14 @@ internal object CameraPresetJsonCodec {
|
||||
primaryBlueHue = obj.float("primaryBlueHue", default.primaryBlueHue),
|
||||
primaryBlueSaturation = obj.float("primaryBlueSaturation", default.primaryBlueSaturation),
|
||||
primaryBlueLightness = obj.float("primaryBlueLightness", default.primaryBlueLightness),
|
||||
gradingShadowHue = obj.float("gradingShadowHue", default.gradingShadowHue),
|
||||
gradingShadowAmount = obj.float("gradingShadowAmount", default.gradingShadowAmount),
|
||||
gradingMidtoneHue = obj.float("gradingMidtoneHue", default.gradingMidtoneHue),
|
||||
gradingMidtoneAmount = obj.float("gradingMidtoneAmount", default.gradingMidtoneAmount),
|
||||
gradingHighlightHue = obj.float("gradingHighlightHue", default.gradingHighlightHue),
|
||||
gradingHighlightAmount = obj.float("gradingHighlightAmount", default.gradingHighlightAmount),
|
||||
gradingBalance = obj.float("gradingBalance", default.gradingBalance),
|
||||
gradingBlending = obj.float("gradingBlending", default.gradingBlending),
|
||||
lutIntensity = obj.float("lutIntensity", default.lutIntensity),
|
||||
remarks = obj.stringOrNull("remarks") ?: default.remarks,
|
||||
masterCurvePoints = obj.floatArrayOrNull("masterCurvePoints") ?: default.masterCurvePoints,
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.hinnka.mycamera.model
|
||||
|
||||
import androidx.annotation.Keep
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonParser
|
||||
import com.hinnka.mycamera.R
|
||||
|
||||
/**
|
||||
@@ -73,6 +74,14 @@ data class ColorRecipeParams(
|
||||
val primaryBlueHue: Float = 0f,
|
||||
val primaryBlueSaturation: Float = 0f,
|
||||
val primaryBlueLightness: Float = 0f,
|
||||
val gradingShadowHue: Float = 0f, // 0.0 ~ 1.0
|
||||
val gradingShadowAmount: Float = 0f, // 0.0 ~ 1.0
|
||||
val gradingMidtoneHue: Float = 0f, // 0.0 ~ 1.0
|
||||
val gradingMidtoneAmount: Float = 0f, // 0.0 ~ 1.0
|
||||
val gradingHighlightHue: Float = 0f, // 0.0 ~ 1.0
|
||||
val gradingHighlightAmount: Float = 0f, // 0.0 ~ 1.0
|
||||
val gradingBalance: Float = 0f, // -1.0 ~ 1.0
|
||||
val gradingBlending: Float = 0.5f, // 0.0 ~ 1.0
|
||||
val lutIntensity: Float = 1f, // 0.0 ~ 1.0 (LUT强度,1为完全应用)
|
||||
val remarks: String? = "", // 用户备注
|
||||
// 曲线控制点 [x0,y0, x1,y1, ...], null = 恒等曲线(无效果)
|
||||
@@ -146,6 +155,14 @@ data class ColorRecipeParams(
|
||||
primaryBlueHue == 0f &&
|
||||
primaryBlueSaturation == 0f &&
|
||||
primaryBlueLightness == 0f &&
|
||||
gradingShadowHue == 0f &&
|
||||
gradingShadowAmount == 0f &&
|
||||
gradingMidtoneHue == 0f &&
|
||||
gradingMidtoneAmount == 0f &&
|
||||
gradingHighlightHue == 0f &&
|
||||
gradingHighlightAmount == 0f &&
|
||||
gradingBalance == 0f &&
|
||||
gradingBlending == 0.5f &&
|
||||
remarks.isNullOrEmpty() &&
|
||||
masterCurvePoints == null &&
|
||||
redCurvePoints == null &&
|
||||
@@ -218,6 +235,14 @@ data class ColorRecipeParams(
|
||||
primaryBlueHue == other.primaryBlueHue &&
|
||||
primaryBlueSaturation == other.primaryBlueSaturation &&
|
||||
primaryBlueLightness == other.primaryBlueLightness &&
|
||||
gradingShadowHue == other.gradingShadowHue &&
|
||||
gradingShadowAmount == other.gradingShadowAmount &&
|
||||
gradingMidtoneHue == other.gradingMidtoneHue &&
|
||||
gradingMidtoneAmount == other.gradingMidtoneAmount &&
|
||||
gradingHighlightHue == other.gradingHighlightHue &&
|
||||
gradingHighlightAmount == other.gradingHighlightAmount &&
|
||||
gradingBalance == other.gradingBalance &&
|
||||
gradingBlending == other.gradingBlending &&
|
||||
lutIntensity == other.lutIntensity &&
|
||||
remarks == other.remarks &&
|
||||
(masterCurvePoints === other.masterCurvePoints || masterCurvePoints?.contentEquals(other.masterCurvePoints) == true) &&
|
||||
@@ -238,7 +263,22 @@ data class ColorRecipeParams(
|
||||
* 从 JSON 字符串反序列化
|
||||
*/
|
||||
fun fromJson(json: String): ColorRecipeParams {
|
||||
return gson.fromJson(json, ColorRecipeParams::class.java)?.copy(halation = 0f) ?: return DEFAULT
|
||||
return try {
|
||||
val root = JsonParser.parseString(json)
|
||||
val parsed = gson.fromJson(root, ColorRecipeParams::class.java) ?: return DEFAULT
|
||||
parsed.copy(
|
||||
halation = 0f,
|
||||
gradingBlending = if (
|
||||
root.isJsonObject && root.asJsonObject.has("gradingBlending")
|
||||
) {
|
||||
parsed.gradingBlending
|
||||
} else {
|
||||
DEFAULT.gradingBlending
|
||||
}
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
DEFAULT
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,478 @@
|
||||
package com.hinnka.mycamera.ui.components
|
||||
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.gestures.detectDragGestures
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.geometry.Size
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import androidx.compose.ui.graphics.lerp
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.hinnka.mycamera.R
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import kotlin.math.PI
|
||||
import kotlin.math.atan2
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.math.sin
|
||||
import kotlin.math.sqrt
|
||||
|
||||
private enum class GradingRange {
|
||||
SHADOWS,
|
||||
MIDTONES,
|
||||
HIGHLIGHTS,
|
||||
}
|
||||
|
||||
private data class GradingSelection(
|
||||
val hue: Float,
|
||||
val amount: Float,
|
||||
)
|
||||
|
||||
private val GradingAccent = Color(0xFFB3E5FC)
|
||||
|
||||
@Composable
|
||||
fun ColorGradingPanel(
|
||||
currentParams: ColorRecipeParams,
|
||||
onParamsChange: (ColorRecipeParams) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
var selectedRange by remember { mutableStateOf(GradingRange.MIDTONES) }
|
||||
val rangeLabels = mapOf(
|
||||
GradingRange.SHADOWS to stringResource(R.string.recipe_param_shadows),
|
||||
GradingRange.MIDTONES to stringResource(R.string.recipe_grading_midtones),
|
||||
GradingRange.HIGHLIGHTS to stringResource(R.string.recipe_param_highlights),
|
||||
)
|
||||
val selected = currentParams.selectionFor(selectedRange)
|
||||
val selectedLabel = rangeLabels.getValue(selectedRange)
|
||||
val selectedColor = gradingColor(selected.hue, selected.amount)
|
||||
|
||||
Column(
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
verticalArrangement = Arrangement.spacedBy(7.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(Color.White.copy(alpha = 0.04f), RoundedCornerShape(8.dp))
|
||||
.padding(3.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
GradingRange.entries.forEach { range ->
|
||||
val selection = currentParams.selectionFor(range)
|
||||
val isSelected = range == selectedRange
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.clip(RoundedCornerShape(6.dp))
|
||||
.background(
|
||||
if (isSelected) Color.White.copy(alpha = 0.14f) else Color.Transparent
|
||||
)
|
||||
.clickable { selectedRange = range }
|
||||
.padding(vertical = 7.dp),
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(7.dp)
|
||||
.clip(CircleShape)
|
||||
.background(
|
||||
if (selection.amount > 0.001f) {
|
||||
gradingColor(selection.hue, selection.amount)
|
||||
} else {
|
||||
Color.White.copy(alpha = 0.22f)
|
||||
}
|
||||
)
|
||||
)
|
||||
Text(
|
||||
text = rangeLabels.getValue(range),
|
||||
color = if (isSelected) Color.White else Color.White.copy(alpha = 0.55f),
|
||||
fontSize = 10.sp,
|
||||
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal,
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.padding(start = 5.dp),
|
||||
maxLines = 1,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GradingColorWheel(
|
||||
hue = selected.hue,
|
||||
amount = selected.amount,
|
||||
contentDescription = selectedLabel,
|
||||
onSelectionChange = { hue, amount ->
|
||||
onParamsChange(currentParams.withSelection(selectedRange, hue, amount))
|
||||
},
|
||||
onReset = {
|
||||
onParamsChange(currentParams.withSelection(selectedRange, 0f, 0f))
|
||||
},
|
||||
modifier = Modifier.size(148.dp),
|
||||
)
|
||||
|
||||
Text(
|
||||
text = "${(selected.hue.coerceIn(0f, 1f) * 360f).roundToInt()}° · " +
|
||||
"${(selected.amount.coerceIn(0f, 1f) * 100f).roundToInt()}%",
|
||||
color = if (selected.amount > 0.001f) selectedColor else Color.White.copy(alpha = 0.48f),
|
||||
fontSize = 11.sp,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
fontFamily = FontFamily.Monospace,
|
||||
)
|
||||
|
||||
GradingTonePreview(
|
||||
params = currentParams,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(14.dp),
|
||||
)
|
||||
|
||||
GradingSliderRow(
|
||||
label = stringResource(R.string.recipe_grading_balance),
|
||||
value = currentParams.gradingBalance,
|
||||
valueRange = -1f..1f,
|
||||
defaultValue = 0f,
|
||||
valueText = formatSignedPercent(currentParams.gradingBalance),
|
||||
onValueChange = {
|
||||
onParamsChange(currentParams.copy(gradingBalance = it.coerceIn(-1f, 1f)))
|
||||
},
|
||||
)
|
||||
GradingSliderRow(
|
||||
label = stringResource(R.string.recipe_grading_blending),
|
||||
value = currentParams.gradingBlending,
|
||||
valueRange = 0f..1f,
|
||||
defaultValue = 0.5f,
|
||||
valueText = "${(currentParams.gradingBlending.coerceIn(0f, 1f) * 100f).roundToInt()}",
|
||||
onValueChange = {
|
||||
onParamsChange(currentParams.copy(gradingBlending = it.coerceIn(0f, 1f)))
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GradingColorWheel(
|
||||
hue: Float,
|
||||
amount: Float,
|
||||
contentDescription: String,
|
||||
onSelectionChange: (Float, Float) -> Unit,
|
||||
onReset: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val currentHue by rememberUpdatedState(hue.coerceIn(0f, 1f))
|
||||
val currentOnSelectionChange by rememberUpdatedState(onSelectionChange)
|
||||
val currentOnReset by rememberUpdatedState(onReset)
|
||||
|
||||
Canvas(
|
||||
modifier = modifier
|
||||
.semantics {
|
||||
this.contentDescription = contentDescription
|
||||
}
|
||||
.pointerInput(Unit) {
|
||||
fun update(position: Offset) {
|
||||
val center = Offset(size.width / 2f, size.height / 2f)
|
||||
val dx = position.x - center.x
|
||||
val dy = position.y - center.y
|
||||
val radius = (minOf(size.width, size.height) / 2f - 8.dp.toPx()).coerceAtLeast(1f)
|
||||
val nextAmount = (sqrt(dx * dx + dy * dy) / radius).coerceIn(0f, 1f)
|
||||
val rawAngle = atan2(dy, dx) + PI.toFloat() / 2f
|
||||
val normalizedHue = (
|
||||
rawAngle / (PI.toFloat() * 2f) + 1f
|
||||
) % 1f
|
||||
val nextHue = if (nextAmount < 0.02f) currentHue else normalizedHue
|
||||
currentOnSelectionChange(nextHue, nextAmount)
|
||||
}
|
||||
|
||||
detectTapGestures(
|
||||
onTap = ::update,
|
||||
onDoubleTap = { currentOnReset() },
|
||||
)
|
||||
}
|
||||
.pointerInput(Unit) {
|
||||
detectDragGestures { change, _ ->
|
||||
change.consume()
|
||||
val center = Offset(size.width / 2f, size.height / 2f)
|
||||
val dx = change.position.x - center.x
|
||||
val dy = change.position.y - center.y
|
||||
val radius = (minOf(size.width, size.height) / 2f - 8.dp.toPx()).coerceAtLeast(1f)
|
||||
val nextAmount = (sqrt(dx * dx + dy * dy) / radius).coerceIn(0f, 1f)
|
||||
val rawAngle = atan2(dy, dx) + PI.toFloat() / 2f
|
||||
val normalizedHue = (
|
||||
rawAngle / (PI.toFloat() * 2f) + 1f
|
||||
) % 1f
|
||||
currentOnSelectionChange(
|
||||
if (nextAmount < 0.02f) currentHue else normalizedHue,
|
||||
nextAmount,
|
||||
)
|
||||
}
|
||||
}
|
||||
) {
|
||||
val inset = 8.dp.toPx()
|
||||
val diameter = minOf(size.width, size.height) - inset * 2f
|
||||
val center = Offset(size.width / 2f, size.height / 2f)
|
||||
val radius = diameter / 2f
|
||||
val wheelTopLeft = Offset(center.x - radius, center.y - radius)
|
||||
val wheelSize = Size(diameter, diameter)
|
||||
|
||||
for (degree in 0 until 360 step 3) {
|
||||
drawArc(
|
||||
color = Color.hsv(degree.toFloat(), 0.78f, 1f),
|
||||
startAngle = degree.toFloat() - 90f,
|
||||
sweepAngle = 4f,
|
||||
useCenter = true,
|
||||
topLeft = wheelTopLeft,
|
||||
size = wheelSize,
|
||||
)
|
||||
}
|
||||
drawCircle(
|
||||
brush = Brush.radialGradient(
|
||||
colors = listOf(
|
||||
Color(0xFFE0E0E0),
|
||||
Color(0x00E0E0E0),
|
||||
),
|
||||
center = center,
|
||||
radius = radius,
|
||||
),
|
||||
radius = radius,
|
||||
center = center,
|
||||
)
|
||||
drawCircle(
|
||||
color = Color.Black.copy(alpha = 0.08f),
|
||||
radius = radius,
|
||||
center = center,
|
||||
)
|
||||
listOf(0.33f, 0.66f).forEach { fraction ->
|
||||
drawCircle(
|
||||
color = Color.White.copy(alpha = 0.18f),
|
||||
radius = radius * fraction,
|
||||
center = center,
|
||||
style = Stroke(width = 0.8.dp.toPx()),
|
||||
)
|
||||
}
|
||||
drawCircle(
|
||||
color = Color.White.copy(alpha = 0.40f),
|
||||
radius = radius,
|
||||
center = center,
|
||||
style = Stroke(width = 1.dp.toPx()),
|
||||
)
|
||||
|
||||
val markerAngle = hue.coerceIn(0f, 1f) * PI.toFloat() * 2f - PI.toFloat() / 2f
|
||||
val markerRadius = amount.coerceIn(0f, 1f) * radius
|
||||
val markerCenter = Offset(
|
||||
center.x + cos(markerAngle) * markerRadius,
|
||||
center.y + sin(markerAngle) * markerRadius,
|
||||
)
|
||||
drawCircle(
|
||||
color = Color.Black.copy(alpha = 0.38f),
|
||||
radius = 10.dp.toPx(),
|
||||
center = markerCenter,
|
||||
)
|
||||
drawCircle(
|
||||
color = Color.White,
|
||||
radius = 7.5.dp.toPx(),
|
||||
center = markerCenter,
|
||||
)
|
||||
drawCircle(
|
||||
color = gradingColor(hue, amount),
|
||||
radius = 5.5.dp.toPx(),
|
||||
center = markerCenter,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GradingTonePreview(
|
||||
params: ColorRecipeParams,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val shadow = previewToneColor(
|
||||
hue = params.gradingShadowHue,
|
||||
amount = params.gradingShadowAmount,
|
||||
neutral = 0.18f,
|
||||
)
|
||||
val midtone = previewToneColor(
|
||||
hue = params.gradingMidtoneHue,
|
||||
amount = params.gradingMidtoneAmount,
|
||||
neutral = 0.50f,
|
||||
)
|
||||
val highlight = previewToneColor(
|
||||
hue = params.gradingHighlightHue,
|
||||
amount = params.gradingHighlightAmount,
|
||||
neutral = 0.84f,
|
||||
)
|
||||
val center = (0.5f - params.gradingBalance.coerceIn(-1f, 1f) * 0.22f)
|
||||
.coerceIn(0.28f, 0.72f)
|
||||
val transition = 0.025f +
|
||||
(0.18f - 0.025f) * params.gradingBlending.coerceIn(0f, 1f)
|
||||
val shadowEdge = center - 0.18f
|
||||
val highlightEdge = center + 0.18f
|
||||
val shadowBlendStart = (shadowEdge - transition).coerceIn(0f, 1f)
|
||||
val shadowBlendEnd = (shadowEdge + transition).coerceIn(0f, 1f)
|
||||
val highlightBlendStart = (highlightEdge - transition).coerceIn(0f, 1f)
|
||||
val highlightBlendEnd = (highlightEdge + transition).coerceIn(0f, 1f)
|
||||
|
||||
Canvas(
|
||||
modifier = modifier.clip(RoundedCornerShape(7.dp))
|
||||
) {
|
||||
drawRoundRect(
|
||||
brush = Brush.horizontalGradient(
|
||||
colorStops = arrayOf(
|
||||
0f to shadow,
|
||||
shadowBlendStart to shadow,
|
||||
shadowBlendEnd to midtone,
|
||||
highlightBlendStart to midtone,
|
||||
highlightBlendEnd to highlight,
|
||||
1f to highlight,
|
||||
)
|
||||
),
|
||||
cornerRadius = androidx.compose.ui.geometry.CornerRadius(
|
||||
7.dp.toPx(),
|
||||
7.dp.toPx(),
|
||||
),
|
||||
)
|
||||
drawRoundRect(
|
||||
color = Color.White.copy(alpha = 0.16f),
|
||||
cornerRadius = androidx.compose.ui.geometry.CornerRadius(
|
||||
7.dp.toPx(),
|
||||
7.dp.toPx(),
|
||||
),
|
||||
style = Stroke(width = 1.dp.toPx()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GradingSliderRow(
|
||||
label: String,
|
||||
value: Float,
|
||||
valueRange: ClosedFloatingPointRange<Float>,
|
||||
defaultValue: Float,
|
||||
valueText: String,
|
||||
onValueChange: (Float) -> Unit,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(36.dp)
|
||||
.background(Color.White.copy(alpha = 0.02f), RoundedCornerShape(6.dp))
|
||||
.padding(horizontal = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(
|
||||
text = label,
|
||||
color = Color.White.copy(alpha = 0.66f),
|
||||
fontSize = 11.sp,
|
||||
modifier = Modifier.size(width = 58.dp, height = 20.dp),
|
||||
maxLines = 1,
|
||||
)
|
||||
CustomSlider(
|
||||
value = value,
|
||||
onValueChange = onValueChange,
|
||||
onDoubleTap = { onValueChange(defaultValue) },
|
||||
valueRange = valueRange,
|
||||
activeTrackColor = GradingAccent,
|
||||
inactiveTrackColor = Color.White.copy(alpha = 0.14f),
|
||||
thumbColor = Color.White,
|
||||
thumbRadius = 7.dp,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(horizontal = 8.dp),
|
||||
)
|
||||
Text(
|
||||
text = valueText,
|
||||
color = Color.White.copy(alpha = 0.72f),
|
||||
fontSize = 10.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
textAlign = TextAlign.End,
|
||||
fontFamily = FontFamily.Monospace,
|
||||
modifier = Modifier.size(width = 42.dp, height = 20.dp),
|
||||
maxLines = 1,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun ColorRecipeParams.selectionFor(range: GradingRange): GradingSelection {
|
||||
return when (range) {
|
||||
GradingRange.SHADOWS -> GradingSelection(gradingShadowHue, gradingShadowAmount)
|
||||
GradingRange.MIDTONES -> GradingSelection(gradingMidtoneHue, gradingMidtoneAmount)
|
||||
GradingRange.HIGHLIGHTS -> GradingSelection(gradingHighlightHue, gradingHighlightAmount)
|
||||
}
|
||||
}
|
||||
|
||||
private fun ColorRecipeParams.withSelection(
|
||||
range: GradingRange,
|
||||
hue: Float,
|
||||
amount: Float,
|
||||
): ColorRecipeParams {
|
||||
val safeHue = hue.coerceIn(0f, 1f)
|
||||
val safeAmount = amount.coerceIn(0f, 1f)
|
||||
return when (range) {
|
||||
GradingRange.SHADOWS -> copy(
|
||||
gradingShadowHue = safeHue,
|
||||
gradingShadowAmount = safeAmount,
|
||||
)
|
||||
GradingRange.MIDTONES -> copy(
|
||||
gradingMidtoneHue = safeHue,
|
||||
gradingMidtoneAmount = safeAmount,
|
||||
)
|
||||
GradingRange.HIGHLIGHTS -> copy(
|
||||
gradingHighlightHue = safeHue,
|
||||
gradingHighlightAmount = safeAmount,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun gradingColor(hue: Float, amount: Float): Color {
|
||||
return if (amount <= 0.001f) {
|
||||
Color.White
|
||||
} else {
|
||||
Color.hsv(
|
||||
hue = hue.coerceIn(0f, 1f) * 360f,
|
||||
saturation = (0.40f + amount.coerceIn(0f, 1f) * 0.45f),
|
||||
value = 1f,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun previewToneColor(hue: Float, amount: Float, neutral: Float): Color {
|
||||
val base = Color(neutral, neutral, neutral, 1f)
|
||||
val tint = Color.hsv(hue.coerceIn(0f, 1f) * 360f, 0.72f, 1f)
|
||||
return lerp(base, tint, amount.coerceIn(0f, 1f) * 0.55f)
|
||||
}
|
||||
|
||||
private fun formatSignedPercent(value: Float): String {
|
||||
val percent = (value.coerceIn(-1f, 1f) * 100f).roundToInt()
|
||||
return if (percent > 0) "+$percent" else percent.toString()
|
||||
}
|
||||
@@ -50,6 +50,7 @@ private enum class ColorPanelSection {
|
||||
BASIC,
|
||||
CALIBRATION,
|
||||
LCH,
|
||||
GRADING,
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -213,7 +214,7 @@ fun ColorRecipePanel(
|
||||
)
|
||||
RecipePanelTab.COLOR -> onParamsChange(
|
||||
resetParams(
|
||||
currentParams,
|
||||
currentParams.resetColorGrading(),
|
||||
parameterGroups[RecipePanelTab.COLOR].orEmpty() +
|
||||
calibrationGroups.flatMap { it.second } +
|
||||
lchGroups.flatMap { it.second }
|
||||
@@ -256,7 +257,7 @@ fun ColorRecipePanel(
|
||||
redCurvePoints = null,
|
||||
greenCurvePoints = null,
|
||||
blueCurvePoints = null
|
||||
),
|
||||
).resetColorGrading(),
|
||||
visibleParams
|
||||
)
|
||||
)
|
||||
@@ -471,6 +472,13 @@ fun ColorRecipePanel(
|
||||
)
|
||||
}
|
||||
}
|
||||
ColorPanelSection.GRADING -> {
|
||||
ColorGradingPanel(
|
||||
currentParams = currentParams,
|
||||
onParamsChange = onParamsChange,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
RecipePanelTab.EFFECTS -> {
|
||||
@@ -521,6 +529,7 @@ private fun ColorSectionTabs(
|
||||
ColorPanelSection.BASIC to R.string.recipe_color_basic,
|
||||
ColorPanelSection.CALIBRATION to R.string.recipe_tab_calibration,
|
||||
ColorPanelSection.LCH to R.string.recipe_tab_lch,
|
||||
ColorPanelSection.GRADING to R.string.recipe_color_grading,
|
||||
)
|
||||
Row(
|
||||
modifier = modifier
|
||||
@@ -534,7 +543,7 @@ private fun ColorSectionTabs(
|
||||
Text(
|
||||
text = stringResource(title),
|
||||
color = if (selected) Color.White else Color.White.copy(alpha = 0.5f),
|
||||
fontSize = 11.sp,
|
||||
fontSize = if (tabs.size > 3) 9.sp else 11.sp,
|
||||
fontWeight = if (selected) FontWeight.Bold else FontWeight.Normal,
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier
|
||||
@@ -548,6 +557,19 @@ private fun ColorSectionTabs(
|
||||
}
|
||||
}
|
||||
|
||||
private fun ColorRecipeParams.resetColorGrading(): ColorRecipeParams {
|
||||
return copy(
|
||||
gradingShadowHue = 0f,
|
||||
gradingShadowAmount = 0f,
|
||||
gradingMidtoneHue = 0f,
|
||||
gradingMidtoneAmount = 0f,
|
||||
gradingHighlightHue = 0f,
|
||||
gradingHighlightAmount = 0f,
|
||||
gradingBalance = 0f,
|
||||
gradingBlending = 0.5f,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun RecipeParamSlider(
|
||||
param: RecipeParam,
|
||||
|
||||
@@ -471,6 +471,10 @@
|
||||
<!-- Color Recipe Tabs -->
|
||||
<string name="recipe_tab_color">色彩</string>
|
||||
<string name="recipe_color_basic">基礎</string>
|
||||
<string name="recipe_color_grading">色彩分級</string>
|
||||
<string name="recipe_grading_midtones">中間調</string>
|
||||
<string name="recipe_grading_balance">平衡</string>
|
||||
<string name="recipe_grading_blending">過渡</string>
|
||||
<string name="recipe_tab_lch">LCH</string>
|
||||
<string name="recipe_tab_light">亮度</string>
|
||||
<string name="recipe_tab_curve">曲線</string>
|
||||
|
||||
@@ -174,6 +174,10 @@
|
||||
<string name="edit_color_and_effects">Farbe und Effekte anpassen</string>
|
||||
<string name="recipe_tab_color">Farbe</string>
|
||||
<string name="recipe_color_basic">Grundlagen</string>
|
||||
<string name="recipe_color_grading">Grading</string>
|
||||
<string name="recipe_grading_midtones">Mitteltöne</string>
|
||||
<string name="recipe_grading_balance">Balance</string>
|
||||
<string name="recipe_grading_blending">Übergang</string>
|
||||
<string name="recipe_tab_light">Licht</string>
|
||||
<string name="recipe_tab_texture">Textur</string>
|
||||
<string name="recipe_tab_post">Entwicklung</string>
|
||||
|
||||
@@ -174,6 +174,10 @@
|
||||
<string name="edit_color_and_effects">Régler la couleur et les effets</string>
|
||||
<string name="recipe_tab_color">Couleur</string>
|
||||
<string name="recipe_color_basic">Base</string>
|
||||
<string name="recipe_color_grading">Étalonnage</string>
|
||||
<string name="recipe_grading_midtones">Tons moyens</string>
|
||||
<string name="recipe_grading_balance">Balance</string>
|
||||
<string name="recipe_grading_blending">Transition</string>
|
||||
<string name="recipe_tab_light">Lumière</string>
|
||||
<string name="recipe_tab_texture">Texture</string>
|
||||
<string name="recipe_tab_post">Développement</string>
|
||||
|
||||
@@ -174,6 +174,10 @@
|
||||
<string name="edit_color_and_effects">Sesuaikan warna dan efek</string>
|
||||
<string name="recipe_tab_color">Warna</string>
|
||||
<string name="recipe_color_basic">Dasar</string>
|
||||
<string name="recipe_color_grading">Gradasi</string>
|
||||
<string name="recipe_grading_midtones">Nada Tengah</string>
|
||||
<string name="recipe_grading_balance">Keseimbangan</string>
|
||||
<string name="recipe_grading_blending">Transisi</string>
|
||||
<string name="recipe_tab_light">Cahaya</string>
|
||||
<string name="recipe_tab_texture">Tekstur</string>
|
||||
<string name="recipe_tab_post">Pasca</string>
|
||||
|
||||
@@ -174,6 +174,10 @@
|
||||
<string name="edit_color_and_effects">カラーとエフェクトを調整</string>
|
||||
<string name="recipe_tab_color">カラー</string>
|
||||
<string name="recipe_color_basic">基本</string>
|
||||
<string name="recipe_color_grading">グレーディング</string>
|
||||
<string name="recipe_grading_midtones">中間調</string>
|
||||
<string name="recipe_grading_balance">バランス</string>
|
||||
<string name="recipe_grading_blending">ブレンド</string>
|
||||
<string name="recipe_tab_light">ライト</string>
|
||||
<string name="recipe_tab_texture">テクスチャ</string>
|
||||
<string name="recipe_tab_post">現像</string>
|
||||
|
||||
@@ -175,6 +175,10 @@
|
||||
<string name="edit_color_and_effects">색상 및 효과 조정</string>
|
||||
<string name="recipe_tab_color">색상</string>
|
||||
<string name="recipe_color_basic">기본</string>
|
||||
<string name="recipe_color_grading">그레이딩</string>
|
||||
<string name="recipe_grading_midtones">중간톤</string>
|
||||
<string name="recipe_grading_balance">밸런스</string>
|
||||
<string name="recipe_grading_blending">블렌딩</string>
|
||||
<string name="recipe_tab_light">빛</string>
|
||||
<string name="recipe_tab_texture">질감</string>
|
||||
<string name="recipe_tab_post">후보정</string>
|
||||
|
||||
@@ -175,6 +175,10 @@
|
||||
<string name="edit_color_and_effects">Ajustar cor e efeitos</string>
|
||||
<string name="recipe_tab_color">Cor</string>
|
||||
<string name="recipe_color_basic">Básico</string>
|
||||
<string name="recipe_color_grading">Gradação</string>
|
||||
<string name="recipe_grading_midtones">Tons médios</string>
|
||||
<string name="recipe_grading_balance">Balanço</string>
|
||||
<string name="recipe_grading_blending">Transição</string>
|
||||
<string name="recipe_tab_light">Luz</string>
|
||||
<string name="recipe_tab_texture">Textura</string>
|
||||
<string name="recipe_tab_post">Pós</string>
|
||||
|
||||
@@ -355,6 +355,10 @@
|
||||
<string name="edit_color_and_effects">ปรับสีและเอฟเฟกต์</string>
|
||||
<string name="recipe_tab_color">สี</string>
|
||||
<string name="recipe_color_basic">พื้นฐาน</string>
|
||||
<string name="recipe_color_grading">เกรดสี</string>
|
||||
<string name="recipe_grading_midtones">โทนกลาง</string>
|
||||
<string name="recipe_grading_balance">สมดุล</string>
|
||||
<string name="recipe_grading_blending">การผสม</string>
|
||||
<string name="recipe_tab_lch">LCH</string>
|
||||
<string name="recipe_tab_light">แสง</string>
|
||||
<string name="recipe_tab_curve">เส้นโค้ง</string>
|
||||
|
||||
@@ -471,6 +471,10 @@
|
||||
<!-- Color Recipe Tabs -->
|
||||
<string name="recipe_tab_color">颜色</string>
|
||||
<string name="recipe_color_basic">基础</string>
|
||||
<string name="recipe_color_grading">色彩分级</string>
|
||||
<string name="recipe_grading_midtones">中间调</string>
|
||||
<string name="recipe_grading_balance">平衡</string>
|
||||
<string name="recipe_grading_blending">过渡</string>
|
||||
<string name="recipe_tab_lch">LCH</string>
|
||||
<string name="recipe_tab_light">亮度</string>
|
||||
<string name="recipe_tab_curve">曲线</string>
|
||||
|
||||
@@ -471,6 +471,10 @@
|
||||
<!-- Color Recipe Tabs -->
|
||||
<string name="recipe_tab_color">色彩</string>
|
||||
<string name="recipe_color_basic">基礎</string>
|
||||
<string name="recipe_color_grading">色彩分級</string>
|
||||
<string name="recipe_grading_midtones">中間調</string>
|
||||
<string name="recipe_grading_balance">平衡</string>
|
||||
<string name="recipe_grading_blending">過渡</string>
|
||||
<string name="recipe_tab_lch">LCH</string>
|
||||
<string name="recipe_tab_light">亮度</string>
|
||||
<string name="recipe_tab_curve">曲線</string>
|
||||
|
||||
@@ -471,6 +471,10 @@
|
||||
<!-- Color Recipe Tabs -->
|
||||
<string name="recipe_tab_color">色彩</string>
|
||||
<string name="recipe_color_basic">基礎</string>
|
||||
<string name="recipe_color_grading">色彩分級</string>
|
||||
<string name="recipe_grading_midtones">中間調</string>
|
||||
<string name="recipe_grading_balance">平衡</string>
|
||||
<string name="recipe_grading_blending">過渡</string>
|
||||
<string name="recipe_tab_lch">LCH</string>
|
||||
<string name="recipe_tab_light">亮度</string>
|
||||
<string name="recipe_tab_curve">曲線</string>
|
||||
|
||||
@@ -476,6 +476,10 @@
|
||||
<!-- Color Recipe Tabs -->
|
||||
<string name="recipe_tab_color">Color</string>
|
||||
<string name="recipe_color_basic">Basic</string>
|
||||
<string name="recipe_color_grading">Grading</string>
|
||||
<string name="recipe_grading_midtones">Midtones</string>
|
||||
<string name="recipe_grading_balance">Balance</string>
|
||||
<string name="recipe_grading_blending">Blending</string>
|
||||
<string name="recipe_tab_lch">LCH</string>
|
||||
<string name="recipe_tab_light">Light</string>
|
||||
<string name="recipe_tab_curve">Curve</string>
|
||||
|
||||
@@ -143,6 +143,14 @@ class CameraPresetJsonCodecTest {
|
||||
"colorRecipe": {
|
||||
"exposure": 0.25,
|
||||
"flash": 0.15,
|
||||
"gradingShadowHue": 0.08,
|
||||
"gradingShadowAmount": 0.22,
|
||||
"gradingMidtoneHue": 0.31,
|
||||
"gradingMidtoneAmount": 0.44,
|
||||
"gradingHighlightHue": 0.58,
|
||||
"gradingHighlightAmount": 0.66,
|
||||
"gradingBalance": -0.18,
|
||||
"gradingBlending": 0.72,
|
||||
"unknownColorField": 10
|
||||
},
|
||||
"effects": {
|
||||
@@ -169,6 +177,14 @@ class CameraPresetJsonCodecTest {
|
||||
assertEquals(0.5f, preset.colorRecipe.paletteX, 0.0001f)
|
||||
assertEquals(1f, preset.colorRecipe.lutIntensity, 0.0001f)
|
||||
assertEquals(0.15f, preset.colorRecipe.flash, 0.0001f)
|
||||
assertEquals(0.08f, preset.colorRecipe.gradingShadowHue, 0.0001f)
|
||||
assertEquals(0.22f, preset.colorRecipe.gradingShadowAmount, 0.0001f)
|
||||
assertEquals(0.31f, preset.colorRecipe.gradingMidtoneHue, 0.0001f)
|
||||
assertEquals(0.44f, preset.colorRecipe.gradingMidtoneAmount, 0.0001f)
|
||||
assertEquals(0.58f, preset.colorRecipe.gradingHighlightHue, 0.0001f)
|
||||
assertEquals(0.66f, preset.colorRecipe.gradingHighlightAmount, 0.0001f)
|
||||
assertEquals(-0.18f, preset.colorRecipe.gradingBalance, 0.0001f)
|
||||
assertEquals(0.72f, preset.colorRecipe.gradingBlending, 0.0001f)
|
||||
assertEquals(-0.2f, preset.effects.vignette, 0.0001f)
|
||||
assertEquals(0.65f, preset.effects.flash, 0.0001f)
|
||||
assertEquals(0f, preset.effects.hdf, 0.0001f)
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.hinnka.mycamera.model
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class ColorGradingParamsTest {
|
||||
@Test
|
||||
fun defaults_doNotEnableColorGrading() {
|
||||
assertTrue(ColorRecipeParams.DEFAULT.isDefault())
|
||||
assertEquals(0.5f, ColorRecipeParams.DEFAULT.gradingBlending, 0.0001f)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun gradingAdjustment_participatesInDefaultAndEqualityChecks() {
|
||||
val adjusted = ColorRecipeParams.DEFAULT.copy(
|
||||
gradingMidtoneHue = 0.36f,
|
||||
gradingMidtoneAmount = 0.42f,
|
||||
)
|
||||
|
||||
assertFalse(adjusted.isDefault())
|
||||
assertFalse(adjusted.isSameAs(ColorRecipeParams.DEFAULT))
|
||||
assertTrue(adjusted.isSameAs(adjusted.copy()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun jsonRoundTrip_preservesAllThreeTonalRanges() {
|
||||
val source = ColorRecipeParams.DEFAULT.copy(
|
||||
gradingShadowHue = 0.08f,
|
||||
gradingShadowAmount = 0.21f,
|
||||
gradingMidtoneHue = 0.37f,
|
||||
gradingMidtoneAmount = 0.43f,
|
||||
gradingHighlightHue = 0.64f,
|
||||
gradingHighlightAmount = 0.72f,
|
||||
gradingBalance = -0.16f,
|
||||
gradingBlending = 0.81f,
|
||||
)
|
||||
|
||||
val decoded = ColorRecipeParams.fromJson(source.toJson())
|
||||
|
||||
assertTrue(source.isSameAs(decoded))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun legacyJson_usesNeutralBlendingDefault() {
|
||||
val decoded = ColorRecipeParams.fromJson(
|
||||
"""
|
||||
{
|
||||
"gradingShadowHue": 0.12,
|
||||
"gradingShadowAmount": 0.25
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
assertEquals(0.12f, decoded.gradingShadowHue, 0.0001f)
|
||||
assertEquals(0.25f, decoded.gradingShadowAmount, 0.0001f)
|
||||
assertEquals(0.5f, decoded.gradingBlending, 0.0001f)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user