home :: CxImage::

About me


Description: Another free C++ image processing and conversion library
Platform: Windows / Linux
License: zlib
Release: 6.00
Last update: 02 Feb 2008



CxImage is a C++ class that can load, save, display, transform images in a very simple and fast way.

CxImage is open source and licensed under the zlib license. In a nutshell, this means that you can use the code however you wish, as long as you don't claim it as your own.

With more than 200 functions, and with comprehensive working demos, CxImage offers all the tools to build simple image processing applications on a fast learning curve. Supported file formats are: BMP, GIF, ICO, CUR, JBG, JPG, JPC, JP2, PCX, PGX, PNG, PNM, RAS, SKA, TGA, TIF, WBMP, WMF, RAW, CRW, NEF, CR2, DNG, ORF, ARW, ERF, 3FR, DCR, X3F, MEF, RAF, MRW, PEF, SR2.

Cximage is highly portable and has been tested with Visual C++ 6 / 2008, C++ Builder 3 / 6, MinGW on Windows, and with gcc 3.3.2 on Linux. The library can be linked statically, or through a DLL or an activex component.


CxImage is documented using Doxygen, however for historical reasons, many uncommon features are still undocumented. The class members reference, together with a short introduction article, release history, and license, can be found here


Image formats:
  • GIF, animated GIF
  • TIF, multipage TIF
  • JPG,
  • PNG,
  • JPC, JP2, J2K, PGX, PNM, RAS,
  • JBG,
  • WMF (read only)
  • RAW, CRW, NEF, CR2, DNG, ORF, ARW, ERF, 3FR, DCR, X3F, MEF, RAF, MRW, PEF, SR2 (read only)


  • Contour, Edge, Dilate, Erode
  • Median, Noise, Jitter, RedEyeRemove
  • Colorize, Gamma, Saturate
  • GaussianBlur, TextBlur, SelectiveBlur, UnsharpMask
  • Filter, Lut, Gamma, Light, Negative, Dither, Grayscale
  • Histogram stretch, equalize, normalize
  • Threshold, OptimalThreshold, AdaptiveThreshold


  • IncreaseBPP, DecreaseBPP
  • Crop, Expand, Thumbnail
  • Resample, Rotate, Skew
  • Mirror, Flip


  • Direct pixel and palette manipulation
  • Pixel interpolation
  • Colorspaces: RGB, HSL, CMYK, YUV, YIQ, XYZ
  • Repair
  • FFT2
  • Mix, Combine, Split
  • Save animated GIFs and multipage ICONs and TIFs
  • Read/Save in memory buffers
  • Alpha layer (transparency)
  • Selections
  • read/copy EXIF
  • automatic file type detection

What's new in version 6.00

The complete list of bugfixes and enhancements is reported in the documentation

An application written with CxImage version 5.99 should work also with the new version; the interface of few methods is different, normally because of new parameters, but the default behaviour is the same.
The applications linked with the old DLL will not work with the new one; but if necessary you can edit the declarations, or add new overloads, and revert to the old interface for the DLL.
An issue to take care is ENUM_CXIMAGE_FORMATS: in the old version the CXIMAGE_FORMAT_... can change the value, depending on the supported formats enabled by the corresponding CXIMAGE_SUPPORT_... switch. In the new version, CXIMAGE_FORMAT_... are assigned to unique values. Static methods like GetNumTypes, GetTypeIdFromName, GetTypeIdFromIndex, GetTypeIndexFromId will help the application to manage the new policy.

File formats & linked C libraries

CxImage works with the latest version of these libraries: Zlib (1.2.3), Jasper ( 1.900.1), LibMNG (1.0.10), LibPNG (1.2.24).
LibTIFF 3.8.2 can be linked with CxImage, but the version included in the CxImage distribution (3.5.7, patched) can read images with OJPEG compression, or with non standard bit per samples. The choice is up to you.
The j2k library (now openjpeg), and the associated class CxImageJ2K, have been removed from the project. JPEG2000 images are supported through Jasper and CxImageJAS.

CxImage 6.00 includes a new class (CxImageRAW) and a new library (LibDCR) to read RAW images from digital cameras; common file extension are: RAW, CRW, NEF, CR2, DNG, ORF, ARW, ERF, 3FR, DCR, X3F, MEF, RAF, MRW, PEF, SR2.
LibDCR is based on Dave Coffin's dcraw.c; and offers the same features of the original dcraw application (see the "dcr.dsw" project included in the \raw directory). The restricted features under the GPL Version 2 are disabled; please read the license terms in "libdcr.h" before enabling the restricted code.
CxImageRAW implements the basic functions to decode the image, the only available option controlled by SetCodecOption, is about the interpolation quality (DECODE_QUALITY_LIN=0, DECODE_QUALITY_VNG=1, DECODE_QUALITY_PPG=2, DECODE_QUALITY_AHD=3).

CxImagePNG has been improved to read and write all of the PNG_COLOR_TYPE_... combinations. PNGs with a "pixel depth" more that 8 bits per channel will be converted down to 8 bits, this is the major limit in CxImage.

CxImageGIF: better support for reading animated GIF, now can decode all frames in a single pass, if enabled with SetRetreiveAllFrames. The CxImage demo implements this option, and shows how to play an animated GIF (when the program asks "File with N images. Read all?", select "Cancel").

CxImageBMP: reads and writes 32 bit images (with alpha layer).
CxImageICO: reads and writes Vista (PNG) icons; and added support for writing multipage icons.
CxImageMNG: reads MNGs with alpha layer.
CxImageSKA: new class for SKA image format, used in some video rental application.

CxImageJPG: new options for the JPEG format subsampling (ENCODE_SUBSAMPLE_422, ENCODE_SUBSAMPLE_444), default is 4:1:1 (high), can be set to 4:2:2 (medium) or 4:4:4 (none).
The next table shows the different amount of artefacts in the compressed image, using to different subsampling. 4:4:4 subsampling is useful in images with sharp edges, to reduce the typical blurring effect of the JPG compression.

original image

JPG image and artefacts,
quality 75, subsampling 4:1:1

JPG image and artefacts,
quality 75, subsampling 4:4:4


The class and the projects have been tested with different compilers, from Microsoft VC++6 to VC++2008, with Borland C++ Builder 3 and 6, and partially with wxDev-C++ and MinGW.
UNICODE and non-UNICODE configurations are provided for all the libraries (thanks to Eric Jesover).

A light version without the C libraries and with a small demo is provided for the first time users, or as a basic template, without the clutter of the full demo project.

The console (\demo2) and the CxImageCrtDll projects can be built with VC++Express2005 and the Microsoft Platform SDK. If you get linker errors like "unresolved external...", check if all the C libraries have been compiled (set the correct project dependencies), or add the "gdi32.lib" and "user32.lib" modules to the "Linker\Input\Additional Dependencies" property.

CxImage works also with Pocket PC 2003; a working version and demo are provided for the VC++2005 compiler (thanks to Vincent Richomme). For the old embedded VC compilers, the main limit was the support for exception handling. To overcome this problem, the try, throw and catch statements have been replaced with 3 macros (defined in ximadef.h), and with the definition of CXIMAGE_SUPPORT_EXCEPTION_HANDLING; in this way it is possible to build the library without exception handling support. Maybe the solution is not so elegant, but the impact on the source code is minimal when exception handling is disabled, while there are no changes in case of exception handling enabled.

The compatibility between little-endian and big-endian platforms, for the built in formats (bmp, ico, tga, pcx, gif, ska) is handled by ntohs and ntohl.

New features

  • CQuantizer : the class is used with the DecreaseBpp menu. In the previous version there was a rounding error, clearly visible when in some case the white colour (255,255,255) was converted to (254,254,254). In the new release this error has been fixed.
  • Copy/Paste : now pastes also metafile pictures (for example, from Office applications). The demo internally uses a custom clipboard format, to test the Dump/Undump methods.
    Copy works on the active selection, use "\CxImage\Remove Selection" to copy the full image.
  • FloodFill : (\View\Tools\Flood Fill) with a floating dialog, you can test the FloodFill colour, tolerance, opacity, and selection. The case with opacity = 0 and selection enabled acts as a "magic wand".
  • Graph data extraction : (\Filters\graph data extraction) extracts the numeric data from graphs (acquired from scanners or downloaded from the internet). The converted values are pasted into the clipboard, and can be saved to text or Excel files.

  • RedEyeRemove : (\Filters\Non Linear\Remove Red Eye) removes the red-eye effect that frequently occurs in pictures. You must select the region around the pupil, where the function will filter the red channel, the selection can be also rectangular, or including part of the iris: the filter works on a circular region centred on the selection.

    original image

    selection around the pupil

    result after RedEyeRemove
  • SelectiveBlur / UnsharpMask : these non linear filters increase the image quality. SelectiveBlur removes the "granular" noise (jpeg artefacts, or digital camera noise) preserving the details, UnsharpMask enhances the details without adding noise in the "flat" regions.
  • Custom linear filters : (\Filters\Linear\Custom) a small graphic interface to test new kernels for the Filter function (thanks to Priyank Bolia).
  • Histogram : (\Colors\Histogram\...) many menus are available to test HistogramStretch with different approaches (0 = luminance, 1 = linked channels , 2 = independent channels); the threshold parameter increases the robustness of the algorithm in case of noisy images. "Half Saturation" and "Full Saturation" test the combination of ConvertColorSpace, Histogram, and Saturate, to stretch the histogram in the YUV colorspace.

    original image

    + HistogramStretch(2,0.005f)

    + "Half saturation"
  • Thresholding : ( \Colors\Threshold... and \Colors\Adaptive Threshold). OptimalThreshold is a new method to find the optimal threshold for image binarization, the available algorithms are:
    1 = Otsu;
    2 = Kittler & Illingworth;
    3 = maximum entropy;
    4 = potential difference;
    0 = average all methods (default, and used in the demo);
    The option "preserve colors less than the threshold" will test Threshold2, useful to filter colored images with a noisy background, the result will be a colored image with an uniform background.
    AdaptiveThreshold is an application of OptimalThreshold to build a variable threshold mask. AdaptiveThreshold is useful in case of images with a non uniform lightness, where a single threshold can't be optimal for the whole image; but in general it will give bad results if the parameters are not well tuned.

    original image

    OptimalThreshold + Threshold


  • Add shadow : (\Filters\Add Shadow...) this menu is a small example on how the simple CxImage methods (selections, GaussianBlur, Mix) can be combined to obtain a common effect.

    purple shadow on white background

    black shadow on red background

  • Text smoothing : DrawStringEx implements a new option, through CXTEXTINFO::smooth, that can be tested with the text tool (\View\Tools\Text), checking the "antialias" option.
    A similar effect can be obtained in post processing with TextBlur (\Filters\Non Linear\Text Blur): a non linear filter that works only on diagonal or round edges, without affecting vertical or horizontal lines. In the next table there is a comparison between different smoothing methods:

    DrawStringEx without smoothing

    DrawStringEx with smoothing

    post processing with TextBlur

    post processing with a linear 3x3 "soften" Filter


2003 - 2008 © Davide Pizzolato - www.xdp.it        top