Why image quality is very low after rotozoomSurfaceXY?

I need to resize a 500500 pixels image to 7575. First, I used rotozoomSurfaceXY and SMOOTHING_ON option. But I found the output image quality is very very low. Then, I used photoshop and fireworks for same job, resize output image quality is so good.

How can I get high quality resize image by SDL2 library?

Photoshop can afford to use way more complex algorithms than your GPU
will do for a textured quad (the GPU will just calculate the texture
coordinates and retrieve the four texels surrounding it, Photoshop
will look for all texels at that pixel). Most games try to hide this
by using mipmapping (which is basically using prerendered shrunk down
versions of the textures on small polygons), though I don’t think SDL
supports this (although I think drivers can force automatic mipmap
generation?).

2015-09-13 23:39 GMT-03:00, Nemo <377307289 at qq.com>:> I need to resize a 500500 pixels image to 7575. First, I used

rotozoomSurfaceXY and SMOOTHING_ON option. But I found the output image
quality is very very low. Then, I used photoshop and fireworks for same job,
resize output image quality is so good.

How can I get high quality resize image by SDL2 library?

I think this is a problem of SDL2_gfx, not SDL2 Per se. rotozoomSurfaceXY
is a function that operates on surfaces and probably does so in software.
Try using SDL_RenderCopyEx().

Pallav Nawani
IronCode Gaming Private Limited
Website: http://www.ironcode.com
Twitter: http://twitter.com/Ironcode_Gaming
Facebook: http://www.facebook.com/Ironcode.Gaming
Mobile: 9997478768On Mon, Sep 14, 2015 at 5:50 PM, Sik the hedgehog < sik.the.hedgehog at gmail.com> wrote:

Photoshop can afford to use way more complex algorithms than your GPU
will do for a textured quad (the GPU will just calculate the texture
coordinates and retrieve the four texels surrounding it, Photoshop
will look for all texels at that pixel). Most games try to hide this
by using mipmapping (which is basically using prerendered shrunk down
versions of the textures on small polygons), though I don’t think SDL
supports this (although I think drivers can force automatic mipmap
generation?).

2015-09-13 23:39 GMT-03:00, Nemo <377307289 at qq.com>:

I need to resize a 500500 pixels image to 7575. First, I used
rotozoomSurfaceXY and SMOOTHING_ON option. But I found the output image
quality is very very low. Then, I used photoshop and fireworks for same
job,
resize output image quality is so good.

How can I get high quality resize image by SDL2 library?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I have this really weird issue going on with threads ? this is the reduced code (I compiled it, and the problem is 100% reproducable)

int APIENTRY _tWinMain(In HINSTANCE hInstance,
In_opt HINSTANCE hPrevInstance,
In LPTSTR lpCmdLine,
In int nCmdShow)
{
bool b = false;
SDL_Thread * t = SDL_CreateThread(NIThreadProc, “2ndThread”, &b);

// ::Sleep(2000);
while (b == false)
{
}

MessageBox(NULL,L"b is now true\n",L"duh",MB_OK);
return 0;

}

int NIThreadProc(void ptr)
{
bool * ready =(bool
) ptr;

::Sleep(100);
MessageBox(NULL, L"setting b to true\n", L"duh", MB_OK);
*ready = true;
return 1;

}

the expected behavior if the program is :
- main app launches
- starts 2nd thread
- 2nd thread waits 100msec then displays a message and sets a passed boolean to true
- main thread waits for that boolean, then displays a message
- application ends

BUT ?. unless I UNCOMMENT the sleep(2000) function, the main thread NEVER exits the while(b==false) loop !!! I see in the task manager that the task is still active (and using CPU), but the ?b is now true? message never appears.

if I do uncomment the sleep, the app works as expected.

also : this is only in release mode, not in debug mode

any ideas ?

My only thought right away is that the main thread is not interacting
nicely with a multitasking environment. Without the SDL_Delay(), it
doesn’t give any chance for synchronization with other threads via the OS
scheduler. Using a mutex would provide the same opportunity for other
threads to run in this program’s process.

Just a guess, but maybe it’s a reasonable way to look at it.

Jonny DOn Tue, Sep 15, 2015 at 5:30 AM, jeroen clarysse <jeroen.clarysse at telenet.be wrote:

I have this really weird issue going on with threads ? this is the reduced
code (I compiled it, and the problem is 100% reproducable)

int APIENTRY _tWinMain(In HINSTANCE hInstance,
In_opt HINSTANCE hPrevInstance,
In LPTSTR lpCmdLine,
In int nCmdShow)
{
bool b = false;
SDL_Thread * t = SDL_CreateThread(NIThreadProc, “2ndThread”, &b);

// ::Sleep(2000);
while (b == false)
{
}

    MessageBox(NULL,L"b is now true\n",L"duh",MB_OK);
    return 0;

}

int NIThreadProc(void ptr)
{
bool * ready =(bool
) ptr;

    ::Sleep(100);
    MessageBox(NULL, L"setting b to true\n", L"duh", MB_OK);
    *ready = true;
    return 1;

}

the expected behavior if the program is :
- main app launches
- starts 2nd thread
- 2nd thread waits 100msec then displays a message and sets a
passed boolean to true
- main thread waits for that boolean, then displays a message
- application ends

BUT ?. unless I UNCOMMENT the sleep(2000) function, the main thread NEVER
exits the while(b==false) loop !!! I see in the task manager that the task
is still active (and using CPU), but the ?b is now true? message never
appears.

if I do uncomment the sleep, the app works as expected.

also : this is only in release mode, not in debug mode

any ideas ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

i found that declaring b as ?volatile? solved it !!!

apparently, not doing so opens doors to compiler optimisations that cause weirdness> My only thought right away is that the main thread is not interacting nicely with a multitasking environment. Without the SDL_Delay(), it doesn’t give any chance for synchronization with other threads via the OS scheduler. Using a mutex would provide the same opportunity for other threads to run in this program’s process.

Just a guess, but maybe it’s a reasonable way to look at it.

Jonny D

On Tue, Sep 15, 2015 at 5:30 AM, jeroen clarysse <@Jeroen_Clarysse> wrote:
I have this really weird issue going on with threads ? this is the reduced code (I compiled it, and the problem is 100% reproducable)

int APIENTRY _tWinMain(In HINSTANCE hInstance,
In_opt HINSTANCE hPrevInstance,
In LPTSTR lpCmdLine,
In int nCmdShow)
{
bool b = false;
SDL_Thread * t = SDL_CreateThread(NIThreadProc, “2ndThread”, &b);

// ::Sleep(2000);
while (b == false)
{
}

    MessageBox(NULL,L"b is now true\n",L"duh",MB_OK);
    return 0;

}

int NIThreadProc(void ptr)
{
bool * ready =(bool
) ptr;

    ::Sleep(100);
    MessageBox(NULL, L"setting b to true\n", L"duh", MB_OK);
    *ready = true;
    return 1;

}

the expected behavior if the program is :
- main app launches
- starts 2nd thread
- 2nd thread waits 100msec then displays a message and sets a passed boolean to true
- main thread waits for that boolean, then displays a message
- application ends

BUT ?. unless I UNCOMMENT the sleep(2000) function, the main thread NEVER exits the while(b==false) loop !!! I see in the task manager that the task is still active (and using CPU), but the ?b is now true? message never appears.

if I do uncomment the sleep, the app works as expected.

also : this is only in release mode, not in debug mode

any ideas ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I have this really weird issue going on with threads ? this is the reduced
code (I compiled it, and the problem is 100% reproducable)
if I do uncomment the sleep, the app works as expected.

also : this is only in release mode, not in debug mode

any ideas ?

I believe the problem is that the compiler doesn’t realise that b might
change in the other thread - it assumes that b can never be changed in the
while loop and so optimises out the check (b == false).
Adding the Sleep works a bit but if (in my testing) if you wait > 2 seconds
before OK’ing the first message box it doesn’t work either.

One solution is to make b volatile which means the compiler has to include
code to check it every time. You also need a cast to void * in
SDL_CreateThread.

PeteOn Tue, 15 Sep 2015 at 10:30 jeroen clarysse <jeroen.clarysse at telenet.be> wrote:

I just found out exactly what you wrote :-)> On 15 Sep 2015, at 15:38, Peter Hull wrote:

On Tue, 15 Sep 2015 at 10:30 jeroen clarysse <@Jeroen_Clarysse> wrote:
I have this really weird issue going on with threads ? this is the reduced code (I compiled it, and the problem is 100% reproducable)
if I do uncomment the sleep, the app works as expected.

also : this is only in release mode, not in debug mode

any ideas ?

I believe the problem is that the compiler doesn’t realise that b might change in the other thread - it assumes that b can never be changed in the while loop and so optimises out the check (b == false).
Adding the Sleep works a bit but if (in my testing) if you wait > 2 seconds before OK’ing the first message box it doesn’t work either.

One solution is to make b volatile which means the compiler has to include code to check it every time. You also need a cast to void * in SDL_CreateThread.

Pete


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Gotta be quick on this list! I will try harder next time…On Tue, 15 Sep 2015 at 14:41 jeroen clarysse <jeroen.clarysse at telenet.be> wrote:

I just found out exactly what you wrote :slight_smile:

On 15 Sep 2015, at 15:38, Peter Hull <@Peter_Hull> wrote:

On Tue, 15 Sep 2015 at 10:30 jeroen clarysse <jeroen.clarysse at telenet.be> wrote:
I have this really weird issue going on with threads ? this is the
reduced code (I compiled it, and the problem is 100% reproducable)
if I do uncomment the sleep, the app works as expected.

also : this is only in release mode, not in debug mode

any ideas ?

I believe the problem is that the compiler doesn’t realise that b might
change in the other thread - it assumes that b can never be changed in the
while loop and so optimises out the check (b == false).
Adding the Sleep works a bit but if (in my testing) if you wait > 2
seconds before OK’ing the first message box it doesn’t work either.

One solution is to make b volatile which means the compiler has to
include code to check it every time. You also need a cast to void * in
SDL_CreateThread.

Pete


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

volatile is not supposed to be used for this kind of purpose. it may
work with some compilerse and not with others[1]
Use proper synchronization with semaphores, mutexes, …[2] or atomics[3].

Cheers,
Daniel

[1]
https://software.intel.com/en-us/blogs/2007/11/30/volatile-almost-useless-for-multi-threaded-programming
[2] https://wiki.libsdl.org/CategoryMutex
[3] https://wiki.libsdl.org/CategoryAtomicOn 09/15/2015 03:38 PM, jeroen clarysse wrote:

i found that declaring b as ?volatile? solved it !!!

apparently, not doing so opens doors to compiler optimisations that cause weirdness

My only thought right away is that the main thread is not interacting nicely with a multitasking environment. Without the SDL_Delay(), it doesn’t give any chance for synchronization with other threads via the OS scheduler. Using a mutex would provide the same opportunity for other threads to run in this program’s process.

Just a guess, but maybe it’s a reasonable way to look at it.

Jonny D

On Tue, Sep 15, 2015 at 5:30 AM, jeroen clarysse <jeroen.clarysse at telenet.be> wrote:
I have this really weird issue going on with threads ? this is the reduced code (I compiled it, and the problem is 100% reproducable)

int APIENTRY _tWinMain(In HINSTANCE hInstance,
In_opt HINSTANCE hPrevInstance,
In LPTSTR lpCmdLine,
In int nCmdShow)
{
bool b = false;
SDL_Thread * t = SDL_CreateThread(NIThreadProc, “2ndThread”, &b);

// ::Sleep(2000);
while (b == false)
{
}

     MessageBox(NULL,L"b is now true\n",L"duh",MB_OK);
     return 0;

}

int NIThreadProc(void ptr)
{
bool * ready =(bool
) ptr;

     ::Sleep(100);
     MessageBox(NULL, L"setting b to true\n", L"duh", MB_OK);
     *ready = true;
     return 1;

}

the expected behavior if the program is :
- main app launches
- starts 2nd thread
- 2nd thread waits 100msec then displays a message and sets a passed boolean to true
- main thread waits for that boolean, then displays a message
- application ends

BUT ?. unless I UNCOMMENT the sleep(2000) function, the main thread NEVER exits the while(b==false) loop !!! I see in the task manager that the task is still active (and using CPU), but the ?b is now true? message never appears.

if I do uncomment the sleep, the app works as expected.

also : this is only in release mode, not in debug mode

any ideas ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Read also the first comment on the article.

It’s true that volatile is not a replacement of std::atomic or mutexes, but
it’s close to that if you use it on simple objects (int32_t, bool…) and
in a wide range of architectures.

There are a lot of lock free programming strategies or embedded system
software that rely on the multithreaded behaviour of volatile, also if, as
the article says, this behaviour is not defined by the standard.On Tue, Sep 15, 2015 at 4:07 PM, Daniel Gibson wrote:

volatile is not supposed to be used for this kind of purpose. it may work
with some compilerse and not with others[1]
Use proper synchronization with semaphores, mutexes, …[2] or atomics[3].

Cheers,
Daniel

[1]
https://software.intel.com/en-us/blogs/2007/11/30/volatile-almost-useless-for-multi-threaded-programming
[2] https://wiki.libsdl.org/CategoryMutex
[3] https://wiki.libsdl.org/CategoryAtomic

On 09/15/2015 03:38 PM, jeroen clarysse wrote:

i found that declaring b as ?volatile? solved it !!!

apparently, not doing so opens doors to compiler optimisations that cause
weirdness

My only thought right away is that the main thread is not interacting

nicely with a multitasking environment. Without the SDL_Delay(), it
doesn’t give any chance for synchronization with other threads via the OS
scheduler. Using a mutex would provide the same opportunity for other
threads to run in this program’s process.

Just a guess, but maybe it’s a reasonable way to look at it.

Jonny D

On Tue, Sep 15, 2015 at 5:30 AM, jeroen clarysse < jeroen.clarysse at telenet.be> wrote:
I have this really weird issue going on with threads ? this is the
reduced code (I compiled it, and the problem is 100% reproducable)

int APIENTRY _tWinMain(In HINSTANCE hInstance,
In_opt HINSTANCE hPrevInstance,
In LPTSTR lpCmdLine,
In int nCmdShow)
{
bool b = false;
SDL_Thread * t = SDL_CreateThread(NIThreadProc, “2ndThread”,
&b);

// ::Sleep(2000);
while (b == false)
{
}

     MessageBox(NULL,L"b is now true\n",L"duh",MB_OK);
     return 0;

}

int NIThreadProc(void ptr)
{
bool * ready =(bool
) ptr;

     ::Sleep(100);
     MessageBox(NULL, L"setting b to true\n", L"duh", MB_OK);
     *ready = true;
     return 1;

}

the expected behavior if the program is :
- main app launches
- starts 2nd thread
- 2nd thread waits 100msec then displays a message and sets a
passed boolean to true
- main thread waits for that boolean, then displays a message
- application ends

BUT ?. unless I UNCOMMENT the sleep(2000) function, the main thread
NEVER exits the while(b==false) loop !!! I see in the task manager that
the task is still active (and using CPU), but the ?b is now true? message
never appears.

if I do uncomment the sleep, the app works as expected.

also : this is only in release mode, not in debug mode

any ideas ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Ing. Gabriele Greco, DARTS Engineering
Tel: +39-0100980150 Fax: +39-0100980184
s-mail: Piazza Della Vittoria 9/3 - 16121 GENOVA (ITALY)