Skip to content

Commit 3a7fd6c

Browse files
committed
upgrade to 1.5.0
1 parent cbb9a81 commit 3a7fd6c

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

avifcoillibrary/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ dependencies {
6464
androidTestImplementation("androidx.test.ext:junit:1.1.5")
6565
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
6666
api("io.coil-kt:coil:2.4.0")
67-
api("com.github.awxkee:avif-coder:1.4.2")
67+
api("com.github.awxkee:avif-coder:1.5.0")
6868
}

avifcoillibrary/src/main/java/com/github/awxkee/avifcoil/decoder/HeifDecoder.kt

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2023 Radzivon Bartoshyk
5+
* avif-coder [https://github.com/awxkee/avif-coder]
6+
*
7+
* Created by Radzivon Bartoshyk on 23/09/2023
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in all
17+
* copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
* SOFTWARE.
26+
*
27+
*/
28+
129
package com.github.awxkee.avifcoil.decoder
230

31+
import android.content.Context
332
import android.graphics.Bitmap
433
import android.graphics.drawable.BitmapDrawable
534
import android.os.Build
@@ -17,11 +46,14 @@ import kotlinx.coroutines.runInterruptible
1746
import okio.ByteString.Companion.encodeUtf8
1847

1948
class HeifDecoder(
49+
private val context: Context?,
2050
private val source: SourceResult,
2151
private val options: Options,
2252
private val imageLoader: ImageLoader,
2353
) : Decoder {
2454

55+
private val coder = HeifCoder(context)
56+
2557
override suspend fun decode(): DecodeResult? = runInterruptible {
2658
// ColorSpace is preferred to be ignored due to lib is trying to handle all color profile by itself
2759
val sourceData = source.source.source().readByteArray()
@@ -42,7 +74,7 @@ class HeifDecoder(
4274

4375
if (options.size == coil.size.Size.ORIGINAL) {
4476
val originalImage =
45-
HeifCoder().decode(
77+
coder.decode(
4678
sourceData,
4779
preferredColorConfig = mPreferredColorConfig
4880
)
@@ -62,7 +94,7 @@ class HeifDecoder(
6294
}
6395

6496
val originalImage =
65-
HeifCoder().decodeSampled(
97+
coder.decodeSampled(
6698
sourceData,
6799
dstWidth,
68100
dstHeight,
@@ -77,15 +109,18 @@ class HeifDecoder(
77109
)
78110
}
79111

80-
class Factory : Decoder.Factory {
112+
/**
113+
* @param context is preferred to be set when displaying an HDR content to apply Vulkan shaders
114+
*/
115+
class Factory(private val context: Context?) : Decoder.Factory {
81116
override fun create(
82117
result: SourceResult,
83118
options: Options,
84119
imageLoader: ImageLoader
85120
): Decoder? {
86121
return if (AVAILABLE_BRANDS.any {
87122
result.source.source().rangeEquals(4, it)
88-
}) HeifDecoder(result, options, imageLoader) else null
123+
}) HeifDecoder(context, result, options, imageLoader) else null
89124
}
90125

91126
companion object {
@@ -101,5 +136,4 @@ class HeifDecoder(
101136
private val AVAILABLE_BRANDS = listOf(MIF, MSF, HEIC, HEIX, HEVC, HEVX, AVIF, AVIS)
102137
}
103138
}
104-
105139
}

0 commit comments

Comments
 (0)