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

Function BmpRead4

src/bmp.cpp:45–65  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

43 * The bitmap is converted to a 8 bpp bitmap
44 */
45static inline bool BmpRead4(RandomAccessFile &file, BmpInfo &info, BmpData &data)
46{
47 uint8_t pad = GB(4 - info.width / 2, 0, 2);
48 for (uint y = info.height; y > 0; y--) {
49 uint x = 0;
50 uint8_t *pixel_row = &data.bitmap[(y - 1) * static_cast<size_t>(info.width)];
51 while (x < info.width) {
52 if (file.AtEndOfFile()) return false; // the file is shorter than expected
53 uint8_t b = file.ReadByte();
54 *pixel_row++ = GB(b, 4, 4);
55 x++;
56 if (x < info.width) {
57 *pixel_row++ = GB(b, 0, 4);
58 x++;
59 }
60 }
61 /* Padding for 32 bit align */
62 file.SkipBytes(pad);
63 }
64 return true;
65}
66
67/**
68 * Reads a 4-bit RLE compressed 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