mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 08:38:14 +01:00
Drop std/png filter_and_swizzle_low_bit_depth
This commit is contained in:
1 parent
baad01d50f
commit
f1a8019f41
2 files changed
+2
-337
No files matched your search
+1
-174
@@ -96,10 +96,6 @@ pub struct decoder? implements base.image_decoder(
|
||||
|
||||
dst_palette : array[4 * 256] base.u8,
|
||||
src_palette : array[4 * 256] base.u8,
|
||||
|
||||
// scratch is used for low bit depths, expanding less-than-1 byte per pixel
|
||||
// to 1 byte per pixel before passing to this.swizzler.
|
||||
scratch : array[1024] base.u8,
|
||||
)
|
||||
|
||||
pub func decoder.set_quirk_enabled!(quirk: base.u32, enabled: base.bool) {
|
||||
@@ -302,7 +298,7 @@ pri func decoder.assign_filter_distance!() {
|
||||
}
|
||||
|
||||
this.filter_distance = 1
|
||||
choose filter_and_swizzle = [filter_and_swizzle_low_bit_depth]
|
||||
this.tricky = true
|
||||
|
||||
} else if this.color_type == 0 {
|
||||
if this.depth == 8 {
|
||||
@@ -696,9 +692,6 @@ pri func decoder.filter_and_swizzle!(dst: ptr base.pixel_buffer, workbuf: slice
|
||||
return "#bad filter"
|
||||
}
|
||||
|
||||
// filter_and_swizzle_low_bit_depth copy-pastes this filter_and_swizzle
|
||||
// function and adds code here to expand to 8 bits per pixel.
|
||||
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: dst,
|
||||
dst_palette: dst_palette,
|
||||
@@ -711,172 +704,6 @@ pri func decoder.filter_and_swizzle!(dst: ptr base.pixel_buffer, workbuf: slice
|
||||
return ok
|
||||
}
|
||||
|
||||
pri func decoder.filter_and_swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, workbuf: slice base.u8) base.status {
|
||||
// This function is largely copy-pasted from filter_and_swizzle.
|
||||
// Differences are marked with a §.
|
||||
|
||||
var dst_pixfmt : base.pixel_format
|
||||
var dst_bits_per_pixel : base.u32[..= 256]
|
||||
var dst_bytes_per_pixel : base.u64[..= 32]
|
||||
var dst_bytes_per_row : base.u64
|
||||
var dst_palette : slice base.u8
|
||||
var tab : table base.u8
|
||||
|
||||
var y : base.u32
|
||||
var dst : slice base.u8
|
||||
var filter : base.u8
|
||||
var curr_row : slice base.u8
|
||||
var prev_row : slice base.u8
|
||||
|
||||
// TODO: the dst_pixfmt variable shouldn't be necessary. We should be able
|
||||
// to chain the two calls: "args.dst.pixel_format().bits_per_pixel()".
|
||||
dst_pixfmt = args.dst.pixel_format()
|
||||
dst_bits_per_pixel = dst_pixfmt.bits_per_pixel()
|
||||
if (dst_bits_per_pixel & 7) <> 0 {
|
||||
return base."#unsupported option"
|
||||
}
|
||||
dst_bytes_per_pixel = (dst_bits_per_pixel / 8) as base.u64
|
||||
dst_bytes_per_row = (this.width as base.u64) * dst_bytes_per_pixel
|
||||
dst_palette = args.dst.palette_or_else(fallback: this.dst_palette[..])
|
||||
tab = args.dst.plane(p: 0)
|
||||
|
||||
while y < this.height {
|
||||
assert y < 0x00FF_FFFF via "a < b: a < c; c <= b"(c: this.height)
|
||||
dst = tab.row(y: y)
|
||||
if dst_bytes_per_row < dst.length() {
|
||||
dst = dst[.. dst_bytes_per_row]
|
||||
}
|
||||
|
||||
if 1 > args.workbuf.length() {
|
||||
return "#internal error: inconsistent workbuf length"
|
||||
}
|
||||
filter = args.workbuf[0]
|
||||
args.workbuf = args.workbuf[1 ..]
|
||||
if this.pass_bytes_per_row > args.workbuf.length() {
|
||||
return "#internal error: inconsistent workbuf length"
|
||||
}
|
||||
curr_row = args.workbuf[.. this.pass_bytes_per_row]
|
||||
args.workbuf = args.workbuf[this.pass_bytes_per_row ..]
|
||||
|
||||
if filter == 0 {
|
||||
// No-op.
|
||||
} else if filter == 1 {
|
||||
this.filter_1!(curr: curr_row)
|
||||
} else if filter == 2 {
|
||||
this.filter_2!(curr: curr_row, prev: prev_row)
|
||||
} else if filter == 3 {
|
||||
this.filter_3!(curr: curr_row, prev: prev_row)
|
||||
} else if filter == 4 {
|
||||
this.filter_4!(curr: curr_row, prev: prev_row)
|
||||
} else {
|
||||
return "#bad filter"
|
||||
}
|
||||
|
||||
this.swizzle_low_bit_depth!( // §
|
||||
dst: dst,
|
||||
dst_palette: dst_palette,
|
||||
dst_bytes_per_pixel: dst_bytes_per_pixel,
|
||||
curr_row: curr_row)
|
||||
|
||||
prev_row = curr_row
|
||||
y += 1
|
||||
} endwhile
|
||||
|
||||
return ok
|
||||
}
|
||||
|
||||
pri func decoder.swizzle_low_bit_depth!(dst: slice base.u8, dst_palette: slice base.u8, dst_bytes_per_pixel: base.u64[..= 32], curr_row: slice base.u8) {
|
||||
var multiplier : base.u8
|
||||
var c : base.u8
|
||||
var i : base.u64
|
||||
var n : base.u64
|
||||
var fragment : slice base.u8
|
||||
var remaining : slice base.u8
|
||||
|
||||
multiplier = 1
|
||||
if this.color_type == 0 { // Color type 0 means base.PIXEL_FORMAT__Y.
|
||||
multiplier = LOW_BIT_DEPTH_MULTIPLIERS[this.depth & 7]
|
||||
}
|
||||
|
||||
remaining = args.curr_row
|
||||
while args.dst.length() > 0 {
|
||||
fragment = remaining
|
||||
remaining = this.util.empty_slice_u8()
|
||||
|
||||
if this.depth == 1 {
|
||||
if fragment.length() > 128 {
|
||||
remaining = fragment[128 ..]
|
||||
fragment = fragment[.. 128]
|
||||
assert fragment.length() <= 128
|
||||
}
|
||||
i = 0
|
||||
while i < fragment.length(),
|
||||
inv fragment.length() <= 128,
|
||||
{
|
||||
assert i < 128 via "a < b: a < c; c <= b"(c: fragment.length())
|
||||
c = fragment[i]
|
||||
this.scratch[(i * 8) + 0] = (0b0001 & (c >> 7)) ~mod* multiplier
|
||||
this.scratch[(i * 8) + 1] = (0b0001 & (c >> 6)) ~mod* multiplier
|
||||
this.scratch[(i * 8) + 2] = (0b0001 & (c >> 5)) ~mod* multiplier
|
||||
this.scratch[(i * 8) + 3] = (0b0001 & (c >> 4)) ~mod* multiplier
|
||||
this.scratch[(i * 8) + 4] = (0b0001 & (c >> 3)) ~mod* multiplier
|
||||
this.scratch[(i * 8) + 5] = (0b0001 & (c >> 2)) ~mod* multiplier
|
||||
this.scratch[(i * 8) + 6] = (0b0001 & (c >> 1)) ~mod* multiplier
|
||||
this.scratch[(i * 8) + 7] = (0b0001 & (c >> 0)) ~mod* multiplier
|
||||
i += 1
|
||||
} endwhile
|
||||
|
||||
} else if this.depth == 2 {
|
||||
if fragment.length() > 256 {
|
||||
remaining = fragment[256 ..]
|
||||
fragment = fragment[.. 256]
|
||||
assert fragment.length() <= 256
|
||||
}
|
||||
i = 0
|
||||
while i < fragment.length(),
|
||||
inv fragment.length() <= 256,
|
||||
{
|
||||
assert i < 256 via "a < b: a < c; c <= b"(c: fragment.length())
|
||||
c = fragment[i]
|
||||
this.scratch[(i * 4) + 0] = (0b0011 & (c >> 6)) ~mod* multiplier
|
||||
this.scratch[(i * 4) + 1] = (0b0011 & (c >> 4)) ~mod* multiplier
|
||||
this.scratch[(i * 4) + 2] = (0b0011 & (c >> 2)) ~mod* multiplier
|
||||
this.scratch[(i * 4) + 3] = (0b0011 & (c >> 0)) ~mod* multiplier
|
||||
i += 1
|
||||
} endwhile
|
||||
|
||||
} else {
|
||||
if fragment.length() > 512 {
|
||||
remaining = fragment[512 ..]
|
||||
fragment = fragment[.. 512]
|
||||
assert fragment.length() <= 512
|
||||
}
|
||||
i = 0
|
||||
while i < fragment.length(),
|
||||
inv fragment.length() <= 512,
|
||||
{
|
||||
assert i < 512 via "a < b: a < c; c <= b"(c: fragment.length())
|
||||
c = fragment[i]
|
||||
this.scratch[(i * 2) + 0] = (0b1111 & (c >> 4)) ~mod* multiplier
|
||||
this.scratch[(i * 2) + 1] = (0b1111 & (c >> 0)) ~mod* multiplier
|
||||
i += 1
|
||||
} endwhile
|
||||
}
|
||||
|
||||
this.swizzler.swizzle_interleaved_from_slice!(
|
||||
dst: args.dst,
|
||||
dst_palette: args.dst_palette,
|
||||
src: this.scratch[.. 1024])
|
||||
|
||||
n = 1024 * args.dst_bytes_per_pixel
|
||||
if n < args.dst.length() {
|
||||
args.dst = args.dst[n ..]
|
||||
} else {
|
||||
args.dst = this.util.empty_slice_u8()
|
||||
}
|
||||
} endwhile
|
||||
}
|
||||
|
||||
pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
|
||||
return this.util.make_rect_ie_u32(
|
||||
min_incl_x: 0,
|
||||
|
||||
Reference in new issue
Block a user