SFML community forums
Help => Graphics => Topic started by: Ashenwraith on April 23, 2010, 01:32:19 pm
-
This is kind of important because a lot of my code is based on this.
Is there a better way than what I'm doing:
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);
-
Why are you putting this question and code in another post ?
You asked it once in this post (http://www.sfml-dev.org/forum/viewtopic.php?p=16408#16408), no ?
-
Why are you putting this question and code in another post ?
You asked it once in this post (http://www.sfml-dev.org/forum/viewtopic.php?p=16408#16408), no ?
Because it's obviously a different thread topic.
-
Ok,
1- I think there is an error in our calcul (y instead of w)
2- Why don't you simply use GetPixel (http://www.sfml-dev.org/documentation/1.6/classsf_1_1Image.htm#b7590e372a153ace848cf8a6081c8bc4) ?
-
1-I think you are confused of what an index of a pixel array is.
2-I originally did use GetPixel (and SetPixel and Image.Copy), but they are slow and not recommended for serious operations.
-
Well, if you rewrite a GetPixel function if probably won't be faster than sf::Image's one (at least in SFML 2).
I don't understand why your code is so much complicated, what about this?
sf::Uint8* Get_Pixel(sf::Uint8* img_ptr,int w,int h,int x,int y)
{
return img_ptr + (x + y * w) * 4;
}
And by the way, if Image::GetPixelsPtr returns a const pointer, it's not to force you to use a const_cast. You really can't modify the returned pixels ;)