SFML community forums

Help => Graphics => Topic started by: Ashenwraith on April 18, 2010, 01:48:30 am

Title: [solved]Strange 'Artifacts' produced by RenderImage
Post 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.
Title: [solved]Strange 'Artifacts' produced by RenderImage
Post by: Laurent on April 18, 2010, 10:57:28 am
Can you provide a complete and minimal example that reproduces this proble?
Title: [solved]Strange 'Artifacts' produced by RenderImage
Post by: Ashenwraith on April 18, 2010, 05:48:02 pm
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.

Code: [Select]
#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;
}
Title: [solved]Strange 'Artifacts' produced by RenderImage
Post by: Laurent on April 18, 2010, 05:56:38 pm
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?
Title: [solved]Strange 'Artifacts' produced by RenderImage
Post by: Ashenwraith on April 18, 2010, 06:07:20 pm
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)
Title: [solved]Strange 'Artifacts' produced by RenderImage
Post by: Laurent on April 18, 2010, 06:16:33 pm
Quote
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.
Title: [solved]Strange 'Artifacts' produced by RenderImage
Post by: Ashenwraith on April 18, 2010, 06:24:33 pm
Quote from: "Laurent"
Quote
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?
Title: [solved]Strange 'Artifacts' produced by RenderImage
Post by: Laurent on April 18, 2010, 06:26:36 pm
Quote from: "Laurent Gomila"
Maybe a simple r_img.Clear(sf::Color(0, 0, 0, 0)) would solve the problem?
Title: [solved]Strange 'Artifacts' produced by RenderImage
Post by: Ashenwraith on April 18, 2010, 07:12:41 pm
Quote from: "Laurent"
Quote from: "Laurent Gomila"
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.
Title: [solved]Strange 'Artifacts' produced by RenderImage
Post by: Laurent on April 18, 2010, 07:19:37 pm
Do you mean that it doesn't solve the problem?
Title: [solved]Strange 'Artifacts' produced by RenderImage
Post by: Ashenwraith on April 18, 2010, 07:24:21 pm
No it works good with:

Code: [Select]

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?
Title: [solved]Strange 'Artifacts' produced by RenderImage
Post by: Laurent on April 18, 2010, 07:28:38 pm
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?
Code: [Select]
c_img00=r_img.GetImage();

img.Copy(c_img00,0,0,rct,true);
Title: [solved]Strange 'Artifacts' produced by RenderImage
Post by: Ashenwraith on April 18, 2010, 07:31:30 pm
Quote from: "Laurent"
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?
Code: [Select]
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.
Title: [solved]Strange 'Artifacts' produced by RenderImage
Post by: Laurent on April 18, 2010, 08:29:35 pm
Ok but you still didn't explain what the above lines of code are supposed to do.
Title: [solved]Strange 'Artifacts' produced by RenderImage
Post by: Ashenwraith on April 18, 2010, 09:14:38 pm
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.
Title: [solved]Strange 'Artifacts' produced by RenderImage
Post by: alwayslearning on April 18, 2010, 09:27:11 pm
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?
Title: [solved]Strange 'Artifacts' produced by RenderImage
Post by: Ashenwraith on April 18, 2010, 09:53:46 pm
Yep