mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 16:47:28 +01:00
Change func out-type from struct to bare type
This commit is contained in:
1 parent
af7b15bc17
commit
9919d78245
19 files changed
+236
-239
No files matched your search
@@ -20,7 +20,7 @@ pub struct hasher?(
|
||||
started base.bool,
|
||||
)
|
||||
|
||||
pub func hasher.update!(x slice base.u8)(checksum base.u32) {
|
||||
pub func hasher.update!(x slice base.u8) base.u32 {
|
||||
// The Adler-32 checksum's magic 65521 and 5552 numbers are discussed in
|
||||
// RFC 1950.
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ pub struct ieee_hasher?(
|
||||
// TODO: should it be ? instead of ! because it's public, and might need a way
|
||||
// to signal "initializer not called"? Should the return type, in the generated
|
||||
// C code, be "struct{ uint32_t checksum; wuffs_crc32__status status }"?
|
||||
pub func ieee_hasher.update!(x slice base.u8)(checksum base.u32) {
|
||||
pub func ieee_hasher.update!(x slice base.u8) base.u32 {
|
||||
var s base.u32 = 0xFFFFFFFF ^ this.state
|
||||
|
||||
iterate (p slice base.u8 =: in.x)(length:8, unroll:8) {
|
||||
|
||||
@@ -122,7 +122,7 @@ pub struct decoder?(
|
||||
end_of_block base.bool,
|
||||
)
|
||||
|
||||
pub func decoder.decode?(dst base.io_writer, src base.io_reader)() {
|
||||
pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||
while true {
|
||||
in.dst.set_mark!()
|
||||
var z base.status = try this.decode_blocks?(dst:in.dst, src:in.src)
|
||||
@@ -174,7 +174,7 @@ pub func decoder.decode?(dst base.io_writer, src base.io_reader)() {
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_blocks?(dst base.io_writer, src base.io_reader)() {
|
||||
pri func decoder.decode_blocks?(dst base.io_writer, src base.io_reader) {
|
||||
var final base.u32
|
||||
while final == 0 {
|
||||
while this.n_bits < 3,
|
||||
@@ -214,7 +214,7 @@ pri func decoder.decode_blocks?(dst base.io_writer, src base.io_reader)() {
|
||||
|
||||
// decode_uncompressed decodes an uncompresed block as per the RFC section
|
||||
// 3.2.4.
|
||||
pri func decoder.decode_uncompressed?(dst base.io_writer, src base.io_reader)() {
|
||||
pri func decoder.decode_uncompressed?(dst base.io_writer, src base.io_reader) {
|
||||
// TODO: make this "if" into a function invariant?
|
||||
//
|
||||
// Ditto for decode_huffman_slow and decode_huffman_fast.
|
||||
@@ -245,7 +245,7 @@ pri func decoder.decode_uncompressed?(dst base.io_writer, src base.io_reader)()
|
||||
}
|
||||
|
||||
// init_fixed_huffman initializes this.huffs as per the RFC section 3.2.6.
|
||||
pri func decoder.init_fixed_huffman?()() {
|
||||
pri func decoder.init_fixed_huffman?() {
|
||||
var i base.u32
|
||||
while i < 144 {
|
||||
this.code_lengths[i] = 8
|
||||
@@ -272,7 +272,7 @@ pri func decoder.init_fixed_huffman?()() {
|
||||
}
|
||||
|
||||
// init_dynamic_huffman initializes this.huffs as per the RFC section 3.2.7.
|
||||
pri func decoder.init_dynamic_huffman?(src base.io_reader)() {
|
||||
pri func decoder.init_dynamic_huffman?(src base.io_reader) {
|
||||
var bits base.u32 = this.bits
|
||||
var n_bits base.u32 = this.n_bits
|
||||
while n_bits < 14,
|
||||
@@ -422,7 +422,7 @@ pri func decoder.init_dynamic_huffman?(src base.io_reader)() {
|
||||
// TODO: skip generating WUFFS_COROUTINE_SUSPENSION_POINTs for *callers* of
|
||||
// this function, as it can only return errors, not suspensions.
|
||||
|
||||
pri func decoder.init_huff?(which base.u32[..1], n_codes0 base.u32[..320], n_codes1 base.u32[..320], base_symbol base.u32)() {
|
||||
pri func decoder.init_huff?(which base.u32[..1], n_codes0 base.u32[..320], n_codes1 base.u32[..320], base_symbol base.u32) {
|
||||
// For the clcode example in this package's README.md:
|
||||
// - n_codes0 = 0
|
||||
// - n_codes1 = 19
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
// TODO: describe how the xxx_fast version differs from the xxx_slow one, the
|
||||
// assumptions that xxx_fast makes, and how that makes it fast.
|
||||
pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader)() {
|
||||
pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader) {
|
||||
// When editing this function, consider making the equivalent change to the
|
||||
// decode_huffman_slow function. Keep the diff between the two
|
||||
// decode_huffman_*.wuffs files as small as possible, while retaining both
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader)() {
|
||||
pri func decoder.decode_huffman_slow?(dst base.io_writer, src base.io_reader) {
|
||||
// When editing this function, consider making the equivalent change to the
|
||||
// decode_huffman_fast function. Keep the diff between the two
|
||||
// decode_huffman_*.wuffs files as small as possible, while retaining both
|
||||
|
||||
+17
-17
@@ -122,7 +122,7 @@ pub struct decoder?(
|
||||
lzw lzw.decoder,
|
||||
)
|
||||
|
||||
pub func decoder.decode_image_config?(dst nptr base.image_config, src base.io_reader)() {
|
||||
pub func decoder.decode_image_config?(dst nptr base.image_config, src base.io_reader) {
|
||||
if this.call_sequence >= 1 {
|
||||
return error "invalid call sequence"
|
||||
}
|
||||
@@ -156,19 +156,19 @@ pub func decoder.decode_image_config?(dst nptr base.image_config, src base.io_re
|
||||
this.call_sequence = 1
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frame_configs()(ret base.u64) {
|
||||
pub func decoder.num_decoded_frame_configs() base.u64 {
|
||||
return this.num_decoded_frame_configs_value
|
||||
}
|
||||
|
||||
pub func decoder.num_decoded_frames()(ret base.u64) {
|
||||
pub func decoder.num_decoded_frames() base.u64 {
|
||||
return this.num_decoded_frames_value
|
||||
}
|
||||
|
||||
pub func decoder.work_buffer_size()(ret base.range_ii_u64) {
|
||||
pub func decoder.work_buffer_size() base.range_ii_u64 {
|
||||
return this.util.make_range_ii_u64(min_incl:0, max_incl:0)
|
||||
}
|
||||
|
||||
pub func decoder.decode_frame_config?(dst nptr base.frame_config, src base.io_reader)() {
|
||||
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)
|
||||
@@ -215,7 +215,7 @@ pub func decoder.decode_frame_config?(dst nptr base.frame_config, src base.io_re
|
||||
this.call_sequence = 2
|
||||
}
|
||||
|
||||
pri func decoder.skip_frame?(src base.io_reader)() {
|
||||
pri func decoder.skip_frame?(src base.io_reader) {
|
||||
var lw base.u8 = in.src.read_u8?()
|
||||
this.skip_blocks?(src:in.src)
|
||||
|
||||
@@ -232,7 +232,7 @@ 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)() {
|
||||
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)
|
||||
}
|
||||
@@ -251,7 +251,7 @@ pub func decoder.decode_frame?(dst ptr base.pixel_buffer, pixbuf_origin_x base.u
|
||||
this.call_sequence = 3
|
||||
}
|
||||
|
||||
pri func decoder.decode_up_to_id_part1?(src base.io_reader)() {
|
||||
pri func decoder.decode_up_to_id_part1?(src base.io_reader) {
|
||||
while true {
|
||||
var block_type base.u8 = in.src.read_u8?()
|
||||
if block_type == 0x21 { // The spec calls 0x21 the "Extension Introducer".
|
||||
@@ -271,7 +271,7 @@ pri func decoder.decode_up_to_id_part1?(src base.io_reader)() {
|
||||
// decode_header reads either "GIF87a" or "GIF89a".
|
||||
//
|
||||
// See the spec section 17 "Header" on page 7.
|
||||
pri func decoder.decode_header?(src base.io_reader)() {
|
||||
pri func decoder.decode_header?(src base.io_reader) {
|
||||
var c array[6] base.u8
|
||||
var i base.u32
|
||||
while i < 6 {
|
||||
@@ -287,7 +287,7 @@ pri func decoder.decode_header?(src base.io_reader)() {
|
||||
// decode_lsd reads the Logical Screen Descriptor.
|
||||
//
|
||||
// See the spec section 18 "Logical Screen Descriptor" on page 8.
|
||||
pri func decoder.decode_lsd?(src base.io_reader)() {
|
||||
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?()
|
||||
@@ -329,7 +329,7 @@ pri func decoder.decode_lsd?(src base.io_reader)() {
|
||||
// - section 24 "Comment Extension" on page 17.
|
||||
// - section 25 "Plain Text Extension" on page 18.
|
||||
// - section 26 "Application Extension" on page 21.
|
||||
pri func decoder.decode_extension?(src base.io_reader)() {
|
||||
pri func decoder.decode_extension?(src base.io_reader) {
|
||||
var label base.u8 = in.src.read_u8?()
|
||||
if label == 0xF9 { // The spec calls 0xF9 the "Graphic Control Label".
|
||||
this.decode_gc?(src:in.src)
|
||||
@@ -343,7 +343,7 @@ pri func decoder.decode_extension?(src base.io_reader)() {
|
||||
this.skip_blocks?(src:in.src)
|
||||
}
|
||||
|
||||
pri func decoder.skip_blocks?(src base.io_reader)() {
|
||||
pri func decoder.skip_blocks?(src base.io_reader) {
|
||||
while true {
|
||||
var block_size base.u8 = in.src.read_u8?()
|
||||
if block_size == 0 {
|
||||
@@ -364,7 +364,7 @@ pri const netscape2dot0 array[11] base.u8 = $(
|
||||
)
|
||||
|
||||
// decode_ae reads an Application Extension.
|
||||
pri func decoder.decode_ae?(src base.io_reader)() {
|
||||
pri func decoder.decode_ae?(src base.io_reader) {
|
||||
// This "while true" always executes exactly once, as it ends with a
|
||||
// "break", but using "break"s throughout simplifies the control flow.
|
||||
while true {
|
||||
@@ -430,7 +430,7 @@ pri func decoder.decode_ae?(src base.io_reader)() {
|
||||
}
|
||||
|
||||
// decode_gc reads a Graphic Control.
|
||||
pri func decoder.decode_gc?(src base.io_reader)() {
|
||||
pri func decoder.decode_gc?(src base.io_reader) {
|
||||
if this.seen_graphic_control {
|
||||
return error "bad graphic control"
|
||||
}
|
||||
@@ -479,7 +479,7 @@ pri func decoder.decode_gc?(src base.io_reader)() {
|
||||
// The code is split into two parts (part0 and part1) because determining the
|
||||
// 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)() {
|
||||
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)
|
||||
@@ -534,7 +534,7 @@ pri func decoder.decode_id_part0?(src base.io_reader)() {
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)() {
|
||||
pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader) {
|
||||
if this.gc_has_transparent_index {
|
||||
if not this.use_local_palette {
|
||||
this.palettes[1][:].copy_from_slice(s:this.palettes[0][:])
|
||||
@@ -622,7 +622,7 @@ pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)
|
||||
// TODO: check for "not enough pixel data".
|
||||
}
|
||||
|
||||
pri func decoder.copy_to_image_buffer?(pb ptr base.pixel_buffer)() {
|
||||
pri func decoder.copy_to_image_buffer?(pb ptr base.pixel_buffer) {
|
||||
// TODO: don't assume a packed pixel format.
|
||||
var dst slice base.u8
|
||||
var src slice base.u8
|
||||
|
||||
@@ -28,11 +28,11 @@ pub struct decoder?(
|
||||
ignore_checksum base.bool,
|
||||
)
|
||||
|
||||
pub func decoder.set_ignore_checksum!(ic base.bool)() {
|
||||
pub func decoder.set_ignore_checksum!(ic base.bool) {
|
||||
this.ignore_checksum = in.ic
|
||||
}
|
||||
|
||||
pub func decoder.decode?(dst base.io_writer, src base.io_reader)() {
|
||||
pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||
// Read the header.
|
||||
var c base.u8 = in.src.read_u8?()
|
||||
if c != 0x1F {
|
||||
|
||||
@@ -24,11 +24,11 @@ pub struct decoder?(
|
||||
prefixes array[4096] base.u16[..4095],
|
||||
)
|
||||
|
||||
pub func decoder.set_literal_width!(lw base.u32[2..8])() {
|
||||
pub func decoder.set_literal_width!(lw base.u32[2..8]) {
|
||||
this.literal_width = in.lw
|
||||
}
|
||||
|
||||
pub func decoder.decode?(dst base.io_writer, src base.io_reader)() {
|
||||
pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||
// These variables don't change over the lifetime of this func.
|
||||
var literal_width base.u32[2..8] = 8
|
||||
if this.literal_width >= 2 {
|
||||
|
||||
@@ -30,11 +30,11 @@ pub struct decoder?(
|
||||
ignore_checksum base.bool,
|
||||
)
|
||||
|
||||
pub func decoder.set_ignore_checksum!(ic base.bool)() {
|
||||
pub func decoder.set_ignore_checksum!(ic base.bool) {
|
||||
this.ignore_checksum = in.ic
|
||||
}
|
||||
|
||||
pub func decoder.decode?(dst base.io_writer, src base.io_reader)() {
|
||||
pub func decoder.decode?(dst base.io_writer, src base.io_reader) {
|
||||
var x base.u16 = in.src.read_u16be?()
|
||||
if ((x >> 8) & 0x0F) != 0x08 {
|
||||
return error "bad compression method"
|
||||
|
||||
Reference in new issue
Block a user