@@ -3,25 +3,59 @@ package com.cyanchill.missingcore.metadataretriever.models
33import com.facebook.react.bridge.Arguments
44import com.facebook.react.bridge.ReadableMap
55
6+ import android.graphics.Bitmap
67import android.net.Uri
78import android.os.Bundle
89
910class ArtworkOptions (options : ReadableMap ) {
1011 /* * If we want to return the artwork as a base64 string. */
1112 val asBase64: Boolean
1213
14+ /* * A value in the range `0.0` - `1.0` specifying the quality of the resulting image. */
15+ val compress: Double
16+ /* * Specifies the format the image will be saved in. */
17+ val format: ImageFormat
1318 /* * Location where we want to save the image. */
1419 val saveUri: String?
15- /* * Save the image at 80% quality. */
16- val compress: Boolean
1720
1821 init {
1922 val optionsBundle = Arguments .toBundle(options) as Bundle
2023 asBase64 = optionsBundle.getBoolean(" base64" )
21- compress = optionsBundle.getBoolean(" compress" )
24+
25+ compress = if (optionsBundle.containsKey(" compress" )) optionsBundle.getDouble(" compress" ) else 1.0
26+ // Default format to JPEG if it's not provided.
27+ format = ImageFormat .fromCode(optionsBundle.getString(" format" )) ? : ImageFormat .JPEG
2228
2329 // Remove `file://` in `saveUri` if provided.
2430 val uri = optionsBundle.getString(" saveUri" )
2531 saveUri = if (uri != null ) Uri .parse(uri).path else null
2632 }
2733}
34+
35+ enum class ImageFormat (val code : String ) {
36+ JPEG (" jpeg" ),
37+ JPG (" jpg" ),
38+ PNG (" png" ),
39+ WEBP (" webp" );
40+
41+ val fileExtension: String
42+ get() = when (this ) {
43+ JPEG , JPG -> " .jpg"
44+ PNG -> " .png"
45+ WEBP -> " .webp"
46+ }
47+
48+ val compressFormat: Bitmap .CompressFormat
49+ get() = when (this ) {
50+ JPEG , JPG -> Bitmap .CompressFormat .JPEG
51+ PNG -> Bitmap .CompressFormat .PNG
52+ WEBP -> Bitmap .CompressFormat .WEBP
53+ }
54+
55+ companion object {
56+ fun fromCode (code : String? ): ImageFormat ? {
57+ if (code == null ) return null
58+ return entries.find { it.code == code }
59+ }
60+ }
61+ }
0 commit comments