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);
222 typedef struct RoqTempData
254 for (y=0; y<enc->
height; y+=16)
255 for (x=0; x<enc->
width; x+=16)
271 for (cp=0; cp<3; cp++) {
273 for (i=0; i<
dim; i++)
274 for (j=0; j<
dim; j++)
275 *mb++ = frame->
data[cp][(y+i)*stride + x + j];
283 int *outIndex,
int dim)
285 int i, lDiff = INT_MAX, pick=0;
288 for (i=0; i<numCB; i++) {
300 #define EVAL_MOTION(MOTION) \
302 diff = eval_motion_dist(enc, j, i, MOTION, blocksize); \
304 if (diff < lowestdiff) { \
323 int diff, lowestdiff, oldbest;
332 int max=(enc->
width/blocksize)*enc->
height/blocksize;
334 if (blocksize == 4) {
342 for (i=0; i<enc->
height; i+=blocksize)
343 for (j=0; j<enc->
width; j+=blocksize) {
352 offset = (i/blocksize)*enc->
width/blocksize + j/blocksize;
353 if (offset < max && offset >= 0)
357 if (offset < max && offset >= 0)
360 offset = (i/blocksize + 1)*enc->
width/blocksize + j/blocksize;
361 if (offset < max && offset >= 0)
364 off[0]= (i/blocksize)*enc->
width/blocksize + j/blocksize - 1;
365 off[1]= off[0] - enc->
width/blocksize + 1;
371 vect.
d[k]=
mid_pred(this_motion[off[0]].d[k],
372 this_motion[off[1]].d[k],
373 this_motion[off[2]].d[k]);
384 while (oldbest != lowestdiff) {
385 oldbest = lowestdiff;
386 for (k=0; k<8; k++) {
388 vect2.
d[0] += offsets[k].
d[0];
389 vect2.
d[1] += offsets[k].
d[1];
394 offset = (i/blocksize)*enc->
width/blocksize + j/blocksize;
395 this_motion[offset] = bestpick;
410 static const int bitsUsed[4] = {2, 10, 10, 34};
431 cluster_index = y*enc->
width/16 + x/4;
471 int i, j, best_dist, divide_bit_use;
473 int bitsUsed[4] = {2, 10, 10, 0};
507 for (i=0; i<4; i++) {
514 bitsUsed[3] = 2 + divide_bit_use;
531 for (i=0; i<4; i++) {
547 tempData->
i2f4[i] = idx;
548 tempData->
f2i4[idx] = i;
560 tempData->
i2f2[i] = idx;
561 tempData->
f2i2[idx] = i;
579 bytestream_put_le32(outp, tempData->
numCB2*6 + tempData->
numCB4*4);
580 bytestream_put_byte(outp, tempData->
numCB4);
581 bytestream_put_byte(outp, tempData->
numCB2);
583 for (i=0; i<tempData->
numCB2; i++) {
585 bytestream_put_byte(outp, enc->
cb2x2[tempData->
f2i2[i]].
u);
586 bytestream_put_byte(outp, enc->
cb2x2[tempData->
f2i2[i]].
v);
589 for (i=0; i<tempData->
numCB4; i++)
591 bytestream_put_byte(outp, tempData->
i2f2[enc->
cb4x4[tempData->
f2i4[i]].
idx[j]]);
600 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)
799 int i, j, k,
ret = 0;
800 int c_size = size*size/4;
818 cbsize, 1, closest_cb, &enc->
randctx);
822 cbsize, 1, closest_cb, &enc->
randctx);
827 for (i=0; i<cbsize; i++)
828 for (k=0; k<c_size; k++) {
830 results->
y[j] = *buf++;
854 if (!results4 || !yuvClusters || !points) {
863 for (i=0; i<max*24; i++) {
865 points[i] = bias*yuvClusters[i];
870 results4, 4, (enc->
quake3_compat ? MAX_CBS_4x4-1 : MAX_CBS_4x4))) < 0)
889 for (i=0; i<codebooks->
numCB2; i++)
893 for (i=0; i<codebooks->
numCB4; i++) {
894 for (j=0; j<4; j++) {
916 memset(tempData, 0,
sizeof(*tempData));
937 if (enc->
lambda > 100000) {
942 "Warning, generated a frame too big for Quake (%d > 65535), "
943 "now switching to a bigger qscale value.\n",
1003 if ((avctx->
width & 0xf) || (avctx->
height & 0xf)) {
1008 if (avctx->
width > 65535 || avctx->
height > 65535) {
1014 av_log(avctx,
AV_LOG_ERROR,
"Warning: dimensions not power of two, this is not supported by quake\n");
1059 bytestream_put_le32(&enc->
out_buf, 8);
1062 bytestream_put_byte(&enc->
out_buf, 0x00);
1063 bytestream_put_byte(&enc->
out_buf, 0x00);
1072 bytestream_put_byte(&enc->
out_buf, 0x08);
1073 bytestream_put_byte(&enc->
out_buf, 0x00);
1074 bytestream_put_byte(&enc->
out_buf, 0x04);
1075 bytestream_put_byte(&enc->
out_buf, 0x00);
1095 size = ((enc->
width * enc->
height / 64) * 138 + 7) / 8 + 256 * (6 + 4) + 8;
1130 #define OFFSET(x) offsetof(RoqContext, x)
1131 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1133 {
"quake3_compat",
"Whether to respect known limitations in Quake 3 decoder",
OFFSET(quake3_compat),
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1,
VE },