72 #define MAX_CBS_4x4 255
74 #define MAX_CBS_2x2 256
77 #define ROQ_LAMBDA_SCALE ((uint64_t) FF_LAMBDA_SCALE)
82 memcpy(u , cell->
y, 4);
83 memset(u+4, cell->
u, 4);
84 memset(u+8, cell->
v, 4);
90 static const int offsets[4] = {0, 2, 8, 10};
92 for (cp=0; cp<3; cp++)
94 u[4*4*cp + offsets[i] ] = cb2[qcell->
idx[i]*2*2*3 + 4*cp ];
95 u[4*4*cp + offsets[i]+1] = cb2[qcell->
idx[i]*2*2*3 + 4*cp+1];
96 u[4*4*cp + offsets[i]+4] = cb2[qcell->
idx[i]*2*2*3 + 4*cp+2];
97 u[4*4*cp + offsets[i]+5] = cb2[qcell->
idx[i]*2*2*3 + 4*cp+3];
106 for(cp=0; cp<3; cp++)
109 *u++ = base[(y/2)*4 + (x/2) + 16*cp];
122 diff +=
square(*b++ - *a++);
130 int x2,
int y2,
const int *stride1,
const int *stride2,
int size)
135 for (k=0; k<3; k++) {
137 for (i=0; i<
size; i++)
138 sse += bias*
eval_sse(buf1[k] + (y1+i)*stride1[k] + x1,
139 buf2[k] + (y2+i)*stride2[k] + x2, size);
151 if (mx < -7 || mx > 7)
154 if (my < -7 || my > 7)
160 if ((
unsigned) mx > enc->
width-size || (
unsigned) my > enc->
height-size)
176 for(cp=0;cp<3;cp++) {
178 sdiff += bias*
eval_sse(a, b, size*size);
224 typedef struct RoqTempData
254 for (y=0; y<enc->
height; y+=16)
255 for (x=0; x<enc->
width; x+=16)
269 for (cp=0; cp<3; cp++) {
271 for (i=0; i<
dim; i++)
272 for (j=0; j<
dim; j++)
273 *mb++ = frame->
data[cp][(y+i)*stride + x + j];
281 int *outIndex,
int dim)
283 int i, lDiff = INT_MAX, pick=0;
286 for (i=0; i<numCB; i++) {
298 #define EVAL_MOTION(MOTION) \
300 diff = eval_motion_dist(enc, j, i, MOTION, blocksize); \
302 if (diff < lowestdiff) { \
321 int diff, lowestdiff, oldbest;
330 int max=(enc->
width/blocksize)*enc->
height/blocksize;
332 if (blocksize == 4) {
340 for (i=0; i<enc->
height; i+=blocksize)
341 for (j=0; j<enc->
width; j+=blocksize) {
350 offset = (i/blocksize)*enc->
width/blocksize + j/blocksize;
351 if (offset < max && offset >= 0)
355 if (offset < max && offset >= 0)
358 offset = (i/blocksize + 1)*enc->
width/blocksize + j/blocksize;
359 if (offset < max && offset >= 0)
362 off[0]= (i/blocksize)*enc->
width/blocksize + j/blocksize - 1;
363 off[1]= off[0] - enc->
width/blocksize + 1;
369 vect.
d[k]=
mid_pred(this_motion[off[0]].d[k],
370 this_motion[off[1]].d[k],
371 this_motion[off[2]].d[k]);
382 while (oldbest != lowestdiff) {
383 oldbest = lowestdiff;
384 for (k=0; k<8; k++) {
386 vect2.
d[0] += offsets[k].
d[0];
387 vect2.
d[1] += offsets[k].
d[1];
392 offset = (i/blocksize)*enc->
width/blocksize + j/blocksize;
393 this_motion[offset] = bestpick;
408 static const int bitsUsed[4] = {2, 10, 10, 34};
429 cluster_index = y*enc->
width/16 + x/4;
469 int i, j, best_dist, divide_bit_use;
471 int bitsUsed[4] = {2, 10, 10, 0};
505 for (i=0; i<4; i++) {
512 bitsUsed[3] = 2 + divide_bit_use;
529 for (i=0; i<4; i++) {
545 tempData->
i2f4[i] = idx;
546 tempData->
f2i4[idx] = i;
558 tempData->
i2f2[i] = idx;
559 tempData->
f2i2[idx] = i;
577 bytestream_put_le32(outp, tempData->
numCB2*6 + tempData->
numCB4*4);
578 bytestream_put_byte(outp, tempData->
numCB4);
579 bytestream_put_byte(outp, tempData->
numCB2);
581 for (i=0; i<tempData->
numCB2; i++) {
583 bytestream_put_byte(outp, enc->
cb2x2[tempData->
f2i2[i]].
u);
584 bytestream_put_byte(outp, enc->
cb2x2[tempData->
f2i2[i]].
v);
587 for (i=0; i<tempData->
numCB4; i++)
589 bytestream_put_byte(outp, tempData->
i2f2[enc->
cb4x4[tempData->
f2i4[i]].
idx[j]]);
598 return ((ax&15)<<4) | (ay&15);
648 bytestream_put_byte(&enc->
out_buf, 0x0);
649 bytestream_put_byte(&enc->
out_buf, 0x0);
651 for (i=0; i<numBlocks; i++) {
685 for (j=0; j<4; j++) {
694 bytestream_put_byte(&spool.
args,
703 bytestream_put_byte(&spool.
args,
719 for (k=0; k<4; k++) {
721 bytestream_put_byte(&spool.
args,
722 tempData->
i2f2[cb_idx]);
725 enc->
cb2x2 + cb_idx);
760 int top,
int left,
const int *
stride)
765 for (j=0; j<2; j++) {
766 int x = (top+i)*stride[0] + left + j;
767 *block++ = data[0][x];
768 x = (top+i)*stride[1] + left + j;
785 for (j=0; j<w; j+=4) {
786 for (k=0; k < 2; k++)
787 for (l=0; l < 2; l++)
795 int *points,
int inputCount,
roq_cell *results,
796 int size,
int cbsize)
799 int c_size = size*size/4;
801 int *codebook =
av_malloc(6*c_size*cbsize*
sizeof(
int));
805 closest_cb =
av_malloc(6*c_size*inputCount*
sizeof(
int));
809 ff_init_elbg(points, 6*c_size, inputCount, codebook, cbsize, 1, closest_cb, &enc->
randctx);
810 ff_do_elbg(points, 6*c_size, inputCount, codebook, cbsize, 1, closest_cb, &enc->
randctx);
816 for (i=0; i<cbsize; i++)
817 for (k=0; k<c_size; k++) {
819 results->
y[j] = *buf++;
837 int *points =
av_malloc(max*6*4*
sizeof(
int));
844 for (i=0; i<max*24; i++) {
846 points[i] = bias*yuvClusters[i];
862 for (i=0; i<codebooks->
numCB2; i++)
866 for (i=0; i<codebooks->
numCB4; i++) {
867 for (j=0; j<4; j++) {
888 memset(tempData, 0,
sizeof(*tempData));
906 "Warning, generated a frame too big (%d > 65535), "
907 "try using a smaller qscale value.\n",
963 if ((avctx->
width & 0xf) || (avctx->
height & 0xf)) {
1007 bytestream_put_le32(&enc->
out_buf, 8);
1010 bytestream_put_byte(&enc->
out_buf, 0x00);
1011 bytestream_put_byte(&enc->
out_buf, 0x00);
1020 bytestream_put_byte(&enc->
out_buf, 0x08);
1021 bytestream_put_byte(&enc->
out_buf, 0x00);
1022 bytestream_put_byte(&enc->
out_buf, 0x04);
1023 bytestream_put_byte(&enc->
out_buf, 0x00);
1043 size = ((enc->
width * enc->
height / 64) * 138 + 7) / 8 + 256 * (6 + 4) + 8;
1085 .supported_framerates = (
const AVRational[]){ {30,1}, {0,0} },