Mercurial > libavcodec.hg
annotate cljr.c @ 1884:de6a0d995ca7 libavcodec
width,height%16!=0 fix
author | michael |
---|---|
date | Sun, 14 Mar 2004 17:33:48 +0000 |
parents | 932d306bf1dc |
children | 8d3540dddd1b |
rev | line source |
---|---|
1385 | 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; | |
1415 | 44 int x, y; |
1385 | 45 |
46 *data_size = 0; | |
47 | |
48 /* special case for last picture */ | |
49 if (buf_size == 0) { | |
50 return 0; | |
51 } | |
52 | |
53 if(p->data[0]) | |
54 avctx->release_buffer(avctx, p); | |
55 | |
56 p->reference= 0; | |
57 if(avctx->get_buffer(avctx, p) < 0){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1415
diff
changeset
|
58 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
1385 | 59 return -1; |
60 } | |
61 p->pict_type= I_TYPE; | |
62 p->key_frame= 1; | |
63 | |
64 init_get_bits(&a->gb, buf, buf_size); | |
65 | |
66 for(y=0; y<avctx->height; y++){ | |
67 uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ]; | |
1386 | 68 uint8_t *cb= &a->picture.data[1][ y*a->picture.linesize[1] ]; |
69 uint8_t *cr= &a->picture.data[2][ y*a->picture.linesize[2] ]; | |
1385 | 70 for(x=0; x<avctx->width; x+=4){ |
71 luma[3] = get_bits(&a->gb, 5) << 3; | |
72 luma[2] = get_bits(&a->gb, 5) << 3; | |
73 luma[1] = get_bits(&a->gb, 5) << 3; | |
74 luma[0] = get_bits(&a->gb, 5) << 3; | |
75 luma+= 4; | |
76 *(cb++) = get_bits(&a->gb, 6) << 2; | |
77 *(cr++) = get_bits(&a->gb, 6) << 2; | |
78 } | |
79 } | |
80 | |
81 *picture= *(AVFrame*)&a->picture; | |
82 *data_size = sizeof(AVPicture); | |
83 | |
84 emms_c(); | |
85 | |
86 return buf_size; | |
87 } | |
88 | |
89 #if 0 | |
90 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ | |
91 CLJRContext * const a = avctx->priv_data; | |
92 AVFrame *pict = data; | |
93 AVFrame * const p= (AVFrame*)&a->picture; | |
94 int size; | |
95 int mb_x, mb_y; | |
96 | |
97 *p = *pict; | |
98 p->pict_type= I_TYPE; | |
99 p->key_frame= 1; | |
100 | |
101 emms_c(); | |
102 | |
103 align_put_bits(&a->pb); | |
104 while(get_bit_count(&a->pb)&31) | |
105 put_bits(&a->pb, 8, 0); | |
106 | |
107 size= get_bit_count(&a->pb)/32; | |
108 | |
109 return size*4; | |
110 } | |
111 #endif | |
112 | |
113 static void common_init(AVCodecContext *avctx){ | |
114 CLJRContext * const a = avctx->priv_data; | |
115 | |
116 avctx->coded_frame= (AVFrame*)&a->picture; | |
117 a->avctx= avctx; | |
118 } | |
119 | |
120 static int decode_init(AVCodecContext *avctx){ | |
1415 | 121 |
1385 | 122 common_init(avctx); |
123 | |
1386 | 124 avctx->pix_fmt= PIX_FMT_YUV411P; |
1385 | 125 |
126 return 0; | |
127 } | |
128 | |
129 static int encode_init(AVCodecContext *avctx){ | |
1415 | 130 |
1385 | 131 common_init(avctx); |
132 | |
133 return 0; | |
134 } | |
135 | |
136 static int decode_end(AVCodecContext *avctx){ | |
137 | |
138 avcodec_default_free_buffers(avctx); | |
139 | |
140 return 0; | |
141 } | |
142 | |
143 AVCodec cljr_decoder = { | |
144 "cljr", | |
145 CODEC_TYPE_VIDEO, | |
146 CODEC_ID_CLJR, | |
147 sizeof(CLJRContext), | |
148 decode_init, | |
149 NULL, | |
150 decode_end, | |
151 decode_frame, | |
152 CODEC_CAP_DR1, | |
153 }; | |
154 #if 0 | |
155 #ifdef CONFIG_ENCODERS | |
156 | |
157 AVCodec cljr_encoder = { | |
158 "cljr", | |
159 CODEC_TYPE_VIDEO, | |
160 CODEC_ID_cljr, | |
161 sizeof(CLJRContext), | |
162 encode_init, | |
163 encode_frame, | |
164 //encode_end, | |
165 }; | |
166 | |
167 #endif //CONFIG_ENCODERS | |
168 #endif |