85 #define FULLPEL_MODE 1
86 #define HALFPEL_MODE 2
87 #define THIRDPEL_MODE 3
88 #define PREDICT_MODE 4
100 0 + 0 * 4, 1 + 0 * 4, 2 + 0 * 4, 2 + 1 * 4,
101 2 + 2 * 4, 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4,
102 0 + 1 * 4, 0 + 2 * 4, 1 + 1 * 4, 1 + 2 * 4,
103 0 + 3 * 4, 1 + 3 * 4, 2 + 3 * 4, 3 + 3 * 4,
109 { 0, 2 }, { 1, 1 }, { 2, 0 },
110 { 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 },
111 { 0, 4 }, { 1, 3 }, { 2, 2 }, { 3, 1 }, { 4, 0 },
112 { 4, 1 }, { 3, 2 }, { 2, 3 }, { 1, 4 },
113 { 2, 4 }, { 3, 3 }, { 4, 2 },
119 { { 2, -1, -1, -1, -1 }, { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 },
120 { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 }, { 1, 2, -1, -1, -1 } },
121 { { 0, 2, -1, -1, -1 }, { 0, 2, 1, 4, 3 }, { 0, 1, 2, 4, 3 },
122 { 0, 2, 1, 4, 3 }, { 2, 0, 1, 3, 4 }, { 0, 4, 2, 1, 3 } },
123 { { 2, 0, -1, -1, -1 }, { 2, 1, 0, 4, 3 }, { 1, 2, 4, 0, 3 },
124 { 2, 1, 0, 4, 3 }, { 2, 1, 4, 3, 0 }, { 1, 2, 4, 0, 3 } },
125 { { 2, 0, -1, -1, -1 }, { 2, 0, 1, 4, 3 }, { 1, 2, 0, 4, 3 },
126 { 2, 1, 0, 4, 3 }, { 2, 1, 3, 4, 0 }, { 2, 4, 1, 0, 3 } },
127 { { 0, 2, -1, -1, -1 }, { 0, 2, 1, 3, 4 }, { 1, 2, 3, 0, 4 },
128 { 2, 0, 1, 3, 4 }, { 2, 1, 3, 0, 4 }, { 2, 0, 4, 3, 1 } },
129 { { 0, 2, -1, -1, -1 }, { 0, 2, 4, 1, 3 }, { 1, 4, 2, 0, 3 },
130 { 4, 2, 0, 1, 3 }, { 2, 0, 1, 4, 3 }, { 4, 2, 1, 0, 3 } },
133 static const struct {
137 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 0, 2 }, { 3, 1 }, { 4, 1 }, { 5, 1 },
138 { 0, 3 }, { 1, 2 }, { 2, 2 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 0, 4 } },
139 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 2, 1 }, { 0, 3 }, { 0, 4 }, { 0, 5 },
140 { 3, 1 }, { 4, 1 }, { 1, 2 }, { 1, 3 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 } }
144 3881, 4351, 4890, 5481, 6154, 6914, 7761, 8718,
145 9781, 10987, 12339, 13828, 15523, 17435, 19561, 21873,
146 24552, 27656, 30847, 34870, 38807, 43747, 49103, 54683,
147 61694, 68745, 77615, 89113, 100253, 109366, 126635, 141533
158 for (i = 0; i < 4; i++) {
159 const int z0 = 13 * (input[4 * i + 0] + input[4 * i + 2]);
160 const int z1 = 13 * (input[4 * i + 0] - input[4 * i + 2]);
161 const int z2 = 7 * input[4 * i + 1] - 17 * input[4 * i + 3];
162 const int z3 = 17 * input[4 * i + 1] + 7 * input[4 * i + 3];
164 temp[4 * i + 0] = z0 + z3;
165 temp[4 * i + 1] = z1 + z2;
166 temp[4 * i + 2] = z1 - z2;
167 temp[4 * i + 3] = z0 - z3;
170 for (i = 0; i < 4; i++) {
171 const int offset = x_offset[i];
172 const int z0 = 13 * (temp[4 * 0 + i] + temp[4 * 2 + i]);
173 const int z1 = 13 * (temp[4 * 0 + i] - temp[4 * 2 + i]);
174 const int z2 = 7 * temp[4 * 1 + i] - 17 * temp[4 * 3 + i];
175 const int z3 = 17 * temp[4 * 1 + i] + 7 * temp[4 * 3 + i];
177 output[
stride * 0 +
offset] = (z0 + z3) * qmul + 0x80000 >> 20;
178 output[
stride * 2 +
offset] = (z1 + z2) * qmul + 0x80000 >> 20;
179 output[
stride * 8 +
offset] = (z1 - z2) * qmul + 0x80000 >> 20;
180 output[
stride * 10 +
offset] = (z0 - z3) * qmul + 0x80000 >> 20;
186 int stride,
int qp,
int dc)
192 dc = 13 * 13 * (dc == 1 ? 1538 * block[0]
193 : qmul * (block[0] >> 3) / 2);
197 for (i = 0; i < 4; i++) {
198 const int z0 = 13 * (block[0 + 4 * i] + block[2 + 4 * i]);
199 const int z1 = 13 * (block[0 + 4 * i] - block[2 + 4 * i]);
200 const int z2 = 7 * block[1 + 4 * i] - 17 * block[3 + 4 * i];
201 const int z3 = 17 * block[1 + 4 * i] + 7 * block[3 + 4 * i];
203 block[0 + 4 * i] = z0 + z3;
204 block[1 + 4 * i] = z1 + z2;
205 block[2 + 4 * i] = z1 - z2;
206 block[3 + 4 * i] = z0 - z3;
209 for (i = 0; i < 4; i++) {
210 const int z0 = 13 * (block[i + 4 * 0] + block[i + 4 * 2]);
211 const int z1 = 13 * (block[i + 4 * 0] - block[i + 4 * 2]);
212 const int z2 = 7 * block[i + 4 * 1] - 17 * block[i + 4 * 3];
213 const int z3 = 17 * block[i + 4 * 1] + 7 * block[i + 4 * 3];
214 const int rr = (dc + 0x80000);
216 dst[i + stride * 0] = av_clip_uint8(dst[i + stride * 0] + ((z0 + z3) * qmul + rr >> 20));
217 dst[i + stride * 1] = av_clip_uint8(dst[i + stride * 1] + ((z1 + z2) * qmul + rr >> 20));
218 dst[i + stride * 2] = av_clip_uint8(dst[i + stride * 2] + ((z1 - z2) * qmul + rr >> 20));
219 dst[i + stride * 3] = av_clip_uint8(dst[i + stride * 3] + ((z0 - z3) * qmul + rr >> 20));
222 memset(block, 0, 16 *
sizeof(int16_t));
226 int index,
const int type)
228 static const uint8_t *
const scan_patterns[4] =
233 const int intra = 3 * type >> 2;
234 const uint8_t *
const scan = scan_patterns[type];
236 for (limit = (16 >> intra); index < 16; index = limit, limit += 8) {
241 sign = (vlc & 1) ? 0 : -1;
248 }
else if (vlc < 4) {
253 level = (vlc + 9 >> 2) - run;
261 level = (vlc >> 3) + ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1)));
264 level = (vlc >> 4) + ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0)));
269 if ((index += run) >= limit)
272 block[scan[
index]] = (level ^ sign) - sign;
285 int mx,
int my,
int dxy,
286 int thirdpel,
int dir,
int avg)
292 int blocksize = 2 - (width >> 3);
297 if (mx < 0 || mx >= s->
h_edge_pos - width - 1 ||
300 mx = av_clip(mx, -16, s->
h_edge_pos - width + 15);
301 my = av_clip(my, -16, s->
v_edge_pos - height + 15);
310 width + 1, height + 1,
324 mx = mx + (mx < (int) x) >> 1;
325 my = my + (my < (int) y) >> 1;
327 height = height >> 1;
330 for (i = 1; i < 3; i++) {
336 width + 1, height + 1,
358 int i, j, k, mx, my, dx, dy, x,
y;
360 const int part_width = ((size & 5) == 4) ? 4 : 16 >> (size & 1);
361 const int part_height = 16 >> ((unsigned)(size + 1) / 3);
362 const int extra_width = (mode ==
PREDICT_MODE) ? -16 * 6 : 0;
363 const int h_edge_pos = 6 * (s->
h_edge_pos - part_width) - extra_width;
364 const int v_edge_pos = 6 * (s->
v_edge_pos - part_height) - extra_width;
366 for (i = 0; i < 16; i += part_height)
367 for (j = 0; j < 16; j += part_width) {
368 const int b_xy = (4 * h->
mb_x + (j >> 2)) +
371 x = 16 * h->
mb_x + j;
372 y = 16 * h->
mb_y + i;
373 k = (j >> 2 & 1) + (i >> 1 & 2) +
374 (j >> 1 & 4) + (i & 8);
377 pred_motion(h, k, part_width >> 2, dir, 1, &mx, &my);
396 mx = av_clip(mx, extra_width - 6 * x, h_edge_pos - 6 * x);
397 my = av_clip(my, extra_width - 6 * y, v_edge_pos - 6 * y);
415 mx = (mx + 1 >> 1) + dx;
416 my = (my + 1 >> 1) + dy;
417 fx = (unsigned)(mx + 0x3000) / 3 - 0x1000;
418 fy = (unsigned)(my + 0x3000) / 3 - 0x1000;
419 dxy = (mx - 3 * fx) + 4 * (my - 3 * fy);
422 fx, fy, dxy, 1, dir, avg);
426 mx = (unsigned)(mx + 1 + 0x3000) / 3 + dx - 0x1000;
427 my = (unsigned)(my + 1 + 0x3000) / 3 + dy - 0x1000;
428 dxy = (mx & 1) + 2 * (my & 1);
431 mx >> 1, my >> 1, dxy, 0, dir, avg);
435 mx = (unsigned)(mx + 3 + 0x6000) / 6 + dx - 0x1000;
436 my = (unsigned)(my + 3 + 0x6000) / 6 + dy - 0x1000;
439 mx, my, 0, 0, dir, avg);
448 if (part_height == 8 && i < 8) {
451 if (part_width == 8 && j < 8)
454 if (part_width == 8 && j < 8)
456 if (part_width == 4 || part_height == 4)
462 part_width >> 2, part_height >> 2, h->
b_stride,
472 int i, j, k,
m, dir,
mode;
476 const int mb_xy = h->
mb_xy;
503 }
else if (mb_type < 8) {
521 for (m = 0; m < 2; m++) {
523 for (i = 0; i < 4; i++)
527 for (i = 0; i < 4; i++)
533 4 * 2 *
sizeof(int16_t));
569 for (i = 0; i < 4; i++)
571 0, 4 * 2 *
sizeof(int16_t));
577 for (i = 0; i < 4; i++)
579 0, 4 * 2 *
sizeof(int16_t));
584 }
else if (mb_type == 8 || mb_type == 33) {
589 for (i = 0; i < 4; i++)
605 for (i = 0; i < 16; i += 2) {
617 left[2] =
svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];
619 if (left[1] == -1 || left[2] == -1) {
625 for (i = 0; i < 4; i++)
637 for (i = 0; i < 4; i++)
647 dir = (dir >> 1) ^ 3 * (dir & 1) ^ 1;
659 for (i = 0; i < 4; i++)
661 0, 4 * 2 *
sizeof(int16_t));
663 for (i = 0; i < 4; i++)
665 0, 4 * 2 *
sizeof(int16_t));
699 "error while decoding intra luma dc\n");
708 for (i = 0; i < 4; i++)
709 if ((cbp & (1 << i))) {
710 for (j = 0; j < 4; j++) {
711 k = index ? (1 * (j & 1) + 2 * (i & 1) +
712 2 * (j & 2) + 4 * (i & 2))
718 "error while decoding block\n");
725 for (i = 1; i < 3; ++i)
728 "error while decoding chroma dc block\n");
733 for (i = 1; i < 3; i++) {
734 for (j = 0; j < 4; j++) {
740 "error while decoding chroma ac block\n");
762 const int mb_xy = h->
mb_xy;
768 if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
773 int length = header >> 5 & 3;
806 if ((header & 0x9F) == 2) {
834 -1, 4 *
sizeof(int8_t));
836 -1, 8 *
sizeof(int8_t) * h->
mb_x);
854 unsigned char *extradata;
855 unsigned char *extradata_end;
857 int marker_found = 0;
886 extradata = (
unsigned char *)avctx->
extradata;
890 if (!memcmp(extradata,
"SEQH", 4)) {
904 if (size > extradata_end - extradata - 8)
910 switch (frame_size_code) {
972 unsigned long buf_len = watermark_width *
973 watermark_height * 4;
977 if (watermark_height <= 0 || (uint64_t)watermark_width*4 > UINT_MAX/watermark_height)
982 watermark_width, watermark_height);
984 "u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n",
985 u1, u2, u3, u4, offset);
986 if (uncompress(buf, &buf_len, extradata + 8 + offset,
987 size - offset) != Z_OK) {
989 "could not uncompress watermark logo\n");
1000 "this svq3 file contains watermark which need zlib support compiled in\n");
1030 const int b4_stride = h->
mb_width * 4 + 1;
1031 const int b4_array_size = b4_stride * h->
mb_height * 4;
1042 for (i = 0; i < 2; i++) {
1072 int buf_size = avpkt->
size;
1078 if (buf_size == 0) {
1094 memcpy(s->
buf, avpkt->
data, buf_size);
1124 for (i = 0; i < 16; i++) {
1128 for (i = 0; i < 16; i++) {
1163 "%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n",
1199 for (m = 0; m < 2; m++) {
1201 for (i = 0; i < 4; i++) {
1203 for (j = -1; j < 4; j++)
1235 "error while decoding MB %d %d\n", h->
mb_x, h->
mb_y);
1239 if (mb_type != 0 || h->
cbp)
1283 for (i = 0; i < 2; i++) {