Factor-2 Contour Stencil Interpolation
  Pascal Getreuer 2009

This package is a C++ implementation of factor-2 contour stencil interpolation, a fast edge-adaptive image interpolation method. The implementation follows the fast algorithm described in section 3.3 of

P. Getreuer, “Contour stencils for edge-adaptive image interpolation.” Proc. SPIE, vol. 7257, 2009.

License

Permission to use, copy, or modify c2xinterp.cpp and its documentation for educational and research purposes only and without fee is hereby granted, provided that this copyright notice and the original author's name appear on all copies and supporting documentation. This software shall not be used, rewritten, or adapted as the basis of a commercial software or hardware product without first obtaining permission of the author. The author makes no representations about the suitability of this software for any purpose. It is provided “as is” without express or implied warranty.

Compilation

Compilation requires the libpng and zlib libraries, freely available at www.libpng.org. The libpng library is used by the CImage class (image.cpp and image.h) for reading and writing PNG files. The interpolation code itself (c2xinterp.cpp) does not depend on any libraries.

A makefile is included for compilation with GCC. Type “make” to compile.

Usage

Compilation produces a simple command-line interface program c2xinterp. The program takes two arguments, an input PNG file and an output PNG file.

Syntax: c2xinterp in.png [out.png]

If no output file is specified, the result is written to “out.png.”

C2xInterp_RGBA

The interpolation code itself is in c2xinterp.cpp, and the interpolation function is C2xInterp_RGBA:

void C2xInterp_RGBA(const uint32_t *wpSrc,
   int iSrcWidth, int iSrcHeight, int iSrcStride,
   uint32_t *wpDest, int iDestStride)

C2xInterp_RGBA interpolates an RGBA color image by factor 2. The arguments are

wpSrcPointer to the source image data in RGBA format
iSrcWidthSource width in pixels
iSrcHeightSource height in pixels
iSrcStrideSouce stride between successive scanlines
wpDestPointer to where to store the interpolated image
iDestStrideDestination stride

In detail, wpSrc points to a buffer of size at least iSrcHeight×iSrcStride, where each element represents one 32-bit RGBA pixel. Similarly, wpDest points to a buffer with size at least 2×iSrcHeight×iDestStride of RGBA pixels.

The stride (or pitch) is the distance in memory between a given pixel and the pixel below in the next scanline, counted in 32-bit words. If there is no excess memory between the end of one scanline and the beginning of the next, the stride is simply the image width,

iStrStride = iSrcWidth,
iDestStride = 2*iSrcWidth.

Using other stride values enables for example interpolating a rectangular subregion of an image.