Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [solved]Strange 'Artifacts' produced by RenderImage  (Read 6311 times)

0 Members and 1 Guest are viewing this topic.

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
[solved]Strange 'Artifacts' produced by RenderImage
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[solved]Strange 'Artifacts' produced by RenderImage
« Reply #1 on: April 18, 2010, 10:57:28 am »
Can you provide a complete and minimal example that reproduces this proble?
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
[solved]Strange 'Artifacts' produced by RenderImage
« Reply #2 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;
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[solved]Strange 'Artifacts' produced by RenderImage
« Reply #3 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?
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
[solved]Strange 'Artifacts' produced by RenderImage
« Reply #4 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)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[solved]Strange 'Artifacts' produced by RenderImage
« Reply #5 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.
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
[solved]Strange 'Artifacts' produced by RenderImage
« Reply #6 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[solved]Strange 'Artifacts' produced by RenderImage
« Reply #7 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?
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
[solved]Strange 'Artifacts' produced by RenderImage
« Reply #8 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[solved]Strange 'Artifacts' produced by RenderImage
« Reply #9 on: April 18, 2010, 07:19:37 pm »
Do you mean that it doesn't solve the problem?
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
[solved]Strange 'Artifacts' produced by RenderImage
« Reply #10 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[solved]Strange 'Artifacts' produced by RenderImage
« Reply #11 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);
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
[solved]Strange 'Artifacts' produced by RenderImage
« Reply #12 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[solved]Strange 'Artifacts' produced by RenderImage
« Reply #13 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.
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
[solved]Strange 'Artifacts' produced by RenderImage
« Reply #14 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.

 

anything