MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / BmpRead24

Function BmpRead24

src/bmp.cpp:223–239  ·  view source on GitHub ↗

* Reads a 24 bpp uncompressed bitmap */

Source from the content-addressed store, hash-verified

221 * Reads a 24 bpp uncompressed bitmap
222 */
223static inline bool BmpRead24(RandomAccessFile &file, BmpInfo &info, BmpData &data)
224{
225 uint8_t pad = GB(4 - info.width * 3, 0, 2);
226 for (uint y = info.height; y > 0; --y) {
227 uint8_t *pixel_row = &data.bitmap[(y - 1) * static_cast<size_t>(info.width) * 3];
228 for (uint x = 0; x < info.width; ++x) {
229 if (file.AtEndOfFile()) return false; // the file is shorter than expected
230 *(pixel_row + 2) = file.ReadByte(); // green
231 *(pixel_row + 1) = file.ReadByte(); // blue
232 *pixel_row = file.ReadByte(); // red
233 pixel_row += 3;
234 }
235 /* Padding for 32 bit align */
236 file.SkipBytes(pad);
237 }
238 return true;
239}
240
241/*
242 * Reads bitmap headers, and palette (if any)

Callers 1

BmpReadBitmapFunction · 0.85

Calls 4

GBFunction · 0.85
AtEndOfFileMethod · 0.80
SkipBytesMethod · 0.80
ReadByteMethod · 0.45

Tested by

no test coverage detected