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 };
47 bytestream_put_be32(&buf, avctx->
width);
48 bytestream_put_be32(&buf, avctx->
height);
52 for (
int y = 0; y < avctx->
height; y++) {
53 for (
int x = 0; x < avctx->
width; x++) {
56 if (!memcmp(px, px_prev, 4)) {
72 if (!memcmp(
index[index_pos], px, 4)) {
75 memcpy(
index[index_pos], px, 4);
77 if (px[3] == px_prev[3]) {
78 int8_t vr = px[0] - px_prev[0];
79 int8_t vg = px[1] - px_prev[1];
80 int8_t vb = px[2] - px_prev[2];
82 int8_t vg_r = vr - vg;
83 int8_t vg_b = vb - vg;
85 if (vr > -3 && vr < 2 &&
88 bytestream_put_byte(&buf,
QOI_OP_DIFF | (vr + 2) << 4 | (vg + 2) << 2 | (vb + 2));
89 }
else if (vg_r > -9 && vg_r < 8 &&
90 vg > -33 && vg < 32 &&
91 vg_b > -9 && vg_b < 8) {
93 bytestream_put_byte(&buf, (vg_r + 8) << 4 | (vg_b + 8));
96 bytestream_put_byte(&buf, px[0]);
97 bytestream_put_byte(&buf, px[1]);
98 bytestream_put_byte(&buf, px[2]);
102 bytestream_put_byte(&buf, px[0]);
103 bytestream_put_byte(&buf, px[1]);
104 bytestream_put_byte(&buf, px[2]);
105 bytestream_put_byte(&buf, px[3]);
110 memcpy(px_prev, px, 4);
119 bytestream_put_be64(&buf, 0x01);