| 874 | // -------------------------------------------------------------------------- |
| 875 | |
| 876 | static FIBITMAP * |
| 877 | LoadOS21XBMP(FreeImageIO *io, fi_handle handle, int flags, unsigned bitmap_bits_offset) { |
| 878 | FIBITMAP *dib = NULL; |
| 879 | |
| 880 | try { |
| 881 | BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS; |
| 882 | |
| 883 | BITMAPINFOOS2_1X_HEADER bios2_1x; |
| 884 | |
| 885 | io->read_proc(&bios2_1x, sizeof(BITMAPINFOOS2_1X_HEADER), 1, handle); |
| 886 | #ifdef FREEIMAGE_BIGENDIAN |
| 887 | SwapOS21XHeader(&bios2_1x); |
| 888 | #endif |
| 889 | // keep some general information about the bitmap |
| 890 | |
| 891 | unsigned used_colors = 0; |
| 892 | unsigned width = bios2_1x.biWidth; |
| 893 | unsigned height = bios2_1x.biHeight; // WARNING: height can be < 0 => check each read_proc using 'height' as a parameter |
| 894 | unsigned bit_count = bios2_1x.biBitCount; |
| 895 | unsigned pitch = CalculatePitch(CalculateLine(width, bit_count)); |
| 896 | |
| 897 | switch (bit_count) { |
| 898 | case 1 : |
| 899 | case 4 : |
| 900 | case 8 : |
| 901 | { |
| 902 | used_colors = CalculateUsedPaletteEntries(bit_count); |
| 903 | |
| 904 | // allocate enough memory to hold the bitmap (header, palette, pixels) and read the palette |
| 905 | |
| 906 | dib = FreeImage_AllocateHeader(header_only, width, height, bit_count); |
| 907 | |
| 908 | if (dib == NULL) { |
| 909 | throw FI_MSG_ERROR_DIB_MEMORY; |
| 910 | } |
| 911 | |
| 912 | // set resolution information to default values (72 dpi in english units) |
| 913 | FreeImage_SetDotsPerMeterX(dib, 2835); |
| 914 | FreeImage_SetDotsPerMeterY(dib, 2835); |
| 915 | |
| 916 | // load the palette |
| 917 | |
| 918 | RGBQUAD *pal = FreeImage_GetPalette(dib); |
| 919 | |
| 920 | for (unsigned count = 0; count < used_colors; count++) { |
| 921 | FILE_BGR bgr; |
| 922 | |
| 923 | io->read_proc(&bgr, sizeof(FILE_BGR), 1, handle); |
| 924 | |
| 925 | pal[count].rgbRed = bgr.r; |
| 926 | pal[count].rgbGreen = bgr.g; |
| 927 | pal[count].rgbBlue = bgr.b; |
| 928 | } |
| 929 | |
| 930 | if(header_only) { |
| 931 | // header only mode |
| 932 | return dib; |
| 933 | } |
no test coverage detected