mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Have std/png decode 16-bit depth images
This commit is contained in:
1 parent
b69e6964f7
commit
77d5fa01e5
3 files changed
+217
-16
No files matched your search
@@ -32732,6 +32732,12 @@ wuffs_png__decoder__assign_filter_distance(
|
||||
self->private_impl.f_dst_pixfmt = 2147485832;
|
||||
self->private_impl.f_src_pixfmt = 2684356744;
|
||||
self->private_impl.f_filter_distance = 3;
|
||||
} else if (self->private_impl.f_depth == 16) {
|
||||
self->private_impl.f_dst_pixfmt = 2164308923;
|
||||
self->private_impl.f_src_pixfmt = 2164308923;
|
||||
self->private_impl.f_filter_distance = 6;
|
||||
self->private_impl.choosy_filter_and_swizzle = (
|
||||
&wuffs_png__decoder__filter_and_swizzle_tricky);
|
||||
}
|
||||
} else if (self->private_impl.f_color_type == 3) {
|
||||
if (self->private_impl.f_depth == 8) {
|
||||
@@ -32740,11 +32746,30 @@ wuffs_png__decoder__assign_filter_distance(
|
||||
self->private_impl.f_filter_distance = 1;
|
||||
}
|
||||
} else if (self->private_impl.f_color_type == 4) {
|
||||
if (self->private_impl.f_depth == 8) {
|
||||
self->private_impl.f_dst_pixfmt = 2164295816;
|
||||
self->private_impl.f_src_pixfmt = 2164295816;
|
||||
self->private_impl.f_filter_distance = 2;
|
||||
self->private_impl.choosy_filter_and_swizzle = (
|
||||
&wuffs_png__decoder__filter_and_swizzle_tricky);
|
||||
} else if (self->private_impl.f_depth == 16) {
|
||||
self->private_impl.f_dst_pixfmt = 2164308923;
|
||||
self->private_impl.f_src_pixfmt = 2164308923;
|
||||
self->private_impl.f_filter_distance = 4;
|
||||
self->private_impl.choosy_filter_and_swizzle = (
|
||||
&wuffs_png__decoder__filter_and_swizzle_tricky);
|
||||
}
|
||||
} else if (self->private_impl.f_color_type == 6) {
|
||||
if (self->private_impl.f_depth == 8) {
|
||||
self->private_impl.f_dst_pixfmt = 2164295816;
|
||||
self->private_impl.f_src_pixfmt = 2701166728;
|
||||
self->private_impl.f_filter_distance = 4;
|
||||
} else if (self->private_impl.f_depth == 16) {
|
||||
self->private_impl.f_dst_pixfmt = 2164308923;
|
||||
self->private_impl.f_src_pixfmt = 2164308923;
|
||||
self->private_impl.f_filter_distance = 8;
|
||||
self->private_impl.choosy_filter_and_swizzle = (
|
||||
&wuffs_png__decoder__filter_and_swizzle_tricky);
|
||||
}
|
||||
}
|
||||
return wuffs_base__make_empty_struct();
|
||||
@@ -33874,8 +33899,8 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
|
||||
wuffs_base__slice_u8 v_s = {0};
|
||||
wuffs_base__slice_u8 v_curr_row = {0};
|
||||
wuffs_base__slice_u8 v_prev_row = {0};
|
||||
uint8_t v_bits_unpacked[8] = {0};
|
||||
uint8_t v_bits_packed = 0;
|
||||
uint8_t v_bits_unpacked[1] = {0};
|
||||
uint8_t v_packs_remaining = 0;
|
||||
uint8_t v_multiplier = 0;
|
||||
uint8_t v_shift = 0;
|
||||
@@ -33893,6 +33918,14 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
|
||||
if (self->private_impl.f_depth >= 8) {
|
||||
v_src_bytes_per_pixel = (((uint64_t)(WUFFS_PNG__NUM_CHANNELS[self->private_impl.f_color_type])) * ((uint64_t)((self->private_impl.f_depth >> 3))));
|
||||
}
|
||||
v_bits_unpacked[0] = 255;
|
||||
v_bits_unpacked[1] = 255;
|
||||
v_bits_unpacked[2] = 255;
|
||||
v_bits_unpacked[3] = 255;
|
||||
v_bits_unpacked[4] = 255;
|
||||
v_bits_unpacked[5] = 255;
|
||||
v_bits_unpacked[6] = 255;
|
||||
v_bits_unpacked[7] = 255;
|
||||
v_y = ((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][5]));
|
||||
while (v_y < self->private_impl.f_height) {
|
||||
v_dst = wuffs_base__table_u8__row(v_tab, v_y);
|
||||
@@ -33923,16 +33956,27 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
|
||||
}
|
||||
v_s = v_curr_row;
|
||||
v_x = ((uint32_t)(WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][2]));
|
||||
if (self->private_impl.f_depth >= 8) {
|
||||
if (self->private_impl.f_depth == 8) {
|
||||
while (v_x < self->private_impl.f_width) {
|
||||
v_i = (((uint64_t)(v_x)) * v_dst_bytes_per_pixel);
|
||||
if ((v_i <= ((uint64_t)(v_dst.len))) && (v_src_bytes_per_pixel <= ((uint64_t)(v_s.len)))) {
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__slice_u8__subslice_j(v_s, v_src_bytes_per_pixel));
|
||||
v_s = wuffs_base__slice_u8__subslice_i(v_s, v_src_bytes_per_pixel);
|
||||
if (v_i <= ((uint64_t)(v_dst.len))) {
|
||||
if (self->private_impl.f_color_type == 4) {
|
||||
if (2 <= ((uint64_t)(v_s.len))) {
|
||||
v_bits_unpacked[0] = v_s.ptr[0];
|
||||
v_bits_unpacked[1] = v_s.ptr[0];
|
||||
v_bits_unpacked[2] = v_s.ptr[0];
|
||||
v_bits_unpacked[3] = v_s.ptr[1];
|
||||
v_s = wuffs_base__slice_u8__subslice_i(v_s, 2);
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(v_bits_unpacked, 4));
|
||||
}
|
||||
} else if (v_src_bytes_per_pixel <= ((uint64_t)(v_s.len))) {
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__slice_u8__subslice_j(v_s, v_src_bytes_per_pixel));
|
||||
v_s = wuffs_base__slice_u8__subslice_i(v_s, v_src_bytes_per_pixel);
|
||||
}
|
||||
}
|
||||
v_x += (((uint32_t)(1)) << WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][0]);
|
||||
}
|
||||
} else {
|
||||
} else if (self->private_impl.f_depth < 8) {
|
||||
v_multiplier = 1;
|
||||
if (self->private_impl.f_color_type == 0) {
|
||||
v_multiplier = WUFFS_PNG__LOW_BIT_DEPTH_MULTIPLIERS[self->private_impl.f_depth];
|
||||
@@ -33954,6 +33998,59 @@ wuffs_png__decoder__filter_and_swizzle_tricky(
|
||||
}
|
||||
v_x += (((uint32_t)(1)) << WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][0]);
|
||||
}
|
||||
} else {
|
||||
while (v_x < self->private_impl.f_width) {
|
||||
v_i = (((uint64_t)(v_x)) * v_dst_bytes_per_pixel);
|
||||
if (v_i <= ((uint64_t)(v_dst.len))) {
|
||||
if (self->private_impl.f_color_type == 0) {
|
||||
if (2 <= ((uint64_t)(v_s.len))) {
|
||||
v_bits_unpacked[0] = v_s.ptr[1];
|
||||
v_bits_unpacked[1] = v_s.ptr[0];
|
||||
v_bits_unpacked[2] = v_s.ptr[1];
|
||||
v_bits_unpacked[3] = v_s.ptr[0];
|
||||
v_bits_unpacked[4] = v_s.ptr[1];
|
||||
v_bits_unpacked[5] = v_s.ptr[0];
|
||||
v_s = wuffs_base__slice_u8__subslice_i(v_s, 2);
|
||||
}
|
||||
} else if (self->private_impl.f_color_type == 2) {
|
||||
if (6 <= ((uint64_t)(v_s.len))) {
|
||||
v_bits_unpacked[0] = v_s.ptr[5];
|
||||
v_bits_unpacked[1] = v_s.ptr[4];
|
||||
v_bits_unpacked[2] = v_s.ptr[3];
|
||||
v_bits_unpacked[3] = v_s.ptr[2];
|
||||
v_bits_unpacked[4] = v_s.ptr[1];
|
||||
v_bits_unpacked[5] = v_s.ptr[0];
|
||||
v_s = wuffs_base__slice_u8__subslice_i(v_s, 6);
|
||||
}
|
||||
} else if (self->private_impl.f_color_type == 4) {
|
||||
if (4 <= ((uint64_t)(v_s.len))) {
|
||||
v_bits_unpacked[0] = v_s.ptr[1];
|
||||
v_bits_unpacked[1] = v_s.ptr[0];
|
||||
v_bits_unpacked[2] = v_s.ptr[1];
|
||||
v_bits_unpacked[3] = v_s.ptr[0];
|
||||
v_bits_unpacked[4] = v_s.ptr[1];
|
||||
v_bits_unpacked[5] = v_s.ptr[0];
|
||||
v_bits_unpacked[6] = v_s.ptr[3];
|
||||
v_bits_unpacked[7] = v_s.ptr[2];
|
||||
v_s = wuffs_base__slice_u8__subslice_i(v_s, 4);
|
||||
}
|
||||
} else {
|
||||
if (8 <= ((uint64_t)(v_s.len))) {
|
||||
v_bits_unpacked[0] = v_s.ptr[5];
|
||||
v_bits_unpacked[1] = v_s.ptr[4];
|
||||
v_bits_unpacked[2] = v_s.ptr[3];
|
||||
v_bits_unpacked[3] = v_s.ptr[2];
|
||||
v_bits_unpacked[4] = v_s.ptr[1];
|
||||
v_bits_unpacked[5] = v_s.ptr[0];
|
||||
v_bits_unpacked[6] = v_s.ptr[7];
|
||||
v_bits_unpacked[7] = v_s.ptr[6];
|
||||
v_s = wuffs_base__slice_u8__subslice_i(v_s, 8);
|
||||
}
|
||||
}
|
||||
wuffs_base__pixel_swizzler__swizzle_interleaved_from_slice(&self->private_impl.f_swizzler, wuffs_base__slice_u8__subslice_i(v_dst, v_i), v_dst_palette, wuffs_base__make_slice_u8(v_bits_unpacked, 8));
|
||||
}
|
||||
v_x += (((uint32_t)(1)) << WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][0]);
|
||||
}
|
||||
}
|
||||
v_prev_row = v_curr_row;
|
||||
v_y += (((uint32_t)(1)) << WUFFS_PNG__INTERLACING[self->private_impl.f_interlace_pass][3]);
|
||||
|
||||
@@ -313,6 +313,11 @@ pri func decoder.assign_filter_distance!() {
|
||||
this.dst_pixfmt = base.PIXEL_FORMAT__BGR
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__RGB
|
||||
this.filter_distance = 3
|
||||
} else if this.depth == 16 {
|
||||
this.dst_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
|
||||
this.filter_distance = 6
|
||||
choose filter_and_swizzle = [filter_and_swizzle_tricky]
|
||||
}
|
||||
|
||||
} else if this.color_type == 3 {
|
||||
@@ -323,13 +328,28 @@ pri func decoder.assign_filter_distance!() {
|
||||
}
|
||||
|
||||
} else if this.color_type == 4 {
|
||||
// TODO: PIXEL_FORMAT__YA_NONPREMUL
|
||||
if this.depth == 8 {
|
||||
this.dst_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
|
||||
this.filter_distance = 2
|
||||
choose filter_and_swizzle = [filter_and_swizzle_tricky]
|
||||
} else if this.depth == 16 {
|
||||
this.dst_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
|
||||
this.filter_distance = 4
|
||||
choose filter_and_swizzle = [filter_and_swizzle_tricky]
|
||||
}
|
||||
|
||||
} else if this.color_type == 6 {
|
||||
if this.depth == 8 {
|
||||
this.dst_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__RGBA_NONPREMUL
|
||||
this.filter_distance = 4
|
||||
} else if this.depth == 16 {
|
||||
this.dst_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE
|
||||
this.filter_distance = 8
|
||||
choose filter_and_swizzle = [filter_and_swizzle_tricky]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
|
||||
var curr_row : slice base.u8
|
||||
var prev_row : slice base.u8
|
||||
|
||||
var bits_unpacked : array[8] base.u8
|
||||
var bits_packed : base.u8
|
||||
var bits_unpacked : array[1] base.u8
|
||||
var packs_remaining : base.u8
|
||||
var multiplier : base.u8
|
||||
var shift : base.u8[..= 7]
|
||||
@@ -55,6 +55,15 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
|
||||
((this.depth >> 3) as base.u64)
|
||||
}
|
||||
|
||||
bits_unpacked[0] = 0xFF
|
||||
bits_unpacked[1] = 0xFF
|
||||
bits_unpacked[2] = 0xFF
|
||||
bits_unpacked[3] = 0xFF
|
||||
bits_unpacked[4] = 0xFF
|
||||
bits_unpacked[5] = 0xFF
|
||||
bits_unpacked[6] = 0xFF
|
||||
bits_unpacked[7] = 0xFF
|
||||
|
||||
y = INTERLACING[this.interlace_pass][5] as base.u32
|
||||
while y < this.height {
|
||||
assert y < 0x00FF_FFFF via "a < b: a < c; c <= b"(c: this.height)
|
||||
@@ -90,23 +99,37 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
|
||||
|
||||
s = curr_row
|
||||
x = INTERLACING[this.interlace_pass][2] as base.u32
|
||||
if this.depth >= 8 {
|
||||
if this.depth == 8 {
|
||||
while x < this.width,
|
||||
inv y < 0x00FF_FFFF,
|
||||
{
|
||||
assert x < 0x00FF_FFFF via "a < b: a < c; c <= b"(c: this.width)
|
||||
i = (x as base.u64) * dst_bytes_per_pixel
|
||||
if (i <= dst.length()) and (src_bytes_per_pixel <= s.length()) {
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst[i ..],
|
||||
dst_palette: dst_palette,
|
||||
src: s[.. src_bytes_per_pixel])
|
||||
s = s[src_bytes_per_pixel ..]
|
||||
if i <= dst.length() {
|
||||
if this.color_type == 4 {
|
||||
if 2 <= s.length() {
|
||||
bits_unpacked[0] = s[0]
|
||||
bits_unpacked[1] = s[0]
|
||||
bits_unpacked[2] = s[0]
|
||||
bits_unpacked[3] = s[1]
|
||||
s = s[2 ..]
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst[i ..],
|
||||
dst_palette: dst_palette,
|
||||
src: bits_unpacked[.. 4])
|
||||
}
|
||||
} else if src_bytes_per_pixel <= s.length() {
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst[i ..],
|
||||
dst_palette: dst_palette,
|
||||
src: s[.. src_bytes_per_pixel])
|
||||
s = s[src_bytes_per_pixel ..]
|
||||
}
|
||||
}
|
||||
x += (1 as base.u32) << INTERLACING[this.interlace_pass][0]
|
||||
} endwhile
|
||||
|
||||
} else {
|
||||
} else if this.depth < 8 {
|
||||
multiplier = 1
|
||||
if this.color_type == 0 { // Color type 0 means base.PIXEL_FORMAT__Y.
|
||||
multiplier = LOW_BIT_DEPTH_MULTIPLIERS[this.depth]
|
||||
@@ -137,6 +160,67 @@ pri func decoder.filter_and_swizzle_tricky!(dst: ptr base.pixel_buffer, workbuf:
|
||||
}
|
||||
x += (1 as base.u32) << INTERLACING[this.interlace_pass][0]
|
||||
} endwhile
|
||||
|
||||
} else {
|
||||
while x < this.width,
|
||||
inv y < 0x00FF_FFFF,
|
||||
{
|
||||
assert x < 0x00FF_FFFF via "a < b: a < c; c <= b"(c: this.width)
|
||||
i = (x as base.u64) * dst_bytes_per_pixel
|
||||
if i <= dst.length() {
|
||||
if this.color_type == 0 {
|
||||
if 2 <= s.length() {
|
||||
bits_unpacked[0] = s[1]
|
||||
bits_unpacked[1] = s[0]
|
||||
bits_unpacked[2] = s[1]
|
||||
bits_unpacked[3] = s[0]
|
||||
bits_unpacked[4] = s[1]
|
||||
bits_unpacked[5] = s[0]
|
||||
s = s[2 ..]
|
||||
}
|
||||
} else if this.color_type == 2 {
|
||||
if 6 <= s.length() {
|
||||
bits_unpacked[0] = s[5]
|
||||
bits_unpacked[1] = s[4]
|
||||
bits_unpacked[2] = s[3]
|
||||
bits_unpacked[3] = s[2]
|
||||
bits_unpacked[4] = s[1]
|
||||
bits_unpacked[5] = s[0]
|
||||
s = s[6 ..]
|
||||
}
|
||||
} else if this.color_type == 4 {
|
||||
if 4 <= s.length() {
|
||||
bits_unpacked[0] = s[1]
|
||||
bits_unpacked[1] = s[0]
|
||||
bits_unpacked[2] = s[1]
|
||||
bits_unpacked[3] = s[0]
|
||||
bits_unpacked[4] = s[1]
|
||||
bits_unpacked[5] = s[0]
|
||||
bits_unpacked[6] = s[3]
|
||||
bits_unpacked[7] = s[2]
|
||||
s = s[4 ..]
|
||||
}
|
||||
} else {
|
||||
if 8 <= s.length() {
|
||||
bits_unpacked[0] = s[5]
|
||||
bits_unpacked[1] = s[4]
|
||||
bits_unpacked[2] = s[3]
|
||||
bits_unpacked[3] = s[2]
|
||||
bits_unpacked[4] = s[1]
|
||||
bits_unpacked[5] = s[0]
|
||||
bits_unpacked[6] = s[7]
|
||||
bits_unpacked[7] = s[6]
|
||||
s = s[8 ..]
|
||||
}
|
||||
}
|
||||
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst[i ..],
|
||||
dst_palette: dst_palette,
|
||||
src: bits_unpacked[.. 8])
|
||||
}
|
||||
x += (1 as base.u32) << INTERLACING[this.interlace_pass][0]
|
||||
} endwhile
|
||||
}
|
||||
|
||||
prev_row = curr_row
|
||||
|
||||
Reference in new issue
Block a user