SFML community forums
Help => Graphics => Topic started by: Ashenwraith on April 18, 2010, 01:48:30 am
-
RenderImage seems to work good, but then I zoomed in and on the bottom of the last row there are some random pixels that do not belong there.
I know they are being produced because they are transparent unlike the rest of my image (and my smoothing is false).
They are also not in my color palette. I also saved copies of the image unscaled and the artifacts do not exist.
They are also smaller than 1x1 pixel that is scaled so no way they are coming from the image.
-
Can you provide a complete and minimal example that reproduces this proble?
-
This was hard to reproduce minimized. It flips the image when I tried to reproduce it, but in my original it doesn't flip and is aligned properly.
The artifact pixels on the bottom are not from the flipped image and are the main problem.
#include <SFML/Graphics.hpp>
#include <string>
#include <sstream>
template <typename T>
std::string X2S(const T& i){std::ostringstream s;s<<i;return s.str();}
int main()
{
sf::Image img00;
float wscale,hscale;
int w,h;
std::string fstr;
if(!sf::RenderImage::IsAvailable()){return -1;}
sf::RenderImage r_img;
int x=2;
for(x=2;x<4;x++)
{
fstr=X2S(x);
img00.LoadFromFile("sfb.png");
img00.SetSmooth(false);
w=img00.GetWidth(),h=img00.GetHeight();
wscale=w*x;
hscale=h*x;
if(x>2)
{
img00.LoadFromFile("fb00.png");wscale=w,hscale=h;
}
sf::Sprite sprt00(img00);
sprt00.Resize(wscale,hscale);
if(!r_img.Create(wscale,hscale)){return -1;}
r_img.SetSmooth(false);
r_img.Draw(sprt00);
r_img.Display();
img00=r_img.GetImage();
img00.SaveToFile("artifacts_img.png");
}
return 0;
}
-
Thanks for the code. However I can't see the artifacts that you're talking about. Can you upload the result and highlight the random pixels?
By the way, I see that you don't clear your image before drawing. Maybe a simple r_img.Clear(sf::Color(0, 0, 0, 0)) would solve the problem?
-
I don't want to clear it if I don't have to because then I'd need to make a copy image and save that in memory because I want them to stack.
Here are the artifacts zoomed in from artifacts_img.png (in photoshop)
-
I don't want to clear it if I don't have to because then I'd need to make a copy image and save that in memory because I want them to stack.
You have to clear the image at least once, because it is created uninitialized and may contain random pixels before you overwrite them.
-
I don't want to clear it if I don't have to because then I'd need to make a copy image and save that in memory because I want them to stack.
You have to clear the image at least once, because it is created uninitialized and may contain random pixels before you overwrite them.
So I have to store another temp image and copy the pixels or is there a technique to avoid that?
-
Maybe a simple r_img.Clear(sf::Color(0, 0, 0, 0)) would solve the problem?
-
Maybe a simple r_img.Clear(sf::Color(0, 0, 0, 0)) would solve the problem?
Yes I read that.
Yes I tested that.
I was just curious if there was another way/mode.
I guess not.
Thanks.
-
Do you mean that it doesn't solve the problem?
-
No it works good with:
if(!r_img.Create(w,h)){return -1;}
r_img.Clear(sf::Color(0,0,0,0));
c_img00=r_img.GetImage();
img.Copy(c_img00,0,0,rct,true);
But I'm doing image processing so I was curious if there was a speedy way to avoid sf::Image::Copy()
I suppose the only faster way is with a GetPixelsPtr right?
-
Sorry but I don't understand at all what you're doing.
Why don't you just clear the render image? What do the following lines mean?
c_img00=r_img.GetImage();
img.Copy(c_img00,0,0,rct,true);
-
Sorry but I don't understand at all what you're doing.
Why don't you just clear the render image? What do the following lines mean?
c_img00=r_img.GetImage();
img.Copy(c_img00,0,0,rct,true);
The final image needs to be a composited stack, that's why I wasn't Clear() before.
-
Ok but you still didn't explain what the above lines of code are supposed to do.
-
That's okay, don't worry we don't need to go any deeper in theory. I'll accept this.
I'll create a new thread on speed with pixels.
Thanks.
-
Correct me if I'm wrong but it sounds like ashen is trying to build layers of sprites on top of each other like a naked character, then clothes, then weapon (built on top of the previous sprite to create the final image).
Is this correct?
-
Yep