73 #define MAX_CBS_4x4 256
75 #define MAX_CBS_2x2 256
78 #define ROQ_LAMBDA_SCALE ((uint64_t) FF_LAMBDA_SCALE)
83 memcpy(u , cell->
y, 4);
84 memset(u+4, cell->
u, 4);
85 memset(u+8, cell->
v, 4);
91 static const int offsets[4] = {0, 2, 8, 10};
93 for (cp=0; cp<3; cp++)
95 u[4*4*cp + offsets[i] ] = cb2[qcell->
idx[i]*2*2*3 + 4*cp ];
96 u[4*4*cp + offsets[i]+1] = cb2[qcell->
idx[i]*2*2*3 + 4*cp+1];
97 u[4*4*cp + offsets[i]+4] = cb2[qcell->
idx[i]*2*2*3 + 4*cp+2];
98 u[4*4*cp + offsets[i]+5] = cb2[qcell->
idx[i]*2*2*3 + 4*cp+3];
107 for(cp=0; cp<3; cp++)
110 *u++ = base[(y/2)*4 + (x/2) + 16*cp];
123 diff +=
square(*b++ - *a++);
131 int x2,
int y2,
const int *stride1,
const int *stride2,
int size)
136 for (k=0; k<3; k++) {
138 for (i=0; i<
size; i++)
139 sse += bias*
eval_sse(buf1[k] + (y1+i)*stride1[k] + x1,
140 buf2[k] + (y2+i)*stride2[k] + x2, size);
152 if (mx < -7 || mx > 7)
155 if (my < -7 || my > 7)
161 if ((
unsigned) mx > enc->
width-size || (
unsigned) my > enc->
height-size)
177 for(cp=0;cp<3;cp++) {
179 sdiff += bias*
eval_sse(a, b, size*size);
225 typedef struct RoqTempData
255 for (y=0; y<enc->
height; y+=16)
256 for (x=0; x<enc->
width; x+=16)
270 for (cp=0; cp<3; cp++) {
272 for (i=0; i<
dim; i++)
273 for (j=0; j<
dim; j++)
274 *mb++ = frame->
data[cp][(y+i)*stride + x + j];
282 int *outIndex,
int dim)
284 int i, lDiff = INT_MAX, pick=0;
287 for (i=0; i<numCB; i++) {
299 #define EVAL_MOTION(MOTION) \
301 diff = eval_motion_dist(enc, j, i, MOTION, blocksize); \
303 if (diff < lowestdiff) { \
322 int diff, lowestdiff, oldbest;
331 int max=(enc->
width/blocksize)*enc->
height/blocksize;
333 if (blocksize == 4) {
341 for (i=0; i<enc->
height; i+=blocksize)
342 for (j=0; j<enc->
width; j+=blocksize) {
351 offset = (i/blocksize)*enc->
width/blocksize + j/blocksize;
352 if (offset < max && offset >= 0)
356 if (offset < max && offset >= 0)
359 offset = (i/blocksize + 1)*enc->
width/blocksize + j/blocksize;
360 if (offset < max && offset >= 0)
363 off[0]= (i/blocksize)*enc->
width/blocksize + j/blocksize - 1;
364 off[1]= off[0] - enc->
width/blocksize + 1;
370 vect.
d[k]=
mid_pred(this_motion[off[0]].d[k],
371 this_motion[off[1]].d[k],
372 this_motion[off[2]].d[k]);
383 while (oldbest != lowestdiff) {
384 oldbest = lowestdiff;
385 for (k=0; k<8; k++) {
387 vect2.
d[0] += offsets[k].
d[0];
388 vect2.
d[1] += offsets[k].
d[1];
393 offset = (i/blocksize)*enc->
width/blocksize + j/blocksize;
394 this_motion[offset] = bestpick;
409 static const int bitsUsed[4] = {2, 10, 10, 34};
430 cluster_index = y*enc->
width/16 + x/4;
470 int i, j, best_dist, divide_bit_use;
472 int bitsUsed[4] = {2, 10, 10, 0};
506 for (i=0; i<4; i++) {
513 bitsUsed[3] = 2 + divide_bit_use;
530 for (i=0; i<4; i++) {
546 tempData->
i2f4[i] = idx;
547 tempData->
f2i4[idx] = i;
559 tempData->
i2f2[i] = idx;
560 tempData->
f2i2[idx] = i;
578 bytestream_put_le32(outp, tempData->
numCB2*6 + tempData->
numCB4*4);
579 bytestream_put_byte(outp, tempData->
numCB4);
580 bytestream_put_byte(outp, tempData->
numCB2);
582 for (i=0; i<tempData->
numCB2; i++) {
584 bytestream_put_byte(outp, enc->
cb2x2[tempData->
f2i2[i]].
u);
585 bytestream_put_byte(outp, enc->
cb2x2[tempData->
f2i2[i]].
v);
588 for (i=0; i<tempData->
numCB4; i++)
590 bytestream_put_byte(outp, tempData->
i2f2[enc->
cb4x4[tempData->
f2i4[i]].
idx[j]]);
599 return ((ax&15)<<4) | (ay&15);
649 bytestream_put_byte(&enc->
out_buf, 0x0);
650 bytestream_put_byte(&enc->
out_buf, 0x0);
652 for (i=0; i<numBlocks; i++) {
686 for (j=0; j<4; j++) {
695 bytestream_put_byte(&spool.
args,
704 bytestream_put_byte(&spool.
args,
720 for (k=0; k<4; k++) {
722 bytestream_put_byte(&spool.
args,
723 tempData->
i2f2[cb_idx]);
726 enc->
cb2x2 + cb_idx);
761 int top,
int left,
const int *
stride)
766 for (j=0; j<2; j++) {
767 int x = (top+i)*stride[0] + left + j;
768 *block++ = data[0][x];
769 x = (top+i)*stride[1] + left + j;
786 for (j=0; j<w; j+=4) {
787 for (k=0; k < 2; k++)
788 for (l=0; l < 2; l++)
796 int *points,
int inputCount,
roq_cell *results,
797 int size,
int cbsize)
800 int c_size = size*size/4;
817 for (i=0; i<cbsize; i++)
818 for (k=0; k<c_size; k++) {
820 results->
y[j] = *buf++;
845 for (i=0; i<max*24; i++) {
847 points[i] = bias*yuvClusters[i];
863 for (i=0; i<codebooks->
numCB2; i++)
867 for (i=0; i<codebooks->
numCB4; i++) {
868 for (j=0; j<4; j++) {
889 memset(tempData, 0,
sizeof(*tempData));
906 if (enc->
lambda > 100000) {
911 "Warning, generated a frame too big for Quake (%d > 65535), "
912 "now switching to a bigger qscale value.\n",
970 if ((avctx->
width & 0xf) || (avctx->
height & 0xf)) {
975 if (avctx->
width > 65535 || avctx->
height > 65535) {
981 av_log(avctx,
AV_LOG_ERROR,
"Warning: dimensions not power of two, this is not supported by quake\n");
1019 bytestream_put_le32(&enc->
out_buf, 8);
1022 bytestream_put_byte(&enc->
out_buf, 0x00);
1023 bytestream_put_byte(&enc->
out_buf, 0x00);
1032 bytestream_put_byte(&enc->
out_buf, 0x08);
1033 bytestream_put_byte(&enc->
out_buf, 0x00);
1034 bytestream_put_byte(&enc->
out_buf, 0x04);
1035 bytestream_put_byte(&enc->
out_buf, 0x00);
1055 size = ((enc->
width * enc->
height / 64) * 138 + 7) / 8 + 256 * (6 + 4) + 8;
1089 #define OFFSET(x) offsetof(RoqContext, x)
1090 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1092 {
"quake3_compat",
"Whether to respect known limitations in Quake 3 decoder",
OFFSET(quake3_compat),
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1,
VE },