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

Author Topic: Scale without anti-aliasing?  (Read 2272 times)

0 Members and 1 Guest are viewing this topic.

Clarity_IV

  • Newbie
  • *
  • Posts: 2
    • View Profile
Scale without anti-aliasing?
« on: February 24, 2012, 01:16:21 am »
Hello,

I was wondering if there was a way to scale an image with SFML without any form of anti-aliasing. I'm not talking about turning anti-aliasing off for the window, but instead scaling an image so it doesn't look blurry.

I tried to write my own scale function to suit the purpose, but it always comes out as a white box covering the full image.

If someone could tell me if there's a function that does this, or what's wrong with my function, that would be great.

Thanks!

Code: [Select]
class AREA{
   
    public:

        Image   img;                            //Area image
        Sprite  spr;                            //Area sprite
        Color   bnd_clr;                        //Boundary color
        int     x,  y;                          //Image size
        bool    bnd[MAX_AREA_X][MAX_AREA_Y];    //Boundaries

}area[MAX_AREA];


Code: [Select]

bool    spr_scale(  int scale,
                    int index   ){

    //Create temporary variables
    int     atmp, btmp, ctmp, dtmp; //Temporary counter integers
    Image   tmp_img;                //Temporary image


    //Create temporary image
    tmp_img.Create( area[index].x * scale,  //Old image's x size * scale value
                    area[index].y * scale,  //Old image's y size * scale value
                    Color(0, 0, 0)      );  //Make the image 100% black


    //Fill new image with scaled old image
    for ( atmp = 1 ; atmp < area[index].y ; ++atmp )        //Original image y counter
        for ( btmp = 1 ; btmp < area[index].x ; ++btmp )    //Original image x counter
            for ( ctmp = 0 ; ctmp < scale ; ++ctmp )        //New image y counter
                for ( dtmp = 0 ; dtmp < scale ; ++dtmp )    //New image x counter
                    //Set the pixel
                    tmp_img.SetPixel(   ( btmp * scale ) + dtmp,                    //x position of pixel
                                        ( atmp * scale ) + ctmp,                    //y position of pixel
                                        area[index].spr.GetPixel( btmp, atmp ) );   //Get old image color


    //Set old image to the new scaled image
    area[index].spr.Resize( ( area[index].x * scale ),      //Set new x size...
                            ( area[index].y * scale ) );    //...set new y size...
    area[index].spr.SetImage( tmp_img );                    //...and make it so


    //Everything went alright
    return true;

}

Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
Scale without anti-aliasing?
« Reply #1 on: February 26, 2012, 12:34:34 am »
can't tell if your C or C++, or some odd language, but, try using curly bracketing for anything past one indent, example:

before:
Code: [Select]
for (blahblahblah)
    for (blahblahblah)
        do.this();


after:
Code: [Select]
for (blahblahblah){
    for (blahblahblah){
        do.this();
    }
}


that may be your problem, but it also looks like your doing more work than you need to, just scale the image with a matrix, and loop into the image and replace each empty pixel with the one before it :)
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion

Clarity_IV

  • Newbie
  • *
  • Posts: 2
    • View Profile
Scale without anti-aliasing?
« Reply #2 on: February 26, 2012, 03:34:57 am »
Quote from: "Weeve"
can't tell if your C or C++, or some odd language, but, try using curly bracketing for anything past one indent, example:


I'm using C++. I've tried both bracketed and unbracketed, it makes no difference.

Quote
that may be your problem, but it also looks like your doing more work than you need to, just scale the image with a matrix, and loop into the image and replace each empty pixel with the one before it :)


That's basically what I'm doing now, how are you saying to do it?

Thanks!

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Scale without anti-aliasing?
« Reply #3 on: February 26, 2012, 04:04:33 am »
Look all proper scaling is based on blurring. Even when you sample from a texture in shaders there is a linear interpolation done. What you want to do is point sampling more or less. Which means you will ignore some pixels. So let's say you scale down 2 times. That means for each pixel you write to the destination, 3 others are ignored around it as there doesn't fit more information. As soon as you try to merge the pixels around into one, that's when you get blurry results. Which is most of the cases more preferable.

Plus since the scale is an int, that means you can only scale up.
And you set the sprite's texture to refer to a temporary image which is deleted when we reach the end of the function.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
Scale without anti-aliasing?
« Reply #4 on: February 26, 2012, 11:48:48 pm »
try asserting all the variables for debugging then, or you could print them all to get a visual of where the problem is, I can't offer much more, but some debugging should fix it, maybe your overwriting the wrong pixels in the wrong way, or calling a function wrong or out of scope?
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion