- BMPHeader_t bmpHeader;
- inputStream.read(reinterpret_cast<byte*>(bmpHeader.id), 2);
- bmpHeader.fileSize = istream_read_uint32_le(inputStream);
- bmpHeader.reserved0 = istream_read_uint32_le(inputStream);
- bmpHeader.bitmapDataOffset = istream_read_uint32_le(inputStream);
- bmpHeader.bitmapHeaderSize = istream_read_uint32_le(inputStream);
- bmpHeader.width = istream_read_uint32_le(inputStream);
- bmpHeader.height = istream_read_uint32_le(inputStream);
- bmpHeader.planes = istream_read_uint16_le(inputStream);
- bmpHeader.bitsPerPixel = istream_read_uint16_le(inputStream);
- bmpHeader.compression = istream_read_uint32_le(inputStream);
- bmpHeader.bitmapDataSize = istream_read_uint32_le(inputStream);
- bmpHeader.hRes = istream_read_uint32_le(inputStream);
- bmpHeader.vRes = istream_read_uint32_le(inputStream);
- bmpHeader.colors = istream_read_uint32_le(inputStream);
- bmpHeader.importantColors = istream_read_uint32_le(inputStream);
-
- if (bmpHeader.bitsPerPixel == 8)
- {
- int paletteSize = bmpHeader.colors * 4;
- inputStream.read(reinterpret_cast<byte*>(bmpHeader.palette), paletteSize);
- }
-
- if (bmpHeader.id[0] != 'B' && bmpHeader.id[1] != 'M')
- {
- globalErrorStream() << "LoadBMP: only Windows-style BMP files supported\n";
- return 0;
- }
- if (bmpHeader.fileSize != length)
- {
- globalErrorStream() << "LoadBMP: header size does not match file size (" << Unsigned(bmpHeader.fileSize) << " vs. " << Unsigned(length) << ")\n";
- return 0;
- }
- if (bmpHeader.compression != 0)
- {
- globalErrorStream() << "LoadBMP: only uncompressed BMP files supported\n";
- return 0;
- }
- if (bmpHeader.bitsPerPixel < 8)
- {
- globalErrorStream() << "LoadBMP: monochrome and 4-bit BMP files not supported\n";
- return 0;
- }
-
- int columns = bmpHeader.width;
- int rows = bmpHeader.height;
- if (rows < 0)
- rows = -rows;
-
- RGBAImage* image = new RGBAImage(columns, rows);
-
- switch(bmpHeader.bitsPerPixel)
- {
- case 8:
- ReadBMP(inputStream, image->getRGBAPixels(), rows, columns, ReadPixel8(bmpHeader.palette));
- break;
- case 16:
- ReadBMP(inputStream, image->getRGBAPixels(), rows, columns, ReadPixel16());
- break;
- case 24:
- ReadBMP(inputStream, image->getRGBAPixels(), rows, columns, ReadPixel24());
- break;
- case 32:
- ReadBMP(inputStream, image->getRGBAPixels(), rows, columns, ReadPixel32());
- break;
- default:
- globalErrorStream() << "LoadBMP: illegal pixel_size '" << bmpHeader.bitsPerPixel << "'\n";
- image->release();
- return 0;
- }
- return image;
+ BMPHeader_t bmpHeader;
+ inputStream.read(reinterpret_cast<byte *>( bmpHeader.id ), 2);
+ bmpHeader.fileSize = istream_read_uint32_le(inputStream);
+ bmpHeader.reserved0 = istream_read_uint32_le(inputStream);
+ bmpHeader.bitmapDataOffset = istream_read_uint32_le(inputStream);
+ bmpHeader.bitmapHeaderSize = istream_read_uint32_le(inputStream);
+ bmpHeader.width = istream_read_uint32_le(inputStream);
+ bmpHeader.height = istream_read_uint32_le(inputStream);
+ bmpHeader.planes = istream_read_uint16_le(inputStream);
+ bmpHeader.bitsPerPixel = istream_read_uint16_le(inputStream);
+ bmpHeader.compression = istream_read_uint32_le(inputStream);
+ bmpHeader.bitmapDataSize = istream_read_uint32_le(inputStream);
+ bmpHeader.hRes = istream_read_uint32_le(inputStream);
+ bmpHeader.vRes = istream_read_uint32_le(inputStream);
+ bmpHeader.colors = istream_read_uint32_le(inputStream);
+ bmpHeader.importantColors = istream_read_uint32_le(inputStream);
+
+ if (bmpHeader.bitsPerPixel == 8) {
+ int paletteSize = bmpHeader.colors * 4;
+ inputStream.read(reinterpret_cast<byte *>( bmpHeader.palette ), paletteSize);
+ }
+
+ if (bmpHeader.id[0] != 'B' && bmpHeader.id[1] != 'M') {
+ globalErrorStream() << "LoadBMP: only Windows-style BMP files supported\n";
+ return 0;
+ }
+ if (bmpHeader.fileSize != length) {
+ globalErrorStream() << "LoadBMP: header size does not match file size (" << Unsigned(bmpHeader.fileSize)
+ << " vs. " << Unsigned(length) << ")\n";
+ return 0;
+ }
+ if (bmpHeader.compression != 0) {
+ globalErrorStream() << "LoadBMP: only uncompressed BMP files supported\n";
+ return 0;
+ }
+ if (bmpHeader.bitsPerPixel < 8) {
+ globalErrorStream() << "LoadBMP: monochrome and 4-bit BMP files not supported\n";
+ return 0;
+ }
+
+ int columns = bmpHeader.width;
+ int rows = bmpHeader.height;
+ if (rows < 0) {
+ rows = -rows;
+ }
+
+ RGBAImage *image = new RGBAImage(columns, rows);
+
+ switch (bmpHeader.bitsPerPixel) {
+ case 8:
+ ReadBMP(inputStream, image->getRGBAPixels(), rows, columns, ReadPixel8(bmpHeader.palette));
+ break;
+ case 16:
+ ReadBMP(inputStream, image->getRGBAPixels(), rows, columns, ReadPixel16());
+ break;
+ case 24:
+ ReadBMP(inputStream, image->getRGBAPixels(), rows, columns, ReadPixel24());
+ break;
+ case 32:
+ ReadBMP(inputStream, image->getRGBAPixels(), rows, columns, ReadPixel32());
+ break;
+ default:
+ globalErrorStream() << "LoadBMP: illegal pixel_size '" << bmpHeader.bitsPerPixel << "'\n";
+ image->release();
+ return 0;
+ }
+ return image;