ref: d2b67d2f95df97111977bb07639afe61b34d9ea2
dir: /f_runlength.c/
#include <u.h> #include <libc.h> #include "pdf.h" /* 7.4.5 RunLengthDecode filter */ static int flreadall(void *aux, Buffer *bi, Buffer *bo) { int sz, i; uchar *p; USED(aux); p = bufdata(bi, &sz); for(; sz > 0;){ i = *p++; sz--; if(i == 0x80) /* EOD */ break; if(i > 0x80){ if(sz < 1){ werrstr("no byte to repeat"); return -1; } for(i = 257 - i; i > 0; i--) bufput(bo, p, 1); p++; }else{ i++; if(i > sz){ werrstr("short data"); return -1; } bufput(bo, p, i); p += i; sz -= i; } } bi->off = bi->sz; return 0; } Filter filterRunLength = { .name = "RunLengthDecode", .readall = flreadall, };