Mercurial > libavcodec.hg
annotate vcr1.c @ 2515:0a68e8dd1c3b libavcodec
10l
author | alex |
---|---|
date | Mon, 21 Feb 2005 17:52:23 +0000 |
parents | f67b63ed036d |
children | e25782262d7d |
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 if(p->data[0]) | |
49 avctx->release_buffer(avctx, p); | |
50 | |
51 p->reference= 0; | |
52 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
|
53 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
1374 | 54 return -1; |
55 } | |
56 p->pict_type= I_TYPE; | |
57 p->key_frame= 1; | |
58 | |
59 for(i=0; i<16; i++){ | |
60 a->delta[i]= *(bytestream++); | |
61 bytestream++; | |
62 } | |
63 | |
64 for(y=0; y<avctx->height; y++){ | |
65 int offset; | |
66 uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ]; | |
67 | |
68 if((y&3) == 0){ | |
69 uint8_t *cb= &a->picture.data[1][ (y>>2)*a->picture.linesize[1] ]; | |
70 uint8_t *cr= &a->picture.data[2][ (y>>2)*a->picture.linesize[2] ]; | |
71 | |
72 for(i=0; i<4; i++) | |
73 a->offset[i]= *(bytestream++); | |
74 | |
1375 | 75 offset= a->offset[0] - a->delta[ bytestream[2]&0xF ]; |
1374 | 76 for(x=0; x<avctx->width; x+=4){ |
77 luma[0]=( offset += a->delta[ bytestream[2]&0xF ]); | |
78 luma[1]=( offset += a->delta[ bytestream[2]>>4 ]); | |
79 luma[2]=( offset += a->delta[ bytestream[0]&0xF ]); | |
80 luma[3]=( offset += a->delta[ bytestream[0]>>4 ]); | |
81 luma += 4; | |
82 | |
1375 | 83 *(cb++) = bytestream[3]; |
84 *(cr++) = bytestream[1]; | |
1374 | 85 |
86 bytestream+= 4; | |
87 } | |
88 }else{ | |
1375 | 89 offset= a->offset[y&3] - a->delta[ bytestream[2]&0xF ]; |
1374 | 90 |
91 for(x=0; x<avctx->width; x+=8){ | |
92 luma[0]=( offset += a->delta[ bytestream[2]&0xF ]); | |
93 luma[1]=( offset += a->delta[ bytestream[2]>>4 ]); | |
94 luma[2]=( offset += a->delta[ bytestream[3]&0xF ]); | |
95 luma[3]=( offset += a->delta[ bytestream[3]>>4 ]); | |
96 luma[4]=( offset += a->delta[ bytestream[0]&0xF ]); | |
97 luma[5]=( offset += a->delta[ bytestream[0]>>4 ]); | |
98 luma[6]=( offset += a->delta[ bytestream[1]&0xF ]); | |
99 luma[7]=( offset += a->delta[ bytestream[1]>>4 ]); | |
100 luma += 8; | |
101 bytestream+= 4; | |
102 } | |
103 } | |
104 } | |
105 | |
106 *picture= *(AVFrame*)&a->picture; | |
107 *data_size = sizeof(AVPicture); | |
108 | |
109 emms_c(); | |
110 | |
111 return buf_size; | |
112 } | |
113 | |
114 #if 0 | |
115 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ | |
116 VCR1Context * const a = avctx->priv_data; | |
117 AVFrame *pict = data; | |
118 AVFrame * const p= (AVFrame*)&a->picture; | |
119 int size; | |
120 int mb_x, mb_y; | |
121 | |
122 *p = *pict; | |
123 p->pict_type= I_TYPE; | |
124 p->key_frame= 1; | |
125 | |
126 emms_c(); | |
127 | |
128 align_put_bits(&a->pb); | |
129 while(get_bit_count(&a->pb)&31) | |
130 put_bits(&a->pb, 8, 0); | |
131 | |
132 size= get_bit_count(&a->pb)/32; | |
133 | |
134 return size*4; | |
135 } | |
136 #endif | |
137 | |
138 static void common_init(AVCodecContext *avctx){ | |
139 VCR1Context * const a = avctx->priv_data; | |
140 | |
141 avctx->coded_frame= (AVFrame*)&a->picture; | |
142 a->avctx= avctx; | |
143 } | |
144 | |
145 static int decode_init(AVCodecContext *avctx){ | |
146 | |
147 common_init(avctx); | |
148 | |
149 avctx->pix_fmt= PIX_FMT_YUV410P; | |
150 | |
151 return 0; | |
152 } | |
153 | |
154 static int encode_init(AVCodecContext *avctx){ | |
155 | |
156 common_init(avctx); | |
157 | |
158 return 0; | |
159 } | |
160 | |
161 AVCodec vcr1_decoder = { | |
162 "vcr1", | |
163 CODEC_TYPE_VIDEO, | |
164 CODEC_ID_VCR1, | |
165 sizeof(VCR1Context), | |
166 decode_init, | |
167 NULL, | |
1994 | 168 NULL, |
1374 | 169 decode_frame, |
170 CODEC_CAP_DR1, | |
171 }; | |
172 #if 0 | |
173 #ifdef CONFIG_ENCODERS | |
174 | |
175 AVCodec vcr1_encoder = { | |
176 "vcr1", | |
177 CODEC_TYPE_VIDEO, | |
178 CODEC_ID_VCR1, | |
179 sizeof(VCR1Context), | |
180 encode_init, | |
181 encode_frame, | |
182 //encode_end, | |
183 }; | |
184 | |
185 #endif //CONFIG_ENCODERS | |
186 #endif |