29 const AVFrame *pict,
int *got_packet)
32 uint8_t px_prev[4] = { 0, 0, 0, 255 };
33 uint8_t px[4] = { 0, 0, 0, 255 };
34 uint8_t
index[64][4] = { 0 };
48 bytestream_put_be32(&buf, avctx->
width);
49 bytestream_put_be32(&buf, avctx->
height);
53 for (
int y = 0; y < avctx->
height; y++) {
54 for (
int x = 0; x < avctx->
width; x++) {
57 if (!memcmp(px, px_prev, 4)) {
73 if (!memcmp(
index[index_pos], px, 4)) {
76 memcpy(
index[index_pos], px, 4);
78 if (px[3] == px_prev[3]) {
79 int8_t vr = px[0] - px_prev[0];
80 int8_t vg = px[1] - px_prev[1];
81 int8_t vb = px[2] - px_prev[2];
83 int8_t vg_r = vr - vg;
84 int8_t vg_b = vb - vg;
86 if (vr > -3 && vr < 2 &&
89 bytestream_put_byte(&buf,
QOI_OP_DIFF | (vr + 2) << 4 | (vg + 2) << 2 | (vb + 2));
90 }
else if (vg_r > -9 && vg_r < 8 &&
91 vg > -33 && vg < 32 &&
92 vg_b > -9 && vg_b < 8) {
94 bytestream_put_byte(&buf, (vg_r + 8) << 4 | (vg_b + 8));
97 bytestream_put_byte(&buf, px[0]);
98 bytestream_put_byte(&buf, px[1]);
99 bytestream_put_byte(&buf, px[2]);
103 bytestream_put_byte(&buf, px[0]);
104 bytestream_put_byte(&buf, px[1]);
105 bytestream_put_byte(&buf, px[2]);
106 bytestream_put_byte(&buf, px[3]);
111 memcpy(px_prev, px, 4);
120 bytestream_put_be64(&buf, 0x01);