Allow an LZW literal width of 1

This commit is contained in:
Nigel Tao committed 2019-05-12 21:32:30 +10:00
1 parent d1133b105e
commit 5bea867f72
4 files changed
+63 -6

No files matched your search

+4 -1
View File
@@ -844,8 +844,11 @@ pri func decoder.decode_id_part1?(dst ptr base.pixel_buffer, src base.io_reader)
this.lzw.reset!()
}
// Process the LZW literal width. The spec says that "images which have one
// color bit must be indicated as having a code size [i.e. literal width]
// of 2", but in practice, some encoders use a literal width of 1.
lw = args.src.read_u8?()
if (lw < 2) or (8 < lw) {
if (lw < 1) or (8 < lw) {
return "#bad literal width"
}
this.lzw.set_literal_width!(lw:lw as base.u32)
+2 -2
View File
@@ -69,7 +69,7 @@ pub struct decoder?(
output array[8192 + 7] base.u8,
)
pub func decoder.set_literal_width!(lw base.u32[2..8]) {
pub func decoder.set_literal_width!(lw base.u32[1..8]) {
this.set_literal_width_arg = args.lw
}
@@ -82,7 +82,7 @@ pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader, workb
// Initialize read_from state.
this.literal_width = 8
if this.set_literal_width_arg >= 2 {
if this.set_literal_width_arg > 0 {
this.literal_width = this.set_literal_width_arg
}
this.clear_code = (1 as base.u32) << this.literal_width