Skip to content

Commit 8fecdb7

Browse files
authored
Merge pull request #32 from awxkee/dev
A lot of improvements
2 parents 5e7fb3b + 61e87d5 commit 8fecdb7

File tree

28 files changed

+1538
-570
lines changed

28 files changed

+1538
-570
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ android {
4545

4646
dependencies {
4747
implementation project(":avif-coder")
48+
// implementation 'com.github.awxkee:avif-coder:1.8.0'
4849
implementation 'androidx.core:core-ktx:1.13.1'
4950
implementation 'androidx.appcompat:appcompat:1.7.0'
5051
implementation 'com.google.android.material:material:1.12.0'

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

Lines changed: 18 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,9 @@ import android.util.Size
3636
import androidx.appcompat.app.AppCompatActivity
3737
import androidx.core.graphics.scale
3838
import androidx.lifecycle.lifecycleScope
39-
import com.radzivon.bartoshyk.avif.coder.AvifAnimatedDecoder
40-
import com.radzivon.bartoshyk.avif.coder.AvifChromaSubsampling
4139
import com.radzivon.bartoshyk.avif.coder.HeifCoder
42-
import com.radzivon.bartoshyk.avif.coder.HeifPreset
43-
import com.radzivon.bartoshyk.avif.coder.PreciseMode
4440
import com.radzivon.bartoshyk.avif.coder.PreferredColorConfig
4541
import com.radzivon.bartoshyk.avif.coder.ScaleMode
46-
import com.radzivon.bartoshyk.avif.coder.ScalingQuality
4742
import com.radzivon.bartoshyk.avif.coder.ToneMapper
4843
import com.radzivon.bartoshyk.avif.databinding.ActivityMainBinding
4944
import com.radzivon.bartoshyk.avif.databinding.BindingImageViewBinding
@@ -57,6 +52,7 @@ import java.io.File
5752
import java.io.FileNotFoundException
5853
import java.io.FileOutputStream
5954
import java.io.IOException
55+
import kotlin.system.measureTimeMillis
6056

6157

6258
class MainActivity : AppCompatActivity() {
@@ -122,9 +118,10 @@ class MainActivity : AppCompatActivity() {
122118
var allFiles = mutableListOf<String>()
123119
allFiles.addAll(allFiles2)
124120
allFiles.addAll(allFiles1)
121+
allFiles = allFiles.take(5).toMutableList()
125122
// allFiles = allFiles.filter { it.contains("wide_gamut.avif") || it.contains("IMG_0199_rr.avif") || it.contains("bt_2020_pq.avif") }.toMutableList()
126123
// allFiles = allFiles.filter { it.contains("bbb_alpha_inverted.avif") }.toMutableList()
127-
// allFiles = allFiles.filter { it.contains("bt_2020_pq.avif") }.toMutableList()
124+
// allFiles = allFiles.filter { it.contains("test_alpha.avif") }.toMutableList()
128125
for (file in allFiles) {
129126
try {
130127
Log.d("AVIF", "start processing $file")
@@ -134,30 +131,30 @@ class MainActivity : AppCompatActivity() {
134131
val size = coder.getSize(buffer)
135132
if (size != null) {
136133
val bitmap0 = coder.decodeSampled(
137-
buffer,
138-
if (size.width > 1800 || size.height > 1800) size.width / 4 else size.width,
139-
if (size.width > 1800 || size.height > 1800) size.height / 4 else size.height,
140-
PreferredColorConfig.RGBA_8888,
141-
ScaleMode.RESIZE
134+
buffer,
135+
if (size.width > 1800 || size.height > 1800) size.width / 4 else size.width,
136+
if (size.width > 1800 || size.height > 1800) size.height / 4 else size.height,
137+
PreferredColorConfig.RGBA_1010102,
138+
ScaleMode.RESIZE
142139
)
143140
var start = System.currentTimeMillis()
144141

145142
// var bitmap0 = coder.decode(
146143
// byteArray = buffer,
147-
// preferredColorConfig = PreferredColorConfig.RGBA_8888,
144+
// preferredColorConfig = PreferredColorConfig.RGBA_F16,
148145
// )
149146

150147
Log.d("AVIFFFF", "Decode time ${System.currentTimeMillis() - start}")
151148

152-
val encode = coder.encodeAvif(bitmap0, avifChromaSubsampling = AvifChromaSubsampling.YUV422)
153-
val roundTripped = coder.decode(encode)
149+
// val encode = coder.encodeAvif(bitmap0, avifChromaSubsampling = AvifChromaSubsampling.YUV420)
150+
// val roundTripped = coder.decode(encode)
154151
//
155-
val cachedFile = File(cacheDir, "yuv400.avif")
156-
FileOutputStream(cachedFile).use {
157-
val bf = it.sink().buffer()
158-
bf.write(encode)
159-
bf.flush()
160-
}
152+
// val cachedFile = File(cacheDir, "yuv400.avif")
153+
// FileOutputStream(cachedFile).use {
154+
// val bf = it.sink().buffer()
155+
// bf.write(encode)
156+
// bf.flush()
157+
// }
161158
//
162159
// val round = coder.decode(
163160
// byteArray = encode,
@@ -172,7 +169,7 @@ class MainActivity : AppCompatActivity() {
172169
binding.scrollViewContainer,
173170
false
174171
)
175-
imageView.root.setImageBitmap(roundTripped)
172+
imageView.root.setImageBitmap(bitmap0)
176173
binding.scrollViewContainer.addView(imageView.root)
177174
}
178175
// lifecycleScope.launch(Dispatchers.Main) {
@@ -194,76 +191,6 @@ class MainActivity : AppCompatActivity() {
194191
}
195192
}
196193
}
197-
198-
// https://wh.aimuse.online/creatives/IMUSE_03617fe2db82a584166_27/TT_a9d21ff1061d785347935fef/68f06252.avif
199-
// https://wh.aimuse.online/preset/federico-beccari.avif
200-
// https://wh.aimuse.online/preset/avif10bit.avif
201-
//
202-
// Glide.with(this)
203-
// .load("https://wh.aimuse.online/preset/federico-beccari.avif")
204-
// .skipMemoryCache(true)
205-
// .into(binding.imageView)
206-
207-
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
208-
// binding.imageView.load("https://wh.aimuse.online/preset/federico-beccari.avif",
209-
// imageLoader = ImageLoader.Builder(this)
210-
// .components {
211-
// add(HeifDecoder.Factory())
212-
// }
213-
// .bitmapConfig(Bitmap.Config.RGBA_F16)
214-
// .build())
215-
// }
216-
217-
// binding.imageView.setImageBitmap(bitmap)
218-
// binding.imageView.setImageBitmap(cc16)
219-
// val avif12DepthBuffer =
220-
// this.assets.open("test_avif_12_bitdepth.avif").source().buffer().readByteArray()
221-
// assert(HeifCoder().isAvif(avif12DepthBuffer))
222-
// val avifHDRBitmap = HeifCoder().decode(avif12DepthBuffer)
223-
// binding.imageView.setImageBitmap(avifHDRBitmap)
224-
// val heicBuffer = this.assets.open("pexels-heif.heif").source().buffer().readByteArray()
225-
// assert(HeifCoder().isHeif(heicBuffer))
226-
// val heicBitmap = HeifCoder().decode(heicBuffer)
227-
// binding.imageView.setImageBitmap(heicBitmap)
228-
// assert(HeifCoder().getSize(heicBuffer) != null)
229-
// assert(HeifCoder().getSize(buffer) != null)
230-
// val heicScaled = HeifCoder().decodeSampled(heicBuffer, 350, 900)
231-
// binding.imageView.setImageBitmap(heicScaled)
232-
// val extremlyLargeBitmapBuffer =
233-
// this.assets.open("extremly_large.avif").source().buffer().readByteArray()
234-
// assert(HeifCoder().isAvif(extremlyLargeBitmapBuffer))
235-
// val extremlyLargeBitmap = HeifCoder().decode(extremlyLargeBitmapBuffer)
236-
// binding.imageView.setImageBitmap(extremlyLargeBitmap)
237-
238-
// val ff = File(this.filesDir, "result.avif")
239-
// ff.delete()
240-
// val output = FileOutputStream(ff)
241-
// output.sink().buffer().use {
242-
// it.write(bytes)
243-
// it.flush()
244-
// }
245-
// output.close()
246-
// Log.d("p", bytes.size.toString())
247-
// writeHevc(decodedBitmap)
248-
// val numbers = IntArray(5) { 1 * (it + 1) }
249-
// numbers.forEach {
250-
// testEncoder("test_${it}.jpg")
251-
// }
252-
// val bytes = HeifCoder().encodeAvif(cc16)
253-
// val ff = File(this.filesDir, "result.avif")
254-
// ff.delete()
255-
// val output = FileOutputStream(ff)
256-
// output.sink().buffer().use {
257-
// it.write(bytes)
258-
// it.flush()
259-
// }
260-
// output.close()
261-
// Log.d("p", bytes.size.toString())
262-
// writeHevc(decodedBitmap)
263-
// val numbers = IntArray(5) { 1 * (it + 1) }
264-
// numbers.forEach {
265-
// testEncoder("test_${it}.jpg")
266-
// }
267194
}
268195

269196
private fun testEncoder(assetName: String) {

avif-coder/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ afterEvaluate {
4242
create<MavenPublication>("mavenJava") {
4343
groupId = "com.github.awxkee"
4444
artifactId = "avif-coder"
45-
version = "2.0.9"
45+
version = "2.0.11"
4646
from(components["release"])
4747
// artifact("androidSourcesJar")
4848
}

avif-coder/src/main/cpp/CMakeLists.txt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ add_library(coder SHARED JniEncoder.cpp JniException.cpp SizeScaler.cpp
1616
HardwareBuffersCompat.cpp imagebits/half.cpp
1717
imagebits/half.hpp imagebits/RgbaU16toHF.cpp
1818
imagebits/RGBAlpha.cpp
19-
colorspace/Trc.cpp YuvConversion.cpp
19+
colorspace/Trc.cpp
2020
colorspace/Rec2408ToneMapper.cpp colorspace/LogarithmicToneMapper.cpp
2121
colorspace/ColorMatrix.cpp imagebits/ScanAlpha.cpp imagebits/Rgba16.cpp
2222
AvifDecoderController.cpp HeifImageDecoder.cpp JniAnimatedController.cpp
@@ -48,9 +48,6 @@ list(APPEND EXTRA_LIBS cpufeatures)
4848
include(CheckCXXCompilerFlag)
4949
if (ANDROID_ABI STREQUAL arm64-v8a)
5050
add_definitions("-DHAVE_NEON=1")
51-
if (CMAKE_BUILD_TYPE STREQUAL "Release")
52-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -mfloat-abi=hard -ftree-vectorize")
53-
endif ()
5451
endif ()
5552

5653
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
@@ -84,6 +81,6 @@ include_directories(icc)
8481
add_subdirectory(avif)
8582

8683
target_link_libraries( # Specifies the target library.
87-
coder PRIVATE
84+
coder
8885
${log-lib} libheif cpufeatures libyuv -ljnigraphics aom avif_shared
89-
libde265 libdav1d libsharpyuv ${android-lib} avifweaver x265)
86+
libde265 libdav1d libsharpyuv ${android-lib} avifweaver x265 m c)

avif-coder/src/main/cpp/JniDecoder.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "AvifDecoderController.h"
1919
#include "ReformatBitmap.h"
2020
#include "JniBitmap.h"
21+
#include <dlfcn.h>
2122

2223
using namespace std;
2324

@@ -28,6 +29,7 @@ jobject decodeImplementationNative(JNIEnv *env, jobject thiz,
2829
PreferredColorConfig preferredColorConfig;
2930
ScaleMode scaleMode;
3031
CurveToneMapper toneMapper;
32+
3133
if (!checkDecodePreconditions(env, javaColorSpace, &preferredColorConfig, javaScaleMode,
3234
&scaleMode, javaToneMapper, &toneMapper)) {
3335
string exception = "Can't retrieve basic values";

0 commit comments

Comments
 (0)