Mercurial > libavcodec.hg
annotate cljr.c @ 2019:93edc9073ffc libavcodec
segfault fix
author | michael |
---|---|
date | Wed, 12 May 2004 02:50:48 +0000 |
parents | 8d3540dddd1b |
children | 141a9539e270 |
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 AVCodec cljr_decoder = { | |
137 "cljr", | |
138 CODEC_TYPE_VIDEO, | |
139 CODEC_ID_CLJR, | |
140 sizeof(CLJRContext), | |
141 decode_init, | |
142 NULL, | |
1994 | 143 NULL, |
1385 | 144 decode_frame, |
145 CODEC_CAP_DR1, | |
146 }; | |
147 #if 0 | |
148 #ifdef CONFIG_ENCODERS | |
149 | |
150 AVCodec cljr_encoder = { | |
151 "cljr", | |
152 CODEC_TYPE_VIDEO, | |
153 CODEC_ID_cljr, | |
154 sizeof(CLJRContext), | |
155 encode_init, | |
156 encode_frame, | |
157 //encode_end, | |
158 }; | |
159 | |
160 #endif //CONFIG_ENCODERS | |
161 #endif |