277
278
/* Average 4/8 pixels at once without rounding using SWAR */
278
279
#define AVG_32(dst, src, ref) \
279
AV_WN32A(dst, ((AV_RN32A(src) + AV_RN32A(ref)) >> 1) & 0x7F7F7F7FUL)
280
AV_WN32A(dst, ((AV_RN32(src) + AV_RN32(ref)) >> 1) & 0x7F7F7F7FUL)
281
282
#define AVG_64(dst, src, ref) \
282
AV_WN64A(dst, ((AV_RN64A(src) + AV_RN64A(ref)) >> 1) & 0x7F7F7F7F7F7F7F7FULL)
283
AV_WN64A(dst, ((AV_RN64(src) + AV_RN64(ref)) >> 1) & 0x7F7F7F7F7F7F7F7FULL)
338
339
copy_block4(dst, ref, row_offset, row_offset, 4 << v_zoom)
340
341
#define RLE_BLOCK_COPY_8 \
341
pix64 = AV_RN64A(ref);\
342
pix64 = AV_RN64(ref);\
342
343
if (is_first_row) {/* special prediction case: top line of a cell */\
343
344
pix64 = replicate64(pix64);\
344
345
fill_64(dst + row_offset, pix64, 7, row_offset);\
350
351
copy_block4(dst, ref, row_offset, row_offset, num_lines << v_zoom)
352
353
#define RLE_LINES_COPY_M10 \
353
pix64 = AV_RN64A(ref);\
354
pix64 = AV_RN64(ref);\
354
355
if (is_top_of_cell) {\
355
356
pix64 = replicate64(pix64);\
356
357
fill_64(dst + row_offset, pix64, (num_lines << 1) - 1, row_offset);\
361
362
#define APPLY_DELTA_4 \
362
363
AV_WN16A(dst + line_offset ,\
363
(AV_RN16A(ref ) + delta_tab->deltas[dyad1]) & 0x7F7F);\
364
(AV_RN16(ref ) + delta_tab->deltas[dyad1]) & 0x7F7F);\
364
365
AV_WN16A(dst + line_offset + 2,\
365
(AV_RN16A(ref + 2) + delta_tab->deltas[dyad2]) & 0x7F7F);\
366
(AV_RN16(ref + 2) + delta_tab->deltas[dyad2]) & 0x7F7F);\
366
367
if (mode >= 3) {\
367
368
if (is_top_of_cell && !cell->ypos) {\
368
AV_COPY32(dst, dst + row_offset);\
369
AV_COPY32U(dst, dst + row_offset);\
370
371
AVG_32(dst, ref, dst + row_offset);\
375
376
/* apply two 32-bit VQ deltas to next even line */\
376
377
if (is_top_of_cell) { \
377
378
AV_WN32A(dst + row_offset , \
378
(replicate32(AV_RN32A(ref )) + delta_tab->deltas_m10[dyad1]) & 0x7F7F7F7F);\
379
(replicate32(AV_RN32(ref )) + delta_tab->deltas_m10[dyad1]) & 0x7F7F7F7F);\
379
380
AV_WN32A(dst + row_offset + 4, \
380
(replicate32(AV_RN32A(ref + 4)) + delta_tab->deltas_m10[dyad2]) & 0x7F7F7F7F);\
381
(replicate32(AV_RN32(ref + 4)) + delta_tab->deltas_m10[dyad2]) & 0x7F7F7F7F);\
382
383
AV_WN32A(dst + row_offset , \
383
(AV_RN32A(ref ) + delta_tab->deltas_m10[dyad1]) & 0x7F7F7F7F);\
384
(AV_RN32(ref ) + delta_tab->deltas_m10[dyad1]) & 0x7F7F7F7F);\
384
385
AV_WN32A(dst + row_offset + 4, \
385
(AV_RN32A(ref + 4) + delta_tab->deltas_m10[dyad2]) & 0x7F7F7F7F);\
386
(AV_RN32(ref + 4) + delta_tab->deltas_m10[dyad2]) & 0x7F7F7F7F);\
387
388
/* odd lines are not coded but rather interpolated/replicated */\
388
389
/* first line of the cell on the top of image? - replicate */\
389
390
/* otherwise - interpolate */\
390
391
if (is_top_of_cell && !cell->ypos) {\
391
AV_COPY64(dst, dst + row_offset);\
392
AV_COPY64U(dst, dst + row_offset);\
393
394
AVG_64(dst, ref, dst + row_offset);
396
397
#define APPLY_DELTA_1011_INTER \
397
398
if (mode == 10) { \
399
(AV_RN32A(dst ) + delta_tab->deltas_m10[dyad1]) & 0x7F7F7F7F);\
400
(AV_RN32(dst ) + delta_tab->deltas_m10[dyad1]) & 0x7F7F7F7F);\
400
401
AV_WN32A(dst + 4 , \
401
(AV_RN32A(dst + 4 ) + delta_tab->deltas_m10[dyad2]) & 0x7F7F7F7F);\
402
(AV_RN32(dst + 4 ) + delta_tab->deltas_m10[dyad2]) & 0x7F7F7F7F);\
402
403
AV_WN32A(dst + row_offset , \
403
(AV_RN32A(dst + row_offset ) + delta_tab->deltas_m10[dyad1]) & 0x7F7F7F7F);\
404
(AV_RN32(dst + row_offset ) + delta_tab->deltas_m10[dyad1]) & 0x7F7F7F7F);\
404
405
AV_WN32A(dst + row_offset + 4, \
405
(AV_RN32A(dst + row_offset + 4) + delta_tab->deltas_m10[dyad2]) & 0x7F7F7F7F);\
406
(AV_RN32(dst + row_offset + 4) + delta_tab->deltas_m10[dyad2]) & 0x7F7F7F7F);\
408
(AV_RN16A(dst ) + delta_tab->deltas[dyad1]) & 0x7F7F);\
409
(AV_RN16(dst ) + delta_tab->deltas[dyad1]) & 0x7F7F);\
409
410
AV_WN16A(dst + 2 , \
410
(AV_RN16A(dst + 2 ) + delta_tab->deltas[dyad2]) & 0x7F7F);\
411
(AV_RN16(dst + 2 ) + delta_tab->deltas[dyad2]) & 0x7F7F);\
411
412
AV_WN16A(dst + row_offset , \
412
(AV_RN16A(dst + row_offset ) + delta_tab->deltas[dyad1]) & 0x7F7F);\
413
(AV_RN16(dst + row_offset ) + delta_tab->deltas[dyad1]) & 0x7F7F);\
413
414
AV_WN16A(dst + row_offset + 2, \
414
(AV_RN16A(dst + row_offset + 2) + delta_tab->deltas[dyad2]) & 0x7F7F);\
415
(AV_RN16(dst + row_offset + 2) + delta_tab->deltas[dyad2]) & 0x7F7F);\
805
806
/* get motion vector index and setup the pointer to the mv set */
806
807
if (!ctx->need_resync)
807
808
ctx->next_cell_data = &ctx->gb.buffer[(get_bits_count(&ctx->gb) + 7) >> 3];
808
mv_idx = *(ctx->next_cell_data++) << 1;
809
mv_idx = *(ctx->next_cell_data++);
809
810
if (mv_idx >= ctx->num_vectors) {
810
811
av_log(avctx, AV_LOG_ERROR, "motion vector index out of range\n");
811
812
return AVERROR_INVALIDDATA;
813
curr_cell.mv_ptr = &ctx->mc_vectors[mv_idx];
814
curr_cell.mv_ptr = &ctx->mc_vectors[mv_idx << 1];
814
815
curr_cell.tree = 1; /* enter the VQ tree */
815
816
UPDATE_BITPOS(8);
816
817
} else { /* VQ tree DATA code */
1006
1007
* @param[in] buf_sel indicates which frame buffer the input data stored in
1007
1008
* @param[out] dst pointer to the buffer receiving converted pixels
1008
1009
* @param[in] dst_pitch pitch for moving to the next y line
1010
* @param[in] dst_height output plane height
1010
static void output_plane(const Plane *plane, int buf_sel, uint8_t *dst, int dst_pitch)
1012
static void output_plane(const Plane *plane, int buf_sel, uint8_t *dst,
1013
int dst_pitch, int dst_height)
1013
1016
const uint8_t *src = plane->pixels[buf_sel];
1014
1017
uint32_t pitch = plane->pitch;
1016
for (y = 0; y < plane->height; y++) {
1019
dst_height = FFMIN(dst_height, plane->height);
1020
for (y = 0; y < dst_height; y++) {
1017
1021
/* convert four pixels at once using SWAR */
1018
1022
for (x = 0; x < plane->width >> 2; x++) {
1019
1023
AV_WN32A(dst, (AV_RN32A(src) & 0x7F7F7F7F) << 1);
1037
1041
ctx->avctx = avctx;
1038
1042
ctx->width = avctx->width;
1039
1043
ctx->height = avctx->height;
1040
avctx->pix_fmt = PIX_FMT_YUV410P;
1044
avctx->pix_fmt = AV_PIX_FMT_YUV410P;
1042
1046
build_requant_tab();
1044
dsputil_init(&ctx->dsp, avctx);
1048
ff_dsputil_init(&ctx->dsp, avctx);
1046
1050
allocate_frame_buffers(ctx, avctx);
1052
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
1056
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
1053
1057
AVPacket *avpkt)
1055
1059
Indeo3DecodeContext *ctx = avctx->priv_data;
1095
1099
avctx->release_buffer(avctx, &ctx->frame);
1097
1101
ctx->frame.reference = 0;
1098
if ((res = avctx->get_buffer(avctx, &ctx->frame)) < 0) {
1102
if ((res = ff_get_buffer(avctx, &ctx->frame)) < 0) {
1099
1103
av_log(ctx->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1103
output_plane(&ctx->planes[0], ctx->buf_sel, ctx->frame.data[0], ctx->frame.linesize[0]);
1104
output_plane(&ctx->planes[1], ctx->buf_sel, ctx->frame.data[1], ctx->frame.linesize[1]);
1105
output_plane(&ctx->planes[2], ctx->buf_sel, ctx->frame.data[2], ctx->frame.linesize[2]);
1107
output_plane(&ctx->planes[0], ctx->buf_sel,
1108
ctx->frame.data[0], ctx->frame.linesize[0],
1110
output_plane(&ctx->planes[1], ctx->buf_sel,
1111
ctx->frame.data[1], ctx->frame.linesize[1],
1112
(avctx->height + 3) >> 2);
1113
output_plane(&ctx->planes[2], ctx->buf_sel,
1114
ctx->frame.data[2], ctx->frame.linesize[2],
1115
(avctx->height + 3) >> 2);
1107
*data_size = sizeof(AVFrame);
1108
1118
*(AVFrame*)data = ctx->frame;
1110
1120
return buf_size;
1126
1136
AVCodec ff_indeo3_decoder = {
1127
1137
.name = "indeo3",
1128
1138
.type = AVMEDIA_TYPE_VIDEO,
1129
.id = CODEC_ID_INDEO3,
1139
.id = AV_CODEC_ID_INDEO3,
1130
1140
.priv_data_size = sizeof(Indeo3DecodeContext),
1131
1141
.init = decode_init,
1132
1142
.close = decode_close,
1133
1143
.decode = decode_frame,
1144
.capabilities = CODEC_CAP_DR1,
1134
1145
.long_name = NULL_IF_CONFIG_SMALL("Intel Indeo 3"),