|
|
@ -2,26 +2,33 @@ package example.imageviewer.storage |
|
|
|
|
|
|
|
|
|
|
|
import androidx.compose.runtime.snapshots.SnapshotStateList |
|
|
|
import androidx.compose.runtime.snapshots.SnapshotStateList |
|
|
|
import androidx.compose.ui.graphics.ImageBitmap |
|
|
|
import androidx.compose.ui.graphics.ImageBitmap |
|
|
|
import androidx.compose.ui.graphics.toComposeImageBitmap |
|
|
|
|
|
|
|
import example.imageviewer.ImageStorage |
|
|
|
import example.imageviewer.ImageStorage |
|
|
|
import example.imageviewer.PlatformStorableImage |
|
|
|
import example.imageviewer.PlatformStorableImage |
|
|
|
import example.imageviewer.model.PictureData |
|
|
|
import example.imageviewer.model.PictureData |
|
|
|
import example.imageviewer.toImageBitmap |
|
|
|
import example.imageviewer.toImageBitmap |
|
|
|
import kotlinx.cinterop.CValue |
|
|
|
import kotlinx.cinterop.CValue |
|
|
|
import kotlinx.cinterop.addressOf |
|
|
|
|
|
|
|
import kotlinx.cinterop.useContents |
|
|
|
import kotlinx.cinterop.useContents |
|
|
|
import kotlinx.cinterop.usePinned |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
import kotlinx.coroutines.* |
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
|
|
|
|
import kotlinx.coroutines.IO |
|
|
|
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
|
|
|
|
import kotlinx.coroutines.withContext |
|
|
|
import kotlinx.serialization.decodeFromString |
|
|
|
import kotlinx.serialization.decodeFromString |
|
|
|
import kotlinx.serialization.encodeToString |
|
|
|
import kotlinx.serialization.encodeToString |
|
|
|
import kotlinx.serialization.json.Json |
|
|
|
import kotlinx.serialization.json.Json |
|
|
|
import org.jetbrains.skia.Image |
|
|
|
|
|
|
|
import platform.CoreGraphics.CGRectMake |
|
|
|
import platform.CoreGraphics.CGRectMake |
|
|
|
import platform.CoreGraphics.CGSize |
|
|
|
import platform.CoreGraphics.CGSize |
|
|
|
import platform.CoreGraphics.CGSizeMake |
|
|
|
import platform.CoreGraphics.CGSizeMake |
|
|
|
import platform.Foundation.* |
|
|
|
import platform.Foundation.NSBundle |
|
|
|
import platform.UIKit.* |
|
|
|
import platform.Foundation.NSData |
|
|
|
import platform.posix.memcpy |
|
|
|
import platform.Foundation.NSFileManager |
|
|
|
|
|
|
|
import platform.Foundation.NSURL |
|
|
|
|
|
|
|
import platform.Foundation.writeToURL |
|
|
|
|
|
|
|
import platform.UIKit.UIGraphicsBeginImageContextWithOptions |
|
|
|
|
|
|
|
import platform.UIKit.UIGraphicsEndImageContext |
|
|
|
|
|
|
|
import platform.UIKit.UIGraphicsGetImageFromCurrentImageContext |
|
|
|
|
|
|
|
import platform.UIKit.UIImage |
|
|
|
|
|
|
|
import platform.UIKit.UIImageJPEGRepresentation |
|
|
|
|
|
|
|
|
|
|
|
private const val maxStorableImageSizePx = 1200 |
|
|
|
private const val maxStorableImageSizePx = 1200 |
|
|
|
private const val storableThumbnailSizePx = 180 |
|
|
|
private const val storableThumbnailSizePx = 180 |
|
|
@ -31,11 +38,18 @@ class IosImageStorage( |
|
|
|
private val pictures: SnapshotStateList<PictureData>, |
|
|
|
private val pictures: SnapshotStateList<PictureData>, |
|
|
|
private val ioScope: CoroutineScope |
|
|
|
private val ioScope: CoroutineScope |
|
|
|
) : ImageStorage { |
|
|
|
) : ImageStorage { |
|
|
|
private val savePictureDir = File(NSFileManager.defaultManager.DocumentDirectory, "ImageViewer/takenPhotos/") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val PictureData.Camera.jpgFile get() = File(savePictureDir, "$id.jpg") |
|
|
|
private val savePictureDir = |
|
|
|
private val PictureData.Camera.thumbnailJpgFile get() = File(savePictureDir, "$id-thumbnail.jpg") |
|
|
|
File(NSFileManager.defaultManager.DocumentDirectory, "ImageViewer/takenPhotos/") |
|
|
|
private val PictureData.Camera.jsonFile get() = File(savePictureDir, "$id.json") |
|
|
|
|
|
|
|
|
|
|
|
private val PictureData.Camera.jpgFile |
|
|
|
|
|
|
|
get() = File(savePictureDir, "$id.jpg") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val PictureData.Camera.thumbnailJpgFile |
|
|
|
|
|
|
|
get() = File(savePictureDir, "$id-thumbnail.jpg") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val PictureData.Camera.jsonFile |
|
|
|
|
|
|
|
get() = File(savePictureDir, "$id.json") |
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
init { |
|
|
|
if (savePictureDir.isDirectory) { |
|
|
|
if (savePictureDir.isDirectory) { |
|
|
|