Skip to content

Commit d088c2e

Browse files
committed
Fixes
1 parent 7253af4 commit d088c2e

File tree

12 files changed

+95
-31
lines changed

12 files changed

+95
-31
lines changed

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

+16-7
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class MainActivity : AppCompatActivity() {
122122
var allFiles = mutableListOf<String>()
123123
allFiles.addAll(allFiles2)
124124
allFiles.addAll(allFiles1)
125-
allFiles = allFiles.filter { it.contains("output_shot.avif") }.toMutableList()
125+
allFiles = allFiles.filter { it.contains("hato-wide-gamut-8bit.avif") }.toMutableList()
126126
// allFiles = allFiles.filter { it.contains("bbb_alpha_inverted.avif") }.toMutableList()
127127
for (file in allFiles) {
128128
try {
@@ -142,15 +142,24 @@ class MainActivity : AppCompatActivity() {
142142

143143
var start = System.currentTimeMillis()
144144

145-
var bitmap0 = coder.decodeSampled(
145+
var bitmap0 = coder.decode(
146146
byteArray = buffer,
147-
scaledWidth = 325,
148-
scaledHeight = 325,
149147
preferredColorConfig = PreferredColorConfig.RGBA_8888,
150-
scaleMode = ScaleMode.FILL,
151-
scaleQuality = ScalingQuality.FASTEST,
152148
)
153149

150+
Log.d("AVIFFFF", "Decode time ${System.currentTimeMillis() - start}")
151+
152+
// val encode = coder.encodeHeic(bitmap0)
153+
//
154+
// val round = coder.decodeSampled(
155+
// byteArray = encode,
156+
// scaledWidth = 700,
157+
// scaledHeight = 700,
158+
// preferredColorConfig = PreferredColorConfig.RGBA_8888,
159+
// scaleMode = ScaleMode.FIT,
160+
// scaleQuality = ScalingQuality.DEFAULT,
161+
// )
162+
154163
// bitmap0.setColorSpace(ColorSpace.getFromDataSpace(DataSpace.DATASPACE_BT2020_PQ)!!)
155164

156165
lifecycleScope.launch(Dispatchers.Main) {
@@ -168,7 +177,7 @@ class MainActivity : AppCompatActivity() {
168177
// binding.scrollViewContainer,
169178
// false
170179
// )
171-
// imageView.root.setImageBitmap(bitmap)
180+
// imageView.root.setImageBitmap(round)
172181
// binding.scrollViewContainer.addView(imageView.root)
173182
// }
174183
}

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "ColorSpaceProfile.h"
3838
#include <ITUR.h>
3939
#include "ColorMatrix.h"
40+
#include "avifweaver.h"
4041

4142
class AvifUniqueImage {
4243
public:
@@ -105,17 +106,17 @@ AvifImageFrame AvifDecoderController::getFrame(uint32_t frame,
105106
auto colorPrimaries = decoder->image->colorPrimaries;
106107
auto transferCharacteristics = decoder->image->transferCharacteristics;
107108

109+
uint32_t bitDepth = decoder->image->depth;
110+
108111
bool isImageRequires64Bit = avifImageUsesU16(decoder->image);
109112
if (isImageRequires64Bit) {
110113
avifUniqueImage.rgbImage.alphaPremultiplied = false;
111-
avifUniqueImage.rgbImage.depth = 16;
114+
avifUniqueImage.rgbImage.depth = bitDepth;
112115
} else {
113116
avifUniqueImage.rgbImage.alphaPremultiplied = false;
114117
avifUniqueImage.rgbImage.depth = 8;
115118
}
116119

117-
uint32_t bitDepth = avifUniqueImage.rgbImage.depth;
118-
119120
avifResult rgbResult = avifUniqueImage.allocateImage();
120121
if (rgbResult != AVIF_RESULT_OK) {
121122
std::string

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

+3
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ aligned_uint8_vector RescaleSourceImage(uint8_t *sourceData,
305305
imageWidth = scaledWidth;
306306
imageHeight = scaledHeight;
307307

308+
*imageWidthPtr = imageWidth;
309+
*imageHeightPtr = imageHeight;
310+
308311
if (xTranslation > 0 || yTranslation > 0) {
309312

310313
int left = std::max(xTranslation, 0);

avif-coder/src/main/cpp/avifweaver.h

+47
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,55 @@
44
#include <ostream>
55
#include <new>
66

7+
enum class YuvMatrix {
8+
Bt601 = 0,
9+
Bt709 = 1,
10+
Bt2020 = 2,
11+
};
12+
13+
enum class YuvStandardRange {
14+
Tv,
15+
Pc,
16+
};
17+
18+
enum class YuvType {
19+
Yuv420,
20+
Yuv422,
21+
Yuv444,
22+
};
23+
724
extern "C" {
825

26+
void weave_yuv8_to_rgba8(const uint8_t *y_plane,
27+
uint32_t y_stride,
28+
const uint8_t *u_plane,
29+
uint32_t u_stride,
30+
const uint8_t *v_plane,
31+
uint32_t v_stride,
32+
uint8_t *rgba,
33+
uint32_t dst_stride,
34+
uint32_t width,
35+
uint32_t height,
36+
YuvStandardRange range,
37+
YuvMatrix matrix,
38+
YuvType yuv_type);
39+
40+
void weave_yuv8_with_alpha_to_rgba8(const uint8_t *y_plane,
41+
uint32_t y_stride,
42+
const uint8_t *u_plane,
43+
uint32_t u_stride,
44+
const uint8_t *v_plane,
45+
uint32_t v_stride,
46+
const uint8_t *a_plane,
47+
uint32_t a_stride,
48+
uint8_t *rgba,
49+
uint32_t dst_stride,
50+
uint32_t width,
51+
uint32_t height,
52+
YuvStandardRange range,
53+
YuvMatrix matrix,
54+
YuvType yuv_type);
55+
956
void weave_scale_u8(const uint8_t *src,
1057
uint32_t src_stride,
1158
uint32_t width,
Binary file not shown.
Binary file not shown.
-162 KB
Binary file not shown.
Binary file not shown.

avifpixart/Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

avifpixart/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ num-traits = "0.2.19"
88
pic-scale = { version = "0.2.11", default-features = false }
99

1010
[target.'cfg(target_arch = "aarch64")'.dependencies]
11-
pic-scale = { version = "0.2.11", default-features = false }
11+
pic-scale = { version = "0.2.11", default-features = false, features = ["disable_simd"] }
1212

1313
[target.'cfg(target_arch = "x86")'.dependencies]
1414
pic-scale = { version = "0.2.11", default-features = false, features = ["disable_simd"] }
@@ -18,3 +18,7 @@ pic-scale = { version = "0.2.11", default-features = false, features = ["disable
1818

1919
[lib]
2020
crate-type = ["cdylib"]
21+
22+
[profile.release]
23+
lto = true
24+
codegen-units = 2

avifpixart/src/lib.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
*/
2929

30+
use pic_scale::{
31+
ImageSize, ImageStore, ResamplingFunction, Scaler, Scaling, ScalingU16, ThreadingPolicy,
32+
};
3033
use std::slice;
31-
use pic_scale::{ImageSize, ImageStore, ResamplingFunction, Scaler, Scaling, ScalingU16, ThreadingPolicy};
3234

3335
#[no_mangle]
3436
pub unsafe extern "C-unwind" fn weave_scale_u8(
@@ -81,7 +83,10 @@ pub unsafe extern "C-unwind" fn weave_scale_u8(
8183
false,
8284
);
8385

84-
for (dst_chunk, src_chunk) in dst_slice.chunks_mut(dst_stride as usize).zip(new_store.as_bytes().chunks(new_width as usize * 4)) {
86+
for (dst_chunk, src_chunk) in dst_slice
87+
.chunks_mut(dst_stride as usize)
88+
.zip(new_store.as_bytes().chunks(new_width as usize * 4))
89+
{
8590
for (dst, src) in dst_chunk.iter_mut().zip(src_chunk.iter()) {
8691
*dst = *src;
8792
}
@@ -108,21 +113,15 @@ pub unsafe extern "C-unwind" fn weave_scale_u16(
108113
for x in 0..width as usize {
109114
let px = lane.add(x * 4);
110115
let dst_px = dst_lane.get_unchecked_mut((x * 4)..);
111-
unsafe {
112-
*dst_px.get_unchecked_mut(0) = px.read_unaligned();
113-
*dst_px.get_unchecked_mut(1) = px.add(1).read_unaligned();
114-
*dst_px.get_unchecked_mut(2) = px.add(2).read_unaligned();
115-
*dst_px.get_unchecked_mut(3) = px.add(3).read_unaligned();
116-
}
116+
*dst_px.get_unchecked_mut(0) = px.read_unaligned();
117+
*dst_px.get_unchecked_mut(1) = px.add(1).read_unaligned();
118+
*dst_px.get_unchecked_mut(2) = px.add(2).read_unaligned();
119+
*dst_px.get_unchecked_mut(3) = px.add(3).read_unaligned();
117120
}
118121
}
119122

120-
let _source_store = ImageStore::<u16, 4>::new(
121-
_src_slice,
122-
width as usize,
123-
height as usize,
124-
)
125-
.unwrap();
123+
let _source_store =
124+
ImageStore::<u16, 4>::new(_src_slice, width as usize, height as usize).unwrap();
126125

127126
let mut scaler = Scaler::new(if method == 3 {
128127
ResamplingFunction::Lanczos3
@@ -133,16 +132,17 @@ pub unsafe extern "C-unwind" fn weave_scale_u16(
133132
});
134133
scaler.set_threading_policy(ThreadingPolicy::Adaptive);
135134

136-
let _new_store_stride = new_width * 4 * std::mem::size_of::<u16>() as u32;
137-
138135
let _new_store = scaler.resize_rgba_u16(
139136
ImageSize::new(new_width as usize, new_height as usize),
140137
_source_store,
141138
bit_depth,
142139
false,
143140
);
144141
let dst_slice = unsafe {
145-
slice::from_raw_parts_mut(dst as *mut u16, new_width as usize * 4 * new_height as usize)
142+
slice::from_raw_parts_mut(
143+
dst as *mut u16,
144+
new_width as usize * 4 * new_height as usize,
145+
)
146146
};
147147
for (src, dst) in _new_store.as_bytes().iter().zip(dst_slice.iter_mut()) {
148148
*dst = *src;

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
plugins {
33
id 'com.android.application' version '8.2.2' apply false
4-
id 'com.android.library' version '8.7.0' apply false
4+
id 'com.android.library' version '8.7.1' apply false
55
id 'org.jetbrains.kotlin.android' version '2.0.20' apply false
66
id 'com.google.devtools.ksp' version '2.0.20-1.0.25' apply false
77
}

0 commit comments

Comments
 (0)