Reputation: 191
I currently have my 8bit bitmap's pixel data stored in an array of bytes: BYTE* pixelData
.
How would I now go about coding my own function to return a pixel's colour by it's position? I've done a fair amount of searching and haven't found anything that covers this using C++.
Upvotes: 0
Views: 1545
Reputation: 942438
You can't, not enough data. Almost all 8bpp pixel formats are indexed formats. They use a color table that stores the actual RGB color, the byte at the pixel location is an index into that table. The table contains 256 entries.
You'll also need a pointer to the color table.
Upvotes: 1
Reputation: 701
BYTE GetPixelColor(BYTE* src, int x, int y, int srcWidth)
{
return src[y * srcWidth + x];
}
...
//suppose you have a 800 x 600 bmp, to get the color for pixel at x 30, y 200
BYTE color = GetPixelColor(src, 30, 200, 800);
Upvotes: 1