Skip to content

Commit

Permalink
bhdr: zrle flag
Browse files Browse the repository at this point in the history
  • Loading branch information
kspalaiologos committed Oct 17, 2024
1 parent 9a9e719 commit a37eda2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions jmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,18 @@ static int read_header_from_map(mmap_t map, int force, int ifactor_override) {
return parse_header(out, force, ifactor_override);
}
#endif
typedef struct { u32 bytes, crc; } block_hdr;
typedef struct { u32 bytes, crc; bool zrle; } block_hdr;
static void write_block_header(FILE * des, block_hdr h) {
u8 b[8]; b[0] = 'X';
u8 b[8]; b[0] = 'X' + zrle; // X/Y.
if (h.bytes > 0xFFFFFF)
FATAL("Could not write the header: block too big.");
b[1] = h.bytes >> 16; b[2] = h.bytes >> 8; b[3] = h.bytes;
b[4] = h.crc >> 24; b[5] = h.crc >> 16; b[6] = h.crc >> 8; b[7] = h.crc;
xfwrite(b, 8, des);
}
static block_hdr parse_block_header(u8 b[8], bool force) {
block_hdr h; bool valid = b[0] == 'X';
block_hdr h; bool valid = b[0] == 'X' || b[0] == 'Y';
h.zrle = b[0] == 'Y';
if (!valid) {
FATAL_UNLESS("Invalid block header.", !force);
h.bytes = 0xFFFFFF; h.crc = 0; return h;
Expand All @@ -264,7 +265,7 @@ static void encode4(FILE * in, FILE * out, int ifactor) {
Fi(ibs, rse32(in_buffer + i * K, o1 + i * N));
do_interlacing(o1, o2, ifactor);
xfwrite(o2, ibs * N, out);
bhdr.bytes = n; bhdr.crc = crc32c(in_buffer, n);
bhdr.bytes = n; bhdr.crc = crc32c(in_buffer, n); bhdr.zrle = false;
write_block_header(out, bhdr);
}
free(in_buffer), free(o1), free(o2); xfclose(out);
Expand All @@ -286,7 +287,7 @@ static void encode3(mmap_t in, FILE * out, int ifactor) {
Fi(ibs, rse32(in_buffer + i * K, o1 + i * N));
do_interlacing(o1, o2, ifactor);
xfwrite(o2, ibs * N, out);
bhdr.bytes = n; bhdr.crc = crc32c(in_buffer, n);
bhdr.bytes = n; bhdr.crc = crc32c(in_buffer, n); bhdr.zrle = false;
write_block_header(out, bhdr);
}
free(in_buffer), free(o1), free(o2); xfclose(out);
Expand Down

0 comments on commit a37eda2

Please sign in to comment.