We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5313 - [rfe] implement image scale interpolator for sw mode
Summary: [rfe] implement image scale interpolator for sw mode
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: render (show other bugs)
Version: 2.0.12
Hardware: x86_64 Linux
: P2 enhancement
Assignee: Sylvain
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.16
Depends on:
Blocks:
 
Reported: 2020-10-10 13:14 UTC by Stas Sergeev
Modified: 2021-01-02 08:56 UTC (History)
1 user (show)

See Also:


Attachments
test app (9.47 KB, text/x-csrc)
2020-12-23 20:54 UTC, Sylvain
Details
test app (14.36 KB, text/x-csrc)
2021-01-02 08:56 UTC, Sylvain
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stas Sergeev 2020-10-10 13:14:09 UTC
Hello.

Currently SW renderer uses SDL_SoftStretch() (called from SDL_BlitScaled()).
It has no interpolator code.
SDL_HINT_RENDER_SCALE_QUALITY is unused by the soft renderer.
Please implement some scaling interpolator.
Comment 1 Sam Lantinga 2020-12-09 14:32:03 UTC
Patches are welcome!
Comment 2 Sylvain 2020-12-13 23:14:26 UTC
Hey, 
I have some code that does that (replacing nearest by linear scaling) and that I can merge.

Not sure if this should be done in SDL_SoftStretch() or in a new SDL_SoftStretchLinear() instead ?
Comment 3 Sam Lantinga 2020-12-14 17:10:31 UTC
Let's have a separate function for it, and add it after SDL 2.0.14 release?
Comment 4 Stas Sergeev 2020-12-14 21:55:26 UTC
If you want/need, I can test. :)
Comment 5 Sylvain 2020-12-14 22:28:52 UTC
Ok, so this will be a new function.
The patch is straight forward and already tested for a while! 
I'll wait after 2.14 then,
Comment 6 Sylvain 2020-12-15 10:34:59 UTC
Maybe we can still add the function for 2.14 release,
but bind with the SW Renderer after ?
Comment 7 Stas Sergeev 2020-12-15 12:53:02 UTC
IMHO that would be a very good decision.
Fedora, even rawhide (development branch)
still has 2.0.12 (which doesn't even have
the proper KMS rendering, which is in 2.0.13).
Waiting the adoption of 2.0.15 will take
many years!

Besides, the scaler code will only be activated
on user's demand (by the use of SDL_HINT_RENDER_SCALE_QUALITY
hint), which means the existing code will
unlikely to be affected.

I'll be very grateful if this landed in 2.0.14.
Because even then I'll likely have to wait
for an year or so...
Comment 8 Sam Lantinga 2020-12-15 17:04:02 UTC
We're in code freeze right now and are not adding any new features for release.

Stas, is there a reason you can't ship a custom SDL library with your project?
Comment 9 Stas Sergeev 2020-12-15 23:23:24 UTC
> Stas, is there a reason you can't ship a custom SDL library with your project?

I am not sure how can this be done.
Static linking?
Building sdl as an internal git sub-module?

Hmm, I can think of one work-around.
You can add SDL_SoftStretchLinear() that
will just call old SDL_SoftStretch() and
do nothing more (no new feature, no new code).
And I can re-define that function with
the new code from patch. If you build
libsdl w/o -Bsymbolic flag, the symbols
can be overridden.
Comment 10 Sylvain 2020-12-23 20:51:00 UTC
So, I've added the SDL_SoftStretchLinear()
in https://hg.libsdl.org/SDL/rev/0c32de1a7fbf
(After splitting SDL_SoftStrech() in https://hg.libsdl.org/SDL/rev/e70a0440e99f )

you can give a try, it should quite fast since there are neon and see optimized routines.

maybe it won't compile because clang has issues with inline, so you need to mess with this define
https://hg.libsdl.org/SDL/file/0c32de1a7fbf/src/video/SDL_stretch.c#l447

I used pixman and SDL_rotozoom before, I end-up validating this code to pixel match pixman outputs.

It still need to be binded with the software renderer:
could be done easily with reading scale quality hint.
but the correct way should be to read the per texture scale quality field.
but SDL_LowerBlitScaled (in SDL_surface.c) doesn't transfer this information
 ... there is some renaming to do ... I won't do that right now.
Comment 11 Sylvain 2020-12-23 20:54:44 UTC
Created attachment 4600 [details]
test app

Some test app to scale and interact with various parameters.
run with an image as a param, press h for help.

You can change rect size, position for src and dst surfaces, while scaling.
Comment 12 Sylvain 2020-12-23 20:56:18 UTC
Oops forgot to run gendynapi.pl, thanks Ozkan !
https://hg.libsdl.org/SDL/rev/74ba009b45f5
Comment 13 Sylvain 2020-12-23 22:26:48 UTC
clang, via sdl-ios-xcode build bot fails to compile SDL_stretch.c 
( https://buildbot.libsdl.org/#/builders/11 )
but on a real Mac with xcode 12 it compiles ?
how to fix it / which clang version the build bot use ?
https://hg.libsdl.org/SDL/file/0c32de1a7fbf/src/video/SDL_stretch.c#l447
Comment 14 Stas Sergeev 2020-12-23 23:03:01 UTC
> ... there is some renaming to do ... I won't do that right now.

I tried and also looked at the code, and
it doesn't seem like this new code is ever
called by the renderer, no matter of the
scaling hint.
Which is probably exactly what you say.
Just confirming.
Please ping when the renderer part can be tested.
Comment 15 Sylvain 2020-12-24 09:02:14 UTC
Indeed, this isn't binded with the software renderer.

you can't test it manually here,
by changing the Strech to StrechLinear

https://hg.libsdl.org/SDL/file/3bea8b825fcd/src/video/SDL_surface.c#l917

Also, this only work with surface with BPP 32
(it can crash because the previous function allow 8/16/24/32 bpp, so it needs some manual check with format bpp field)
Comment 16 Sylvain 2020-12-27 19:31:37 UTC
Scale mode is now forwarded to the software renderer: 
https://hg.libsdl.org/SDL/rev/02f670c66eed

But it only works with simplest blits (no blending), 32 bits, no ARGB2101010,
and the video output format should be same as the surface format.
Comment 17 Stas Sergeev 2020-12-27 20:14:58 UTC
Thanks, I can confirm that it works perfectly for me!
It doesn't even blur the default size when no scaling
is needed, which is very good (some other libs I tried,
blur the picture even if resize is not needed).

This all makes me quite motivated to try and fix #5341,
as SDL is really becoming very usable these days.
So lets see if I can do that...
Comment 18 Sylvain 2020-12-27 20:49:10 UTC
Ok great so I marked this as fixed ! 
Just wondering, OpenGL isn't working x11 ?
Comment 19 Sylvain 2020-12-27 20:49:35 UTC
marked as fixed
Comment 20 Stas Sergeev 2020-12-27 20:52:26 UTC
(In reply to Sylvain from comment #18)
> Ok great so I marked this as fixed ! 

I thought you would extend it a bit, for not only 32bpp,
to format conversion etc? :)

> Just wondering, OpenGL isn't working x11 ?

No, not for me.
I have a threaded renderer, which is a no-no with openGL.
Still waiting for SDL to support vulkan rendering. :)
Comment 21 Sylvain 2020-12-27 22:04:35 UTC
ok :) so here's a fallback for other modes and formats:
https://hg.libsdl.org/SDL/rev/942819bd5deb
it uses an intermediate surface to do the linear scale, 
them do a non scale blit!

please give a try !
Comment 22 Sylvain 2020-12-27 22:26:04 UTC
it's actually buggy because it doesn't handle format, so I'll rework that !
Comment 23 Stas Sergeev 2020-12-27 22:39:50 UTC
It wouldn't be straight-forward test for
me as I always use the native format for
speed-up. Of course I can make a hack or
2 to test the format conversion. :)
Comment 24 Sylvain 2020-12-27 23:00:11 UTC
I have updated the fallback: 
 https://hg.libsdl.org/SDL/rev/5bab4dabaf08

but it's isn't fully tested. Yes please give a try with 
an non fast format, and with/without blending
Comment 25 Stas Sergeev 2020-12-27 23:08:33 UTC
I can see a few white-space errors in
your last patch.
Comment 26 Stas Sergeev 2020-12-27 23:38:01 UTC
I tried a few non-native formats (RGBA8888, RGB888, ARGB888)
and all seems well!
Comment 27 Sylvain 2020-12-28 09:42:50 UTC
ok great, thanks.
I have also tested some various combination and paths.

fixed indentation in:
https://hg.libsdl.org/SDL/rev/19613ce246db
Comment 28 Sylvain 2021-01-02 08:56:34 UTC
Created attachment 4626 [details]
test app

Improve the test app

For the record, 
add check for input format:
https://hg.libsdl.org/SDL/rev/0c1b34c8cb23

revert from bug #2687 and #3340
https://hg.libsdl.org/SDL/rev/1889c850fafc