Hello everyone, I've a project where I have to compress an image. Everything is ok except the displaying of the image (after decompression).
To have my pixelArray, I made:
struct Pixel
{
uint8_t B, G, R;
};
Pixel** pixelArray = new Pixel*[bmpHeader.ImageWidth];
for (int i = 0; i < bmpHeader.ImageWidth; ++i)
pixelArray[i] = new Pixel[bmpHeader.ImageHeight];
Do not care about what is bmpHeader, that just give the size of the image.
Now I would like to display it with SFML, I think texture.update() would work fine but I don't know how to convert Pixel** to sf::Uint8*, and are we oblige to use rbga ? (because I don't use transparency)
Can you please tell me how sf::Uint8* works ? Or even better, can you guide me to convert Pixel** to sf::Uint8* ?
Thanks a lot !
Just thinking aloud here. Could you do something like:
sf::Image image(bmpHeader.ImageWidth, bmpHeader.ImageHeight);
and then use setPixel() (http://sfml-dev.org/documentation/2.1/classsf_1_1Image.php#a9fd329b8cd7d4439e07fb5d3bb2d9744) to modify each pixel based on pixel.
Maybe something like:
image.setPixel(sf::Color(pixel.r, pixel.g, pixel.b));
or equivalent, modifying to accommodate pointer usage.
Then, to create a texture, it's just:
sf::Texture texture;
if (!image.loadFromImage(image))
return errorCode;
The reason I suggest this method is because your pixels are stored in a different format (type Pixel) to how sfml seems to require (type sf::Color) and would need conversion.
Can you please tell me how sf::Uint8* works ?
sf::Uint8 is an 8-bit unsigned integer (actually it's an unsigned char - a byte: 0-255)
EDIT: Corrected setPixel's link.