Skip to content

Commit

Permalink
jmode.c: zrle-pack, zrle-unpack
Browse files Browse the repository at this point in the history
  • Loading branch information
kspalaiologos committed Oct 17, 2024
1 parent 2529f42 commit 2034044
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions jmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,28 @@ static bool zrle_consider(u8 * restrict in, sz n) {
return savings > 0;
}

static sz zrle_pack(u8 * restrict in, sz n, u8 * restrict out) {
sz j = 0;
Fi(n, if (!in[i]) {
sz k = i + 1;
while (k < n && in[k] == 0) k++;
out[j++] = 0;
out[j++] = k - i - 1;
i = k - 1;
} else out[j++] = in[i]);
return j;
}

static sz zrle_unpack(u8 * restrict in, sz n, u8 * restrict out, sz outmax) {
sz j = 0;
Fi(n, if (!in[i]) {
if (j + in[i + 1] >= outmax) return 0;
memset(out + j, 0, in[i + 1]);
j += in[i + 1]; i++;
} else out[j++] = in[i]);
return j;
}

// ============================================================================
// Processing. We apply a few strategies that depend on some specifics of the
// process at hand:
Expand Down

0 comments on commit 2034044

Please sign in to comment.