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

Function LoadOS22XBMP

Dependencies/FreeImage/Source/FreeImage/PluginBMP.cpp:673–872  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

671// --------------------------------------------------------------------------
672
673static FIBITMAP *
674LoadOS22XBMP(FreeImageIO *io, fi_handle handle, int flags, unsigned bitmap_bits_offset) {
675 FIBITMAP *dib = NULL;
676
677 try {
678 BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS;
679
680 // load the info header
681
682 BITMAPINFOHEADER bih;
683
684 io->read_proc(&bih, sizeof(BITMAPINFOHEADER), 1, handle);
685#ifdef FREEIMAGE_BIGENDIAN
686 SwapInfoHeader(&bih);
687#endif
688
689 // keep some general information about the bitmap
690
691 unsigned used_colors = bih.biClrUsed;
692 int width = bih.biWidth;
693 int height = bih.biHeight; // WARNING: height can be < 0 => check each read_proc using 'height' as a parameter
694 unsigned bit_count = bih.biBitCount;
695 unsigned compression = bih.biCompression;
696 unsigned pitch = CalculatePitch(CalculateLine(width, bit_count));
697
698 switch (bit_count) {
699 case 1 :
700 case 4 :
701 case 8 :
702 {
703 if ((used_colors == 0) || (used_colors > CalculateUsedPaletteEntries(bit_count)))
704 used_colors = CalculateUsedPaletteEntries(bit_count);
705
706 // allocate enough memory to hold the bitmap (header, palette, pixels) and read the palette
707
708 dib = FreeImage_AllocateHeader(header_only, width, height, bit_count);
709
710 if (dib == NULL) {
711 throw FI_MSG_ERROR_DIB_MEMORY;
712 }
713
714 // set resolution information
715 FreeImage_SetDotsPerMeterX(dib, bih.biXPelsPerMeter);
716 FreeImage_SetDotsPerMeterY(dib, bih.biYPelsPerMeter);
717
718 // load the palette
719 // note that it may contain RGB or RGBA values : we will calculate this
720 unsigned pal_size = (bitmap_bits_offset - sizeof(BITMAPFILEHEADER) - bih.biSize) / used_colors;
721
722 io->seek_proc(handle, sizeof(BITMAPFILEHEADER) + bih.biSize, SEEK_SET);
723
724 RGBQUAD *pal = FreeImage_GetPalette(dib);
725
726 if(pal_size == 4) {
727 for (unsigned count = 0; count < used_colors; count++) {
728 FILE_BGRA bgra;
729
730 io->read_proc(&bgra, sizeof(FILE_BGRA), 1, handle);

Callers 1

DLL_CALLCONV LoadFunction · 0.85

Calls 7

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

Tested by

no test coverage detected