feat: support embedded gainmaps in photo processing pipeline
This commit is contained in:
1 parent
6dbdd5ef6d
commit
caa5719067
5 files changed
+38
-11
No files matched your search
@@ -2543,7 +2543,8 @@ object GalleryManager {
|
||||
|
||||
private fun detectEmbeddedGainmap(context: Context, photoFile: File): Boolean {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE || !photoFile.exists()) return false
|
||||
return hasBitmapGainmap(loadBitmap(context, Uri.fromFile(photoFile), preserveHdr = true))
|
||||
// Use a small maxEdge for performance; gainmap detection works on downsampled bitmaps.
|
||||
return hasBitmapGainmap(loadBitmap(context, Uri.fromFile(photoFile), maxEdge = 512, preserveHdr = true))
|
||||
}
|
||||
|
||||
|
||||
@@ -2651,7 +2652,7 @@ object GalleryManager {
|
||||
width = processedBitmap.width,
|
||||
height = processedBitmap.height,
|
||||
rotation = 0,
|
||||
manualHdrEffectEnabled = userPrefs?.autoEnableHdr ?: false,
|
||||
manualHdrEffectEnabled = false,
|
||||
)
|
||||
saveMetadata(context, photoId, updatedMetadata)
|
||||
// if (updatedMetadata.computationalAperture != null) {
|
||||
@@ -2672,11 +2673,7 @@ object GalleryManager {
|
||||
val hasEmbeddedGainmap = detectEmbeddedGainmap(context, photoFile)
|
||||
val updatedMetadata = currentMetadata.copy(
|
||||
hasEmbeddedGainmap = hasEmbeddedGainmap,
|
||||
manualHdrEffectEnabled = if (hasEmbeddedGainmap) {
|
||||
true
|
||||
} else {
|
||||
userPrefs?.autoEnableHdr ?: false
|
||||
}
|
||||
manualHdrEffectEnabled = hasEmbeddedGainmap
|
||||
)
|
||||
saveMetadata(context, photoId, updatedMetadata)
|
||||
// if (metadata.computationalAperture != null) {
|
||||
|
||||
@@ -195,6 +195,21 @@ class PhotoProcessor(
|
||||
}
|
||||
}
|
||||
|
||||
if (source == null) {
|
||||
val photoFile = GalleryManager.getPhotoFile(context, photoId)
|
||||
if (photoFile.exists()) {
|
||||
val bitmap = GalleryManager.loadBitmap(context, photoId, preserveHdr = true)
|
||||
if (bitmap != null) {
|
||||
source = GainmapSourceSet(
|
||||
sdrBase = bitmap,
|
||||
sourceKind = SourceKind.SDR_BITMAP,
|
||||
confidence = if (metadata.hasEmbeddedGainmap) 1.0f else 0.5f,
|
||||
displayHdrSdrRatio = readDisplayHdrSdrRatio()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If source was generated from DNG/YUV, and we have an AI denoised base, replace the sdrBase.
|
||||
// The AI base is persisted in ai_denoise.jpg so exports and HDR gainmaps never rerun the slow model.
|
||||
if (source != null && metadata.hasAiDenoisedBase) {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.hinnka.mycamera.hdr
|
||||
|
||||
import android.os.Build
|
||||
|
||||
class EmbeddedGainmapProducer : GainmapProducer {
|
||||
override suspend fun build(source: GainmapSourceSet, strength: Float): GainmapResult? {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) return null
|
||||
|
||||
val gainmap = source.sdrBase.gainmap ?: return null
|
||||
|
||||
return GainmapResult(
|
||||
gainmap = gainmap,
|
||||
sourceKind = source.sourceKind,
|
||||
confidence = source.confidence
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ class UnifiedGainmapProducer(
|
||||
private val producers: List<GainmapProducer> = listOf(
|
||||
HlgGainmapProducer(),
|
||||
RawGainmapProducer(),
|
||||
EmbeddedGainmapProducer(),
|
||||
EstimatedSdrGainmapProducer(),
|
||||
)
|
||||
) : GainmapProducer {
|
||||
|
||||
@@ -2580,11 +2580,8 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
var successCount = 0
|
||||
|
||||
withContext(Dispatchers.IO) {
|
||||
val lutId = defaultLutId.firstOrNull() ?: contentRepository.getAvailableLuts()
|
||||
.firstOrNull { it.isDefault }?.id
|
||||
val computationalAperture = defaultVirtualAperture.firstOrNull()?.let { if (it > 0f) it else null }
|
||||
uris.forEach { uri ->
|
||||
val photoId = GalleryManager.importPhoto(context, uri, lutId, computationalAperture)
|
||||
val photoId = GalleryManager.importPhoto(context, uri, null, null)
|
||||
if (photoId != null) {
|
||||
successCount++
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user