33 #define GLYPH_COORD_VECT_SIZE 16
34 #define PALETTE_SIZE 256
35 #define PALETTE_DELTA 768
38 0, 1, 2, 3, 3, 3, 3, 2, 1, 0, 0, 0, 1, 2, 2, 1
42 0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 2, 1, 1, 1, 2, 2
46 0, 2, 5, 7, 7, 7, 7, 7, 7, 5, 2, 0, 0, 0, 0, 0
50 0, 0, 0, 0, 1, 3, 4, 6, 7, 7, 7, 7, 6, 4, 3, 1
54 { 0, 0 }, { -1, -43 }, { 6, -43 }, { -9, -42 }, { 13, -41 },
55 { -16, -40 }, { 19, -39 }, { -23, -36 }, { 26, -34 }, { -2, -33 },
56 { 4, -33 }, { -29, -32 }, { -9, -32 }, { 11, -31 }, { -16, -29 },
57 { 32, -29 }, { 18, -28 }, { -34, -26 }, { -22, -25 }, { -1, -25 },
58 { 3, -25 }, { -7, -24 }, { 8, -24 }, { 24, -23 }, { 36, -23 },
59 { -12, -22 }, { 13, -21 }, { -38, -20 }, { 0, -20 }, { -27, -19 },
60 { -4, -19 }, { 4, -19 }, { -17, -18 }, { -8, -17 }, { 8, -17 },
61 { 18, -17 }, { 28, -17 }, { 39, -17 }, { -12, -15 }, { 12, -15 },
62 { -21, -14 }, { -1, -14 }, { 1, -14 }, { -41, -13 }, { -5, -13 },
63 { 5, -13 }, { 21, -13 }, { -31, -12 }, { -15, -11 }, { -8, -11 },
64 { 8, -11 }, { 15, -11 }, { -2, -10 }, { 1, -10 }, { 31, -10 },
65 { -23, -9 }, { -11, -9 }, { -5, -9 }, { 4, -9 }, { 11, -9 },
66 { 42, -9 }, { 6, -8 }, { 24, -8 }, { -18, -7 }, { -7, -7 },
67 { -3, -7 }, { -1, -7 }, { 2, -7 }, { 18, -7 }, { -43, -6 },
68 { -13, -6 }, { -4, -6 }, { 4, -6 }, { 8, -6 }, { -33, -5 },
69 { -9, -5 }, { -2, -5 }, { 0, -5 }, { 2, -5 }, { 5, -5 },
70 { 13, -5 }, { -25, -4 }, { -6, -4 }, { -3, -4 }, { 3, -4 },
71 { 9, -4 }, { -19, -3 }, { -7, -3 }, { -4, -3 }, { -2, -3 },
72 { -1, -3 }, { 0, -3 }, { 1, -3 }, { 2, -3 }, { 4, -3 },
73 { 6, -3 }, { 33, -3 }, { -14, -2 }, { -10, -2 }, { -5, -2 },
74 { -3, -2 }, { -2, -2 }, { -1, -2 }, { 0, -2 }, { 1, -2 },
75 { 2, -2 }, { 3, -2 }, { 5, -2 }, { 7, -2 }, { 14, -2 },
76 { 19, -2 }, { 25, -2 }, { 43, -2 }, { -7, -1 }, { -3, -1 },
77 { -2, -1 }, { -1, -1 }, { 0, -1 }, { 1, -1 }, { 2, -1 },
78 { 3, -1 }, { 10, -1 }, { -5, 0 }, { -3, 0 }, { -2, 0 },
79 { -1, 0 }, { 1, 0 }, { 2, 0 }, { 3, 0 }, { 5, 0 },
80 { 7, 0 }, { -10, 1 }, { -7, 1 }, { -3, 1 }, { -2, 1 },
81 { -1, 1 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 3, 1 },
82 { -43, 2 }, { -25, 2 }, { -19, 2 }, { -14, 2 }, { -5, 2 },
83 { -3, 2 }, { -2, 2 }, { -1, 2 }, { 0, 2 }, { 1, 2 },
84 { 2, 2 }, { 3, 2 }, { 5, 2 }, { 7, 2 }, { 10, 2 },
85 { 14, 2 }, { -33, 3 }, { -6, 3 }, { -4, 3 }, { -2, 3 },
86 { -1, 3 }, { 0, 3 }, { 1, 3 }, { 2, 3 }, { 4, 3 },
87 { 19, 3 }, { -9, 4 }, { -3, 4 }, { 3, 4 }, { 7, 4 },
88 { 25, 4 }, { -13, 5 }, { -5, 5 }, { -2, 5 }, { 0, 5 },
89 { 2, 5 }, { 5, 5 }, { 9, 5 }, { 33, 5 }, { -8, 6 },
90 { -4, 6 }, { 4, 6 }, { 13, 6 }, { 43, 6 }, { -18, 7 },
91 { -2, 7 }, { 0, 7 }, { 2, 7 }, { 7, 7 }, { 18, 7 },
92 { -24, 8 }, { -6, 8 }, { -42, 9 }, { -11, 9 }, { -4, 9 },
93 { 5, 9 }, { 11, 9 }, { 23, 9 }, { -31, 10 }, { -1, 10 },
94 { 2, 10 }, { -15, 11 }, { -8, 11 }, { 8, 11 }, { 15, 11 },
95 { 31, 12 }, { -21, 13 }, { -5, 13 }, { 5, 13 }, { 41, 13 },
96 { -1, 14 }, { 1, 14 }, { 21, 14 }, { -12, 15 }, { 12, 15 },
97 { -39, 17 }, { -28, 17 }, { -18, 17 }, { -8, 17 }, { 8, 17 },
98 { 17, 18 }, { -4, 19 }, { 0, 19 }, { 4, 19 }, { 27, 19 },
99 { 38, 20 }, { -13, 21 }, { 12, 22 }, { -36, 23 }, { -24, 23 },
100 { -8, 24 }, { 7, 24 }, { -3, 25 }, { 1, 25 }, { 22, 25 },
101 { 34, 26 }, { -18, 28 }, { -32, 29 }, { 16, 29 }, { -11, 31 },
102 { 9, 32 }, { 29, 32 }, { -4, 33 }, { 2, 33 }, { -26, 34 },
103 { 23, 36 }, { -19, 39 }, { 16, 40 }, { -13, 41 }, { 9, 42 },
104 { -6, 43 }, { 1, 43 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
108 0, 0, 1, 0, 2, 0, 3, 0, 5, 0, 8, 0, 13, 0, 21,
109 0, -1, 0, -2, 0, -3, 0, -5, 0, -8, 0, -13, 0, -17, 0,
110 -21, 0, 0, 1, 1, 1, 2, 1, 3, 1, 5, 1, 8, 1, 13,
111 1, 21, 1, -1, 1, -2, 1, -3, 1, -5, 1, -8, 1, -13, 1,
112 -17, 1, -21, 1, 0, 2, 1, 2, 2, 2, 3, 2, 5, 2, 8,
113 2, 13, 2, 21, 2, -1, 2, -2, 2, -3, 2, -5, 2, -8, 2,
114 -13, 2, -17, 2, -21, 2, 0, 3, 1, 3, 2, 3, 3, 3, 5,
115 3, 8, 3, 13, 3, 21, 3, -1, 3, -2, 3, -3, 3, -5, 3,
116 -8, 3, -13, 3, -17, 3, -21, 3, 0, 5, 1, 5, 2, 5, 3,
117 5, 5, 5, 8, 5, 13, 5, 21, 5, -1, 5, -2, 5, -3, 5,
118 -5, 5, -8, 5, -13, 5, -17, 5, -21, 5, 0, 8, 1, 8, 2,
119 8, 3, 8, 5, 8, 8, 8, 13, 8, 21, 8, -1, 8, -2, 8,
120 -3, 8, -5, 8, -8, 8, -13, 8, -17, 8, -21, 8, 0, 13, 1,
121 13, 2, 13, 3, 13, 5, 13, 8, 13, 13, 13, 21, 13, -1, 13,
122 -2, 13, -3, 13, -5, 13, -8, 13, -13, 13, -17, 13, -21, 13, 0,
123 21, 1, 21, 2, 21, 3, 21, 5, 21, 8, 21, 13, 21, 21, 21,
124 -1, 21, -2, 21, -3, 21, -5, 21, -8, 21, -13, 21, -17, 21, -21,
125 21, 0, -1, 1, -1, 2, -1, 3, -1, 5, -1, 8, -1, 13, -1,
126 21, -1, -1, -1, -2, -1, -3, -1, -5, -1, -8, -1, -13, -1, -17,
127 -1, -21, -1, 0, -2, 1, -2, 2, -2, 3, -2, 5, -2, 8, -2,
128 13, -2, 21, -2, -1, -2, -2, -2, -3, -2, -5, -2, -8, -2, -13,
129 -2, -17, -2, -21, -2, 0, -3, 1, -3, 2, -3, 3, -3, 5, -3,
130 8, -3, 13, -3, 21, -3, -1, -3, -2, -3, -3, -3, -5, -3, -8,
131 -3, -13, -3, -17, -3, -21, -3, 0, -5, 1, -5, 2, -5, 3, -5,
132 5, -5, 8, -5, 13, -5, 21, -5, -1, -5, -2, -5, -3, -5, -5,
133 -5, -8, -5, -13, -5, -17, -5, -21, -5, 0, -8, 1, -8, 2, -8,
134 3, -8, 5, -8, 8, -8, 13, -8, 21, -8, -1, -8, -2, -8, -3,
135 -8, -5, -8, -8, -8, -13, -8, -17, -8, -21, -8, 0, -13, 1, -13,
136 2, -13, 3, -13, 5, -13, 8, -13, 13, -13, 21, -13, -1, -13, -2,
137 -13, -3, -13, -5, -13, -8, -13, -13, -13, -17, -13, -21, -13, 0, -17,
138 1, -17, 2, -17, 3, -17, 5, -17, 8, -17, 13, -17, 21, -17, -1,
139 -17, -2, -17, -3, -17, -5, -17, -8, -17, -13, -17, -17, -17, -21, -17,
140 0, -21, 1, -21, 2, -21, 3, -21, 5, -21, 8, -21, 13, -21, 21,
141 -21, -1, -21, -2, -21, -3, -21, -5, -21, -8, -21, -13, -21, -17, -21,
142 0, 0, -8, -29, 8, -29, -18, -25, 17, -25, 0, -23, -6, -22, 6,
143 -22, -13, -19, 12, -19, 0, -18, 25, -18, -25, -17, -5, -17, 5, -17,
144 -10, -15, 10, -15, 0, -14, -4, -13, 4, -13, 19, -13, -19, -12, -8,
145 -11, -2, -11, 0, -11, 2, -11, 8, -11, -15, -10, -4, -10, 4, -10,
146 15, -10, -6, -9, -1, -9, 1, -9, 6, -9, -29, -8, -11, -8, -8,
147 -8, -3, -8, 3, -8, 8, -8, 11, -8, 29, -8, -5, -7, -2, -7,
148 0, -7, 2, -7, 5, -7, -22, -6, -9, -6, -6, -6, -3, -6, -1,
149 -6, 1, -6, 3, -6, 6, -6, 9, -6, 22, -6, -17, -5, -7, -5,
150 -4, -5, -2, -5, 0, -5, 2, -5, 4, -5, 7, -5, 17, -5, -13,
151 -4, -10, -4, -5, -4, -3, -4, -1, -4, 0, -4, 1, -4, 3, -4,
152 5, -4, 10, -4, 13, -4, -8, -3, -6, -3, -4, -3, -3, -3, -2,
153 -3, -1, -3, 0, -3, 1, -3, 2, -3, 4, -3, 6, -3, 8, -3,
154 -11, -2, -7, -2, -5, -2, -3, -2, -2, -2, -1, -2, 0, -2, 1,
155 -2, 2, -2, 3, -2, 5, -2, 7, -2, 11, -2, -9, -1, -6, -1,
156 -4, -1, -3, -1, -2, -1, -1, -1, 0, -1, 1, -1, 2, -1, 3,
157 -1, 4, -1, 6, -1, 9, -1, -31, 0, -23, 0, -18, 0, -14, 0,
158 -11, 0, -7, 0, -5, 0, -4, 0, -3, 0, -2, 0, -1, 0, 0,
159 -31, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 7, 0, 11, 0,
160 14, 0, 18, 0, 23, 0, 31, 0, -9, 1, -6, 1, -4, 1, -3,
161 1, -2, 1, -1, 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1,
162 6, 1, 9, 1, -11, 2, -7, 2, -5, 2, -3, 2, -2, 2, -1,
163 2, 0, 2, 1, 2, 2, 2, 3, 2, 5, 2, 7, 2, 11, 2,
164 -8, 3, -6, 3, -4, 3, -2, 3, -1, 3, 0, 3, 1, 3, 2,
165 3, 3, 3, 4, 3, 6, 3, 8, 3, -13, 4, -10, 4, -5, 4,
166 -3, 4, -1, 4, 0, 4, 1, 4, 3, 4, 5, 4, 10, 4, 13,
167 4, -17, 5, -7, 5, -4, 5, -2, 5, 0, 5, 2, 5, 4, 5,
168 7, 5, 17, 5, -22, 6, -9, 6, -6, 6, -3, 6, -1, 6, 1,
169 6, 3, 6, 6, 6, 9, 6, 22, 6, -5, 7, -2, 7, 0, 7,
170 2, 7, 5, 7, -29, 8, -11, 8, -8, 8, -3, 8, 3, 8, 8,
171 8, 11, 8, 29, 8, -6, 9, -1, 9, 1, 9, 6, 9, -15, 10,
172 -4, 10, 4, 10, 15, 10, -8, 11, -2, 11, 0, 11, 2, 11, 8,
173 11, 19, 12, -19, 13, -4, 13, 4, 13, 0, 14, -10, 15, 10, 15,
174 -5, 17, 5, 17, 25, 17, -25, 18, 0, 18, -12, 19, 13, 19, -6,
175 22, 6, 22, 0, 23, -17, 25, 18, 25, -8, 29, 8, 29, 0, 31,
176 0, 0, -6, -22, 6, -22, -13, -19, 12, -19, 0, -18, -5, -17, 5,
177 -17, -10, -15, 10, -15, 0, -14, -4, -13, 4, -13, 19, -13, -19, -12,
178 -8, -11, -2, -11, 0, -11, 2, -11, 8, -11, -15, -10, -4, -10, 4,
179 -10, 15, -10, -6, -9, -1, -9, 1, -9, 6, -9, -11, -8, -8, -8,
180 -3, -8, 0, -8, 3, -8, 8, -8, 11, -8, -5, -7, -2, -7, 0,
181 -7, 2, -7, 5, -7, -22, -6, -9, -6, -6, -6, -3, -6, -1, -6,
182 1, -6, 3, -6, 6, -6, 9, -6, 22, -6, -17, -5, -7, -5, -4,
183 -5, -2, -5, -1, -5, 0, -5, 1, -5, 2, -5, 4, -5, 7, -5,
184 17, -5, -13, -4, -10, -4, -5, -4, -3, -4, -2, -4, -1, -4, 0,
185 -4, 1, -4, 2, -4, 3, -4, 5, -4, 10, -4, 13, -4, -8, -3,
186 -6, -3, -4, -3, -3, -3, -2, -3, -1, -3, 0, -3, 1, -3, 2,
187 -3, 3, -3, 4, -3, 6, -3, 8, -3, -11, -2, -7, -2, -5, -2,
188 -4, -2, -3, -2, -2, -2, -1, -2, 0, -2, 1, -2, 2, -2, 3,
189 -2, 4, -2, 5, -2, 7, -2, 11, -2, -9, -1, -6, -1, -5, -1,
190 -4, -1, -3, -1, -2, -1, -1, -1, 0, -1, 1, -1, 2, -1, 3,
191 -1, 4, -1, 5, -1, 6, -1, 9, -1, -23, 0, -18, 0, -14, 0,
192 -11, 0, -7, 0, -5, 0, -4, 0, -3, 0, -2, 0, -1, 0, 0,
193 -23, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 7, 0, 11, 0,
194 14, 0, 18, 0, 23, 0, -9, 1, -6, 1, -5, 1, -4, 1, -3,
195 1, -2, 1, -1, 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1,
196 5, 1, 6, 1, 9, 1, -11, 2, -7, 2, -5, 2, -4, 2, -3,
197 2, -2, 2, -1, 2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 2,
198 5, 2, 7, 2, 11, 2, -8, 3, -6, 3, -4, 3, -3, 3, -2,
199 3, -1, 3, 0, 3, 1, 3, 2, 3, 3, 3, 4, 3, 6, 3,
200 8, 3, -13, 4, -10, 4, -5, 4, -3, 4, -2, 4, -1, 4, 0,
201 4, 1, 4, 2, 4, 3, 4, 5, 4, 10, 4, 13, 4, -17, 5,
202 -7, 5, -4, 5, -2, 5, -1, 5, 0, 5, 1, 5, 2, 5, 4,
203 5, 7, 5, 17, 5, -22, 6, -9, 6, -6, 6, -3, 6, -1, 6,
204 1, 6, 3, 6, 6, 6, 9, 6, 22, 6, -5, 7, -2, 7, 0,
205 7, 2, 7, 5, 7, -11, 8, -8, 8, -3, 8, 0, 8, 3, 8,
206 8, 8, 11, 8, -6, 9, -1, 9, 1, 9, 6, 9, -15, 10, -4,
207 10, 4, 10, 15, 10, -8, 11, -2, 11, 0, 11, 2, 11, 8, 11,
208 19, 12, -19, 13, -4, 13, 4, 13, 0, 14, -10, 15, 10, 15, -5,
209 17, 5, 17, 0, 18, -12, 19, 13, 19, -6, 22, 6, 22, 0, 23,
277 const int edge_max = edge_size - 1;
281 else if (y == edge_max)
285 else if (x == edge_max)
314 static void interp_point(int8_t *points,
int x0,
int y0,
int x1,
int y1,
315 int pos,
int npoints)
318 points[0] = (x0 * pos + x1 * (npoints - pos) + (npoints >> 1)) / npoints;
319 points[1] = (y0 * pos + y1 * (npoints - pos) + (npoints >> 1)) / npoints;
334 static void make_glyphs(int8_t *pglyphs,
const int8_t *xvec,
const int8_t *yvec,
335 const int side_length)
337 const int glyph_size = side_length * side_length;
338 int8_t *pglyph = pglyphs;
354 for (ipoint = 0; ipoint <= npoints; ipoint++) {
362 for (irow = point[1]; irow >= 0; irow--)
363 pglyph[point[0] + irow * side_length] = 1;
367 for (irow = point[1]; irow < side_length; irow++)
368 pglyph[point[0] + irow * side_length] = 1;
372 for (icol = point[0]; icol >= 0; icol--)
373 pglyph[icol + point[1] * side_length] = 1;
377 for (icol = point[0]; icol < side_length; icol++)
378 pglyph[icol + point[1] * side_length] = 1;
432 if (rotate_code == 2)
464 for (i = 0; i < 256; i++)
485 opcode = bytestream2_get_byte(&ctx->
gb);
486 run_len = (opcode >> 1) + 1;
491 color = bytestream2_get_byte(&ctx->
gb);
492 memset(dst, color, run_len);
510 int i, j,
len, flag, code, val, pos, end;
512 for (i = 0; i <
height; i++) {
518 len = bytestream2_get_le16u(&ctx->
gb);
525 code = bytestream2_get_byteu(&ctx->
gb);
527 code = (code >> 1) + 1;
528 if (pos + code > width)
531 val = bytestream2_get_byteu(&ctx->
gb);
533 memset(dst + pos, val, code);
538 for (j = 0; j < code; j++) {
539 val = bytestream2_get_byteu(&ctx->
gb);
559 for (j = 0; j < 4; j++) {
560 for (i = 0; i < 4; i++) {
561 if ((pos + i) < 0 || (pos + i) >= height * stride)
579 int compr = bytestream2_get_byte(&ctx->
gb);
580 int mvoff = bytestream2_get_byte(&ctx->
gb);
581 int seq = bytestream2_get_le16(&ctx->
gb);
582 uint32_t decoded_size = bytestream2_get_le32(&ctx->
gb);
586 flags = bytestream2_get_byte(&ctx->
gb);
589 if (decoded_size > ctx->
height * stride - left - top * stride) {
590 decoded_size = ctx->
height * stride - left - top *
stride;
596 if (((seq & 1) || !(flags & 1)) && (compr && compr != 2))
609 for (i = 0; i <
height; i++) {
625 for (j = 0; j <
height; j += 4) {
626 for (i = 0; i <
width; i += 4) {
635 code = bytestream2_get_byteu(&ctx->
gb);
640 for (k = 0; k < 4; k++)
646 for (k = 0; k < 4; k++)
647 memset(dst + i + k * stride, bytestream2_get_byteu(&ctx->
gb), 4);
652 t = bytestream2_get_byteu(&ctx->
gb);
653 for (k = 0; k < 4; k++)
654 memset(dst + i + k * stride, t, 4);
657 if (compr == 4 && !code) {
660 skip_run = bytestream2_get_byteu(&ctx->
gb) + 1;
665 mx =
c37_mv[(mvoff * 255 + code) * 2];
666 my =
c37_mv[(mvoff * 255 + code) * 2 + 1];
667 codec37_mv(dst + i, prev + i + mx + my * stride,
668 ctx->
height, stride, i + mx, j + my);
676 for (j = 0; j <
height; j += 4) {
677 for (i = 0; i <
width; i += 4) {
684 code = bytestream2_get_byte(&ctx->
gb);
688 for (k = 0; k < 4; k++)
690 }
else if (compr == 4 && !code) {
693 skip_run = bytestream2_get_byteu(&ctx->
gb) + 1;
698 mx =
c37_mv[(mvoff * 255 + code) * 2];
699 my =
c37_mv[(mvoff * 255 + code) * 2 + 1];
700 codec37_mv(dst + i, prev + i + mx + my * stride,
701 ctx->
height, stride, i + mx, j + my);
711 "Subcodec 37 compression %d", compr);
728 code = bytestream2_get_byteu(&ctx->
gb);
735 dst[0] = bytestream2_get_byteu(&ctx->
gb);
736 dst[1] = bytestream2_get_byteu(&ctx->
gb);
737 dst[0 +
stride] = bytestream2_get_byteu(&ctx->
gb);
738 dst[1 +
stride] = bytestream2_get_byteu(&ctx->
gb);
741 if (
process_block(ctx, dst, prev1, prev2, stride, tbl, size))
743 if (
process_block(ctx, dst + size, prev1 + size, prev2 + size,
749 if (
process_block(ctx, dst, prev1, prev2, stride, tbl, size))
751 if (
process_block(ctx, dst + size, prev1 + size, prev2 + size,
760 t = bytestream2_get_byteu(&ctx->
gb);
761 for (k = 0; k <
size; k++)
762 memset(dst + k * stride, t, size);
768 code = bytestream2_get_byteu(&ctx->
gb);
772 for (k = 0; k <
size; k++)
773 for (t = 0; t <
size; t++)
774 dst[t + k * stride] = colors[!*pglyph++];
777 for (k = 0; k <
size; k++)
778 memcpy(dst + k * stride, prev1 + k * stride, size);
783 t = bytestream2_get_byte(&ctx->
gb);
785 for (k = 0; k <
size; k++)
786 memset(dst + k * stride, t, size);
795 if (index < -mx - my * stride ||
796 (ctx->
buf_size >> 1) - index < mx + size + (my + size - 1) * stride) {
801 for (k = 0; k <
size; k++)
802 memcpy(dst + k * stride, prev2 + mx + (my + k) * stride, size);
811 uint32_t decoded_size;
818 int seq = bytestream2_get_le16(&ctx->
gb);
819 int compr = bytestream2_get_byte(&ctx->
gb);
820 int new_rot = bytestream2_get_byte(&ctx->
gb);
821 int skip = bytestream2_get_byte(&ctx->
gb);
824 decoded_size = bytestream2_get_le32(&ctx->
gb);
827 if (decoded_size > ctx->
height * stride - left - top * stride) {
828 decoded_size = ctx->
height * stride - left - top *
stride;
836 memset(prev1, 0, ctx->
height * stride);
837 memset(prev2, 0, ctx->
height * stride);
844 for (j = 0; j <
height; j++) {
852 for (j = 0; j <
height; j += 2) {
853 for (i = 0; i <
width; i += 2) {
857 dst[stride + i + 1] = bytestream2_get_byteu(&ctx->
gb);
864 for (j = 0; j <
height; j += 8) {
865 for (i = 0; i <
width; i += 8)
866 if (
process_block(ctx, dst + i, prev1 + i, prev2 + i, stride,
887 "Subcodec 47 compression %d", compr);
901 uint16_t codec = bytestream2_get_le16u(&ctx->
gb);
902 uint16_t left = bytestream2_get_le16u(&ctx->
gb);
903 uint16_t top = bytestream2_get_le16u(&ctx->
gb);
904 uint16_t w = bytestream2_get_le16u(&ctx->
gb);
905 uint16_t h = bytestream2_get_le16u(&ctx->
gb);
912 if (ctx->
width < left + w || ctx->
height < top + h) {
945 uint16_t *frm = ctx->
frm0;
952 for (y = 0; y < ctx->
height; y++) {
953 for (x = 0; x < ctx->
width; x++)
954 frm[x] = bytestream2_get_le16u(&ctx->
gb);
966 static void copy_block(uint16_t *pdest, uint16_t *psrc,
int block_size,
int pitch)
972 switch (block_size) {
990 for (y = 0; y < block_size; y++, pdest += pitch)
991 for (x = 0; x < block_size; x++)
996 uint16_t fg_color, uint16_t bg_color,
int block_size,
1000 uint16_t colors[2] = { fg_color, bg_color };
1009 pitch -= block_size;
1011 for (y = 0; y < block_size; y++, dst += pitch)
1012 for (x = 0; x < block_size; x++)
1013 *dst++ = colors[*pglyph++];
1019 uint16_t *dst = ctx->
frm0 + cx + cy * ctx->
pitch;
1021 if (block_size == 2) {
1027 indices = bytestream2_get_le32u(&ctx->
gb);
1028 dst[0] = ctx->
codebook[indices & 0xFF];
1030 dst[1] = ctx->
codebook[indices & 0xFF];
1032 dst[pitch] = ctx->
codebook[indices & 0xFF];
1034 dst[pitch + 1] = ctx->
codebook[indices & 0xFF];
1036 uint16_t fgcolor, bgcolor;
1042 glyph = bytestream2_get_byteu(&ctx->
gb);
1043 bgcolor = ctx->
codebook[bytestream2_get_byteu(&ctx->
gb)];
1044 fgcolor = ctx->
codebook[bytestream2_get_byteu(&ctx->
gb)];
1046 draw_glyph(ctx, dst, glyph, fgcolor, bgcolor, block_size, pitch);
1053 uint16_t *dst = ctx->
frm0 + cx + cy * ctx->
pitch;
1055 if (block_size == 2) {
1059 dst[0] = bytestream2_get_le16u(&ctx->
gb);
1060 dst[1] = bytestream2_get_le16u(&ctx->
gb);
1061 dst[pitch] = bytestream2_get_le16u(&ctx->
gb);
1062 dst[pitch + 1] = bytestream2_get_le16u(&ctx->
gb);
1064 uint16_t fgcolor, bgcolor;
1070 glyph = bytestream2_get_byteu(&ctx->
gb);
1071 bgcolor = bytestream2_get_le16u(&ctx->
gb);
1072 fgcolor = bytestream2_get_le16u(&ctx->
gb);
1074 draw_glyph(ctx, dst, glyph, fgcolor, bgcolor, block_size, pitch);
1082 int start_pos = cx + mx + (cy + my) * ctx->
pitch;
1083 int end_pos = start_pos + (block_size - 1) * (ctx->
pitch + 1);
1085 int good = start_pos >= 0 && end_pos < (ctx->
buf_size >> 1);
1089 "Ignoring invalid motion vector (%i, %i)->(%u, %u), block size = %u\n",
1090 cx + mx, cy + my, cx, cy, block_size);
1097 int16_t mx, my,
index;
1103 opcode = bytestream2_get_byteu(&ctx->
gb);
1110 if (
good_mvec(ctx, cx, cy, mx, my, blk_size)) {
1112 ctx->
frm2 + cx + mx + ctx->
pitch * (cy + my),
1113 blk_size, ctx->
pitch);
1119 index = bytestream2_get_le16u(&ctx->
gb);
1121 mx = index % ctx->
width;
1122 my = index / ctx->
width;
1124 if (
good_mvec(ctx, cx, cy, mx, my, blk_size)) {
1126 ctx->
frm2 + cx + mx + ctx->
pitch * (cy + my),
1127 blk_size, ctx->
pitch);
1133 blk_size, ctx->
pitch);
1153 ctx->
codebook[bytestream2_get_byteu(&ctx->
gb)], blk_size, ctx->
pitch);
1159 bytestream2_get_le16u(&ctx->
gb), blk_size, ctx->
pitch);
1162 if (blk_size == 2) {
1230 uint16_t *frm = ctx->
frm0;
1237 *frm++ = ctx->
codebook[bytestream2_get_byteu(&ctx->
gb)];
1244 uint16_t *pdest = ctx->
frm0;
1282 hdr->
width = bytestream2_get_le32u(&ctx->
gb);
1283 hdr->
height = bytestream2_get_le32u(&ctx->
gb);
1290 hdr->
seq_num = bytestream2_get_le16u(&ctx->
gb);
1291 hdr->
codec = bytestream2_get_byteu(&ctx->
gb);
1296 for (i = 0; i < 4; i++)
1298 hdr->
bg_color = bytestream2_get_le16u(&ctx->
gb);
1303 for (i = 0; i < 256; i++)
1304 ctx->
codebook[i] = bytestream2_get_le16u(&ctx->
gb);
1322 int srcpitch = ctx->
pitch * (hdr ?
sizeof(ctx->
frm0[0]) : 1);
1331 memcpy(dst, src, srcpitch);
1355 sig = bytestream2_get_be32u(&ctx->
gb);
1356 size = bytestream2_get_be32u(&ctx->
gb);
1364 case MKBETAG(
'N',
'P',
'A',
'L'):
1367 "Incorrect palette block size %"PRIu32
".\n", size);
1371 ctx->
pal[i] = 0xFFU << 24 | bytestream2_get_be24u(&ctx->
gb);
1373 case MKBETAG(
'F',
'O',
'B',
'J'):
1379 case MKBETAG(
'X',
'P',
'A',
'L'):
1380 if (size == 6 || size == 4) {
1385 for (j = 0; j < 3; j++) {
1386 int t = (ctx->
pal[i] >> (16 - j * 8)) & 0xFF;
1387 tmp[j] = av_clip_uint8((t * 129 + ctx->
delta_pal[i * 3 + j]) >> 7);
1394 "Incorrect palette change block size %"PRIu32
".\n",
1400 ctx->
delta_pal[i] = bytestream2_get_le16u(&ctx->
gb);
1401 if (size >= PALETTE_DELTA * 5 + 4) {
1403 ctx->
pal[i] = 0xFFU << 24 | bytestream2_get_be24u(&ctx->
gb);
1405 memset(ctx->
pal, 0,
sizeof(ctx->
pal));
1409 case MKBETAG(
'S',
'T',
'O',
'R'):
1412 case MKBETAG(
'F',
'T',
'C',
'H'):
1418 "Unknown/unsupported chunk %"PRIx32
".\n", sig);
1449 "Subcodec %d: error decoding frame.\n", header.
codec);
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int process_frame_obj(SANMVideoContext *ctx)
This structure describes decoded (raw) audio or video data.
static int read_frame_header(SANMVideoContext *ctx, SANMFrameHeader *hdr)
int8_t p4x4glyphs[NGLYPHS][16]
#define AV_LOG_WARNING
Something somehow does not look correct.
static void fill_frame(uint16_t *pbuf, int buf_size, uint16_t color)
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
static void copy_block16(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
uint32_t pal[PALETTE_SIZE]
static int opcode_0xf8(SANMVideoContext *ctx, int cx, int cy, int block_size, int pitch)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *pkt)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer with padding, reusing the given one if large enough.
static enum GlyphEdge which_edge(int x, int y, int edge_size)
Return enum GlyphEdge of box where point (x, y) lies.
#define FF_ARRAY_ELEMS(a)
static const int8_t glyph4_x[GLYPH_COORD_VECT_SIZE]
static const int8_t glyph8_y[GLYPH_COORD_VECT_SIZE]
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static const uint8_t run_len[7][16]
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static int draw_glyph(SANMVideoContext *ctx, uint16_t *dst, int index, uint16_t fg_color, uint16_t bg_color, int block_size, int pitch)
static av_cold int decode_init(AVCodecContext *avctx)
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
8 bit with PIX_FMT_RGB32 palette
static int good_mvec(SANMVideoContext *ctx, int cx, int cy, int mx, int my, int block_size)
static void codec37_mv(uint8_t *dst, const uint8_t *src, int height, int stride, int x, int y)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static const int8_t glyph4_y[GLYPH_COORD_VECT_SIZE]
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
static const int8_t motion_vectors[256][2]
static int decode_5(SANMVideoContext *ctx)
uint16_t small_codebook[4]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_cold int decode_end(AVCodecContext *avctx)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static int rle_decode(SANMVideoContext *ctx, uint8_t *dst, const int out_size)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
simple assert() macros that are a bit more flexible than ISO C assert().
void av_log(void *avcl, int level, const char *fmt,...)
static int decode_3(SANMVideoContext *ctx)
const char * name
Name of the codec implementation.
static enum GlyphDir which_direction(enum GlyphEdge edge0, enum GlyphEdge edge1)
static void make_glyphs(int8_t *pglyphs, const int8_t *xvec, const int8_t *yvec, const int side_length)
Construct glyphs by iterating through vector coordinates.
uint32_t stored_frame_size
enum AVPictureType pict_type
Picture type of the frame.
int width
picture width / height.
static void destroy_buffers(SANMVideoContext *ctx)
static void interp_point(int8_t *points, int x0, int y0, int x1, int y1, int pos, int npoints)
static void copy_block(uint16_t *pdest, uint16_t *psrc, int block_size, int pitch)
static int old_codec47(SANMVideoContext *ctx, int top, int left, int width, int height)
static int copy_output(SANMVideoContext *ctx, SANMFrameHeader *hdr)
if(ac->has_optimized_func)
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
static av_cold int init_buffers(SANMVideoContext *ctx)
static av_always_inline int bytestream2_tell(GetByteContext *g)
static const int8_t c37_mv[]
Libavcodec external API header.
#define GLYPH_COORD_VECT_SIZE
static int decode_nop(SANMVideoContext *ctx)
static int decode_6(SANMVideoContext *ctx)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
static int codec2subblock(SANMVideoContext *ctx, int cx, int cy, int blk_size)
static void close(AVCodecParserContext *s)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static int process_block(SANMVideoContext *ctx, uint8_t *dst, uint8_t *prev1, uint8_t *prev2, int stride, int tbl, int size)
static int opcode_0xf7(SANMVideoContext *ctx, int cx, int cy, int block_size, int pitch)
static int decode_2(SANMVideoContext *ctx)
static int decode_8(SANMVideoContext *ctx)
static int decode_0(SANMVideoContext *ctx)
static void rotate_bufs(SANMVideoContext *ctx, int rotate_code)
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static const frm_decoder v1_decoders[]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static void fill_block(uint16_t *pdest, uint16_t color, int block_size, int pitch)
unsigned int rle_buf_size
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
static int old_codec37(SANMVideoContext *ctx, int top, int left, int width, int height)
common internal api header.
static void init_sizes(SANMVideoContext *ctx, int width, int height)
static const uint8_t color[]
static av_cold int init(AVCodecParserContext *s)
#define MKBETAG(a, b, c, d)
static const int8_t glyph8_x[GLYPH_COORD_VECT_SIZE]
static int decode_4(SANMVideoContext *ctx)
int16_t delta_pal[PALETTE_DELTA]
static void copy_block4(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
int key_frame
1 -> keyframe, 0-> not
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
static void copy_block8(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h)
#define AV_PIX_FMT_RGB565
static int old_codec1(SANMVideoContext *ctx, int top, int left, int width, int height)
int8_t p8x8glyphs[NGLYPHS][64]
#define FFSWAP(type, a, b)
This structure stores compressed data.
int(* frm_decoder)(SANMVideoContext *ctx)