Skip to content

Commit a37eda2

Browse files
committed
bhdr: zrle flag
1 parent 9a9e719 commit a37eda2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

jmode.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,18 @@ static int read_header_from_map(mmap_t map, int force, int ifactor_override) {
230230
return parse_header(out, force, ifactor_override);
231231
}
232232
#endif
233-
typedef struct { u32 bytes, crc; } block_hdr;
233+
typedef struct { u32 bytes, crc; bool zrle; } block_hdr;
234234
static void write_block_header(FILE * des, block_hdr h) {
235-
u8 b[8]; b[0] = 'X';
235+
u8 b[8]; b[0] = 'X' + zrle; // X/Y.
236236
if (h.bytes > 0xFFFFFF)
237237
FATAL("Could not write the header: block too big.");
238238
b[1] = h.bytes >> 16; b[2] = h.bytes >> 8; b[3] = h.bytes;
239239
b[4] = h.crc >> 24; b[5] = h.crc >> 16; b[6] = h.crc >> 8; b[7] = h.crc;
240240
xfwrite(b, 8, des);
241241
}
242242
static block_hdr parse_block_header(u8 b[8], bool force) {
243-
block_hdr h; bool valid = b[0] == 'X';
243+
block_hdr h; bool valid = b[0] == 'X' || b[0] == 'Y';
244+
h.zrle = b[0] == 'Y';
244245
if (!valid) {
245246
FATAL_UNLESS("Invalid block header.", !force);
246247
h.bytes = 0xFFFFFF; h.crc = 0; return h;
@@ -264,7 +265,7 @@ static void encode4(FILE * in, FILE * out, int ifactor) {
264265
Fi(ibs, rse32(in_buffer + i * K, o1 + i * N));
265266
do_interlacing(o1, o2, ifactor);
266267
xfwrite(o2, ibs * N, out);
267-
bhdr.bytes = n; bhdr.crc = crc32c(in_buffer, n);
268+
bhdr.bytes = n; bhdr.crc = crc32c(in_buffer, n); bhdr.zrle = false;
268269
write_block_header(out, bhdr);
269270
}
270271
free(in_buffer), free(o1), free(o2); xfclose(out);
@@ -286,7 +287,7 @@ static void encode3(mmap_t in, FILE * out, int ifactor) {
286287
Fi(ibs, rse32(in_buffer + i * K, o1 + i * N));
287288
do_interlacing(o1, o2, ifactor);
288289
xfwrite(o2, ibs * N, out);
289-
bhdr.bytes = n; bhdr.crc = crc32c(in_buffer, n);
290+
bhdr.bytes = n; bhdr.crc = crc32c(in_buffer, n); bhdr.zrle = false;
290291
write_block_header(out, bhdr);
291292
}
292293
free(in_buffer), free(o1), free(o2); xfclose(out);

0 commit comments

Comments
 (0)