feat: ensure ARGB_8888 for bokeh processing and refine generation flow
This commit is contained in:
1 parent
2182b970d3
commit
bc81589639
2 files changed
+35
-13
No files matched your search
@@ -1188,6 +1188,7 @@ object GalleryManager {
|
||||
writeFinalJpeg(bitmap, outputStream, photoQuality)
|
||||
}
|
||||
tempFile.renameTo(photoFile)
|
||||
generateBokehPhoto(context, photoId, metadata, bitmap)
|
||||
val preparedUltraHdrSource = if (metadata.manualHdrEffectEnabled) {
|
||||
photoProcessor.prepareUltraHdrSourceFromRawResult(
|
||||
context = context,
|
||||
@@ -1339,6 +1340,7 @@ object GalleryManager {
|
||||
writeFinalJpeg(bitmap, outputStream, photoQuality)
|
||||
}
|
||||
tempFile.renameTo(photoFile)
|
||||
// generateBokehPhoto(context, photoId, metadata, bitmap)
|
||||
queueDetailHdrCacheBuild(
|
||||
context = context,
|
||||
photoId = photoId,
|
||||
@@ -1597,6 +1599,7 @@ object GalleryManager {
|
||||
writeFinalJpeg(result, outputStream, photoQuality)
|
||||
}
|
||||
tempFile.renameTo(photoFile)
|
||||
generateBokehPhoto(context, photoId, metadata, result)
|
||||
// Auto Save
|
||||
if (shouldAutoSave) {
|
||||
val metadata = loadMetadata(context, photoId) ?: return@withContext
|
||||
@@ -1755,6 +1758,7 @@ object GalleryManager {
|
||||
writeFinalJpeg(result, outputStream, photoQuality)
|
||||
}
|
||||
tempFile.renameTo(photoFile)
|
||||
generateBokehPhoto(context, photoId, metadata, result)
|
||||
// Auto Save
|
||||
if (shouldAutoSave) {
|
||||
exportPhoto(
|
||||
@@ -2633,9 +2637,9 @@ object GalleryManager {
|
||||
manualHdrEffectEnabled = userPrefs?.autoEnableHdr ?: false,
|
||||
)
|
||||
metadataFile.writeText(updatedMetadata.toJson())
|
||||
if (updatedMetadata.computationalAperture != null) {
|
||||
generateBokehPhoto(context, photoId, updatedMetadata, processedBitmap)
|
||||
}
|
||||
// if (updatedMetadata.computationalAperture != null) {
|
||||
// generateBokehPhoto(context, photoId, updatedMetadata, processedBitmap)
|
||||
// }
|
||||
|
||||
processedBitmap.recycle()
|
||||
} else {
|
||||
@@ -2658,13 +2662,13 @@ object GalleryManager {
|
||||
}
|
||||
)
|
||||
saveMetadata(context, photoId, updatedMetadata)
|
||||
if (metadata.computationalAperture != null) {
|
||||
val bitmap = BitmapFactory.decodeFile(photoFile.absolutePath)
|
||||
if (bitmap != null) {
|
||||
generateBokehPhoto(context, photoId, metadata, bitmap)
|
||||
bitmap.recycle()
|
||||
}
|
||||
}
|
||||
// if (metadata.computationalAperture != null) {
|
||||
// val bitmap = BitmapFactory.decodeFile(photoFile.absolutePath)
|
||||
// if (bitmap != null) {
|
||||
// generateBokehPhoto(context, photoId, metadata, bitmap)
|
||||
// bitmap.recycle()
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// Check for Motion Photo after import
|
||||
|
||||
@@ -56,8 +56,10 @@ class DepthBokehProcessor(context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
val inputForBokeh = ensureArgb8888(originalImage)
|
||||
|
||||
if (depthMap == null) {
|
||||
depthMap = depthEstimator.estimateDepth(originalImage)
|
||||
depthMap = depthEstimator.estimateDepth(inputForBokeh)
|
||||
|
||||
if (depthMap != null && depthFile != null) {
|
||||
try {
|
||||
@@ -81,18 +83,34 @@ class DepthBokehProcessor(context: Context) {
|
||||
TAG,
|
||||
"Prepared bokeh depth: inverted=${preparedDepth.inverted} focusDepth=${preparedDepth.focusDepth} normalScore=${preparedDepth.normalScore} invertedScore=${preparedDepth.invertedScore}"
|
||||
)
|
||||
result = processor.applyBokeh(
|
||||
originalImage,
|
||||
val bokehResult = processor.applyBokeh(
|
||||
inputForBokeh,
|
||||
preparedDepth.depthMap,
|
||||
focusX ?: 0.5f,
|
||||
focusY ?: 0.5f,
|
||||
aperture
|
||||
)
|
||||
if (inputForBokeh !== originalImage && !inputForBokeh.isRecycled) {
|
||||
inputForBokeh.recycle()
|
||||
}
|
||||
result = bokehResult
|
||||
}
|
||||
|
||||
return result ?: originalImage
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a bitmap to ARGB_8888 if it isn't already.
|
||||
* RGBA_F16 bitmaps (from RAW processing) are not compatible with
|
||||
* GLUtils.texImage2D used by OglBokehProcessor.
|
||||
*/
|
||||
private fun ensureArgb8888(bitmap: Bitmap): Bitmap {
|
||||
if (bitmap.config == Bitmap.Config.ARGB_8888) return bitmap
|
||||
PLog.d(TAG, "Converting bitmap from ${bitmap.config} to ARGB_8888 for bokeh processing (${bitmap.width}x${bitmap.height})")
|
||||
val converted = bitmap.copy(Bitmap.Config.ARGB_8888, false)
|
||||
return converted ?: bitmap
|
||||
}
|
||||
|
||||
fun close() {
|
||||
depthEstimator.close()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user