2 Pass Scaling using Filters

Scaling sample:

Unlike traditional scaling of images, where every n'th pixel is sampled and copied to the result image, this template provides much more accurate image scaling features.

It takes a buffer of RGB values (as COLORREFs) and creates another buffer with new dimensions. The input / output buffers are sequential pixels (not compressed) compatible with the format used in 24-bit DIBs.

The template is instantiated with a specific filter. The filter determines the quality of the output image. Different basic filters are supplied with this template and additional filters can be easily added.

Major features:

  • Provides professional quality image scaling.
  • Code is optimized for image quality, not speed.
  • Supports various image filters:
    • Box filter.
    • Bilinear filter.
    • Gaussian filter.
    • Hamming filter.
    • Blackman filter.
    • ...New filters can be easily added.
  • Supports both magnification and minification.
  • Does not force aspect ratio limitations. e.g. an image can be magnified horizontally and minified vertically.
  • Supports 24-bit images. With little change can support other image formats / depths.
  • Template based - no need for libraries, DLLs etc. No linkage problems.

How to use the scaling template:

Assuming you have a non-compressed true-color 24-bit DIB in memory (the bits array is pointed by m_pBits), where the original bitmap width is m_dwWidth and height is m_dwHeight.

Your code should look something like this:


#include <2PassScale.h>

...

void CMyDIB::ScaleTo (DWORD dwNewWidth, DWORD dwNewHeight)
{
    C2PassScale <CBilinearFilter> ScaleEngine;

    COLORREF *pOldBitmap = m_pBits;

    m_pBits = ScaleEngine.AllocAndScale (   m_pBits,
                                            m_dwWidth,
                                            m_dwHeight,
                                            dwNewWidth,
                                            dwNewHeight
                                        );
    if (NULL == m_pBits)
    {
        //
        // Handle errors here
        //
    }
    m_dwWidth = dwNewWidth;
    m_dwHeight = dwNewHeight;
    delete pOldBitmap;
}

//
// Alternatively, if you already have a pre-allocated destination buffer
// in the new size you can call ScaleEngine.Scale (...) and give it that buffer
//

Download source - 3.5 KB



Comments

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds