MCPcopy Create free account
hub / github.com/TheCherno/Sparky / LoadWindowsBMP

Function LoadWindowsBMP

Dependencies/FreeImage/Source/FreeImage/PluginBMP.cpp:457–669  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

455// --------------------------------------------------------------------------
456
457static FIBITMAP *
458LoadWindowsBMP(FreeImageIO *io, fi_handle handle, int flags, unsigned bitmap_bits_offset, int type) {
459 FIBITMAP *dib = NULL;
460
461 try {
462 BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
463
464 // load the info header
465
466 BITMAPINFOHEADER bih;
467
468 io->read_proc(&bih, sizeof(BITMAPINFOHEADER), 1, handle);
469#ifdef FREEIMAGE_BIGENDIAN
470 SwapInfoHeader(&bih);
471#endif
472
473 // keep some general information about the bitmap
474
475 unsigned used_colors = bih.biClrUsed;
476 int width = bih.biWidth;
477 int height = bih.biHeight; // WARNING: height can be < 0 => check each call using 'height' as a parameter
478 unsigned bit_count = bih.biBitCount;
479 unsigned compression = bih.biCompression;
480 unsigned pitch = CalculatePitch(CalculateLine(width, bit_count));
481
482 switch (bit_count) {
483 case 1 :
484 case 4 :
485 case 8 :
486 {
487 if ((used_colors == 0) || (used_colors > CalculateUsedPaletteEntries(bit_count))) {
488 used_colors = CalculateUsedPaletteEntries(bit_count);
489 }
490
491 // allocate enough memory to hold the bitmap (header, palette, pixels) and read the palette
492
493 dib = FreeImage_AllocateHeader(header_only, width, height, bit_count);
494 if (dib == NULL) {
495 throw FI_MSG_ERROR_DIB_MEMORY;
496 }
497
498 // set resolution information
499 FreeImage_SetDotsPerMeterX(dib, bih.biXPelsPerMeter);
500 FreeImage_SetDotsPerMeterY(dib, bih.biYPelsPerMeter);
501
502 // seek to the end of the header (depending on the BMP header version)
503 // type == sizeof(BITMAPVxINFOHEADER)
504 switch(type) {
505 case 40: // sizeof(BITMAPINFOHEADER) - all Windows versions since Windows 3.0
506 break;
507 case 52: // sizeof(BITMAPV2INFOHEADER) (undocumented)
508 case 56: // sizeof(BITMAPV3INFOHEADER) (undocumented)
509 case 108: // sizeof(BITMAPV4HEADER) - all Windows versions since Windows 95/NT4 (not supported)
510 case 124: // sizeof(BITMAPV5HEADER) - Windows 98/2000 and newer (not supported)
511 io->seek_proc(handle, (long)(type - sizeof(BITMAPINFOHEADER)), SEEK_CUR);
512 break;
513 }
514

Callers 1

DLL_CALLCONV LoadFunction · 0.85

Calls 8

LoadPixelDataFunction · 0.85
LoadPixelDataRLE4Function · 0.85
LoadPixelDataRLE8Function · 0.85
SwapInfoHeaderFunction · 0.70
CalculatePitchFunction · 0.50
CalculateLineFunction · 0.50
INPLACESWAPFunction · 0.50

Tested by

no test coverage detected