yading@10
|
1 /*
|
yading@10
|
2 * Aura 2 decoder
|
yading@10
|
3 *
|
yading@10
|
4 * This file is part of FFmpeg.
|
yading@10
|
5 *
|
yading@10
|
6 * FFmpeg is free software; you can redistribute it and/or
|
yading@10
|
7 * modify it under the terms of the GNU Lesser General Public
|
yading@10
|
8 * License as published by the Free Software Foundation; either
|
yading@10
|
9 * version 2.1 of the License, or (at your option) any later version.
|
yading@10
|
10 *
|
yading@10
|
11 * FFmpeg is distributed in the hope that it will be useful,
|
yading@10
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@10
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@10
|
14 * Lesser General Public License for more details.
|
yading@10
|
15 *
|
yading@10
|
16 * You should have received a copy of the GNU Lesser General Public
|
yading@10
|
17 * License along with FFmpeg; if not, write to the Free Software
|
yading@10
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@10
|
19 */
|
yading@10
|
20
|
yading@10
|
21 /**
|
yading@10
|
22 * @file
|
yading@10
|
23 * Aura 2 decoder
|
yading@10
|
24 */
|
yading@10
|
25
|
yading@10
|
26 #include "avcodec.h"
|
yading@10
|
27 #include "internal.h"
|
yading@10
|
28 #include "libavutil/internal.h"
|
yading@10
|
29
|
yading@10
|
30 static av_cold int aura_decode_init(AVCodecContext *avctx)
|
yading@10
|
31 {
|
yading@10
|
32 /* width needs to be divisible by 4 for this codec to work */
|
yading@10
|
33 if (avctx->width & 0x3)
|
yading@10
|
34 return AVERROR(EINVAL);
|
yading@10
|
35 avctx->pix_fmt = AV_PIX_FMT_YUV422P;
|
yading@10
|
36
|
yading@10
|
37 return 0;
|
yading@10
|
38 }
|
yading@10
|
39
|
yading@10
|
40 static int aura_decode_frame(AVCodecContext *avctx,
|
yading@10
|
41 void *data, int *got_frame,
|
yading@10
|
42 AVPacket *pkt)
|
yading@10
|
43 {
|
yading@10
|
44 AVFrame *frame = data;
|
yading@10
|
45 uint8_t *Y, *U, *V;
|
yading@10
|
46 uint8_t val;
|
yading@10
|
47 int x, y, ret;
|
yading@10
|
48 const uint8_t *buf = pkt->data;
|
yading@10
|
49
|
yading@10
|
50 /* prediction error tables (make it clear that they are signed values) */
|
yading@10
|
51 const int8_t *delta_table = (const int8_t*)buf + 16;
|
yading@10
|
52
|
yading@10
|
53 if (pkt->size != 48 + avctx->height * avctx->width) {
|
yading@10
|
54 av_log(avctx, AV_LOG_ERROR, "got a buffer with %d bytes when %d were expected\n",
|
yading@10
|
55 pkt->size, 48 + avctx->height * avctx->width);
|
yading@10
|
56 return AVERROR_INVALIDDATA;
|
yading@10
|
57 }
|
yading@10
|
58
|
yading@10
|
59 /* pixel data starts 48 bytes in, after 3x16-byte tables */
|
yading@10
|
60 buf += 48;
|
yading@10
|
61
|
yading@10
|
62 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
|
yading@10
|
63 return ret;
|
yading@10
|
64
|
yading@10
|
65 Y = frame->data[0];
|
yading@10
|
66 U = frame->data[1];
|
yading@10
|
67 V = frame->data[2];
|
yading@10
|
68
|
yading@10
|
69 /* iterate through each line in the height */
|
yading@10
|
70 for (y = 0; y < avctx->height; y++) {
|
yading@10
|
71 /* reset predictors */
|
yading@10
|
72 val = *buf++;
|
yading@10
|
73 U[0] = val & 0xF0;
|
yading@10
|
74 Y[0] = val << 4;
|
yading@10
|
75 val = *buf++;
|
yading@10
|
76 V[0] = val & 0xF0;
|
yading@10
|
77 Y[1] = Y[0] + delta_table[val & 0xF];
|
yading@10
|
78 Y += 2; U++; V++;
|
yading@10
|
79
|
yading@10
|
80 /* iterate through the remaining pixel groups (4 pixels/group) */
|
yading@10
|
81 for (x = 1; x < (avctx->width >> 1); x++) {
|
yading@10
|
82 val = *buf++;
|
yading@10
|
83 U[0] = U[-1] + delta_table[val >> 4];
|
yading@10
|
84 Y[0] = Y[-1] + delta_table[val & 0xF];
|
yading@10
|
85 val = *buf++;
|
yading@10
|
86 V[0] = V[-1] + delta_table[val >> 4];
|
yading@10
|
87 Y[1] = Y[ 0] + delta_table[val & 0xF];
|
yading@10
|
88 Y += 2; U++; V++;
|
yading@10
|
89 }
|
yading@10
|
90 Y += frame->linesize[0] - avctx->width;
|
yading@10
|
91 U += frame->linesize[1] - (avctx->width >> 1);
|
yading@10
|
92 V += frame->linesize[2] - (avctx->width >> 1);
|
yading@10
|
93 }
|
yading@10
|
94
|
yading@10
|
95 *got_frame = 1;
|
yading@10
|
96
|
yading@10
|
97 return pkt->size;
|
yading@10
|
98 }
|
yading@10
|
99
|
yading@10
|
100 AVCodec ff_aura2_decoder = {
|
yading@10
|
101 .name = "aura2",
|
yading@10
|
102 .type = AVMEDIA_TYPE_VIDEO,
|
yading@10
|
103 .id = AV_CODEC_ID_AURA2,
|
yading@10
|
104 .init = aura_decode_init,
|
yading@10
|
105 .decode = aura_decode_frame,
|
yading@10
|
106 .capabilities = CODEC_CAP_DR1,
|
yading@10
|
107 .long_name = NULL_IF_CONFIG_SMALL("Auravision Aura 2"),
|
yading@10
|
108 };
|