@@ -36,6 +36,7 @@ import android.util.Size
3636import androidx.appcompat.app.AppCompatActivity
3737import androidx.core.graphics.scale
3838import androidx.lifecycle.lifecycleScope
39+ import com.radzivon.bartoshyk.avif.coder.AvifAnimatedDecoder
3940import com.radzivon.bartoshyk.avif.coder.HeifCoder
4041import com.radzivon.bartoshyk.avif.coder.PreciseMode
4142import com.radzivon.bartoshyk.avif.coder.PreferredColorConfig
@@ -103,21 +104,30 @@ class MainActivity : AppCompatActivity() {
103104// imageView.root.setImageBitmap(decoded100)
104105// binding.scrollViewContainer.addView(imageView.root)
105106// }
106- val coder = HeifCoder ( ToneMapper .REC2408 )
107+ val coder = HeifCoder (ToneMapper .REC2408 )
107108 val allFiles1 =
108- getAllFilesFromAssets().filter { it.contains(" .avif" ) || it.contains(" .heic" ) }
109+ getAllFilesFromAssets().filter {
110+ it.contains(" .avif" ) || it.contains(" .heic" ) || it.contains(
111+ " .heif"
112+ )
113+ }
109114 val allFiles2 =
110- getAllFilesFromAssets(path = " hdr" ).filter { it.contains(" .avif" ) || it.contains(" .heic" ) }
115+ getAllFilesFromAssets(path = " hdr" ).filter {
116+ it.contains(" .avif" ) || it.contains(" .heic" ) || it.contains(
117+ " .heif"
118+ )
119+ }
111120 var allFiles = mutableListOf<String >()
112121 allFiles.addAll(allFiles2)
113122 allFiles.addAll(allFiles1)
114- allFiles = allFiles.filter { it.contains(" WJS01456-Enhanced-NR-2 .avif" ) }.toMutableList()
123+ allFiles = allFiles.filter { it.contains(" test_1 .avif" ) }.toMutableList()
115124// allFiles = allFiles.filter { it.contains("bbb_alpha_inverted.avif") }.toMutableList()
116125 for (file in allFiles) {
117126 try {
118127 Log .d(" AVIF" , " start processing $file " )
119128 val buffer = this @MainActivity.assets.open(file).source().buffer()
120129 .readByteArray()
130+
121131 val size = coder.getSize(buffer)
122132 if (size != null ) {
123133// val bitmap = coder.decodeSampled(
@@ -132,9 +142,10 @@ class MainActivity : AppCompatActivity() {
132142
133143 var bitmap0 = coder.decodeSampled(
134144 byteArray = buffer,
135- scaledWidth = size.width / 2 ,
136- scaledHeight = size.height / 2 ,
145+ scaledWidth = size.width / 5 ,
146+ scaledHeight = size.height / 5 ,
137147 preferredColorConfig = PreferredColorConfig .RGBA_8888 ,
148+ scaleMode = ScaleMode .FILL ,
138149 scaleQuality = ScalingQuality .HIGH ,
139150 )
140151
@@ -154,8 +165,8 @@ class MainActivity : AppCompatActivity() {
154165 }
155166 )
156167
157- // val encode = coder.encodeAvif(bitmap = bmp1, quality = 55 )
158- // val bitmap = coder.decode(encode)
168+ val encode = coder.encodeAvif(bitmap = bmp1, quality = 75 )
169+ val bitmap = coder.decode(encode)
159170
160171 lifecycleScope.launch(Dispatchers .Main ) {
161172 val imageView = BindingImageViewBinding .inflate(
@@ -166,15 +177,15 @@ class MainActivity : AppCompatActivity() {
166177 imageView.root.setImageBitmap(bitmap0)
167178 binding.scrollViewContainer.addView(imageView.root)
168179 }
169- // lifecycleScope.launch(Dispatchers.Main) {
170- // val imageView = BindingImageViewBinding.inflate(
171- // layoutInflater,
172- // binding.scrollViewContainer,
173- // false
174- // )
175- // imageView.root.setImageBitmap(bitmap)
176- // binding.scrollViewContainer.addView(imageView.root)
177- // }
180+ lifecycleScope.launch(Dispatchers .Main ) {
181+ val imageView = BindingImageViewBinding .inflate(
182+ layoutInflater,
183+ binding.scrollViewContainer,
184+ false
185+ )
186+ imageView.root.setImageBitmap(bitmap)
187+ binding.scrollViewContainer.addView(imageView.root)
188+ }
178189 }
179190 } catch (e: Exception ) {
180191 Log .d(" AVIF" , e.toString())
0 commit comments