Fixed initialisation of tf in file_open(). Without setting the memory to 0,
[cinelerra_cv/mob.git] / quicktime / ffmpeg / libavcodec / cljr.c
blob8072eee1827968c803ffa762944d1acae4838c19
1 /*
2 * Cirrus Logic AccuPak (CLJR) codec
3 * Copyright (c) 2003 Alex Beregszaszi
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /**
22 * @file cljr.c
23 * Cirrus Logic AccuPak codec.
26 #include "avcodec.h"
27 #include "mpegvideo.h"
29 typedef struct CLJRContext{
30 AVCodecContext *avctx;
31 AVFrame picture;
32 int delta[16];
33 int offset[4];
34 GetBitContext gb;
35 } CLJRContext;
37 static int decode_frame(AVCodecContext *avctx,
38 void *data, int *data_size,
39 uint8_t *buf, int buf_size)
41 CLJRContext * const a = avctx->priv_data;
42 AVFrame *picture = data;
43 AVFrame * const p= (AVFrame*)&a->picture;
44 int x, y;
46 if(p->data[0])
47 avctx->release_buffer(avctx, p);
49 p->reference= 0;
50 if(avctx->get_buffer(avctx, p) < 0){
51 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
52 return -1;
54 p->pict_type= I_TYPE;
55 p->key_frame= 1;
57 init_get_bits(&a->gb, buf, buf_size);
59 for(y=0; y<avctx->height; y++){
60 uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ];
61 uint8_t *cb= &a->picture.data[1][ y*a->picture.linesize[1] ];
62 uint8_t *cr= &a->picture.data[2][ y*a->picture.linesize[2] ];
63 for(x=0; x<avctx->width; x+=4){
64 luma[3] = get_bits(&a->gb, 5) << 3;
65 luma[2] = get_bits(&a->gb, 5) << 3;
66 luma[1] = get_bits(&a->gb, 5) << 3;
67 luma[0] = get_bits(&a->gb, 5) << 3;
68 luma+= 4;
69 *(cb++) = get_bits(&a->gb, 6) << 2;
70 *(cr++) = get_bits(&a->gb, 6) << 2;
74 *picture= *(AVFrame*)&a->picture;
75 *data_size = sizeof(AVPicture);
77 emms_c();
79 return buf_size;
82 #if 0
83 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
84 CLJRContext * const a = avctx->priv_data;
85 AVFrame *pict = data;
86 AVFrame * const p= (AVFrame*)&a->picture;
87 int size;
88 int mb_x, mb_y;
90 *p = *pict;
91 p->pict_type= I_TYPE;
92 p->key_frame= 1;
94 emms_c();
96 align_put_bits(&a->pb);
97 while(get_bit_count(&a->pb)&31)
98 put_bits(&a->pb, 8, 0);
100 size= get_bit_count(&a->pb)/32;
102 return size*4;
104 #endif
106 static void common_init(AVCodecContext *avctx){
107 CLJRContext * const a = avctx->priv_data;
109 avctx->coded_frame= (AVFrame*)&a->picture;
110 a->avctx= avctx;
113 static int decode_init(AVCodecContext *avctx){
115 common_init(avctx);
117 avctx->pix_fmt= PIX_FMT_YUV411P;
119 return 0;
122 #if 0
123 static int encode_init(AVCodecContext *avctx){
125 common_init(avctx);
127 return 0;
129 #endif
131 AVCodec cljr_decoder = {
132 "cljr",
133 CODEC_TYPE_VIDEO,
134 CODEC_ID_CLJR,
135 sizeof(CLJRContext),
136 decode_init,
137 NULL,
138 NULL,
139 decode_frame,
140 CODEC_CAP_DR1,
142 #if 0
143 #ifdef CONFIG_ENCODERS
145 AVCodec cljr_encoder = {
146 "cljr",
147 CODEC_TYPE_VIDEO,
148 CODEC_ID_cljr,
149 sizeof(CLJRContext),
150 encode_init,
151 encode_frame,
152 //encode_end,
155 #endif //CONFIG_ENCODERS
156 #endif