#include <MagickCodec.h>
Inheritance diagram for prapi::MagickCodec< T >:

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. | |
|
||||||||||
|
Create a new image codec.
|
|
||||||||||
|
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,
1,2,3,
4,5,6,
7,8,9);
Image* imageMagicImage = MagickCodec<int>constituteImage(mat);
... do whatever you need ...
DestroyImage(imageMagicImage);
|
|
||||||||||
|
Convert an ImageMagick image to a matrix. For example:
Image* image = (get this somehow); Matrix<Color<int,3> > colorImage(MagicCodec<Color<int,3> >::constituteMatrix(image)); |
|
||||||||||||||||
|
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 >. |