public static int PDJPG_EscapeEncodeBuffer(BytePtr ibuf, int isz, BytePtr obuf, int osz) { BytePtr cs, ct, cse, cte; cs = ibuf; cse = ibuf + isz; ct = obuf; cte = obuf + osz; while ((cs < cse) && (ct < cte)) { if (cs[0] == 0xFF) { cs++; ct.emit(0xFF); ct.emit(0x00); continue; } ct.emit(cs.next()); } if (ct >= cte) return (-1); return (ct - obuf); }
public static int PDJPG_EscapeDecodeSingleBuffer(BytePtr buf, int sz) { BytePtr cs, ct, cse, cte; cs = buf; cse = buf + sz; ct = buf; cte = buf + sz; while ((cs < cse) && (ct < cte)) { if ((cs[0] == 0xFF) && (cs[1] == 0x00)) { cs += 2; ct.emit(0xFF); continue; } if ((cs[0] == 0xFF) && (cs[1] <= 0x0F)) { ct.emit(0xFF); ct.emit(cs[1] - 1); cs += 2; continue; } ct.emit(cs.next()); } if (ct >= cte) return (-1); return (ct - buf); }