Have std/bmp skip_frame handle RLE compression

This commit is contained in:
Nigel Tao committed 2020-12-15 16:19:18 +11:00
1 parent 290adc9069
commit 688de33f2a
2 files changed
+258 -9

No files matched your search

+90 -1
View File
@@ -1087,8 +1087,97 @@ pri func decoder.swizzle_low_bit_depth!(dst: ptr base.pixel_buffer, src: base.io
}
pri func decoder.skip_frame?(src: base.io_reader) {
var code : base.u8
var rle_state : base.u32
args.src.skip_u32?(n: this.padding)
args.src.skip?(n: this.bytes_per_row * (this.height as base.u64))
if (this.compression <> COMPRESSION_RLE8) and
(this.compression <> COMPRESSION_RLE4) {
args.src.skip?(n: this.bytes_per_row * (this.height as base.u64))
} else {
while.loop true {
if rle_state == RLE_STATE_NEUTRAL {
code = args.src.read_u8?()
if code == 0 {
rle_state = RLE_STATE_ESCAPE
continue.loop
}
this.rle_length = code as base.u32
rle_state = RLE_STATE_RUN
continue.loop
} else if rle_state == RLE_STATE_RUN {
code = args.src.read_u8?()
this.dst_x ~sat+= this.rle_length
rle_state = RLE_STATE_NEUTRAL
continue.loop
} else if rle_state == RLE_STATE_ESCAPE {
code = args.src.read_u8?()
if code < 2 { // 0=EOL, 1=EOF.
if (this.dst_y >= this.height) and (code == 0) {
return "#bad RLE compression"
}
this.dst_x = 0
this.dst_y ~mod+= this.dst_y_inc
if code > 0 {
break.loop
}
rle_state = RLE_STATE_NEUTRAL
continue.loop
} else if code == 2 { // 2=DELTA.
rle_state = RLE_STATE_DELTA_X
continue.loop
}
this.rle_length = code as base.u32
rle_state = RLE_STATE_LITERAL
continue.loop
} else if rle_state == RLE_STATE_LITERAL {
if this.bits_per_pixel == 8 {
args.src.skip_u32?(n: ((this.rle_length + 1) / 2) * 2)
} else {
args.src.skip_u32?(n: ((this.rle_length + 3) / 4) * 2)
}
this.dst_x ~sat+= this.rle_length
this.rle_length = 0
rle_state = RLE_STATE_NEUTRAL
continue.loop
} else if rle_state == RLE_STATE_DELTA_X {
this.rle_delta_x = args.src.read_u8?()
rle_state = RLE_STATE_DELTA_Y
continue.loop
} // else (rle_state == RLE_STATE_DELTA_Y).
code = args.src.read_u8?()
if this.rle_delta_x > 0 {
this.dst_x ~sat+= this.rle_delta_x as base.u32
this.rle_delta_x = 0
if this.dst_x > this.width {
return "#bad RLE compression"
}
}
if code > 0 {
code -= 1
while true {
this.dst_y ~mod+= this.dst_y_inc
if this.dst_y >= this.height {
return "#bad RLE compression"
}
if code <= 0 {
break
}
code -= 1
} endwhile
}
rle_state = RLE_STATE_NEUTRAL
} endwhile.loop
}
this.call_sequence = 3
}