Would You Like To Supersize It ? (Source Included)

BlitzMax Forums/BlitzMax Programming/Would You Like To Supersize It ? (Source Included)

dw817(Posted 2016) [#1]
Years ago I had a chance to see some vectored images scale up and down in a program on the Commodore Amiga. While it wouldn't take pixeled images, I wondered if it was possible to write code that would correctly slope jaggies in a picture that was pixel enlarged.

Sitting down on graph paper I drew a series of two boxes connected to each other by only their edge. I asked myself what could be done to improve it ? I couldn't see anything, there wasn't enough room.

So then I drew 8-boxes. One in a 2x2 block and the other also in a 2x2 block but connected diagonally just at the ending tip.

And then it came to me. To fix a jaggy I just need to create a crutch, and in my head I was very much thinking of the very item that you use to help you walk.

So I took my pencil and filled in the square just above and filled an additional one to the left of where they met in the middle, and there I had it. I fixed the jaggy and made a smooth slope !



Now for some reason in my coding, when I tried to fix the jaggy in the other direction it just made a mess on the screen. Fidgeting with it, I finally found a solution. If I go BACKWARDS, that is starting from the bottom-right-hand corner to the top-left-hand corner, it works ! And - I'm glad that fixes both of them.

Also I don't know - today is this considered a unique and original enlarging procedure ? It is, then please give credit if you use this code or method in your projects.

Enjoi !






AdamStrange(Posted 2016) [#2]
mmm, block looks good.
The most important thing here is the alpha channel - which has a real nasty halo on everything but the block enlarge

so using the sprite images everything would look real sh*tty apart from block!


grable(Posted 2016) [#3]
Seems to create similar results to all the other scalers out there.
They all work more or less on the same principle, of creating "tiles" out of 2x2 or similar patterns like a graphics filter.

Yours looks good in 2x though, as it still keeps some hard edges.
And the algorithm seems fairly simple, which is a plus :)
I guess the real test would be doing it in realtime hehe

For the others, I like Scale2x for keeping that pixelated feel and Hq2x for that more highrez look.
Those two also seem to handle scaling larger than 2x pretty well, many of the others tend to smooth out too much.
One that also looks good is xBR/xBRZ, but few use it.

Check out this page for some comparisons and algorithm info: http://www.datagenetics.com/blog/december32013/index.html
Note that EPX in that article is basically ScaleX.


grable(Posted 2016) [#4]
At first glance i thought it did scaling, but it only beautifies pre-scaled images.
And it seems to produce similar results to 2xSai and variants, which does produce artifacts in some instances. Still nice though :)

My test suite with a little more control. Moving, Zooming etc.



dw817(Posted 2016) [#5]
Trying out your code, Grable. Wow. Damn. That is REALLY neat ! :D It crashes in debug mode, but without it runs REALLY well ! There's quite a bit I can learn from reading what you wrote here too.

Adam Strange, yes, it's odd. Sprites create this weird halo effect when you use normal dither. I have no idea where it comes from.

Would be awesome if BlitzMAX had internal ALL filters for enlarging. Then I could compare 2xSai with mine. I think though 2xSai has a smidge of blur to it and likely added just at the right place.

. . .

I am trying out the XBRZ filter from the Scaler Testing Tool. Is this written in BlitzMAX and/or is the source code available for download ?

. . .

Looking I am seeing it is not scaling black. I guess there is no reason it shouldn't. Changed a few lines, seems to run better:

LINE 114
If c1 = c4 And c1 >= 0 And (c1 <> c2 Or c1 <> c3) Then


LINE 132
If c2 = c3 And c2 >= 0 And (c2 <> c1 Or c2 <> c4) Then

I know I can take out the C2 comparison entirely, but I want to leave it in, just in case there are problems or further comparison adjustments later.


grable(Posted 2016) [#6]
.


grable(Posted 2016) [#7]
I forgot to change Pitch into Format in DoublePixmap ;) so the assertion would always fire hehe. Fixed now.

EDIT:
Source to xBR/Z is here: https://sourceforge.net/projects/xbrz/files/xBRZ/xBRZ_1.4.zip/download
But its in C++, and NOT very pretty or easy to understand :(

EDIT2: Removed sample.
See post #10 for better comparison.


dw817(Posted 2016) [#8]
Hi Grable.

This last one is not very fair in comparison. If you zoom, you are showing what my 2x2 filter does in an already zoomed picture of 4x4 or 8x8 without taking into account working it up (2x2) one step at a time for each level as you did in the previous code.

"NOT very pretty or easy to understand" Coming from you it must be an absolute nightmare. I'll stick with BlitzMAX code 10quverymuch ! :)


grable(Posted 2016) [#9]
There is no extra scaling in this one, as the shader is locked.
But somehow it ended up being x3 for the shader not x2 as i initially though.

It probaby has something to do with the texture not being the same size as the image, as Max2D resizes them to fit power of 2 in both directions.

Updated the sample for a more true comparison, using x4 for your scaler instead.
Their pixels are not 100% the same size, but its close enough.

This again makes it slightly unfair towards the shader scaler though, as its more of an x3.1 or something.
It seems to be the same in most instances, only the scaling does weird things to the pixels, so counting them isnt straight forward.

EDIT: Seems im downscaling d817's x4 to x3 to fit the shaders x3. Havent been able to get the shader to do anything other than x3 either, as its dimensions does not fit what Max2D uses for some reason.
That is the reason dw817's look weird, as scaling x4 to x3 will produce artifacts.



grable(Posted 2016) [#10]
Heres an updated version with a proper Scale2x shader, for a real comparison :)
Press 1 and 2 to change left/right modes.

Now there isnt that much difference between the two, Scale2x keeps more detail in some cases and dw817_x2 smooths more in others.



Casaber(Posted 2016) [#11]
I only get an error on those. Any chance of some screenshots? I´m curious how they compare.

Scale2x:
ERROR: 0:4: Incompatible types (vec2 and vec4) in assignment (and no available implicit conversion)

Scale2x:
ERROR: 0:6: Invalid call of undeclared identifier 'textureSize'
ERROR: 0:7: Use of undeclared identifier 'tmp'
ERROR: 0:8: Use of undeclared identifier 'tmp'
ERROR: 0:10: Use of undeclared identifier 'uv'
ERROR: 0:11: Use of undeclared identifier 'uv'
ERROR: 0:12: Use of undeclared identifier 'uv'
ERROR: 0:13: Use of undeclared identifier 'uv'
ERROR: 0:14: Use of undeclared identifier 'uv'
ERROR: 0:17: Use of undeclared identifier 'p'
ERROR: 0:18: Use of undeclared identifier 'p'
ERROR: 0:18: Use of undeclared identifier 'B'
ERROR: 0:18: Use of undeclared identifier 'F'
ERROR: 0:18: Use of undeclared identifier 'B'
ERROR: 0:18: Use of undeclared identifier 'D'
ERROR: 0:18: Use of undeclared identifier 'F'
ERROR: 0:18: Use of undeclared identifier 'H'
ERROR: 0:18: Use of undeclared identifier 'F'
ERROR: 0:18: Use of undeclared identifier 'E'
ERROR: 0:19: Use of undeclared identifier 'H'
ERROR: 0:19: Use of undeclared identifier 'F'
ERROR: 0:19: Use of undeclared identifier 'D'
ERROR: 0:19: Use of undeclared identifier 'H'
ERROR: 0:19: Use of undeclared identifier 'B'
ERROR: 0:19: Use of undeclared identifier 'F'
ERROR: 0:19: Use of undeclared identifier 'F'
ERROR: 0:19: Use of undeclared identifier 'E'
ERROR: 0:21: Use of undeclared identifier 'p'
ERROR: 0:21: Use of undeclared identifier 'D'
ERROR: 0:21: Use of undeclared identifier 'B'
ERROR: 0:21: Use of undeclared identifier 'B'
ERROR: 0:21: Use of undeclared identifier 'F'
ERROR: 0:21: Use of undeclared identifier 'D'
ERROR: 0:21: Use of undeclared identifier 'H'
ERROR: 0:21: Use of undeclared identifier 'D'
ERROR: 0:21: Use of undeclared identifier 'E'
ERROR: 0:22: Use of undeclared identifier 'D'
ERROR: 0:22: Use of undeclared identifier 'H'
ERROR: 0:22: Use of undeclared identifier 'D'
ERROR: 0:22: Use of undeclared identifier 'B'
ERROR: 0:22: Use of undeclared identifier 'H'
ERROR: 0:22: Use of undeclared identifier 'F'
ERROR: 0:22: Use of undeclared identifier 'D'
ERROR: 0:22: Use of undeclared identifier 'E'

Scale2x:
ERROR: One or more attached shaders not successfully compiled


grable(Posted 2016) [#12]
This depends on which version of GLSL your driver defaults to. My AMD drivers default to the highest supported by the gpu, well sortof. It is probably still 1.10 but with all extensions enabled.
Nvidia may not be as permissive.

textureSize and texelFetch came in 1.30 which is rather old by modern standards. But if your on older Intel gpus (like netbooks) you might be stuck at 1.10 :p

Try sticking #version 130 compatibility at the top of the GLSL code.
If that doesnt work, try 150 which supports the full extensions to the functions (even though i dont use those).

EDIT: Added #version 130 to the sample above, so you dont have to ;)

Check out https://www.opengl.org/wiki/Core_Language_%28GLSL%29 for more info on OpenGL vs GLSL versioning.

Some screens if you still cant run the GLSL code.
dw817_x2 vs scale2x
dw817_x2_2 vs scale2x_2

EDIT: Made images into links, they were too big.


dw817(Posted 2016) [#13]
Works great here, Grable. No errors at all. I can see my filter does not leave a dangler. That's what I'm going to call it. Any pixel that is left from a triangle. Mine smooths it out whereas the Scale2x filter does not and it sticks out ugly.

Mine also smooths too much whereas Scale2x sometimes smooths too little.

So - I could certainly see if it's possible to make improvements to my formula. :)

Casaber, I get no errors at all. If the variables aren't being recognized or something, maybe take out Superstrict so they don't need to be defined ?


grable(Posted 2016) [#14]
The error is GLSL related, the shader langauge.
Im guessing he has an Nvidia gpu, as their GLSL compiler is way more strict than AMD. AMD is almost too permissive in what i allows sometimes.

Im hoping manually setting the version helps, but there can be more incompatibilities.. So let me know of any errors and i will fix them :)

Yeah, the quality all depends on the art. I use many different scalers for the different emulators and their games.

I made a complete package including images and external glsl files for easier hacking (made it for a friend but posting it here as well)
ScaleShader.7z press F1 for help.


dw817(Posted 2016) [#15]
Hi Grable. Trying out your ScaleShader. Yes ! This is great. I can definitely see a good comparison now. Hit SPACE to show a new picture. Mouse Scroll to scale and keys "1" and "2" to change filters.

Looks like the best images for the scaler I wrote is RPG sprites, and that's fine with me. I can definitely work that into future code.


Casaber(Posted 2016) [#16]
Thanks, and that looks great.

Are those the same or similiar as this one seem to have got hefty headlines of being groundbreaking?
http://www.extremetech.com/gaming/84040-depixelizing-pixel-art-upscaling-retro-8bit-games


Casaber(Posted 2016) [#17]
Really love this. It's so much fun to follow this forum when these kinds of quality things pops up. Great work.


dw817(Posted 2016) [#18]
Hi Casaber. Yep, but I don't think mine is so groundbreaking. Let me see if I can reproduce that fish output.

...

Nope. That's a nice bit of rescaling they are doing there. I can't reproduce to that quality, not w my current code.

Other items look good with it though, as long as you don't scale too high.



Latest filter, big improvements !




dw817(Posted 2016) [#19]
Hi Grable:

Here is your scaler using an alternative method I'm trying. Instead of reading pixels for what got modified it only reads pixels from an unmodified source and saves to a final result picture.

Thus it won't build pixels developed from previously changed ones.

Here is the code:

WOAH ! Wait a sec ... this should be a dramatic improvement ... changing the code a bit, working ...

Okay, here it is. Try the "ALIEN.PNG," the gun muzzle is a perfect slope !
Also permanently removes the 'half pixel' artefact.




dw817(Posted 2016) [#20]
Here is one that keeps stray pixels at the cost of blurring others.



While I'm not very fond of it, you can certainly figure it into the other methods I've already written.