SFML community forums
Help => Graphics => Topic started by: Ashenwraith on April 22, 2010, 03:04:38 am
-
How do I store sf::Uint8 if arrays of type sf::Uint8 are unsigned chars?
I'm trying convert my sf::Volor arrays and the only thing I can think of is filling them with uint8 data and making the logic really long with 0,1,2,3 checks.
-
Sorry, I don't understand what you want to do. Maybe you can show some code?
-
sf::Uint8 *color[3];
*color[0]=0;
*color[1]=0;
*color[2]=0;
*color[3]=0;
sf::Uint8 *container[1023];
*container[0]=*color; //cannot convert sf::Uint8* to unsigned char
-
Why do you have two levels of indirection (ie. arrays of pointers to sf::Uint8)?
To manipulate an array of pixels you just need to have an array of sf::Uint8s, no pointers.
sf::Uint8 pixels[WIDTH * HEIGHT * 4];
// or
std::vector<sf::Uint8> pixels(width * height * 4);
-
I know about *4, but I wanted to just work with the sf::Uint8 similar to sf::Color because I had arrays of sf::Color in my previous code.
Right now I am doing like you suggested, but with pointers.
I'm using pointers because GetPixelsPtr returns a pointer.
Is there a better way?
sf::Uint8* Get_Pixel(sf::Uint8* img_ptr,int w,int h,int x,int y)
{
int index=(((y*h)-y)+(x))*4;
sf::Uint8 *ptr=new sf::Uint8[3];
ptr[0]=img_ptr[index];
ptr[1]=img_ptr[index+1];
ptr[2]=img_ptr[index+2];
ptr[3]=img_ptr[index+3];
return ptr;
}
sf::Uint8 *img_ptr=const_cast<sf::Uint8*>(img.GetPixelsPtr());
sf::Uint8 *ptr3=Get_Pixel(img_ptr,w,h,80,0);