feat: update thumbnail after photo processing and metadata changes
This commit is contained in:
1 parent
a1d144e49f
commit
146b89d9f4
2 files changed
+77
No files matched your search
@@ -1075,6 +1075,7 @@ object GalleryManager {
|
||||
noiseReduction = noiseReductionValue,
|
||||
chromaNoiseReduction = chromaNoiseReductionValue
|
||||
)
|
||||
// updateThumbnail(context, photoId, photoProcessor, metadata)
|
||||
if (shouldAutoSave) {
|
||||
exportPhoto(
|
||||
context,
|
||||
@@ -1235,6 +1236,7 @@ object GalleryManager {
|
||||
preparedGainmapResult = preparedGainmapResult
|
||||
)
|
||||
}
|
||||
updateThumbnail(context, photoId, photoProcessor, metadata)
|
||||
if (shouldAutoSave) {
|
||||
exportPhoto(
|
||||
context,
|
||||
@@ -1370,6 +1372,7 @@ object GalleryManager {
|
||||
noiseReduction = noiseReductionValue,
|
||||
chromaNoiseReduction = chromaNoiseReductionValue
|
||||
)
|
||||
// updateThumbnail(context, photoId, photoProcessor, metadata)
|
||||
|
||||
if (shouldAutoSave) {
|
||||
exportPhoto(
|
||||
@@ -1778,6 +1781,8 @@ object GalleryManager {
|
||||
}
|
||||
tempFile.renameTo(photoFile)
|
||||
generateBokehPhoto(context, photoId, metadata, result)
|
||||
|
||||
updateThumbnail(context, photoId, photoProcessor, metadata)
|
||||
// Auto Save
|
||||
if (shouldAutoSave) {
|
||||
exportPhoto(
|
||||
@@ -2525,6 +2530,46 @@ object GalleryManager {
|
||||
return loadBitmap(context, Uri.fromFile(photoFile), maxEdge, preserveHdr)
|
||||
}
|
||||
|
||||
suspend fun updateThumbnail(
|
||||
context: Context,
|
||||
photoId: String,
|
||||
photoProcessor: PhotoProcessor,
|
||||
metadata: MediaMetadata? = null
|
||||
) {
|
||||
withContext(Dispatchers.IO) {
|
||||
try {
|
||||
val resolvedMetadata = metadata ?: loadMetadata(context, photoId) ?: return@withContext
|
||||
// 加载原始位图,限制尺寸以提高性能
|
||||
val originalBitmap = loadOriginalBitmap(context, photoId, maxEdge = THUMBNAIL_MAX_EDGE)
|
||||
?: loadBitmap(context, photoId, maxEdge = THUMBNAIL_MAX_EDGE)
|
||||
?: return@withContext
|
||||
|
||||
// 应用所有效果(LUT、虚化、裁切、边框等)到缩略图尺寸的位图
|
||||
val processedBitmap = photoProcessor.processBitmap(
|
||||
context = context,
|
||||
photoId = photoId,
|
||||
input = originalBitmap,
|
||||
metadata = resolvedMetadata,
|
||||
sharpening = resolvedMetadata.sharpening ?: 0f,
|
||||
noiseReduction = resolvedMetadata.noiseReduction ?: 0f,
|
||||
chromaNoiseReduction = resolvedMetadata.chromaNoiseReduction ?: 0f,
|
||||
useComputationalAperture = true
|
||||
)
|
||||
|
||||
val thumbnailFile = getThumbnailFile(context, photoId)
|
||||
generateThumbnail(processedBitmap, thumbnailFile)
|
||||
|
||||
if (processedBitmap !== originalBitmap) {
|
||||
processedBitmap.recycle()
|
||||
}
|
||||
originalBitmap.recycle()
|
||||
PLog.d(TAG, "Thumbnail updated for photo: $photoId")
|
||||
} catch (e: Exception) {
|
||||
PLog.e(TAG, "Failed to update thumbnail for photo: $photoId", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun loadBitmap(context: Context, uri: Uri, maxEdge: Int? = null, preserveHdr: Boolean = false): Bitmap? {
|
||||
var infoSize: android.util.Size? = null
|
||||
var infoMimeType: String? = null
|
||||
|
||||
@@ -393,6 +393,12 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
if (!isActive) return@launch
|
||||
GalleryManager.saveBokehPhoto(context, photoData.id, bokeh)
|
||||
GalleryManager.deleteDetailHdrFile(context, photoData.id)
|
||||
GalleryManager.updateThumbnail(
|
||||
context = context,
|
||||
photoId = photoData.id,
|
||||
photoProcessor = contentRepository.photoProcessor,
|
||||
metadata = metadata
|
||||
)
|
||||
photoRefreshKeys[photoData.id] = System.currentTimeMillis()
|
||||
}
|
||||
}
|
||||
@@ -491,6 +497,12 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
noiseReduction = updatedMetadata.noiseReduction ?: 0f,
|
||||
chromaNoiseReduction = updatedMetadata.chromaNoiseReduction ?: 0f
|
||||
)
|
||||
GalleryManager.updateThumbnail(
|
||||
context = context,
|
||||
photoId = photo.id,
|
||||
photoProcessor = contentRepository.photoProcessor,
|
||||
metadata = updatedMetadata
|
||||
)
|
||||
|
||||
_isAiDenoising.value = false
|
||||
withContext(Dispatchers.Main) { onComplete(true) }
|
||||
@@ -540,6 +552,12 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
chromaNoiseReduction = updatedMetadata.chromaNoiseReduction ?: 0f
|
||||
)
|
||||
}
|
||||
GalleryManager.updateThumbnail(
|
||||
context = context,
|
||||
photoId = photo.id,
|
||||
photoProcessor = contentRepository.photoProcessor,
|
||||
metadata = updatedMetadata
|
||||
)
|
||||
invalidatePreviewCache(photo.id)
|
||||
photoRefreshKeys[photo.id] = System.currentTimeMillis()
|
||||
_isAiDenoising.value = false
|
||||
@@ -1776,6 +1794,13 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
if (updated != null) {
|
||||
currentMediaMetadata = updated
|
||||
mediaData.metadata = updated
|
||||
GalleryManager.updateThumbnail(
|
||||
context = context,
|
||||
photoId = mediaData.id,
|
||||
photoProcessor = contentRepository.photoProcessor,
|
||||
metadata = updated
|
||||
)
|
||||
photoRefreshKeys[mediaData.id] = System.currentTimeMillis()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2369,6 +2394,13 @@ class GalleryViewModel(application: Application) : AndroidViewModel(application)
|
||||
noiseReduction = success.noiseReduction ?: 0f,
|
||||
chromaNoiseReduction = success.chromaNoiseReduction ?: 0f
|
||||
)
|
||||
GalleryManager.updateThumbnail(
|
||||
context = context,
|
||||
photoId = targetPhotoId,
|
||||
photoProcessor = contentRepository.photoProcessor,
|
||||
metadata = success
|
||||
)
|
||||
photoRefreshKeys[targetPhotoId] = System.currentTimeMillis()
|
||||
}
|
||||
onComplete(success != null)
|
||||
} catch (e: Exception) {
|
||||
|
||||
Reference in new issue
Block a user