Lines Matching defs:enc
229 static int eval_motion_dist(RoqEncContext *enc, int x, int y, motion_vect vect,
232 RoqContext *const roq = &enc->common;
248 return block_sse(enc->frame_to_enc->data, roq->last_frame->data, x, y,
250 enc->frame_to_enc->linesize, roq->last_frame->linesize,
274 static int create_cel_evals(RoqEncContext *enc)
276 RoqContext *const roq = &enc->common;
278 enc->cel_evals = av_malloc_array(roq->width * roq->height / 64, sizeof(CelEvaluation));
279 if (!enc->cel_evals)
286 enc->cel_evals[n ].sourceX = x + (i&1)*8;
287 enc->cel_evals[n++].sourceY = y + (i&2)*4;
331 diff = eval_motion_dist(enc, j, i, MOTION, blocksize); \
339 static void motion_search(RoqEncContext *enc, int blocksize)
352 RoqContext *const roq = &enc->common;
364 last_motion = enc->last_motion4;
365 this_motion = enc->this_motion4;
367 last_motion = enc->last_motion8;
368 this_motion = enc->this_motion8;
373 lowestdiff = eval_motion_dist(enc, j, i, (motion_vect) {{0,0}},
379 EVAL_MOTION(enc->this_motion8[(i/8) * (roq->width/8) + j/8]);
432 int y, RoqEncContext *enc)
434 RoqContext *const roq = &enc->common;
435 RoqTempData *const tempData = &enc->tmp_data;
443 if (enc->framesSinceKeyframe >= 1) {
444 subcel->motion = enc->this_motion4[y * roq->width / 16 + x / 4];
447 eval_motion_dist(enc, x, y,
448 enc->this_motion4[y * roq->width / 16 + x / 4], 4);
452 if (enc->framesSinceKeyframe >= 2)
453 subcel->eval_dist[RoQ_ID_MOT] = block_sse(enc->frame_to_enc->data,
456 enc->frame_to_enc->linesize,
464 get_frame_mb(enc->frame_to_enc, x, y, mb4, 4);
474 subcel->subCels[i] = enc->closest_cb[cluster_index*4+i];
476 get_frame_mb(enc->frame_to_enc, x+2*(i&1),
485 if (ROQ_LAMBDA_SCALE*subcel->eval_dist[i] + enc->lambda*bitsUsed[i] <
490 enc->lambda*bitsUsed[i];
497 static void gather_data_for_cel(CelEvaluation *cel, RoqEncContext *enc)
499 RoqContext *const roq = &enc->common;
500 RoqTempData *const tempData = &enc->tmp_data;
507 if (enc->framesSinceKeyframe >= 1) {
508 cel->motion = enc->this_motion8[index];
511 eval_motion_dist(enc, cel->sourceX, cel->sourceY,
512 enc->this_motion8[index], 8);
516 if (enc->framesSinceKeyframe >= 2)
517 cel->eval_dist[RoQ_ID_MOT] = block_sse(enc->frame_to_enc->data,
521 enc->frame_to_enc->linesize,
526 get_frame_mb(enc->frame_to_enc, cel->sourceX, cel->sourceY, mb8, 8);
532 gather_data_for_subcel(cel->subCels + 0, cel->sourceX+0, cel->sourceY+0, enc);
533 gather_data_for_subcel(cel->subCels + 1, cel->sourceX+4, cel->sourceY+0, enc);
534 gather_data_for_subcel(cel->subCels + 2, cel->sourceX+0, cel->sourceY+4, enc);
535 gather_data_for_subcel(cel->subCels + 3, cel->sourceX+4, cel->sourceY+4, enc);
549 if (ROQ_LAMBDA_SCALE*cel->eval_dist[i] + enc->lambda*bitsUsed[i] <
553 enc->lambda*bitsUsed[i];
572 static void remap_codebooks(RoqEncContext *enc)
574 RoqContext *const roq = &enc->common;
575 RoqTempData *const tempData = &enc->tmp_data;
579 for (i=0; i<(enc->quake3_compat ? MAX_CBS_4x4-1 : MAX_CBS_4x4); i++) {
606 static void write_codebooks(RoqEncContext *enc)
608 RoqContext *const roq = &enc->common;
609 RoqTempData *const tempData = &enc->tmp_data;
611 uint8_t **outp= &enc->out_buf;
662 static void reconstruct_and_encode_image(RoqEncContext *enc,
665 RoqContext *const roq = &enc->common;
666 RoqTempData *const tempData = &enc->tmp_data;
679 spool.pout = &enc->out_buf;
685 bytestream_put_le16(&enc->out_buf, RoQ_QUAD_VQ);
686 bytestream_put_le32(&enc->out_buf, tempData->mainChunkSize/8);
687 bytestream_put_byte(&enc->out_buf, 0x0);
688 bytestream_put_byte(&enc->out_buf, 0x0);
691 eval = enc->cel_evals + i;
817 static int generate_codebook(RoqEncContext *enc,
824 int *codebook = enc->tmp_codebook_buf;
825 int *closest_cb = enc->closest_cb;
827 ret = avpriv_elbg_do(&enc->elbg, points, 6 * c_size, inputCount, codebook,
828 cbsize, 1, closest_cb, &enc->randctx, 0);
845 static int generate_new_codebooks(RoqEncContext *enc)
848 RoqCodebooks *codebooks = &enc->tmp_data.codebooks;
849 RoqContext *const roq = &enc->common;
852 int *points = enc->points;
855 create_clusters(enc->frame_to_enc, roq->width, roq->height, points);
857 codebooks->numCB4 = (enc->quake3_compat ? MAX_CBS_4x4-1 : MAX_CBS_4x4);
860 if ((ret = generate_codebook(enc, points, max, enc->results4,
865 if ((ret = generate_codebook(enc, points, max * 4,
878 unpack_roq_cell(&enc->results4[4*i + j], mb2);
891 static int roq_encode_video(RoqEncContext *enc)
893 RoqTempData *const tempData = &enc->tmp_data;
894 RoqContext *const roq = &enc->common;
899 ret = generate_new_codebooks(enc);
903 if (enc->framesSinceKeyframe >= 1) {
904 motion_search(enc, 8);
905 motion_search(enc, 4);
910 gather_data_for_cel(enc->cel_evals + i, enc);
913 if (tempData->mainChunkSize/8 > 65535 && enc->quake3_compat) {
914 if (enc->lambda > 100000) {
922 enc->lambda *= 1.5;
933 remap_codebooks(enc);
935 write_codebooks(enc);
937 reconstruct_and_encode_image(enc, roq->width, roq->height,
942 FFSWAP(motion_vect *, enc->last_motion4, enc->this_motion4);
943 FFSWAP(motion_vect *, enc->last_motion8, enc->this_motion8);
945 enc->framesSinceKeyframe++;
952 RoqEncContext *const enc = avctx->priv_data;
954 av_frame_free(&enc->common.current_frame);
955 av_frame_free(&enc->common.last_frame);
957 av_freep(&enc->cel_evals);
958 av_freep(&enc->closest_cb);
959 av_freep(&enc->this_motion4);
960 av_freep(&enc->last_motion4);
961 av_freep(&enc->this_motion8);
962 av_freep(&enc->last_motion8);
964 avpriv_elbg_free(&enc->elbg);
971 RoqEncContext *const enc = avctx->priv_data;
972 RoqContext *const roq = &enc->common;
974 av_lfg_init(&enc->randctx, 1);
978 enc->framesSinceKeyframe = 0;
985 av_log(avctx, AV_LOG_ERROR, "Dimensions are max %d\n", enc->quake3_compat ? 32768 : 65535);
995 enc->framesSinceKeyframe = 0;
996 enc->first_frame = 1;
1003 enc->this_motion4 =
1004 av_calloc(roq->width * roq->height / 16, sizeof(*enc->this_motion4));
1006 enc->last_motion4 =
1009 enc->this_motion8 =
1010 av_calloc(roq->width * roq->height / 64, sizeof(*enc->this_motion8));
1012 enc->last_motion8 =
1017 enc->closest_cb =
1020 if (!enc->this_motion4 || !enc->last_motion4 ||
1021 !enc->this_motion8 || !enc->last_motion8 || !enc->closest_cb)
1024 enc->points = enc->closest_cb + roq->width * roq->height * 3 / 2;
1026 return create_cel_evals(enc);
1029 static void roq_write_video_info_chunk(RoqEncContext *enc)
1032 bytestream_put_le16(&enc->out_buf, RoQ_INFO);
1035 bytestream_put_le32(&enc->out_buf, 8);
1038 bytestream_put_byte(&enc->out_buf, 0x00);
1039 bytestream_put_byte(&enc->out_buf, 0x00);
1042 bytestream_put_le16(&enc->out_buf, enc->common.width);
1045 bytestream_put_le16(&enc->out_buf, enc->common.height);
1048 bytestream_put_byte(&enc->out_buf, 0x08);
1049 bytestream_put_byte(&enc->out_buf, 0x00);
1050 bytestream_put_byte(&enc->out_buf, 0x04);
1051 bytestream_put_byte(&enc->out_buf, 0x00);
1057 RoqEncContext *const enc = avctx->priv_data;
1058 RoqContext *const roq = &enc->common;
1063 enc->frame_to_enc = frame;
1066 enc->lambda = frame->quality - 1;
1068 enc->lambda = 2*ROQ_LAMBDA_SCALE;
1075 enc->out_buf = pkt->data;
1078 if (enc->framesSinceKeyframe == avctx->gop_size)
1079 enc->framesSinceKeyframe = 0;
1081 if (enc->first_frame) {
1089 roq_write_video_info_chunk(enc);
1091 enc->first_frame = 0;
1095 ret = roq_encode_video(enc);
1099 pkt->size = enc->out_buf - pkt->data;
1100 if (enc->framesSinceKeyframe == 1)