Mercurial > libavcodec.hg
comparison bmp.c @ 7909:9fd3f57e4c16 libavcodec
Add support for 1-bit, 4-bit, 8-bit and some 16-bit raw BMP
author | kostya |
---|---|
date | Tue, 23 Sep 2008 08:38:32 +0000 |
parents | dc825905f93f |
children | 87bbd8322244 |
comparison
equal
deleted
inserted
replaced
7908:dc825905f93f | 7909:9fd3f57e4c16 |
---|---|
147 avctx->pix_fmt = PIX_FMT_BGR24; | 147 avctx->pix_fmt = PIX_FMT_BGR24; |
148 break; | 148 break; |
149 case 16: | 149 case 16: |
150 if(comp == BMP_RGB) | 150 if(comp == BMP_RGB) |
151 avctx->pix_fmt = PIX_FMT_RGB555; | 151 avctx->pix_fmt = PIX_FMT_RGB555; |
152 if(comp == BMP_BITFIELDS) | |
153 avctx->pix_fmt = rgb[1] == 0x07E0 ? PIX_FMT_RGB565 : PIX_FMT_RGB555; | |
154 break; | |
155 case 8: | |
156 if(hsize - ihsize - 14 > 0) | |
157 avctx->pix_fmt = PIX_FMT_PAL8; | |
158 else | |
159 avctx->pix_fmt = PIX_FMT_GRAY8; | |
160 break; | |
161 case 4: | |
162 if(hsize - ihsize - 14 > 0){ | |
163 avctx->pix_fmt = PIX_FMT_PAL8; | |
164 }else{ | |
165 av_log(avctx, AV_LOG_ERROR, "Unknown palette for 16-colour BMP\n"); | |
166 return -1; | |
167 } | |
168 break; | |
169 case 1: | |
170 avctx->pix_fmt = PIX_FMT_MONOBLACK; | |
152 break; | 171 break; |
153 default: | 172 default: |
154 av_log(avctx, AV_LOG_ERROR, "depth %d not supported\n", depth); | 173 av_log(avctx, AV_LOG_ERROR, "depth %d not supported\n", depth); |
155 return -1; | 174 return -1; |
156 } | 175 } |
180 if(n * avctx->height > dsize){ | 199 if(n * avctx->height > dsize){ |
181 av_log(avctx, AV_LOG_ERROR, "not enough data (%d < %d)\n", | 200 av_log(avctx, AV_LOG_ERROR, "not enough data (%d < %d)\n", |
182 dsize, n * avctx->height); | 201 dsize, n * avctx->height); |
183 return -1; | 202 return -1; |
184 } | 203 } |
204 | |
205 if(depth == 4 || depth == 8) | |
206 memset(p->data[1], 0, 1024); | |
185 | 207 |
186 if(height > 0){ | 208 if(height > 0){ |
187 ptr = p->data[0] + (avctx->height - 1) * p->linesize[0]; | 209 ptr = p->data[0] + (avctx->height - 1) * p->linesize[0]; |
188 linesize = -p->linesize[0]; | 210 linesize = -p->linesize[0]; |
189 } else { | 211 } else { |
190 ptr = p->data[0]; | 212 ptr = p->data[0]; |
191 linesize = p->linesize[0]; | 213 linesize = p->linesize[0]; |
192 } | 214 } |
193 | 215 |
216 if(avctx->pix_fmt == PIX_FMT_PAL8){ | |
217 buf = buf0 + 14 + ihsize; //palette location | |
218 if((hsize-ihsize-14)>>depth < 4){ // OS/2 bitmap, 3 bytes per palette entry | |
219 for(i = 0; i < (1 << depth); i++) | |
220 ((uint32_t*)p->data[1])[i] = bytestream_get_le24(&buf); | |
221 }else{ | |
222 for(i = 0; i < (1 << depth); i++) | |
223 ((uint32_t*)p->data[1])[i] = bytestream_get_le32(&buf); | |
224 } | |
225 buf = buf0 + hsize; | |
226 } | |
194 switch(depth){ | 227 switch(depth){ |
228 case 1: | |
229 for(i = 0; i < avctx->height; i++){ | |
230 memcpy(ptr, buf, n); | |
231 buf += n; | |
232 ptr += linesize; | |
233 } | |
234 break; | |
235 case 4: | |
236 for(i = 0; i < avctx->height; i++){ | |
237 int j; | |
238 for(j = 0; j < n; j++){ | |
239 ptr[j*2+0] = (buf[j] >> 4) & 0xF; | |
240 ptr[j*2+1] = buf[j] & 0xF; | |
241 } | |
242 buf += n; | |
243 ptr += linesize; | |
244 } | |
245 break; | |
246 case 8: | |
247 for(i = 0; i < avctx->height; i++){ | |
248 memcpy(ptr, buf, avctx->width); | |
249 buf += n; | |
250 ptr += linesize; | |
251 } | |
252 break; | |
195 case 24: | 253 case 24: |
196 for(i = 0; i < avctx->height; i++){ | 254 for(i = 0; i < avctx->height; i++){ |
197 memcpy(ptr, buf, avctx->width*(depth>>3)); | 255 memcpy(ptr, buf, avctx->width*(depth>>3)); |
198 buf += n; | 256 buf += n; |
199 ptr += linesize; | 257 ptr += linesize; |