feat: add configurable RAW super resolution scale and remove CPU stacking paths
This commit is contained in:
1 parent
4c0d2f8963
commit
a4a9417f7d
9 files changed
+131
-255
No files matched your search
@@ -34,6 +34,17 @@ constexpr bool kFastPath = false;
|
||||
|
||||
using PerfClock = std::chrono::steady_clock;
|
||||
|
||||
namespace {
|
||||
|
||||
uint32_t rawSuperResOutputSize(uint32_t inputSize, float scale) {
|
||||
uint32_t value =
|
||||
static_cast<uint32_t>(std::max(1L, std::lround(inputSize * scale * 0.5f))) *
|
||||
2u;
|
||||
return std::max(value, 2u);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
inline double elapsedMillis(PerfClock::time_point start,
|
||||
PerfClock::time_point end) {
|
||||
return std::chrono::duration<double, std::milli>(end - start).count();
|
||||
@@ -186,8 +197,8 @@ VulkanRawStacker::VulkanRawStacker(uint32_t w, uint32_t h, bool enableSuperRes,
|
||||
}
|
||||
|
||||
if (mEnableSuperRes) {
|
||||
uint32_t outW = (uint32_t)std::lround(width * mSuperResScale);
|
||||
uint32_t outH = (uint32_t)std::lround(height * mSuperResScale);
|
||||
uint32_t outW = rawSuperResOutputSize(width, mSuperResScale);
|
||||
uint32_t outH = rawSuperResOutputSize(height, mSuperResScale);
|
||||
const uint32_t MAX_TILE_SIZE = 4096;
|
||||
numTilesX = (outW + MAX_TILE_SIZE - 1) / MAX_TILE_SIZE;
|
||||
numTilesY = (outH + MAX_TILE_SIZE - 1) / MAX_TILE_SIZE;
|
||||
@@ -218,8 +229,8 @@ void VulkanRawStacker::initVulkanResources() {
|
||||
}
|
||||
|
||||
float scale = mEnableSuperRes ? mSuperResScale : 1.0f;
|
||||
uint32_t outW = (uint32_t)std::lround(width * scale);
|
||||
uint32_t outH = (uint32_t)std::lround(height * scale);
|
||||
uint32_t outW = rawSuperResOutputSize(width, scale);
|
||||
uint32_t outH = rawSuperResOutputSize(height, scale);
|
||||
|
||||
uint32_t planeW = outW;
|
||||
uint32_t planeH = outH;
|
||||
@@ -2659,8 +2670,8 @@ bool VulkanRawStacker::processStack(uint16_t *outBuffer, size_t bufferSize) {
|
||||
}
|
||||
|
||||
float scale = mEnableSuperRes ? mSuperResScale : 1.0f;
|
||||
uint32_t outputW = (uint32_t)std::lround(width * scale);
|
||||
uint32_t outputH = (uint32_t)std::lround(height * scale);
|
||||
uint32_t outputW = rawSuperResOutputSize(width, scale);
|
||||
uint32_t outputH = rawSuperResOutputSize(height, scale);
|
||||
uint32_t inputW = width / 2;
|
||||
uint32_t inputH = height / 2;
|
||||
uint32_t localTilesX = (inputW + 15) / 16;
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.hinnka.mycamera.raw.RawProfile
|
||||
import com.hinnka.mycamera.screencapture.PhantomPipCrop
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import com.hinnka.mycamera.utils.DeviceUtil
|
||||
import com.hinnka.mycamera.video.CaptureMode
|
||||
import com.hinnka.mycamera.video.VideoAspectRatio
|
||||
import com.hinnka.mycamera.video.VIDEO_AUDIO_INPUT_AUTO
|
||||
@@ -115,12 +114,11 @@ data class UserPreferences(
|
||||
val useMultipleExposure: Boolean = false, // 是否启用多重曝光
|
||||
val multipleExposureCount: Int = 2, // 多重曝光张数
|
||||
val useMFSR: Boolean = false, // 是否启用 RAW 多帧超分
|
||||
val superResolutionScale: Float = 1.5f, // RAW 多帧超分倍率
|
||||
val superResolutionScale: Float = 1.2f, // RAW 多帧超分倍率
|
||||
val photoQuality: Int = 95, // 照片质量: 90, 95, 100
|
||||
val useLivePhoto: Boolean = false, // 是否启用 Live Photo (Motion Photo)
|
||||
val enableDevelopAnimation: Boolean = false, // 是否启用拍摄后的显影动画
|
||||
val backgroundImage: String = "camera_bg", // 背景图资源名或文件路径
|
||||
val useGpuAcceleration: Boolean = DeviceUtil.defaultGpuAcceleration, // 多帧合成是否使用 GPU 加速
|
||||
val droMode: String = "OFF", // DRO 模式
|
||||
val applyUltraHDR: Boolean = false, // 是否应用 Ultra HDR 策略
|
||||
val colorSpace: ColorSpace = ColorSpace.SRGB,
|
||||
@@ -232,7 +230,6 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
private val USE_LIVE_PHOTO = booleanPreferencesKey("use_live_photo")
|
||||
private val ENABLE_DEVELOP_ANIMATION = booleanPreferencesKey("enable_develop_animation")
|
||||
private val BACKGROUND_IMAGE = stringPreferencesKey("background_image")
|
||||
private val USE_GPU_ACCELERATION = booleanPreferencesKey("use_gpu_acceleration")
|
||||
private val DRO_MODE = stringPreferencesKey("dro_mode")
|
||||
private val APPLY_ULTRA_HDR = booleanPreferencesKey("apply_ultra_hdr")
|
||||
private val COLOR_SPACE = stringPreferencesKey("color_space")
|
||||
@@ -348,12 +345,11 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
useMultipleExposure = preferences[USE_MULTIPLE_EXPOSURE] ?: false,
|
||||
multipleExposureCount = preferences[MULTIPLE_EXPOSURE_COUNT] ?: 2,
|
||||
useMFSR = preferences[USE_SUPER_RESOLUTION] ?: false,
|
||||
superResolutionScale = preferences[RAW_SUPER_RESOLUTION_SCALE] ?: 1.5f,
|
||||
superResolutionScale = preferences[RAW_SUPER_RESOLUTION_SCALE] ?: 1.2f,
|
||||
photoQuality = preferences[PHOTO_QUALITY] ?: 95,
|
||||
useLivePhoto = preferences[USE_LIVE_PHOTO] ?: false,
|
||||
enableDevelopAnimation = preferences[ENABLE_DEVELOP_ANIMATION] ?: false,
|
||||
backgroundImage = preferences[BACKGROUND_IMAGE] ?: "camera_bg",
|
||||
useGpuAcceleration = preferences[USE_GPU_ACCELERATION] ?: DeviceUtil.defaultGpuAcceleration,
|
||||
droMode = preferences[DRO_MODE] ?: if (preferences[RAW_DRO_ENABLED_KEY] == true) "DR100" else "OFF",
|
||||
applyUltraHDR = preferences[APPLY_ULTRA_HDR] ?: false,
|
||||
colorSpace = ColorSpace.valueOf(preferences[COLOR_SPACE] ?: ColorSpace.SRGB.name),
|
||||
@@ -1039,15 +1035,6 @@ class UserPreferencesRepository(private val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存是否启用 GPU 加速
|
||||
*/
|
||||
suspend fun saveUseGpuAcceleration(enabled: Boolean) {
|
||||
context.dataStore.edit { preferences ->
|
||||
preferences[USE_GPU_ACCELERATION] = enabled
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存 DRO 模式
|
||||
*/
|
||||
|
||||
@@ -1029,8 +1029,8 @@ object GalleryManager {
|
||||
// 预先准备所有文件路径
|
||||
val photoFile = File(photoDir, PHOTO_FILE)
|
||||
val tempFile = File(photoDir, "temp.jpg")
|
||||
val yuvFile = File(photoDir, YUV_FILE)
|
||||
val hdrFile = File(photoDir, HDR_FILE)
|
||||
val yuvFile = File(photoDir, YUV_FILE)
|
||||
|
||||
val metadata = loadMetadata(context, photoId) ?: return@withContext
|
||||
|
||||
@@ -1574,7 +1574,6 @@ object GalleryManager {
|
||||
photoQuality: Int = 95,
|
||||
useSuperResolution: Boolean = false,
|
||||
superResolutionScale: Float = 1.0f,
|
||||
useGpuAcceleration: Boolean = true,
|
||||
) = withContext(Dispatchers.IO) {
|
||||
try {
|
||||
val photoDir = getPhotoDir(context, photoId, true)
|
||||
@@ -1590,9 +1589,8 @@ object GalleryManager {
|
||||
images,
|
||||
rotation,
|
||||
aspectRatio,
|
||||
yuvFile.absolutePath,
|
||||
currentUseSuperResolution,
|
||||
useGpuAcceleration,
|
||||
true,
|
||||
ColorSpace.get(metadata.colorSpace)
|
||||
)
|
||||
|
||||
@@ -1603,9 +1601,8 @@ object GalleryManager {
|
||||
images,
|
||||
rotation,
|
||||
aspectRatio,
|
||||
yuvFile.absolutePath,
|
||||
false,
|
||||
useGpuAcceleration,
|
||||
true,
|
||||
ColorSpace.get(metadata.colorSpace)
|
||||
)
|
||||
}
|
||||
@@ -1659,7 +1656,6 @@ object GalleryManager {
|
||||
photoQuality: Int = 95,
|
||||
useSuperResolution: Boolean = false,
|
||||
superResolutionScale: Float = 1.0f,
|
||||
useGpuAcceleration: Boolean = true,
|
||||
exposureBias: Float? = null,
|
||||
exportDngWithRawExport: Boolean = false
|
||||
) = withContext(Dispatchers.IO) {
|
||||
@@ -1670,7 +1666,6 @@ object GalleryManager {
|
||||
val photoFile = File(photoDir, PHOTO_FILE)
|
||||
val dngFile = File(photoDir, DNG_FILE)
|
||||
val tempFile = File(photoDir, "temp.jpg")
|
||||
val yuvFile = File(photoDir, YUV_FILE)
|
||||
|
||||
val metadata = loadMetadata(context, photoId) ?: return@withContext
|
||||
|
||||
@@ -1694,7 +1689,7 @@ object GalleryManager {
|
||||
images, rawMetadata.cfaPattern,
|
||||
currentUseSuperResolution,
|
||||
superResolutionScale,
|
||||
useGpuAcceleration,
|
||||
true,
|
||||
masterBlackLevel = rawMetadata.blackLevel,
|
||||
whiteLevel = rawMetadata.whiteLevel.toInt(),
|
||||
whiteBalanceGains = rawMetadata.whiteBalanceGains,
|
||||
@@ -1939,7 +1934,6 @@ object GalleryManager {
|
||||
photoQuality: Int = 95,
|
||||
useSuperResolution: Boolean = false,
|
||||
superResolutionScale: Float = 1.0f,
|
||||
useGpuAcceleration: Boolean = true,
|
||||
exposureBias: Float? = null,
|
||||
exportDngWithRawExport: Boolean = false
|
||||
) = withContext(Dispatchers.IO) {
|
||||
@@ -1958,8 +1952,7 @@ object GalleryManager {
|
||||
chromaNoiseReductionValue,
|
||||
photoQuality,
|
||||
useSuperResolution,
|
||||
superResolutionScale,
|
||||
useGpuAcceleration
|
||||
superResolutionScale
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1980,7 +1973,6 @@ object GalleryManager {
|
||||
photoQuality,
|
||||
useSuperResolution,
|
||||
superResolutionScale,
|
||||
useGpuAcceleration,
|
||||
exposureBias,
|
||||
exportDngWithRawExport
|
||||
)
|
||||
|
||||
@@ -2,8 +2,6 @@ package com.hinnka.mycamera.processor
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.ColorSpace
|
||||
import android.media.Image
|
||||
import android.util.Log
|
||||
import com.hinnka.mycamera.utils.PLog
|
||||
import java.nio.ByteBuffer
|
||||
import androidx.core.graphics.createBitmap
|
||||
@@ -20,6 +18,10 @@ data class RawStackResult(
|
||||
val isNormalizedSensorData: Boolean,
|
||||
)
|
||||
|
||||
fun calculateRawSuperResolutionOutputSize(inputSize: Int, scale: Float): Int {
|
||||
return ((inputSize.toFloat() * scale / 2f).roundToInt() * 2).coerceAtLeast(2)
|
||||
}
|
||||
|
||||
/**
|
||||
* Multi-Frame Stacker
|
||||
*
|
||||
@@ -57,7 +59,6 @@ object MultiFrameStacker {
|
||||
images: List<SafeImage>,
|
||||
rotation: Int,
|
||||
aspectRatio: AspectRatio?,
|
||||
outputPath: String? = null,
|
||||
enableSuperResolution: Boolean = false,
|
||||
useVulkan: Boolean = true,
|
||||
colorSpace: ColorSpace,
|
||||
@@ -104,6 +105,7 @@ object MultiFrameStacker {
|
||||
if (!processOk) {
|
||||
PLog.w(TAG, "Vulkan stack processing failed, invalidating cached stacker")
|
||||
invalidateCachedVulkanStacker(stackerPtr)
|
||||
return null
|
||||
} else {
|
||||
PLog.i(TAG, "Vulkan stacking completed in ${System.currentTimeMillis() - startTime}ms")
|
||||
return previewBitmap
|
||||
@@ -111,62 +113,15 @@ object MultiFrameStacker {
|
||||
} catch (e: Exception) {
|
||||
PLog.e(TAG, "Error during Vulkan stacking", e)
|
||||
invalidateCachedVulkanStacker(stackerPtr)
|
||||
return null
|
||||
}
|
||||
}
|
||||
PLog.e(TAG, "Failed to obtain Vulkan stacker")
|
||||
return null
|
||||
}
|
||||
|
||||
// Fallback or legacy path
|
||||
PLog.i(
|
||||
TAG,
|
||||
"Starting legacy stacking process for ${images.size} frames ($width x $height). SR=$enableSuperResolution"
|
||||
)
|
||||
val stackerPtr = createStackerNative(width, height, enableSuperResolution)
|
||||
if (stackerPtr == 0L) return null
|
||||
|
||||
try {
|
||||
val stagedIndices = mutableListOf<Int>()
|
||||
for (image in images) {
|
||||
image.use {
|
||||
val planes = image.planes
|
||||
stageFrameNative(
|
||||
stackerPtr,
|
||||
planes[0].buffer, planes[1].buffer, planes[2].buffer,
|
||||
planes[0].rowStride, planes[1].rowStride, planes[1].pixelStride,
|
||||
image.format
|
||||
)
|
||||
stagedIndices.add(stagedIndices.size)
|
||||
}
|
||||
}
|
||||
|
||||
for (idx in stagedIndices) {
|
||||
processFrameNative(stackerPtr, idx)
|
||||
}
|
||||
clearStagedFramesNative(stackerPtr)
|
||||
|
||||
val dimensions = BitmapUtils.calculateProcessedRect(width, height, aspectRatio, null, rotation)
|
||||
val targetW = dimensions.width() * scale
|
||||
val targetH = dimensions.height() * scale
|
||||
val previewBitmap = try {
|
||||
createBitmap(targetW, targetH, colorSpace = colorSpace)
|
||||
} catch (e: OutOfMemoryError) {
|
||||
PLog.e(TAG, "OOM creating legacy stack bitmap ($targetW x $targetH)", e)
|
||||
return null
|
||||
}
|
||||
|
||||
processStackNative(
|
||||
stackerPtr,
|
||||
previewBitmap,
|
||||
rotation,
|
||||
aspectRatio?.widthRatio ?: width,
|
||||
aspectRatio?.heightRatio ?: height,
|
||||
outputPath
|
||||
)
|
||||
|
||||
PLog.i(TAG, "Legacy stacking completed in ${System.currentTimeMillis() - startTime}ms")
|
||||
return previewBitmap
|
||||
} finally {
|
||||
releaseStackerNative(stackerPtr)
|
||||
}
|
||||
PLog.e(TAG, "YUV CPU stacking path is disabled")
|
||||
return null
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
@@ -245,7 +200,7 @@ object MultiFrameStacker {
|
||||
images: List<SafeImage>,
|
||||
cfaPattern: Int,
|
||||
enableSuperResolution: Boolean = false,
|
||||
superResolutionScale: Float = 1.5f,
|
||||
superResolutionScale: Float = 1.2f,
|
||||
useVulkan: Boolean = true,
|
||||
masterBlackLevel: FloatArray = floatArrayOf(0f, 0f, 0f, 0f),
|
||||
whiteLevel: Int = 1023,
|
||||
@@ -263,138 +218,67 @@ object MultiFrameStacker {
|
||||
"Starting RAW stacking for ${images.size} frames. Pattern=$cfaPattern SR=$enableSuperResolution scale=$superResolutionScale Vulkan=$useVulkan WL=$whiteLevel"
|
||||
)
|
||||
val outputScale = if (enableSuperResolution) superResolutionScale.coerceIn(1.0f, 2.0f) else 1.0f
|
||||
val useNativeSuperResolution = outputScale > 1.0f
|
||||
|
||||
if (useVulkan) {
|
||||
val vulkanStackerPtr = createVulkanRawStackerNative(
|
||||
width, height, enableSuperResolution, outputScale,
|
||||
masterBlackLevel, whiteLevel, whiteBalanceGains, noiseModel,
|
||||
lensShading, lensShadingWidth, lensShadingHeight
|
||||
)
|
||||
if (vulkanStackerPtr != 0L) {
|
||||
PLog.i(TAG, "Using Vulkan RAW stacker")
|
||||
var vulkanFusedBayer: ByteBuffer? = null
|
||||
try {
|
||||
for (image in images) {
|
||||
image.use {
|
||||
if (image.width != width || image.height != height) return@use
|
||||
val buffer = image.planes[0].buffer
|
||||
val rowStride = image.planes[0].rowStride
|
||||
addVulkanRawFrameNative(vulkanStackerPtr, buffer, rowStride, cfaPattern)
|
||||
}
|
||||
}
|
||||
|
||||
val outWidth = (width * outputScale).roundToInt()
|
||||
val outHeight = (height * outputScale).roundToInt()
|
||||
vulkanFusedBayer = try {
|
||||
ByteBuffer.allocateDirect(outWidth * outHeight * 2)
|
||||
.order(ByteOrder.nativeOrder())
|
||||
} catch (e: OutOfMemoryError) {
|
||||
PLog.e(TAG, "OOM allocating Vulkan fused Bayer buffer", e)
|
||||
return null
|
||||
}
|
||||
|
||||
val fusedOk = processVulkanRawStackNative(vulkanStackerPtr, vulkanFusedBayer)
|
||||
if (fusedOk) {
|
||||
vulkanFusedBayer.rewind()
|
||||
PLog.i(TAG, "Vulkan RAW stacking completed successfully")
|
||||
return RawStackResult(
|
||||
fusedBayerBuffer = vulkanFusedBayer,
|
||||
width = outWidth,
|
||||
height = outHeight,
|
||||
isNormalizedSensorData = true
|
||||
)
|
||||
} else {
|
||||
PLog.w(TAG, "Vulkan RAW stacking failed, falling back to CPU")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
PLog.e(TAG, "Vulkan RAW stacking error: ${e.message}, falling back to CPU")
|
||||
} finally {
|
||||
releaseVulkanRawStackerNative(vulkanStackerPtr)
|
||||
}
|
||||
// fallback 到 CPU 路径前显式释放 Vulkan buffer 引用,避免与 CPU 路径的分配叠加
|
||||
// 仅 fused Bayer 持续到 DNG 保存完成。
|
||||
vulkanFusedBayer = null
|
||||
@Suppress("ExplicitGarbageCollectionCall")
|
||||
System.gc()
|
||||
} else {
|
||||
PLog.w(TAG, "Failed to create Vulkan RAW stacker, falling back to CPU")
|
||||
}
|
||||
}
|
||||
|
||||
PLog.i(TAG, "Using CPU RAW stacker")
|
||||
val stackerPtr = createRawStackerNative(width, height, useNativeSuperResolution)
|
||||
if (stackerPtr == 0L) {
|
||||
PLog.e(TAG, "Failed to create CPU raw stacker")
|
||||
if (!useVulkan) {
|
||||
PLog.e(TAG, "RAW CPU stacking path is disabled")
|
||||
return null
|
||||
}
|
||||
|
||||
try {
|
||||
val stagedIndices = mutableListOf<Int>()
|
||||
for (image in images) {
|
||||
image.use {
|
||||
if (image.width != width || image.height != height) return@use
|
||||
val buffer = image.planes[0].buffer
|
||||
val rowStride = image.planes[0].rowStride
|
||||
stageRawFrameNative(stackerPtr, buffer, rowStride, cfaPattern)
|
||||
stagedIndices.add(stagedIndices.size)
|
||||
val vulkanStackerPtr = createVulkanRawStackerNative(
|
||||
width, height, enableSuperResolution, outputScale,
|
||||
masterBlackLevel, whiteLevel, whiteBalanceGains, noiseModel,
|
||||
lensShading, lensShadingWidth, lensShadingHeight
|
||||
)
|
||||
if (vulkanStackerPtr != 0L) {
|
||||
PLog.i(TAG, "Using Vulkan RAW stacker")
|
||||
var vulkanFusedBayer: ByteBuffer? = null
|
||||
try {
|
||||
for (image in images) {
|
||||
image.use {
|
||||
if (image.width != width || image.height != height) return@use
|
||||
val buffer = image.planes[0].buffer
|
||||
val rowStride = image.planes[0].rowStride
|
||||
addVulkanRawFrameNative(vulkanStackerPtr, buffer, rowStride, cfaPattern)
|
||||
}
|
||||
}
|
||||
}
|
||||
for (idx in stagedIndices) {
|
||||
processRawFrameNative(stackerPtr, idx)
|
||||
}
|
||||
clearStagedRawFramesNative(stackerPtr)
|
||||
|
||||
val stackedWidth = if (useNativeSuperResolution) width * 2 else width
|
||||
val stackedHeight = if (useNativeSuperResolution) height * 2 else height
|
||||
val fusedBayerBuffer = try {
|
||||
ByteBuffer.allocateDirect(stackedWidth * stackedHeight * 2)
|
||||
.order(ByteOrder.nativeOrder())
|
||||
} catch (e: OutOfMemoryError) {
|
||||
PLog.e(TAG, "OOM allocating fused Bayer buffer", e)
|
||||
val outWidth = calculateRawSuperResolutionOutputSize(width, outputScale)
|
||||
val outHeight = calculateRawSuperResolutionOutputSize(height, outputScale)
|
||||
vulkanFusedBayer = try {
|
||||
ByteBuffer.allocateDirect(outWidth * outHeight * 2)
|
||||
.order(ByteOrder.nativeOrder())
|
||||
} catch (e: OutOfMemoryError) {
|
||||
PLog.e(TAG, "OOM allocating Vulkan fused Bayer buffer", e)
|
||||
return null
|
||||
}
|
||||
|
||||
val fusedOk = processVulkanRawStackNative(vulkanStackerPtr, vulkanFusedBayer)
|
||||
if (fusedOk) {
|
||||
vulkanFusedBayer.rewind()
|
||||
PLog.i(TAG, "Vulkan RAW stacking completed successfully")
|
||||
return RawStackResult(
|
||||
fusedBayerBuffer = vulkanFusedBayer,
|
||||
width = outWidth,
|
||||
height = outHeight,
|
||||
isNormalizedSensorData = true
|
||||
)
|
||||
} else {
|
||||
PLog.e(TAG, "Vulkan RAW stacking failed")
|
||||
return null
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
PLog.e(TAG, "Vulkan RAW stacking error: ${e.message}", e)
|
||||
return null
|
||||
} finally {
|
||||
releaseVulkanRawStackerNative(vulkanStackerPtr)
|
||||
}
|
||||
processRawStackWithBufferNative(stackerPtr, fusedBayerBuffer)
|
||||
|
||||
fusedBayerBuffer.rewind()
|
||||
PLog.i(TAG, "CPU RAW stacking completed successfully")
|
||||
return RawStackResult(
|
||||
fusedBayerBuffer = fusedBayerBuffer,
|
||||
width = stackedWidth,
|
||||
height = stackedHeight,
|
||||
isNormalizedSensorData = false
|
||||
)
|
||||
|
||||
} finally {
|
||||
releaseRawStackerNative(stackerPtr)
|
||||
} else {
|
||||
PLog.e(TAG, "Failed to create Vulkan RAW stacker")
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
// --- Native Methods ---
|
||||
|
||||
private external fun createStackerNative(width: Int, height: Int, enableSuperRes: Boolean): Long
|
||||
|
||||
private external fun stageFrameNative(
|
||||
stackerPtr: Long,
|
||||
yBuffer: ByteBuffer, uBuffer: ByteBuffer, vBuffer: ByteBuffer,
|
||||
yRowStride: Int, uvRowStride: Int, uvPixelStride: Int,
|
||||
format: Int
|
||||
)
|
||||
|
||||
private external fun processFrameNative(stackerPtr: Long, index: Int)
|
||||
private external fun clearStagedFramesNative(stackerPtr: Long)
|
||||
|
||||
private external fun processStackNative(
|
||||
stackerPtr: Long,
|
||||
outBitmap: Bitmap?,
|
||||
rotation: Int,
|
||||
targetWR: Int,
|
||||
targetHR: Int,
|
||||
outputPath: String?
|
||||
)
|
||||
|
||||
private external fun releaseStackerNative(stackerPtr: Long)
|
||||
|
||||
private external fun createVulkanStackerNative(width: Int, height: Int, enableSuperRes: Boolean): Long
|
||||
private external fun addVulkanFrameNative(
|
||||
stackerPtr: Long,
|
||||
@@ -405,13 +289,6 @@ object MultiFrameStacker {
|
||||
private external fun releaseVulkanStackerNative(stackerPtr: Long)
|
||||
private external fun resetVulkanStackerNative(stackerPtr: Long): Boolean
|
||||
|
||||
private external fun createRawStackerNative(width: Int, height: Int, enableSuperRes: Boolean): Long
|
||||
private external fun stageRawFrameNative(stackerPtr: Long, rawData: ByteBuffer, rowStride: Int, cfaPattern: Int)
|
||||
private external fun processRawFrameNative(stackerPtr: Long, index: Int)
|
||||
private external fun clearStagedRawFramesNative(stackerPtr: Long)
|
||||
private external fun processRawStackWithBufferNative(stackerPtr: Long, outputBuffer: ByteBuffer)
|
||||
private external fun releaseRawStackerNative(stackerPtr: Long)
|
||||
|
||||
// Vulkan RAW Stacker
|
||||
private external fun createVulkanRawStackerNative(
|
||||
width: Int, height: Int, enableSuperRes: Boolean, superResScale: Float,
|
||||
|
||||
@@ -194,6 +194,7 @@ fun SettingsScreen(
|
||||
val useRaw by viewModel.useRaw.collectAsState(initial = false)
|
||||
val exportDngWithRawExport by viewModel.exportDngWithRawExport.collectAsState(initial = true)
|
||||
val useSuperResolution by viewModel.useMFSR.collectAsState(initial = false)
|
||||
val superResolutionScale by viewModel.superResolutionScale.collectAsState(initial = 1.2f)
|
||||
// 软件处理参数
|
||||
val sharpening by viewModel.sharpening.collectAsState(initial = 0f)
|
||||
val noiseReduction by viewModel.noiseReduction.collectAsState(initial = 0f)
|
||||
@@ -206,7 +207,6 @@ fun SettingsScreen(
|
||||
val useLivePhoto by viewModel.useLivePhoto.collectAsState()
|
||||
val enableDevelopAnimation by viewModel.enableDevelopAnimation.collectAsState()
|
||||
val photoQuality by viewModel.photoQuality.collectAsState(initial = 95)
|
||||
val useGpuAcceleration by viewModel.useGpuAcceleration.collectAsState()
|
||||
val useP010 by viewModel.useP010.collectAsState()
|
||||
val useHlg10 by viewModel.useHlg10.collectAsState()
|
||||
val hlgHardwareCompatibilityEnabled by viewModel.hlgHardwareCompatibilityEnabled.collectAsState()
|
||||
@@ -247,6 +247,8 @@ fun SettingsScreen(
|
||||
|
||||
var selectedTab by remember { mutableStateOf(SettingsTab.GENERAL) }
|
||||
var isRawSliderAdjusting by remember { mutableStateOf(false) }
|
||||
var isSuperResolutionScaleAdjusting by remember { mutableStateOf(false) }
|
||||
var superResolutionScaleUi by remember { mutableStateOf(superResolutionScale) }
|
||||
var rawNlmNoiseFactorUi by remember { mutableStateOf(rawNlmNoiseFactor) }
|
||||
var rawExposureCompensationUi by remember { mutableStateOf(rawExposureCompensation) }
|
||||
var rawBlackPointCorrectionUi by remember { mutableStateOf(rawBlackPointCorrection) }
|
||||
@@ -264,6 +266,12 @@ fun SettingsScreen(
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(superResolutionScale) {
|
||||
if (!isSuperResolutionScaleAdjusting) {
|
||||
superResolutionScaleUi = superResolutionScale
|
||||
}
|
||||
}
|
||||
|
||||
fun commitRawSliderValues() {
|
||||
isRawSliderAdjusting = false
|
||||
viewModel.setRawNlmNoiseFactor(rawNlmNoiseFactorUi)
|
||||
@@ -272,6 +280,11 @@ fun SettingsScreen(
|
||||
viewModel.setRawWhitePointCorrection(rawWhitePointCorrectionUi)
|
||||
}
|
||||
|
||||
fun commitSuperResolutionScale() {
|
||||
isSuperResolutionScaleAdjusting = false
|
||||
viewModel.setSuperResolutionScale(superResolutionScaleUi)
|
||||
}
|
||||
|
||||
val context = androidx.compose.ui.platform.LocalContext.current
|
||||
val coroutineScope = androidx.compose.runtime.rememberCoroutineScope()
|
||||
val isHdrSettingsSupported = remember { Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && !DeviceUtil.isHarmonyOS }
|
||||
@@ -1125,23 +1138,6 @@ fun SettingsScreen(
|
||||
onLevelSelected = { viewModel.setMultipleExposureCount(it) }
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
color = Color.White.copy(alpha = 0.1f),
|
||||
modifier = Modifier.padding(vertical = 8.dp)
|
||||
)
|
||||
|
||||
SwitchSettingItem(
|
||||
title = stringResource(R.string.settings_use_gpu_acceleration),
|
||||
description = stringResource(R.string.settings_use_gpu_acceleration_description),
|
||||
checked = useGpuAcceleration,
|
||||
onCheckedChange = { viewModel.setUseGpuAcceleration(it) }
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
color = Color.White.copy(alpha = 0.1f),
|
||||
modifier = Modifier.padding(vertical = 8.dp)
|
||||
)
|
||||
|
||||
SwitchSettingItem(
|
||||
title = stringResource(R.string.settings_use_live_photo),
|
||||
description = stringResource(R.string.settings_use_live_photo_description),
|
||||
@@ -1326,6 +1322,27 @@ fun SettingsScreen(
|
||||
}
|
||||
|
||||
SettingsTab.RAW -> {
|
||||
SliderSettingItem(
|
||||
title = stringResource(R.string.settings_super_resolution_scale),
|
||||
description = stringResource(R.string.settings_super_resolution_scale_description),
|
||||
value = superResolutionScaleUi,
|
||||
valueRange = 1.0f..2.0f,
|
||||
onValueChange = {
|
||||
isSuperResolutionScaleAdjusting = true
|
||||
superResolutionScaleUi = it.coerceIn(1.0f, 2.0f)
|
||||
},
|
||||
resetValue = 1.2f,
|
||||
toggleValue = useSuperResolution,
|
||||
onToggleChange = { viewModel.setUseMFSR(it) },
|
||||
onValueChangeFinished = { commitSuperResolutionScale() },
|
||||
valueTextFormatter = { "%.2fx".format(it) }
|
||||
)
|
||||
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(vertical = 8.dp),
|
||||
color = Color.White.copy(alpha = 0.1f)
|
||||
)
|
||||
|
||||
RawEditPanel(
|
||||
selectedDcpId = rawDcpId,
|
||||
availableDcps = availableDcps,
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.hinnka.mycamera.lut.creator.OpenAIApiClient
|
||||
import com.hinnka.mycamera.model.ColorRecipeParams
|
||||
import com.hinnka.mycamera.model.SafeImage
|
||||
import com.hinnka.mycamera.phantom.PhantomWidgetProvider
|
||||
import com.hinnka.mycamera.processor.calculateRawSuperResolutionOutputSize
|
||||
import com.hinnka.mycamera.raw.ColorSpace
|
||||
import com.hinnka.mycamera.raw.DcpProfileParser
|
||||
import com.hinnka.mycamera.raw.DcpInfo
|
||||
@@ -313,6 +314,9 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
val useMFSR: StateFlow<Boolean> = userPreferencesRepository.userPreferences
|
||||
.map { it.useMFSR }
|
||||
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
|
||||
val superResolutionScale: StateFlow<Float> = userPreferencesRepository.userPreferences
|
||||
.map { it.superResolutionScale }
|
||||
.stateIn(viewModelScope, SharingStarted.Eagerly, 1.2f)
|
||||
val useLivePhoto: StateFlow<Boolean> = userPreferencesRepository.userPreferences
|
||||
.map { it.useLivePhoto }
|
||||
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
|
||||
@@ -322,9 +326,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
val backgroundImage: StateFlow<String> = userPreferencesRepository.userPreferences
|
||||
.map { it.backgroundImage }
|
||||
.stateIn(viewModelScope, SharingStarted.Eagerly, "camera_bg")
|
||||
val useGpuAcceleration: StateFlow<Boolean> = userPreferencesRepository.userPreferences
|
||||
.map { it.useGpuAcceleration }
|
||||
.stateIn(viewModelScope, SharingStarted.Eagerly, DeviceUtil.defaultGpuAcceleration)
|
||||
val droMode: StateFlow<String> = userPreferencesRepository.userPreferences
|
||||
.map { it.droMode }
|
||||
.stateIn(viewModelScope, SharingStarted.Eagerly, "OFF")
|
||||
@@ -2169,8 +2170,9 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
|
||||
fun setSuperResolutionScale(scale: Float) {
|
||||
val normalizedScale = scale.coerceIn(1.0f, 2.0f)
|
||||
viewModelScope.launch {
|
||||
userPreferencesRepository.saveSuperResolutionScale(scale)
|
||||
userPreferencesRepository.saveSuperResolutionScale(normalizedScale)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3063,7 +3065,7 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
val rotation = (baseRotation + orientationOffset) % 360
|
||||
|
||||
val useSuperRes = useMFSR.value
|
||||
val superResScale = if (useSuperRes) 2f else 1.0f
|
||||
val superResScale = if (useSuperRes) superResolutionScale.value.coerceIn(1.0f, 2.0f) else 1.0f
|
||||
|
||||
val aperture = if (state.value.isVirtualApertureEnabled) state.value.virtualAperture else null
|
||||
val defaultHdrEffectEnabled = defaultHdrEffectEnabled(
|
||||
@@ -3098,8 +3100,8 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
rawBlackLevelMode = userPrefs?.rawBlackLevelModes?.get(currentCameraId) ?: "Default",
|
||||
rawCustomBlackLevel = userPrefs?.rawCustomBlackLevels?.get(currentCameraId) ?: 0f,
|
||||
cameraId = currentCameraId,
|
||||
width = (images[0].width.toFloat() * superResScale).roundToInt(),
|
||||
height = (images[0].height.toFloat() * superResScale).roundToInt(),
|
||||
width = calculateRawSuperResolutionOutputSize(images[0].width, superResScale),
|
||||
height = calculateRawSuperResolutionOutputSize(images[0].height, superResScale),
|
||||
ratio = aspectRatio,
|
||||
rotation = rotation,
|
||||
deviceModel = captureInfo.model,
|
||||
@@ -3170,7 +3172,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
photoQualityValue,
|
||||
useSuperResolution = useSuperRes,
|
||||
superResolutionScale = superResScale,
|
||||
useGpuAcceleration = useGpuAcceleration.value,
|
||||
exposureBias = state.value.exposureBias,
|
||||
exportDngWithRawExport = exportDngWithRawExport.value
|
||||
)
|
||||
@@ -3352,15 +3353,6 @@ class CameraViewModel(application: Application) : AndroidViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置多帧合成是否使用 GPU 加速
|
||||
*/
|
||||
fun setUseGpuAcceleration(enabled: Boolean) {
|
||||
viewModelScope.launch {
|
||||
userPreferencesRepository.saveUseGpuAcceleration(enabled)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存从外部选择的背景图
|
||||
*/
|
||||
|
||||
@@ -214,7 +214,7 @@
|
||||
<string name="settings_use_super_resolution">多帧超分</string>
|
||||
<string name="settings_use_super_resolution_description">启用多帧超分</string>
|
||||
<string name="settings_super_resolution_scale">超分倍率</string>
|
||||
<string name="settings_super_resolution_scale_description">设置多帧超分倍率,默认 1x。</string>
|
||||
<string name="settings_super_resolution_scale_description">设置 RAW 多帧超分倍率,范围 1.00x–2.00x,默认 1.20x。</string>
|
||||
<string name="settings_raw_engine">RAW 处理引擎</string>
|
||||
<string name="settings_raw_engine_description">选择用于处理 RAW 数据的引擎</string>
|
||||
<string name="settings_raw_engine_native">原生</string>
|
||||
|
||||
@@ -137,7 +137,7 @@
|
||||
<string name="settings_multi_frame_count_description">多幀合成所使用的幀數(幀數越多效果越好,但合成也越慢)。</string>
|
||||
<string name="settings_use_super_resolution">超解析度</string>
|
||||
<string name="settings_use_super_resolution_description">使用 2x 多幀超解析度以獲得更多細節。(需要開啟多幀合成)</string>
|
||||
<string name="settings_super_resolution_scale_description">设置多帧超分倍率,默认 1.5x。</string>
|
||||
<string name="settings_super_resolution_scale_description">設定 RAW 多幀超分倍率,範圍 1.00x–2.00x,預設 1.20x。</string>
|
||||
<string name="settings_raw_engine">RAW 處理引擎</string>
|
||||
<string name="settings_raw_engine_description">選擇用於處理 RAW 資料的引擎</string>
|
||||
<string name="settings_raw_engine_native">原生</string>
|
||||
|
||||
@@ -216,7 +216,7 @@
|
||||
<string name="settings_use_super_resolution">Multi-Frame Super Resolution</string>
|
||||
<string name="settings_use_super_resolution_description">Enable multi-frame super resolution.</string>
|
||||
<string name="settings_super_resolution_scale">Super Resolution Scale</string>
|
||||
<string name="settings_super_resolution_scale_description">Set the multi-frame super resolution scale. Default is 1x.</string>
|
||||
<string name="settings_super_resolution_scale_description">Set the RAW multi-frame super resolution scale from 1.00x to 2.00x. Default is 1.20x.</string>
|
||||
<string name="settings_raw_engine">RAW Processing Engine</string>
|
||||
<string name="settings_raw_engine_description">Choose the engine for RAW data processing</string>
|
||||
<string name="settings_raw_engine_native">Native</string>
|
||||
|
||||
Reference in new issue
Block a user