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
23 * Cirrus Logic AccuPak codec.
27 #include "mpegvideo.h"
29 typedef struct CLJRContext{
30 AVCodecContext *avctx;
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 uint8_t *bytestream= buf;
49 /* special case for last picture */
55 avctx->release_buffer(avctx, p);
58 if(avctx->get_buffer(avctx, p) < 0){
59 fprintf(stderr, "get_buffer() failed\n");
65 init_get_bits(&a->gb, buf, buf_size);
67 for(y=0; y<avctx->height; y++){
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;
78 *(cb++) = get_bits(&a->gb, 6) << 2;
79 *(cr++) = get_bits(&a->gb, 6) << 2;
83 *picture= *(AVFrame*)&a->picture;
84 *data_size = sizeof(AVPicture);
92 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
93 CLJRContext * const a = avctx->priv_data;
95 AVFrame * const p= (AVFrame*)&a->picture;
100 p->pict_type= I_TYPE;
105 align_put_bits(&a->pb);
106 while(get_bit_count(&a->pb)&31)
107 put_bits(&a->pb, 8, 0);
109 size= get_bit_count(&a->pb)/32;
115 static void common_init(AVCodecContext *avctx){
116 CLJRContext * const a = avctx->priv_data;
118 avctx->coded_frame= (AVFrame*)&a->picture;
122 static int decode_init(AVCodecContext *avctx){
123 CLJRContext * const a = avctx->priv_data;
124 AVFrame *p= (AVFrame*)&a->picture;
129 avctx->pix_fmt= PIX_FMT_YUV411P;
134 static int encode_init(AVCodecContext *avctx){
135 CLJRContext * const a = avctx->priv_data;
143 static int decode_end(AVCodecContext *avctx){
144 CLJRContext * const a = avctx->priv_data;
146 avcodec_default_free_buffers(avctx);
151 AVCodec cljr_decoder = {
163 #ifdef CONFIG_ENCODERS
165 AVCodec cljr_encoder = {
175 #endif //CONFIG_ENCODERS