|
|
|
@ -1,6 +1,5 @@
|
|
|
|
|
package example.imageviewer |
|
|
|
|
|
|
|
|
|
import androidx.compose.runtime.snapshots.SnapshotStateList |
|
|
|
|
import androidx.compose.ui.graphics.ImageBitmap |
|
|
|
|
import androidx.compose.ui.graphics.toAwtImage |
|
|
|
|
import androidx.compose.ui.graphics.toComposeImageBitmap |
|
|
|
@ -13,25 +12,24 @@ private const val maxStorableImageSizePx = 2000
|
|
|
|
|
private const val storableThumbnailSizePx = 200 |
|
|
|
|
|
|
|
|
|
class DesktopImageStorage( |
|
|
|
|
private val pictures: SnapshotStateList<PictureData>, |
|
|
|
|
private val ioScope: CoroutineScope |
|
|
|
|
) : ImageStorage { |
|
|
|
|
private val largeImages = mutableMapOf<PictureData.Camera, ImageBitmap>() |
|
|
|
|
private val thumbnails = mutableMapOf<PictureData.Camera, ImageBitmap>() |
|
|
|
|
private val largeImages = mutableMapOf<String, ImageBitmap>() |
|
|
|
|
private val thumbnails = mutableMapOf<String, ImageBitmap>() |
|
|
|
|
|
|
|
|
|
override fun saveImage(picture: PictureData.Camera, image: PlatformStorableImage) { |
|
|
|
|
if (image.imageBitmap.width == 0 || image.imageBitmap.height == 0) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
ioScope.launch { |
|
|
|
|
largeImages[picture] = image.imageBitmap.fitInto(maxStorableImageSizePx) |
|
|
|
|
thumbnails[picture] = image.imageBitmap.fitInto(storableThumbnailSizePx) |
|
|
|
|
pictures.add(0, picture) |
|
|
|
|
largeImages[picture.id] = image.imageBitmap.fitInto(maxStorableImageSizePx) |
|
|
|
|
thumbnails[picture.id] = image.imageBitmap.fitInto(storableThumbnailSizePx) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun delete(picture: PictureData.Camera) { |
|
|
|
|
// For now, on Desktop pictures saving in memory. We don't need additional delete logic. |
|
|
|
|
largeImages.remove(picture.id) |
|
|
|
|
thumbnails.remove(picture.id) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun rewrite(picture: PictureData.Camera) { |
|
|
|
@ -39,11 +37,11 @@ class DesktopImageStorage(
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override suspend fun getThumbnail(picture: PictureData.Camera): ImageBitmap { |
|
|
|
|
return thumbnails[picture]!! |
|
|
|
|
return thumbnails[picture.id]!! |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override suspend fun getImage(picture: PictureData.Camera): ImageBitmap { |
|
|
|
|
return largeImages[picture]!! |
|
|
|
|
return largeImages[picture.id]!! |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|