Skip to content

Commit f0afbab

Browse files
committed
Vulkan PQ and HLG Transfer functions, Added proper license
1 parent 95ece44 commit f0afbab

File tree

93 files changed

+2680
-304
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+2680
-304
lines changed

app/src/androidTest/java/com/radzivon/bartoshyk/avif/ExampleInstrumentedTest.kt

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

328
import androidx.test.platform.app.InstrumentationRegistry

app/src/main/AndroidManifest.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
11
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ MIT License
4+
~
5+
~ Copyright (c) 2023 Radzivon Bartoshyk
6+
~
7+
~ Permission is hereby granted, free of charge, to any person obtaining a copy
8+
~ of this software and associated documentation files (the "Software"), to deal
9+
~ in the Software without restriction, including without limitation the rights
10+
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
~ copies of the Software, and to permit persons to whom the Software is
12+
~ furnished to do so, subject to the following conditions:
13+
~
14+
~ The above copyright notice and this permission notice shall be included in all
15+
~ copies or substantial portions of the Software.
16+
~
17+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
~ SOFTWARE.
24+
~
25+
-->
26+
227
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
328
xmlns:tools="http://schemas.android.com/tools">
429

app/src/main/java/com/radzivon/bartoshyk/avif/MainActivity.kt

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

328
import android.graphics.Bitmap
@@ -41,17 +66,19 @@ class MainActivity : AppCompatActivity() {
4166

4267
// Example of a call to a native method
4368
//
44-
val buffer = this.assets.open("federico-beccari-hlg.avif").source().buffer().readByteArray()
69+
val coder = HeifCoder(this)
70+
val buffer = this.assets.open("bt_2020_pq.avif").source().buffer().readByteArray()
4571
// assert(HeifCoder().isAvif(buffer))
46-
val size = HeifCoder().getSize(buffer)!!
72+
val size = coder.getSize(buffer)!!
4773
assert(size != null)
48-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
74+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
4975
val time = measureTimeMillis {
50-
val bitmap = HeifCoder().decodeSampled(
76+
val bitmap = coder.decodeSampled(
5177
buffer,
5278
size.width / 2,
5379
size.height / 2,
54-
PreferredColorConfig.RGB_565
80+
PreferredColorConfig.RGBA_F16,
81+
ScaleMode.RESIZE
5582
)
5683
// val opts = BitmapFactory.Options()
5784
// opts.inMutable = true
@@ -138,6 +165,7 @@ class MainActivity : AppCompatActivity() {
138165
}
139166

140167
private fun testEncoder(assetName: String) {
168+
val coder = HeifCoder(this)
141169
val buffer = this.assets.open(assetName).source().buffer().readByteArray()
142170
val opts = BitmapFactory.Options()
143171
opts.inMutable = true
@@ -151,7 +179,7 @@ class MainActivity : AppCompatActivity() {
151179
bitmap = rr
152180
// val newBitmap = bitmap.aspectFit(bitmap.width, bitmap.height)
153181
// bitmap.recycle()
154-
val bytes = HeifCoder().encodeAvif(bitmap)
182+
val bytes = coder.encodeAvif(bitmap)
155183
bitmap.recycle()
156184
val ff = File(this.filesDir, "${File(assetName).nameWithoutExtension}.avif")
157185
ff.delete()
@@ -202,7 +230,7 @@ class MainActivity : AppCompatActivity() {
202230
}
203231

204232
private fun writeHevc(bitmap: Bitmap) {
205-
val bytes = HeifCoder().encodeHeic(bitmap)
233+
val bytes = HeifCoder(this).encodeHeic(bitmap)
206234
val ff = File(this.filesDir, "result.heic")
207235
ff.delete()
208236
val output = FileOutputStream(ff)

app/src/main/java/com/radzivon/bartoshyk/avif/glide/AvifCoderByteBufferDecoder.kt

Lines changed: 31 additions & 2 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.radzivon.bartoshyk.avif.glide
230

31+
import android.content.Context
332
import android.graphics.Bitmap
433
import android.os.Build
534
import com.bumptech.glide.load.DecodeFormat
@@ -15,10 +44,10 @@ import com.radzivon.bartoshyk.avif.coder.PreferredColorConfig
1544
import com.radzivon.bartoshyk.avif.coder.ScaleMode
1645
import java.nio.ByteBuffer
1746

18-
class AvifCoderByteBufferDecoder(private val bitmapPool: BitmapPool) :
47+
class AvifCoderByteBufferDecoder(private val context: Context, private val bitmapPool: BitmapPool) :
1948
ResourceDecoder<ByteBuffer, Bitmap> {
2049

21-
private val coder = HeifCoder()
50+
private val coder = HeifCoder(context)
2251

2352
override fun handles(source: ByteBuffer, options: Options): Boolean {
2453
return coder.isSupportedImage(source)

app/src/main/java/com/radzivon/bartoshyk/avif/glide/AvifCoderStreamDecoder.kt

Lines changed: 31 additions & 2 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.radzivon.bartoshyk.avif.glide
230

31+
import android.content.Context
332
import android.graphics.Bitmap
433
import com.bumptech.glide.load.Options
534
import com.bumptech.glide.load.ResourceDecoder
@@ -8,10 +37,10 @@ import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
837
import com.bumptech.glide.util.ByteBufferUtil
938
import java.io.InputStream
1039

11-
class AvifCoderStreamDecoder(private val bitmapPool: BitmapPool) :
40+
class AvifCoderStreamDecoder(private val context: Context, private val bitmapPool: BitmapPool) :
1241
ResourceDecoder<InputStream, Bitmap> {
1342

14-
private val byteBufferDecoder = AvifCoderByteBufferDecoder(bitmapPool)
43+
private val byteBufferDecoder = AvifCoderByteBufferDecoder(context, bitmapPool)
1544

1645
override fun handles(source: InputStream, options: Options): Boolean {
1746
val bb = ByteBufferUtil.fromStream(source)

app/src/main/java/com/radzivon/bartoshyk/avif/glide/AvifGlideModule.kt

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
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.radzivon.bartoshyk.avif.glide
230

331
import android.content.Context
@@ -14,9 +42,11 @@ class AvifCoderGlideModule : LibraryGlideModule() {
1442
override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
1543
// Add the Avif ResourceDecoders before any of the available system decoders. This ensures that
1644
// the integration will be preferred for Avif images.
17-
val byteBufferBitmapDecoder = AvifCoderByteBufferDecoder(glide.bitmapPool)
45+
val byteBufferBitmapDecoder =
46+
AvifCoderByteBufferDecoder(context.applicationContext, glide.bitmapPool)
1847
registry.prepend(ByteBuffer::class.java, Bitmap::class.java, byteBufferBitmapDecoder)
19-
val streamBitmapDecoder = AvifCoderStreamDecoder(glide.bitmapPool)
48+
val streamBitmapDecoder =
49+
AvifCoderStreamDecoder(context.applicationContext, glide.bitmapPool)
2050
registry.prepend(InputStream::class.java, Bitmap::class.java, streamBitmapDecoder)
2151
}
2252
}

app/src/main/res/drawable-v24/ic_launcher_foreground.xml

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

app/src/main/res/drawable/ic_launcher_background.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
11
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ MIT License
4+
~
5+
~ Copyright (c) 2023 Radzivon Bartoshyk
6+
~
7+
~ Permission is hereby granted, free of charge, to any person obtaining a copy
8+
~ of this software and associated documentation files (the "Software"), to deal
9+
~ in the Software without restriction, including without limitation the rights
10+
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
~ copies of the Software, and to permit persons to whom the Software is
12+
~ furnished to do so, subject to the following conditions:
13+
~
14+
~ The above copyright notice and this permission notice shall be included in all
15+
~ copies or substantial portions of the Software.
16+
~
17+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
~ SOFTWARE.
24+
~
25+
-->
26+
227
<vector xmlns:android="http://schemas.android.com/apk/res/android"
328
android:width="108dp"
429
android:height="108dp"

app/src/main/res/layout/activity_main.xml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
11
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ MIT License
4+
~
5+
~ Copyright (c) 2023 Radzivon Bartoshyk
6+
~
7+
~ Permission is hereby granted, free of charge, to any person obtaining a copy
8+
~ of this software and associated documentation files (the "Software"), to deal
9+
~ in the Software without restriction, including without limitation the rights
10+
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
~ copies of the Software, and to permit persons to whom the Software is
12+
~ furnished to do so, subject to the following conditions:
13+
~
14+
~ The above copyright notice and this permission notice shall be included in all
15+
~ copies or substantial portions of the Software.
16+
~
17+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
~ SOFTWARE.
24+
~
25+
-->
26+
227
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
328
xmlns:app="http://schemas.android.com/apk/res-auto"
429
xmlns:tools="http://schemas.android.com/tools"
@@ -18,8 +43,8 @@
1843

1944
<ImageView
2045
android:id="@+id/imageView"
21-
android:layout_width="320dp"
22-
android:layout_height="320dp"
46+
android:layout_width="match_parent"
47+
android:layout_height="wrap_content"
2348
android:scaleType="fitCenter"
2449
app:layout_constraintBottom_toBottomOf="parent"
2550
app:layout_constraintEnd_toEndOf="parent"

0 commit comments

Comments
 (0)