Reads bitmap metadata from fp into info. Returns 0 on EOF or invalid info, * or nonzero on success. info is assumed to be initialized to 0 already. */
| 273 | * or nonzero on success. info is assumed to be initialized to 0 already. |
| 274 | */ |
| 275 | static int ReadInfo(bmp_info * info, FILE * fp) |
| 276 | { |
| 277 | if(!ReadLittleUint32(&info->info_size, fp)) return 0; |
| 278 | |
| 279 | /* Older formats might not have all the fields we require, so this check |
| 280 | * comes first. |
| 281 | */ |
| 282 | if(info->info_size < MIN_INFO_SIZE) return 0; |
| 283 | |
| 284 | if(!ReadLittleInt32( &info->width, fp)) return 0; |
| 285 | if(!ReadLittleInt32( &info->height, fp)) return 0; |
| 286 | if(!ReadLittleUint16(&info->planes, fp)) return 0; |
| 287 | if(!ReadLittleUint16(&info->bits, fp)) return 0; |
| 288 | if(!ReadLittleUint32(&info->compression, fp)) return 0; |
| 289 | if(!ReadLittleUint32(&info->unused0[0], fp)) return 0; |
| 290 | if(!ReadLittleUint32(&info->unused0[1], fp)) return 0; |
| 291 | if(!ReadLittleUint32(&info->unused0[2], fp)) return 0; |
| 292 | if(!ReadLittleUint32(&info->colors, fp)) return 0; |
| 293 | if(!ReadLittleUint32(&info->unused1, fp)) return 0; |
| 294 | |
| 295 | /* We don't bother to even try to read bitmasks if they aren't needed, |
| 296 | * since they won't be present in Windows 3 format bitmap files. |
| 297 | */ |
| 298 | if(info->compression == COMPRESSION_BITFIELDS) |
| 299 | { |
| 300 | /* Reject Windows NT format files with bitfields, since we don't |
| 301 | * support them, and their masks aren't part of the info header anyway. |
| 302 | */ |
| 303 | if(info->info_size == BMP3_INFO_SIZE) return 0; |
| 304 | |
| 305 | if(!ReadLittleUint32(&info->masks[0], fp)) return 0; |
| 306 | if(!ReadLittleUint32(&info->masks[1], fp)) return 0; |
| 307 | if(!ReadLittleUint32(&info->masks[2], fp)) return 0; |
| 308 | if(!ReadLittleUint32(&info->masks[3], fp)) return 0; |
| 309 | } |
| 310 | |
| 311 | return 1; |
| 312 | } |
| 313 | |
| 314 | /* Bitfields for 16- and 32-bit files. We track the first set bit (rightmost |
| 315 | * being 0) and how many bits it spans. |
no test coverage detected