]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/blob - libavcodec/cljr.c
410p -> 411p
[frescor/ffmpeg.git] / libavcodec / cljr.c
1 /*
2  * Cirrus Logic AccuPak (CLJR) codec
3  * Copyright (c) 2003 Alex Beregszaszi
4  *
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.
9  *
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.
14  *
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
18  *
19  */
20  
21 /**
22  * @file cljr.c
23  * Cirrus Logic AccuPak codec.
24  */
25  
26 #include "avcodec.h"
27 #include "mpegvideo.h"
28
29 typedef struct CLJRContext{
30     AVCodecContext *avctx;
31     AVFrame picture;
32     int delta[16];
33     int offset[4];
34     GetBitContext gb;
35 } CLJRContext;
36
37 static int decode_frame(AVCodecContext *avctx, 
38                         void *data, int *data_size,
39                         uint8_t *buf, int buf_size)
40 {
41     CLJRContext * const a = avctx->priv_data;
42     AVFrame *picture = data;
43     AVFrame * const p= (AVFrame*)&a->picture;
44     uint8_t *bytestream= buf;
45     int i, x, y;
46
47     *data_size = 0;
48
49     /* special case for last picture */
50     if (buf_size == 0) {
51         return 0;
52     }
53
54     if(p->data[0])
55         avctx->release_buffer(avctx, p);
56
57     p->reference= 0;
58     if(avctx->get_buffer(avctx, p) < 0){
59         fprintf(stderr, "get_buffer() failed\n");
60         return -1;
61     }
62     p->pict_type= I_TYPE;
63     p->key_frame= 1;
64
65     init_get_bits(&a->gb, buf, buf_size);
66
67     for(y=0; y<avctx->height; y++){
68         int offset;
69         uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ];
70         uint8_t *cb= &a->picture.data[1][ y*a->picture.linesize[1] ];
71         uint8_t *cr= &a->picture.data[2][ y*a->picture.linesize[2] ];
72         for(x=0; x<avctx->width; x+=4){
73             luma[3] = get_bits(&a->gb, 5) << 3;
74             luma[2] = get_bits(&a->gb, 5) << 3;
75             luma[1] = get_bits(&a->gb, 5) << 3;
76             luma[0] = get_bits(&a->gb, 5) << 3;
77             luma+= 4;
78             *(cb++) = get_bits(&a->gb, 6) << 2;
79             *(cr++) = get_bits(&a->gb, 6) << 2;
80         }
81     }
82
83     *picture= *(AVFrame*)&a->picture;
84     *data_size = sizeof(AVPicture);
85
86     emms_c();
87     
88     return buf_size;
89 }
90
91 #if 0
92 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
93     CLJRContext * const a = avctx->priv_data;
94     AVFrame *pict = data;
95     AVFrame * const p= (AVFrame*)&a->picture;
96     int size;
97     int mb_x, mb_y;
98
99     *p = *pict;
100     p->pict_type= I_TYPE;
101     p->key_frame= 1;
102
103     emms_c();
104     
105     align_put_bits(&a->pb);
106     while(get_bit_count(&a->pb)&31)
107         put_bits(&a->pb, 8, 0);
108     
109     size= get_bit_count(&a->pb)/32;
110     
111     return size*4;
112 }
113 #endif
114
115 static void common_init(AVCodecContext *avctx){
116     CLJRContext * const a = avctx->priv_data;
117
118     avctx->coded_frame= (AVFrame*)&a->picture;
119     a->avctx= avctx;
120 }
121
122 static int decode_init(AVCodecContext *avctx){
123     CLJRContext * const a = avctx->priv_data;
124     AVFrame *p= (AVFrame*)&a->picture;
125     int i;
126  
127     common_init(avctx);
128     
129     avctx->pix_fmt= PIX_FMT_YUV411P;
130
131     return 0;
132 }
133
134 static int encode_init(AVCodecContext *avctx){
135     CLJRContext * const a = avctx->priv_data;
136     int i;
137  
138     common_init(avctx);
139     
140     return 0;
141 }
142
143 static int decode_end(AVCodecContext *avctx){
144     CLJRContext * const a = avctx->priv_data;
145
146     avcodec_default_free_buffers(avctx);
147
148     return 0;
149 }
150
151 AVCodec cljr_decoder = {
152     "cljr",
153     CODEC_TYPE_VIDEO,
154     CODEC_ID_CLJR,
155     sizeof(CLJRContext),
156     decode_init,
157     NULL,
158     decode_end,
159     decode_frame,
160     CODEC_CAP_DR1,
161 };
162 #if 0
163 #ifdef CONFIG_ENCODERS
164
165 AVCodec cljr_encoder = {
166     "cljr",
167     CODEC_TYPE_VIDEO,
168     CODEC_ID_cljr,
169     sizeof(CLJRContext),
170     encode_init,
171     encode_frame,
172     //encode_end,
173 };
174
175 #endif //CONFIG_ENCODERS
176 #endif