comparison bmp.c @ 10257:af449680f6ee libavcodec

Take into account real number of colours when reading BMP palette. This fixes issue 1408
author kostya
date Thu, 24 Sep 2009 05:24:46 +0000
parents 6e4c341027f2
children 3b0a2384ff9f
comparison
equal deleted inserted replaced
10256:541055a030f3 10257:af449680f6ee
229 ptr = p->data[0]; 229 ptr = p->data[0];
230 linesize = p->linesize[0]; 230 linesize = p->linesize[0];
231 } 231 }
232 232
233 if(avctx->pix_fmt == PIX_FMT_PAL8){ 233 if(avctx->pix_fmt == PIX_FMT_PAL8){
234 int colors = 1 << depth;
235 if(ihsize >= 36){
236 int t;
237 buf = buf0 + 46;
238 t = bytestream_get_le32(&buf);
239 if(t < 0 || t > (1 << depth)){
240 av_log(avctx, AV_LOG_ERROR, "Incorrect number of colors - %X for bitdepth %d\n", t, depth);
241 }else if(t){
242 colors = t;
243 }
244 }
234 buf = buf0 + 14 + ihsize; //palette location 245 buf = buf0 + 14 + ihsize; //palette location
235 if((hsize-ihsize-14)>>depth < 4){ // OS/2 bitmap, 3 bytes per palette entry 246 if((hsize-ihsize-14) < (colors << 2)){ // OS/2 bitmap, 3 bytes per palette entry
236 for(i = 0; i < (1 << depth); i++) 247 for(i = 0; i < colors; i++)
237 ((uint32_t*)p->data[1])[i] = bytestream_get_le24(&buf); 248 ((uint32_t*)p->data[1])[i] = bytestream_get_le24(&buf);
238 }else{ 249 }else{
239 for(i = 0; i < (1 << depth); i++) 250 for(i = 0; i < colors; i++)
240 ((uint32_t*)p->data[1])[i] = bytestream_get_le32(&buf); 251 ((uint32_t*)p->data[1])[i] = bytestream_get_le32(&buf);
241 } 252 }
242 buf = buf0 + hsize; 253 buf = buf0 + hsize;
243 } 254 }
244 if(comp == BMP_RLE4 || comp == BMP_RLE8){ 255 if(comp == BMP_RLE4 || comp == BMP_RLE8){