Rename the implicit in variable to args

This commit is contained in:
Nigel Tao committed 2018-07-29 10:26:22 +10:00
1 parent 58ded30954
commit ca06083f8a
19 files changed
+254 -252

No files matched your search

+64 -64
View File
@@ -70,8 +70,8 @@ pub struct decoder?(
//
// Where:
// - F is decode_frame, implicit means skip_frame
// - FC is decode_frame_config, implicit means nullptr in.dst
// - IC is decode_image_config, implicit means nullptr in.dst
// - FC is decode_frame_config, implicit means nullptr args.dst
// - IC is decode_image_config, implicit means nullptr args.dst
call_sequence base.u8,
end_of_data base.bool,
@@ -126,9 +126,9 @@ pub func decoder.decode_image_config?(dst nptr base.image_config, src base.io_re
if this.call_sequence >= 1 {
return error "invalid call sequence"
}
this.decode_header?(src:in.src)
this.decode_lsd?(src:in.src)
this.decode_up_to_id_part1?(src:in.src)
this.decode_header?(src:args.src)
this.decode_lsd?(src:args.src)
this.decode_up_to_id_part1?(src:args.src)
// TODO: if this.end_of_data, return an error and/or set dst to zero?
@@ -144,12 +144,12 @@ pub func decoder.decode_image_config?(dst nptr base.image_config, src base.io_re
(this.frame_rect_y1 == this.height) and
(this.has_full_palette)
if in.dst != nullptr {
if args.dst != nullptr {
// TODO: rename initialize to set?
//
// TODO: a Wuffs (not just C) name for the
// WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_INDEXED magic pixfmt constant.
in.dst.initialize!(pixfmt:0x22088888, pixsub:0,
args.dst.initialize!(pixfmt:0x22088888, pixsub:0,
width:this.width, height:this.height, num_loops:num_loops, first_frame_is_opaque:ffio)
}
@@ -171,12 +171,12 @@ pub func decoder.work_buffer_size() base.range_ii_u64 {
pub func decoder.decode_frame_config?(dst nptr base.frame_config, src base.io_reader) {
if not this.end_of_data {
if this.call_sequence == 0 {
this.decode_image_config?(dst:nullptr, src:in.src)
this.decode_image_config?(dst:nullptr, src:args.src)
} else if this.call_sequence != 1 {
if this.call_sequence == 2 {
this.skip_frame?(src:in.src)
this.skip_frame?(src:args.src)
}
this.decode_up_to_id_part1?(src:in.src)
this.decode_up_to_id_part1?(src:args.src)
}
}
@@ -201,8 +201,8 @@ pub func decoder.decode_frame_config?(dst nptr base.frame_config, src base.io_re
this.previous_use_global_palette =
not (this.use_local_palette or this.gc_has_transparent_index)
if in.dst != nullptr {
in.dst.update!(bounds:this.util.make_rect_ie_u32(
if args.dst != nullptr {
args.dst.update!(bounds:this.util.make_rect_ie_u32(
min_incl_x:this.frame_rect_x0,
min_incl_y:this.frame_rect_y0,
max_excl_x:this.frame_rect_x1,
@@ -216,8 +216,8 @@ pub func decoder.decode_frame_config?(dst nptr base.frame_config, src base.io_re
}
pri func decoder.skip_frame?(src base.io_reader) {
var lw base.u8 = in.src.read_u8?()
this.skip_blocks?(src:in.src)
var lw base.u8 = args.src.read_u8?()
this.skip_blocks?(src:args.src)
// The Image Descriptor is mandatory, but the Graphic Control extension is
// optional. Reset the GC related fields for the next decode_frame call.
@@ -234,10 +234,10 @@ pri func decoder.skip_frame?(src base.io_reader) {
// TODO: honor pixbuf_origin_x and pixbuf_origin_y args.
pub func decoder.decode_frame?(dst ptr base.pixel_buffer, pixbuf_origin_x base.u32, pixbuf_origin_y base.u32, src base.io_reader, work_buffer slice base.u8) {
if this.call_sequence != 2 {
this.decode_frame_config?(dst:nullptr, src:in.src)
this.decode_frame_config?(dst:nullptr, src:args.src)
}
this.decode_id_part1?(dst:in.dst, src:in.src)
this.decode_id_part1?(dst:args.dst, src:args.src)
// The Image Descriptor is mandatory, but the Graphic Control extension is
// optional. Reset the GC related fields for the next decode_frame call.
@@ -253,11 +253,11 @@ pub func decoder.decode_frame?(dst ptr base.pixel_buffer, pixbuf_origin_x base.u
pri func decoder.decode_up_to_id_part1?(src base.io_reader) {
while true {
var block_type base.u8 = in.src.read_u8?()
var block_type base.u8 = args.src.read_u8?()
if block_type == 0x21 { // The spec calls 0x21 the "Extension Introducer".
this.decode_extension?(src:in.src)
this.decode_extension?(src:args.src)
} else if block_type == 0x2C { // The spec calls 0x2C the "Image Separator".
this.decode_id_part0?(src:in.src)
this.decode_id_part0?(src:args.src)
break
} else if block_type == 0x3B { // The spec calls 0x3B the "Trailer".
this.end_of_data = true
@@ -275,7 +275,7 @@ pri func decoder.decode_header?(src base.io_reader) {
var c array[6] base.u8
var i base.u32
while i < 6 {
c[i] = in.src.read_u8?()
c[i] = args.src.read_u8?()
i += 1
}
if (c[0] != 0x47) or (c[1] != 0x49) or (c[2] != 0x46) or (c[3] != 0x38) or
@@ -288,11 +288,11 @@ pri func decoder.decode_header?(src base.io_reader) {
//
// See the spec section 18 "Logical Screen Descriptor" on page 8.
pri func decoder.decode_lsd?(src base.io_reader) {
this.width = in.src.read_u16le?() as base.u32
this.height = in.src.read_u16le?() as base.u32
var flags base.u8 = in.src.read_u8?()
this.width = args.src.read_u16le?() as base.u32
this.height = args.src.read_u16le?() as base.u32
var flags base.u8 = args.src.read_u8?()
// Ignore the Background Color Index and Pixel Aspect Ratio bytes.
in.src.skip?(n:2)
args.src.skip?(n:2)
// Read the optional Global Color Table.
if (flags & 0x80) != 0 {
@@ -302,7 +302,7 @@ pri func decoder.decode_lsd?(src base.io_reader) {
assert i < 256 via "a < b: a < c; c <= b"(c:num_palette_entries)
// Convert from RGB (in memory order) to ARGB (in native u32 order)
// to BGRA (in memory order).
var argb base.u32 = in.src.read_u24be?() | 0xFF000000
var argb base.u32 = args.src.read_u24be?() | 0xFF000000
this.palettes[0][(4 * i) + 0] = ((argb >> 0) & 0xFF) as base.u8
this.palettes[0][(4 * i) + 1] = ((argb >> 8) & 0xFF) as base.u8
this.palettes[0][(4 * i) + 2] = ((argb >> 16) & 0xFF) as base.u8
@@ -330,26 +330,26 @@ pri func decoder.decode_lsd?(src base.io_reader) {
// - section 25 "Plain Text Extension" on page 18.
// - section 26 "Application Extension" on page 21.
pri func decoder.decode_extension?(src base.io_reader) {
var label base.u8 = in.src.read_u8?()
var label base.u8 = args.src.read_u8?()
if label == 0xF9 { // The spec calls 0xF9 the "Graphic Control Label".
this.decode_gc?(src:in.src)
this.decode_gc?(src:args.src)
return
} else if label == 0xFF { // The spec calls 0xFF the "Application Extension Label".
this.decode_ae?(src:in.src)
this.decode_ae?(src:args.src)
return
}
// We skip over all other extensions, including 0x01 "Plain Text Label" and
// 0xFE "Comment Label".
this.skip_blocks?(src:in.src)
this.skip_blocks?(src:args.src)
}
pri func decoder.skip_blocks?(src base.io_reader) {
while true {
var block_size base.u8 = in.src.read_u8?()
var block_size base.u8 = args.src.read_u8?()
if block_size == 0 {
return
}
in.src.skip?(n:block_size as base.u32)
args.src.skip?(n:block_size as base.u32)
}
}
@@ -369,7 +369,7 @@ pri func decoder.decode_ae?(src base.io_reader) {
// "break", but using "break"s throughout simplifies the control flow.
while true {
var c base.u8
var block_size base.u8 = in.src.read_u8?()
var block_size base.u8 = args.src.read_u8?()
if block_size == 0 {
return
}
@@ -379,14 +379,14 @@ pri func decoder.decode_ae?(src base.io_reader) {
// - http://www.vurdalakov.net/misc/gif/animexts-looping-application-extension
// - http://www.vurdalakov.net/misc/gif/netscape-looping-application-extension
if block_size != 11 {
in.src.skip?(n:block_size as base.u32)
args.src.skip?(n:block_size as base.u32)
break
}
var not_animexts base.bool
var not_netscape base.bool
block_size = 0 // Re-purpose the block_size variable as a counter.
while block_size < 11 {
c = in.src.read_u8?()
c = args.src.read_u8?()
not_animexts = not_animexts or (c != animexts1dot0[block_size])
not_netscape = not_netscape or (c != netscape2dot0[block_size])
block_size += 1
@@ -397,17 +397,17 @@ pri func decoder.decode_ae?(src base.io_reader) {
// Those 11 bytes should be followed by 0x03, 0x01 and then the loop
// count.
block_size = in.src.read_u8?()
block_size = args.src.read_u8?()
if block_size != 3 {
in.src.skip?(n:block_size as base.u32)
args.src.skip?(n:block_size as base.u32)
break
}
c = in.src.read_u8?()
c = args.src.read_u8?()
if c != 0x01 {
in.src.skip?(n:2)
args.src.skip?(n:2)
break
}
this.num_loops = in.src.read_u16le?() as base.u32
this.num_loops = args.src.read_u16le?() as base.u32
this.seen_num_loops = true
// A loop count of N, in the wire format, actually means "repeat N
@@ -426,7 +426,7 @@ pri func decoder.decode_ae?(src base.io_reader) {
break
}
this.skip_blocks?(src:in.src)
this.skip_blocks?(src:args.src)
}
// decode_gc reads a Graphic Control.
@@ -434,12 +434,12 @@ pri func decoder.decode_gc?(src base.io_reader) {
if this.seen_graphic_control {
return error "bad graphic control"
}
var c base.u8 = in.src.read_u8?()
var c base.u8 = args.src.read_u8?()
if c != 4 {
return error "bad graphic control"
}
var flags base.u8 = in.src.read_u8?()
var flags base.u8 = args.src.read_u8?()
this.gc_has_transparent_index = (flags & 0x01) != 0
// Convert the disposal method from GIF's wire format to Wuffs constants.
@@ -461,10 +461,10 @@ pri func decoder.decode_gc?(src base.io_reader) {
}
// There are 7056000 flicks per centisecond.
this.gc_duration = (in.src.read_u16le?() as base.u64) * 7056000
this.gc_transparent_index = in.src.read_u8?()
this.gc_duration = (args.src.read_u16le?() as base.u64) * 7056000
this.gc_transparent_index = args.src.read_u8?()
c = in.src.read_u8?()
c = args.src.read_u8?()
if c != 0 {
return error "bad graphic control"
}
@@ -480,10 +480,10 @@ pri func decoder.decode_gc?(src base.io_reader) {
// overall image's width and height also requires decoding the first frame's
// bounds (but doesn't require decoding the first frame's pixels).
pri func decoder.decode_id_part0?(src base.io_reader) {
this.frame_rect_x0 = in.src.read_u16le?() as base.u32
this.frame_rect_y0 = in.src.read_u16le?() as base.u32
this.frame_rect_x1 = this.frame_rect_x0 ~mod+ (in.src.read_u16le?() as base.u32)
this.frame_rect_y1 = this.frame_rect_y0 ~mod+ (in.src.read_u16le?() as base.u32)
this.frame_rect_x0 = args.src.read_u16le?() as base.u32
this.frame_rect_y0 = args.src.read_u16le?() as base.u32
this.frame_rect_x1 = this.frame_rect_x0 ~mod+ (args.src.read_u16le?() as base.u32)
this.frame_rect_y1 = this.frame_rect_y0 ~mod+ (args.src.read_u16le?() as base.u32)
this.dst_x = this.frame_rect_x0
this.dst_y = this.frame_rect_y0
@@ -497,7 +497,7 @@ pri func decoder.decode_id_part0?(src base.io_reader) {
this.height = this.height.max(x:this.frame_rect_y1)
}
var flags base.u8 = in.src.read_u8?()
var flags base.u8 = args.src.read_u8?()
if (flags & 0x40) != 0 {
this.interlace = 4
} else {
@@ -515,7 +515,7 @@ pri func decoder.decode_id_part0?(src base.io_reader) {
assert i < 256 via "a < b: a < c; c <= b"(c:num_palette_entries)
// Convert from RGB (in memory order) to ARGB (in native u32 order)
// to BGRA (in memory order).
var argb base.u32 = in.src.read_u24be?() | 0xFF000000
var argb base.u32 = args.src.read_u24be?() | 0xFF000000
this.palettes[1][(4 * i) + 0] = ((argb >> 0) & 0xFF) as base.u8
this.palettes[1][(4 * i) + 1] = ((argb >> 8) & 0xFF) as base.u8
this.palettes[1][(4 * i) + 2] = ((argb >> 16) & 0xFF) as base.u8
@@ -546,7 +546,7 @@ pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)
this.palettes[1][(4 * (this.gc_transparent_index as base.u32)) + 2] = 0x00
this.palettes[1][(4 * (this.gc_transparent_index as base.u32)) + 3] = 0x00
}
in.dst.set_palette!(palette:this.palettes[this.which_palette & 1][:])
args.dst.set_palette!(palette:this.palettes[this.which_palette & 1][:])
// Other GIF implementations accept GIF files that aren't completely spec
// compliant. For example, the test/data/gifplayer-muybridge.gif file
@@ -567,7 +567,7 @@ pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)
this.lzw.reset()
}
var lw base.u8 = in.src.read_u8?()
var lw base.u8 = args.src.read_u8?()
if (lw < 2) or (8 < lw) {
return error "bad literal width"
}
@@ -575,7 +575,7 @@ pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)
this.previous_lzw_decode_ended_abruptly = true
while true {
var block_size base.u64 = in.src.read_u8?() as base.u64
var block_size base.u64 = args.src.read_u8?() as base.u64
if block_size == 0 {
break
}
@@ -583,7 +583,7 @@ pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)
while:inner true {
var w base.io_writer
io_bind (in.src, w) {
io_bind (args.src, w) {
w.set!(s:this.uncompressed[this.uncompressed_wi:])
// TODO: enforce that calling r.set_limit has a precondition
// that r.is_bound(), and that you can't suspend inside an
@@ -591,15 +591,15 @@ pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)
// complicated if we must save and re-apply limits.
//
// Should calling r.set_mark also require r.is_bound()?
in.src.set_limit!(l:block_size)
in.src.set_mark!()
var z base.status = try this.lzw.decode?(dst:w, src:in.src)
args.src.set_limit!(l:block_size)
args.src.set_mark!()
var z base.status = try this.lzw.decode?(dst:w, src:args.src)
this.uncompressed_wi = 4096 - (w.available().min(x:4096) as base.u32)
block_size ~sat-= in.src.since_mark().length()
block_size ~sat-= args.src.since_mark().length()
}
if z.is_ok() or (z == suspension "short write") {
this.copy_to_image_buffer?(pb:in.dst)
this.copy_to_image_buffer?(pb:args.dst)
if z == suspension "short write" {
continue:inner
@@ -616,7 +616,7 @@ pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)
}
if this.uncompressed_ri != this.uncompressed_wi {
this.copy_to_image_buffer?(pb:in.dst)
this.copy_to_image_buffer?(pb:args.dst)
}
// TODO: check for "not enough pixel data".
@@ -630,7 +630,7 @@ pri func decoder.copy_to_image_buffer?(pb ptr base.pixel_buffer) {
// TODO: we shouldn't need this temporary variable.
var new_ri base.u32
var tab table base.u8 = in.pb.plane(p:0)
var tab table base.u8 = args.pb.plane(p:0)
while this.uncompressed_wi > this.uncompressed_ri {
assert this.uncompressed_ri < this.uncompressed_wi via "a < b: b > a"()
@@ -641,7 +641,7 @@ pri func decoder.copy_to_image_buffer?(pb ptr base.pixel_buffer) {
}
// First, copy from src to that part of the frame rect that is inside
// in.pb's bounds.
// args.pb's bounds.
dst = tab.row(y:this.dst_y)
if (this.dst_x as base.u64) < dst.length() {
@@ -676,7 +676,7 @@ pri func decoder.copy_to_image_buffer?(pb ptr base.pixel_buffer) {
}
// Second, skip over src for that part of the frame rect that is
// outside in.pb's bounds. This second step should be infrequent.
// outside args.pb's bounds. This second step should be infrequent.
// Set n to the number of pixels (i.e. the number of bytes) to skip.
n = this.frame_rect_x1 - this.dst_x