2xSaI and other filters

0 favourites
  • Sometimes you discover that the images you have made for your game are too small for your purposes. For example, you decide to switch from an old-school 320x200 style to something allowing more details. Or you use sprite rips as placeholders, but the resolution of the rips is lower than you'd like.

    There are numerous ways of addressing that, ranging from the standard bicubic filtering found in most image editors and to Genuine Fractals, $160 Photoshop plugin.

    There are, however, several lesser-known options.

    Well, who am I kidding, most of us used an emulator at least once, so most people already know what filters like 2xSaI or SuperEagle do.

    Anyway, here's a bunch of such filters:

    • Scale2x - despite what the name suggests, it allows 2x, 3x and 4x scaling. Also it respects alpha, if only 1-bit.
    • HQ2x - honest 2x scaling here. Probably the best real-time scaling algorithm there is right now.
    • HQ3x - same as the above, only 3x. The page contains the explanation of the algorithm.
    • HQ4x - same as the above, only 4x. Just like it's 'smaller brothers', doesn't support alpha.

    Here is a sample of Scale2x:

    <img src="http://img528.imageshack.us/img528/3739/scale2d.png">

    and here's HQ3x:

    <img src="http://img22.imageshack.us/img22/3564/hq3x.png">

    There's also good old 2xSaI, with SuperEagle bundled with it, but you'll need to compile those manually.

    Of course, no algorithm can add detail to your image, but at least the filtered sprites are a good starting point for further tweaking.

    Anyway, filters from the list are downloadable as executables, but those only allow processing a single file at a time, which is a pain if you have a lot of files to enlarge.

    I made a simple script to automate such tasks.

    It takes a name of a filter and a folder name and runs all the images in that folder through the specified filter. It is really dumb, it only processes files of a fitting format (tga for HQ?x, png for scale2x. HQ?x also allows bmp, but only 24bpp, I think, so I only allow tga just to be sure it processes it without errors), and it will processes all such files in a folder. Have some files that don't need enlarging? Move them somewhere else. It also doesn't have any kind of GUI and is purely commandline. Also, it relies on the aforementioned exe files, but it doesn't even check for their presence. It simply passes strings for the shell to execute.


    As I said, it takes two parameters: first one is a filter name (scaler2, scaler3, scaler4, hq2x, hq3x or hq4x) and a folder name. If you run it without parameters, it will use scaler2 on the folder you run it from. If you run it with just one parameter it will use it as a filter name, and apply this filter to the current folder.


    You should put the filter exes (and all they need to run, namely libpng.dll and zlib.dll for the scalerx) in the same folder as my script. It uses scalerx.exe, not scaler.exe, by the way.

    The folder will contain the following:

      batchfilter.rb (or batchfilter.exe, if you use the "compiled" version) hq2x.exe hq3x.exe hq4x.exe libpng.dll scalerx.exe zlib.dll

    Let me say this again: the script does not check if those files are present. You have been warned.

    Anyway, without further ado, here's the script:


    It is written in Ruby, so you'll need a Ruby interpreter to run it. If downloading 25Mb for a tiny script doesn't sound like fun for you, you can use the exe version:


    It's quite large (1.5MB), since it basically contains a Ruby interpreter plus the original script, but it's still smaller than 25Mb, right?

    Anyway, I really hope that someone sees merit in it and rewrites it in C or something, so it's not so horribly bloated.

  • Looks a bit like GreyCstoration


  • I'm sure modern GPUs are powerful enough to run these filters dynamically, if they are written in a shader. Construct only supports shader model 2 at the moment though, and DirectX 9 only supports up to PS 3. I wonder if anyone's managed to put these filters in a shader yet, and if so, what shader model is necessary.

  • I don't think these filters really need shaders, they've been in things like console emulators with no hardware acceleration for years. Filters like 2xSaI and such are meant to be real-time filters.

    But making a shader maybe would benefit it? I dunno.

  • Running effects in software doesn't really work particularly well with DirectX: you start to have to move graphics data between the GPU and CPU every frame, which is very slow.

  • Looks a bit like GreyCstoration


    Well, for resizing they seem to use something similar to anisotropic diffusion. Anyway, it is intended for photos, and therefore not very good for sprites, as it makes 'em only slightly less blurry than bicubic. HQ?x and the likes, on the other hand, keep the colors crisp and the outlines sharp. Well, none of these filters are perfect anyway...

  • Personally I kind of like it, sort of a cross between watercolors, and oils.

    Might be a nice stylization for a game, something different anyways.

  • This whole discussion is widely overlooked though it's been so widely used in emulators for years. If they can do it in real time with emulators, why hasn't someone more tech savvy not tackled this?

    I may want to learn python just to find a way to write a script. It makes games look way nicer and could be the deciding factor in the future of 2D gaming.

  • I think the issue is the flow of information. A cpu has no problem running the filter, but the filter needs to be run after the screen has been drawn. If I'm not mistaken, the flow of data goes CPU to GPU to monitor. To run the filter, you'd have to send the data from the CPU to GPU, back to the CPU to run the filter, back to the GPU again and then to the monitor. Your framerate would take a HUGE hit.

    The reason emulators and such can do it is they're using software rendering via the CPU - the graphics card isn't doing the rendering like construct does. Unless it can be coded as a pixel shader and therefore runs on the card, or construct gets a software renderer, it's not efficient in the slightest.

  • It would be nice then to see if someone can design a pixel shader to do it.

    On that topic, is there any pixel shader that already is in construct that makes low res images look nicer and more smooth?

  • That'd be "crispify" effect.

  • I like how HQ2x looks but since it blends the edges of pixels with the background it is really only useful as a realtime filter.

    Or you could just place all of your sprites on a black background... but that leaves them with a thick outline (which doesn't always look bad, depending on what style you're going for).

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • These filters are run on source images to bump the resolution.

    They're slow and they don't make sense if you've already scaled the source material (as neighboring pixels will change so will inferred slope), so it's not a good idea to implement them as a shader.

    That said, they ARE a nice thing to have. Perhaps as an action? (duplicate frame/animation resolution with 2xSaI, etc) or better yet in the IDE?

  • As I said before, this would probably be fast implemented as a shader, but I haven't seen any shader implementations of this anywhere. Do they exist? There's no point doing it in software since transferring data between VRAM and system RAM for CPU drawing is really slow.

  • Googling for 2xSai, shader and dx9 returned this very thread.

    Anyway, if you omit dx9, you'll find some shader attempts on Pete's board, ngemu and dosbox sites. All require PS3.0, I am afraid, but I haven't checked thoroughly. Here is one, some might be PS2.0:


Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)