Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members  

prapi::MagickCodec< T > Class Template Reference

#include <MagickCodec.h>

Inheritance diagram for prapi::MagickCodec< T >:

MatrixCodec< T > Object List of all members.

Detailed Description

template<class T>
class prapi::MagickCodec< T >

MagickCodec is a general-purpose image codec that uses the ImageMagick library to read and write images.

It supports gray-scale (intensity), RGB and RGBA (RGB-Alpha) images, all common image formats, and many not so common ones. Intensity images are represented as char, short, int, long, float or double images. Depending on your ImageMagick installation, the maximum value for the non-floating point types is either 255 or 65535. Floating point images are assumed to be in the range [0,1]. Images are always read and written as integers. Color images are presented as matrices of type Color<T,n>, where T is the type of the color (char, short, int, long, float, double), and n is the number of color channels. 1, 3, and 4 channels are supported. If the colors have only one channel, it is assumed to be intensity, 3-channel colors are treated as RGB, and 4-channel colors as RGBA.

The template parameter determines the type of the matrix you will get. If the image read is of a different type, automatic conversion can be made in most cases.

An example:

 MagickCodec<int> codec;
 //Automatic conversion to gray scale if needed
 Matrix<int> image(codec.readFromFile("image.tif"));
 codec.writeToFile("image.jpg", image);

 MagicCodec<Color<int,3> > codec2;
 //Colors preserved
 Matrix<Color<int,3> > colorImage(codec.readFromFile("image.tif"));

Public Methods

 MagickCodec (const char *imageFormat="TIFF")
 Create a new image codec.

void setImageFormat (const char *format)
 Set the image format.

const char * getImageFormat ()
 Get the image format.

util::Matrix< T > readFromFile (std::string file) throw (util::MatrixException&, util::io::IOException&)
 Read an image from a file.

void writeToFile (std::string file, const util::Matrix< T > &mat) throw (util::MatrixException&, util::io::IOException&)
 Write an image to a file.

void decodeMatrix (std::istream &in, util::Matrix< T > &mat) throw (util::MatrixException&, util::io::IOException&)
 Decode the contents of a stream, and store decoded bytes into an image.

void encodeMatrix (std::ostream &out, const util::Matrix< T > &mat) throw (util::MatrixException&, util::io::IOException&)
 Encode an image and write it into a stream.

static::Image * constituteImage (const util::Matrix< T > &mat) throw (util::MatrixException&)
 Convert a matrix to an ImageMagick image.

Static Public Methods

util::Matrix< T > constituteMatrix (::Image *image) throw (util::MatrixException&)
 Convert an ImageMagick image to a matrix.

Constructor & Destructor Documentation

template<class T>
prapi::MagickCodec< T >::MagickCodec const char *    imageFormat = "TIFF" [inline]

Create a new image codec.

imageFormat  the default format when images are written into a stream. Normally, file name suffix is used to determine the format. Valid formats are "GIF", "TIFF", "JPG", "XPM", "BMP" etc. See your local ImageMagick docs for a comprehensive list of supported image formats.

Member Function Documentation

template<class T>
Image * prapi::MagickCodec< T >::constituteImage const util::Matrix< T > &    mat throw (util::MatrixException&)

Convert a matrix to an ImageMagick image.

A newly allocated Image is returned, and must be destroyed by the caller with the DestroyImage(image) ImageMagick function. Example:

 Matrix<int> mat(3,3,

 Image* imageMagicImage = MagickCodec<int>constituteImage(mat);

 ... do whatever you need ...

template<class T>
util::Matrix< T > prapi::MagickCodec< T >::constituteMatrix ::Image   image throw (util::MatrixException&) [static]

Convert an ImageMagick image to a matrix.

For example:

 Image* image = (get this somehow);
 Matrix<Color<int,3> > colorImage(MagicCodec<Color<int,3> &gt::constituteMatrix(image));

template<class T>
void prapi::MagickCodec< T >::decodeMatrix std::istream &    in,
util::Matrix< T > &    mat
throw (util::MatrixException&, util::io::IOException&) [virtual]

Decode the contents of a stream, and store decoded bytes into an image.

This method reads the stream until it ends, or the program runs out of memory. When the input ends, the data read is encoded.

Implements MatrixCodec< T >.

The documentation for this class was generated from the following file:
Documentation generated on 11.09.2003 with Doxygen.
The documentation is copyrighted material.
Copyright © Topi Mäenpää 2003. All rights reserved.