Mercurial > libavcodec.hg
comparison cljr.c @ 1385:a16990d50fce libavcodec
CLJR decoding support
author | al3x |
---|---|
date | Sun, 27 Jul 2003 20:20:31 +0000 |
parents | |
children | 5cabff29411e |
comparison
equal
deleted
inserted
replaced
1384:18cdce49339e | 1385:a16990d50fce |
---|---|
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>>2)*a->picture.linesize[1] ]; | |
71 uint8_t *cr= &a->picture.data[2][ (y>>2)*a->picture.linesize[2] ]; | |
72 | |
73 for(x=0; x<avctx->width; x+=4){ | |
74 luma[3] = get_bits(&a->gb, 5) << 3; | |
75 luma[2] = get_bits(&a->gb, 5) << 3; | |
76 luma[1] = get_bits(&a->gb, 5) << 3; | |
77 luma[0] = get_bits(&a->gb, 5) << 3; | |
78 luma+= 4; | |
79 *(cb++) = get_bits(&a->gb, 6) << 2; | |
80 *(cr++) = get_bits(&a->gb, 6) << 2; | |
81 } | |
82 } | |
83 | |
84 *picture= *(AVFrame*)&a->picture; | |
85 *data_size = sizeof(AVPicture); | |
86 | |
87 emms_c(); | |
88 | |
89 return buf_size; | |
90 } | |
91 | |
92 #if 0 | |
93 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ | |
94 CLJRContext * const a = avctx->priv_data; | |
95 AVFrame *pict = data; | |
96 AVFrame * const p= (AVFrame*)&a->picture; | |
97 int size; | |
98 int mb_x, mb_y; | |
99 | |
100 *p = *pict; | |
101 p->pict_type= I_TYPE; | |
102 p->key_frame= 1; | |
103 | |
104 emms_c(); | |
105 | |
106 align_put_bits(&a->pb); | |
107 while(get_bit_count(&a->pb)&31) | |
108 put_bits(&a->pb, 8, 0); | |
109 | |
110 size= get_bit_count(&a->pb)/32; | |
111 | |
112 return size*4; | |
113 } | |
114 #endif | |
115 | |
116 static void common_init(AVCodecContext *avctx){ | |
117 CLJRContext * const a = avctx->priv_data; | |
118 | |
119 avctx->coded_frame= (AVFrame*)&a->picture; | |
120 a->avctx= avctx; | |
121 } | |
122 | |
123 static int decode_init(AVCodecContext *avctx){ | |
124 CLJRContext * const a = avctx->priv_data; | |
125 AVFrame *p= (AVFrame*)&a->picture; | |
126 int i; | |
127 | |
128 common_init(avctx); | |
129 | |
130 avctx->pix_fmt= PIX_FMT_YUV410P; | |
131 | |
132 return 0; | |
133 } | |
134 | |
135 static int encode_init(AVCodecContext *avctx){ | |
136 CLJRContext * const a = avctx->priv_data; | |
137 int i; | |
138 | |
139 common_init(avctx); | |
140 | |
141 return 0; | |
142 } | |
143 | |
144 static int decode_end(AVCodecContext *avctx){ | |
145 CLJRContext * const a = avctx->priv_data; | |
146 | |
147 avcodec_default_free_buffers(avctx); | |
148 | |
149 return 0; | |
150 } | |
151 | |
152 AVCodec cljr_decoder = { | |
153 "cljr", | |
154 CODEC_TYPE_VIDEO, | |
155 CODEC_ID_CLJR, | |
156 sizeof(CLJRContext), | |
157 decode_init, | |
158 NULL, | |
159 decode_end, | |
160 decode_frame, | |
161 CODEC_CAP_DR1, | |
162 }; | |
163 #if 0 | |
164 #ifdef CONFIG_ENCODERS | |
165 | |
166 AVCodec cljr_encoder = { | |
167 "cljr", | |
168 CODEC_TYPE_VIDEO, | |
169 CODEC_ID_cljr, | |
170 sizeof(CLJRContext), | |
171 encode_init, | |
172 encode_frame, | |
173 //encode_end, | |
174 }; | |
175 | |
176 #endif //CONFIG_ENCODERS | |
177 #endif |