Hi guys,
I am trying to write a bitmap parser, and every thing is good when my bitmap texture is of dimension of power of two, but when it is not I am not able to get correct pixel at location and not able to set it as well, I know this is an alignment issue, but I am not able to get to it…
how get the correct pixel color in a RGB struct and set it as well…
//reading bmp file
infile.seekg(m_BMPHeader.Offset, ios_base::beg);
m_PixelRowSize = (((size_t)m_DibHeader.BitsPerPixel * abs(m_DibHeader.Width) + 31) / 32) * 4;
m_PixelData.resize(m_PixelRowSize * abs(m_DibHeader.Height));
infile.read(reinterpret_cast<char*>(m_PixelData.data()), m_PixelData.size());
infile.close();
vector<uint8_t> m_PixelData;
//wrting to a pixel at location
void BMPImporter::SetPixel(int x, int y, BGR bgr)
{
int channels = m_DibHeader.BitsPerPixel / 8;
m_PixelData[channels * (y * GetWidth() + x) + 0] = bgr.Blue;
m_PixelData[channels * (y * GetWidth() + x) + 1] = bgr.Green;
m_PixelData[channels * (y * GetWidth() + x) + 2] = bgr.Red;
}