base: rename min/max arg to no_more/less_than

This commit is contained in:
Nigel Tao committed 2023-04-16 12:12:27 +10:00
1 parent 95630b6677
commit bc86394bef
8 files changed
+45 -44

No files matched your search

+1
View File
@@ -13,6 +13,7 @@ The dot points below probably aren't of interest unless you're _writing_ Wuffs
code (instead of writing C/C++ code that _uses_ Wuffs' standard library). code (instead of writing C/C++ code that _uses_ Wuffs' standard library).
- Added read-only type decorators: `roarray`, `roslice` and `rotable`. - Added read-only type decorators: `roarray`, `roslice` and `rotable`.
- Renamed `base` `min/max` argument from `a` to `no_more/less_than`.
- Wuffs struct private data now needs a "+" between the "()" pairs. - Wuffs struct private data now needs a "+" between the "()" pairs.
- `wuffsfmt` double-indents hanging lines and each indent is now 4 spaces (not - `wuffsfmt` double-indents hanging lines and each indent is now 4 spaces (not
a tab). a tab).
+8 -8
View File
@@ -347,23 +347,23 @@ var Funcs = [][]string{
var funcsOther = [...]string{ var funcsOther = [...]string{
"u8.high_bits(n: u32[..= 7]) u8", "u8.high_bits(n: u32[..= 7]) u8",
"u8.low_bits(n: u32[..= 7]) u8", "u8.low_bits(n: u32[..= 7]) u8",
"u8.max(a: u8) u8", "u8.max(no_less_than: u8) u8",
"u8.min(a: u8) u8", "u8.min(no_more_than: u8) u8",
"u16.high_bits(n: u32[..= 15]) u16", "u16.high_bits(n: u32[..= 15]) u16",
"u16.low_bits(n: u32[..= 15]) u16", "u16.low_bits(n: u32[..= 15]) u16",
"u16.max(a: u16) u16", "u16.max(no_less_than: u16) u16",
"u16.min(a: u16) u16", "u16.min(no_more_than: u16) u16",
"u32.high_bits(n: u32[..= 31]) u32", "u32.high_bits(n: u32[..= 31]) u32",
"u32.low_bits(n: u32[..= 31]) u32", "u32.low_bits(n: u32[..= 31]) u32",
"u32.max(a: u32) u32", "u32.max(no_less_than: u32) u32",
"u32.min(a: u32) u32", "u32.min(no_more_than: u32) u32",
"u64.high_bits(n: u32[..= 63]) u64", "u64.high_bits(n: u32[..= 63]) u64",
"u64.low_bits(n: u32[..= 63]) u64", "u64.low_bits(n: u32[..= 63]) u64",
"u64.max(a: u64) u64", "u64.max(no_less_than: u64) u64",
"u64.min(a: u64) u64", "u64.min(no_more_than: u64) u64",
// ---- utility // ---- utility
+10 -10
View File
@@ -577,7 +577,7 @@ pri func decoder.swizzle_none!(dst: ptr base.pixel_buffer, src: base.io_reader)
return "#unsupported BMP file" return "#unsupported BMP file"
} }
n = args.src.length() / (src_bytes_per_pixel as base.u64) n = args.src.length() / (src_bytes_per_pixel as base.u64)
n = n.min(a: (this.width ~mod- this.dst_x) as base.u64) n = n.min(no_more_than: (this.width ~mod- this.dst_x) as base.u64)
j = n j = n
while j >= 8 { while j >= 8 {
if args.src.length() >= ((src_bytes_per_pixel * 8) as base.u64) { if args.src.length() >= ((src_bytes_per_pixel * 8) as base.u64) {
@@ -770,7 +770,7 @@ pri func decoder.swizzle_rle!(dst: ptr base.pixel_buffer, src: base.io_reader) b
p0 = (p0 & 255) + 0x04 p0 = (p0 & 255) + 0x04
chunk_count -= 1 chunk_count -= 1
} endwhile } endwhile
p0 = p0.min(a: this.rle_length) p0 = p0.min(no_more_than: this.rle_length)
this.swizzler.swizzle_interleaved_from_slice!( this.swizzler.swizzle_interleaved_from_slice!(
dst: dst, dst: dst,
dst_palette: dst_palette, dst_palette: dst_palette,
@@ -930,7 +930,7 @@ pri func decoder.swizzle_bitfields!(dst: ptr base.pixel_buffer, src: base.io_rea
// -------- BEGIN convert to PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE. // -------- BEGIN convert to PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE.
p1_temp = this.width ~mod- this.dst_x p1_temp = this.width ~mod- this.dst_x
p1 = p1_temp.min(a: 256) p1 = p1_temp.min(no_more_than: 256)
p0 = 0 p0 = 0
while p0 < p1 { while p0 < p1 {
assert p0 < 256 via "a < b: a < c; c <= b"(c: p1) assert p0 < 256 via "a < b: a < c; c <= b"(c: p1)
@@ -1057,12 +1057,12 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
} }
while (chunk_count >= 64) and (args.src.length() >= 256) { while (chunk_count >= 64) and (args.src.length() >= 256) {
args.src.skip_u32_fast!(actual: 256, worst_case: 256) args.src.skip_u32_fast!(actual: 256, worst_case: 256)
this.dst_x = this.width.min(a: this.dst_x ~mod+ (pixels_per_chunk * 64)) this.dst_x = this.width.min(no_more_than: this.dst_x ~mod+ (pixels_per_chunk * 64))
chunk_count -= 64 chunk_count -= 64
} endwhile } endwhile
while (chunk_count >= 8) and (args.src.length() >= 32) { while (chunk_count >= 8) and (args.src.length() >= 32) {
args.src.skip_u32_fast!(actual: 32, worst_case: 32) args.src.skip_u32_fast!(actual: 32, worst_case: 32)
this.dst_x = this.width.min(a: this.dst_x ~mod+ (pixels_per_chunk * 8)) this.dst_x = this.width.min(no_more_than: this.dst_x ~mod+ (pixels_per_chunk * 8))
chunk_count -= 8 chunk_count -= 8
} endwhile } endwhile
while chunk_count > 0 { while chunk_count > 0 {
@@ -1070,7 +1070,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
return "@internal note: short read" return "@internal note: short read"
} }
args.src.skip_u32_fast!(actual: 4, worst_case: 4) args.src.skip_u32_fast!(actual: 4, worst_case: 4)
this.dst_x = this.width.min(a: this.dst_x ~mod+ (pixels_per_chunk * 1)) this.dst_x = this.width.min(no_more_than: this.dst_x ~mod+ (pixels_per_chunk * 1))
chunk_count -= 1 chunk_count -= 1
} endwhile } endwhile
continue.loop continue.loop
@@ -1082,7 +1082,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
// Calculate the remaining number of 32-bit chunks. At 1 bit per // Calculate the remaining number of 32-bit chunks. At 1 bit per
// pixel there are 32 pixels per chunk. Division rounds up. // pixel there are 32 pixels per chunk. Division rounds up.
chunk_count = ((this.width ~sat- this.dst_x) + 31) / 32 chunk_count = ((this.width ~sat- this.dst_x) + 31) / 32
chunk_count = chunk_count.min(a: 16) // Keep p0 <= 512. chunk_count = chunk_count.min(no_more_than: 16) // Keep p0 <= 512.
while (chunk_count > 0) and (args.src.length() >= 4) { while (chunk_count > 0) and (args.src.length() >= 4) {
chunk_bits = args.src.peek_u32be() chunk_bits = args.src.peek_u32be()
args.src.skip_u32_fast!(actual: 4, worst_case: 4) args.src.skip_u32_fast!(actual: 4, worst_case: 4)
@@ -1126,7 +1126,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
// Calculate the remaining number of 32-bit chunks. At 2 bits per // Calculate the remaining number of 32-bit chunks. At 2 bits per
// pixel there are 16 pixels per chunk. Division rounds up. // pixel there are 16 pixels per chunk. Division rounds up.
chunk_count = ((this.width ~sat- this.dst_x) + 15) / 16 chunk_count = ((this.width ~sat- this.dst_x) + 15) / 16
chunk_count = chunk_count.min(a: 32) // Keep p0 <= 512. chunk_count = chunk_count.min(no_more_than: 32) // Keep p0 <= 512.
while (chunk_count > 0) and (args.src.length() >= 4) { while (chunk_count > 0) and (args.src.length() >= 4) {
chunk_bits = args.src.peek_u32be() chunk_bits = args.src.peek_u32be()
args.src.skip_u32_fast!(actual: 4, worst_case: 4) args.src.skip_u32_fast!(actual: 4, worst_case: 4)
@@ -1154,7 +1154,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
// Calculate the remaining number of 32-bit chunks. At 4 bits per // Calculate the remaining number of 32-bit chunks. At 4 bits per
// pixel there are 8 pixels per chunk. Division rounds up. // pixel there are 8 pixels per chunk. Division rounds up.
chunk_count = ((this.width ~sat- this.dst_x) + 7) / 8 chunk_count = ((this.width ~sat- this.dst_x) + 7) / 8
chunk_count = chunk_count.min(a: 64) // Keep p0 <= 512. chunk_count = chunk_count.min(no_more_than: 64) // Keep p0 <= 512.
while (chunk_count > 0) and (args.src.length() >= 4) { while (chunk_count > 0) and (args.src.length() >= 4) {
chunk_bits = args.src.peek_u32be() chunk_bits = args.src.peek_u32be()
args.src.skip_u32_fast!(actual: 4, worst_case: 4) args.src.skip_u32_fast!(actual: 4, worst_case: 4)
@@ -1171,7 +1171,7 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
} endwhile } endwhile
} }
p0 = p0.min(a: this.width ~sat- this.dst_x) p0 = p0.min(no_more_than: this.width ~sat- this.dst_x)
n = this.swizzler.swizzle_interleaved_from_slice!( n = this.swizzler.swizzle_interleaved_from_slice!(
dst: dst, dst: dst,
dst_palette: dst_palette, dst_palette: dst_palette,
+2 -2
View File
@@ -330,7 +330,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
yield? base."$short write" yield? base."$short write"
continue continue
} }
n64 = string_length.min(a: args.src.length()) n64 = string_length.min(no_more_than: args.src.length())
token_length = (n64 & 0xFFFF) as base.u32 token_length = (n64 & 0xFFFF) as base.u32
if n64 > 0xFFFF { if n64 > 0xFFFF {
token_length = 0xFFFF token_length = 0xFFFF
@@ -413,7 +413,7 @@ pub func decoder.decode_tokens?(dst: base.token_writer, src: base.io_reader, wor
yield? base."$short write" yield? base."$short write"
continue continue
} }
n64 = string_length.min(a: 0xFFFF) n64 = string_length.min(no_more_than: 0xFFFF)
n64 = args.src.valid_utf_8_length(up_to: n64) n64 = args.src.valid_utf_8_length(up_to: n64)
token_length = (n64 & 0xFFFF) as base.u32 token_length = (n64 & 0xFFFF) as base.u32
if token_length <= 0 { if token_length <= 0 {
+19 -19
View File
@@ -294,13 +294,13 @@ pub func decoder.num_decoded_frames() base.u64 {
} }
pub func decoder.frame_dirty_rect() base.rect_ie_u32 { pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
// The "foo.min(a:this.width_or_height)" calls clip the nominal frame_rect // The "foo.min(no_more_than: this.width_or_height)" calls clip the nominal
// to the image_rect. // frame_rect to the image_rect.
return this.util.make_rect_ie_u32( return this.util.make_rect_ie_u32(
min_incl_x: this.frame_rect_x0.min(a: this.width), min_incl_x: this.frame_rect_x0.min(no_more_than: this.width),
min_incl_y: this.frame_rect_y0.min(a: this.height), min_incl_y: this.frame_rect_y0.min(no_more_than: this.height),
max_excl_x: this.frame_rect_x1.min(a: this.width), max_excl_x: this.frame_rect_x1.min(no_more_than: this.width),
max_excl_y: this.dirty_max_excl_y.min(a: this.height)) max_excl_y: this.dirty_max_excl_y.min(no_more_than: this.height))
} }
pub func decoder.workbuf_len() base.range_ii_u64 { pub func decoder.workbuf_len() base.range_ii_u64 {
@@ -390,13 +390,13 @@ pri func decoder.do_decode_frame_config?(dst: nptr base.frame_config, src: base.
} }
if args.dst <> nullptr { if args.dst <> nullptr {
// The "foo.min(a:this.width_or_height)" calls clip the nominal // The "foo.min(no_more_than: this.width_or_height)" calls clip the
// frame_rect to the image_rect. // nominal frame_rect to the image_rect.
args.dst.set!(bounds: this.util.make_rect_ie_u32( args.dst.set!(bounds: this.util.make_rect_ie_u32(
min_incl_x: this.frame_rect_x0.min(a: this.width), min_incl_x: this.frame_rect_x0.min(no_more_than: this.width),
min_incl_y: this.frame_rect_y0.min(a: this.height), min_incl_y: this.frame_rect_y0.min(no_more_than: this.height),
max_excl_x: this.frame_rect_x1.min(a: this.width), max_excl_x: this.frame_rect_x1.min(no_more_than: this.width),
max_excl_y: this.frame_rect_y1.min(a: this.height)), max_excl_y: this.frame_rect_y1.min(no_more_than: this.height)),
duration: this.gc_duration, duration: this.gc_duration,
index: this.num_decoded_frame_configs_value, index: this.num_decoded_frame_configs_value,
io_position: this.frame_config_io_position, io_position: this.frame_config_io_position,
@@ -804,8 +804,8 @@ pri func decoder.decode_id_part0?(src: base.io_reader) {
// test/data/artificial/gif-frame-out-of-bounds.gif.make-artificial.txt for // test/data/artificial/gif-frame-out-of-bounds.gif.make-artificial.txt for
// more discussion. // more discussion.
if (this.num_decoded_frame_configs_value == 0) and (not this.quirks[QUIRK_IMAGE_BOUNDS_ARE_STRICT - QUIRKS_BASE]) { if (this.num_decoded_frame_configs_value == 0) and (not this.quirks[QUIRK_IMAGE_BOUNDS_ARE_STRICT - QUIRKS_BASE]) {
this.width = this.width.max(a: this.frame_rect_x1) this.width = this.width.max(no_less_than: this.frame_rect_x1)
this.height = this.height.max(a: this.frame_rect_y1) this.height = this.height.max(no_less_than: this.frame_rect_y1)
} }
} }
@@ -936,7 +936,7 @@ pri func decoder.decode_id_part2?(dst: ptr base.pixel_buffer, src: base.io_reade
this.compressed_wi = 0 this.compressed_wi = 0
} }
while this.compressed_wi <= (4096 - 255) { while this.compressed_wi <= (4096 - 255) {
n_compressed = block_size.min(a: args.src.length()) n_compressed = block_size.min(no_more_than: args.src.length())
if n_compressed <= 0 { if n_compressed <= 0 {
break break
} }
@@ -1078,7 +1078,7 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: slice bas
src_ri ~sat+= n src_ri ~sat+= n
this.dst_x ~sat+= (n & 0xFFFF_FFFF) as base.u32 this.dst_x ~sat+= (n & 0xFFFF_FFFF) as base.u32
this.dirty_max_excl_y = this.dirty_max_excl_y.max(a: this.dst_y ~sat+ 1) this.dirty_max_excl_y = this.dirty_max_excl_y.max(no_less_than: this.dst_y ~sat+ 1)
} }
if this.frame_rect_x1 <= this.dst_x { if this.frame_rect_x1 <= this.dst_x {
@@ -1102,14 +1102,14 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: slice bas
replicate_src = tab.row_u32(y: this.dst_y) replicate_src = tab.row_u32(y: this.dst_y)
replicate_y0 = this.dst_y ~sat+ 1 replicate_y0 = this.dst_y ~sat+ 1
replicate_y1 = this.dst_y ~sat+ (INTERLACE_COUNT[this.interlace] as base.u32) replicate_y1 = this.dst_y ~sat+ (INTERLACE_COUNT[this.interlace] as base.u32)
replicate_y1 = replicate_y1.min(a: this.frame_rect_y1) replicate_y1 = replicate_y1.min(no_more_than: this.frame_rect_y1)
while replicate_y0 < replicate_y1 { while replicate_y0 < replicate_y1 {
assert replicate_y0 < 0xFFFF_FFFF via "a < b: a < c; c <= b"(c: replicate_y1) assert replicate_y0 < 0xFFFF_FFFF via "a < b: a < c; c <= b"(c: replicate_y1)
replicate_dst = tab.row_u32(y: replicate_y0) replicate_dst = tab.row_u32(y: replicate_y0)
replicate_dst.copy_from_slice!(s: replicate_src) replicate_dst.copy_from_slice!(s: replicate_src)
replicate_y0 += 1 replicate_y0 += 1
} endwhile } endwhile
this.dirty_max_excl_y = this.dirty_max_excl_y.max(a: replicate_y1) this.dirty_max_excl_y = this.dirty_max_excl_y.max(no_less_than: replicate_y1)
} }
this.dst_y ~sat+= INTERLACE_DELTA[this.interlace] as base.u32 this.dst_y ~sat+= INTERLACE_DELTA[this.interlace] as base.u32
@@ -1131,7 +1131,7 @@ pri func decoder.copy_to_image_buffer!(pb: ptr base.pixel_buffer, src: slice bas
// Set n to the number of pixels (i.e. the number of bytes) to skip. // Set n to the number of pixels (i.e. the number of bytes) to skip.
n = (this.frame_rect_x1 - this.dst_x) as base.u64 n = (this.frame_rect_x1 - this.dst_x) as base.u64
n = n.min(a: args.src.length() - src_ri) n = n.min(no_more_than: args.src.length() - src_ri)
src_ri ~sat+= n src_ri ~sat+= n
this.dst_x ~sat+= (n & 0xFFFF_FFFF) as base.u32 this.dst_x ~sat+= (n & 0xFFFF_FFFF) as base.u32
+1 -1
View File
@@ -246,7 +246,7 @@ pri func decoder.swizzle!(dst: ptr base.pixel_buffer, src: base.io_reader) base.
assert src_bytes_per_pixel > 0 assert src_bytes_per_pixel > 0
} }
n = args.src.length() / (src_bytes_per_pixel as base.u64) n = args.src.length() / (src_bytes_per_pixel as base.u64)
n = n.min(a: (this.width ~mod- this.dst_x) as base.u64) n = n.min(no_more_than: (this.width ~mod- this.dst_x) as base.u64)
j = n j = n
while j >= 8 { while j >= 8 {
if args.src.length() >= ((src_bytes_per_pixel * 8) as base.u64) { if args.src.length() >= ((src_bytes_per_pixel * 8) as base.u64) {
+3 -3
View File
@@ -84,7 +84,7 @@ pri func decoder.filter_2!(curr: slice base.u8, prev: slice base.u8) {
var n : base.u64 var n : base.u64
var i : base.u64 var i : base.u64
n = args.curr.length().min(a: args.prev.length()) n = args.curr.length().min(no_more_than: args.prev.length())
i = 0 i = 0
while i < n, while i < n,
inv n <= args.curr.length(), inv n <= args.curr.length(),
@@ -122,7 +122,7 @@ pri func decoder.filter_3!(curr: slice base.u8, prev: slice base.u8),
} endwhile } endwhile
} else { } else {
n = args.curr.length().min(a: args.prev.length()) n = args.curr.length().min(no_more_than: args.prev.length())
i = 0 i = 0
while (i < n) and (i < filter_distance), while (i < n) and (i < filter_distance),
inv n <= args.curr.length(), inv n <= args.curr.length(),
@@ -238,7 +238,7 @@ pri func decoder.filter_4!(curr: slice base.u8, prev: slice base.u8),
var pc : base.u32 var pc : base.u32
filter_distance = this.filter_distance as base.u64 filter_distance = this.filter_distance as base.u64
n = args.curr.length().min(a: args.prev.length()) n = args.curr.length().min(no_more_than: args.prev.length())
i = 0 i = 0
while (i < n) and (i < filter_distance), while (i < n) and (i < filter_distance),
inv n <= args.curr.length(), inv n <= args.curr.length(),
+1 -1
View File
@@ -378,7 +378,7 @@ pri func decoder.do_decode_frame?(dst: ptr base.pixel_buffer, src: base.io_reade
if lit_length > 0 { if lit_length > 0 {
mark = args.src.mark() mark = args.src.mark()
num_pixels64 = args.src.length() / (this.src_bytes_per_pixel as base.u64) num_pixels64 = args.src.length() / (this.src_bytes_per_pixel as base.u64)
num_pixels32 = num_pixels64.min(a: lit_length as base.u64) as base.u32 num_pixels32 = num_pixels64.min(no_more_than: lit_length as base.u64) as base.u32
num_dst_bytes = (num_pixels32 as base.u64) * dst_bytes_per_pixel num_dst_bytes = (num_pixels32 as base.u64) * dst_bytes_per_pixel
num_src_bytes = num_pixels32 * this.src_bytes_per_pixel num_src_bytes = num_pixels32 * this.src_bytes_per_pixel
args.src.skip_u32?(n: num_src_bytes) args.src.skip_u32?(n: num_src_bytes)