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

Function BmpRead1

src/bmp.cpp:21–39  ·  view source on GitHub ↗

* Reads a 1 bpp uncompressed bitmap * The bitmap is converted to a 8 bpp bitmap */

Source from the content-addressed store, hash-verified

19 * The bitmap is converted to a 8 bpp bitmap
20 */
21static inline bool BmpRead1(RandomAccessFile &file, BmpInfo &info, BmpData &data)
22{
23 uint8_t pad = GB(4 - info.width / 8, 0, 2);
24 for (uint y = info.height; y > 0; y--) {
25 uint x = 0;
26 uint8_t *pixel_row = &data.bitmap[(y - 1) * static_cast<size_t>(info.width)];
27 while (x < info.width) {
28 if (file.AtEndOfFile()) return false; // the file is shorter than expected
29 uint8_t b = file.ReadByte();
30 for (uint i = 8; i > 0; i--) {
31 if (x < info.width) *pixel_row++ = GB(b, i - 1, 1);
32 x++;
33 }
34 }
35 /* Padding for 32 bit align */
36 file.SkipBytes(pad);
37 }
38 return true;
39}
40
41/**
42 * Reads a 4 bpp uncompressed bitmap

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