fix: black crop for rawmax
This commit is contained in:
1 parent
5d68519c00
commit
cae7fcca78
3 files changed
+76
-2
No files matched your search
@@ -185,6 +185,32 @@ data class RawBlackBorderCrop(
|
||||
) {
|
||||
val hasCrop: Boolean
|
||||
get() = leftPx > 0 || topPx > 0 || rightPx > 0 || bottomPx > 0
|
||||
|
||||
/**
|
||||
* Maps native RAW crop margins onto a uniformly resampled output pixel grid.
|
||||
*
|
||||
* ISZ lens settings are recorded against the camera's native RAW dimensions. RAWmax may
|
||||
* produce a larger RAW grid, so keeping the native pixel counts would leave part of the
|
||||
* configured black border in the rendered image.
|
||||
*/
|
||||
internal fun scaledForOutput(outputScale: Float): RawBlackBorderCrop {
|
||||
if (!hasCrop || !outputScale.isFinite() || outputScale <= 0f || outputScale == 1f) {
|
||||
return this
|
||||
}
|
||||
|
||||
fun scaleMargin(value: Int): Int {
|
||||
return (value.coerceAtLeast(0).toFloat() * outputScale)
|
||||
.roundToInt()
|
||||
.coerceAtLeast(0)
|
||||
}
|
||||
|
||||
return RawBlackBorderCrop(
|
||||
leftPx = scaleMargin(leftPx),
|
||||
topPx = scaleMargin(topPx),
|
||||
rightPx = scaleMargin(rightPx),
|
||||
bottomPx = scaleMargin(bottomPx)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,6 +19,7 @@ import androidx.exifinterface.media.ExifInterface
|
||||
import com.hinnka.mycamera.camera.AspectRatio
|
||||
import com.hinnka.mycamera.camera.CaptureInfo
|
||||
import com.hinnka.mycamera.camera.HdrBracketConfig
|
||||
import com.hinnka.mycamera.camera.MultiFrameConfig
|
||||
import com.hinnka.mycamera.data.ContentRepository
|
||||
import com.hinnka.mycamera.gallery.db.GalleryMediaStore
|
||||
import com.hinnka.mycamera.hdr.GainmapResult
|
||||
@@ -2843,6 +2844,11 @@ object GalleryManager {
|
||||
}
|
||||
|
||||
val currentUseSuperResolution = useSuperResolution
|
||||
val rawStackOutputScale = if (currentUseSuperResolution) {
|
||||
MultiFrameConfig.normalizeOutputScale(superResolutionScale)
|
||||
} else {
|
||||
1f
|
||||
}
|
||||
val applyRawLensShading = resolveRawLensShadingCorrectionEnabled(context, metadata)
|
||||
val effectiveRawStackFrames = if (rawStackFrames.size == images.size &&
|
||||
rawStackFrames.indices.all { rawStackFrames[it].image === images[it] }
|
||||
@@ -2867,7 +2873,7 @@ object GalleryManager {
|
||||
MultiFrameStacker.processBurstRaw(
|
||||
frames = effectiveRawStackFrames,
|
||||
cfaPattern = stackCfaPattern,
|
||||
outputScale = if (currentUseSuperResolution) superResolutionScale else 1f,
|
||||
outputScale = rawStackOutputScale,
|
||||
masterBlackLevel = stackBlackLevel,
|
||||
whiteLevel = stackWhiteLevel,
|
||||
whiteBalanceGains = rawMetadata.whiteBalanceGains,
|
||||
@@ -2885,11 +2891,24 @@ object GalleryManager {
|
||||
val finalStackResult = rawStackResult ?: return@withContext
|
||||
gpuSourceToRelease = finalStackResult.gpuLinearRgbSource
|
||||
|
||||
val stackedMetadata = if (finalStackResult.isNormalizedSensorData) {
|
||||
val outputRawBlackBorderCrop =
|
||||
metadata.rawBlackBorderCrop.scaledForOutput(rawStackOutputScale)
|
||||
val stackedMetadataBase = if (finalStackResult.isNormalizedSensorData) {
|
||||
metadata.withNormalizedRawLevelCorrectionsCleared("RAW stack")
|
||||
} else {
|
||||
metadata
|
||||
}
|
||||
val stackedMetadata = stackedMetadataBase.copy(
|
||||
rawBlackBorderCrop = outputRawBlackBorderCrop
|
||||
)
|
||||
if (outputRawBlackBorderCrop != metadata.rawBlackBorderCrop) {
|
||||
PLog.i(
|
||||
TAG,
|
||||
"RAWmax black border crop mapped to output scale: " +
|
||||
"scale=$rawStackOutputScale native=${metadata.rawBlackBorderCrop} " +
|
||||
"output=$outputRawBlackBorderCrop"
|
||||
)
|
||||
}
|
||||
val fusedBayerBuffer = finalStackResult.fusedBayerBuffer ?: return@withContext
|
||||
var fusedBufferReleased = false
|
||||
fun releaseFusedBuffer() {
|
||||
|
||||
@@ -78,4 +78,33 @@ class IszLensConfigTest {
|
||||
assertEquals(VendorCaptureValueType.INT, VendorCaptureKey.MTK_RAW_BPP.valueType)
|
||||
assertEquals("mtk_raw_bpp_14", settings.toVirtualLensProfileId())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun rawBlackBorderCrop_scaledForOutputMapsEveryMarginToRawMaxGrid() {
|
||||
val nativeCrop = RawBlackBorderCrop(
|
||||
leftPx = 7,
|
||||
topPx = 10,
|
||||
rightPx = 13,
|
||||
bottomPx = 20
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
RawBlackBorderCrop(
|
||||
leftPx = 11,
|
||||
topPx = 15,
|
||||
rightPx = 20,
|
||||
bottomPx = 30
|
||||
),
|
||||
nativeCrop.scaledForOutput(1.5f)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun rawBlackBorderCrop_scaledForOutputKeepsNativeGridForUnitOrInvalidScale() {
|
||||
val nativeCrop = RawBlackBorderCrop(leftPx = 12, bottomPx = 8)
|
||||
|
||||
assertEquals(nativeCrop, nativeCrop.scaledForOutput(1f))
|
||||
assertEquals(nativeCrop, nativeCrop.scaledForOutput(Float.NaN))
|
||||
assertEquals(nativeCrop, nativeCrop.scaledForOutput(0f))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user