SFML community forums
General => SFML projects => Topic started by: LB on August 12, 2011, 01:16:02 am
-
This is a extension to apply the HQ2x/HQ3x/HQ4x algorithm with SFML images. The interface is pretty simple, with this methods:
namespace sfe {
using namespace sf;
// Initializes the HQx algorithm. Takes about one second and 64MB of RAM.
// This is called automatically by the methods below, if necessary.
inline void InitHQx();
// Receives a sf::Image and returns a 2-times bigger sf::Image, using the
// HQ2x magnification algorithm.
Image HQ2x(const Image& input);
// Receives a sf::Image and returns a 3-times bigger sf::Image, using the
// HQ3x magnification algorithm.
Image HQ3x(const Image& input);
// Receives a sf::Image and returns a 4-times bigger sf::Image, using the
// HQ4x magnification algorithm.
Image HQ4x(const Image& input);
}
Here's a code sample:
#include <SFML/Graphics.hpp>
#include <SFE/HQx.cpp>
int main() {
sf::Image img, hq2x, hq3x, hq4x;
img.LoadFromFile("test.png");
sfe::InitHQx(); // Unnecessary
hq2x = sfe::HQ2x(img);
hq2x.SaveToFile("hq2x.png");
hq3x = sfe::HQ3x(img);
hq3x.SaveToFile("hq3x.png");
hq4x = sfe::HQ4x(img);
hq4x.SaveToFile("hq4x.png");
return 0;
}
Samples: (HQ3x)
(http://www.hiend3d.com/img/test_nn.gif) (http://www.hiend3d.com/img/test_hq3x.gif)
(http://www.hiend3d.com/img/mailbox_nn.gif) (http://www.hiend3d.com/img/mailbox_hq3x.gif) (http://www.hiend3d.com/img/randam_nn3x.png) (http://www.hiend3d.com/img/randam_hq3x.png)
This is my first open-source code. I got the HQx code from here (http://code.google.com/p/hqx/), and I did some modifications in it to make it working with 32-bit colors. Also, don't try to use it with images that has some pixel with alpha channel other than 255.
Download link: Click Here (http://dl.dropbox.com/u/18473445/SFML_HQx.zip)
-
Very nice! :)
I read the Wikipedia article about HQx some time ago, and I also had the idea to implement this algorithm in SFML. Up to now, I haven't had the time to do so. Don't you want to announce the project on the Wiki?
Unfortunately, your project doesn't compile on Visual Studio 2010.- It contains C code that is incompatible to C++, for example ambigous calls to overloaded abs() functions. labs() works however (I hope long is the right type...).
- The keyword not instead of operator! is not supported by the Microsoft compiler
- uint32_t is not declared, use sf::Uint32 instead
- The files hq2x.c, hq3x.c and hq4x.c don't compile on their own, you should probably make them to headers instead