Mercurial > libavcodec.hg
annotate vcr1.c @ 2359:a3c029107a88 libavcodec
fixing rv20201002
author | michael |
---|---|
date | Fri, 19 Nov 2004 18:19:36 +0000 |
parents | 141a9539e270 |
children | f67b63ed036d |
rev | line source |
---|---|
1374 | 1 /* |
2 * ATI VCR1 codec | |
3 * Copyright (c) 2003 Michael Niedermayer | |
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 * @file vcr1.c | |
22 * ati vcr1 codec. | |
23 */ | |
24 | |
25 #include "avcodec.h" | |
26 #include "mpegvideo.h" | |
27 | |
28 //#undef NDEBUG | |
29 //#include <assert.h> | |
30 | |
31 typedef struct VCR1Context{ | |
32 AVCodecContext *avctx; | |
33 AVFrame picture; | |
34 int delta[16]; | |
35 int offset[4]; | |
36 } VCR1Context; | |
37 | |
38 static int decode_frame(AVCodecContext *avctx, | |
39 void *data, int *data_size, | |
40 uint8_t *buf, int buf_size) | |
41 { | |
42 VCR1Context * const a = avctx->priv_data; | |
43 AVFrame *picture = data; | |
44 AVFrame * const p= (AVFrame*)&a->picture; | |
45 uint8_t *bytestream= buf; | |
46 int i, x, y; | |
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:
1419
diff
changeset
|
58 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
1374 | 59 return -1; |
60 } | |
61 p->pict_type= I_TYPE; | |
62 p->key_frame= 1; | |
63 | |
64 for(i=0; i<16; i++){ | |
65 a->delta[i]= *(bytestream++); | |
66 bytestream++; | |
67 } | |
68 | |
69 for(y=0; y<avctx->height; y++){ | |
70 int offset; | |
71 uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ]; | |
72 | |
73 if((y&3) == 0){ | |
74 uint8_t *cb= &a->picture.data[1][ (y>>2)*a->picture.linesize[1] ]; | |
75 uint8_t *cr= &a->picture.data[2][ (y>>2)*a->picture.linesize[2] ]; | |
76 | |
77 for(i=0; i<4; i++) | |
78 a->offset[i]= *(bytestream++); | |
79 | |
1375 | 80 offset= a->offset[0] - a->delta[ bytestream[2]&0xF ]; |
1374 | 81 for(x=0; x<avctx->width; x+=4){ |
82 luma[0]=( offset += a->delta[ bytestream[2]&0xF ]); | |
83 luma[1]=( offset += a->delta[ bytestream[2]>>4 ]); | |
84 luma[2]=( offset += a->delta[ bytestream[0]&0xF ]); | |
85 luma[3]=( offset += a->delta[ bytestream[0]>>4 ]); | |
86 luma += 4; | |
87 | |
1375 | 88 *(cb++) = bytestream[3]; |
89 *(cr++) = bytestream[1]; | |
1374 | 90 |
91 bytestream+= 4; | |
92 } | |
93 }else{ | |
1375 | 94 offset= a->offset[y&3] - a->delta[ bytestream[2]&0xF ]; |
1374 | 95 |
96 for(x=0; x<avctx->width; x+=8){ | |
97 luma[0]=( offset += a->delta[ bytestream[2]&0xF ]); | |
98 luma[1]=( offset += a->delta[ bytestream[2]>>4 ]); | |
99 luma[2]=( offset += a->delta[ bytestream[3]&0xF ]); | |
100 luma[3]=( offset += a->delta[ bytestream[3]>>4 ]); | |
101 luma[4]=( offset += a->delta[ bytestream[0]&0xF ]); | |
102 luma[5]=( offset += a->delta[ bytestream[0]>>4 ]); | |
103 luma[6]=( offset += a->delta[ bytestream[1]&0xF ]); | |
104 luma[7]=( offset += a->delta[ bytestream[1]>>4 ]); | |
105 luma += 8; | |
106 bytestream+= 4; | |
107 } | |
108 } | |
109 } | |
110 | |
111 *picture= *(AVFrame*)&a->picture; | |
112 *data_size = sizeof(AVPicture); | |
113 | |
114 emms_c(); | |
115 | |
116 return buf_size; | |
117 } | |
118 | |
119 #if 0 | |
120 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ | |
121 VCR1Context * const a = avctx->priv_data; | |
122 AVFrame *pict = data; | |
123 AVFrame * const p= (AVFrame*)&a->picture; | |
124 int size; | |
125 int mb_x, mb_y; | |
126 | |
127 *p = *pict; | |
128 p->pict_type= I_TYPE; | |
129 p->key_frame= 1; | |
130 | |
131 emms_c(); | |
132 | |
133 align_put_bits(&a->pb); | |
134 while(get_bit_count(&a->pb)&31) | |
135 put_bits(&a->pb, 8, 0); | |
136 | |
137 size= get_bit_count(&a->pb)/32; | |
138 | |
139 return size*4; | |
140 } | |
141 #endif | |
142 | |
143 static void common_init(AVCodecContext *avctx){ | |
144 VCR1Context * const a = avctx->priv_data; | |
145 | |
146 avctx->coded_frame= (AVFrame*)&a->picture; | |
147 a->avctx= avctx; | |
148 } | |
149 | |
150 static int decode_init(AVCodecContext *avctx){ | |
151 | |
152 common_init(avctx); | |
153 | |
154 avctx->pix_fmt= PIX_FMT_YUV410P; | |
155 | |
156 return 0; | |
157 } | |
158 | |
159 static int encode_init(AVCodecContext *avctx){ | |
160 | |
161 common_init(avctx); | |
162 | |
163 return 0; | |
164 } | |
165 | |
166 AVCodec vcr1_decoder = { | |
167 "vcr1", | |
168 CODEC_TYPE_VIDEO, | |
169 CODEC_ID_VCR1, | |
170 sizeof(VCR1Context), | |
171 decode_init, | |
172 NULL, | |
1994 | 173 NULL, |
1374 | 174 decode_frame, |
175 CODEC_CAP_DR1, | |
176 }; | |
177 #if 0 | |
178 #ifdef CONFIG_ENCODERS | |
179 | |
180 AVCodec vcr1_encoder = { | |
181 "vcr1", | |
182 CODEC_TYPE_VIDEO, | |
183 CODEC_ID_VCR1, | |
184 sizeof(VCR1Context), | |
185 encode_init, | |
186 encode_frame, | |
187 //encode_end, | |
188 }; | |
189 | |
190 #endif //CONFIG_ENCODERS | |
191 #endif |