I want to get pixel color on raster coordinates like for example:
[0,0] - pixel in first row and first column (top left)
[0,1] - pixel in first row and second column and so on.
I'm loading my bitmap like so:
BitsPerPixel = FileInfo[28];
width = FileInfo[18] + (FileInfo[19] << 8);
height = FileInfo[22] + (FileInfo[23] << 8);
int PixelsOffset = FileInfo[10] + (FileInfo[11] << 8);
int size = ((width * BitsPerPixel + 31) / 32) * 4 * height;
Pixels.resize(size);
hFile.seekg(PixelsOffset, ios::beg);
hFile.read(reinterpret_cast<char*>(Pixels.data()), size);
hFile.close();
and my GetPixel function:
void BITMAPLOADER::GetPixel(int x, int y, unsigned char* pixel_color)
{
y = height - y;
const int RowLength = 4 * ((width * BitsPerPixel + 31) / 32);
pixel_color[0] = Pixels[RowLength * y * BitsPerPixel / 8 + x * BitsPerPixel / 8];
pixel_color[1] = Pixels[RowLength * y * BitsPerPixel / 8 + x * BitsPerPixel / 8 + 1];
pixel_color[2] = Pixels[RowLength * y * BitsPerPixel / 8 + x * BitsPerPixel / 8 + 2];
pixel_color[3] = Pixels[RowLength * y * BitsPerPixel / 8 + x * BitsPerPixel / 8 + 3];
}
I know the data in bitmap are stored up side down, so I wanted to invert it using the y = height - y;
but with this line I only get some values which even are not in the image data array. Without inverting the image I get some values which are in the array but they never correspond with the coords given. My bitmap can be 24-bit or 32-bit.