annotate indeo2.c @ 9805:7d851240d479 libavcodec

ptx image decoder uses get_buffer, set CODEC_CAP_DR1
author bcoudurier
date Fri, 05 Jun 2009 08:35:36 +0000
parents d719a2711c64
children 136334ad62b3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
1 /*
3724
42b08e756c3b Fix Indel --> Intel typo.
diego
parents: 3036
diff changeset
2 * Intel Indeo 2 codec
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
3 * Copyright (c) 2005 Konstantin Shishkov
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3724
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3724
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3724
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3724
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3724
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
15 * Lesser General Public License for more details.
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
16 *
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3724
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2967
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
20 */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2834
diff changeset
21
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
22 /**
8718
e9d9d946f213 Use full internal pathname in doxygen @file directives.
diego
parents: 7040
diff changeset
23 * @file libavcodec/indeo2.c
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
24 * Intel Indeo 2 decoder.
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
25 */
2664
f20c1cdfce76 support the LE reader, so it can be tested a little
michael
parents: 2621
diff changeset
26 #define ALT_BITSTREAM_READER_LE
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
27 #include "avcodec.h"
9428
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents: 9355
diff changeset
28 #include "get_bits.h"
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
29 #include "indeo2data.h"
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
30
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
31 typedef struct Ir2Context{
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
32 AVCodecContext *avctx;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
33 AVFrame picture;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
34 GetBitContext gb;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
35 int decode_delta;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
36 } Ir2Context;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
37
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
38 #define CODE_VLC_BITS 14
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
39 static VLC ir2_vlc;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
40
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
41 /* Indeo 2 codes are in range 0x01..0x7F and 0x81..0x90 */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
42 static inline int ir2_get_code(GetBitContext *gb)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
43 {
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
44 return get_vlc2(gb, ir2_vlc.table, CODE_VLC_BITS, 1) + 1;
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
45 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
46
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
47 static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride,
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
48 const uint8_t *table)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
49 {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
50 int i;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
51 int j;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
52 int out = 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
53 int c;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
54 int t;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2834
diff changeset
55
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
56 if(width&1)
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
57 return -1;
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
58
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
59 /* first line contain absolute values, other lines contain deltas */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
60 while (out < width){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
61 c = ir2_get_code(&ctx->gb);
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
62 if(c >= 0x80) { /* we have a run */
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
63 c -= 0x7F;
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
64 if(out + c*2 > width)
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
65 return -1;
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
66 for (i = 0; i < c * 2; i++)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
67 dst[out++] = 0x80;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
68 } else { /* copy two values from table */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
69 dst[out++] = table[c * 2];
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
70 dst[out++] = table[(c * 2) + 1];
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
71 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
72 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
73 dst += stride;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2834
diff changeset
74
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
75 for (j = 1; j < height; j++){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
76 out = 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
77 while (out < width){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
78 c = ir2_get_code(&ctx->gb);
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
79 if(c >= 0x80) { /* we have a skip */
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
80 c -= 0x7F;
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
81 if(out + c*2 > width)
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
82 return -1;
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
83 for (i = 0; i < c * 2; i++) {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
84 dst[out] = dst[out - stride];
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
85 out++;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
86 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
87 } else { /* add two deltas from table */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
88 t = dst[out - stride] + (table[c * 2] - 128);
4594
a96d905dcbaa Add av_ prefix to clip functions
reimar
parents: 3947
diff changeset
89 t= av_clip_uint8(t);
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
90 dst[out] = t;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
91 out++;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
92 t = dst[out - stride] + (table[(c * 2) + 1] - 128);
4594
a96d905dcbaa Add av_ prefix to clip functions
reimar
parents: 3947
diff changeset
93 t= av_clip_uint8(t);
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
94 dst[out] = t;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
95 out++;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
96 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
97 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
98 dst += stride;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
99 }
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
100 return 0;
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
101 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
102
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
103 static int ir2_decode_plane_inter(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride,
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
104 const uint8_t *table)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
105 {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
106 int j;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
107 int out = 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
108 int c;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
109 int t;
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
110
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
111 if(width&1)
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
112 return -1;
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
113
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
114 for (j = 0; j < height; j++){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
115 out = 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
116 while (out < width){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
117 c = ir2_get_code(&ctx->gb);
2621
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
118 if(c >= 0x80) { /* we have a skip */
0a55e35d3e5e simplify
michael
parents: 2619
diff changeset
119 c -= 0x7F;
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
120 out += c * 2;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
121 } else { /* add two deltas from table */
2783
7a411f408d74 Here is the patch suggested by: unkaggregate, users sf net
michael
parents: 2664
diff changeset
122 t = dst[out] + (((table[c * 2] - 128)*3) >> 2);
4594
a96d905dcbaa Add av_ prefix to clip functions
reimar
parents: 3947
diff changeset
123 t= av_clip_uint8(t);
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
124 dst[out] = t;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
125 out++;
2783
7a411f408d74 Here is the patch suggested by: unkaggregate, users sf net
michael
parents: 2664
diff changeset
126 t = dst[out] + (((table[(c * 2) + 1] - 128)*3) >> 2);
4594
a96d905dcbaa Add av_ prefix to clip functions
reimar
parents: 3947
diff changeset
127 t= av_clip_uint8(t);
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
128 dst[out] = t;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
129 out++;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
130 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
131 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
132 dst += stride;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
133 }
2619
c39756a516a5 buffer overflows
michael
parents: 2618
diff changeset
134 return 0;
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
135 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
136
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2834
diff changeset
137 static int ir2_decode_frame(AVCodecContext *avctx,
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
138 void *data, int *data_size,
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
139 AVPacket *avpkt)
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
140 {
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
141 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
142 int buf_size = avpkt->size;
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
143 Ir2Context * const s = avctx->priv_data;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
144 AVFrame *picture = data;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
145 AVFrame * const p= (AVFrame*)&s->picture;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
146 int start;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
147
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
148 if(p->data[0])
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
149 avctx->release_buffer(avctx, p);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
150
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
151 p->reference = 1;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
152 p->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
153 if (avctx->reget_buffer(avctx, p)) {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
154 av_log(s->avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
155 return -1;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
156 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
157
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
158 s->decode_delta = buf[18];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2834
diff changeset
159
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
160 /* decide whether frame uses deltas or not */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2834
diff changeset
161 #ifndef ALT_BITSTREAM_READER_LE
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
162 for (i = 0; i < buf_size; i++)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
163 buf[i] = ff_reverse[buf[i]];
2664
f20c1cdfce76 support the LE reader, so it can be tested a little
michael
parents: 2621
diff changeset
164 #endif
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
165 start = 48; /* hardcoded for now */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
166
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
167 init_get_bits(&s->gb, buf + start, buf_size - start);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
168
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
169 if (s->decode_delta) { /* intraframe */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
170 ir2_decode_plane(s, avctx->width, avctx->height,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
171 s->picture.data[0], s->picture.linesize[0], ir2_luma_table);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
172 /* swapped U and V */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
173 ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
174 s->picture.data[2], s->picture.linesize[2], ir2_luma_table);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
175 ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
176 s->picture.data[1], s->picture.linesize[1], ir2_luma_table);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
177 } else { /* interframe */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
178 ir2_decode_plane_inter(s, avctx->width, avctx->height,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
179 s->picture.data[0], s->picture.linesize[0], ir2_luma_table);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
180 /* swapped U and V */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
181 ir2_decode_plane_inter(s, avctx->width >> 2, avctx->height >> 2,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
182 s->picture.data[2], s->picture.linesize[2], ir2_luma_table);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
183 ir2_decode_plane_inter(s, avctx->width >> 2, avctx->height >> 2,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
184 s->picture.data[1], s->picture.linesize[1], ir2_luma_table);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
185 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
186
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
187 *picture= *(AVFrame*)&s->picture;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
188 *data_size = sizeof(AVPicture);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
189
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
190 return buf_size;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
191 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
192
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6218
diff changeset
193 static av_cold int ir2_decode_init(AVCodecContext *avctx){
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
194 Ir2Context * const ic = avctx->priv_data;
9463
d719a2711c64 Use new static VLC scheme in Indeo2, Musepack and WNV1 decoders
kostya
parents: 9428
diff changeset
195 static VLC_TYPE vlc_tables[1 << CODE_VLC_BITS][2];
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
196
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
197 ic->avctx = avctx;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
198
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
199 avctx->pix_fmt= PIX_FMT_YUV410P;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2834
diff changeset
200
9463
d719a2711c64 Use new static VLC scheme in Indeo2, Musepack and WNV1 decoders
kostya
parents: 9428
diff changeset
201 ir2_vlc.table = vlc_tables;
d719a2711c64 Use new static VLC scheme in Indeo2, Musepack and WNV1 decoders
kostya
parents: 9428
diff changeset
202 ir2_vlc.table_allocated = 1 << CODE_VLC_BITS;
5096
1210710a6c6a fix error: indeo2.c:202:1: directives may not be used inside a macro argument,
gpoirier
parents: 4594
diff changeset
203 #ifdef ALT_BITSTREAM_READER_LE
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
204 init_vlc(&ir2_vlc, CODE_VLC_BITS, IR2_CODES,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
205 &ir2_codes[0][1], 4, 2,
9463
d719a2711c64 Use new static VLC scheme in Indeo2, Musepack and WNV1 decoders
kostya
parents: 9428
diff changeset
206 &ir2_codes[0][0], 4, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE);
2664
f20c1cdfce76 support the LE reader, so it can be tested a little
michael
parents: 2621
diff changeset
207 #else
5096
1210710a6c6a fix error: indeo2.c:202:1: directives may not be used inside a macro argument,
gpoirier
parents: 4594
diff changeset
208 init_vlc(&ir2_vlc, CODE_VLC_BITS, IR2_CODES,
1210710a6c6a fix error: indeo2.c:202:1: directives may not be used inside a macro argument,
gpoirier
parents: 4594
diff changeset
209 &ir2_codes[0][1], 4, 2,
9463
d719a2711c64 Use new static VLC scheme in Indeo2, Musepack and WNV1 decoders
kostya
parents: 9428
diff changeset
210 &ir2_codes[0][0], 4, 2, INIT_VLC_USE_NEW_STATIC);
2664
f20c1cdfce76 support the LE reader, so it can be tested a little
michael
parents: 2621
diff changeset
211 #endif
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2834
diff changeset
212
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
213 return 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
214 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
215
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
216 AVCodec indeo2_decoder = {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
217 "indeo2",
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
218 CODEC_TYPE_VIDEO,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
219 CODEC_ID_INDEO2,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
220 sizeof(Ir2Context),
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
221 ir2_decode_init,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
222 NULL,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
223 NULL,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
224 ir2_decode_frame,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
225 CODEC_CAP_DR1,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6710
diff changeset
226 .long_name = NULL_IF_CONFIG_SMALL("Intel Indeo 2"),
2618
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
227 };