Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: HQx Magnification Filter  (Read 4622 times)

0 Members and 1 Guest are viewing this topic.

LB

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
HQx Magnification Filter
« 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:

Code: [Select]
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:

Code: [Select]
#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)

   

           

This is my first open-source code. I got the HQx code from here, 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

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
HQx Magnification Filter
« Reply #1 on: August 12, 2011, 01:47:21 am »
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
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: