diff --git a/app/src/main/java/com/hinnka/mycamera/camera/Camera2Controller.kt b/app/src/main/java/com/hinnka/mycamera/camera/Camera2Controller.kt index 49a308c3..2f54f63f 100644 --- a/app/src/main/java/com/hinnka/mycamera/camera/Camera2Controller.kt +++ b/app/src/main/java/com/hinnka/mycamera/camera/Camera2Controller.kt @@ -1495,7 +1495,6 @@ class Camera2Controller(private val context: Context) { characteristics, state.aspectRatio, ) - CaptureMode.QUICK_SHOT -> refreshQuickShotCapabilities(characteristics) CaptureMode.VIDEO -> { availableTonemapModes = characteristics.get( CameraCharacteristics.TONEMAP_AVAILABLE_TONE_MAP_MODES diff --git a/app/src/main/java/com/hinnka/mycamera/data/UserPreferencesRepository.kt b/app/src/main/java/com/hinnka/mycamera/data/UserPreferencesRepository.kt index 2533f3a2..2536fd04 100644 --- a/app/src/main/java/com/hinnka/mycamera/data/UserPreferencesRepository.kt +++ b/app/src/main/java/com/hinnka/mycamera/data/UserPreferencesRepository.kt @@ -218,8 +218,6 @@ data class UserPreferences( val captureButtonImagePath: String? = null, val droMode: String = "OFF", // DRO 模式 val tonemapMode: String = "SYSTEM_DEFAULT", // 色调映射模式 - val naturalLightEnabled: Boolean = false, // 是否启用自然光影 - val naturalLightWarningShown: Boolean = false, // 是否已提示自然光影兼容性风险 val fixTonemapPreview: Boolean = false, // 修复部分设备自定义色调映射预览异常 val fixTonemapCapture: Boolean = false, // 修复部分设备自定义色调映射拍摄异常 val applyUltraHDR: Boolean = false, // 是否应用 Ultra HDR 策略 @@ -479,8 +477,6 @@ class UserPreferencesRepository(private val context: Context) { private val CAPTURE_BUTTON_IMAGE_PATH = stringPreferencesKey("capture_button_image_path") private val DRO_MODE = stringPreferencesKey("dro_mode") private val TONEMAP_MODE = stringPreferencesKey("tonemap_mode") - private val NATURAL_LIGHT_ENABLED = booleanPreferencesKey("natural_light_enabled") - private val NATURAL_LIGHT_WARNING_SHOWN = booleanPreferencesKey("natural_light_warning_shown") private val FIX_TONEMAP_PREVIEW = booleanPreferencesKey("fix_tonemap_preview") private val FIX_TONEMAP_CAPTURE = booleanPreferencesKey("fix_tonemap_capture") private val APPLY_ULTRA_HDR = booleanPreferencesKey("apply_ultra_hdr") @@ -765,8 +761,6 @@ class UserPreferencesRepository(private val context: Context) { ?.takeIf { it.isNotBlank() }, droMode = preferences[DRO_MODE] ?: if (preferences[RAW_DRO_ENABLED_KEY] == true) "DR100" else "OFF", tonemapMode = sanitizeTonemapMode(preferences[TONEMAP_MODE] ?: "SYSTEM_DEFAULT"), - naturalLightEnabled = preferences[NATURAL_LIGHT_ENABLED] ?: false, - naturalLightWarningShown = preferences[NATURAL_LIGHT_WARNING_SHOWN] ?: false, fixTonemapPreview = preferences[FIX_TONEMAP_PREVIEW] ?: false, fixTonemapCapture = preferences[FIX_TONEMAP_CAPTURE] ?: false, applyUltraHDR = preferences[APPLY_ULTRA_HDR] ?: false, @@ -1304,7 +1298,6 @@ class UserPreferencesRepository(private val context: Context) { return@edit } preferences[TONEMAP_MODE] = "SYSTEM_DEFAULT" - preferences[NATURAL_LIGHT_ENABLED] = false val exposureMode = RawAdaptiveExposureMode.fromPersistedValue( value = preferences[RAW_AUTO_EXPOSURE_MODE_KEY], usePhotonHdr = @@ -2077,21 +2070,6 @@ class UserPreferencesRepository(private val context: Context) { } } - /** - * 保存是否启用自然光影 - */ - suspend fun saveNaturalLightEnabled(enabled: Boolean) { - context.dataStore.edit { preferences -> - preferences[NATURAL_LIGHT_ENABLED] = enabled - } - } - - suspend fun saveNaturalLightWarningShown(shown: Boolean) { - context.dataStore.edit { preferences -> - preferences[NATURAL_LIGHT_WARNING_SHOWN] = shown - } - } - /** * 保存是否修复自定义色调映射预览异常 */ diff --git a/app/src/main/java/com/hinnka/mycamera/gallery/GalleryManager.kt b/app/src/main/java/com/hinnka/mycamera/gallery/GalleryManager.kt index 1b32c35b..3580f248 100644 --- a/app/src/main/java/com/hinnka/mycamera/gallery/GalleryManager.kt +++ b/app/src/main/java/com/hinnka/mycamera/gallery/GalleryManager.kt @@ -293,7 +293,7 @@ object GalleryManager { } val metadata = baseMetadata.copy( lutId = lutId, - tonemapMode = mgcTonemapMode(preferences?.naturalLightEnabled, preferences?.tonemapMode), + tonemapMode = mgcTonemapMode(preferences?.tonemapMode), colorRecipeParams = lutId?.let { repository.lutManager.loadColorRecipeParams(it) }, baselineTarget = baselineLutId?.let { BaselineColorCorrectionTarget.RAW }, baselineLutId = baselineLutId, @@ -370,8 +370,7 @@ object GalleryManager { } } - private fun mgcTonemapMode(naturalLightEnabled: Boolean?, tonemapMode: String?): String { - if (naturalLightEnabled == true) return TONEMAP_MODE_NATURAL_LIGHT + private fun mgcTonemapMode(tonemapMode: String?): String { return when (tonemapMode) { "FAST", "HIGH_QUALITY", null -> "SYSTEM_DEFAULT" "REC709" -> "SRGB" @@ -2047,14 +2046,6 @@ object GalleryManager { previewBitmap = mirroredPreview } - if (metadata.usesNaturalLightToneMap()) { - val sourcePreview = checkNotNull(previewBitmap) - val toneMappedPreview = photoProcessor.processCapturePreviewToneMap(sourcePreview, metadata) - if (toneMappedPreview !== sourcePreview && !sourcePreview.isRecycled) { - sourcePreview.recycle() - } - previewBitmap = toneMappedPreview - } val originalFile = writeInternalOriginalPhoto(photoDir, checkNotNull(previewBitmap), photoQuality) ?: return@withContext PLog.d(TAG, "saveYuvPhoto internal original saved=${originalFile.name}") @@ -3129,17 +3120,11 @@ object GalleryManager { result = BitmapUtils.flipHorizontal(result) } - var previewBitmap = result - if (metadata.usesNaturalLightToneMap()) { - previewBitmap = photoProcessor.processCapturePreviewToneMap(result, metadata) - } + val previewBitmap = result val originalFile = writeInternalOriginalPhoto(photoDir, previewBitmap, photoQuality) ?: return@withContext PLog.d(TAG, "saveYuvStackedPhoto internal original saved=${originalFile.name}") generateBokehPhoto(context, photoId, metadata, previewBitmap) - if (previewBitmap !== result && !previewBitmap.isRecycled) { - previewBitmap.recycle() - } // Auto Save if (shouldAutoSave) { val metadata = loadMetadata(context, photoId) ?: return@withContext diff --git a/app/src/main/java/com/hinnka/mycamera/gallery/MediaMetadata.kt b/app/src/main/java/com/hinnka/mycamera/gallery/MediaMetadata.kt index c7dee956..5f94e462 100644 --- a/app/src/main/java/com/hinnka/mycamera/gallery/MediaMetadata.kt +++ b/app/src/main/java/com/hinnka/mycamera/gallery/MediaMetadata.kt @@ -25,8 +25,6 @@ import java.text.SimpleDateFormat import java.util.* import kotlin.math.log2 -const val TONEMAP_MODE_NATURAL_LIGHT = "NATURAL_LIGHT" - private fun JSONObject.optCompatibleRawAutoExposure(): Boolean? { if (!isNull("rawAutoExposureMode")) { when (optString("rawAutoExposureMode")) { @@ -218,14 +216,6 @@ data class MediaMetadata( val resolution: String get() = "${width}x${height}" - fun usesNaturalLightToneMap(): Boolean { - return tonemapMode == TONEMAP_MODE_NATURAL_LIGHT - } - - fun shouldApplyNaturalLightDefaultChromaDenoise(): Boolean { - return usesNaturalLightToneMap() && captureNoiseReductionLevel in LOW_HARDWARE_NOISE_REDUCTION_LEVELS - } - /** * 从 RawMetadata 补齐信息 */ @@ -274,8 +264,6 @@ data class MediaMetadata( companion object { private const val TAG = "PhotoMetadata" private const val RAW_ISO_FALLBACK_VALUE = 100 - private val LOW_HARDWARE_NOISE_REDUCTION_LEVELS = setOf(0, 4) - // 旧格式,以后不再更新 fun fromLegacyJson(json: String): MediaMetadata? { return try { diff --git a/app/src/main/java/com/hinnka/mycamera/gallery/PhotoProcessor.kt b/app/src/main/java/com/hinnka/mycamera/gallery/PhotoProcessor.kt index a0b00fde..565f57c4 100644 --- a/app/src/main/java/com/hinnka/mycamera/gallery/PhotoProcessor.kt +++ b/app/src/main/java/com/hinnka/mycamera/gallery/PhotoProcessor.kt @@ -742,26 +742,6 @@ class PhotoProcessor( result } - suspend fun processCapturePreviewToneMap( - input: Bitmap, - metadata: MediaMetadata, - ): Bitmap = withContext(Dispatchers.IO) { - if (!metadata.usesNaturalLightToneMap()) return@withContext input - if (shouldDecodeHlgInput(metadata)) return@withContext input - lutImageProcessor.applyLut( - bitmap = input, - isHlgInput = false, - lutConfig = null, - colorRecipeParams = null, - linearInputToneMap = true, - naturalLightInputSrgb = true, - linearInputExposureEv = metadata.rawExposureCompensation ?: 0f, - rawRenderingEngine = metadata.rawRenderingEngine, - rawHncsFilmCurveMode = metadata.rawHncsFilmCurveMode, - rawToneMappingParameters = metadata.rawToneMappingParameters - ) - } - /** * @param input 输入 Bitmap * @param metadata 照片元数据(包含编辑配置和拍摄信息) diff --git a/app/src/main/java/com/hinnka/mycamera/lut/LutImageProcessor.kt b/app/src/main/java/com/hinnka/mycamera/lut/LutImageProcessor.kt index 7b37c385..24ab36f3 100644 --- a/app/src/main/java/com/hinnka/mycamera/lut/LutImageProcessor.kt +++ b/app/src/main/java/com/hinnka/mycamera/lut/LutImageProcessor.kt @@ -18,17 +18,7 @@ import com.hinnka.mycamera.processor.GlesComputeWorkGroup import com.hinnka.mycamera.processor.DenoiseStrength import com.hinnka.mycamera.raw.DenoiseProfileNlmConfig import com.hinnka.mycamera.raw.DenoiseProfileShaders -import com.hinnka.mycamera.raw.HncsFilmCurveMode -import com.hinnka.mycamera.raw.HncsNaturalLightGl -import com.hinnka.mycamera.raw.HncsNaturalLightOutputPassShaders -import com.hinnka.mycamera.raw.RawProfileExposureGl -import com.hinnka.mycamera.raw.RawRenderingEngine -import com.hinnka.mycamera.raw.RawEngineTonePass -import com.hinnka.mycamera.raw.RawFullscreenQuad import com.hinnka.mycamera.raw.RawSharpenPass -import com.hinnka.mycamera.raw.RawSrgbPass -import com.hinnka.mycamera.raw.RawToneMappingGl -import com.hinnka.mycamera.raw.RawToneMappingParameters import com.hinnka.mycamera.utils.LargeDirectBuffer import com.hinnka.mycamera.utils.PLog import kotlinx.coroutines.asCoroutineDispatcher @@ -90,21 +80,6 @@ class LutImageProcessor(context: Context? = null) { private var pboId = 0 private var readbackBuffer: ByteBuffer? = null private var readbackBufferSize = 0 - private val naturalLightPrograms = IntArray(RawRenderingEngine.entries.size) - private var naturalLightTextureId = 0 - private var naturalLightFboId = 0 - private var naturalLightWidth = 0 - private var naturalLightHeight = 0 - private var naturalLightCurveTextureId = 0 - private var naturalLightCurveSize = 0 - private var naturalLightDummy3DTextureId = 0 - private var naturalLightSrgbOutputProgram = 0 - private var naturalLightHncsOutputProgram = 0 - private var naturalLightOutputTextureId = 0 - private var naturalLightOutputFboId = 0 - private var naturalLightOutputWidth = 0 - private var naturalLightOutputHeight = 0 - private val naturalLightHncsGl = context?.let(::HncsNaturalLightGl) private var vertexBuffer: FloatBuffer? = null private var texCoordBuffer: FloatBuffer? = null @@ -117,7 +92,6 @@ class LutImageProcessor(context: Context? = null) { private var bitmapDenoisePassthroughProgram = 0 private var computeCapabilitiesChecked = false private var computeCapabilitiesSupported = false - private var naturalLightSrgbToLinearProgram = 0 private var bitmapChromaDenoiseGuideProgram = 0 private var bitmapChromaDenoiseProgram = 0 private var lutSharpenProgram = 0 @@ -379,12 +353,6 @@ class LutImageProcessor(context: Context? = null) { noiseReductionValue: Float = 0f, chromaNoiseReductionValue: Float = 0f, lutMaskType: Int = 0, - linearInputToneMap: Boolean = false, - linearInputExposureEv: Float = 0f, - naturalLightDefaultChromaDenoise: Boolean = false, - rawRenderingEngine: RawRenderingEngine = RawRenderingEngine.AdobeCurve, - rawHncsFilmCurveMode: HncsFilmCurveMode = HncsFilmCurveMode.Standard, - rawToneMappingParameters: RawToneMappingParameters = RawToneMappingParameters.DEFAULT, ): Bitmap = withContext(glDispatcher) { currentCoroutineContext().ensureActive() if (!isInitialized) { @@ -404,11 +372,7 @@ class LutImageProcessor(context: Context? = null) { val sharpening: Float = sharpeningValue val noiseReduction: Float = noiseReductionValue val chromaNoiseReduction: Float = chromaNoiseReductionValue - val applyNaturalLightToneMap = linearInputToneMap && !isHlgInput - val preToneMapChromaDenoise = resolvePreToneMapChromaDenoise( - userStrength = chromaNoiseReduction, - applyNaturalLightDefault = applyNaturalLightToneMap && naturalLightDefaultChromaDenoise - ) + val chromaDenoiseStrength = DenoiseStrength.clamp(chromaNoiseReduction) // 激活上下文 EGL14.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext) @@ -421,12 +385,12 @@ class LutImageProcessor(context: Context? = null) { uploadImageTextureFromArgb(argbData, width, height) currentCoroutineContext().ensureActive() - if (preToneMapChromaDenoise > 0) { - renderBitmapChromaDenoise(imageTextureId, width, height, preToneMapChromaDenoise) + if (chromaDenoiseStrength > 0) { + renderBitmapChromaDenoise(imageTextureId, width, height, chromaDenoiseStrength) currentCoroutineContext().ensureActive() } - val chromaDenoisedTexId = if (preToneMapChromaDenoise > 0) bitmapDenoiseTexId[0] else imageTextureId + val chromaDenoisedTexId = if (chromaDenoiseStrength > 0) bitmapDenoiseTexId[0] else imageTextureId if (noiseReduction > 0) { renderBitmapDenoiseProfile(chromaDenoisedTexId, width, height, noiseReduction) currentCoroutineContext().ensureActive() @@ -443,45 +407,25 @@ class LutImageProcessor(context: Context? = null) { chromaDenoisedTexId } - val renderInputTexId = if (applyNaturalLightToneMap) { - renderNaturalLightToneMap( - inputTexId, - width, - height, - rawRenderingEngine, - rawHncsFilmCurveMode, - rawToneMappingParameters, - linearInputExposureEv - ) - } else { - inputTexId - } - val naturalLightApplied = applyNaturalLightToneMap && renderInputTexId != inputTexId - val renderColorSpace = if (naturalLightApplied) { - ColorSpace.get(ColorSpace.Named.SRGB) - } else { - colorSpace - } - // HDF 光晕效果预处理(在主 shader 之前,需要模糊的光晕纹理) if (halation > 0f) { - renderHDFBlur(renderInputTexId, width, height, halation) + renderHDFBlur(inputTexId, width, height, halation) currentCoroutineContext().ensureActive() } if (softLight > 0f) { - renderSoftLightBlur(renderInputTexId, width, height) + renderSoftLightBlur(inputTexId, width, height) currentCoroutineContext().ensureActive() } if (redHalation > 0f) { - renderHalationBlur(renderInputTexId, width, height, redHalation) + renderHalationBlur(inputTexId, width, height, redHalation) currentCoroutineContext().ensureActive() } // 执行渲染 val outputBitmap = performRender( width, height, - renderInputTexId, - renderColorSpace, + inputTexId, + colorSpace, isHlgInput, lutConfig, effectiveRecipeParams, @@ -503,18 +447,11 @@ class LutImageProcessor(context: Context? = null) { sharpeningValue: Float = 0f, noiseReductionValue: Float = 0f, chromaNoiseReductionValue: Float = 0f, - linearInputToneMap: Boolean = false, - linearInputExposureEv: Float = 0f, - naturalLightDefaultChromaDenoise: Boolean = false, - rawRenderingEngine: RawRenderingEngine = RawRenderingEngine.AdobeCurve, - rawHncsFilmCurveMode: HncsFilmCurveMode = HncsFilmCurveMode.Standard, - rawToneMappingParameters: RawToneMappingParameters = RawToneMappingParameters.DEFAULT, ): Bitmap { val hasBaseline = baselineLayer?.lutConfig != null || baselineLayer?.colorRecipeParams != null val hasCreative = creativeLayer?.lutConfig != null || creativeLayer?.colorRecipeParams != null return when { hasBaseline && hasCreative -> { - val runDenoiseBeforeNaturalLight = linearInputToneMap && !isHlgInput val baseBitmap = applyLut( argbData = argbData, width = width, @@ -523,22 +460,16 @@ class LutImageProcessor(context: Context? = null) { isHlgInput = isHlgInput, lutConfig = baselineLayer.lutConfig, colorRecipeParams = baselineLayer.colorRecipeParams, - noiseReductionValue = if (runDenoiseBeforeNaturalLight) noiseReductionValue else 0f, - chromaNoiseReductionValue = if (runDenoiseBeforeNaturalLight) chromaNoiseReductionValue else 0f, - linearInputToneMap = linearInputToneMap, - linearInputExposureEv = linearInputExposureEv, - naturalLightDefaultChromaDenoise = naturalLightDefaultChromaDenoise, - rawRenderingEngine = rawRenderingEngine, - rawHncsFilmCurveMode = rawHncsFilmCurveMode, - rawToneMappingParameters = rawToneMappingParameters, + noiseReductionValue = 0f, + chromaNoiseReductionValue = 0f, ) applyLut( bitmap = baseBitmap, lutConfig = creativeLayer.lutConfig, colorRecipeParams = creativeLayer.colorRecipeParams, sharpeningValue = sharpeningValue, - noiseReductionValue = if (runDenoiseBeforeNaturalLight) 0f else noiseReductionValue, - chromaNoiseReductionValue = if (runDenoiseBeforeNaturalLight) 0f else chromaNoiseReductionValue + noiseReductionValue = noiseReductionValue, + chromaNoiseReductionValue = chromaNoiseReductionValue ) } hasBaseline -> applyLut( @@ -551,13 +482,7 @@ class LutImageProcessor(context: Context? = null) { colorRecipeParams = baselineLayer.colorRecipeParams, sharpeningValue = sharpeningValue, noiseReductionValue = noiseReductionValue, - chromaNoiseReductionValue = chromaNoiseReductionValue, - linearInputToneMap = linearInputToneMap, - linearInputExposureEv = linearInputExposureEv, - naturalLightDefaultChromaDenoise = naturalLightDefaultChromaDenoise, - rawRenderingEngine = rawRenderingEngine, - rawHncsFilmCurveMode = rawHncsFilmCurveMode, - rawToneMappingParameters = rawToneMappingParameters + chromaNoiseReductionValue = chromaNoiseReductionValue ) else -> applyLut( argbData = argbData, @@ -569,13 +494,7 @@ class LutImageProcessor(context: Context? = null) { colorRecipeParams = creativeLayer?.colorRecipeParams, sharpeningValue = sharpeningValue, noiseReductionValue = noiseReductionValue, - chromaNoiseReductionValue = chromaNoiseReductionValue, - linearInputToneMap = linearInputToneMap, - linearInputExposureEv = linearInputExposureEv, - naturalLightDefaultChromaDenoise = naturalLightDefaultChromaDenoise, - rawRenderingEngine = rawRenderingEngine, - rawHncsFilmCurveMode = rawHncsFilmCurveMode, - rawToneMappingParameters = rawToneMappingParameters + chromaNoiseReductionValue = chromaNoiseReductionValue ) } } @@ -599,13 +518,6 @@ class LutImageProcessor(context: Context? = null) { noiseReductionValue: Float = 0f, chromaNoiseReductionValue: Float = 0f, lutMaskType: Int = 0, - linearInputToneMap: Boolean = false, - naturalLightInputSrgb: Boolean = false, - linearInputExposureEv: Float = 0f, - naturalLightDefaultChromaDenoise: Boolean = false, - rawRenderingEngine: RawRenderingEngine = RawRenderingEngine.AdobeCurve, - rawHncsFilmCurveMode: HncsFilmCurveMode = HncsFilmCurveMode.Standard, - rawToneMappingParameters: RawToneMappingParameters = RawToneMappingParameters.DEFAULT, ): Bitmap = withContext(glDispatcher) { currentCoroutineContext().ensureActive() if (!isInitialized) { @@ -624,11 +536,7 @@ class LutImageProcessor(context: Context? = null) { val sharpening: Float = sharpeningValue val noiseReduction: Float = noiseReductionValue val chromaNoiseReduction: Float = chromaNoiseReductionValue - val applyNaturalLightToneMap = linearInputToneMap && !isHlgInput - val preToneMapChromaDenoise = resolvePreToneMapChromaDenoise( - userStrength = chromaNoiseReduction, - applyNaturalLightDefault = applyNaturalLightToneMap && naturalLightDefaultChromaDenoise - ) + val chromaDenoiseStrength = DenoiseStrength.clamp(chromaNoiseReduction) // 确保上下文激活 EGL14.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext) @@ -644,12 +552,12 @@ class LutImageProcessor(context: Context? = null) { uploadImageTexture(bitmap) currentCoroutineContext().ensureActive() - if (preToneMapChromaDenoise > 0) { - renderBitmapChromaDenoise(imageTextureId, width, height, preToneMapChromaDenoise) + if (chromaDenoiseStrength > 0) { + renderBitmapChromaDenoise(imageTextureId, width, height, chromaDenoiseStrength) currentCoroutineContext().ensureActive() } - val chromaDenoisedTexId = if (preToneMapChromaDenoise > 0) bitmapDenoiseTexId[0] else imageTextureId + val chromaDenoisedTexId = if (chromaDenoiseStrength > 0) bitmapDenoiseTexId[0] else imageTextureId if (noiseReduction > 0) { renderBitmapDenoiseProfile(chromaDenoisedTexId, width, height, noiseReduction) currentCoroutineContext().ensureActive() @@ -665,49 +573,26 @@ class LutImageProcessor(context: Context? = null) { } else { chromaDenoisedTexId } - val naturalLightSourceTexId = if (applyNaturalLightToneMap && naturalLightInputSrgb) { - renderSrgbInputToLinear(inputTexId, width, height) - } else { - inputTexId - } - val renderInputTexId = if (applyNaturalLightToneMap) { - renderNaturalLightToneMap( - naturalLightSourceTexId, - width, - height, - rawRenderingEngine, - rawHncsFilmCurveMode, - rawToneMappingParameters, - linearInputExposureEv - ) - } else { - inputTexId - } - val naturalLightApplied = applyNaturalLightToneMap && renderInputTexId != inputTexId - val renderColorSpace = if (naturalLightApplied) { - ColorSpace.get(ColorSpace.Named.SRGB) - } else { - bitmap.colorSpace ?: ColorSpace.get(ColorSpace.Named.SRGB) - } + val renderColorSpace = bitmap.colorSpace ?: ColorSpace.get(ColorSpace.Named.SRGB) // HDF 光晕效果预处理 if (halation > 0f) { - renderHDFBlur(renderInputTexId, width, height, halation) + renderHDFBlur(inputTexId, width, height, halation) currentCoroutineContext().ensureActive() } if (softLight > 0f) { - renderSoftLightBlur(renderInputTexId, width, height) + renderSoftLightBlur(inputTexId, width, height) currentCoroutineContext().ensureActive() } if (redHalation > 0f) { - renderHalationBlur(renderInputTexId, width, height, redHalation) + renderHalationBlur(inputTexId, width, height, redHalation) currentCoroutineContext().ensureActive() } // 执行渲染 val outputBitmap = performRender( width, height, - renderInputTexId, + inputTexId, renderColorSpace, isHlgInput, lutConfig, @@ -727,39 +612,26 @@ class LutImageProcessor(context: Context? = null) { sharpeningValue: Float = 0f, noiseReductionValue: Float = 0f, chromaNoiseReductionValue: Float = 0f, - linearInputToneMap: Boolean = false, - linearInputExposureEv: Float = 0f, - naturalLightDefaultChromaDenoise: Boolean = false, - rawRenderingEngine: RawRenderingEngine = RawRenderingEngine.AdobeCurve, - rawHncsFilmCurveMode: HncsFilmCurveMode = HncsFilmCurveMode.Standard, - rawToneMappingParameters: RawToneMappingParameters = RawToneMappingParameters.DEFAULT, ): Bitmap { val hasBaseline = baselineLayer?.lutConfig != null || baselineLayer?.colorRecipeParams != null val hasCreative = creativeLayer?.lutConfig != null || creativeLayer?.colorRecipeParams != null return when { hasBaseline && hasCreative -> { - val runDenoiseBeforeNaturalLight = linearInputToneMap && !isHlgInput val baseBitmap = applyLut( bitmap = bitmap, isHlgInput = isHlgInput, lutConfig = baselineLayer.lutConfig, colorRecipeParams = baselineLayer.colorRecipeParams, - noiseReductionValue = if (runDenoiseBeforeNaturalLight) noiseReductionValue else 0f, - chromaNoiseReductionValue = if (runDenoiseBeforeNaturalLight) chromaNoiseReductionValue else 0f, - linearInputToneMap = linearInputToneMap, - linearInputExposureEv = linearInputExposureEv, - naturalLightDefaultChromaDenoise = naturalLightDefaultChromaDenoise, - rawRenderingEngine = rawRenderingEngine, - rawHncsFilmCurveMode = rawHncsFilmCurveMode, - rawToneMappingParameters = rawToneMappingParameters, + noiseReductionValue = 0f, + chromaNoiseReductionValue = 0f, ) applyLut( bitmap = baseBitmap, lutConfig = creativeLayer.lutConfig, colorRecipeParams = creativeLayer.colorRecipeParams, sharpeningValue = sharpeningValue, - noiseReductionValue = if (runDenoiseBeforeNaturalLight) 0f else noiseReductionValue, - chromaNoiseReductionValue = if (runDenoiseBeforeNaturalLight) 0f else chromaNoiseReductionValue + noiseReductionValue = noiseReductionValue, + chromaNoiseReductionValue = chromaNoiseReductionValue ) } hasBaseline -> applyLut( @@ -769,13 +641,7 @@ class LutImageProcessor(context: Context? = null) { colorRecipeParams = baselineLayer.colorRecipeParams, sharpeningValue = sharpeningValue, noiseReductionValue = noiseReductionValue, - chromaNoiseReductionValue = chromaNoiseReductionValue, - linearInputToneMap = linearInputToneMap, - linearInputExposureEv = linearInputExposureEv, - naturalLightDefaultChromaDenoise = naturalLightDefaultChromaDenoise, - rawRenderingEngine = rawRenderingEngine, - rawHncsFilmCurveMode = rawHncsFilmCurveMode, - rawToneMappingParameters = rawToneMappingParameters + chromaNoiseReductionValue = chromaNoiseReductionValue ) else -> applyLut( bitmap = bitmap, @@ -784,13 +650,7 @@ class LutImageProcessor(context: Context? = null) { colorRecipeParams = creativeLayer?.colorRecipeParams, sharpeningValue = sharpeningValue, noiseReductionValue = noiseReductionValue, - chromaNoiseReductionValue = chromaNoiseReductionValue, - linearInputToneMap = linearInputToneMap, - linearInputExposureEv = linearInputExposureEv, - naturalLightDefaultChromaDenoise = naturalLightDefaultChromaDenoise, - rawRenderingEngine = rawRenderingEngine, - rawHncsFilmCurveMode = rawHncsFilmCurveMode, - rawToneMappingParameters = rawToneMappingParameters + chromaNoiseReductionValue = chromaNoiseReductionValue ) } } @@ -808,12 +668,6 @@ class LutImageProcessor(context: Context? = null) { sharpeningValue: Float = 0f, noiseReductionValue: Float = 0f, chromaNoiseReductionValue: Float = 0f, - linearInputToneMap: Boolean = false, - linearInputExposureEv: Float = 0f, - naturalLightDefaultChromaDenoise: Boolean = false, - rawRenderingEngine: RawRenderingEngine = RawRenderingEngine.AdobeCurve, - rawHncsFilmCurveMode: HncsFilmCurveMode = HncsFilmCurveMode.Standard, - rawToneMappingParameters: RawToneMappingParameters = RawToneMappingParameters.DEFAULT, luminanceGainDownsample: Int = 1, ): LutStackRenderResult { val rendered = applyLutStack( @@ -824,12 +678,6 @@ class LutImageProcessor(context: Context? = null) { sharpeningValue = sharpeningValue, noiseReductionValue = noiseReductionValue, chromaNoiseReductionValue = chromaNoiseReductionValue, - linearInputToneMap = linearInputToneMap, - linearInputExposureEv = linearInputExposureEv, - naturalLightDefaultChromaDenoise = naturalLightDefaultChromaDenoise, - rawRenderingEngine = rawRenderingEngine, - rawHncsFilmCurveMode = rawHncsFilmCurveMode, - rawToneMappingParameters = rawToneMappingParameters, ) val luminanceGainMap = if (isHlgInput || !bitmap.colorSpace.isEncodedSrgbFamily() || !rendered.colorSpace.isEncodedSrgbFamily() @@ -1353,491 +1201,6 @@ class LutImageProcessor(context: Context? = null) { releaseLutSharpenFramebuffer() } - private fun renderNaturalLightToneMap( - inputTextureId: Int, - width: Int, - height: Int, - engine: RawRenderingEngine, - hncsFilmCurveMode: HncsFilmCurveMode, - toneMappingParameters: RawToneMappingParameters, - exposureCompensationEv: Float - ): Int { - val effectiveEngine = if (engine.isHncs) RawRenderingEngine.HncsCcm else engine - val program = getOrCreateNaturalLightProgram(effectiveEngine) - if (program == 0) return inputTextureId - setupNaturalLightFramebuffer(width, height) - if (naturalLightFboId == 0 || naturalLightTextureId == 0) return inputTextureId - - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, naturalLightFboId) - GLES30.glViewport(0, 0, width, height) - GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT) - GLES30.glUseProgram(program) - - GLES30.glActiveTexture(GLES30.GL_TEXTURE0) - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, inputTextureId) - setUniform1i(program, "uInputTexture", 0) - RawToneMappingGl.bindRawToneMappingUniforms(program, toneMappingParameters) - bindNaturalLightProfileExposureUniforms(program, effectiveEngine, exposureCompensationEv) - setUniform1f(program, "uBlacks", 0f) - setUniform1f(program, "uWhites", 0f) - bindNaturalLightColorTransforms(program, effectiveEngine) - if (effectiveEngine == RawRenderingEngine.AdobeCurve) { - bindNaturalLightDisabledDcpUniforms(program) - bindNaturalLightAdobeCurve(program, toneMappingParameters) - } - if (effectiveEngine == RawRenderingEngine.Spektrafilm) { - bindNaturalLightDummySpectralFilmUniforms(program) - } - if (effectiveEngine.isHncs) { - checkNotNull(naturalLightHncsGl) { - "HNCS Natural Light rendering requires an application Context" - }.bindCombinedResources( - program = program, - filmCurveMode = hncsFilmCurveMode, - ) - } - val identityMatrix = FloatArray(16) - android.opengl.Matrix.setIdentityM(identityMatrix, 0) - GLES30.glUniformMatrix4fv( - GLES30.glGetUniformLocation(program, "uTexMatrix"), - 1, - false, - identityMatrix, - 0 - ) - // Resource uploads may leave texture unit 3 active. Reassert the image source before - // drawing so initial and cached HNCS renders cannot sample the FilmCurve as input. - GLES30.glActiveTexture(GLES30.GL_TEXTURE0) - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, inputTextureId) - setUniform1i(program, "uInputTexture", 0) - drawQuad(program) - val error = GLES30.glGetError() - if (error != GLES30.GL_NO_ERROR) { - PLog.e(TAG, "renderNaturalLightToneMap glError $error") - return inputTextureId - } - val outputTextureId = if (effectiveEngine.isHncs) { - renderNaturalLightHncsOutput( - inputTextureId = naturalLightTextureId, - width = width, - height = height, - ) - } else { - renderNaturalLightSrgbOutput( - inputTextureId = naturalLightTextureId, - width = width, - height = height, - ) - } - return if (outputTextureId != 0) outputTextureId else inputTextureId - } - - private fun renderNaturalLightHncsOutput( - inputTextureId: Int, - width: Int, - height: Int, - ): Int { - val program = getOrCreateNaturalLightHncsOutputProgram() - if (program == 0) return 0 - setupNaturalLightOutputFramebuffer(width, height) - if (naturalLightOutputFboId == 0 || naturalLightOutputTextureId == 0) return 0 - - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, naturalLightOutputFboId) - GLES30.glViewport(0, 0, width, height) - GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT) - GLES30.glUseProgram(program) - GLES30.glActiveTexture(GLES30.GL_TEXTURE0) - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, inputTextureId) - setUniform1i(program, "uInputTexture", 0) - val outputTransform = RawToneMappingGl.computeWorkingToOutputTransform( - com.hinnka.mycamera.raw.ColorSpace.HNCS, - com.hinnka.mycamera.raw.ColorSpace.SRGB, - ) - GLES30.glUniformMatrix3fv( - GLES30.glGetUniformLocation(program, "uHncsToLinearOutput"), - 1, - false, - RawToneMappingGl.transposeMatrix3x3(outputTransform), - 0, - ) - setUniform1f(program, "uBlacks", 0f) - setUniform1f(program, "uWhites", 0f) - val identityMatrix = FloatArray(16) - android.opengl.Matrix.setIdentityM(identityMatrix, 0) - GLES30.glUniformMatrix4fv( - GLES30.glGetUniformLocation(program, "uTexMatrix"), - 1, - false, - identityMatrix, - 0, - ) - drawQuad(program) - val error = GLES30.glGetError() - if (error != GLES30.GL_NO_ERROR) { - PLog.e(TAG, "renderNaturalLightHncsOutput glError $error") - return 0 - } - return naturalLightOutputTextureId - } - - private fun renderNaturalLightSrgbOutput( - inputTextureId: Int, - width: Int, - height: Int, - ): Int { - val program = getOrCreateNaturalLightSrgbOutputProgram() - if (program == 0) return 0 - setupNaturalLightOutputFramebuffer(width, height) - if (naturalLightOutputFboId == 0 || naturalLightOutputTextureId == 0) return 0 - - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, naturalLightOutputFboId) - GLES30.glViewport(0, 0, width, height) - GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT) - GLES30.glUseProgram(program) - GLES30.glActiveTexture(GLES30.GL_TEXTURE0) - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, inputTextureId) - setUniform1i(program, "uInputTexture", 0) - val identityMatrix = FloatArray(16) - android.opengl.Matrix.setIdentityM(identityMatrix, 0) - GLES30.glUniformMatrix4fv( - GLES30.glGetUniformLocation(program, "uTexMatrix"), - 1, - false, - identityMatrix, - 0, - ) - drawQuad(program) - val error = GLES30.glGetError() - if (error != GLES30.GL_NO_ERROR) { - PLog.e(TAG, "renderNaturalLightSrgbOutput glError $error") - return 0 - } - return naturalLightOutputTextureId - } - - private fun getOrCreateNaturalLightProgram(engine: RawRenderingEngine): Int { - val cached = naturalLightPrograms[engine.ordinal] - if (cached != 0) return cached - val vertexShader = compileShader(GLES30.GL_VERTEX_SHADER, RawFullscreenQuad.VERTEX_SHADER) - val fragmentShader = compileShader( - GLES30.GL_FRAGMENT_SHADER, - RawEngineTonePass.combinedFragmentShaderFor(engine, includeShadowsHighlights = false) - ) - if (vertexShader == 0 || fragmentShader == 0) { - if (vertexShader != 0) GLES30.glDeleteShader(vertexShader) - if (fragmentShader != 0) GLES30.glDeleteShader(fragmentShader) - return 0 - } - val program = GLES30.glCreateProgram() - GLES30.glAttachShader(program, vertexShader) - GLES30.glAttachShader(program, fragmentShader) - GLES30.glLinkProgram(program) - GLES30.glDeleteShader(vertexShader) - GLES30.glDeleteShader(fragmentShader) - val linked = IntArray(1) - GLES30.glGetProgramiv(program, GLES30.GL_LINK_STATUS, linked, 0) - if (linked[0] == 0) { - PLog.e(TAG, "Natural light program link failed: ${GLES30.glGetProgramInfoLog(program)}") - GLES30.glDeleteProgram(program) - return 0 - } - naturalLightPrograms[engine.ordinal] = program - return program - } - - private fun getOrCreateNaturalLightHncsOutputProgram(): Int { - if (naturalLightHncsOutputProgram != 0) return naturalLightHncsOutputProgram - naturalLightHncsOutputProgram = createFragmentProgram( - RawFullscreenQuad.VERTEX_SHADER, - HncsNaturalLightOutputPassShaders.FRAGMENT_SHADER, - "NaturalLight_HncsOutput", - ) - return naturalLightHncsOutputProgram - } - - private fun getOrCreateNaturalLightSrgbOutputProgram(): Int { - if (naturalLightSrgbOutputProgram != 0) return naturalLightSrgbOutputProgram - naturalLightSrgbOutputProgram = createFragmentProgram( - RawFullscreenQuad.VERTEX_SHADER, - RawSrgbPass.FRAGMENT_SHADER, - "NaturalLight_SrgbOutput", - ) - return naturalLightSrgbOutputProgram - } - - private fun setupNaturalLightFramebuffer(width: Int, height: Int) { - if (naturalLightTextureId != 0 && - naturalLightFboId != 0 && - naturalLightWidth == width && - naturalLightHeight == height - ) { - return - } - releaseNaturalLightFramebuffer() - - val textures = IntArray(1) - GLES30.glGenTextures(1, textures, 0) - naturalLightTextureId = textures[0] - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, naturalLightTextureId) - GLES30.glTexImage2D( - GLES30.GL_TEXTURE_2D, - 0, - GLES30.GL_RGBA16F, - width, - height, - 0, - GLES30.GL_RGBA, - GLES30.GL_FLOAT, - null - ) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_LINEAR) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE) - - val fbos = IntArray(1) - GLES30.glGenFramebuffers(1, fbos, 0) - naturalLightFboId = fbos[0] - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, naturalLightFboId) - GLES30.glFramebufferTexture2D( - GLES30.GL_FRAMEBUFFER, - GLES30.GL_COLOR_ATTACHMENT0, - GLES30.GL_TEXTURE_2D, - naturalLightTextureId, - 0 - ) - val status = GLES30.glCheckFramebufferStatus(GLES30.GL_FRAMEBUFFER) - if (status != GLES30.GL_FRAMEBUFFER_COMPLETE) { - PLog.e(TAG, "Natural light framebuffer not complete: $status") - releaseNaturalLightFramebuffer() - return - } - naturalLightWidth = width - naturalLightHeight = height - } - - private fun releaseNaturalLightFramebuffer() { - if (naturalLightFboId != 0) { - GLES30.glDeleteFramebuffers(1, intArrayOf(naturalLightFboId), 0) - naturalLightFboId = 0 - } - if (naturalLightTextureId != 0) { - GLES30.glDeleteTextures(1, intArrayOf(naturalLightTextureId), 0) - naturalLightTextureId = 0 - } - naturalLightWidth = 0 - naturalLightHeight = 0 - } - - private fun setupNaturalLightOutputFramebuffer(width: Int, height: Int) { - if (naturalLightOutputTextureId != 0 && - naturalLightOutputFboId != 0 && - naturalLightOutputWidth == width && - naturalLightOutputHeight == height - ) { - return - } - releaseNaturalLightOutputFramebuffer() - - val textures = IntArray(1) - GLES30.glGenTextures(1, textures, 0) - naturalLightOutputTextureId = textures[0] - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, naturalLightOutputTextureId) - GLES30.glTexImage2D( - GLES30.GL_TEXTURE_2D, - 0, - GLES30.GL_RGBA16F, - width, - height, - 0, - GLES30.GL_RGBA, - GLES30.GL_FLOAT, - null, - ) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_LINEAR) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE) - - val framebuffers = IntArray(1) - GLES30.glGenFramebuffers(1, framebuffers, 0) - naturalLightOutputFboId = framebuffers[0] - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, naturalLightOutputFboId) - GLES30.glFramebufferTexture2D( - GLES30.GL_FRAMEBUFFER, - GLES30.GL_COLOR_ATTACHMENT0, - GLES30.GL_TEXTURE_2D, - naturalLightOutputTextureId, - 0, - ) - val status = GLES30.glCheckFramebufferStatus(GLES30.GL_FRAMEBUFFER) - if (status != GLES30.GL_FRAMEBUFFER_COMPLETE) { - PLog.e(TAG, "Natural Light output framebuffer not complete: $status") - releaseNaturalLightOutputFramebuffer() - return - } - naturalLightOutputWidth = width - naturalLightOutputHeight = height - } - - private fun releaseNaturalLightOutputFramebuffer() { - if (naturalLightOutputFboId != 0) { - GLES30.glDeleteFramebuffers( - 1, - intArrayOf(naturalLightOutputFboId), - 0, - ) - naturalLightOutputFboId = 0 - } - if (naturalLightOutputTextureId != 0) { - GLES30.glDeleteTextures( - 1, - intArrayOf(naturalLightOutputTextureId), - 0, - ) - naturalLightOutputTextureId = 0 - } - naturalLightOutputWidth = 0 - naturalLightOutputHeight = 0 - } - - private fun bindNaturalLightColorTransforms(program: Int, engine: RawRenderingEngine) { - val profileToEngine = RawToneMappingGl.computeWorkingToOutputTransform( - com.hinnka.mycamera.raw.ColorSpace.SRGB, - engine.workingColorSpace - ) - val outputTransform = RawToneMappingGl.computeWorkingToOutputTransform( - engine.workingColorSpace, - com.hinnka.mycamera.raw.ColorSpace.SRGB - ) - GLES30.glUniformMatrix3fv( - GLES30.glGetUniformLocation(program, "uProfileToEngineTransform"), - 1, - false, - RawToneMappingGl.transposeMatrix3x3(profileToEngine), - 0 - ) - GLES30.glUniformMatrix3fv( - GLES30.glGetUniformLocation(program, "uOutputTransform"), - 1, - false, - RawToneMappingGl.transposeMatrix3x3(outputTransform), - 0 - ) - } - - private fun bindNaturalLightProfileExposureUniforms( - program: Int, - engine: RawRenderingEngine, - exposureCompensationEv: Float - ) { - val exposure = RawProfileExposureGl.compute( - profileExposureCompensation = exposureCompensationEv + engine.defaultExposureCompensationEv, - useRamp = engine == RawRenderingEngine.AdobeCurve - ) - RawProfileExposureGl.bindUniforms(program, exposure) - } - - private fun bindNaturalLightDisabledDcpUniforms(program: Int) { - val dummyTextureId = ensureNaturalLightDummy3DTexture() - setUniform1i(program, "uDcpHueSatTexture", 2) - setUniform1i(program, "uDcpLookTableTexture", 3) - setUniform1i(program, "uDcpHueSatEnabled", 0) - setUniform1i(program, "uDcpLookTableEnabled", 0) - setUniform3i(program, "uDcpHueSatDivisions", 1, 1, 1) - setUniform3i(program, "uDcpLookTableDivisions", 1, 1, 1) - setUniform1i(program, "uDcpHueSatEncoding", 0) - setUniform1i(program, "uDcpLookTableEncoding", 0) - GLES30.glActiveTexture(GLES30.GL_TEXTURE2) - GLES30.glBindTexture(GLES30.GL_TEXTURE_3D, dummyTextureId) - GLES30.glActiveTexture(GLES30.GL_TEXTURE3) - GLES30.glBindTexture(GLES30.GL_TEXTURE_3D, dummyTextureId) - } - - private fun bindNaturalLightAdobeCurve( - program: Int, - toneMappingParameters: RawToneMappingParameters - ) { - val curve = RawToneMappingGl.adobeCurveSamplesFor(toneMappingParameters) - uploadNaturalLightCurveTexture(curve) - GLES30.glActiveTexture(GLES30.GL_TEXTURE1) - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, naturalLightCurveTextureId) - setUniform1i(program, "uCurveTexture", 1) - setUniform1f(program, "uCurveSize", curve.size.toFloat()) - setUniform1i(program, "uCurveEnabled", 1) - } - - private fun bindNaturalLightDummySpectralFilmUniforms(program: Int) { - setUniform1i(program, "uSpectralFilmTexture", 6) - setUniform1i(program, "uSpectralFilmSize", 1) - GLES30.glActiveTexture(GLES30.GL_TEXTURE6) - GLES30.glBindTexture(GLES30.GL_TEXTURE_3D, ensureNaturalLightDummy3DTexture()) - } - - private fun uploadNaturalLightCurveTexture(curve: FloatArray) { - if (naturalLightCurveTextureId != 0 && naturalLightCurveSize == curve.size) return - if (naturalLightCurveTextureId == 0) { - val textures = IntArray(1) - GLES30.glGenTextures(1, textures, 0) - naturalLightCurveTextureId = textures[0] - } - val buffer = ByteBuffer.allocateDirect(curve.size * 4) - .order(ByteOrder.nativeOrder()) - .asFloatBuffer() - buffer.put(curve) - buffer.position(0) - - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, naturalLightCurveTextureId) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_LINEAR) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE) - GLES30.glTexImage2D( - GLES30.GL_TEXTURE_2D, - 0, - GLES30.GL_R16F, - curve.size, - 1, - 0, - GLES30.GL_RED, - GLES30.GL_FLOAT, - buffer - ) - naturalLightCurveSize = curve.size - } - - private fun ensureNaturalLightDummy3DTexture(): Int { - if (naturalLightDummy3DTextureId != 0) return naturalLightDummy3DTextureId - val textures = IntArray(1) - GLES30.glGenTextures(1, textures, 0) - naturalLightDummy3DTextureId = textures[0] - val buffer = ByteBuffer.allocateDirect(4 * 4) - .order(ByteOrder.nativeOrder()) - .asFloatBuffer() - buffer.put(floatArrayOf(0f, 1f, 1f, 1f)) - buffer.position(0) - - GLES30.glBindTexture(GLES30.GL_TEXTURE_3D, naturalLightDummy3DTextureId) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_3D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_3D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_NEAREST) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_3D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_3D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_3D, GLES30.GL_TEXTURE_WRAP_R, GLES30.GL_CLAMP_TO_EDGE) - GLES30.glTexImage3D( - GLES30.GL_TEXTURE_3D, - 0, - GLES30.GL_RGBA16F, - 1, - 1, - 1, - 0, - GLES30.GL_RGBA, - GLES30.GL_FLOAT, - buffer - ) - return naturalLightDummy3DTextureId - } - private fun setUniform1i(program: Int, name: String, value: Int) { val location = GLES30.glGetUniformLocation(program, name) if (location >= 0) GLES30.glUniform1i(location, value) @@ -1848,11 +1211,6 @@ class LutImageProcessor(context: Context? = null) { if (location >= 0) GLES30.glUniform1f(location, value) } - private fun setUniform3i(program: Int, name: String, x: Int, y: Int, z: Int) { - val location = GLES30.glGetUniformLocation(program, name) - if (location >= 0) GLES30.glUniform3i(location, x, y, z) - } - private fun obtainReadbackBuffer(pixelSize: Int): ByteBuffer { val current = readbackBuffer if (current != null && readbackBufferSize >= pixelSize) { @@ -2084,16 +1442,6 @@ class LutImageProcessor(context: Context? = null) { } } - private fun ensureNaturalLightSrgbToLinearProgram() { - if (naturalLightSrgbToLinearProgram == 0) { - naturalLightSrgbToLinearProgram = createFragmentProgram( - IMAGE_VERTEX_SHADER, - SRGB_TO_LINEAR_SHADER, - "NaturalLight_SrgbToLinear", - ) - } - } - private fun ensureBitmapChromaDenoisePrograms() { ensureBitmapDenoisePassthroughProgram() if (bitmapChromaDenoiseGuideProgram == 0) { @@ -2421,17 +1769,6 @@ class LutImageProcessor(context: Context? = null) { checkGlError("renderBitmapChromaDenoiseEdgeGuide") } - private fun resolvePreToneMapChromaDenoise( - userStrength: Float, - applyNaturalLightDefault: Boolean - ): Float { - return if (applyNaturalLightDefault) { - ChromaDenoiseDefaults.forRawCapture(userStrength) - } else { - DenoiseStrength.clamp(userStrength) - } - } - private fun renderTexturePassthrough(sourceTextureId: Int, targetFboId: Int, width: Int, height: Int) { GLES30.glUseProgram(bitmapDenoisePassthroughProgram) GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, targetFboId) @@ -2451,34 +1788,6 @@ class LutImageProcessor(context: Context? = null) { drawQuad(bitmapDenoisePassthroughProgram) } - private fun renderSrgbInputToLinear(sourceTextureId: Int, width: Int, height: Int): Int { - ensureNaturalLightSrgbToLinearProgram() - setupBitmapDenoiseFramebuffers(width, height) - if (naturalLightSrgbToLinearProgram == 0) return sourceTextureId - val targetIndex = if (sourceTextureId == bitmapDenoiseTexId[0]) 1 else 0 - val targetFboId = bitmapDenoiseFboId[targetIndex] - val targetTextureId = bitmapDenoiseTexId[targetIndex] - val identityMatrix = FloatArray(16) - android.opengl.Matrix.setIdentityM(identityMatrix, 0) - - GLES30.glUseProgram(naturalLightSrgbToLinearProgram) - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, targetFboId) - GLES30.glViewport(0, 0, width, height) - GLES30.glActiveTexture(GLES30.GL_TEXTURE0) - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, sourceTextureId) - GLES30.glUniform1i(GLES30.glGetUniformLocation(naturalLightSrgbToLinearProgram, "uInputTexture"), 0) - GLES30.glUniformMatrix4fv( - GLES30.glGetUniformLocation(naturalLightSrgbToLinearProgram, "uMVPMatrix"), - 1, - false, - identityMatrix, - 0 - ) - drawQuad(naturalLightSrgbToLinearProgram) - checkGlError("renderSrgbInputToLinear") - return targetTextureId - } - private fun setupLutSharpenFramebuffer(width: Int, height: Int): Boolean { if (lutSharpenFboId != 0 && lutSharpenTextureId != 0 && @@ -3769,32 +3078,6 @@ class LutImageProcessor(context: Context? = null) { } basicToneTextures.release() releaseOutputFramebuffer() - releaseNaturalLightFramebuffer() - releaseNaturalLightOutputFramebuffer() - for (i in naturalLightPrograms.indices) { - if (naturalLightPrograms[i] != 0) { - GLES30.glDeleteProgram(naturalLightPrograms[i]) - naturalLightPrograms[i] = 0 - } - } - if (naturalLightHncsOutputProgram != 0) { - GLES30.glDeleteProgram(naturalLightHncsOutputProgram) - naturalLightHncsOutputProgram = 0 - } - if (naturalLightSrgbOutputProgram != 0) { - GLES30.glDeleteProgram(naturalLightSrgbOutputProgram) - naturalLightSrgbOutputProgram = 0 - } - naturalLightHncsGl?.release() - if (naturalLightCurveTextureId != 0) { - GLES30.glDeleteTextures(1, intArrayOf(naturalLightCurveTextureId), 0) - naturalLightCurveTextureId = 0 - naturalLightCurveSize = 0 - } - if (naturalLightDummy3DTextureId != 0) { - GLES30.glDeleteTextures(1, intArrayOf(naturalLightDummy3DTextureId), 0) - naturalLightDummy3DTextureId = 0 - } if (pboId != 0) { GLES30.glDeleteBuffers(1, intArrayOf(pboId), 0) pboId = 0 @@ -3806,7 +3089,6 @@ class LutImageProcessor(context: Context? = null) { if (bitmapDenoiseNlmFusedAccuProgram != 0) GLES31.glDeleteProgram(bitmapDenoiseNlmFusedAccuProgram) if (bitmapDenoiseNlmFinishProgram != 0) GLES31.glDeleteProgram(bitmapDenoiseNlmFinishProgram) if (bitmapDenoisePassthroughProgram != 0) GLES30.glDeleteProgram(bitmapDenoisePassthroughProgram) - if (naturalLightSrgbToLinearProgram != 0) GLES30.glDeleteProgram(naturalLightSrgbToLinearProgram) if (bitmapChromaDenoiseGuideProgram != 0) GLES30.glDeleteProgram(bitmapChromaDenoiseGuideProgram) if (bitmapChromaDenoiseProgram != 0) GLES30.glDeleteProgram(bitmapChromaDenoiseProgram) if (lutSharpenProgram != 0) { @@ -3945,33 +3227,6 @@ class LutImageProcessor(context: Context? = null) { } """.trimIndent() - private val SRGB_TO_LINEAR_SHADER = """ - #version 300 es - precision highp float; - - in vec2 vTexCoord; - out vec4 fragColor; - - uniform sampler2D uInputTexture; - - vec3 srgbToLinear(vec3 srgb) { - vec3 color = max(srgb, vec3(0.0)); - bvec3 useHigh = greaterThan(color, vec3(0.04045)); - vec3 low = color / 12.92; - vec3 high = pow((color + 0.055) / 1.055, vec3(2.4)); - return vec3( - useHigh.r ? high.r : low.r, - useHigh.g ? high.g : low.g, - useHigh.b ? high.b : low.b - ); - } - - void main() { - vec4 color = texture(uInputTexture, vTexCoord); - fragColor = vec4(srgbToLinear(color.rgb), color.a); - } - """.trimIndent() - private val SHADER_BODY = """ in vec2 vTexCoord; out vec4 fragColor; diff --git a/app/src/main/java/com/hinnka/mycamera/lut/LutRenderer.kt b/app/src/main/java/com/hinnka/mycamera/lut/LutRenderer.kt index 1559c893..502fe62a 100644 --- a/app/src/main/java/com/hinnka/mycamera/lut/LutRenderer.kt +++ b/app/src/main/java/com/hinnka/mycamera/lut/LutRenderer.kt @@ -12,16 +12,6 @@ import com.hinnka.mycamera.model.ColorPaletteMapper import com.hinnka.mycamera.preview.EyeFocusPreviewFrame import com.hinnka.mycamera.preview.EyeFocusProcessingTiming import com.hinnka.mycamera.raw.ColorSpace -import com.hinnka.mycamera.raw.HncsFilmCurveMode -import com.hinnka.mycamera.raw.HncsNaturalLightGl -import com.hinnka.mycamera.raw.HncsNaturalLightOutputPassShaders -import com.hinnka.mycamera.raw.RawProfileExposureGl -import com.hinnka.mycamera.raw.RawRenderingEngine -import com.hinnka.mycamera.raw.RawEngineTonePass -import com.hinnka.mycamera.raw.RawFullscreenQuad -import com.hinnka.mycamera.raw.RawSrgbPass -import com.hinnka.mycamera.raw.RawToneMappingGl -import com.hinnka.mycamera.raw.RawToneMappingParameters import com.hinnka.mycamera.screencapture.PhantomPipCrop import com.hinnka.mycamera.camera.MeteringMode import com.hinnka.mycamera.utils.PLog @@ -70,25 +60,10 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer { private const val EYE_FOCUS_TIMING_EMA_ALPHA = 0.25 private const val EYE_FOCUS_TIMING_HEADROOM = 1.15 private const val EYE_FOCUS_TIMING_LOG_INTERVAL_MS = 2_000L - private const val RAW_PREVIEW_STAGE_COUNT = 3 - private const val RAW_PREVIEW_INPUT_STAGE = 0 - private const val RAW_PREVIEW_COMBINED_STAGE = 1 - private const val RAW_PREVIEW_OUTPUT_STAGE = 2 private const val CLARITY_PYRAMID_LEVELS = 3 } private val colorProgramCache = PreviewColorProgramCache() - private val rawPreviewHncsGl = HncsNaturalLightGl(context) - - private data class PreviewSourceOverride( - val textureSource: PreviewColorTextureSource, - val textureTarget: Int, - val textureId: Int, - val stMatrix: FloatArray, - val cropRect: FloatArray, - val mvpMatrix: FloatArray, - val treatSourceAsHlgInput: Boolean - ) private data class PreviewCaptureRequest( val width: Int, @@ -138,20 +113,6 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer { private var stackFboWidth: Int = 0 private var stackFboHeight: Int = 0 - // RAW 预览前置处理资源:线性输入 -> RAW combined - private val rawPreviewFboIds = IntArray(RAW_PREVIEW_STAGE_COUNT) - private val rawPreviewTextureIds = IntArray(RAW_PREVIEW_STAGE_COUNT) - private var rawPreviewWidth: Int = 0 - private var rawPreviewHeight: Int = 0 - private var rawPreviewAllocatedStageCount: Int = 0 - private var rawPreviewInputProgramId: Int = 0 - private var rawPreviewCurveTextureId: Int = 0 - private var rawPreviewCurveSize: Int = 0 - private var rawPreviewDummy3DTextureId: Int = 0 - private var rawPreviewSrgbOutputProgramId: Int = 0 - private var rawPreviewHncsOutputProgramId: Int = 0 - private val rawPreviewCombinedPrograms = IntArray(RawRenderingEngine.entries.size) - // Copy Shader (FBO -> Screen) private var copyProgramId: Int = 0 private var uCopyTextureLoc: Int = 0 @@ -164,27 +125,6 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer { // 是否以 HLG10 动态范围采集(Log LUT 兼容性方案) var isHlgInput: Boolean = false - @Volatile - var rawPreviewEnabled: Boolean = false - - @Volatile - var rawPreviewExposureCompensation: Float = 0f - - @Volatile - var rawPreviewBlackPointCorrection: Float = 0f - - @Volatile - var rawPreviewWhitePointCorrection: Float = 0f - - @Volatile - var rawPreviewRenderingEngine: RawRenderingEngine = RawRenderingEngine.AdobeCurve - - @Volatile - var rawPreviewToneMappingParameters: RawToneMappingParameters = RawToneMappingParameters.DEFAULT - - @Volatile - var rawPreviewHncsFilmCurveMode: HncsFilmCurveMode = HncsFilmCurveMode.Standard - // 曲线纹理 private var curveTextureId: Int = 0 private var baselineCurveTextureId: Int = 0 @@ -658,18 +598,6 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer { stackTextureId = 0 stackFboWidth = 0 stackFboHeight = 0 - rawPreviewFboIds.fill(0) - rawPreviewTextureIds.fill(0) - rawPreviewWidth = 0 - rawPreviewHeight = 0 - rawPreviewAllocatedStageCount = 0 - rawPreviewInputProgramId = 0 - rawPreviewCurveTextureId = 0 - rawPreviewCurveSize = 0 - rawPreviewDummy3DTextureId = 0 - rawPreviewHncsOutputProgramId = 0 - rawPreviewHncsGl.resetAfterContextLoss() - rawPreviewCombinedPrograms.fill(0) copyProgramId = 0 hdfExtractBlurHProgram = 0 hdfBlurVProgram = 0 @@ -842,572 +770,6 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer { stackFboHeight == height } - private fun renderRawPreviewSource(width: Int, height: Int): PreviewSourceOverride? { - if (!ensureRawPreviewFramebuffers(width, height)) return null - val effectiveEngine = resolveRawPreviewEngine() - if (!renderRawPreviewInputStage(width, height)) return null - if (!renderRawPreviewCombinedStage(width, height, effectiveEngine)) return null - val outputRendered = if (effectiveEngine.isHncs) { - renderRawPreviewHncsOutputStage(width, height) - } else { - renderRawPreviewSrgbOutputStage(width, height) - } - if (!outputRendered) return null - - val identityMatrix = FloatArray(16).also { Matrix.setIdentityM(it, 0) } - return PreviewSourceOverride( - textureSource = PreviewColorTextureSource.TEXTURE_2D, - textureTarget = GLES30.GL_TEXTURE_2D, - textureId = rawPreviewTextureIds[RAW_PREVIEW_OUTPUT_STAGE], - stMatrix = identityMatrix, - cropRect = floatArrayOf(0f, 0f, 1f, 1f), - mvpMatrix = identityMatrix, - treatSourceAsHlgInput = false - ) - } - - private fun resolveRawPreviewEngine(): RawRenderingEngine { - return when (rawPreviewRenderingEngine) { - // Spectral film requires a selected stock and print, neither of which belongs to the - // Natural Light viewfinder contract. - RawRenderingEngine.Spektrafilm -> RawRenderingEngine.AdobeCurve - // A live preview is already in sRGB, outside the RAW camera domain required by the - // sensor-specific HNCS color map. Keep the common HNCS CCM + FilmCurve path. - RawRenderingEngine.HncsLut -> RawRenderingEngine.HncsCcm - else -> rawPreviewRenderingEngine - } - } - - private fun ensureRawPreviewFramebuffers(width: Int, height: Int): Boolean { - if ( - rawPreviewWidth == width && - rawPreviewHeight == height && - rawPreviewAllocatedStageCount == RAW_PREVIEW_STAGE_COUNT && - (0 until RAW_PREVIEW_STAGE_COUNT).all { index -> - rawPreviewFboIds[index] != 0 && rawPreviewTextureIds[index] != 0 - } - ) { - return true - } - - releaseRawPreviewFramebuffers() - rawPreviewWidth = width - rawPreviewHeight = height - rawPreviewAllocatedStageCount = RAW_PREVIEW_STAGE_COUNT - - GLES30.glGenFramebuffers(RAW_PREVIEW_STAGE_COUNT, rawPreviewFboIds, 0) - GLES30.glGenTextures(RAW_PREVIEW_STAGE_COUNT, rawPreviewTextureIds, 0) - for (i in 0 until RAW_PREVIEW_STAGE_COUNT) { - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, rawPreviewTextureIds[i]) - GLES30.glTexImage2D( - GLES30.GL_TEXTURE_2D, - 0, - GLES30.GL_RGBA16F, - width, - height, - 0, - GLES30.GL_RGBA, - GLES30.GL_HALF_FLOAT, - null - ) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_LINEAR) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE) - - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, rawPreviewFboIds[i]) - GLES30.glFramebufferTexture2D( - GLES30.GL_FRAMEBUFFER, - GLES30.GL_COLOR_ATTACHMENT0, - GLES30.GL_TEXTURE_2D, - rawPreviewTextureIds[i], - 0 - ) - val status = GLES30.glCheckFramebufferStatus(GLES30.GL_FRAMEBUFFER) - if (status != GLES30.GL_FRAMEBUFFER_COMPLETE) { - PLog.e(TAG, "RAW preview FBO $i incomplete: $status") - releaseRawPreviewFramebuffers() - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0) - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0) - return false - } - } - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0) - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0) - return true - } - - private fun renderRawPreviewInputStage(width: Int, height: Int): Boolean { - val program = getOrCreateRawPreviewInputProgram() - if (program == 0) return false - - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, rawPreviewFboIds[RAW_PREVIEW_INPUT_STAGE]) - GLES30.glViewport(0, 0, width, height) - GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT) - GLES30.glUseProgram(program) - - GLES30.glActiveTexture(GLES30.GL_TEXTURE0) - GLES30.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, cameraTextureId) - GLES30.glUniform1i(GLES30.glGetUniformLocation(program, "uCameraTexture"), 0) - GLES30.glUniformMatrix4fv(GLES30.glGetUniformLocation(program, "uMVPMatrix"), 1, false, mvpMatrix, 0) - GLES30.glUniformMatrix4fv(GLES30.glGetUniformLocation(program, "uSTMatrix"), 1, false, stMatrix, 0) - GLES30.glUniform4f( - GLES30.glGetUniformLocation(program, "uCropRect"), - cropRect[0], - cropRect[1], - cropRect[2], - cropRect[3] - ) - GLES30.glUniform1f( - GLES30.glGetUniformLocation(program, "uExposureEv"), - 0f - ) - drawRawPreviewQuad(program) - GlUtils.checkGlError("renderRawPreviewInputStage") - return true - } - - private fun renderRawPreviewCombinedStage( - width: Int, - height: Int, - engine: RawRenderingEngine - ): Boolean { - val program = getOrCreateRawPreviewCombinedProgram(engine) - if (program == 0) return false - - GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, rawPreviewFboIds[RAW_PREVIEW_COMBINED_STAGE]) - GLES30.glViewport(0, 0, width, height) - GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT) - GLES30.glUseProgram(program) - - GLES30.glActiveTexture(GLES30.GL_TEXTURE0) - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, rawPreviewTextureIds[RAW_PREVIEW_INPUT_STAGE]) - GLES30.glUniform1i(GLES30.glGetUniformLocation(program, "uInputTexture"), 0) - RawToneMappingGl.bindRawToneMappingUniforms(program, rawPreviewToneMappingParameters) - bindRawPreviewProfileExposureUniforms(program, engine) - bindRawPreviewBlacksWhitesUniforms( - program = program, - applyAdjustments = !engine.isHncs, - ) - bindRawPreviewColorTransforms(program, engine) - if (engine == RawRenderingEngine.AdobeCurve) { - bindRawPreviewDisabledDcpUniforms(program) - bindRawPreviewAdobeCurve(program) - } - if (engine == RawRenderingEngine.Spektrafilm) { - bindRawPreviewDummySpectralFilmUniforms(program) - } - if (engine.isHncs) { - rawPreviewHncsGl.bindCombinedResources( - program = program, - filmCurveMode = rawPreviewHncsFilmCurveMode, - ) - } - val identityMatrix = FloatArray(16).also { Matrix.setIdentityM(it, 0) } - GLES30.glUniformMatrix4fv( - GLES30.glGetUniformLocation(program, "uTexMatrix"), - 1, - false, - identityMatrix, - 0 - ) - // Resource setup may change the active unit. Reassert the per-frame image binding so a - // first HNCS frame and all cached frames have exactly the same sampler state. - GLES30.glActiveTexture(GLES30.GL_TEXTURE0) - GLES30.glBindTexture( - GLES30.GL_TEXTURE_2D, - rawPreviewTextureIds[RAW_PREVIEW_INPUT_STAGE], - ) - GLES30.glUniform1i(GLES30.glGetUniformLocation(program, "uInputTexture"), 0) - drawRawPreviewQuad(program) - GlUtils.checkGlError("renderRawPreviewCombinedStage") - return true - } - - private fun renderRawPreviewHncsOutputStage(width: Int, height: Int): Boolean { - val program = getOrCreateRawPreviewHncsOutputProgram() - if (program == 0) return false - - GLES30.glBindFramebuffer( - GLES30.GL_FRAMEBUFFER, - rawPreviewFboIds[RAW_PREVIEW_OUTPUT_STAGE], - ) - GLES30.glViewport(0, 0, width, height) - GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT) - GLES30.glUseProgram(program) - - GLES30.glActiveTexture(GLES30.GL_TEXTURE0) - GLES30.glBindTexture( - GLES30.GL_TEXTURE_2D, - rawPreviewTextureIds[RAW_PREVIEW_COMBINED_STAGE], - ) - GLES30.glUniform1i(GLES30.glGetUniformLocation(program, "uInputTexture"), 0) - val outputTransform = RawToneMappingGl.computeWorkingToOutputTransform( - ColorSpace.HNCS, - ColorSpace.SRGB, - ) - GLES30.glUniformMatrix3fv( - GLES30.glGetUniformLocation(program, "uHncsToLinearOutput"), - 1, - false, - RawToneMappingGl.transposeMatrix3x3(outputTransform), - 0, - ) - GLES30.glUniform1f( - GLES30.glGetUniformLocation(program, "uBlacks"), - rawPreviewBlackPointCorrection.coerceIn(-1f, 1f), - ) - GLES30.glUniform1f( - GLES30.glGetUniformLocation(program, "uWhites"), - rawPreviewWhitePointCorrection.coerceIn(-1f, 1f), - ) - val identityMatrix = FloatArray(16).also { Matrix.setIdentityM(it, 0) } - GLES30.glUniformMatrix4fv( - GLES30.glGetUniformLocation(program, "uTexMatrix"), - 1, - false, - identityMatrix, - 0, - ) - drawRawPreviewQuad(program) - GlUtils.checkGlError("renderRawPreviewHncsOutputStage") - return true - } - - private fun renderRawPreviewSrgbOutputStage(width: Int, height: Int): Boolean { - val program = getOrCreateRawPreviewSrgbOutputProgram() - if (program == 0) return false - - GLES30.glBindFramebuffer( - GLES30.GL_FRAMEBUFFER, - rawPreviewFboIds[RAW_PREVIEW_OUTPUT_STAGE], - ) - GLES30.glViewport(0, 0, width, height) - GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT) - GLES30.glUseProgram(program) - - GLES30.glActiveTexture(GLES30.GL_TEXTURE0) - GLES30.glBindTexture( - GLES30.GL_TEXTURE_2D, - rawPreviewTextureIds[RAW_PREVIEW_COMBINED_STAGE], - ) - GLES30.glUniform1i(GLES30.glGetUniformLocation(program, "uInputTexture"), 0) - val identityMatrix = FloatArray(16).also { Matrix.setIdentityM(it, 0) } - GLES30.glUniformMatrix4fv( - GLES30.glGetUniformLocation(program, "uTexMatrix"), - 1, - false, - identityMatrix, - 0, - ) - drawRawPreviewQuad(program) - GlUtils.checkGlError("renderRawPreviewSrgbOutputStage") - return true - } - - private fun getOrCreateRawPreviewInputProgram(): Int { - if (rawPreviewInputProgramId != 0) return rawPreviewInputProgramId - val vertexShader = GlUtils.compileShader(GLES30.GL_VERTEX_SHADER, Shaders.VERTEX_SHADER) - val fragmentShader = GlUtils.compileShader( - GLES30.GL_FRAGMENT_SHADER, - RawPreviewShaders.LINEAR_INPUT_FRAGMENT_SHADER - ) - if (vertexShader == 0 || fragmentShader == 0) { - if (vertexShader != 0) GLES30.glDeleteShader(vertexShader) - if (fragmentShader != 0) GLES30.glDeleteShader(fragmentShader) - return 0 - } - rawPreviewInputProgramId = GlUtils.linkProgram(vertexShader, fragmentShader) - GLES30.glDeleteShader(vertexShader) - GLES30.glDeleteShader(fragmentShader) - return rawPreviewInputProgramId - } - - private fun getOrCreateRawPreviewCombinedProgram(engine: RawRenderingEngine): Int { - val cached = rawPreviewCombinedPrograms[engine.ordinal] - if (cached != 0) return cached - val vertexShader = GlUtils.compileShader( - GLES30.GL_VERTEX_SHADER, - RawFullscreenQuad.VERTEX_SHADER, - ) - val fragmentShader = GlUtils.compileShader( - GLES30.GL_FRAGMENT_SHADER, - RawEngineTonePass.combinedFragmentShaderFor(engine, includeShadowsHighlights = false) - ) - if (vertexShader == 0 || fragmentShader == 0) { - if (vertexShader != 0) GLES30.glDeleteShader(vertexShader) - if (fragmentShader != 0) GLES30.glDeleteShader(fragmentShader) - return 0 - } - val program = GlUtils.linkProgram(vertexShader, fragmentShader) - GLES30.glDeleteShader(vertexShader) - GLES30.glDeleteShader(fragmentShader) - rawPreviewCombinedPrograms[engine.ordinal] = program - return program - } - - private fun getOrCreateRawPreviewHncsOutputProgram(): Int { - if (rawPreviewHncsOutputProgramId != 0) return rawPreviewHncsOutputProgramId - val vertexShader = GlUtils.compileShader( - GLES30.GL_VERTEX_SHADER, - RawFullscreenQuad.VERTEX_SHADER, - ) - val fragmentShader = GlUtils.compileShader( - GLES30.GL_FRAGMENT_SHADER, - HncsNaturalLightOutputPassShaders.FRAGMENT_SHADER, - ) - if (vertexShader == 0 || fragmentShader == 0) { - if (vertexShader != 0) GLES30.glDeleteShader(vertexShader) - if (fragmentShader != 0) GLES30.glDeleteShader(fragmentShader) - return 0 - } - rawPreviewHncsOutputProgramId = GlUtils.linkProgram(vertexShader, fragmentShader) - GLES30.glDeleteShader(vertexShader) - GLES30.glDeleteShader(fragmentShader) - return rawPreviewHncsOutputProgramId - } - - private fun getOrCreateRawPreviewSrgbOutputProgram(): Int { - if (rawPreviewSrgbOutputProgramId != 0) return rawPreviewSrgbOutputProgramId - val vertexShader = GlUtils.compileShader( - GLES30.GL_VERTEX_SHADER, - RawFullscreenQuad.VERTEX_SHADER, - ) - val fragmentShader = GlUtils.compileShader( - GLES30.GL_FRAGMENT_SHADER, - RawSrgbPass.FRAGMENT_SHADER, - ) - if (vertexShader == 0 || fragmentShader == 0) { - if (vertexShader != 0) GLES30.glDeleteShader(vertexShader) - if (fragmentShader != 0) GLES30.glDeleteShader(fragmentShader) - return 0 - } - rawPreviewSrgbOutputProgramId = GlUtils.linkProgram(vertexShader, fragmentShader) - GLES30.glDeleteShader(vertexShader) - GLES30.glDeleteShader(fragmentShader) - return rawPreviewSrgbOutputProgramId - } - - private fun bindRawPreviewBlacksWhitesUniforms( - program: Int, - applyAdjustments: Boolean, - ) { - GLES30.glUniform1f( - GLES30.glGetUniformLocation(program, "uBlacks"), - if (applyAdjustments) rawPreviewBlackPointCorrection.coerceIn(-1f, 1f) else 0f, - ) - GLES30.glUniform1f( - GLES30.glGetUniformLocation(program, "uWhites"), - if (applyAdjustments) rawPreviewWhitePointCorrection.coerceIn(-1f, 1f) else 0f, - ) - } - - private fun bindRawPreviewColorTransforms(program: Int, engine: RawRenderingEngine) { - val profileToEngine = RawToneMappingGl.computeWorkingToOutputTransform(ColorSpace.SRGB, engine.workingColorSpace) - val outputTransform = RawToneMappingGl.computeWorkingToOutputTransform(engine.workingColorSpace, ColorSpace.SRGB) - GLES30.glUniformMatrix3fv( - GLES30.glGetUniformLocation(program, "uProfileToEngineTransform"), - 1, - false, - RawToneMappingGl.transposeMatrix3x3(profileToEngine), - 0 - ) - GLES30.glUniformMatrix3fv( - GLES30.glGetUniformLocation(program, "uOutputTransform"), - 1, - false, - RawToneMappingGl.transposeMatrix3x3(outputTransform), - 0 - ) - } - - private fun bindRawPreviewProfileExposureUniforms(program: Int, engine: RawRenderingEngine) { - val exposure = RawProfileExposureGl.compute( - profileExposureCompensation = rawPreviewExposureCompensation + engine.defaultExposureCompensationEv, - useRamp = engine == RawRenderingEngine.AdobeCurve - ) - RawProfileExposureGl.bindUniforms(program, exposure) - } - - private fun bindRawPreviewDisabledDcpUniforms(program: Int) { - val dummyTextureId = ensureRawPreviewDummy3DTexture() - uniform1i(program, "uDcpHueSatTexture", 2) - uniform1i(program, "uDcpLookTableTexture", 3) - uniform1i(program, "uDcpHueSatEnabled", 0) - uniform1i(program, "uDcpLookTableEnabled", 0) - uniform3i(program, "uDcpHueSatDivisions", 1, 1, 1) - uniform3i(program, "uDcpLookTableDivisions", 1, 1, 1) - uniform1i(program, "uDcpHueSatEncoding", 0) - uniform1i(program, "uDcpLookTableEncoding", 0) - GLES30.glActiveTexture(GLES30.GL_TEXTURE2) - GLES30.glBindTexture(GLES30.GL_TEXTURE_3D, dummyTextureId) - GLES30.glActiveTexture(GLES30.GL_TEXTURE3) - GLES30.glBindTexture(GLES30.GL_TEXTURE_3D, dummyTextureId) - } - - private fun bindRawPreviewAdobeCurve(program: Int) { - val curve = RawToneMappingGl.adobeCurveSamplesFor(rawPreviewToneMappingParameters) - uploadRawPreviewCurveTexture(curve) - GLES30.glActiveTexture(GLES30.GL_TEXTURE1) - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, rawPreviewCurveTextureId) - GLES30.glUniform1i(GLES30.glGetUniformLocation(program, "uCurveTexture"), 1) - GLES30.glUniform1f(GLES30.glGetUniformLocation(program, "uCurveSize"), curve.size.toFloat()) - GLES30.glUniform1i(GLES30.glGetUniformLocation(program, "uCurveEnabled"), 1) - } - - private fun bindRawPreviewDummySpectralFilmUniforms(program: Int) { - uniform1i(program, "uSpectralFilmTexture", 6) - uniform1i(program, "uSpectralFilmSize", 1) - GLES30.glActiveTexture(GLES30.GL_TEXTURE6) - GLES30.glBindTexture(GLES30.GL_TEXTURE_3D, ensureRawPreviewDummy3DTexture()) - } - - private fun uploadRawPreviewCurveTexture(curve: FloatArray) { - if (rawPreviewCurveTextureId != 0 && rawPreviewCurveSize == curve.size) return - if (rawPreviewCurveTextureId == 0) { - val textures = IntArray(1) - GLES30.glGenTextures(1, textures, 0) - rawPreviewCurveTextureId = textures[0] - } - val buffer = ByteBuffer.allocateDirect(curve.size * 4) - .order(ByteOrder.nativeOrder()) - .asFloatBuffer() - buffer.put(curve) - buffer.position(0) - - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, rawPreviewCurveTextureId) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_LINEAR) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE) - GLES30.glTexImage2D( - GLES30.GL_TEXTURE_2D, - 0, - GLES30.GL_R16F, - curve.size, - 1, - 0, - GLES30.GL_RED, - GLES30.GL_FLOAT, - buffer - ) - rawPreviewCurveSize = curve.size - } - - private fun ensureRawPreviewDummy3DTexture(): Int { - if (rawPreviewDummy3DTextureId != 0) return rawPreviewDummy3DTextureId - val textures = IntArray(1) - GLES30.glGenTextures(1, textures, 0) - rawPreviewDummy3DTextureId = textures[0] - val buffer = ByteBuffer.allocateDirect(4 * 4) - .order(ByteOrder.nativeOrder()) - .asFloatBuffer() - buffer.put(floatArrayOf(0f, 1f, 1f, 1f)) - buffer.position(0) - - GLES30.glBindTexture(GLES30.GL_TEXTURE_3D, rawPreviewDummy3DTextureId) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_3D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_3D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_NEAREST) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_3D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_3D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE) - GLES30.glTexParameteri(GLES30.GL_TEXTURE_3D, GLES30.GL_TEXTURE_WRAP_R, GLES30.GL_CLAMP_TO_EDGE) - GLES30.glTexImage3D( - GLES30.GL_TEXTURE_3D, - 0, - GLES30.GL_RGBA16F, - 1, - 1, - 1, - 0, - GLES30.GL_RGBA, - GLES30.GL_FLOAT, - buffer - ) - GlUtils.checkGlError("ensureRawPreviewDummy3DTexture") - return rawPreviewDummy3DTextureId - } - - private fun drawRawPreviewQuad(program: Int) { - val posLoc = GLES30.glGetAttribLocation(program, "aPosition") - val texLoc = GLES30.glGetAttribLocation(program, "aTexCoord") - GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, vertexBufferId) - if (posLoc >= 0) { - GLES30.glEnableVertexAttribArray(posLoc) - GLES30.glVertexAttribPointer(posLoc, POSITION_COMPONENT_COUNT, GLES30.GL_FLOAT, false, 0, 0) - } - GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, texCoordBufferId) - if (texLoc >= 0) { - GLES30.glEnableVertexAttribArray(texLoc) - GLES30.glVertexAttribPointer(texLoc, TEXTURE_COORD_COMPONENT_COUNT, GLES30.GL_FLOAT, false, 0, 0) - } - GLES30.glBindBuffer(GLES30.GL_ELEMENT_ARRAY_BUFFER, indexBufferId) - GLES30.glDrawElements(GLES30.GL_TRIANGLES, Shaders.DRAW_ORDER.size, GLES30.GL_UNSIGNED_SHORT, 0) - if (posLoc >= 0) GLES30.glDisableVertexAttribArray(posLoc) - if (texLoc >= 0) GLES30.glDisableVertexAttribArray(texLoc) - GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0) - GLES30.glBindBuffer(GLES30.GL_ELEMENT_ARRAY_BUFFER, 0) - } - - private fun uniform1i(program: Int, name: String, value: Int) { - val location = GLES30.glGetUniformLocation(program, name) - if (location >= 0) GLES30.glUniform1i(location, value) - } - - private fun uniform3i(program: Int, name: String, x: Int, y: Int, z: Int) { - val location = GLES30.glGetUniformLocation(program, name) - if (location >= 0) GLES30.glUniform3i(location, x, y, z) - } - - private fun uniform1f(program: Int, name: String, value: Float) { - val location = GLES30.glGetUniformLocation(program, name) - if (location >= 0) GLES30.glUniform1f(location, value) - } - - private fun releaseRawPreviewFramebuffers() { - if (rawPreviewAllocatedStageCount > 0 && rawPreviewFboIds.any { it != 0 }) { - GLES30.glDeleteFramebuffers( - rawPreviewAllocatedStageCount, - rawPreviewFboIds, - 0, - ) - rawPreviewFboIds.fill(0) - } - if (rawPreviewAllocatedStageCount > 0 && rawPreviewTextureIds.any { it != 0 }) { - GLES30.glDeleteTextures( - rawPreviewAllocatedStageCount, - rawPreviewTextureIds, - 0, - ) - rawPreviewTextureIds.fill(0) - } - rawPreviewWidth = 0 - rawPreviewHeight = 0 - rawPreviewAllocatedStageCount = 0 - } - - private fun releaseRawPreviewPrograms() { - GlUtils.deleteProgram(rawPreviewInputProgramId) - rawPreviewInputProgramId = 0 - GlUtils.deleteProgram(rawPreviewSrgbOutputProgramId) - rawPreviewSrgbOutputProgramId = 0 - GlUtils.deleteProgram(rawPreviewHncsOutputProgramId) - rawPreviewHncsOutputProgramId = 0 - for (i in rawPreviewCombinedPrograms.indices) { - GlUtils.deleteProgram(rawPreviewCombinedPrograms[i]) - rawPreviewCombinedPrograms[i] = 0 - } - if (rawPreviewCurveTextureId != 0) { - GLES30.glDeleteTextures(1, intArrayOf(rawPreviewCurveTextureId), 0) - rawPreviewCurveTextureId = 0 - rawPreviewCurveSize = 0 - } - if (rawPreviewDummy3DTextureId != 0) { - GLES30.glDeleteTextures(1, intArrayOf(rawPreviewDummy3DTextureId), 0) - rawPreviewDummy3DTextureId = 0 - } - rawPreviewHncsGl.release() - } - private fun hasBaselineLayer(): Boolean { return (baselineLutEnabled && currentBaselineLutConfig != null) || baselineColorRecipeEnabled || @@ -1655,10 +1017,8 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer { val hasBaselineLayer = hasBaselineLayer() && !suppressBaselineLayerForVideoLog val hasCreativeLayer = hasCreativeLayer() val hasDualLayer = hasBaselineLayer && hasCreativeLayer - val rawPreviewNeeded = rawPreviewEnabled uploadPendingCurveTextures() - val requestedFbo = rawPreviewNeeded || - liveRecorder != null || + val requestedFbo = liveRecorder != null || postProcessEffectEnabled || clarityEnabled || filmGrainEnabled || @@ -1676,11 +1036,6 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer { val currentWidth = viewportWidth val currentHeight = viewportHeight - val rawPreviewSource = if (rawPreviewNeeded) { - renderRawPreviewSource(viewportWidth, viewportHeight) - } else { - null - } // 渲染色彩链路到 FBO drawInternal( @@ -1688,8 +1043,7 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer { width = currentWidth, height = currentHeight, preferBaselineLayer = hasDualLayer, - suppressBaselineLayer = suppressBaselineLayerForVideoLog, - sourceOverride = rawPreviewSource + suppressBaselineLayer = suppressBaselineLayerForVideoLog ) var currentTexId = fboTextureId @@ -1841,7 +1195,6 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer { } } capturePendingPreviewFrames( - rawPreviewSource = rawPreviewSource, finalDisplayTextureId = finalDisplayTextureId, finalDisplayWidth = finalDisplayWidth, finalDisplayHeight = finalDisplayHeight, @@ -1864,7 +1217,6 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer { suppressBaselineLayer = suppressBaselineLayerForVideoLog ) capturePendingPreviewFrames( - rawPreviewSource = null, finalDisplayTextureId = null, finalDisplayWidth = viewportWidth, finalDisplayHeight = viewportHeight, @@ -1935,8 +1287,7 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer { targetMvpMatrix: FloatArray = mvpMatrix, preferBaselineLayer: Boolean = false, suppressBaselineLayer: Boolean = false, - suppressCreativeLayer: Boolean = false, - sourceOverride: PreviewSourceOverride? = null + suppressCreativeLayer: Boolean = false ) { val baselineLayerAvailable = hasBaselineLayer() && !suppressBaselineLayer val creativeLayerAvailable = hasCreativeLayer() && !suppressCreativeLayer @@ -1974,31 +1325,24 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer { false } val enableVideoLog = true - val textureSource = sourceOverride?.textureSource ?: PreviewColorTextureSource.EXTERNAL_OES - val sourceTextureTarget = sourceOverride?.textureTarget ?: GLES11Ext.GL_TEXTURE_EXTERNAL_OES - val sourceTextureId = sourceOverride?.textureId ?: cameraTextureId - val sourceStMatrix = sourceOverride?.stMatrix ?: stMatrix - val sourceCropRect = sourceOverride?.cropRect ?: cropRect - val sourceMvpMatrix = sourceOverride?.mvpMatrix ?: targetMvpMatrix - val treatSourceAsHlgInput = sourceOverride?.treatSourceAsHlgInput ?: isHlgInput val locations = getColorPassLocations( - textureSource = textureSource, + textureSource = PreviewColorTextureSource.EXTERNAL_OES, lutConfig = layerLutConfig, lutEnabled = layerLutEnabled, params = layerParams, enableVideoLog = enableVideoLog, - treatSourceAsHlgInput = treatSourceAsHlgInput, + treatSourceAsHlgInput = isHlgInput, ) ?: return drawColorPass( locations = locations, targetFboId = fboId, width = width, height = height, - sourceTextureTarget = sourceTextureTarget, - sourceTextureId = sourceTextureId, - sourceStMatrix = sourceStMatrix, - sourceCropRect = sourceCropRect, - targetMvpMatrix = sourceMvpMatrix, + sourceTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES, + sourceTextureId = cameraTextureId, + sourceStMatrix = stMatrix, + sourceCropRect = cropRect, + targetMvpMatrix = targetMvpMatrix, lutConfig = layerLutConfig, lutTextureId = layerLutTextureId, lutSize = layerLutSize, @@ -2007,7 +1351,7 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer { curveTextureId = layerCurveTextureId, curveEnabled = layerCurveEnabled, enableVideoLog = enableVideoLog, - treatSourceAsHlgInput = treatSourceAsHlgInput + treatSourceAsHlgInput = isHlgInput ) // 测光和直方图(按需) @@ -3390,7 +2734,6 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer { } private fun capturePendingPreviewFrames( - rawPreviewSource: PreviewSourceOverride?, finalDisplayTextureId: Int?, finalDisplayWidth: Int, finalDisplayHeight: Int, @@ -3399,10 +2742,7 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer { while (pendingPreviewCaptureRequests.isNotEmpty()) { val request = pendingPreviewCaptureRequests.removeFirst() when (request.source) { - PreviewCaptureSource.Original -> captureOriginalPreviewFrameInternal( - request = request, - rawPreviewSource = rawPreviewSource - ) + PreviewCaptureSource.Original -> captureOriginalPreviewFrameInternal(request) PreviewCaptureSource.FinalDisplay -> capturePreviewFrameInternal( request = request, @@ -3510,21 +2850,7 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer { } } - private fun captureOriginalPreviewFrameInternal( - request: PreviewCaptureRequest, - rawPreviewSource: PreviewSourceOverride? - ) { - if (rawPreviewSource != null) { - capturePreviewFrameInternal( - request = request, - sourceTextureId = rawPreviewSource.textureId, - sourceWidth = viewportWidth, - sourceHeight = viewportHeight, - compositeWithHdf = false - ) - return - } - + private fun captureOriginalPreviewFrameInternal(request: PreviewCaptureRequest) { capturePreviewFrameInternal( request = request, suppressColorLayers = true @@ -3948,9 +3274,6 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer { } postProcessScratchWidth = 0 postProcessScratchHeight = 0 - releaseRawPreviewFramebuffers() - releaseRawPreviewPrograms() - // 删除缓冲 if (vertexBufferId != 0) { GLES30.glDeleteBuffers(1, intArrayOf(vertexBufferId), 0) @@ -4192,24 +3515,6 @@ class LutRenderer(context: Context) : GLSurfaceView.Renderer { } } - fun setRawPreviewSettings( - enabled: Boolean, - exposureCompensation: Float, - blackPointCorrection: Float, - whitePointCorrection: Float, - renderingEngine: RawRenderingEngine, - hncsFilmCurveMode: HncsFilmCurveMode, - toneMappingParameters: RawToneMappingParameters - ) { - rawPreviewEnabled = enabled - rawPreviewExposureCompensation = exposureCompensation - rawPreviewBlackPointCorrection = blackPointCorrection - rawPreviewWhitePointCorrection = whitePointCorrection - rawPreviewRenderingEngine = renderingEngine - rawPreviewHncsFilmCurveMode = hncsFilmCurveMode - rawPreviewToneMappingParameters = toneMappingParameters - } - fun updateBaselineRecipeParams(params: com.hinnka.mycamera.model.ColorRecipeParams) { baselineRecipeParams = params baselineColorRecipeEnabled = !params.isDefault() diff --git a/app/src/main/java/com/hinnka/mycamera/lut/RawPreviewShaders.kt b/app/src/main/java/com/hinnka/mycamera/lut/RawPreviewShaders.kt deleted file mode 100644 index 7e6e4cc8..00000000 --- a/app/src/main/java/com/hinnka/mycamera/lut/RawPreviewShaders.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.hinnka.mycamera.lut - -internal object RawPreviewShaders { - val LINEAR_INPUT_FRAGMENT_SHADER = """ - #version 300 es - #extension GL_OES_EGL_image_external_essl3 : require - precision highp float; - - in vec2 vTexCoord; - out vec4 fragColor; - - uniform samplerExternalOES uCameraTexture; - uniform float uExposureEv; - - vec3 srgbToLinear(vec3 color) { - vec3 clampedColor = max(color, vec3(0.0)); - vec3 low = clampedColor / 12.92; - vec3 high = pow((clampedColor + 0.055) / 1.055, vec3(2.4)); - bvec3 useHigh = greaterThan(clampedColor, vec3(0.04045)); - return vec3( - useHigh.r ? high.r : low.r, - useHigh.g ? high.g : low.g, - useHigh.b ? high.b : low.b - ); - } - - void main() { - vec3 color = texture(uCameraTexture, vTexCoord).rgb; - color = srgbToLinear(color); - color *= exp2(uExposureEv); - fragColor = vec4(color, 1.0); - } - """.trimIndent() -} diff --git a/app/src/main/java/com/hinnka/mycamera/raw/HncsNaturalLightGl.kt b/app/src/main/java/com/hinnka/mycamera/raw/HncsNaturalLightGl.kt deleted file mode 100644 index 6950ce46..00000000 --- a/app/src/main/java/com/hinnka/mycamera/raw/HncsNaturalLightGl.kt +++ /dev/null @@ -1,269 +0,0 @@ -package com.hinnka.mycamera.raw - -import android.content.Context -import android.opengl.GLES30 -import java.nio.ByteBuffer -import java.nio.ByteOrder - -/** - * GL resources shared by the live and bitmap Natural Light preview paths. - * - * A viewfinder/JPEG preview is already in linear sRGB after its input stage, so it cannot - * truthfully enter the camera-domain HNCS color-map branch. Both HNCS selections therefore use - * the HNCS CCM working-space conversion and the selected Phocus FilmCurve here. The camera-domain - * LUT remains exclusive to the RAW renderer, where the sensor matrix, white balance and profile - * metadata are available. - */ -internal class HncsNaturalLightGl(context: Context) { - private val profileManager = HncsProfileManager(context.applicationContext) - private val renderPlans = mutableMapOf() - private var curveTextureId = 0 - private var curveTextureKey: String? = null - - fun bindCombinedResources( - program: Int, - filmCurveMode: HncsFilmCurveMode, - ) { - val renderPlan = renderPlans.getOrPut(filmCurveMode) { - profileManager.createCcmRenderPlan(filmCurveMode) - } - ensureCurveTexture(renderPlan) - - GLES30.glUniform1i( - GLES30.glGetUniformLocation(program, "uHncsColorMapTexture"), - COLOR_MAP_TEXTURE_UNIT, - ) - GLES30.glUniform1i( - GLES30.glGetUniformLocation(program, "uHncsCurveTexture"), - CURVE_TEXTURE_UNIT, - ) - GLES30.glActiveTexture(GLES30.GL_TEXTURE0 + COLOR_MAP_TEXTURE_UNIT) - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, curveTextureId) - GLES30.glActiveTexture(GLES30.GL_TEXTURE0 + CURVE_TEXTURE_UNIT) - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, curveTextureId) - - GLES30.glUniform1i( - GLES30.glGetUniformLocation(program, "uHncsColorMapEnabled"), - 0, - ) - GLES30.glUniform2i( - GLES30.glGetUniformLocation(program, "uHncsColorMapSize"), - 1, - 1, - ) - GLES30.glUniform3f( - GLES30.glGetUniformLocation(program, "uHncsColorMapGrid"), - 0f, - 0f, - 1f, - ) - GLES30.glUniformMatrix3fv( - GLES30.glGetUniformLocation(program, "uHncsRgbToYcc"), - 1, - false, - RawToneMappingGl.transposeMatrix3x3(renderPlan.rgbToYccMatrix), - 0, - ) - GLES30.glUniformMatrix3fv( - GLES30.glGetUniformLocation(program, "uHncsYccToRgb"), - 1, - false, - RawToneMappingGl.transposeMatrix3x3(renderPlan.yccToRgbMatrix), - 0, - ) - GLES30.glUniform2fv( - GLES30.glGetUniformLocation(program, "uHncsGrayThresholds"), - 1, - renderPlan.colorCorrection.grayThresholds, - 0, - ) - GLES30.glUniform4fv( - GLES30.glGetUniformLocation(program, "uHncsLowLightDesaturation"), - 1, - renderPlan.colorCorrection.lowLightDesaturation, - 0, - ) - GLES30.glUniform1f( - GLES30.glGetUniformLocation(program, "uHncsFilmCurveGain"), - renderPlan.filmCurveGain, - ) - GLES30.glUniform1i( - GLES30.glGetUniformLocation(program, "uHncsGammaFilterEnabled"), - if (renderPlan.gamma.filterEnabled) 1 else 0, - ) - GLES30.glUniform1f( - GLES30.glGetUniformLocation(program, "uHncsGamma"), - renderPlan.gamma.gamma, - ) - GLES30.glUniform1f( - GLES30.glGetUniformLocation(program, "uHncsHdrMaxGain"), - renderPlan.gamma.hdrMaxGain, - ) - GLES30.glUniform1f( - GLES30.glGetUniformLocation(program, "uHncsHdrRgbLimit"), - renderPlan.gamma.hdrRgbLimit, - ) - GLES30.glUniform1i( - GLES30.glGetUniformLocation(program, "uHncsDiagnosticStage"), - 0, - ) - } - - fun resetAfterContextLoss() { - curveTextureId = 0 - curveTextureKey = null - } - - fun release() { - if (curveTextureId != 0) { - GLES30.glDeleteTextures(1, intArrayOf(curveTextureId), 0) - curveTextureId = 0 - } - curveTextureKey = null - } - - private fun ensureCurveTexture(renderPlan: HncsRenderPlan) { - val textureKey = - "${renderPlan.filmCurveAssetPath}|${renderPlan.filmCurveAssetSha256}" - if (curveTextureId != 0 && curveTextureKey == textureKey) return - - if (curveTextureId == 0) { - val textures = IntArray(1) - GLES30.glGenTextures(1, textures, 0) - curveTextureId = textures[0] - } - val values = renderPlan.filmCurveTexture - require( - values.size == - HncsProfileManager.CURVE_TEXTURE_EDGE * - HncsProfileManager.CURVE_TEXTURE_EDGE * - RGBA_CHANNEL_COUNT - ) { - "Invalid HNCS FilmCurve texture payload: ${values.size}" - } - val buffer = ByteBuffer.allocateDirect(values.size * Float.SIZE_BYTES) - .order(ByteOrder.nativeOrder()) - .asFloatBuffer() - .apply { - put(values) - position(0) - } - - // Never upload on GL_TEXTURE0: callers keep their per-frame image source there. - GLES30.glActiveTexture(GLES30.GL_TEXTURE0 + CURVE_TEXTURE_UNIT) - GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, curveTextureId) - GLES30.glTexParameteri( - GLES30.GL_TEXTURE_2D, - GLES30.GL_TEXTURE_MIN_FILTER, - GLES30.GL_NEAREST, - ) - GLES30.glTexParameteri( - GLES30.GL_TEXTURE_2D, - GLES30.GL_TEXTURE_MAG_FILTER, - GLES30.GL_NEAREST, - ) - GLES30.glTexParameteri( - GLES30.GL_TEXTURE_2D, - GLES30.GL_TEXTURE_WRAP_S, - GLES30.GL_CLAMP_TO_EDGE, - ) - GLES30.glTexParameteri( - GLES30.GL_TEXTURE_2D, - GLES30.GL_TEXTURE_WRAP_T, - GLES30.GL_CLAMP_TO_EDGE, - ) - GLES30.glTexImage2D( - GLES30.GL_TEXTURE_2D, - 0, - GLES30.GL_RGBA16F, - HncsProfileManager.CURVE_TEXTURE_EDGE, - HncsProfileManager.CURVE_TEXTURE_EDGE, - 0, - GLES30.GL_RGBA, - GLES30.GL_FLOAT, - buffer, - ) - curveTextureKey = textureKey - } - - private companion object { - const val COLOR_MAP_TEXTURE_UNIT = 2 - const val CURVE_TEXTURE_UNIT = 3 - const val RGBA_CHANNEL_COUNT = 4 - } -} - -/** - * Fused equivalent of the RAW HNCS output-linear and sRGB passes for preview-sized images. - * - * Keeping this as one pass avoids another full-resolution RGBA16F viewfinder buffer while - * preserving the same Gamma 2.2 decode, HNCS-to-output matrix and sRGB display encoding. - */ -internal object HncsNaturalLightOutputPassShaders { - val FRAGMENT_SHADER = """ - #version 300 es - precision highp float; - - in vec2 vTexCoord; - out vec4 fragColor; - - uniform sampler2D uInputTexture; - uniform mat3 uHncsToLinearOutput; - uniform float uBlacks; - uniform float uWhites; - - const vec3 BW_LUMA = vec3(0.2126, 0.7152, 0.0722); - const float BW_EPSILON = 0.000001; - - vec3 gamma22Eotf(vec3 value) { - return pow(max(value, vec3(0.0)), vec3(2.2)); - } - - float blackInputLevel(float blacks) { - float value = clamp(blacks, -1.0, 1.0); - return value < 0.0 ? -value * 0.18 : -value * 0.12; - } - - float whiteInputLevel(float whites) { - float value = clamp(whites, -1.0, 1.0); - return value > 0.0 ? mix(1.0, 0.72, value) : mix(1.0, 1.55, -value); - } - - vec3 applyBlackWhiteLevels(vec3 color) { - float blacks = clamp(uBlacks, -1.0, 1.0); - float whites = clamp(uWhites, -1.0, 1.0); - if (abs(blacks) < 0.001 && abs(whites) < 0.001) { - return color; - } - float blackLevel = blackInputLevel(blacks); - float whiteLevel = max(whiteInputLevel(whites), blackLevel + 0.05); - vec3 positiveColor = max(color, vec3(0.0)); - float luma = dot(positiveColor, BW_LUMA); - float adjustedLuma = - max((luma - blackLevel) / max(whiteLevel - blackLevel, BW_EPSILON), 0.0); - if (luma <= BW_EPSILON) { - return vec3(adjustedLuma); - } - return color * (adjustedLuma / luma); - } - - vec3 linearToSrgb(vec3 color) { - vec3 clampedColor = max(color, vec3(0.0)); - vec3 low = clampedColor * 12.92; - vec3 high = 1.055 * pow(clampedColor, vec3(1.0 / 2.4)) - 0.055; - bvec3 useHigh = greaterThan(clampedColor, vec3(0.0031308)); - return vec3( - useHigh.r ? high.r : low.r, - useHigh.g ? high.g : low.g, - useHigh.b ? high.b : low.b - ); - } - - void main() { - vec4 sampleValue = texture(uInputTexture, vTexCoord); - vec3 linearOutput = uHncsToLinearOutput * gamma22Eotf(sampleValue.rgb); - linearOutput = applyBlackWhiteLevels(linearOutput); - fragColor = vec4(linearToSrgb(linearOutput), sampleValue.a); - } - """.trimIndent() -} diff --git a/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraGLSurfaceView.kt b/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraGLSurfaceView.kt index a78fe256..1ef2fe52 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraGLSurfaceView.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraGLSurfaceView.kt @@ -16,9 +16,6 @@ import com.hinnka.mycamera.preview.EyeFocusProcessingTiming import com.hinnka.mycamera.lut.PreviewCaptureSource import com.hinnka.mycamera.model.ColorRecipeParams import com.hinnka.mycamera.model.ColorPaletteMapper -import com.hinnka.mycamera.raw.HncsFilmCurveMode -import com.hinnka.mycamera.raw.RawRenderingEngine -import com.hinnka.mycamera.raw.RawToneMappingParameters import com.hinnka.mycamera.screencapture.PhantomPipCrop import com.hinnka.mycamera.utils.PLog import com.hinnka.mycamera.video.VideoLogProfile @@ -206,29 +203,6 @@ class CameraGLSurfaceView @JvmOverloads constructor( requestRender() } - fun setRawPreviewSettings( - enabled: Boolean, - exposureCompensation: Float, - blackPointCorrection: Float, - whitePointCorrection: Float, - renderingEngine: RawRenderingEngine, - hncsFilmCurveMode: HncsFilmCurveMode, - toneMappingParameters: RawToneMappingParameters - ) { - queueEvent { - renderer.setRawPreviewSettings( - enabled = enabled, - exposureCompensation = exposureCompensation, - blackPointCorrection = blackPointCorrection, - whitePointCorrection = whitePointCorrection, - renderingEngine = renderingEngine, - hncsFilmCurveMode = hncsFilmCurveMode, - toneMappingParameters = toneMappingParameters - ) - requestRender() - } - } - fun setAutoFocus(auto: Boolean) { renderer.isAutoFocus = auto requestRender() diff --git a/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraPreviewGL.kt b/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraPreviewGL.kt index 176ebea5..f0fb2a41 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraPreviewGL.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraPreviewGL.kt @@ -24,9 +24,6 @@ import com.hinnka.mycamera.camera.MeteringMode import com.hinnka.mycamera.lut.LutConfig import com.hinnka.mycamera.model.ColorRecipeParams import com.hinnka.mycamera.preview.EyeFocusPreviewFrame -import com.hinnka.mycamera.raw.HncsFilmCurveMode -import com.hinnka.mycamera.raw.RawRenderingEngine -import com.hinnka.mycamera.raw.RawToneMappingParameters import com.hinnka.mycamera.ui.components.FocusIndicator import com.hinnka.mycamera.utils.OrientationObserver import com.hinnka.mycamera.video.CaptureMode @@ -68,13 +65,6 @@ fun CameraPreviewGL( livePhotoRecorder: LivePhotoRecorder? = null, videoLogProfile: VideoLogProfile = VideoLogProfile.OFF, isHlgInput: Boolean = false, - naturalLightEnabled: Boolean = false, - rawExposureCompensation: Float = 0f, - rawBlackPointCorrection: Float = 0f, - rawWhitePointCorrection: Float = 0f, - rawRenderingEngine: RawRenderingEngine = RawRenderingEngine.AdobeCurve, - rawHncsFilmCurveMode: HncsFilmCurveMode = HncsFilmCurveMode.Standard, - rawToneMappingParameters: RawToneMappingParameters = RawToneMappingParameters.DEFAULT, isEyeFocusBusy: Boolean = false, onGLSurfaceViewReady: ((CameraGLSurfaceView) -> Unit)? = null, isAutoFocus: Boolean = true, @@ -283,15 +273,6 @@ fun CameraPreviewGL( glSurfaceView.setLivePhotoRecorder(livePhotoRecorder) glSurfaceView.setVideoLogProfile(videoLogProfile) glSurfaceView.setIsHlgInput(isHlgInput) - glSurfaceView.setRawPreviewSettings( - enabled = naturalLightEnabled, - exposureCompensation = rawExposureCompensation, - blackPointCorrection = rawBlackPointCorrection, - whitePointCorrection = rawWhitePointCorrection, - renderingEngine = rawRenderingEngine, - hncsFilmCurveMode = rawHncsFilmCurveMode, - toneMappingParameters = rawToneMappingParameters - ) glSurfaceView.setAutoFocus(isAutoFocus) glSurfaceView.setFocusPeakingEnabled(focusPeakingEnabled) glSurfaceView.setEyeFocusBusy(isEyeFocusBusy) diff --git a/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraScreen.kt b/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraScreen.kt index a6f07b1f..0a8a4883 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraScreen.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraScreen.kt @@ -258,11 +258,9 @@ fun CameraScreen( val droMode by viewModel.droMode.collectAsState() val rawColorEngine by viewModel.rawRenderingEngine.collectAsState() val rawToneMappingParameters by viewModel.rawToneMappingParameters.collectAsState() - val naturalLightEnabled by viewModel.naturalLightEnabled.collectAsState() val availableHncsProfiles = remember(context) { HncsProfileManager(context.applicationContext).getAvailableProfiles() } - val naturalLightWarningShown by viewModel.naturalLightWarningShown.collectAsState() val rawSpectralFilmStock by viewModel.rawSpectralFilmStock.collectAsState() val rawSpectralFilmSelection by viewModel.rawSpectralFilmSelection.collectAsState() val rawSpectralFilmPrint by viewModel.rawSpectralFilmPrint.collectAsState() @@ -1162,13 +1160,6 @@ fun CameraScreen( livePhotoRecorder = viewModel.livePhotoRecorder, videoLogProfile = state.videoConfig.logProfile, isHlgInput = if (hlgHardwareCompatibilityEnabled) state.isHLG else false, - naturalLightEnabled = naturalLightEnabled, - rawExposureCompensation = rawExposureCompensation, - rawBlackPointCorrection = rawBlackPointCorrection, - rawWhitePointCorrection = rawWhitePointCorrection, - rawRenderingEngine = rawColorEngine, - rawHncsFilmCurveMode = rawHncsFilmCurveMode, - rawToneMappingParameters = rawToneMappingParameters, isEyeFocusBusy = viewModel.isEyeFocusBusy, isAutoFocus = state.isAutoFocus, focusPeakingEnabled = focusPeakingEnabled && !state.isHyperfocalFocusEnabled, @@ -1430,7 +1421,6 @@ fun CameraScreen( galleryViewModel = galleryViewModel, latestPhoto = latestPhoto, useMultipleExposure = useMultipleExposure, - naturalLightEnabled = naturalLightEnabled, multipleExposureState = multipleExposureState, onGalleryThumbnailBoundsChanged = { bounds -> galleryThumbnailBounds = bounds @@ -1598,14 +1588,6 @@ fun CameraScreen( useRaw = useRaw && state.isRawSupported, onRawToggle = { viewModel.setUseRaw(it) }, isRawSupported = state.isRawSupported, - useNaturalLight = naturalLightEnabled, - naturalLightWarningShown = naturalLightWarningShown, - onNaturalLightToggle = { - runPreviewTransition { - viewModel.setNaturalLightToneMapEnabled(it) - } - }, - onNaturalLightWarningShown = { viewModel.setNaturalLightWarningShown(true) }, rawDcpId = rawDcpId, rawDcpIdsByLens = rawDcpIdsByLens, rawDcpLensOptions = rawDcpLensOptions(state.availableCameras), @@ -1950,7 +1932,6 @@ fun Controls( galleryViewModel: GalleryViewModel, latestPhoto: com.hinnka.mycamera.gallery.MediaData?, useMultipleExposure: Boolean, - naturalLightEnabled: Boolean, multipleExposureState: com.hinnka.mycamera.viewmodel.MultipleExposureSessionState, onGalleryThumbnailBoundsChanged: (Rect) -> Unit, onSwitchCameraClick: () -> Unit, @@ -2000,8 +1981,7 @@ fun Controls( isVideoRecording = state.videoRecordingState.isRecording, isVideoProcessing = state.videoRecordingState.isProcessing, isPaused = state.videoRecordingState.isPaused, - allowLongPress = !naturalLightEnabled && - state.captureMode == CaptureMode.PHOTO && + allowLongPress = state.captureMode == CaptureMode.PHOTO && !useMultipleExposure, multipleExposureEnabled = useMultipleExposure && state.captureMode == CaptureMode.PHOTO, multipleExposureProgress = multipleExposureState.capturedCount.toFloat() / diff --git a/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraTopSheet.kt b/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraTopSheet.kt index b247f1e1..bccc44a3 100644 --- a/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraTopSheet.kt +++ b/app/src/main/java/com/hinnka/mycamera/ui/camera/CameraTopSheet.kt @@ -118,10 +118,6 @@ fun CameraTopSheet( useRaw: Boolean, onRawToggle: (Boolean) -> Unit, isRawSupported: Boolean, - useNaturalLight: Boolean, - naturalLightWarningShown: Boolean, - onNaturalLightToggle: (Boolean) -> Unit, - onNaturalLightWarningShown: () -> Unit, rawDcpId: String?, rawDcpIdsByLens: Map = emptyMap(), rawDcpLensOptions: List = emptyList(), @@ -175,53 +171,16 @@ fun CameraTopSheet( ) { var expandedVideoPanel by rememberSaveable { mutableStateOf(null) } var showRawSheet by rememberSaveable { mutableStateOf(false) } - var showNaturalLightWarning by rememberSaveable { mutableStateOf(false) } var showContentManagementOptions by rememberSaveable { mutableStateOf(false) } fun handleContentManagementAction(action: () -> Unit) { showContentManagementOptions = false action() } - fun handleNaturalLightToggle(enabled: Boolean) { - if (enabled && !useNaturalLight && !naturalLightWarningShown) { - showNaturalLightWarning = true - } else { - onNaturalLightToggle(enabled) - } - } - LaunchedEffect(visible, captureMode) { showContentManagementOptions = false } - if (showNaturalLightWarning) { - AlertDialog( - onDismissRequest = { showNaturalLightWarning = false }, - title = { - Text(text = stringResource(R.string.natural_light_warning_title)) - }, - text = { - Text(text = stringResource(R.string.natural_light_warning_message)) - }, - confirmButton = { - TextButton( - onClick = { - showNaturalLightWarning = false - onNaturalLightWarningShown() - onNaturalLightToggle(true) - } - ) { - Text(text = stringResource(R.string.natural_light_warning_confirm)) - } - }, - dismissButton = { - TextButton(onClick = { showNaturalLightWarning = false }) { - Text(text = stringResource(R.string.cancel)) - } - } - ) - } - AnimatedVisibility( visible = visible, enter = slideInVertically(initialOffsetY = { -it }) + fadeIn(), @@ -305,18 +264,6 @@ fun CameraTopSheet( onClick = { showRawSheet = true }, modifier = Modifier.weight(1f) ) - - NaturalLightQuickSetting( - checked = useNaturalLight, - onCheckedChange = ::handleNaturalLightToggle, - modifier = Modifier.weight(1f) - ) - } else { - NaturalLightQuickSetting( - checked = useNaturalLight, - onCheckedChange = ::handleNaturalLightToggle, - modifier = Modifier.weight(1f) - ) } QuickSettingToggle( @@ -883,20 +830,6 @@ private fun SectionLabel(title: String) { ) } -@Composable -private fun NaturalLightQuickSetting( - checked: Boolean, - onCheckedChange: (Boolean) -> Unit, - modifier: Modifier = Modifier -) { - QuickSettingToggle( - title = stringResource(R.string.settings_tonemap_mode_natural_light), - checked = checked, - onCheckedChange = onCheckedChange, - modifier = modifier - ) -} - @Composable private fun MeteringModeQuickSetting( meteringMode: MeteringMode, diff --git a/app/src/main/java/com/hinnka/mycamera/viewmodel/CameraViewModel.kt b/app/src/main/java/com/hinnka/mycamera/viewmodel/CameraViewModel.kt index 0a3919d2..83382f6a 100644 --- a/app/src/main/java/com/hinnka/mycamera/viewmodel/CameraViewModel.kt +++ b/app/src/main/java/com/hinnka/mycamera/viewmodel/CameraViewModel.kt @@ -34,7 +34,6 @@ import com.hinnka.mycamera.frame.FramePreviewFactory import com.hinnka.mycamera.gallery.GalleryManager import com.hinnka.mycamera.gallery.MediaMetadata import com.hinnka.mycamera.gallery.PhotoSavePath -import com.hinnka.mycamera.gallery.TONEMAP_MODE_NATURAL_LIGHT import com.hinnka.mycamera.lut.BaselineColorCorrectionTarget import com.hinnka.mycamera.lut.BakedLutExporter import com.hinnka.mycamera.lut.LutConfig @@ -148,11 +147,7 @@ private fun sanitizeViewModelTonemapMode(mode: String): String { } private fun resolvePreviewBaselineTarget(prefs: UserPreferences): BaselineColorCorrectionTarget? { - return when { - prefs.useRaw && prefs.naturalLightEnabled -> BaselineColorCorrectionTarget.RAW - prefs.useRaw -> null - else -> BaselineColorCorrectionTarget.JPG - } + return if (prefs.useRaw) null else BaselineColorCorrectionTarget.JPG } private fun UserPreferences.getBaselineLutId(target: BaselineColorCorrectionTarget): String? { @@ -1069,10 +1064,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application) } } - private fun shouldDisableNaturalLightForJpgMax(prefs: UserPreferences): Boolean { - return prefs.useJpgMax - } - private fun resolveCaptureRawRenderingEngine(userPrefs: UserPreferences?): RawRenderingEngine { return userPrefs?.rawRenderingEngine ?: RawRenderingEngine.AdobeCurve } @@ -1085,50 +1076,11 @@ class CameraViewModel(application: Application) : AndroidViewModel(application) } private fun effectiveCameraTonemapMode(prefs: UserPreferences): String { - return if (prefs.naturalLightEnabled) { - TONEMAP_MODE_SRGB - } else { - sanitizeViewModelTonemapMode(prefs.tonemapMode) - } + return sanitizeViewModelTonemapMode(prefs.tonemapMode) } private fun metadataTonemapMode(prefs: UserPreferences?): String { - return if (prefs?.naturalLightEnabled == true) { - TONEMAP_MODE_NATURAL_LIGHT - } else { - sanitizeViewModelTonemapMode(prefs?.tonemapMode ?: TONEMAP_MODE_SYSTEM_DEFAULT) - } - } - - private suspend fun saveNaturalLightEnabledWithCameraReopen( - enabled: Boolean, - prefs: UserPreferences? = null - ) { - val currentPrefs = prefs ?: userPreferencesRepository.userPreferences.first() - if (currentPrefs.naturalLightEnabled == enabled) return - - val previousTonemapMode = effectiveCameraTonemapMode(currentPrefs) - val nextPrefs = currentPrefs.copy(naturalLightEnabled = enabled) - val nextTonemapMode = effectiveCameraTonemapMode(nextPrefs) - - userPreferencesRepository.saveNaturalLightEnabled(enabled) - if (previousTonemapMode != nextTonemapMode) { - cameraController.setTonemapMode(nextTonemapMode) - } - PLog.d( - TAG, - "Reopening camera for Natural Light change: enabled=$enabled, " + - "tonemap=$previousTonemapMode->$nextTonemapMode" - ) - reopenCamera() - } - - private suspend fun disableNaturalLightIfNeeded(reason: String, prefs: UserPreferences? = null) { - val currentPrefs = prefs ?: userPreferencesRepository.userPreferences.first() - if (currentPrefs.naturalLightEnabled) { - PLog.d(TAG, "Disabling Natural Light tone map: $reason") - saveNaturalLightEnabledWithCameraReopen(false, currentPrefs) - } + return sanitizeViewModelTonemapMode(prefs?.tonemapMode ?: TONEMAP_MODE_SYSTEM_DEFAULT) } fun savePreset(preset: com.hinnka.mycamera.model.CameraPreset) { @@ -1738,12 +1690,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application) val tonemapMode: StateFlow = userPreferencesRepository.userPreferences .map { it.tonemapMode } .stateIn(viewModelScope, SharingStarted.Eagerly, "SYSTEM_DEFAULT") - val naturalLightEnabled: StateFlow = userPreferencesRepository.userPreferences - .map { it.naturalLightEnabled } - .stateIn(viewModelScope, SharingStarted.Eagerly, false) - val naturalLightWarningShown: StateFlow = userPreferencesRepository.userPreferences - .map { it.naturalLightWarningShown } - .stateIn(viewModelScope, SharingStarted.Eagerly, false) val fixTonemapPreview: StateFlow = userPreferencesRepository.userPreferences .map { it.fixTonemapPreview } .stateIn(viewModelScope, SharingStarted.Eagerly, false) @@ -2175,16 +2121,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application) userPreferencesRepository.saveRawColorEngine(effectiveRawRenderingEngine) } } - if (it.naturalLightEnabled && - (multipleExposureEnabled || shouldDisableNaturalLightForJpgMax(it)) - ) { - viewModelScope.launch { - disableNaturalLightIfNeeded( - reason = "conflicting persisted camera feature state", - prefs = it - ) - } - } if (currentCameraState.useMultipleExposure != multipleExposureEnabled) { cameraController.setUseMultipleExposure(multipleExposureEnabled) } @@ -3162,9 +3098,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application) fun setUseMultipleExposure(enabled: Boolean) { viewModelScope.launch { - if (enabled) { - disableNaturalLightIfNeeded("multiple exposure enabled") - } applyCameraFeatureUpdate( CameraFeatureUpdate(useMultipleExposure = SettingValue(enabled)) ) @@ -3451,10 +3384,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application) * 开始连拍 */ fun startContinuousCapture() { - if (naturalLightEnabled.value) { - PLog.d(TAG, "Continuous photo burst disabled while Natural Light tone map is active") - return - } if (state.value.useRaw && state.value.isRawSupported) return generateThumbnail() burstImages.clear() @@ -4581,13 +4510,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application) /** JPGmax:YUV 多帧降噪。 */ fun setUseJpgMax(enabled: Boolean) { viewModelScope.launch { - if (enabled) { - val prefs = userPreferencesRepository.userPreferences.first() - disableNaturalLightIfNeeded( - reason = "JPGmax enabled", - prefs = prefs, - ) - } applyCameraFeatureUpdate( CameraFeatureUpdate(useJpgMax = SettingValue(enabled)) ) @@ -6227,14 +6149,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application) captureMode = captureMode, multipleExposureFrameCount = expectedFrameCount, baselineTarget = BaselineColorCorrectionTarget.JPG, - ).let { hdrMetadata -> - if (hdrMetadata.usesNaturalLightToneMap()) { - PLog.d(TAG, "YUV HDR bracket stores SYSTEM_DEFAULT tonemap metadata") - hdrMetadata.copy(tonemapMode = "SYSTEM_DEFAULT") - } else { - hdrMetadata - } - } + ) val photoId = GalleryManager.preparePhoto( context, @@ -6725,40 +6640,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application) } } - fun setNaturalLightToneMapEnabled(enabled: Boolean) { - viewModelScope.launch { - if (enabled) { - val prefs = userPreferencesRepository.userPreferences.first() - val shouldDisableMultipleExposure = prefs.useMultipleExposure - val shouldDisableJpgMax = shouldDisableNaturalLightForJpgMax(prefs) - - if (shouldDisableMultipleExposure || shouldDisableJpgMax) { - applyCameraFeatureUpdate( - CameraFeatureUpdate( - useMultipleExposure = if (shouldDisableMultipleExposure) { - SettingValue(false) - } else { - null - }, - useJpgMax = if (shouldDisableJpgMax) { - SettingValue(false) - } else { - null - } - ) - ) - } - } - saveNaturalLightEnabledWithCameraReopen(enabled) - } - } - - fun setNaturalLightWarningShown(shown: Boolean) { - viewModelScope.launch { - userPreferencesRepository.saveNaturalLightWarningShown(shown) - } - } - fun setFixTonemapPreview(enabled: Boolean) { viewModelScope.launch { userPreferencesRepository.saveFixTonemapPreview(enabled) diff --git a/app/src/main/res/values-b+zh+Hant/strings.xml b/app/src/main/res/values-b+zh+Hant/strings.xml index 6a60e931..206916ce 100644 --- a/app/src/main/res/values-b+zh+Hant/strings.xml +++ b/app/src/main/res/values-b+zh+Hant/strings.xml @@ -386,10 +386,6 @@ 調整硬體色調映射(對比度/伽馬)模式 系統預設 sRGB - 自然光影 - 開啟自然光影 - 自然光影會修改系統色調映射路徑,讓預覽和拍攝使用更接近線性輸入的色彩處理。部分設備的 Camera2 實現可能因此出現預覽偏色、亮度異常,或拍攝結果異常。如果遇到問題,請到“設定 > 色彩與 HDR”按需開啟預覽或拍攝的色調映射修復。 - 繼續開啟 修復色調映射預覽異常 部分設備預覽已自帶 sRGB Gamma。開啟后僅在預覽中先轉為線性再應用自訂色調曲線,拍攝輸出不變。 修復色調映射拍攝異常 diff --git a/app/src/main/res/values-th/strings.xml b/app/src/main/res/values-th/strings.xml index 72397119..a1edd138 100644 --- a/app/src/main/res/values-th/strings.xml +++ b/app/src/main/res/values-th/strings.xml @@ -254,10 +254,6 @@ ปรับโหมดการจับคู่โทนสีฮาร์ดแวร์ (คอนทราสต์/แกมมา) ค่าเริ่มต้นของระบบ sRGB - แสงเงาธรรมชาติ - เปิดแสงเงาธรรมชาติ - แสงเงาธรรมชาติจะเปลี่ยนเส้นทางการทำแผนที่โทนของระบบ เพื่อให้ภาพตัวอย่างและภาพถ่ายใช้การประมวลผลสีที่ใกล้เคียงอินพุตเชิงเส้นมากขึ้น การใช้งาน Camera2 ของอุปกรณ์บางรุ่นอาจทำให้สีตัวอย่างผิดปกติ ความสว่างผิดปกติ หรือภาพถ่ายผิดปกติ หากพบปัญหา ให้ไปที่ ตั้งค่า > สีและ HDR แล้วเปิดการแก้ไขการทำแผนที่โทนสำหรับภาพตัวอย่างหรือการถ่ายภาพตามที่จำเป็น - ดำเนินการต่อ แก้ไขข้อยกเว้นการแสดงตัวอย่างการแมปโทน ตัวอย่างอุปกรณ์บางรุ่นมาพร้อมกับ sRGB Gamma อยู่แล้ว หลังจากเปิดใช้งาน กล้องจะแปลงเป็นเส้นตรงในหน้าตัวอย่างเท่านั้น จากนั้นจึงใช้ Tone Curve แบบกำหนดเอง และเอาต์พุตการถ่ายภาพยังคงไม่เปลี่ยนแปลง แก้ไขข้อยกเว้นการถ่ายภาพการแมปโทน diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 331427e8..6947a220 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -404,10 +404,6 @@ 调整硬件色调映射(对比度/伽马)模式 系统默认 sRGB - 自然光影 - 开启自然光影 - 自然光影会修改系统色调映射路径,让预览和拍摄使用更接近线性输入的色彩处理。部分设备的 Camera2 实现可能因此出现预览偏色、亮度异常,或拍摄结果异常。如果遇到问题,请到“设置 > 色彩与 HDR”按需开启预览或拍摄的色调映射修复。 - 继续开启 修复色调映射预览异常 部分设备预览已自带 sRGB Gamma。开启后仅在预览中先转为线性再应用自定义色调曲线,拍摄输出不变。 修复色调映射拍摄异常 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index b436b1ab..e51a9246 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -386,10 +386,6 @@ 調整硬體色調映射(對比度/伽馬)模式 系統預設 sRGB - 自然光影 - 開啟自然光影 - 自然光影會修改系統色調映射路徑,讓預覽和拍攝使用更接近線性輸入的色彩處理。部分設備的 Camera2 實現可能因此出現預覽偏色、亮度異常,或拍攝結果異常。如果遇到問題,請到“設定 > 色彩與 HDR”按需開啟預覽或拍攝的色調映射修復。 - 繼續開啟 修復色調映射預覽異常 部分設備預覽已自帶 sRGB Gamma。開啟后僅在預覽中先轉為線性再應用自訂色調曲線,拍攝輸出不變。 修復色調映射拍攝異常 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index c6d5472f..149d7a12 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -386,10 +386,6 @@ 調整硬體色調映射(對比度/伽馬)模式 系統預設 sRGB - 自然光影 - 開啟自然光影 - 自然光影會修改系統色調映射路徑,讓預覽和拍攝使用更接近線性輸入的色彩處理。部分設備的 Camera2 實現可能因此出現預覽偏色、亮度異常,或拍攝結果異常。如果遇到問題,請到“設定 > 色彩與 HDR”按需開啟預覽或拍攝的色調映射修復。 - 繼續開啟 修復色調映射預覽異常 部分設備預覽已自帶 sRGB Gamma。開啟后僅在預覽中先轉為線性再應用自訂色調曲線,拍攝輸出不變。 修復色調映射拍攝異常 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6b538b1a..50bee0c2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -408,10 +408,6 @@ Adjust the hardware tone mapping (contrast/gamma) mode System Default sRGB - Natural Light - Enable Natural Light - Natural Light changes the system tone mapping path so preview and capture can use a more linear color pipeline. Some Camera2 implementations may show abnormal preview color, incorrect brightness, or abnormal captured images. If this happens, open Settings > Color and HDR and enable the preview or capture tone mapping fix as needed. - Continue Fix tone mapping preview Linearize preview input before applying custom tone curves on devices whose preview already includes sRGB gamma. Capture output is unchanged. Fix tone mapping capture diff --git a/app/src/test/java/com/hinnka/mycamera/raw/RawHncsShadersTest.kt b/app/src/test/java/com/hinnka/mycamera/raw/RawHncsShadersTest.kt index 9982becd..3d816f0e 100644 --- a/app/src/test/java/com/hinnka/mycamera/raw/RawHncsShadersTest.kt +++ b/app/src/test/java/com/hinnka/mycamera/raw/RawHncsShadersTest.kt @@ -42,20 +42,7 @@ class RawHncsShadersTest { } @Test - fun naturalLightHncsOutputDecodesThenTransformsThenEncodes() { - val shader = HncsNaturalLightOutputPassShaders.FRAGMENT_SHADER - val decode = shader.indexOf("gamma22Eotf(sampleValue.rgb)") - val transform = shader.indexOf("uHncsToLinearOutput * gamma22Eotf") - val displayEncode = shader.indexOf("linearToSrgb(linearOutput)") - - assertTrue(transform >= 0) - assertTrue(decode in transform until displayEncode) - assertTrue(displayEncode > transform) - assertTrue(shader.contains("linearOutput = applyBlackWhiteLevels(linearOutput);")) - } - - @Test - fun naturalLightStandardOutputEncodesLinearRgbExactlyOnce() { + fun rawSrgbOutputEncodesLinearRgbExactlyOnce() { val shader = RawSrgbPass.FRAGMENT_SHADER assertTrue(shader.contains("vec3 color = texture(uInputTexture, vTexCoord).rgb;")) @@ -91,7 +78,6 @@ class RawHncsShadersTest { colorEngine = RawRenderingEngine.HncsLut, includeShadowsHighlights = true, ), - HncsNaturalLightOutputPassShaders.FRAGMENT_SHADER, RawSrgbPass.FRAGMENT_SHADER, ) shaders.forEachIndexed { index, shader -> diff --git a/docs/hncs-rendering-engine.md b/docs/hncs-rendering-engine.md index 85f54015..b318b671 100644 --- a/docs/hncs-rendering-engine.md +++ b/docs/hncs-rendering-engine.md @@ -401,12 +401,6 @@ Hasselblad/LStar Gamma 分支,不能仅凭相机品牌或 UI 选项推断。 没有 LUT→CCM、HNCS→Adobe Curve、首 profile 或默认 5000 K 回退。 -这里的约束针对 RAW 渲染计划。自然光影取景器/系统 JPEG 预览已经进入 sRGB 域,不再持有 -执行相机二维 LUT 所需的 RAW camera matrix、as-shot gains 与实测 CCT;这条预览链路只显示 -两个 HNCS 选择共有的 sRGB→HNCS CCM→FilmCurve tone rendering,再完成 HNCS companding -解码与 sRGB 输出。它不会把某个相机 profile 的二维 LUT 套到 sRGB 图像,也不改变最终 RAW -仍按所选 HNCS LUT 计划渲染的行为。 - ## 相机域截断与 headroom 原始 `ColorCorrectAll` shader 在输入矩阵前执行: