Statistics
| Branch: | Revision:

ffmpeg / libavcodec / huffyuv.c @ 71e445fc

History | View | Annotate | Download (40.7 KB)

1 11f18faf Michael Niedermayer
/*
2
 * huffyuv codec for libavcodec
3
 *
4 aaa1e4cd Michael Niedermayer
 * Copyright (c) 2002-2003 Michael Niedermayer <michaelni@gmx.at>
5 11f18faf Michael Niedermayer
 *
6 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9 11f18faf Michael Niedermayer
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
12 11f18faf Michael Niedermayer
 *
13 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
14 11f18faf Michael Niedermayer
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
20 5509bffa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 11f18faf Michael Niedermayer
 *
22
 * see http://www.pcisys.net/~melanson/codecs/huffyuv.txt for a description of
23 115329f1 Diego Biurrun
 * the algorithm used
24 11f18faf Michael Niedermayer
 */
25 115329f1 Diego Biurrun
26 983e3246 Michael Niedermayer
/**
27
 * @file huffyuv.c
28
 * huffyuv codec for libavcodec.
29
 */
30 11f18faf Michael Niedermayer
31
#include "common.h"
32 caa336b4 Michael Niedermayer
#include "bitstream.h"
33 11f18faf Michael Niedermayer
#include "avcodec.h"
34
#include "dsputil.h"
35
36
#define VLC_BITS 11
37 1e491e29 Michael Niedermayer
38 3ad7dd8c Michael Niedermayer
#ifdef WORDS_BIGENDIAN
39
#define B 3
40
#define G 2
41
#define R 1
42
#else
43
#define B 0
44
#define G 1
45
#define R 2
46
#endif
47
48 11f18faf Michael Niedermayer
typedef enum Predictor{
49
    LEFT= 0,
50
    PLANE,
51
    MEDIAN,
52
} Predictor;
53 115329f1 Diego Biurrun
54 11f18faf Michael Niedermayer
typedef struct HYuvContext{
55
    AVCodecContext *avctx;
56
    Predictor predictor;
57
    GetBitContext gb;
58
    PutBitContext pb;
59
    int interlaced;
60
    int decorrelate;
61
    int bitstream_bpp;
62
    int version;
63
    int yuy2;                               //use yuy2 instead of 422P
64
    int bgr32;                              //use bgr32 instead of bgr24
65
    int width, height;
66
    int flags;
67 11087086 Loren Merritt
    int context;
68 11f18faf Michael Niedermayer
    int picture_number;
69 7c5ab7b8 Michael Niedermayer
    int last_slice_end;
70 0ecca7a4 Michael Niedermayer
    uint8_t *temp[3];
71 11f18faf Michael Niedermayer
    uint64_t stats[3][256];
72
    uint8_t len[3][256];
73
    uint32_t bits[3][256];
74
    VLC vlc[3];
75 492cd3a9 Michael Niedermayer
    AVFrame picture;
76 0ecca7a4 Michael Niedermayer
    uint8_t *bitstream_buffer;
77 f038fe8b Diego Biurrun
    unsigned int bitstream_buffer_size;
78 115329f1 Diego Biurrun
    DSPContext dsp;
79 11f18faf Michael Niedermayer
}HYuvContext;
80
81 24def10e Zdenek Kabelac
static const unsigned char classic_shift_luma[] = {
82 676b385c Michael Niedermayer
  34,36,35,69,135,232,9,16,10,24,11,23,12,16,13,10,14,8,15,8,
83
  16,8,17,20,16,10,207,206,205,236,11,8,10,21,9,23,8,8,199,70,
84
  69,68, 0
85
};
86
87 24def10e Zdenek Kabelac
static const unsigned char classic_shift_chroma[] = {
88 676b385c Michael Niedermayer
  66,36,37,38,39,40,41,75,76,77,110,239,144,81,82,83,84,85,118,183,
89
  56,57,88,89,56,89,154,57,58,57,26,141,57,56,58,57,58,57,184,119,
90
  214,245,116,83,82,49,80,79,78,77,44,75,41,40,39,38,37,36,34, 0
91
};
92
93 24def10e Zdenek Kabelac
static const unsigned char classic_add_luma[256] = {
94 676b385c Michael Niedermayer
    3,  9,  5, 12, 10, 35, 32, 29, 27, 50, 48, 45, 44, 41, 39, 37,
95
   73, 70, 68, 65, 64, 61, 58, 56, 53, 50, 49, 46, 44, 41, 38, 36,
96
   68, 65, 63, 61, 58, 55, 53, 51, 48, 46, 45, 43, 41, 39, 38, 36,
97
   35, 33, 32, 30, 29, 27, 26, 25, 48, 47, 46, 44, 43, 41, 40, 39,
98
   37, 36, 35, 34, 32, 31, 30, 28, 27, 26, 24, 23, 22, 20, 19, 37,
99
   35, 34, 33, 31, 30, 29, 27, 26, 24, 23, 21, 20, 18, 17, 15, 29,
100
   27, 26, 24, 22, 21, 19, 17, 16, 14, 26, 25, 23, 21, 19, 18, 16,
101
   15, 27, 25, 23, 21, 19, 17, 16, 14, 26, 25, 23, 21, 18, 17, 14,
102
   12, 17, 19, 13,  4,  9,  2, 11,  1,  7,  8,  0, 16,  3, 14,  6,
103
   12, 10,  5, 15, 18, 11, 10, 13, 15, 16, 19, 20, 22, 24, 27, 15,
104
   18, 20, 22, 24, 26, 14, 17, 20, 22, 24, 27, 15, 18, 20, 23, 25,
105
   28, 16, 19, 22, 25, 28, 32, 36, 21, 25, 29, 33, 38, 42, 45, 49,
106
   28, 31, 34, 37, 40, 42, 44, 47, 49, 50, 52, 54, 56, 57, 59, 60,
107
   62, 64, 66, 67, 69, 35, 37, 39, 40, 42, 43, 45, 47, 48, 51, 52,
108
   54, 55, 57, 59, 60, 62, 63, 66, 67, 69, 71, 72, 38, 40, 42, 43,
109
   46, 47, 49, 51, 26, 28, 30, 31, 33, 34, 18, 19, 11, 13,  7,  8,
110
};
111
112 24def10e Zdenek Kabelac
static const unsigned char classic_add_chroma[256] = {
113 676b385c Michael Niedermayer
    3,  1,  2,  2,  2,  2,  3,  3,  7,  5,  7,  5,  8,  6, 11,  9,
114
    7, 13, 11, 10,  9,  8,  7,  5,  9,  7,  6,  4,  7,  5,  8,  7,
115
   11,  8, 13, 11, 19, 15, 22, 23, 20, 33, 32, 28, 27, 29, 51, 77,
116
   43, 45, 76, 81, 46, 82, 75, 55, 56,144, 58, 80, 60, 74,147, 63,
117
  143, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
118
   80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 27, 30, 21, 22,
119
   17, 14,  5,  6,100, 54, 47, 50, 51, 53,106,107,108,109,110,111,
120
  112,113,114,115,  4,117,118, 92, 94,121,122,  3,124,103,  2,  1,
121
    0,129,130,131,120,119,126,125,136,137,138,139,140,141,142,134,
122
  135,132,133,104, 64,101, 62, 57,102, 95, 93, 59, 61, 28, 97, 96,
123
   52, 49, 48, 29, 32, 25, 24, 46, 23, 98, 45, 44, 43, 20, 42, 41,
124
   19, 18, 99, 40, 15, 39, 38, 16, 13, 12, 11, 37, 10,  9,  8, 36,
125
    7,128,127,105,123,116, 35, 34, 33,145, 31, 79, 42,146, 78, 26,
126
   83, 48, 49, 50, 44, 47, 26, 31, 30, 18, 17, 19, 21, 24, 25, 13,
127
   14, 16, 17, 18, 20, 21, 12, 14, 15,  9, 10,  6,  9,  6,  5,  8,
128
    6, 12,  8, 10,  7,  9,  6,  4,  6,  2,  2,  3,  3,  3,  3,  2,
129
};
130
131 11f18faf Michael Niedermayer
static inline int add_left_prediction(uint8_t *dst, uint8_t *src, int w, int acc){
132
    int i;
133
134
    for(i=0; i<w-1; i++){
135
        acc+= src[i];
136
        dst[i]= acc;
137
        i++;
138
        acc+= src[i];
139
        dst[i]= acc;
140
    }
141
142
    for(; i<w; i++){
143
        acc+= src[i];
144
        dst[i]= acc;
145
    }
146
147
    return acc;
148
}
149
150
static inline void add_median_prediction(uint8_t *dst, uint8_t *src1, uint8_t *diff, int w, int *left, int *left_top){
151
    int i;
152
    uint8_t l, lt;
153
154
    l= *left;
155
    lt= *left_top;
156
157
    for(i=0; i<w; i++){
158
        l= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF) + diff[i];
159
        lt= src1[i];
160
        dst[i]= l;
161 115329f1 Diego Biurrun
    }
162 11f18faf Michael Niedermayer
163
    *left= l;
164
    *left_top= lt;
165
}
166 5fd74135 Michael Niedermayer
167 11f18faf Michael Niedermayer
static inline void add_left_prediction_bgr32(uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue){
168
    int i;
169
    int r,g,b;
170
    r= *red;
171
    g= *green;
172
    b= *blue;
173
174
    for(i=0; i<w; i++){
175 3ad7dd8c Michael Niedermayer
        b+= src[4*i+B];
176
        g+= src[4*i+G];
177
        r+= src[4*i+R];
178 115329f1 Diego Biurrun
179 3ad7dd8c Michael Niedermayer
        dst[4*i+B]= b;
180
        dst[4*i+G]= g;
181
        dst[4*i+R]= r;
182 11f18faf Michael Niedermayer
    }
183
184
    *red= r;
185
    *green= g;
186
    *blue= b;
187
}
188
189 7c5ab7b8 Michael Niedermayer
static inline int sub_left_prediction(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int left){
190 11f18faf Michael Niedermayer
    int i;
191 7c5ab7b8 Michael Niedermayer
    if(w<32){
192
        for(i=0; i<w; i++){
193
            const int temp= src[i];
194
            dst[i]= temp - left;
195
            left= temp;
196
        }
197
        return left;
198
    }else{
199
        for(i=0; i<16; i++){
200
            const int temp= src[i];
201
            dst[i]= temp - left;
202
            left= temp;
203
        }
204
        s->dsp.diff_bytes(dst+16, src+16, src+15, w-16);
205
        return src[w-1];
206 11f18faf Michael Niedermayer
    }
207
}
208 2a250222 Michael Niedermayer
209 11f18faf Michael Niedermayer
static void read_len_table(uint8_t *dst, GetBitContext *gb){
210
    int i, val, repeat;
211 115329f1 Diego Biurrun
212 11f18faf Michael Niedermayer
    for(i=0; i<256;){
213
        repeat= get_bits(gb, 3);
214
        val   = get_bits(gb, 5);
215
        if(repeat==0)
216
            repeat= get_bits(gb, 8);
217
//printf("%d %d\n", val, repeat);
218
        while (repeat--)
219
            dst[i++] = val;
220
    }
221
}
222
223
static int generate_bits_table(uint32_t *dst, uint8_t *len_table){
224
    int len, index;
225
    uint32_t bits=0;
226
227
    for(len=32; len>0; len--){
228
        for(index=0; index<256; index++){
229 14b74d38 Michael Niedermayer
            if(len_table[index]==len)
230
                dst[index]= bits++;
231 11f18faf Michael Niedermayer
        }
232 14b74d38 Michael Niedermayer
        if(bits & 1){
233 9b879566 Michel Bardiaux
            av_log(NULL, AV_LOG_ERROR, "Error generating huffman table\n");
234 14b74d38 Michael Niedermayer
            return -1;
235
        }
236
        bits >>= 1;
237 11f18faf Michael Niedermayer
    }
238
    return 0;
239
}
240
241 62bb489b Måns Rullgård
#ifdef CONFIG_ENCODERS
242 11f18faf Michael Niedermayer
static void generate_len_table(uint8_t *dst, uint64_t *stats, int size){
243
    uint64_t counts[2*size];
244
    int up[2*size];
245
    int offset, i, next;
246 115329f1 Diego Biurrun
247 11f18faf Michael Niedermayer
    for(offset=1; ; offset<<=1){
248
        for(i=0; i<size; i++){
249
            counts[i]= stats[i] + offset - 1;
250
        }
251 115329f1 Diego Biurrun
252 11f18faf Michael Niedermayer
        for(next=size; next<size*2; next++){
253
            uint64_t min1, min2;
254
            int min1_i, min2_i;
255 115329f1 Diego Biurrun
256 11f18faf Michael Niedermayer
            min1=min2= INT64_MAX;
257
            min1_i= min2_i=-1;
258 115329f1 Diego Biurrun
259 11f18faf Michael Niedermayer
            for(i=0; i<next; i++){
260
                if(min2 > counts[i]){
261
                    if(min1 > counts[i]){
262
                        min2= min1;
263
                        min2_i= min1_i;
264
                        min1= counts[i];
265
                        min1_i= i;
266
                    }else{
267
                        min2= counts[i];
268
                        min2_i= i;
269
                    }
270
                }
271
            }
272 115329f1 Diego Biurrun
273 11f18faf Michael Niedermayer
            if(min2==INT64_MAX) break;
274 115329f1 Diego Biurrun
275 11f18faf Michael Niedermayer
            counts[next]= min1 + min2;
276
            counts[min1_i]=
277 0626afe9 Michael Niedermayer
            counts[min2_i]= INT64_MAX;
278 11f18faf Michael Niedermayer
            up[min1_i]=
279
            up[min2_i]= next;
280
            up[next]= -1;
281
        }
282 115329f1 Diego Biurrun
283 11f18faf Michael Niedermayer
        for(i=0; i<size; i++){
284
            int len;
285
            int index=i;
286 115329f1 Diego Biurrun
287 11f18faf Michael Niedermayer
            for(len=0; up[index] != -1; len++)
288
                index= up[index];
289 115329f1 Diego Biurrun
290 48cb67c6 Michael Niedermayer
            if(len >= 32) break;
291 115329f1 Diego Biurrun
292 11f18faf Michael Niedermayer
            dst[i]= len;
293
        }
294
        if(i==size) break;
295
    }
296
}
297 62bb489b Måns Rullgård
#endif /* CONFIG_ENCODERS */
298 11f18faf Michael Niedermayer
299
static int read_huffman_tables(HYuvContext *s, uint8_t *src, int length){
300
    GetBitContext gb;
301
    int i;
302 115329f1 Diego Biurrun
303 68f593b4 Michael Niedermayer
    init_get_bits(&gb, src, length*8);
304 115329f1 Diego Biurrun
305 11f18faf Michael Niedermayer
    for(i=0; i<3; i++){
306
        read_len_table(s->len[i], &gb);
307 115329f1 Diego Biurrun
308 11f18faf Michael Niedermayer
        if(generate_bits_table(s->bits[i], s->len[i])<0){
309
            return -1;
310
        }
311
#if 0
312
for(j=0; j<256; j++){
313
printf("%6X, %2d,  %3d\n", s->bits[i][j], s->len[i][j], j);
314
}
315
#endif
316 11087086 Loren Merritt
        free_vlc(&s->vlc[i]);
317 073c2593 Burkhard Plaum
        init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4, 0);
318 11f18faf Michael Niedermayer
    }
319 115329f1 Diego Biurrun
320 11087086 Loren Merritt
    return (get_bits_count(&gb)+7)/8;
321 11f18faf Michael Niedermayer
}
322
323
static int read_old_huffman_tables(HYuvContext *s){
324 676b385c Michael Niedermayer
#if 1
325 11f18faf Michael Niedermayer
    GetBitContext gb;
326
    int i;
327
328 68f593b4 Michael Niedermayer
    init_get_bits(&gb, classic_shift_luma, sizeof(classic_shift_luma)*8);
329 11f18faf Michael Niedermayer
    read_len_table(s->len[0], &gb);
330 68f593b4 Michael Niedermayer
    init_get_bits(&gb, classic_shift_chroma, sizeof(classic_shift_chroma)*8);
331 11f18faf Michael Niedermayer
    read_len_table(s->len[1], &gb);
332 115329f1 Diego Biurrun
333 11f18faf Michael Niedermayer
    for(i=0; i<256; i++) s->bits[0][i] = classic_add_luma  [i];
334
    for(i=0; i<256; i++) s->bits[1][i] = classic_add_chroma[i];
335
336
    if(s->bitstream_bpp >= 24){
337
        memcpy(s->bits[1], s->bits[0], 256*sizeof(uint32_t));
338
        memcpy(s->len[1] , s->len [0], 256*sizeof(uint8_t));
339
    }
340
    memcpy(s->bits[2], s->bits[1], 256*sizeof(uint32_t));
341
    memcpy(s->len[2] , s->len [1], 256*sizeof(uint8_t));
342 115329f1 Diego Biurrun
343 11087086 Loren Merritt
    for(i=0; i<3; i++){
344
        free_vlc(&s->vlc[i]);
345 073c2593 Burkhard Plaum
        init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4, 0);
346 11087086 Loren Merritt
    }
347 115329f1 Diego Biurrun
348 11f18faf Michael Niedermayer
    return 0;
349
#else
350 267f7edc Steve L'Homme
    av_log(s->avctx, AV_LOG_DEBUG, "v1 huffyuv is not supported \n");
351 11f18faf Michael Niedermayer
    return -1;
352
#endif
353
}
354
355 ae2f1d46 Michael Niedermayer
static void alloc_temp(HYuvContext *s){
356
    int i;
357 115329f1 Diego Biurrun
358 ae2f1d46 Michael Niedermayer
    if(s->bitstream_bpp<24){
359
        for(i=0; i<3; i++){
360
            s->temp[i]= av_malloc(s->width + 16);
361
        }
362
    }else{
363
        s->temp[0]= av_malloc(4*s->width + 16);
364
    }
365
}
366
367 0ecca7a4 Michael Niedermayer
static int common_init(AVCodecContext *avctx){
368 11f18faf Michael Niedermayer
    HYuvContext *s = avctx->priv_data;
369
370
    s->avctx= avctx;
371
    s->flags= avctx->flags;
372 115329f1 Diego Biurrun
373 1d98dca3 Michael Niedermayer
    dsputil_init(&s->dsp, avctx);
374 115329f1 Diego Biurrun
375 0ecca7a4 Michael Niedermayer
    s->width= avctx->width;
376
    s->height= avctx->height;
377
    assert(s->width>0 && s->height>0);
378 115329f1 Diego Biurrun
379 0ecca7a4 Michael Niedermayer
    return 0;
380
}
381
382 62bb489b Måns Rullgård
#ifdef CONFIG_DECODERS
383 0ecca7a4 Michael Niedermayer
static int decode_init(AVCodecContext *avctx)
384
{
385
    HYuvContext *s = avctx->priv_data;
386
387
    common_init(avctx);
388 11087086 Loren Merritt
    memset(s->vlc, 0, 3*sizeof(VLC));
389 115329f1 Diego Biurrun
390 492cd3a9 Michael Niedermayer
    avctx->coded_frame= &s->picture;
391 0ecca7a4 Michael Niedermayer
    s->interlaced= s->height > 288;
392 1e491e29 Michael Niedermayer
393 11f18faf Michael Niedermayer
s->bgr32=1;
394
//if(avctx->extradata)
395
//  printf("extradata:%X, extradata_size:%d\n", *(uint32_t*)avctx->extradata, avctx->extradata_size);
396
    if(avctx->extradata_size){
397 152ba68c Michael Niedermayer
        if((avctx->bits_per_sample&7) && avctx->bits_per_sample != 12)
398 11f18faf Michael Niedermayer
            s->version=1; // do such files exist at all?
399
        else
400
            s->version=2;
401
    }else
402
        s->version=0;
403 115329f1 Diego Biurrun
404 11f18faf Michael Niedermayer
    if(s->version==2){
405 42dd22c4 Loren Merritt
        int method, interlace;
406 11f18faf Michael Niedermayer
407
        method= ((uint8_t*)avctx->extradata)[0];
408
        s->decorrelate= method&64 ? 1 : 0;
409
        s->predictor= method&63;
410
        s->bitstream_bpp= ((uint8_t*)avctx->extradata)[1];
411 115329f1 Diego Biurrun
        if(s->bitstream_bpp==0)
412 11f18faf Michael Niedermayer
            s->bitstream_bpp= avctx->bits_per_sample&~7;
413 42dd22c4 Loren Merritt
        interlace= (((uint8_t*)avctx->extradata)[2] & 0x30) >> 4;
414
        s->interlaced= (interlace==1) ? 1 : (interlace==2) ? 0 : s->interlaced;
415 11087086 Loren Merritt
        s->context= ((uint8_t*)avctx->extradata)[2] & 0x40 ? 1 : 0;
416 115329f1 Diego Biurrun
417 11f18faf Michael Niedermayer
        if(read_huffman_tables(s, ((uint8_t*)avctx->extradata)+4, avctx->extradata_size) < 0)
418
            return -1;
419
    }else{
420
        switch(avctx->bits_per_sample&7){
421
        case 1:
422
            s->predictor= LEFT;
423
            s->decorrelate= 0;
424
            break;
425
        case 2:
426
            s->predictor= LEFT;
427
            s->decorrelate= 1;
428
            break;
429
        case 3:
430
            s->predictor= PLANE;
431
            s->decorrelate= avctx->bits_per_sample >= 24;
432
            break;
433
        case 4:
434
            s->predictor= MEDIAN;
435
            s->decorrelate= 0;
436
            break;
437
        default:
438
            s->predictor= LEFT; //OLD
439
            s->decorrelate= 0;
440
            break;
441
        }
442
        s->bitstream_bpp= avctx->bits_per_sample & ~7;
443 11087086 Loren Merritt
        s->context= 0;
444 115329f1 Diego Biurrun
445 11f18faf Michael Niedermayer
        if(read_old_huffman_tables(s) < 0)
446
            return -1;
447
    }
448 115329f1 Diego Biurrun
449 11f18faf Michael Niedermayer
    switch(s->bitstream_bpp){
450
    case 12:
451
        avctx->pix_fmt = PIX_FMT_YUV420P;
452
        break;
453
    case 16:
454
        if(s->yuy2){
455 71e445fc Diego Biurrun
            avctx->pix_fmt = PIX_FMT_YUYV422;
456 11f18faf Michael Niedermayer
        }else{
457
            avctx->pix_fmt = PIX_FMT_YUV422P;
458
        }
459
        break;
460
    case 24:
461
    case 32:
462
        if(s->bgr32){
463 71e445fc Diego Biurrun
            avctx->pix_fmt = PIX_FMT_RGB32;
464 11f18faf Michael Niedermayer
        }else{
465
            avctx->pix_fmt = PIX_FMT_BGR24;
466
        }
467
        break;
468
    default:
469
        assert(0);
470
    }
471 115329f1 Diego Biurrun
472 ae2f1d46 Michael Niedermayer
    alloc_temp(s);
473 115329f1 Diego Biurrun
474 07140e39 Michael Niedermayer
//    av_log(NULL, AV_LOG_DEBUG, "pred:%d bpp:%d hbpp:%d il:%d\n", s->predictor, s->bitstream_bpp, avctx->bits_per_sample, s->interlaced);
475
476 11f18faf Michael Niedermayer
    return 0;
477
}
478 62bb489b Måns Rullgård
#endif
479 11f18faf Michael Niedermayer
480 62bb489b Måns Rullgård
#ifdef CONFIG_ENCODERS
481 11087086 Loren Merritt
static int store_table(HYuvContext *s, uint8_t *len, uint8_t *buf){
482 11f18faf Michael Niedermayer
    int i;
483 11087086 Loren Merritt
    int index= 0;
484 11f18faf Michael Niedermayer
485
    for(i=0; i<256;){
486
        int val= len[i];
487 a003ee9a Michael Niedermayer
        int repeat=0;
488 115329f1 Diego Biurrun
489 a003ee9a Michael Niedermayer
        for(; i<256 && len[i]==val && repeat<255; i++)
490
            repeat++;
491 115329f1 Diego Biurrun
492 a003ee9a Michael Niedermayer
        assert(val < 32 && val >0 && repeat<256 && repeat>0);
493 11f18faf Michael Niedermayer
        if(repeat>7){
494 11087086 Loren Merritt
            buf[index++]= val;
495
            buf[index++]= repeat;
496 11f18faf Michael Niedermayer
        }else{
497 11087086 Loren Merritt
            buf[index++]= val | (repeat<<5);
498 11f18faf Michael Niedermayer
        }
499
    }
500 115329f1 Diego Biurrun
501 11087086 Loren Merritt
    return index;
502 11f18faf Michael Niedermayer
}
503
504
static int encode_init(AVCodecContext *avctx)
505
{
506
    HYuvContext *s = avctx->priv_data;
507 0ecca7a4 Michael Niedermayer
    int i, j;
508 11f18faf Michael Niedermayer
509 0ecca7a4 Michael Niedermayer
    common_init(avctx);
510 115329f1 Diego Biurrun
511 0ecca7a4 Michael Niedermayer
    avctx->extradata= av_mallocz(1024*30); // 256*3+4 == 772
512
    avctx->stats_out= av_mallocz(1024*30); // 21*256*3(%llu ) + 3(\n) + 1(0) = 16132
513 11f18faf Michael Niedermayer
    s->version=2;
514 115329f1 Diego Biurrun
515 492cd3a9 Michael Niedermayer
    avctx->coded_frame= &s->picture;
516 115329f1 Diego Biurrun
517 11f18faf Michael Niedermayer
    switch(avctx->pix_fmt){
518 152ba68c Michael Niedermayer
    case PIX_FMT_YUV420P:
519
        s->bitstream_bpp= 12;
520
        break;
521 11f18faf Michael Niedermayer
    case PIX_FMT_YUV422P:
522
        s->bitstream_bpp= 16;
523
        break;
524
    default:
525 9b879566 Michel Bardiaux
        av_log(avctx, AV_LOG_ERROR, "format not supported\n");
526 11f18faf Michael Niedermayer
        return -1;
527
    }
528
    avctx->bits_per_sample= s->bitstream_bpp;
529
    s->decorrelate= s->bitstream_bpp >= 24;
530
    s->predictor= avctx->prediction_method;
531 ee598f7b Loren Merritt
    s->interlaced= avctx->flags&CODEC_FLAG_INTERLACED_ME ? 1 : 0;
532 11087086 Loren Merritt
    if(avctx->context_model==1){
533
        s->context= avctx->context_model;
534
        if(s->flags & (CODEC_FLAG_PASS1|CODEC_FLAG_PASS2)){
535
            av_log(avctx, AV_LOG_ERROR, "context=1 is not compatible with 2 pass huffyuv encoding\n");
536
            return -1;
537
        }
538
    }else s->context= 0;
539 115329f1 Diego Biurrun
540 f37b9768 Loren Merritt
    if(avctx->codec->id==CODEC_ID_HUFFYUV){
541
        if(avctx->pix_fmt==PIX_FMT_YUV420P){
542
            av_log(avctx, AV_LOG_ERROR, "Error: YV12 is not supported by huffyuv; use vcodec=ffvhuff or format=422p\n");
543
            return -1;
544
        }
545
        if(avctx->context_model){
546
            av_log(avctx, AV_LOG_ERROR, "Error: per-frame huffman tables are not supported by huffyuv; use vcodec=ffvhuff\n");
547
            return -1;
548
        }
549 0ecca7a4 Michael Niedermayer
        if(s->interlaced != ( s->height > 288 ))
550 f37b9768 Loren Merritt
            av_log(avctx, AV_LOG_INFO, "using huffyuv 2.2.0 or newer interlacing flag\n");
551
    }
552 115329f1 Diego Biurrun
553 11f18faf Michael Niedermayer
    ((uint8_t*)avctx->extradata)[0]= s->predictor;
554
    ((uint8_t*)avctx->extradata)[1]= s->bitstream_bpp;
555 42dd22c4 Loren Merritt
    ((uint8_t*)avctx->extradata)[2]= s->interlaced ? 0x10 : 0x20;
556 11087086 Loren Merritt
    if(s->context)
557
        ((uint8_t*)avctx->extradata)[2]|= 0x40;
558 11f18faf Michael Niedermayer
    ((uint8_t*)avctx->extradata)[3]= 0;
559
    s->avctx->extradata_size= 4;
560 115329f1 Diego Biurrun
561 11f18faf Michael Niedermayer
    if(avctx->stats_in){
562
        char *p= avctx->stats_in;
563 115329f1 Diego Biurrun
564 11f18faf Michael Niedermayer
        for(i=0; i<3; i++)
565
            for(j=0; j<256; j++)
566
                s->stats[i][j]= 1;
567
568
        for(;;){
569
            for(i=0; i<3; i++){
570
                char *next;
571
572
                for(j=0; j<256; j++){
573
                    s->stats[i][j]+= strtol(p, &next, 0);
574
                    if(next==p) return -1;
575
                    p=next;
576 115329f1 Diego Biurrun
                }
577 11f18faf Michael Niedermayer
            }
578
            if(p[0]==0 || p[1]==0 || p[2]==0) break;
579
        }
580
    }else{
581
        for(i=0; i<3; i++)
582
            for(j=0; j<256; j++){
583
                int d= FFMIN(j, 256-j);
584 115329f1 Diego Biurrun
585 11f18faf Michael Niedermayer
                s->stats[i][j]= 100000000/(d+1);
586
            }
587
    }
588 115329f1 Diego Biurrun
589 11f18faf Michael Niedermayer
    for(i=0; i<3; i++){
590
        generate_len_table(s->len[i], s->stats[i], 256);
591
592
        if(generate_bits_table(s->bits[i], s->len[i])<0){
593
            return -1;
594
        }
595 115329f1 Diego Biurrun
596 11087086 Loren Merritt
        s->avctx->extradata_size+=
597
        store_table(s, s->len[i], &((uint8_t*)s->avctx->extradata)[s->avctx->extradata_size]);
598 11f18faf Michael Niedermayer
    }
599
600 11087086 Loren Merritt
    if(s->context){
601
        for(i=0; i<3; i++){
602 0ecca7a4 Michael Niedermayer
            int pels = s->width*s->height / (i?40:10);
603 11087086 Loren Merritt
            for(j=0; j<256; j++){
604
                int d= FFMIN(j, 256-j);
605
                s->stats[i][j]= pels/(d+1);
606
            }
607
        }
608
    }else{
609
        for(i=0; i<3; i++)
610
            for(j=0; j<256; j++)
611
                s->stats[i][j]= 0;
612
    }
613 115329f1 Diego Biurrun
614 11f18faf Michael Niedermayer
//    printf("pred:%d bpp:%d hbpp:%d il:%d\n", s->predictor, s->bitstream_bpp, avctx->bits_per_sample, s->interlaced);
615 5fd74135 Michael Niedermayer
616 ae2f1d46 Michael Niedermayer
    alloc_temp(s);
617
618 11f18faf Michael Niedermayer
    s->picture_number=0;
619 5fd74135 Michael Niedermayer
620 11f18faf Michael Niedermayer
    return 0;
621
}
622 62bb489b Måns Rullgård
#endif /* CONFIG_ENCODERS */
623 11f18faf Michael Niedermayer
624
static void decode_422_bitstream(HYuvContext *s, int count){
625
    int i;
626 5fd74135 Michael Niedermayer
627 11f18faf Michael Niedermayer
    count/=2;
628 115329f1 Diego Biurrun
629 11f18faf Michael Niedermayer
    for(i=0; i<count; i++){
630 115329f1 Diego Biurrun
        s->temp[0][2*i  ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
631
        s->temp[1][  i  ]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
632
        s->temp[0][2*i+1]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
633
        s->temp[2][  i  ]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3);
634 11f18faf Michael Niedermayer
    }
635
}
636
637 152ba68c Michael Niedermayer
static void decode_gray_bitstream(HYuvContext *s, int count){
638
    int i;
639 115329f1 Diego Biurrun
640 152ba68c Michael Niedermayer
    count/=2;
641 115329f1 Diego Biurrun
642 152ba68c Michael Niedermayer
    for(i=0; i<count; i++){
643 115329f1 Diego Biurrun
        s->temp[0][2*i  ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
644
        s->temp[0][2*i+1]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
645 152ba68c Michael Niedermayer
    }
646
}
647
648 62bb489b Måns Rullgård
#ifdef CONFIG_ENCODERS
649 0ecca7a4 Michael Niedermayer
static int encode_422_bitstream(HYuvContext *s, int count){
650 11f18faf Michael Niedermayer
    int i;
651 115329f1 Diego Biurrun
652 0ecca7a4 Michael Niedermayer
    if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 2*4*count){
653
        av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
654
        return -1;
655
    }
656 115329f1 Diego Biurrun
657 11f18faf Michael Niedermayer
    count/=2;
658
    if(s->flags&CODEC_FLAG_PASS1){
659
        for(i=0; i<count; i++){
660
            s->stats[0][ s->temp[0][2*i  ] ]++;
661
            s->stats[1][ s->temp[1][  i  ] ]++;
662
            s->stats[0][ s->temp[0][2*i+1] ]++;
663
            s->stats[2][ s->temp[2][  i  ] ]++;
664
        }
665 09b0499f Michael Niedermayer
    }
666
    if(s->avctx->flags2&CODEC_FLAG2_NO_OUTPUT)
667
        return 0;
668
    if(s->context){
669 11087086 Loren Merritt
        for(i=0; i<count; i++){
670
            s->stats[0][ s->temp[0][2*i  ] ]++;
671
            put_bits(&s->pb, s->len[0][ s->temp[0][2*i  ] ], s->bits[0][ s->temp[0][2*i  ] ]);
672
            s->stats[1][ s->temp[1][  i  ] ]++;
673
            put_bits(&s->pb, s->len[1][ s->temp[1][  i  ] ], s->bits[1][ s->temp[1][  i  ] ]);
674
            s->stats[0][ s->temp[0][2*i+1] ]++;
675
            put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]);
676
            s->stats[2][ s->temp[2][  i  ] ]++;
677
            put_bits(&s->pb, s->len[2][ s->temp[2][  i  ] ], s->bits[2][ s->temp[2][  i  ] ]);
678
        }
679 11f18faf Michael Niedermayer
    }else{
680
        for(i=0; i<count; i++){
681
            put_bits(&s->pb, s->len[0][ s->temp[0][2*i  ] ], s->bits[0][ s->temp[0][2*i  ] ]);
682
            put_bits(&s->pb, s->len[1][ s->temp[1][  i  ] ], s->bits[1][ s->temp[1][  i  ] ]);
683
            put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]);
684
            put_bits(&s->pb, s->len[2][ s->temp[2][  i  ] ], s->bits[2][ s->temp[2][  i  ] ]);
685
        }
686
    }
687 0ecca7a4 Michael Niedermayer
    return 0;
688 11f18faf Michael Niedermayer
}
689
690 0ecca7a4 Michael Niedermayer
static int encode_gray_bitstream(HYuvContext *s, int count){
691 152ba68c Michael Niedermayer
    int i;
692 115329f1 Diego Biurrun
693 0ecca7a4 Michael Niedermayer
    if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 4*count){
694
        av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
695
        return -1;
696
    }
697
698 152ba68c Michael Niedermayer
    count/=2;
699
    if(s->flags&CODEC_FLAG_PASS1){
700
        for(i=0; i<count; i++){
701
            s->stats[0][ s->temp[0][2*i  ] ]++;
702
            s->stats[0][ s->temp[0][2*i+1] ]++;
703
        }
704 09b0499f Michael Niedermayer
    }
705
    if(s->avctx->flags2&CODEC_FLAG2_NO_OUTPUT)
706
        return 0;
707 115329f1 Diego Biurrun
708 09b0499f Michael Niedermayer
    if(s->context){
709 11087086 Loren Merritt
        for(i=0; i<count; i++){
710
            s->stats[0][ s->temp[0][2*i  ] ]++;
711
            put_bits(&s->pb, s->len[0][ s->temp[0][2*i  ] ], s->bits[0][ s->temp[0][2*i  ] ]);
712
            s->stats[0][ s->temp[0][2*i+1] ]++;
713
            put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]);
714
        }
715 152ba68c Michael Niedermayer
    }else{
716
        for(i=0; i<count; i++){
717
            put_bits(&s->pb, s->len[0][ s->temp[0][2*i  ] ], s->bits[0][ s->temp[0][2*i  ] ]);
718
            put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]);
719
        }
720
    }
721 0ecca7a4 Michael Niedermayer
    return 0;
722 152ba68c Michael Niedermayer
}
723 62bb489b Måns Rullgård
#endif /* CONFIG_ENCODERS */
724 152ba68c Michael Niedermayer
725 11f18faf Michael Niedermayer
static void decode_bgr_bitstream(HYuvContext *s, int count){
726
    int i;
727 5fd74135 Michael Niedermayer
728 11f18faf Michael Niedermayer
    if(s->decorrelate){
729
        if(s->bitstream_bpp==24){
730
            for(i=0; i<count; i++){
731 115329f1 Diego Biurrun
                s->temp[0][4*i+G]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
732 0722ccdb Michael Niedermayer
                s->temp[0][4*i+B]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3) + s->temp[0][4*i+G];
733
                s->temp[0][4*i+R]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3) + s->temp[0][4*i+G];
734 11f18faf Michael Niedermayer
            }
735
        }else{
736
            for(i=0; i<count; i++){
737 115329f1 Diego Biurrun
                s->temp[0][4*i+G]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
738 3ad7dd8c Michael Niedermayer
                s->temp[0][4*i+B]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3) + s->temp[0][4*i+G];
739 115329f1 Diego Biurrun
                s->temp[0][4*i+R]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3) + s->temp[0][4*i+G];
740 11f18faf Michael Niedermayer
                                   get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); //?!
741
            }
742
        }
743
    }else{
744
        if(s->bitstream_bpp==24){
745
            for(i=0; i<count; i++){
746 0722ccdb Michael Niedermayer
                s->temp[0][4*i+B]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
747 115329f1 Diego Biurrun
                s->temp[0][4*i+G]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
748
                s->temp[0][4*i+R]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3);
749 11f18faf Michael Niedermayer
            }
750
        }else{
751
            for(i=0; i<count; i++){
752 3ad7dd8c Michael Niedermayer
                s->temp[0][4*i+B]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
753 115329f1 Diego Biurrun
                s->temp[0][4*i+G]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
754
                s->temp[0][4*i+R]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3);
755 11f18faf Michael Niedermayer
                                   get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); //?!
756
            }
757
        }
758
    }
759
}
760
761 62bb489b Måns Rullgård
#ifdef CONFIG_DECODERS
762 7c5ab7b8 Michael Niedermayer
static void draw_slice(HYuvContext *s, int y){
763
    int h, cy;
764 7a06ff14 Michael Niedermayer
    int offset[4];
765 115329f1 Diego Biurrun
766
    if(s->avctx->draw_horiz_band==NULL)
767 7c5ab7b8 Michael Niedermayer
        return;
768 115329f1 Diego Biurrun
769 7c5ab7b8 Michael Niedermayer
    h= y - s->last_slice_end;
770
    y -= h;
771 115329f1 Diego Biurrun
772 7c5ab7b8 Michael Niedermayer
    if(s->bitstream_bpp==12){
773
        cy= y>>1;
774
    }else{
775
        cy= y;
776
    }
777 7a06ff14 Michael Niedermayer
778
    offset[0] = s->picture.linesize[0]*y;
779
    offset[1] = s->picture.linesize[1]*cy;
780
    offset[2] = s->picture.linesize[2]*cy;
781
    offset[3] = 0;
782 7c5ab7b8 Michael Niedermayer
    emms_c();
783
784 3bb07d61 Michael Niedermayer
    s->avctx->draw_horiz_band(s->avctx, &s->picture, offset, y, 3, h);
785 115329f1 Diego Biurrun
786 7c5ab7b8 Michael Niedermayer
    s->last_slice_end= y + h;
787
}
788
789 11f18faf Michael Niedermayer
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size){
790
    HYuvContext *s = avctx->priv_data;
791
    const int width= s->width;
792
    const int width2= s->width>>1;
793
    const int height= s->height;
794 22f3e8be Michael Niedermayer
    int fake_ystride, fake_ustride, fake_vstride;
795 492cd3a9 Michael Niedermayer
    AVFrame * const p= &s->picture;
796 11087086 Loren Merritt
    int table_size= 0;
797 11f18faf Michael Niedermayer
798 492cd3a9 Michael Niedermayer
    AVFrame *picture = data;
799 11f18faf Michael Niedermayer
800 0ecca7a4 Michael Niedermayer
    s->bitstream_buffer= av_fast_realloc(s->bitstream_buffer, &s->bitstream_buffer_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
801 11f18faf Michael Niedermayer
802 3d2e8cce Michael Niedermayer
    s->dsp.bswap_buf((uint32_t*)s->bitstream_buffer, (uint32_t*)buf, buf_size/4);
803 115329f1 Diego Biurrun
804 e20c4069 Michael Niedermayer
    if(p->data[0])
805
        avctx->release_buffer(avctx, p);
806
807 1e491e29 Michael Niedermayer
    p->reference= 0;
808
    if(avctx->get_buffer(avctx, p) < 0){
809 9b879566 Michel Bardiaux
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
810 1e491e29 Michael Niedermayer
        return -1;
811 22f3e8be Michael Niedermayer
    }
812 115329f1 Diego Biurrun
813 11087086 Loren Merritt
    if(s->context){
814
        table_size = read_huffman_tables(s, s->bitstream_buffer, buf_size);
815
        if(table_size < 0)
816
            return -1;
817
    }
818
819 e70e7a4b Michael Niedermayer
    if((unsigned)(buf_size-table_size) >= INT_MAX/8)
820
        return -1;
821
822 11087086 Loren Merritt
    init_get_bits(&s->gb, s->bitstream_buffer+table_size, (buf_size-table_size)*8);
823 1e491e29 Michael Niedermayer
824
    fake_ystride= s->interlaced ? p->linesize[0]*2  : p->linesize[0];
825
    fake_ustride= s->interlaced ? p->linesize[1]*2  : p->linesize[1];
826
    fake_vstride= s->interlaced ? p->linesize[2]*2  : p->linesize[2];
827 115329f1 Diego Biurrun
828 7c5ab7b8 Michael Niedermayer
    s->last_slice_end= 0;
829 115329f1 Diego Biurrun
830 11f18faf Michael Niedermayer
    if(s->bitstream_bpp<24){
831 152ba68c Michael Niedermayer
        int y, cy;
832 11f18faf Michael Niedermayer
        int lefty, leftu, leftv;
833
        int lefttopy, lefttopu, lefttopv;
834 115329f1 Diego Biurrun
835 11f18faf Michael Niedermayer
        if(s->yuy2){
836 1e491e29 Michael Niedermayer
            p->data[0][3]= get_bits(&s->gb, 8);
837
            p->data[0][2]= get_bits(&s->gb, 8);
838
            p->data[0][1]= get_bits(&s->gb, 8);
839
            p->data[0][0]= get_bits(&s->gb, 8);
840 115329f1 Diego Biurrun
841 160d679c Mike Melanson
            av_log(avctx, AV_LOG_ERROR, "YUY2 output is not implemented yet\n");
842 11f18faf Michael Niedermayer
            return -1;
843
        }else{
844 115329f1 Diego Biurrun
845 1e491e29 Michael Niedermayer
            leftv= p->data[2][0]= get_bits(&s->gb, 8);
846
            lefty= p->data[0][1]= get_bits(&s->gb, 8);
847
            leftu= p->data[1][0]= get_bits(&s->gb, 8);
848
                   p->data[0][0]= get_bits(&s->gb, 8);
849 115329f1 Diego Biurrun
850 11f18faf Michael Niedermayer
            switch(s->predictor){
851
            case LEFT:
852
            case PLANE:
853
                decode_422_bitstream(s, width-2);
854 1e491e29 Michael Niedermayer
                lefty= add_left_prediction(p->data[0] + 2, s->temp[0], width-2, lefty);
855 11f18faf Michael Niedermayer
                if(!(s->flags&CODEC_FLAG_GRAY)){
856 1e491e29 Michael Niedermayer
                    leftu= add_left_prediction(p->data[1] + 1, s->temp[1], width2-1, leftu);
857
                    leftv= add_left_prediction(p->data[2] + 1, s->temp[2], width2-1, leftv);
858 11f18faf Michael Niedermayer
                }
859
860 152ba68c Michael Niedermayer
                for(cy=y=1; y<s->height; y++,cy++){
861 11f18faf Michael Niedermayer
                    uint8_t *ydst, *udst, *vdst;
862 115329f1 Diego Biurrun
863 152ba68c Michael Niedermayer
                    if(s->bitstream_bpp==12){
864
                        decode_gray_bitstream(s, width);
865 115329f1 Diego Biurrun
866 1e491e29 Michael Niedermayer
                        ydst= p->data[0] + p->linesize[0]*y;
867 152ba68c Michael Niedermayer
868
                        lefty= add_left_prediction(ydst, s->temp[0], width, lefty);
869
                        if(s->predictor == PLANE){
870
                            if(y>s->interlaced)
871
                                s->dsp.add_bytes(ydst, ydst - fake_ystride, width);
872
                        }
873
                        y++;
874
                        if(y>=s->height) break;
875
                    }
876 115329f1 Diego Biurrun
877 7c5ab7b8 Michael Niedermayer
                    draw_slice(s, y);
878 115329f1 Diego Biurrun
879 1e491e29 Michael Niedermayer
                    ydst= p->data[0] + p->linesize[0]*y;
880
                    udst= p->data[1] + p->linesize[1]*cy;
881
                    vdst= p->data[2] + p->linesize[2]*cy;
882 115329f1 Diego Biurrun
883 152ba68c Michael Niedermayer
                    decode_422_bitstream(s, width);
884 11f18faf Michael Niedermayer
                    lefty= add_left_prediction(ydst, s->temp[0], width, lefty);
885
                    if(!(s->flags&CODEC_FLAG_GRAY)){
886
                        leftu= add_left_prediction(udst, s->temp[1], width2, leftu);
887
                        leftv= add_left_prediction(vdst, s->temp[2], width2, leftv);
888
                    }
889
                    if(s->predictor == PLANE){
890 152ba68c Michael Niedermayer
                        if(cy>s->interlaced){
891 11f18faf Michael Niedermayer
                            s->dsp.add_bytes(ydst, ydst - fake_ystride, width);
892
                            if(!(s->flags&CODEC_FLAG_GRAY)){
893
                                s->dsp.add_bytes(udst, udst - fake_ustride, width2);
894
                                s->dsp.add_bytes(vdst, vdst - fake_vstride, width2);
895
                            }
896
                        }
897
                    }
898
                }
899 7c5ab7b8 Michael Niedermayer
                draw_slice(s, height);
900 115329f1 Diego Biurrun
901 11f18faf Michael Niedermayer
                break;
902
            case MEDIAN:
903
                /* first line except first 2 pixels is left predicted */
904
                decode_422_bitstream(s, width-2);
905 1e491e29 Michael Niedermayer
                lefty= add_left_prediction(p->data[0] + 2, s->temp[0], width-2, lefty);
906 11f18faf Michael Niedermayer
                if(!(s->flags&CODEC_FLAG_GRAY)){
907 1e491e29 Michael Niedermayer
                    leftu= add_left_prediction(p->data[1] + 1, s->temp[1], width2-1, leftu);
908
                    leftv= add_left_prediction(p->data[2] + 1, s->temp[2], width2-1, leftv);
909 11f18faf Michael Niedermayer
                }
910 115329f1 Diego Biurrun
911 152ba68c Michael Niedermayer
                cy=y=1;
912 115329f1 Diego Biurrun
913 11f18faf Michael Niedermayer
                /* second line is left predicted for interlaced case */
914
                if(s->interlaced){
915
                    decode_422_bitstream(s, width);
916 1e491e29 Michael Niedermayer
                    lefty= add_left_prediction(p->data[0] + p->linesize[0], s->temp[0], width, lefty);
917 11f18faf Michael Niedermayer
                    if(!(s->flags&CODEC_FLAG_GRAY)){
918 1e491e29 Michael Niedermayer
                        leftu= add_left_prediction(p->data[1] + p->linesize[2], s->temp[1], width2, leftu);
919
                        leftv= add_left_prediction(p->data[2] + p->linesize[1], s->temp[2], width2, leftv);
920 11f18faf Michael Niedermayer
                    }
921 152ba68c Michael Niedermayer
                    y++; cy++;
922 11f18faf Michael Niedermayer
                }
923
924
                /* next 4 pixels are left predicted too */
925
                decode_422_bitstream(s, 4);
926 1e491e29 Michael Niedermayer
                lefty= add_left_prediction(p->data[0] + fake_ystride, s->temp[0], 4, lefty);
927 11f18faf Michael Niedermayer
                if(!(s->flags&CODEC_FLAG_GRAY)){
928 1e491e29 Michael Niedermayer
                    leftu= add_left_prediction(p->data[1] + fake_ustride, s->temp[1], 2, leftu);
929
                    leftv= add_left_prediction(p->data[2] + fake_vstride, s->temp[2], 2, leftv);
930 11f18faf Michael Niedermayer
                }
931
932
                /* next line except the first 4 pixels is median predicted */
933 1e491e29 Michael Niedermayer
                lefttopy= p->data[0][3];
934 11f18faf Michael Niedermayer
                decode_422_bitstream(s, width-4);
935 1e491e29 Michael Niedermayer
                add_median_prediction(p->data[0] + fake_ystride+4, p->data[0]+4, s->temp[0], width-4, &lefty, &lefttopy);
936 11f18faf Michael Niedermayer
                if(!(s->flags&CODEC_FLAG_GRAY)){
937 1e491e29 Michael Niedermayer
                    lefttopu= p->data[1][1];
938
                    lefttopv= p->data[2][1];
939
                    add_median_prediction(p->data[1] + fake_ustride+2, p->data[1]+2, s->temp[1], width2-2, &leftu, &lefttopu);
940
                    add_median_prediction(p->data[2] + fake_vstride+2, p->data[2]+2, s->temp[2], width2-2, &leftv, &lefttopv);
941 11f18faf Michael Niedermayer
                }
942 152ba68c Michael Niedermayer
                y++; cy++;
943 115329f1 Diego Biurrun
944 152ba68c Michael Niedermayer
                for(; y<height; y++,cy++){
945 11f18faf Michael Niedermayer
                    uint8_t *ydst, *udst, *vdst;
946 152ba68c Michael Niedermayer
947
                    if(s->bitstream_bpp==12){
948
                        while(2*cy > y){
949
                            decode_gray_bitstream(s, width);
950 1e491e29 Michael Niedermayer
                            ydst= p->data[0] + p->linesize[0]*y;
951 152ba68c Michael Niedermayer
                            add_median_prediction(ydst, ydst - fake_ystride, s->temp[0], width, &lefty, &lefttopy);
952
                            y++;
953
                        }
954
                        if(y>=height) break;
955
                    }
956 7c5ab7b8 Michael Niedermayer
                    draw_slice(s, y);
957 152ba68c Michael Niedermayer
958 11f18faf Michael Niedermayer
                    decode_422_bitstream(s, width);
959 152ba68c Michael Niedermayer
960 1e491e29 Michael Niedermayer
                    ydst= p->data[0] + p->linesize[0]*y;
961
                    udst= p->data[1] + p->linesize[1]*cy;
962
                    vdst= p->data[2] + p->linesize[2]*cy;
963 11f18faf Michael Niedermayer
964
                    add_median_prediction(ydst, ydst - fake_ystride, s->temp[0], width, &lefty, &lefttopy);
965
                    if(!(s->flags&CODEC_FLAG_GRAY)){
966
                        add_median_prediction(udst, udst - fake_ustride, s->temp[1], width2, &leftu, &lefttopu);
967
                        add_median_prediction(vdst, vdst - fake_vstride, s->temp[2], width2, &leftv, &lefttopv);
968
                    }
969
                }
970 7c5ab7b8 Michael Niedermayer
971
                draw_slice(s, height);
972 11f18faf Michael Niedermayer
                break;
973
            }
974
        }
975
    }else{
976
        int y;
977
        int leftr, leftg, leftb;
978 1e491e29 Michael Niedermayer
        const int last_line= (height-1)*p->linesize[0];
979 115329f1 Diego Biurrun
980 11f18faf Michael Niedermayer
        if(s->bitstream_bpp==32){
981 0722ccdb Michael Niedermayer
            skip_bits(&s->gb, 8);
982
            leftr= p->data[0][last_line+R]= get_bits(&s->gb, 8);
983
            leftg= p->data[0][last_line+G]= get_bits(&s->gb, 8);
984
            leftb= p->data[0][last_line+B]= get_bits(&s->gb, 8);
985 11f18faf Michael Niedermayer
        }else{
986 0722ccdb Michael Niedermayer
            leftr= p->data[0][last_line+R]= get_bits(&s->gb, 8);
987
            leftg= p->data[0][last_line+G]= get_bits(&s->gb, 8);
988
            leftb= p->data[0][last_line+B]= get_bits(&s->gb, 8);
989 11f18faf Michael Niedermayer
            skip_bits(&s->gb, 8);
990
        }
991 115329f1 Diego Biurrun
992 11f18faf Michael Niedermayer
        if(s->bgr32){
993
            switch(s->predictor){
994
            case LEFT:
995
            case PLANE:
996
                decode_bgr_bitstream(s, width-1);
997 1e491e29 Michael Niedermayer
                add_left_prediction_bgr32(p->data[0] + last_line+4, s->temp[0], width-1, &leftr, &leftg, &leftb);
998 11f18faf Michael Niedermayer
999
                for(y=s->height-2; y>=0; y--){ //yes its stored upside down
1000
                    decode_bgr_bitstream(s, width);
1001 115329f1 Diego Biurrun
1002 1e491e29 Michael Niedermayer
                    add_left_prediction_bgr32(p->data[0] + p->linesize[0]*y, s->temp[0], width, &leftr, &leftg, &leftb);
1003 11f18faf Michael Niedermayer
                    if(s->predictor == PLANE){
1004 fc0be57f Michael Niedermayer
                        if((y&s->interlaced)==0 && y<s->height-1-s->interlaced){
1005 115329f1 Diego Biurrun
                            s->dsp.add_bytes(p->data[0] + p->linesize[0]*y,
1006 1e491e29 Michael Niedermayer
                                             p->data[0] + p->linesize[0]*y + fake_ystride, fake_ystride);
1007 11f18faf Michael Niedermayer
                        }
1008
                    }
1009
                }
1010 160d679c Mike Melanson
                draw_slice(s, height); // just 1 large slice as this is not possible in reverse order
1011 11f18faf Michael Niedermayer
                break;
1012
            default:
1013 9b879566 Michel Bardiaux
                av_log(avctx, AV_LOG_ERROR, "prediction type not supported!\n");
1014 11f18faf Michael Niedermayer
            }
1015
        }else{
1016
1017 160d679c Mike Melanson
            av_log(avctx, AV_LOG_ERROR, "BGR24 output is not implemented yet\n");
1018 11f18faf Michael Niedermayer
            return -1;
1019
        }
1020
    }
1021
    emms_c();
1022 115329f1 Diego Biurrun
1023 1e491e29 Michael Niedermayer
    *picture= *p;
1024 492cd3a9 Michael Niedermayer
    *data_size = sizeof(AVFrame);
1025 115329f1 Diego Biurrun
1026 1adc29ee Michael Niedermayer
    return (get_bits_count(&s->gb)+31)/32*4 + table_size;
1027 11f18faf Michael Niedermayer
}
1028 62bb489b Måns Rullgård
#endif
1029 11f18faf Michael Niedermayer
1030 0ecca7a4 Michael Niedermayer
static int common_end(HYuvContext *s){
1031
    int i;
1032 115329f1 Diego Biurrun
1033 0ecca7a4 Michael Niedermayer
    for(i=0; i<3; i++){
1034
        av_freep(&s->temp[i]);
1035
    }
1036
    return 0;
1037
}
1038
1039 62bb489b Måns Rullgård
#ifdef CONFIG_DECODERS
1040 11f18faf Michael Niedermayer
static int decode_end(AVCodecContext *avctx)
1041
{
1042
    HYuvContext *s = avctx->priv_data;
1043
    int i;
1044 115329f1 Diego Biurrun
1045 0ecca7a4 Michael Niedermayer
    common_end(s);
1046
    av_freep(&s->bitstream_buffer);
1047 115329f1 Diego Biurrun
1048 11f18faf Michael Niedermayer
    for(i=0; i<3; i++){
1049
        free_vlc(&s->vlc[i]);
1050
    }
1051 1e491e29 Michael Niedermayer
1052 11f18faf Michael Niedermayer
    return 0;
1053
}
1054 62bb489b Måns Rullgård
#endif
1055 11f18faf Michael Niedermayer
1056 62bb489b Måns Rullgård
#ifdef CONFIG_ENCODERS
1057 11f18faf Michael Niedermayer
static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
1058
    HYuvContext *s = avctx->priv_data;
1059 492cd3a9 Michael Niedermayer
    AVFrame *pict = data;
1060 11f18faf Michael Niedermayer
    const int width= s->width;
1061
    const int width2= s->width>>1;
1062
    const int height= s->height;
1063
    const int fake_ystride= s->interlaced ? pict->linesize[0]*2  : pict->linesize[0];
1064
    const int fake_ustride= s->interlaced ? pict->linesize[1]*2  : pict->linesize[1];
1065
    const int fake_vstride= s->interlaced ? pict->linesize[2]*2  : pict->linesize[2];
1066 492cd3a9 Michael Niedermayer
    AVFrame * const p= &s->picture;
1067 11087086 Loren Merritt
    int i, j, size=0;
1068 11f18faf Michael Niedermayer
1069 1e491e29 Michael Niedermayer
    *p = *pict;
1070 aaa1e4cd Michael Niedermayer
    p->pict_type= FF_I_TYPE;
1071
    p->key_frame= 1;
1072 115329f1 Diego Biurrun
1073 11087086 Loren Merritt
    if(s->context){
1074
        for(i=0; i<3; i++){
1075
            generate_len_table(s->len[i], s->stats[i], 256);
1076
            if(generate_bits_table(s->bits[i], s->len[i])<0)
1077
                return -1;
1078
            size+= store_table(s, s->len[i], &buf[size]);
1079
        }
1080
1081
        for(i=0; i<3; i++)
1082
            for(j=0; j<256; j++)
1083
                s->stats[i][j] >>= 1;
1084
    }
1085
1086
    init_put_bits(&s->pb, buf+size, buf_size-size);
1087
1088 152ba68c Michael Niedermayer
    if(avctx->pix_fmt == PIX_FMT_YUV422P || avctx->pix_fmt == PIX_FMT_YUV420P){
1089
        int lefty, leftu, leftv, y, cy;
1090 11f18faf Michael Niedermayer
1091 1e491e29 Michael Niedermayer
        put_bits(&s->pb, 8, leftv= p->data[2][0]);
1092
        put_bits(&s->pb, 8, lefty= p->data[0][1]);
1093
        put_bits(&s->pb, 8, leftu= p->data[1][0]);
1094
        put_bits(&s->pb, 8,        p->data[0][0]);
1095 115329f1 Diego Biurrun
1096 1e491e29 Michael Niedermayer
        lefty= sub_left_prediction(s, s->temp[0], p->data[0]+2, width-2 , lefty);
1097
        leftu= sub_left_prediction(s, s->temp[1], p->data[1]+1, width2-1, leftu);
1098
        leftv= sub_left_prediction(s, s->temp[2], p->data[2]+1, width2-1, leftv);
1099 115329f1 Diego Biurrun
1100 11f18faf Michael Niedermayer
        encode_422_bitstream(s, width-2);
1101 115329f1 Diego Biurrun
1102 11f18faf Michael Niedermayer
        if(s->predictor==MEDIAN){
1103
            int lefttopy, lefttopu, lefttopv;
1104 152ba68c Michael Niedermayer
            cy=y=1;
1105 11f18faf Michael Niedermayer
            if(s->interlaced){
1106 1e491e29 Michael Niedermayer
                lefty= sub_left_prediction(s, s->temp[0], p->data[0]+p->linesize[0], width , lefty);
1107
                leftu= sub_left_prediction(s, s->temp[1], p->data[1]+p->linesize[1], width2, leftu);
1108
                leftv= sub_left_prediction(s, s->temp[2], p->data[2]+p->linesize[2], width2, leftv);
1109 115329f1 Diego Biurrun
1110 11f18faf Michael Niedermayer
                encode_422_bitstream(s, width);
1111 152ba68c Michael Niedermayer
                y++; cy++;
1112 11f18faf Michael Niedermayer
            }
1113 115329f1 Diego Biurrun
1114 1e491e29 Michael Niedermayer
            lefty= sub_left_prediction(s, s->temp[0], p->data[0]+fake_ystride, 4, lefty);
1115 07140e39 Michael Niedermayer
            leftu= sub_left_prediction(s, s->temp[1], p->data[1]+fake_ustride, 2, leftu);
1116
            leftv= sub_left_prediction(s, s->temp[2], p->data[2]+fake_vstride, 2, leftv);
1117 115329f1 Diego Biurrun
1118 11f18faf Michael Niedermayer
            encode_422_bitstream(s, 4);
1119 152ba68c Michael Niedermayer
1120 1e491e29 Michael Niedermayer
            lefttopy= p->data[0][3];
1121
            lefttopu= p->data[1][1];
1122
            lefttopv= p->data[2][1];
1123 84705403 Michael Niedermayer
            s->dsp.sub_hfyu_median_prediction(s->temp[0], p->data[0]+4, p->data[0] + fake_ystride+4, width-4 , &lefty, &lefttopy);
1124
            s->dsp.sub_hfyu_median_prediction(s->temp[1], p->data[1]+2, p->data[1] + fake_ustride+2, width2-2, &leftu, &lefttopu);
1125
            s->dsp.sub_hfyu_median_prediction(s->temp[2], p->data[2]+2, p->data[2] + fake_vstride+2, width2-2, &leftv, &lefttopv);
1126 11f18faf Michael Niedermayer
            encode_422_bitstream(s, width-4);
1127 152ba68c Michael Niedermayer
            y++; cy++;
1128 11f18faf Michael Niedermayer
1129 152ba68c Michael Niedermayer
            for(; y<height; y++,cy++){
1130 11f18faf Michael Niedermayer
                uint8_t *ydst, *udst, *vdst;
1131 115329f1 Diego Biurrun
1132 152ba68c Michael Niedermayer
                if(s->bitstream_bpp==12){
1133
                    while(2*cy > y){
1134 1e491e29 Michael Niedermayer
                        ydst= p->data[0] + p->linesize[0]*y;
1135 84705403 Michael Niedermayer
                        s->dsp.sub_hfyu_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy);
1136 152ba68c Michael Niedermayer
                        encode_gray_bitstream(s, width);
1137
                        y++;
1138
                    }
1139
                    if(y>=height) break;
1140
                }
1141 1e491e29 Michael Niedermayer
                ydst= p->data[0] + p->linesize[0]*y;
1142
                udst= p->data[1] + p->linesize[1]*cy;
1143
                vdst= p->data[2] + p->linesize[2]*cy;
1144 11f18faf Michael Niedermayer
1145 84705403 Michael Niedermayer
                s->dsp.sub_hfyu_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy);
1146
                s->dsp.sub_hfyu_median_prediction(s->temp[1], udst - fake_ustride, udst, width2, &leftu, &lefttopu);
1147
                s->dsp.sub_hfyu_median_prediction(s->temp[2], vdst - fake_vstride, vdst, width2, &leftv, &lefttopv);
1148 11f18faf Michael Niedermayer
1149
                encode_422_bitstream(s, width);
1150
            }
1151
        }else{
1152 152ba68c Michael Niedermayer
            for(cy=y=1; y<height; y++,cy++){
1153 11f18faf Michael Niedermayer
                uint8_t *ydst, *udst, *vdst;
1154 115329f1 Diego Biurrun
1155 152ba68c Michael Niedermayer
                /* encode a luma only line & y++ */
1156
                if(s->bitstream_bpp==12){
1157 1e491e29 Michael Niedermayer
                    ydst= p->data[0] + p->linesize[0]*y;
1158 152ba68c Michael Niedermayer
1159
                    if(s->predictor == PLANE && s->interlaced < y){
1160 7c5ab7b8 Michael Niedermayer
                        s->dsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
1161 152ba68c Michael Niedermayer
1162 7c5ab7b8 Michael Niedermayer
                        lefty= sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
1163 152ba68c Michael Niedermayer
                    }else{
1164 7c5ab7b8 Michael Niedermayer
                        lefty= sub_left_prediction(s, s->temp[0], ydst, width , lefty);
1165 152ba68c Michael Niedermayer
                    }
1166
                    encode_gray_bitstream(s, width);
1167
                    y++;
1168
                    if(y>=height) break;
1169
                }
1170 115329f1 Diego Biurrun
1171 1e491e29 Michael Niedermayer
                ydst= p->data[0] + p->linesize[0]*y;
1172
                udst= p->data[1] + p->linesize[1]*cy;
1173
                vdst= p->data[2] + p->linesize[2]*cy;
1174 11f18faf Michael Niedermayer
1175 152ba68c Michael Niedermayer
                if(s->predictor == PLANE && s->interlaced < cy){
1176 7c5ab7b8 Michael Niedermayer
                    s->dsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
1177
                    s->dsp.diff_bytes(s->temp[2], udst, udst - fake_ustride, width2);
1178 ae2f1d46 Michael Niedermayer
                    s->dsp.diff_bytes(s->temp[2] + width2, vdst, vdst - fake_vstride, width2);
1179 11f18faf Michael Niedermayer
1180 7c5ab7b8 Michael Niedermayer
                    lefty= sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
1181
                    leftu= sub_left_prediction(s, s->temp[1], s->temp[2], width2, leftu);
1182 ae2f1d46 Michael Niedermayer
                    leftv= sub_left_prediction(s, s->temp[2], s->temp[2] + width2, width2, leftv);
1183 11f18faf Michael Niedermayer
                }else{
1184 7c5ab7b8 Michael Niedermayer
                    lefty= sub_left_prediction(s, s->temp[0], ydst, width , lefty);
1185
                    leftu= sub_left_prediction(s, s->temp[1], udst, width2, leftu);
1186
                    leftv= sub_left_prediction(s, s->temp[2], vdst, width2, leftv);
1187 11f18faf Michael Niedermayer
                }
1188
1189
                encode_422_bitstream(s, width);
1190
            }
1191 115329f1 Diego Biurrun
        }
1192 11f18faf Michael Niedermayer
    }else{
1193 9b879566 Michel Bardiaux
        av_log(avctx, AV_LOG_ERROR, "Format not supported!\n");
1194 11f18faf Michael Niedermayer
    }
1195
    emms_c();
1196 115329f1 Diego Biurrun
1197 11087086 Loren Merritt
    size+= (put_bits_count(&s->pb)+31)/8;
1198
    size/= 4;
1199 115329f1 Diego Biurrun
1200 11f18faf Michael Niedermayer
    if((s->flags&CODEC_FLAG_PASS1) && (s->picture_number&31)==0){
1201
        int j;
1202
        char *p= avctx->stats_out;
1203 2fc8ea24 Michael Niedermayer
        char *end= p + 1024*30;
1204 11f18faf Michael Niedermayer
        for(i=0; i<3; i++){
1205
            for(j=0; j<256; j++){
1206 4733abcb Måns Rullgård
                snprintf(p, end-p, "%"PRIu64" ", s->stats[i][j]);
1207 11f18faf Michael Niedermayer
                p+= strlen(p);
1208
                s->stats[i][j]= 0;
1209
            }
1210 2fc8ea24 Michael Niedermayer
            snprintf(p, end-p, "\n");
1211 11f18faf Michael Niedermayer
            p++;
1212
        }
1213 09b0499f Michael Niedermayer
    }
1214
    if(!(s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT)){
1215 152ba68c Michael Niedermayer
        flush_put_bits(&s->pb);
1216 3d2e8cce Michael Niedermayer
        s->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, size);
1217 d925c516 Michael Niedermayer
        avctx->stats_out[0] = '\0';
1218 11f18faf Michael Niedermayer
    }
1219 115329f1 Diego Biurrun
1220 11f18faf Michael Niedermayer
    s->picture_number++;
1221 1e491e29 Michael Niedermayer
1222 11f18faf Michael Niedermayer
    return size*4;
1223
}
1224
1225
static int encode_end(AVCodecContext *avctx)
1226
{
1227 0ecca7a4 Michael Niedermayer
    HYuvContext *s = avctx->priv_data;
1228 115329f1 Diego Biurrun
1229 0ecca7a4 Michael Niedermayer
    common_end(s);
1230 11f18faf Michael Niedermayer
1231
    av_freep(&avctx->extradata);
1232
    av_freep(&avctx->stats_out);
1233 115329f1 Diego Biurrun
1234 11f18faf Michael Niedermayer
    return 0;
1235
}
1236 62bb489b Måns Rullgård
#endif /* CONFIG_ENCODERS */
1237 11f18faf Michael Niedermayer
1238 62bb489b Måns Rullgård
#ifdef CONFIG_DECODERS
1239 11f18faf Michael Niedermayer
AVCodec huffyuv_decoder = {
1240
    "huffyuv",
1241
    CODEC_TYPE_VIDEO,
1242
    CODEC_ID_HUFFYUV,
1243
    sizeof(HYuvContext),
1244
    decode_init,
1245
    NULL,
1246
    decode_end,
1247
    decode_frame,
1248 7c5ab7b8 Michael Niedermayer
    CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND,
1249 11f18faf Michael Niedermayer
    NULL
1250
};
1251
1252 f37b9768 Loren Merritt
AVCodec ffvhuff_decoder = {
1253
    "ffvhuff",
1254
    CODEC_TYPE_VIDEO,
1255
    CODEC_ID_FFVHUFF,
1256
    sizeof(HYuvContext),
1257
    decode_init,
1258
    NULL,
1259
    decode_end,
1260
    decode_frame,
1261
    CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND,
1262
    NULL
1263
};
1264 62bb489b Måns Rullgård
#endif
1265 f37b9768 Loren Merritt
1266 5fd74135 Michael Niedermayer
#ifdef CONFIG_ENCODERS
1267
1268 11f18faf Michael Niedermayer
AVCodec huffyuv_encoder = {
1269
    "huffyuv",
1270
    CODEC_TYPE_VIDEO,
1271
    CODEC_ID_HUFFYUV,
1272
    sizeof(HYuvContext),
1273
    encode_init,
1274
    encode_frame,
1275
    encode_end,
1276 27dc20a0 Michael Niedermayer
    .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV422P, -1},
1277 11f18faf Michael Niedermayer
};
1278 5fd74135 Michael Niedermayer
1279 f37b9768 Loren Merritt
AVCodec ffvhuff_encoder = {
1280
    "ffvhuff",
1281
    CODEC_TYPE_VIDEO,
1282
    CODEC_ID_FFVHUFF,
1283
    sizeof(HYuvContext),
1284
    encode_init,
1285
    encode_frame,
1286
    encode_end,
1287 27dc20a0 Michael Niedermayer
    .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, -1},
1288 f37b9768 Loren Merritt
};
1289
1290 aea22133 Zdenek Kabelac
#endif //CONFIG_ENCODERS