1 /*
2 * Intel Indeo 2 codec
3 * Copyright (c) 2005 Konstantin Shishkov
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * Intel Indeo 2 decoder.
25 */
26
28
29 #define BITSTREAM_READER_LE
35
42
43 #define CODE_VLC_BITS 14
45
46 /* Indeo 2 codes are in range 0x01..0x7F and 0x81..0x90 */
48 {
50 }
51
54 {
55 int i;
56 int j;
58
59 if (width & 1)
61
62 /* first line contain absolute values, other lines contain deltas */
63 while (out < width) {
65 if (c >= 0x80) { /* we have a run */
66 c -= 0x7F;
67 if (out + c*2 > width)
69 for (i = 0; i < c * 2; i++)
70 dst[out++] = 0x80;
71 } else { /* copy two values from table */
72 if (c <= 0)
74 dst[out++] = table[c * 2];
75 dst[out++] = table[(c * 2) + 1];
76 }
77 }
78 dst += pitch;
79
80 for (j = 1; j <
height; j++) {
81 out = 0;
84 while (out < width) {
86 if (c >= 0x80) { /* we have a skip */
87 c -= 0x7F;
88 if (out + c*2 > width)
90 for (i = 0; i < c * 2; i++) {
91 dst[
out] = dst[out - pitch];
92 out++;
93 }
94 } else { /* add two deltas from table */
95 int t;
96 if (c <= 0)
98 t = dst[out - pitch] + (table[c * 2] - 128);
99 t = av_clip_uint8(t);
101 out++;
102 t = dst[out - pitch] + (table[(c * 2) + 1] - 128);
103 t = av_clip_uint8(t);
105 out++;
106 }
107 }
108 dst += pitch;
109 }
110 return 0;
111 }
112
115 {
116 int j;
119 int t;
120
121 if (width & 1)
123
124 for (j = 0; j <
height; j++) {
125 out = 0;
128 while (out < width) {
130 if (c >= 0x80) { /* we have a skip */
131 c -= 0x7F;
132 out += c * 2;
133 } else { /* add two deltas from table */
134 if (c <= 0)
136 t = dst[
out] + (((table[c * 2] - 128)*3) >> 2);
137 t = av_clip_uint8(t);
139 out++;
140 t = dst[
out] + (((table[(c * 2) + 1] - 128)*3) >> 2);
141 t = av_clip_uint8(t);
143 out++;
144 }
145 }
146 dst += pitch;
147 }
148 return 0;
149 }
150
152 void *
data,
int *got_frame,
154 {
157 int buf_size = avpkt->
size;
161 int ltab, ctab;
162
164 return ret;
165
166 start = 48; /* hardcoded for now */
167
168 if (start >= buf_size) {
171 }
172
174
175 /* decide whether frame uses deltas or not */
176 #ifndef BITSTREAM_READER_LE
177 for (i = 0; i < buf_size; i++)
179 #endif
180
182 return ret;
183
184 ltab = buf[0x22] & 3;
185 ctab = buf[0x22] >> 2;
186
187 if (ctab > 3) {
190 }
191
196 return ret;
197
198 /* swapped U and V */
202 return ret;
206 return ret;
207 } else { /* interframe */
211 return ret;
212 /* swapped U and V */
216 return ret;
220 return ret;
221 }
222
224 return ret;
225
226 *got_frame = 1;
227
228 return buf_size;
229 }
230
232 {
235
237
239
243
246 #ifdef BITSTREAM_READER_LE
250 #else
254 #endif
255
256 return 0;
257 }
258
260 {
262
264
265 return 0;
266 }
267
278 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int ir2_get_code(GetBitContext *gb)
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
static av_cold int init(AVCodecContext *avctx)
const uint8_t ff_reverse[256]
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
Identical in function to av_frame_make_writable(), except it uses ff_get_buffer() to allocate the buf...
Macro definitions for various function/variable attributes.
static int ir2_decode_plane_inter(Ir2Context *ctx, int width, int height, uint8_t *dst, int pitch, const uint8_t *table)
AVCodec ff_indeo2_decoder
static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst, int pitch, const uint8_t *table)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
bitstream reader API header.
static av_cold int ir2_decode_init(AVCodecContext *avctx)
static int get_bits_left(GetBitContext *gb)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static const struct endianess table[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const char * name
Name of the codec implementation.
static av_cold int ir2_decode_end(AVCodecContext *avctx)
int width
picture width / height.
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
Libavcodec external API header.
static int ir2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
main external API structure.
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
static VLC_TYPE vlc_tables[VLC_TABLES_SIZE][2]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
common internal api header.
#define INIT_VLC_USE_NEW_STATIC
VLC_TYPE(* table)[2]
code, bits
static const uint8_t ir2_delta_table[4][256]
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static const uint16_t ir2_codes[IR2_CODES][2]