70 #define MAX_CBS_4x4 255
72 #define MAX_CBS_2x2 256
75 #define ROQ_LAMBDA_SCALE ((uint64_t) FF_LAMBDA_SCALE)
80 memcpy(u , cell->
y, 4);
81 memset(u+4, cell->
u, 4);
82 memset(u+8, cell->
v, 4);
88 static const int offsets[4] = {0, 2, 8, 10};
90 for (cp=0; cp<3; cp++)
92 u[4*4*cp + offsets[i] ] = cb2[qcell->
idx[i]*2*2*3 + 4*cp ];
93 u[4*4*cp + offsets[i]+1] = cb2[qcell->
idx[i]*2*2*3 + 4*cp+1];
94 u[4*4*cp + offsets[i]+4] = cb2[qcell->
idx[i]*2*2*3 + 4*cp+2];
95 u[4*4*cp + offsets[i]+5] = cb2[qcell->
idx[i]*2*2*3 + 4*cp+3];
104 for(cp=0; cp<3; cp++)
107 *u++ = base[(y/2)*4 + (x/2) + 16*cp];
115 static inline int eval_sse(uint8_t *
a, uint8_t *
b,
int count)
120 diff +=
square(*b++ - *a++);
127 static int block_sse(uint8_t **buf1, uint8_t **buf2,
int x1,
int y1,
int x2,
128 int y2,
int *stride1,
int *stride2,
int size)
133 for (k=0; k<3; k++) {
135 for (i=0; i<
size; i++)
136 sse += bias*
eval_sse(buf1[k] + (y1+i)*stride1[k] + x1,
137 buf2[k] + (y2+i)*stride2[k] + x2, size);
149 if (mx < -7 || mx > 7)
152 if (my < -7 || my > 7)
158 if ((
unsigned) mx > enc->
width-size || (
unsigned) my > enc->
height-size)
174 for(cp=0;cp<3;cp++) {
176 sdiff += bias*
eval_sse(a, b, size*size);
252 for (y=0; y<enc->
height; y+=16)
253 for (x=0; x<enc->
width; x+=16)
267 for (cp=0; cp<3; cp++) {
269 for (i=0; i<
dim; i++)
270 for (j=0; j<
dim; j++)
271 *mb++ = frame->
data[cp][(y+i)*stride + x + j];
278 static int index_mb(uint8_t cluster[], uint8_t cb[],
int numCB,
279 int *outIndex,
int dim)
281 int i, lDiff = INT_MAX, pick=0;
284 for (i=0; i<numCB; i++) {
296 #define EVAL_MOTION(MOTION) \
298 diff = eval_motion_dist(enc, j, i, MOTION, blocksize); \
300 if (diff < lowestdiff) { \
319 int diff, lowestdiff, oldbest;
328 int max=(enc->
width/blocksize)*enc->
height/blocksize;
330 if (blocksize == 4) {
338 for (i=0; i<enc->
height; i+=blocksize)
339 for (j=0; j<enc->
width; j+=blocksize) {
348 offset = (i/blocksize)*enc->
width/blocksize + j/blocksize;
349 if (offset < max && offset >= 0)
353 if (offset < max && offset >= 0)
356 offset = (i/blocksize + 1)*enc->
width/blocksize + j/blocksize;
357 if (offset < max && offset >= 0)
360 off[0]= (i/blocksize)*enc->
width/blocksize + j/blocksize - 1;
361 off[1]= off[0] - enc->
width/blocksize + 1;
367 vect.
d[k]=
mid_pred(this_motion[off[0]].d[k],
368 this_motion[off[1]].d[k],
369 this_motion[off[2]].d[k]);
380 while (oldbest != lowestdiff) {
381 oldbest = lowestdiff;
382 for (k=0; k<8; k++) {
384 vect2.
d[0] += offsets[k].
d[0];
385 vect2.
d[1] += offsets[k].
d[1];
390 offset = (i/blocksize)*enc->
width/blocksize + j/blocksize;
391 this_motion[offset] = bestpick;
406 static const int bitsUsed[4] = {2, 10, 10, 34};
427 cluster_index = y*enc->
width/16 + x/4;
467 int i, j, best_dist, divide_bit_use;
469 int bitsUsed[4] = {2, 10, 10, 0};
503 for (i=0; i<4; i++) {
510 bitsUsed[3] = 2 + divide_bit_use;
527 for (i=0; i<4; i++) {
543 tempData->
i2f4[i] = idx;
544 tempData->
f2i4[idx] = i;
556 tempData->
i2f2[i] = idx;
557 tempData->
f2i2[idx] = i;
575 bytestream_put_le32(outp, tempData->
numCB2*6 + tempData->
numCB4*4);
576 bytestream_put_byte(outp, tempData->
numCB4);
577 bytestream_put_byte(outp, tempData->
numCB2);
579 for (i=0; i<tempData->
numCB2; i++) {
581 bytestream_put_byte(outp, enc->
cb2x2[tempData->
f2i2[i]].
u);
582 bytestream_put_byte(outp, enc->
cb2x2[tempData->
f2i2[i]].
v);
585 for (i=0; i<tempData->
numCB4; i++)
587 bytestream_put_byte(outp, tempData->
i2f2[enc->
cb4x4[tempData->
f2i4[i]].
idx[j]]);
594 uint8_t ax = 8 - ((uint8_t) mot.
d[0]);
595 uint8_t ay = 8 - ((uint8_t) mot.
d[1]);
596 return ((ax&15)<<4) | (ay&15);
603 uint8_t argumentSpool[64];
646 bytestream_put_byte(&enc->
out_buf, 0x0);
647 bytestream_put_byte(&enc->
out_buf, 0x0);
649 for (i=0; i<numBlocks; i++) {
683 for (j=0; j<4; j++) {
692 bytestream_put_byte(&spool.
args,
701 bytestream_put_byte(&spool.
args,
717 for (k=0; k<4; k++) {
719 bytestream_put_byte(&spool.
args,
720 tempData->
i2f2[cb_idx]);
723 enc->
cb2x2 + cb_idx);
758 int top,
int left,
int *
stride)
763 for (j=0; j<2; j++) {
764 int x = (top+i)*stride[0] + left + j;
765 *block++ = data[0][x];
766 x = (top+i)*stride[1] + left + j;
783 for (j=0; j<w; j+=4) {
784 for (k=0; k < 2; k++)
785 for (l=0; l < 2; l++)
793 int *points,
int inputCount,
roq_cell *results,
794 int size,
int cbsize)
797 int c_size = size*size/4;
799 int *codebook =
av_malloc(6*c_size*cbsize*
sizeof(
int));
803 closest_cb =
av_malloc(6*c_size*inputCount*
sizeof(
int));
807 ff_init_elbg(points, 6*c_size, inputCount, codebook, cbsize, 1, closest_cb, &enc->
randctx);
808 ff_do_elbg(points, 6*c_size, inputCount, codebook, cbsize, 1, closest_cb, &enc->
randctx);
814 for (i=0; i<cbsize; i++)
815 for (k=0; k<c_size; k++) {
817 results->
y[j] = *buf++;
834 uint8_t *yuvClusters=
av_malloc(
sizeof(
int)*max*6*4);
835 int *points =
av_malloc(max*6*4*
sizeof(
int));
842 for (i=0; i<max*24; i++) {
844 points[i] = bias*yuvClusters[i];
860 for (i=0; i<codebooks->
numCB2; i++)
864 for (i=0; i<codebooks->
numCB4; i++) {
865 for (j=0; j<4; j++) {
886 memset(tempData, 0,
sizeof(*tempData));
904 "Warning, generated a frame too big (%d > 65535), "
905 "try using a smaller qscale value.\n",
945 if ((avctx->
width & 0xf) || (avctx->
height & 0xf)) {
985 bytestream_put_le32(&enc->
out_buf, 8);
988 bytestream_put_byte(&enc->
out_buf, 0x00);
989 bytestream_put_byte(&enc->
out_buf, 0x00);
998 bytestream_put_byte(&enc->
out_buf, 0x08);
999 bytestream_put_byte(&enc->
out_buf, 0x00);
1000 bytestream_put_byte(&enc->
out_buf, 0x04);
1001 bytestream_put_byte(&enc->
out_buf, 0x00);
1008 uint8_t *buf_start = buf;
1022 if (((enc->
width*enc->
height/64)*138+7)/8 + 256*(6+4) + 8 > buf_size) {
1049 return enc->
out_buf - buf_start;
1076 .supported_framerates = (
const AVRational[]){{30,1}, {0,0}},