annotate indeo2.c @ 2618:fc91ca5b9066 libavcodec

Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
author michael
date Wed, 20 Apr 2005 09:42:47 +0000
parents
children c39756a516a5
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 /*
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
2 * Indel Indeo 2 codec
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 *
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
6 * 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
7 * License as published by the Free Software Foundation; either
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
9 *
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
13 * Lesser General Public License for more details.
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
14 *
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
18 *
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
19 */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
20
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
21 /**
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
22 * @file indeo2.c
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
23 * Intel Indeo 2 decoder.
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
24 */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
25
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
26 #include "avcodec.h"
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
27 #include "bitstream.h"
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
28 #include "indeo2data.h"
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
29
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
30 typedef struct Ir2Context{
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
31 AVCodecContext *avctx;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
32 AVFrame picture;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
33 GetBitContext gb;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
34 int decode_delta;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
35 } Ir2Context;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
36
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
37 #define CODE_VLC_BITS 14
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
38 static VLC ir2_vlc;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
39
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
40 /* 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
41 static inline int ir2_get_code(GetBitContext *gb)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
42 {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
43 int code;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
44
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
45 code = get_vlc2(gb, ir2_vlc.table, CODE_VLC_BITS, 1) + 1;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
46 if (code >= 0x80)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
47 return (code + 1);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
48 return code;
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 #define CLAMP_TO_BYTE(value) \
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
51 if (value > 255) \
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
52 value = 255; \
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
53 else if (value < 0) \
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
54 value = 0; \
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
55
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
56 static void ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
57 const uint8_t *table)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
58 {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
59 int i;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
60 int j;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
61 int out = 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
62 int c;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
63 int t;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
64
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
65 /* first line contain absolute values, other lines contain deltas */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
66 while (out < width){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
67 c = ir2_get_code(&ctx->gb);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
68 if(c > 0x80) { /* we have a run */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
69 c -= 0x80;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
70 for (i = 0; i < c * 2; i++)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
71 dst[out++] = 0x80;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
72 } else { /* copy two values from table */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
73 dst[out++] = table[c * 2];
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
74 dst[out++] = table[(c * 2) + 1];
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
75 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
76 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
77 dst += stride;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
78
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
79 for (j = 1; j < height; j++){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
80 out = 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
81 while (out < width){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
82 c = ir2_get_code(&ctx->gb);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
83 if(c > 0x80) { /* we have a skip */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
84 c -= 0x80;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
85 for (i = 0; i < c * 2; i++) {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
86 dst[out] = dst[out - stride];
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
87 out++;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
88 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
89 } else { /* add two deltas from table */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
90 t = dst[out - stride] + (table[c * 2] - 128);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
91 CLAMP_TO_BYTE(t);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
92 dst[out] = t;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
93 out++;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
94 t = dst[out - stride] + (table[(c * 2) + 1] - 128);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
95 CLAMP_TO_BYTE(t);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
96 dst[out] = t;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
97 out++;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
98 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
99 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
100 dst += stride;
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 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
103
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
104 static void ir2_decode_plane_inter(Ir2Context *ctx, int width, int height, uint8_t *dst, int stride,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
105 const uint8_t *table)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
106 {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
107 int j;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
108 int out = 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
109 int c;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
110 int t;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
111
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
112 for (j = 0; j < height; j++){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
113 out = 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
114 while (out < width){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
115 c = ir2_get_code(&ctx->gb);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
116 if(c > 0x80) { /* we have a skip */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
117 c -= 0x80;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
118 out += c * 2;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
119 } else { /* add two deltas from table */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
120 t = dst[out] + (table[c * 2] - 128);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
121 CLAMP_TO_BYTE(t);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
122 dst[out] = t;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
123 out++;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
124 t = dst[out] + (table[(c * 2) + 1] - 128);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
125 CLAMP_TO_BYTE(t);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
126 dst[out] = t;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
127 out++;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
128 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
129 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
130 dst += stride;
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 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
133
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
134 static int ir2_decode_frame(AVCodecContext *avctx,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
135 void *data, int *data_size,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
136 uint8_t *buf, int buf_size)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
137 {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
138 Ir2Context * const s = avctx->priv_data;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
139 AVFrame *picture = data;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
140 AVFrame * const p= (AVFrame*)&s->picture;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
141 int start;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
142 int i;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
143
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
144 if(p->data[0])
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
145 avctx->release_buffer(avctx, p);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
146
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
147 p->reference = 1;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
148 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
149 if (avctx->reget_buffer(avctx, p)) {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
150 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
151 return -1;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
152 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
153
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
154 s->decode_delta = buf[18];
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
155
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
156 /* decide whether frame uses deltas or not */
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 for (i = 0; i < buf_size; i++)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
159 buf[i] = ff_reverse[buf[i]];
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
160
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
161 start = 48; /* hardcoded for now */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
162
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
163 init_get_bits(&s->gb, buf + start, buf_size - start);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
164
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
165 if (s->decode_delta) { /* intraframe */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
166 ir2_decode_plane(s, avctx->width, avctx->height,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
167 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
168 /* swapped U and V */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
169 ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
170 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
171 ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
172 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
173 } else { /* interframe */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
174 ir2_decode_plane_inter(s, avctx->width, avctx->height,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
175 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
176 /* swapped U and V */
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
177 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
178 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
179 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
180 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
181 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
182
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
183 *picture= *(AVFrame*)&s->picture;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
184 *data_size = sizeof(AVPicture);
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 return buf_size;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
187 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
188
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
189 static int ir2_decode_init(AVCodecContext *avctx){
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
190 Ir2Context * const ic = avctx->priv_data;
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 ic->avctx = avctx;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
193
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
194 avctx->pix_fmt= PIX_FMT_YUV410P;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
195
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
196 if (!ir2_vlc.table)
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
197 init_vlc(&ir2_vlc, CODE_VLC_BITS, IR2_CODES,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
198 &ir2_codes[0][1], 4, 2,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
199 &ir2_codes[0][0], 4, 2, 1);
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
200
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
201 return 0;
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
202 }
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
203
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
204 AVCodec indeo2_decoder = {
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
205 "indeo2",
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
206 CODEC_TYPE_VIDEO,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
207 CODEC_ID_INDEO2,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
208 sizeof(Ir2Context),
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
209 ir2_decode_init,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
210 NULL,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
211 NULL,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
212 ir2_decode_frame,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
213 CODEC_CAP_DR1,
fc91ca5b9066 Indeo 2 decoder by (Kostya <> kostya.shishkov gmail com)
michael
parents:
diff changeset
214 };