2xSaI : The advanced 2x Scale and Interpolation engine

Last updated Aug 2 2001

2xSaI is Copyright (c) 1999-2001 by Derek Liauw Kie Fa.

2xSaI is free under GPL. I hope you'll give me appropriate credit. If you want another license for your (free) project, contact me.




February 8 2002

Ok, now it seems xoom.com died as well, and so are all the links. Unfortunately i didn't have a backup for 2XSAIUT.ZIP, so this is what I could gather. Click here-> 2xSaI_sources.rar  <- . It contains the original old sample DOS Djgpp/Allegro code (and is the exact code used in Snes9x DOS), with sample mmx asm linking. Only problem now is, that I updated the 2xSaImmx.asm from the ZSNES sources, because I added an MMX version of Super2xSaI (yes, regardless of what the comments in 2xSaI.cpp say; you'll have to figure that one out yourself ;-). As far as I know you need to redefine/replace the NEWSYM macro, so it makes the functions visible outside the object. (similar to extern "C" {} ).

As for correctness, robustness etc etc of the code. My friend Bob (yes, just Bob) took care of some bounds checking etc.. And made it compile in MSVC as well. I haven't checked it out yet, but you can download it on his webpage here -> http://pages.infinit.net/voidstar/ <-.

Now another thing. About  Exult. I've been trying out some new stuff, but it seems the guys @ Exult either don't like my filter (proposed name 'Bilinear Plus'), or they compeletely forgot to add it (it's been over a month or two now since I proposed it). So here are the modifications needed to see it. In scale.cc under the function 

void Scale_2xBilinear { } find the line which is 

// upper left pixel in quad: just copy it in
//*to++ = manip.rgb(*ar, *ag, *ab);

and replace with

*to++ = manip.rgb(
(((*ar)<<2) +((*ar)) + (*cr+*br+*br) )>> 3,
(((*ag)<<2) +((*ag)) + (*cg+*bg+*bg) )>> 3,
(((*ab)<<2) +((*ab)) + (*cb+*bb+*bb) )>> 3);

or alternatively with 

*to++ = manip.rgb(
(((*ar)<<3) +((*ar)<<1) + (*cr+*br+*br+*cr) )>> 4,
(((*ag)<<3) +((*ag)<<1) + (*cg+*bg+*bg+*cg) )>> 4,
(((*ab)<<3) +((*ab)<<1) + (*cb+*bb+*bb+*cb) )>> 4);

This effectively demonstrates the new filter without too much work. It's like a  TV effect, if I do say so myself :-). Unfortunately I don't have time etc, to create seperate functions and gumps are whatever they call it (so it shows up properly in the Exult GUI). So if you like it, see if you can add it yourself, or pester the main programmers :-).


August 2 2001

Since netaddress.com started to charge money for their services, my e-mail address has changed... You can now reach me at DerekL666@yahoo.com, or ICQ. The last C/C++ for DJGPP/old dos allegro source can be downloaded from http://members.xoom.com/derek_liauw/2XSAIUT.ZIP. It's 'last' since I'm not really working on it anymore.. And you probably noticed there's no "versioning" anymore, since I've gotten feedback from zsnes/snes9x users who prefered older versions etc..so I decided to just give them different names ... 2xSaI, Super2xSaI, and SuperEagle, my favorite being Super2xSaI... See link above for C/C++ code...  For some (open source) projects  which have implemented the code sucessfully see the links section. They may or may not have updated versions, customizations done by either me, or someone else.. 2xSaImmx.asm has been updated to reflect changes done by myself in the ZSNES source. All 3 different engines have equivalent MMX versions now..  (ZSNES is currently the only project I know of which is currently up to date, regarding the MMX versions.. Snes9x afaik has an older 'graphically bugged' Super2xSaI mmx version). Projects which only use C/C++ versions are probably up-to-date. 

Miscellaneous stuff.:

Check out a severely unfinished (not so multiplayer) Snake game written in Java.. http://members.xoom.com/derek_liauw/games/Snake.html I gave up on the synchronization issues.

The links section has been updated a bit.


May 3 1999

I managed to merge the 2 engines afterall (sort of). The graphics are just aweome :o) Really smooth AND really sharp!! Ahh.... the wonders of anti-aliasing. Stay tuned for Snes9x 1.19 DOS which will (99% likely) have the new engine (v 0.70 C and MMX) implemented.

BTW Notice the Incredible Shrinking Chrono above. 2xSaI is good for 2x, not so good for 4x ;o(.

If you're wondering what it looks like, you're in luck. The screenshot and utilty are updated !!! The source code and utility docs are not (yet).


April 27 1999

Started on a new engine (again). This time it's an Eagle clone using some 2xSaI stuff in an effort to combine the engines (read on further below for an explanation). I haven't scrapped the other new engine; just seeing which one looks better. Both new engines look good (better than the old one !!), have their pros and cons, but most of the time it's just personal opinion (mine), so I may be doing 2 engines instead of one for the next version.

So here I am, thinking I'm doing completely new writing 2xSaI, and what happens?, I wind up remaking Eagle... argh.

Because of the way 2xSaI works, the engine (all versions) has some problems in cases where 2 lines intersect. I made a huge (slow) routine to solve that problem, but it doesn't always work right. Eagle doesn't really have that problem, since it works differently (image enhancement, rather than image reconstruction), so I thought maybe if I combine both engines the problem would dissappear !!! Unfortunately combining the engines seems impossible :o(

Some screenshots using both engines will be put up soon. I'm just too lazy to do it (webpage editing is just not my thing), and I just can't seem to make good screenshots.


April 16 1999

Started on a new engine today (should be doing my biology report, instead of this...), totally from scratch. It doubles the pixels vertically, and an adapted (rewritten) 2xSaI does the rest horizontally. The bluriness is virtually all gone !! Have to readd 8 patterns, and I think the next version will be ready.


April 13 1999

Putting up some source code. You can just plug em in snes9x (dos / linux). Still no "generic" version though.

Get it at the download section.


Back to Top

What is 2xSaI ?

Images rendered by most emulators are lo-res, and when put on a hi-res monitor, the image is either really small, or really blocky when stretched.
Today's computers are fast, so why not use some of that horsepower to make a beautiful, big, scaled image from the small one???

2xSaI tries to do just that. I wasn't quite satisfied with Eagle (another good engine with similar goals), so I started with my own engine, 2xSaI.

2xSaI is a one-pass engine which scales bitmap images by a factor of 2, while trying to keep the orginal smoothness and brightness of the original bitmap (in other words: reducing blockiness and bluriness to a minimum). 2xSaI borrows some ideas from Dirk Stevens' Eagle Engine, but is (fundamentally) a lot different. It was originally created for (and is currently used in the dos port of) my favorite emulator, Snes9x. At the moment it only processes 16-bit images, but that will probably change in the future.

2xSaI is still in development (when I have time). If you have any bright ideas, just let me know, and I'll see what I can do.


Back to Top

How does it work?

2xSaI doesn't use conventional methods to scale images. 2xSaI detects certain color patterns (actually just lines and edges) in the original bitmap. A 2x scaled image has 4 times the amount of pixels of the original one. Of those one is directly taken from the source bitmap. The other 3 pixels are "guessed", using the patterns I mentioned earlier.

A better document describing how 2xSaI works has yet to be written (when this 17 year old has some more time)...

For now check out the screenshots section or download the 2xSaI utility to see how it looks!!

Back to Top

Can it be used in an emulator ?

It certainly can !!

Snes9x 1.18 Dos uses version 0.40 of 2xSaI and runs at decent speed on my K6-233, and with MMX-optimization enabled (my own built version, not released) it runs even faster!!

Emu authors can contact me if they're interested in implementing the 2xSaI engine.

Back to Top


Click on the thumbnails to see the the full-size images generated by 2xSaI!!

Be patient. Wait for the whole image to load. The images are about 40 - 120 k each. At first the image will seem blocky, but it will get (a lot) better as the image loads. (stupid GIF format)

Chrono Trigger

Final Fantasy 3/6j

Killer Instinct


Lufia 2


Super Metroid 3


Super Mario Kart

Secret of Mana

SuperStreetfighter 2


SuperStreetFighter 2

Tales of Phantasia

Thanks to NeoTuxedoMask




Back to Top

Version History

Scrap this... it's outdated.. (see news aug 2, 2001).

v0.10 - Initial version. Detects 2 patterns. Already a significant improvement !
v0.20 - Extended those 2 patterns: 8 more added.
v0.30 - Some shapes didn't look right. Added some checking to correct that. Some loss of brightness (and speed), but ______looks OK now.
v0.40 - Thin lines (text) didn't come up well.. Fixed that (2 more patterns).
v0.40x - Finished the MMX version!!
v0.50 - Added a row sharpen filter every other line to increase overall brightness and contrast.
______I've decided to call the engine 2xSaI.
______The name might change again (soon)
v0.50x - Updated MMX version to 0.50.

Back to Top


2xSaI.zip :   //older version

2xSaI_sources.rar: // newest version which includes sample C/asm source to 

This DOS utility produces a 2x scaled image from PCX and BMP files using the 2xSaI engine (It outputs to PCX or BMP files). Great for blowing up some screenshots for webpages.

Note that the engine works best on "drawn" graphics (SNES, NES etc). Letting it process photographs is usually just a waste of time. Dunno about computer generated graphics though.


Source Code

See above for C/C++ versions.. 

2xSaImmx.asm - MMX version of the code. Define __DJGPP__ if using DJGPP. Note that register fs, is NOT restored. (laziness on my part..). If you don't define DJGPP the code will not use a far pointer (for the linux version), so you might lose data if you're not careful.

There are different function prototypes for _2xSaIline() (with and without far pointers) depending on that define.

Any questions? Just mail me, and I'll try to answer em.

If you can get it working on other emulators, please tell me !!

Back to Top

Related Links

Unrelated/personal links.. 

And pry lots more.. but I can't think right now (if you feel you need to be listed, e-mail me) ;)

Back to Top

Contact Information

Electronic mail address

Web address



Back to Top

2xSaI is Copyright (c) 1999-2001 by Derek Liauw Kie Fa.

2xSaI is free under GPL, I hope you'll give me appropriate credit. If you want another license for your (free) project, contact me.

Last revised: February 08, 2002.