89 #define FULLPEL_MODE 1
90 #define HALFPEL_MODE 2
91 #define THIRDPEL_MODE 3
92 #define PREDICT_MODE 4
104 0 + 0 * 4, 1 + 0 * 4, 2 + 0 * 4, 2 + 1 * 4,
105 2 + 2 * 4, 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4,
106 0 + 1 * 4, 0 + 2 * 4, 1 + 1 * 4, 1 + 2 * 4,
107 0 + 3 * 4, 1 + 3 * 4, 2 + 3 * 4, 3 + 3 * 4,
113 { 0, 2 }, { 1, 1 }, { 2, 0 },
114 { 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 },
115 { 0, 4 }, { 1, 3 }, { 2, 2 }, { 3, 1 }, { 4, 0 },
116 { 4, 1 }, { 3, 2 }, { 2, 3 }, { 1, 4 },
117 { 2, 4 }, { 3, 3 }, { 4, 2 },
123 { { 2, -1, -1, -1, -1 }, { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 },
124 { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 }, { 1, 2, -1, -1, -1 } },
125 { { 0, 2, -1, -1, -1 }, { 0, 2, 1, 4, 3 }, { 0, 1, 2, 4, 3 },
126 { 0, 2, 1, 4, 3 }, { 2, 0, 1, 3, 4 }, { 0, 4, 2, 1, 3 } },
127 { { 2, 0, -1, -1, -1 }, { 2, 1, 0, 4, 3 }, { 1, 2, 4, 0, 3 },
128 { 2, 1, 0, 4, 3 }, { 2, 1, 4, 3, 0 }, { 1, 2, 4, 0, 3 } },
129 { { 2, 0, -1, -1, -1 }, { 2, 0, 1, 4, 3 }, { 1, 2, 0, 4, 3 },
130 { 2, 1, 0, 4, 3 }, { 2, 1, 3, 4, 0 }, { 2, 4, 1, 0, 3 } },
131 { { 0, 2, -1, -1, -1 }, { 0, 2, 1, 3, 4 }, { 1, 2, 3, 0, 4 },
132 { 2, 0, 1, 3, 4 }, { 2, 1, 3, 0, 4 }, { 2, 0, 4, 3, 1 } },
133 { { 0, 2, -1, -1, -1 }, { 0, 2, 4, 1, 3 }, { 1, 4, 2, 0, 3 },
134 { 4, 2, 0, 1, 3 }, { 2, 0, 1, 4, 3 }, { 4, 2, 1, 0, 3 } },
137 static const struct {
141 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 0, 2 }, { 3, 1 }, { 4, 1 }, { 5, 1 },
142 { 0, 3 }, { 1, 2 }, { 2, 2 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 0, 4 } },
143 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 2, 1 }, { 0, 3 }, { 0, 4 }, { 0, 5 },
144 { 3, 1 }, { 4, 1 }, { 1, 2 }, { 1, 3 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 } }
148 3881, 4351, 4890, 5481, 6154, 6914, 7761, 8718,
149 9781, 10987, 12339, 13828, 15523, 17435, 19561, 21873,
150 24552, 27656, 30847, 34870, 38807, 43747, 49103, 54683,
151 61694, 68745, 77615, 89113, 100253, 109366, 126635, 141533
162 for (i = 0; i < 4; i++) {
163 const int z0 = 13 * (input[4 * i + 0] + input[4 * i + 2]);
164 const int z1 = 13 * (input[4 * i + 0] - input[4 * i + 2]);
165 const int z2 = 7 * input[4 * i + 1] - 17 * input[4 * i + 3];
166 const int z3 = 17 * input[4 * i + 1] + 7 * input[4 * i + 3];
168 temp[4 * i + 0] = z0 + z3;
169 temp[4 * i + 1] = z1 + z2;
170 temp[4 * i + 2] = z1 - z2;
171 temp[4 * i + 3] = z0 - z3;
174 for (i = 0; i < 4; i++) {
175 const int offset = x_offset[i];
176 const int z0 = 13 * (temp[4 * 0 + i] + temp[4 * 2 + i]);
177 const int z1 = 13 * (temp[4 * 0 + i] - temp[4 * 2 + i]);
178 const int z2 = 7 * temp[4 * 1 + i] - 17 * temp[4 * 3 + i];
179 const int z3 = 17 * temp[4 * 1 + i] + 7 * temp[4 * 3 + i];
181 output[
stride * 0 +
offset] = (z0 + z3) * qmul + 0x80000 >> 20;
182 output[
stride * 2 +
offset] = (z1 + z2) * qmul + 0x80000 >> 20;
183 output[
stride * 8 +
offset] = (z1 - z2) * qmul + 0x80000 >> 20;
184 output[
stride * 10 +
offset] = (z0 - z3) * qmul + 0x80000 >> 20;
190 int stride,
int qp,
int dc)
196 dc = 13 * 13 * (dc == 1 ? 1538 * block[0]
197 : qmul * (block[0] >> 3) / 2);
201 for (i = 0; i < 4; i++) {
202 const int z0 = 13 * (block[0 + 4 * i] + block[2 + 4 * i]);
203 const int z1 = 13 * (block[0 + 4 * i] - block[2 + 4 * i]);
204 const int z2 = 7 * block[1 + 4 * i] - 17 * block[3 + 4 * i];
205 const int z3 = 17 * block[1 + 4 * i] + 7 * block[3 + 4 * i];
207 block[0 + 4 * i] = z0 + z3;
208 block[1 + 4 * i] = z1 + z2;
209 block[2 + 4 * i] = z1 - z2;
210 block[3 + 4 * i] = z0 - z3;
213 for (i = 0; i < 4; i++) {
214 const int z0 = 13 * (block[i + 4 * 0] + block[i + 4 * 2]);
215 const int z1 = 13 * (block[i + 4 * 0] - block[i + 4 * 2]);
216 const int z2 = 7 * block[i + 4 * 1] - 17 * block[i + 4 * 3];
217 const int z3 = 17 * block[i + 4 * 1] + 7 * block[i + 4 * 3];
218 const int rr = (dc + 0x80000);
220 dst[i + stride * 0] = av_clip_uint8(dst[i + stride * 0] + ((z0 + z3) * qmul + rr >> 20));
221 dst[i + stride * 1] = av_clip_uint8(dst[i + stride * 1] + ((z1 + z2) * qmul + rr >> 20));
222 dst[i + stride * 2] = av_clip_uint8(dst[i + stride * 2] + ((z1 - z2) * qmul + rr >> 20));
223 dst[i + stride * 3] = av_clip_uint8(dst[i + stride * 3] + ((z0 - z3) * qmul + rr >> 20));
226 memset(block, 0, 16 *
sizeof(int16_t));
230 int index,
const int type)
232 static const uint8_t *
const scan_patterns[4] =
237 const int intra = 3 * type >> 2;
238 const uint8_t *
const scan = scan_patterns[type];
240 for (limit = (16 >> intra); index < 16; index = limit, limit += 8) {
245 sign = (vlc & 1) ? 0 : -1;
252 }
else if (vlc < 4) {
257 level = (vlc + 9 >> 2) - run;
265 level = (vlc >> 3) + ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1)));
268 level = (vlc >> 4) + ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0)));
273 if ((index += run) >= limit)
276 block[scan[
index]] = (level ^ sign) - sign;
289 int mx,
int my,
int dxy,
290 int thirdpel,
int dir,
int avg)
296 int blocksize = 2 - (width >> 3);
301 if (mx < 0 || mx >= s->
h_edge_pos - width - 1 ||
304 mx = av_clip(mx, -16, s->
h_edge_pos - width + 15);
305 my = av_clip(my, -16, s->
v_edge_pos - height + 15);
314 width + 1, height + 1,
328 mx = mx + (mx < (int) x) >> 1;
329 my = my + (my < (int) y) >> 1;
331 height = height >> 1;
334 for (i = 1; i < 3; i++) {
340 width + 1, height + 1,
362 int i, j, k, mx, my, dx, dy, x,
y;
364 const int part_width = ((size & 5) == 4) ? 4 : 16 >> (size & 1);
365 const int part_height = 16 >> ((unsigned)(size + 1) / 3);
366 const int extra_width = (mode ==
PREDICT_MODE) ? -16 * 6 : 0;
367 const int h_edge_pos = 6 * (s->
h_edge_pos - part_width) - extra_width;
368 const int v_edge_pos = 6 * (s->
v_edge_pos - part_height) - extra_width;
370 for (i = 0; i < 16; i += part_height)
371 for (j = 0; j < 16; j += part_width) {
372 const int b_xy = (4 * h->
mb_x + (j >> 2)) +
375 x = 16 * h->
mb_x + j;
376 y = 16 * h->
mb_y + i;
377 k = (j >> 2 & 1) + (i >> 1 & 2) +
378 (j >> 1 & 4) + (i & 8);
381 pred_motion(h, k, part_width >> 2, dir, 1, &mx, &my);
400 mx = av_clip(mx, extra_width - 6 * x, h_edge_pos - 6 * x);
401 my = av_clip(my, extra_width - 6 * y, v_edge_pos - 6 * y);
419 mx = (mx + 1 >> 1) + dx;
420 my = (my + 1 >> 1) + dy;
421 fx = (unsigned)(mx + 0x3000) / 3 - 0x1000;
422 fy = (unsigned)(my + 0x3000) / 3 - 0x1000;
423 dxy = (mx - 3 * fx) + 4 * (my - 3 * fy);
426 fx, fy, dxy, 1, dir, avg);
430 mx = (unsigned)(mx + 1 + 0x3000) / 3 + dx - 0x1000;
431 my = (unsigned)(my + 1 + 0x3000) / 3 + dy - 0x1000;
432 dxy = (mx & 1) + 2 * (my & 1);
435 mx >> 1, my >> 1, dxy, 0, dir, avg);
439 mx = (unsigned)(mx + 3 + 0x6000) / 6 + dx - 0x1000;
440 my = (unsigned)(my + 3 + 0x6000) / 6 + dy - 0x1000;
443 mx, my, 0, 0, dir, avg);
452 if (part_height == 8 && i < 8) {
455 if (part_width == 8 && j < 8)
458 if (part_width == 8 && j < 8)
460 if (part_width == 4 || part_height == 4)
466 part_width >> 2, part_height >> 2, h->
b_stride,
476 int i, j, k,
m, dir,
mode;
480 const int mb_xy = h->
mb_xy;
507 }
else if (mb_type < 8) {
525 for (m = 0; m < 2; m++) {
527 for (i = 0; i < 4; i++)
531 for (i = 0; i < 4; i++)
537 4 * 2 *
sizeof(int16_t));
573 for (i = 0; i < 4; i++)
575 0, 4 * 2 *
sizeof(int16_t));
581 for (i = 0; i < 4; i++)
583 0, 4 * 2 *
sizeof(int16_t));
588 }
else if (mb_type == 8 || mb_type == 33) {
593 for (i = 0; i < 4; i++)
609 for (i = 0; i < 16; i += 2) {
621 left[2] =
svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];
623 if (left[1] == -1 || left[2] == -1) {
629 for (i = 0; i < 4; i++)
641 for (i = 0; i < 4; i++)
651 dir = (dir >> 1) ^ 3 * (dir & 1) ^ 1;
663 for (i = 0; i < 4; i++)
665 0, 4 * 2 *
sizeof(int16_t));
667 for (i = 0; i < 4; i++)
669 0, 4 * 2 *
sizeof(int16_t));
703 "error while decoding intra luma dc\n");
712 for (i = 0; i < 4; i++)
713 if ((cbp & (1 << i))) {
714 for (j = 0; j < 4; j++) {
715 k = index ? (1 * (j & 1) + 2 * (i & 1) +
716 2 * (j & 2) + 4 * (i & 2))
722 "error while decoding block\n");
729 for (i = 1; i < 3; ++i)
732 "error while decoding chroma dc block\n");
737 for (i = 1; i < 3; i++) {
738 for (j = 0; j < 4; j++) {
744 "error while decoding chroma ac block\n");
766 const int mb_xy = h->
mb_xy;
772 if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
777 int length = header >> 5 & 3;
810 if ((header & 0x9F) == 2) {
838 -1, 4 *
sizeof(int8_t));
840 -1, 8 *
sizeof(int8_t) * h->
mb_x);
858 unsigned char *extradata;
859 unsigned char *extradata_end;
861 int marker_found = 0;
891 extradata = (
unsigned char *)avctx->
extradata;
895 if (!memcmp(extradata,
"SEQH", 4)) {
909 if (size > extradata_end - extradata - 8)
915 switch (frame_size_code) {
977 unsigned long buf_len = watermark_width *
978 watermark_height * 4;
982 if (watermark_height <= 0 || (uint64_t)watermark_width*4 > UINT_MAX/watermark_height)
987 watermark_width, watermark_height);
989 "u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n",
990 u1, u2, u3, u4, offset);
991 if (uncompress(buf, &buf_len, extradata + 8 + offset,
992 size - offset) != Z_OK) {
994 "could not uncompress watermark logo\n");
1005 "this svq3 file contains watermark which need zlib support compiled in\n");
1032 for (i = 0; i < 2; i++) {
1047 const int b4_stride = h->
mb_width * 4 + 1;
1048 const int b4_array_size = b4_stride * h->
mb_height * 4;
1059 for (i = 0; i < 2; i++) {
1098 int buf_size = avpkt->
size;
1104 if (buf_size == 0) {
1122 memcpy(s->
buf, avpkt->
data, buf_size);
1155 for (i = 0; i < 16; i++) {
1159 for (i = 0; i < 16; i++) {
1194 "%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n",
1230 for (m = 0; m < 2; m++) {
1232 for (i = 0; i < 4; i++) {
1234 for (j = -1; j < 4; j++)
1266 "error while decoding MB %d %d\n", h->
mb_x, h->
mb_y);
1270 if (mb_type != 0 || h->
cbp)