mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00: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
@@ -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