MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / sReadBMP

Function sReadBMP

Engine/source/gfx/bitmap/loaders/bitmapBmp.cpp:93–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91//
92
93static bool sReadBMP(Stream &stream, GBitmap *bitmap)
94{
95 PROFILE_SCOPE(sReadBMP);
96 BITMAPINFOHEADER bi;
97 BITMAPFILEHEADER bf;
98 RGBQUAD rgb[256];
99
100 stream.read(&bf.bfType);
101 stream.read(&bf.bfSize);
102 stream.read(&bf.bfReserved1);
103 stream.read(&bf.bfReserved2);
104 stream.read(&bf.bfOffBits);
105
106 stream.read(&bi.biSize);
107 stream.read(&bi.biWidth);
108 stream.read(&bi.biHeight);
109 stream.read(&bi.biPlanes);
110 stream.read(&bi.biBitCount);
111 stream.read(&bi.biCompression);
112 stream.read(&bi.biSizeImage);
113 stream.read(&bi.biXPelsPerMeter);
114 stream.read(&bi.biYPelsPerMeter);
115 stream.read(&bi.biClrUsed);
116 stream.read(&bi.biClrImportant);
117
118 GFXFormat fmt = GFXFormatR8G8B8;
119 if(bi.biBitCount == 8)
120 {
121 // read in texture palette
122 if(!bi.biClrUsed)
123 bi.biClrUsed = 256;
124 stream.read(sizeof(RGBQUAD) * bi.biClrUsed, rgb);
125 }
126 bitmap->allocateBitmap(bi.biWidth, bi.biHeight, false, fmt);
127 U32 width = bitmap->getWidth();
128 U32 height = bitmap->getHeight();
129 U32 bytesPerPixel = bitmap->getBytesPerPixel();
130
131 for(U32 i = 0; i < bi.biHeight; i++)
132 {
133 U8 *rowDest = bitmap->getAddress(0, height - i - 1);
134 if (bi.biBitCount == 8)
135 {
136 // use palette...don't worry about being slow
137 for (S32 j=0; j<width; j++)
138 {
139 U8 palIdx;
140 stream.read(&palIdx);
141 U8 * pixelLocation = &rowDest[j*bytesPerPixel];
142 pixelLocation[0] = rgb[palIdx].rgbRed;
143 pixelLocation[1] = rgb[palIdx].rgbGreen;
144 pixelLocation[2] = rgb[palIdx].rgbBlue;
145 if (bytesPerPixel==3)
146 pixelLocation[3] = 255;
147 }
148 }
149 else
150 stream.read(bytesPerPixel * width, rowDest);

Callers

nothing calls this directly

Calls 7

allocateBitmapMethod · 0.80
getAddressMethod · 0.80
setHasTransparencyMethod · 0.80
readMethod · 0.45
getWidthMethod · 0.45
getHeightMethod · 0.45
getBytesPerPixelMethod · 0.45

Tested by

no test coverage detected