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,
111 0 * 16 + 0 * 64, 1 * 16 + 0 * 64, 2 * 16 + 0 * 64, 0 * 16 + 2 * 64,
112 3 * 16 + 0 * 64, 0 * 16 + 1 * 64, 1 * 16 + 1 * 64, 2 * 16 + 1 * 64,
113 1 * 16 + 2 * 64, 2 * 16 + 2 * 64, 3 * 16 + 2 * 64, 0 * 16 + 3 * 64,
114 3 * 16 + 1 * 64, 1 * 16 + 3 * 64, 2 * 16 + 3 * 64, 3 * 16 + 3 * 64,
120 { 0, 2 }, { 1, 1 }, { 2, 0 },
121 { 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 },
122 { 0, 4 }, { 1, 3 }, { 2, 2 }, { 3, 1 }, { 4, 0 },
123 { 4, 1 }, { 3, 2 }, { 2, 3 }, { 1, 4 },
124 { 2, 4 }, { 3, 3 }, { 4, 2 },
130 { { 2, -1, -1, -1, -1 }, { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 },
131 { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 }, { 1, 2, -1, -1, -1 } },
132 { { 0, 2, -1, -1, -1 }, { 0, 2, 1, 4, 3 }, { 0, 1, 2, 4, 3 },
133 { 0, 2, 1, 4, 3 }, { 2, 0, 1, 3, 4 }, { 0, 4, 2, 1, 3 } },
134 { { 2, 0, -1, -1, -1 }, { 2, 1, 0, 4, 3 }, { 1, 2, 4, 0, 3 },
135 { 2, 1, 0, 4, 3 }, { 2, 1, 4, 3, 0 }, { 1, 2, 4, 0, 3 } },
136 { { 2, 0, -1, -1, -1 }, { 2, 0, 1, 4, 3 }, { 1, 2, 0, 4, 3 },
137 { 2, 1, 0, 4, 3 }, { 2, 1, 3, 4, 0 }, { 2, 4, 1, 0, 3 } },
138 { { 0, 2, -1, -1, -1 }, { 0, 2, 1, 3, 4 }, { 1, 2, 3, 0, 4 },
139 { 2, 0, 1, 3, 4 }, { 2, 1, 3, 0, 4 }, { 2, 0, 4, 3, 1 } },
140 { { 0, 2, -1, -1, -1 }, { 0, 2, 4, 1, 3 }, { 1, 4, 2, 0, 3 },
141 { 4, 2, 0, 1, 3 }, { 2, 0, 1, 4, 3 }, { 4, 2, 1, 0, 3 } },
144 static const struct {
148 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 0, 2 }, { 3, 1 }, { 4, 1 }, { 5, 1 },
149 { 0, 3 }, { 1, 2 }, { 2, 2 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 0, 4 } },
150 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 2, 1 }, { 0, 3 }, { 0, 4 }, { 0, 5 },
151 { 3, 1 }, { 4, 1 }, { 1, 2 }, { 1, 3 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 } }
155 3881, 4351, 4890, 5481, 6154, 6914, 7761, 8718,
156 9781, 10987, 12339, 13828, 15523, 17435, 19561, 21873,
157 24552, 27656, 30847, 34870, 38807, 43747, 49103, 54683,
158 61694, 68745, 77615, 89113, 100253, 109366, 126635, 141533
169 for (i = 0; i < 4; i++) {
170 const int z0 = 13 * (input[4 * i + 0] + input[4 * i + 2]);
171 const int z1 = 13 * (input[4 * i + 0] - input[4 * i + 2]);
172 const int z2 = 7 * input[4 * i + 1] - 17 * input[4 * i + 3];
173 const int z3 = 17 * input[4 * i + 1] + 7 * input[4 * i + 3];
175 temp[4 * i + 0] = z0 + z3;
176 temp[4 * i + 1] = z1 + z2;
177 temp[4 * i + 2] = z1 - z2;
178 temp[4 * i + 3] = z0 - z3;
181 for (i = 0; i < 4; i++) {
182 const int offset = x_offset[i];
183 const int z0 = 13 * (temp[4 * 0 + i] + temp[4 * 2 + i]);
184 const int z1 = 13 * (temp[4 * 0 + i] - temp[4 * 2 + i]);
185 const int z2 = 7 * temp[4 * 1 + i] - 17 * temp[4 * 3 + i];
186 const int z3 = 17 * temp[4 * 1 + i] + 7 * temp[4 * 3 + i];
188 output[
stride * 0 +
offset] = (z0 + z3) * qmul + 0x80000 >> 20;
189 output[
stride * 2 +
offset] = (z1 + z2) * qmul + 0x80000 >> 20;
190 output[
stride * 8 +
offset] = (z1 - z2) * qmul + 0x80000 >> 20;
191 output[
stride * 10 +
offset] = (z0 - z3) * qmul + 0x80000 >> 20;
197 int stride,
int qp,
int dc)
203 dc = 13 * 13 * (dc == 1 ? 1538 * block[0]
204 : qmul * (block[0] >> 3) / 2);
208 for (i = 0; i < 4; i++) {
209 const int z0 = 13 * (block[0 + 4 * i] + block[2 + 4 * i]);
210 const int z1 = 13 * (block[0 + 4 * i] - block[2 + 4 * i]);
211 const int z2 = 7 * block[1 + 4 * i] - 17 * block[3 + 4 * i];
212 const int z3 = 17 * block[1 + 4 * i] + 7 * block[3 + 4 * i];
214 block[0 + 4 * i] = z0 + z3;
215 block[1 + 4 * i] = z1 + z2;
216 block[2 + 4 * i] = z1 - z2;
217 block[3 + 4 * i] = z0 - z3;
220 for (i = 0; i < 4; i++) {
221 const int z0 = 13 * (block[i + 4 * 0] + block[i + 4 * 2]);
222 const int z1 = 13 * (block[i + 4 * 0] - block[i + 4 * 2]);
223 const int z2 = 7 * block[i + 4 * 1] - 17 * block[i + 4 * 3];
224 const int z3 = 17 * block[i + 4 * 1] + 7 * block[i + 4 * 3];
225 const int rr = (dc + 0x80000);
227 dst[i + stride * 0] = av_clip_uint8(dst[i + stride * 0] + ((z0 + z3) * qmul + rr >> 20));
228 dst[i + stride * 1] = av_clip_uint8(dst[i + stride * 1] + ((z1 + z2) * qmul + rr >> 20));
229 dst[i + stride * 2] = av_clip_uint8(dst[i + stride * 2] + ((z1 - z2) * qmul + rr >> 20));
230 dst[i + stride * 3] = av_clip_uint8(dst[i + stride * 3] + ((z0 - z3) * qmul + rr >> 20));
233 memset(block, 0, 16 *
sizeof(int16_t));
237 int index,
const int type)
239 static const uint8_t *
const scan_patterns[4] =
244 const int intra = 3 * type >> 2;
245 const uint8_t *
const scan = scan_patterns[type];
247 for (limit = (16 >> intra); index < 16; index = limit, limit += 8) {
252 sign = (vlc & 1) ? 0 : -1;
259 }
else if (vlc < 4) {
264 level = (vlc + 9 >> 2) - run;
272 level = (vlc >> 3) + ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1)));
275 level = (vlc >> 4) + ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0)));
280 if ((index += run) >= limit)
283 block[scan[
index]] = (level ^ sign) - sign;
296 int mx,
int my,
int dxy,
297 int thirdpel,
int dir,
int avg)
303 int blocksize = 2 - (width >> 3);
308 if (mx < 0 || mx >= s->
h_edge_pos - width - 1 ||
311 mx = av_clip(mx, -16, s->
h_edge_pos - width + 15);
312 my = av_clip(my, -16, s->
v_edge_pos - height + 15);
322 width + 1, height + 1,
336 mx = mx + (mx < (int) x) >> 1;
337 my = my + (my < (int) y) >> 1;
339 height = height >> 1;
342 for (i = 1; i < 3; i++) {
349 width + 1, height + 1,
371 int i, j, k, mx, my, dx, dy, x,
y;
373 const int part_width = ((size & 5) == 4) ? 4 : 16 >> (size & 1);
374 const int part_height = 16 >> ((unsigned)(size + 1) / 3);
375 const int extra_width = (mode ==
PREDICT_MODE) ? -16 * 6 : 0;
376 const int h_edge_pos = 6 * (s->
h_edge_pos - part_width) - extra_width;
377 const int v_edge_pos = 6 * (s->
v_edge_pos - part_height) - extra_width;
379 for (i = 0; i < 16; i += part_height)
380 for (j = 0; j < 16; j += part_width) {
381 const int b_xy = (4 * h->
mb_x + (j >> 2)) +
384 x = 16 * h->
mb_x + j;
385 y = 16 * h->
mb_y + i;
386 k = (j >> 2 & 1) + (i >> 1 & 2) +
387 (j >> 1 & 4) + (i & 8);
390 pred_motion(h, k, part_width >> 2, dir, 1, &mx, &my);
409 mx = av_clip(mx, extra_width - 6 * x, h_edge_pos - 6 * x);
410 my = av_clip(my, extra_width - 6 * y, v_edge_pos - 6 * y);
428 mx = (mx + 1 >> 1) + dx;
429 my = (my + 1 >> 1) + dy;
430 fx = (unsigned)(mx + 0x3000) / 3 - 0x1000;
431 fy = (unsigned)(my + 0x3000) / 3 - 0x1000;
432 dxy = (mx - 3 * fx) + 4 * (my - 3 * fy);
435 fx, fy, dxy, 1, dir, avg);
439 mx = (unsigned)(mx + 1 + 0x3000) / 3 + dx - 0x1000;
440 my = (unsigned)(my + 1 + 0x3000) / 3 + dy - 0x1000;
441 dxy = (mx & 1) + 2 * (my & 1);
444 mx >> 1, my >> 1, dxy, 0, dir, avg);
448 mx = (unsigned)(mx + 3 + 0x6000) / 6 + dx - 0x1000;
449 my = (unsigned)(my + 3 + 0x6000) / 6 + dy - 0x1000;
452 mx, my, 0, 0, dir, avg);
461 if (part_height == 8 && i < 8) {
464 if (part_width == 8 && j < 8)
467 if (part_width == 8 && j < 8)
469 if (part_width == 4 || part_height == 4)
475 part_width >> 2, part_height >> 2, h->
b_stride,
485 int i, j, k,
m, dir,
mode;
489 const int mb_xy = h->
mb_xy;
516 }
else if (mb_type < 8) {
534 for (m = 0; m < 2; m++) {
536 for (i = 0; i < 4; i++)
540 for (i = 0; i < 4; i++)
546 4 * 2 *
sizeof(int16_t));
582 for (i = 0; i < 4; i++)
584 0, 4 * 2 *
sizeof(int16_t));
590 for (i = 0; i < 4; i++)
592 0, 4 * 2 *
sizeof(int16_t));
597 }
else if (mb_type == 8 || mb_type == 33) {
602 for (i = 0; i < 4; i++)
618 for (i = 0; i < 16; i += 2) {
630 left[2] =
svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];
632 if (left[1] == -1 || left[2] == -1) {
638 for (i = 0; i < 4; i++)
650 for (i = 0; i < 4; i++)
660 dir = (dir >> 1) ^ 3 * (dir & 1) ^ 1;
672 for (i = 0; i < 4; i++)
674 0, 4 * 2 *
sizeof(int16_t));
676 for (i = 0; i < 4; i++)
678 0, 4 * 2 *
sizeof(int16_t));
712 "error while decoding intra luma dc\n");
721 for (i = 0; i < 4; i++)
722 if ((cbp & (1 << i))) {
723 for (j = 0; j < 4; j++) {
724 k = index ? (1 * (j & 1) + 2 * (i & 1) +
725 2 * (j & 2) + 4 * (i & 2))
731 "error while decoding block\n");
738 for (i = 1; i < 3; ++i)
741 "error while decoding chroma dc block\n");
746 for (i = 1; i < 3; i++) {
747 for (j = 0; j < 4; j++) {
753 "error while decoding chroma ac block\n");
775 const int mb_xy = h->
mb_xy;
781 if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
786 int length = header >> 5 & 3;
819 if ((header & 0x9F) == 2) {
847 -1, 4 *
sizeof(int8_t));
849 -1, 8 *
sizeof(int8_t) * h->
mb_x);
867 unsigned char *extradata;
868 unsigned char *extradata_end;
870 int marker_found = 0;
900 extradata = (
unsigned char *)avctx->
extradata;
904 if (!memcmp(extradata,
"SEQH", 4)) {
918 if (size > extradata_end - extradata - 8)
924 switch (frame_size_code) {
986 unsigned long buf_len = watermark_width *
987 watermark_height * 4;
991 if (watermark_height <= 0 ||
992 (uint64_t)watermark_width * 4 > UINT_MAX / watermark_height)
997 watermark_width, watermark_height);
999 "u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n",
1000 u1, u2, u3, u4, offset);
1001 if (uncompress(buf, &buf_len, extradata + 8 + offset,
1002 size - offset) != Z_OK) {
1004 "could not uncompress watermark logo\n");
1015 "this svq3 file contains watermark which need zlib support compiled in\n");
1042 for (i = 0; i < 2; i++) {
1057 const int b4_stride = h->
mb_width * 4 + 1;
1058 const int b4_array_size = b4_stride * h->
mb_height * 4;
1069 for (i = 0; i < 2; i++) {
1108 int buf_size = avpkt->
size;
1114 if (buf_size == 0) {
1132 memcpy(s->
buf, avpkt->
data, buf_size);
1165 for (i = 0; i < 16; i++) {
1169 for (i = 0; i < 16; i++) {
1204 "%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n",
1240 for (m = 0; m < 2; m++) {
1242 for (i = 0; i < 4; i++) {
1244 for (j = -1; j < 4; j++)
1276 "error while decoding MB %d %d\n", h->
mb_x, h->
mb_y);
1280 if (mb_type != 0 || h->
cbp)