75 #define FULLPEL_MODE 1
76 #define HALFPEL_MODE 2
77 #define THIRDPEL_MODE 3
78 #define PREDICT_MODE 4
90 0+0*4, 1+0*4, 2+0*4, 2+1*4,
91 2+2*4, 3+0*4, 3+1*4, 3+2*4,
92 0+1*4, 0+2*4, 1+1*4, 1+2*4,
93 0+3*4, 1+3*4, 2+3*4, 3+3*4,
99 { 0, 2 }, { 1, 1 }, { 2, 0 },
100 { 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 },
101 { 0, 4 }, { 1, 3 }, { 2, 2 }, { 3, 1 }, { 4, 0 },
102 { 4, 1 }, { 3, 2 }, { 2, 3 }, { 1, 4 },
103 { 2, 4 }, { 3, 3 }, { 4, 2 },
109 { { 2,-1,-1,-1,-1 }, { 2, 1,-1,-1,-1 }, { 1, 2,-1,-1,-1 },
110 { 2, 1,-1,-1,-1 }, { 1, 2,-1,-1,-1 }, { 1, 2,-1,-1,-1 } },
111 { { 0, 2,-1,-1,-1 }, { 0, 2, 1, 4, 3 }, { 0, 1, 2, 4, 3 },
112 { 0, 2, 1, 4, 3 }, { 2, 0, 1, 3, 4 }, { 0, 4, 2, 1, 3 } },
113 { { 2, 0,-1,-1,-1 }, { 2, 1, 0, 4, 3 }, { 1, 2, 4, 0, 3 },
114 { 2, 1, 0, 4, 3 }, { 2, 1, 4, 3, 0 }, { 1, 2, 4, 0, 3 } },
115 { { 2, 0,-1,-1,-1 }, { 2, 0, 1, 4, 3 }, { 1, 2, 0, 4, 3 },
116 { 2, 1, 0, 4, 3 }, { 2, 1, 3, 4, 0 }, { 2, 4, 1, 0, 3 } },
117 { { 0, 2,-1,-1,-1 }, { 0, 2, 1, 3, 4 }, { 1, 2, 3, 0, 4 },
118 { 2, 0, 1, 3, 4 }, { 2, 1, 3, 0, 4 }, { 2, 0, 4, 3, 1 } },
119 { { 0, 2,-1,-1,-1 }, { 0, 2, 4, 1, 3 }, { 1, 4, 2, 0, 3 },
120 { 4, 2, 0, 1, 3 }, { 2, 0, 1, 4, 3 }, { 4, 2, 1, 0, 3 } },
124 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 0, 2 }, { 3, 1 }, { 4, 1 }, { 5, 1 },
125 { 0, 3 }, { 1, 2 }, { 2, 2 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 0, 4 } },
126 { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 2, 1 }, { 0, 3 }, { 0, 4 }, { 0, 5 },
127 { 3, 1 }, { 4, 1 }, { 1, 2 }, { 1, 3 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 } }
131 3881, 4351, 4890, 5481, 6154, 6914, 7761, 8718,
132 9781, 10987, 12339, 13828, 15523, 17435, 19561, 21873,
133 24552, 27656, 30847, 34870, 38807, 43747, 49103, 54683,
134 61694, 68745, 77615, 89113,100253,109366,126635,141533
142 static const uint8_t x_offset[4]={0, 1*
stride, 4*
stride, 5*stride};
145 const int z0 = 13*(input[4*i+0] + input[4*i+2]);
146 const int z1 = 13*(input[4*i+0] - input[4*i+2]);
147 const int z2 = 7* input[4*i+1] - 17*input[4*i+3];
148 const int z3 = 17* input[4*i+1] + 7*input[4*i+3];
157 const int offset= x_offset[i];
158 const int z0= 13*(temp[4*0+i] + temp[4*2+i]);
159 const int z1= 13*(temp[4*0+i] - temp[4*2+i]);
160 const int z2= 7* temp[4*1+i] - 17*temp[4*3+i];
161 const int z3= 17* temp[4*1+i] + 7*temp[4*3+i];
163 output[
stride* 0+offset] = ((z0 + z3)*qmul + 0x80000) >> 20;
164 output[
stride* 2+offset] = ((z1 + z2)*qmul + 0x80000) >> 20;
165 output[
stride* 8+offset] = ((z1 - z2)*qmul + 0x80000) >> 20;
166 output[
stride*10+offset] = ((z0 - z3)*qmul + 0x80000) >> 20;
178 dc = 13*13*((dc == 1) ? 1538*block[0] : ((qmul*(block[0] >> 3)) / 2));
182 for (i = 0; i < 4; i++) {
183 const int z0 = 13*(block[0 + 4*i] + block[2 + 4*i]);
184 const int z1 = 13*(block[0 + 4*i] - block[2 + 4*i]);
185 const int z2 = 7* block[1 + 4*i] - 17*block[3 + 4*i];
186 const int z3 = 17* block[1 + 4*i] + 7*block[3 + 4*i];
188 block[0 + 4*i] = z0 + z3;
189 block[1 + 4*i] = z1 + z2;
190 block[2 + 4*i] = z1 - z2;
191 block[3 + 4*i] = z0 - z3;
194 for (i = 0; i < 4; i++) {
195 const int z0 = 13*(block[i + 4*0] + block[i + 4*2]);
196 const int z1 = 13*(block[i + 4*0] - block[i + 4*2]);
197 const int z2 = 7* block[i + 4*1] - 17*block[i + 4*3];
198 const int z3 = 17* block[i + 4*1] + 7*block[i + 4*3];
199 const int rr = (dc + 0x80000);
201 dst[i + stride*0] = av_clip_uint8( dst[i + stride*0] + (((z0 + z3)*qmul + rr) >> 20) );
202 dst[i + stride*1] = av_clip_uint8( dst[i + stride*1] + (((z1 + z2)*qmul + rr) >> 20) );
203 dst[i + stride*2] = av_clip_uint8( dst[i + stride*2] + (((z1 - z2)*qmul + rr) >> 20) );
204 dst[i + stride*3] = av_clip_uint8( dst[i + stride*3] + (((z0 - z3)*qmul + rr) >> 20) );
209 int index,
const int type)
211 static const uint8_t *
const scan_patterns[4] =
215 const int intra = (3 * type) >> 2;
216 const uint8_t *
const scan = scan_patterns[type];
218 for (limit = (16 >> intra); index < 16; index = limit, limit += 8) {
224 sign = (vlc & 0x1) - 1;
225 vlc = (vlc + 1) >> 1;
231 }
else if (vlc < 4) {
236 level = ((vlc + 9) >> 2) -
run;
244 level = (vlc >> 3) + ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1)));
247 level = (vlc >> 4) + ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0)));
251 if ((index += run) >= limit)
254 block[scan[
index]] = (level ^ sign) - sign;
267 int mx,
int my,
int dxy,
268 int thirdpel,
int dir,
int avg)
273 int blocksize = 2 - (width>>3);
278 if (mx < 0 || mx >= (s->
h_edge_pos - width - 1) ||
279 my < 0 || my >= (s->
v_edge_pos - height - 1)) {
285 mx = av_clip (mx, -16, (s->
h_edge_pos - width + 15));
286 my = av_clip (my, -16, (s->
v_edge_pos - height + 15));
304 mx = (mx + (mx < (int) x)) >> 1;
305 my = (my + (my < (int) y)) >> 1;
306 width = (width >> 1);
307 height = (height >> 1);
310 for (i = 1; i < 3; i++) {
330 int i, j, k, mx, my, dx, dy, x, y;
332 const int part_width = ((size & 5) == 4) ? 4 : 16 >> (size & 1);
333 const int part_height = 16 >> ((unsigned) (size + 1) / 3);
334 const int extra_width = (mode ==
PREDICT_MODE) ? -16*6 : 0;
335 const int h_edge_pos = 6*(s->
h_edge_pos - part_width ) - extra_width;
336 const int v_edge_pos = 6*(s->
v_edge_pos - part_height) - extra_width;
338 for (i = 0; i < 16; i += part_height) {
339 for (j = 0; j < 16; j += part_width) {
340 const int b_xy = (4*s->
mb_x + (j >> 2)) + (4*s->
mb_y + (i >> 2))*h->
b_stride;
344 k = ((j >> 2) & 1) + ((i >> 1) & 2) + ((j >> 1) & 4) + (i & 8);
347 pred_motion(h, k, (part_width >> 2), dir, 1, &mx, &my);
362 mx = av_clip(mx, extra_width - 6*x, h_edge_pos - 6*x);
363 my = av_clip(my, extra_width - 6*y, v_edge_pos - 6*y);
381 mx = ((mx + 1)>>1) + dx;
382 my = ((my + 1)>>1) + dy;
383 fx = ((unsigned)(mx + 0x3000))/3 - 0x1000;
384 fy = ((unsigned)(my + 0x3000))/3 - 0x1000;
385 dxy = (mx - 3*fx) + 4*(my - 3*fy);
387 svq3_mc_dir_part(s, x, y, part_width, part_height, fx, fy, dxy, 1, dir, avg);
391 mx = ((unsigned)(mx + 1 + 0x3000))/3 + dx - 0x1000;
392 my = ((unsigned)(my + 1 + 0x3000))/3 + dy - 0x1000;
393 dxy = (mx&1) + 2*(my&1);
395 svq3_mc_dir_part(s, x, y, part_width, part_height, mx>>1, my>>1, dxy, 0, dir, avg);
399 mx = ((unsigned)(mx + 3 + 0x6000))/6 + dx - 0x1000;
400 my = ((unsigned)(my + 3 + 0x6000))/6 + dy - 0x1000;
402 svq3_mc_dir_part(s, x, y, part_width, part_height, mx, my, 0, 0, dir, avg);
411 if (part_height == 8 && i < 8) {
414 if (part_width == 8 && j < 8) {
418 if (part_width == 8 && j < 8) {
421 if (part_width == 4 || part_height == 4) {
428 part_width >> 2, part_height >> 2, h->
b_stride,
439 int i, j, k, m, dir, mode;
444 const int mb_xy = h->
mb_xy;
453 svq3_mc_dir_part(s, 16*s->
mb_x, 16*s->
mb_y, 16, 16, 0, 0, 0, 0, 0, 0);
456 svq3_mc_dir_part(s, 16*s->
mb_x, 16*s->
mb_y, 16, 16, 0, 0, 0, 0, 1, 1);
469 }
else if (mb_type < 8) {
487 for (m = 0; m < 2; m++) {
489 for (i = 0; i < 4; i++) {
493 for (i = 0; i < 4; i++) {
529 for (i = 0; i < 4; i++) {
534 if (
svq3_mc_dir(h, 0, mode, 1, (mb_type == 3)) < 0)
537 for (i = 0; i < 4; i++) {
544 }
else if (mb_type == 8 || mb_type == 33) {
549 for (i = 0; i < 4; i++) {
568 for (i = 0; i < 16; i+=2) {
580 left[2] =
svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];
582 if (left[1] == -1 || left[2] == -1){
588 for (i = 0; i < 4; i++) {
601 for (i = 0; i < 4; i++) {
612 dir = (dir >> 1) ^ 3*(dir & 1) ^ 1;
624 for (i = 0; i < 4; i++) {
628 for (i = 0; i < 4; i++) {
671 for (i = 0; i < 4; i++) {
672 if ((cbp & (1 << i))) {
673 for (j = 0; j < 4; j++) {
674 k = index ? ((j&1) + 2*(i&1) + 2*(j&2) + 4*(i&2)) : (4*i + j);
686 for (i = 1; i < 3; ++i) {
694 for (i = 1; i < 3; i++) {
695 for (j = 0; j < 4; j++) {
724 const int mb_xy = h->
mb_xy;
729 if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
734 int length = (header >> 5) & 3;
764 if ((header & 0x9F) == 2) {
765 i = (s->
mb_num < 64) ? 6 : (1 + av_log2 (s->
mb_num - 1));
812 unsigned char *extradata;
813 unsigned char *extradata_end;
815 int marker_found = 0;
834 extradata = (
unsigned char *)avctx->
extradata;
838 if (!memcmp(extradata,
"SEQH", 4)) {
853 if (size > extradata_end - extradata - 8)
859 switch (frame_size_code) {
860 case 0: avctx->
width = 160; avctx->
height = 120;
break;
861 case 1: avctx->
width = 128; avctx->
height = 96;
break;
862 case 2: avctx->
width = 176; avctx->
height = 144;
break;
863 case 3: avctx->
width = 352; avctx->
height = 288;
break;
864 case 4: avctx->
width = 704; avctx->
height = 576;
break;
865 case 5: avctx->
width = 240; avctx->
height = 180;
break;
866 case 6: avctx->
width = 320; avctx->
height = 240;
break;
901 unsigned long buf_len = watermark_width*watermark_height*4;
905 if (watermark_height > 0 &&
906 (uint64_t)watermark_width * 4 > UINT_MAX / watermark_height)
910 av_log(avctx,
AV_LOG_DEBUG,
"watermark size: %dx%d\n", watermark_width, watermark_height);
911 av_log(avctx,
AV_LOG_DEBUG,
"u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n", u1, u2, u3, u4, offset);
912 if (uncompress(buf, &buf_len, extradata + 8 + offset, size - offset) != Z_OK) {
922 av_log(avctx,
AV_LOG_ERROR,
"this svq3 file contains watermark which need zlib support compiled in\n");
946 void *
data,
int *data_size,
949 const uint8_t *buf = avpkt->
data;
953 int buf_size = avpkt->
size;
1024 for (m = 0; m < 2; m++){
1026 for (i = 0; i < 4; i++){
1028 for (j = -1; j < 4; j++)