| 888 | } |
| 889 | |
| 890 | Task<vector<ImageData>> BmpImageLoader::loadWithoutFileHeader( |
| 891 | istream& iStream, |
| 892 | const fs::path& path, |
| 893 | string_view channelSelector, |
| 894 | const ImageLoaderSettings& settings, |
| 895 | int priority, |
| 896 | optional<size_t> pixelDataOffset, |
| 897 | Vector2i* sizeInOut, |
| 898 | bool alphaByDefault |
| 899 | ) const { |
| 900 | const bool reverseEndianness = endian::native == endian::big; |
| 901 | |
| 902 | struct DibHeader { |
| 903 | uint32_t size; |
| 904 | int32_t width; |
| 905 | int32_t height; |
| 906 | uint16_t planes; |
| 907 | uint16_t bitsPerPixel; |
| 908 | uint32_t compression; |
| 909 | uint32_t imageSize; |
| 910 | int32_t xPixelsPerMeter; |
| 911 | int32_t yPixelsPerMeter; |
| 912 | uint32_t colorsUsed; |
| 913 | uint32_t importantColors; |
| 914 | // The following members differ between OS/2 and Windows BMP formats. We don't really care about them in the case of OS/2 (no |
| 915 | // actionable info for tev), so we define just the Windows values in this struct |
| 916 | uint32_t redMask; |
| 917 | uint32_t greenMask; |
| 918 | uint32_t blueMask; |
| 919 | uint32_t alphaMask; |
| 920 | uint32_t colorSpaceType; |
| 921 | uint32_t redX; |
| 922 | uint32_t redY; |
| 923 | uint32_t redZ; |
| 924 | uint32_t greenX; |
| 925 | uint32_t greenY; |
| 926 | uint32_t greenZ; |
| 927 | uint32_t blueX; |
| 928 | uint32_t blueY; |
| 929 | uint32_t blueZ; |
| 930 | uint32_t gammaRed; |
| 931 | uint32_t gammaGreen; |
| 932 | uint32_t gammaBlue; |
| 933 | uint32_t intent; |
| 934 | uint32_t iccProfileData; |
| 935 | uint32_t iccProfileSize; |
| 936 | uint32_t reserved; |
| 937 | } dib = {}; |
| 938 | static_assert(sizeof(dib) == 124, "DibHeader struct must be exactly 124 bytes to match the Windows BMP header v5 format."); |
| 939 | |
| 940 | const size_t dibHeaderBegin = iStream.tellg(); |
| 941 | |
| 942 | iStream.read((char*)&dib.size, sizeof(uint32_t)); |
| 943 | if (!iStream) { |
| 944 | throw ImageLoadError{"Failed to read BMP DIB header size."}; |
| 945 | } |
| 946 | |
| 947 | if (reverseEndianness) { |
no test coverage detected