GraphicsMagick Search site

- Home
- License
- Mission
- Download
- Installation
- FAQ
- News
- Formats

- Process
- Contribute
- CVS
- Mailing Lists
- ChangeLog
- Report Bugs
- Utilities
- Programming
- Links

# constitute

## Read or write an image

Contents

- ConstituteImage
- ConstituteTextureImage
- DispatchImage
- ExportImagePixelArea
- ExportViewPixelArea
- ExportPixelAreaOptionsInit
- ImportImagePixelArea
- ImportViewPixelArea
- ImportPixelAreaOptionsInit
- PingImage
- ReadImage
- ReadInlineImage
- WriteImage
- WriteImages

# ConstituteImage

## Synopsis

    Image *ConstituteImage( const unsigned long width, const unsigned long height,
                            const char *map, const StorageType type, const void *pixels,
                            ExceptionInfo *exception );

## Description

ConstituteImage() returns an Image corresponding to an image stored in a raw memory array format. The pixel data must be in scanline order top-to-bottom. The data can be unsigned char, unsigned short int, unsigned int, unsigned long, float, or double. Float and double require the pixels to be normalized to the range [0..1], otherwise the range is [0..MaxVal] where MaxVal is the maximum possible value for that type.

Note that for most 32-bit architectures the size of an unsigned long is the same as unsigned int, but for 64-bit architectures observing the LP64 standard, an unsigned long is 64 bits, while an unsigned int remains 32 bits. This should be considered when deciding if the data should be described as "Integer" or "Long".

For example, to create a 640x480 image from unsigned red-green-blue character data, use

image=ConstituteImage(640,480,"RGB",CharPixel,pixels,&exception);

The format of the Constitute method is:

    Image *ConstituteImage( const unsigned long width, const unsigned long height,
                            const char *map, const StorageType type, const void *pixels,
                            ExceptionInfo *exception );

width:
  width in pixels of the image.
height:
  height in pixels of the image.
map:
  This string reflects the expected ordering of the pixel array. It can be any combination or order of R = red, G = green, B = blue, A = alpha (same as Transparency), O = Opacity, T = Transparency, C = cyan, Y = yellow, M = magenta, K = black, or I = intensity (for grayscale). Specify "P" = pad, to skip over a quantum which is intentionally ignored. Creation of an alpha channel for CMYK images is currently not supported.
type:
  Define the data type of the pixels. Float and double types are expected to be normalized [0..1] otherwise [0..MaxRGB]. Choose from these types: CharPixel, ShortPixel, IntegerPixel, LongPixel, FloatPixel, or DoublePixel.
pixels:
  This array of values contain the pixel components as defined by map and type. You must preallocate this array where the expected length varies depending on the values of width, height, map, and type.
exception:
  Return any errors or warnings in this structure.

# ConstituteTextureImage

## Synopsis

    Image *ConstituteTextureImage( unsigned long columns, unsigned long rows,
                                   const Image *texture, ExceptionInfo *exception );

## Description

ConstituteTextureImage() returns a new image canvas based on repeatedly tiling the texture image across and down the new image canvas. The returned image properties are similar to the texture image properties.

The format of the TextureImage method is:

    Image *ConstituteTextureImage( unsigned long columns, unsigned long rows,
                                   const Image *texture, ExceptionInfo *exception );

columns:
  The number of columns in the new image.
rows:
  The number of rows in the new image.
texture:
  The texture image to layer on the background.
exceptions:
  Any errors are reported here.

# DispatchImage

## Synopsis

    unsigned int DispatchImage( const Image *image, const long x_offset, const long y_offset,
                                const unsigned long columns, const unsigned long rows,
                                const char *map, const StorageType type, void *pixels,
                                ExceptionInfo *exception );

## Description

DispatchImage() extracts pixel data from an Image into a raw memory array. The pixel data is written in scanline order top-to-bottom using an arbitrary quantum order specified by 'map', and with quantum size specified by 'type'.

The output array data may be unsigned char, unsigned short int, unsigned int, unsigned long, float, or double. Float and double require the pixels to be normalized to the range [0..1], otherwise the range is [0..MaxVal] where MaxVal is the maximum possible value for that type.

The method returns MagickPass on success or MagickFail if an error is encountered.

Suppose we want want to extract the first scanline of a 640x480 image as character data in red-green-blue order:

DispatchImage(image,0,0,640,1,"RGB",0,pixels,exception);

The format of the DispatchImage method is:

    unsigned int DispatchImage( const Image *image, const long x_offset, const long y_offset,
                                const unsigned long columns, const unsigned long rows,
                                const char *map, const StorageType type, void *pixels,
                                ExceptionInfo *exception );

image:
  The image.
x_offset, y_offset, columns, rows:
  These values define the perimeter of a region of pixels you want to extract.
map:
  This string reflects the expected ordering of the pixel array. It can be any combination or order of R = red, G = green, B = blue, A = alpha (same as Transparency), O = Opacity, T = Transparency, C = cyan, Y = yellow, M = magenta, K = black, I = intensity (for grayscale). Specify "P" = pad, to output a pad quantum. Pad quantums are zero-value.
type:
  Define the data type of the pixels. Float and double types are expected to be normalized [0..1] otherwise [0..MaxRGB]. Choose from these types: CharPixel, ShortPixel, IntegerPixel, LongPixel, FloatPixel, or DoublePixel.
pixels:
  This array of values contain the pixel components as defined by map and type. You must preallocate this array where the expected length varies depending on the values of width, height, map, and type.
exception:
  Return any errors or warnings in this structure.

# ExportImagePixelArea

## Synopsis

    MagickPassFail ExportImagePixelArea( const Image *image, const QuantumType quantum_type,
                                         unsigned int quantum_size, unsigned char *destination,
                                         const ExportPixelAreaOptions *options,
                                         ExportPixelAreaInfo *export_info );

## Description

ExportImagePixelArea() transfers one or more pixel components from the default image pixel cache view to a user supplied buffer. By default, values are written in network (big-endian) byte/bit order. By setting the 'endian' member of ExportPixelAreaOptions, 16, 32 and 64-bit values may be output as little (LSBEndian), big (MSBEndian), or host native (NativeEndian) endian values. This function is quite powerful in that besides common native CPU type sizes, it can support any integer bit depth from 1 to 32 (e.g. 13), 64-bits as well as 32 and 64-bit float.

MagickPass is returned if the pixels are successfully transferred, otherwise MagickFail.

The format of the ExportImagePixelArea method is:

    MagickPassFail ExportImagePixelArea( const Image *image, const QuantumType quantum_type,
                                         unsigned int quantum_size, unsigned char *destination,
                                         const ExportPixelAreaOptions *options,
                                         ExportPixelAreaInfo *export_info );

status:
  Returns MagickPass if the pixels are successfully transferred, otherwise MagickFail.
image:
  The image.
quantum_type:
  Declare which pixel components to transfer (AlphaQuantum, BlackQuantum, BlueQuantum, CMYKAQuantum, CMYKQuantum, CyanQuantum, GrayAlphaQuantum, GrayQuantum, GreenQuantum, IndexAlphaQuantum, IndexQuantum, MagentaQuantum, RGBAQuantum, RGBQuantum, RedQuantum, YellowQuantum)
quantum_size:
  Bits per quantum sample (range 1-32, and 64).
destination:
  The components are transferred to this buffer. The user is responsible for ensuring that the destination buffer is large enough.
options:
  Additional options specific to quantum_type (may be NULL).
export_info :
  Populated with information regarding the pixels exported (may be NULL)

# ExportViewPixelArea

## Synopsis

    MagickPassFail ExportViewPixelArea( const ViewInfo *view, const QuantumType quantum_type,
                                        unsigned int quantum_size, unsigned char *destination,
                                        const ExportPixelAreaOptions *options,
                                        ExportPixelAreaInfo *export_info );

## Description

ExportViewPixelArea() transfers one or more pixel components from the specified image pixel cache view to a user supplied buffer. By default, values are written in network (big-endian) byte/bit order. By setting the 'endian' member of ExportPixelAreaOptions, 16, 32 and 64-bit values may be output as little (LSBEndian), big (MSBEndian), or host native (NativeEndian) endian values. This function is quite powerful in that besides common native CPU type sizes, it can support any integer bit depth from 1 to 32 (e.g. 13), 64-bits as well as 32 and 64-bit float.

MagickPass is returned if the pixels are successfully transferred, otherwise MagickFail.

The format of the ExportViewPixelArea method is:

    MagickPassFail ExportViewPixelArea( const ViewInfo *view, const QuantumType quantum_type,
                                        unsigned int quantum_size, unsigned char *destination,
                                        const ExportPixelAreaOptions *options,
                                        ExportPixelAreaInfo *export_info );

status:
  Returns MagickPass if the pixels are successfully transferred, otherwise MagickFail.
view:
  The image pixel cache view.
quantum_type:
  Declare which pixel components to transfer (AlphaQuantum, BlackQuantum, BlueQuantum, CMYKAQuantum, CMYKQuantum, CyanQuantum, GrayAlphaQuantum, GrayQuantum, GreenQuantum, IndexAlphaQuantum, IndexQuantum, MagentaQuantum, RGBAQuantum, RGBQuantum, RedQuantum, YellowQuantum)
quantum_size:
  Bits per quantum sample (range 1-32, and 64).
destination:
  The components are transferred to this buffer. The user is responsible for ensuring that the destination buffer is large enough.
options:
  Additional options specific to quantum_type (may be NULL).
export_info :
  Populated with information regarding the pixels exported (may be NULL)

# ExportPixelAreaOptionsInit

## Synopsis

    void ExportPixelAreaOptionsInit( ExportPixelAreaOptions *options );

## Description

ExportPixelAreaOptionsInit() initializes the options structure which is optionally passed to ExportPixelArea()

The format of the ExportPixelAreaOptionsInit method is:

    void ExportPixelAreaOptionsInit( ExportPixelAreaOptions *options );

A description of each parameter follows:

options:
  Options structure to initialize.

# ImportImagePixelArea

## Synopsis

    MagickPassFail ImportImagePixelArea( Image *image, const QuantumType quantum_type,
                                         const unsigned int quantum_size,
                                         const unsigned char *source,
                                         const ImportPixelAreaOptions *options,
                                         ImportPixelAreaInfo *import_info );

## Description

ImportImagePixelArea() transfers one or more pixel components from a user supplied buffer into the default image pixel cache view. By default, values are read in network (big-endian) byte/bit order. By setting the 'endian' member of ExportPixelAreaOptions, 16, 32 and 64-bit values may be output as little (LSBEndian), big (MSBEndian), or host native (NativeEndian) endian values. This function is quite powerful in that besides common native CPU type sizes, it can support any integer bit depth from 1 to 32 (e.g. 13), 64-bits, as well as 32 and 64-bit float.

MagickPass is returned if the pixels are successfully transferred, otherwise MagickFail.

The format of the ImportImagePixelArea method is:

    MagickPassFail ImportImagePixelArea( Image *image, const QuantumType quantum_type,
                                         const unsigned int quantum_size,
                                         const unsigned char *source,
                                         const ImportPixelAreaOptions *options,
                                         ImportPixelAreaInfo *import_info );

status:
  Method PushImagePixels returns MagickPass if the pixels are successfully transferred, otherwise MagickFail.
image:
  The image.
quantum_type:
  Declare which pixel components to transfer (AlphaQuantum, BlackQuantum, BlueQuantum, CMYKAQuantum, CMYKQuantum, CyanQuantum, GrayAlphaQuantum, GrayQuantum, GreenQuantum, IndexAlphaQuantum, IndexQuantum, MagentaQuantum, RGBAQuantum, RGBQuantum, RedQuantum, YellowQuantum)
quantum_size:
  Bits per quantum sample (range 1-32, and 64).
source:
  The pixel components are transferred from this buffer.
options:
  Additional options specific to quantum_type (may be NULL).
import_info :
  Populated with information regarding the pixels imported (may be NULL)

# ImportViewPixelArea

## Synopsis

    MagickPassFail ImportViewPixelArea( ViewInfo *view, const QuantumType quantum_type,
                                        const unsigned int quantum_size,
                                        const unsigned char *source,
                                        const ImportPixelAreaOptions *options,
                                        ImportPixelAreaInfo *import_info );

## Description

ImportViewPixelArea() transfers one or more pixel components from a user supplied buffer into the specified image pixel cache view of an image. By default, values are read in network (big-endian) byte/bit order. By setting the 'endian' member of ExportPixelAreaOptions, 16, 32 and 64-bit values may be output as little (LSBEndian), big (MSBEndian), or host native (NativeEndian) endian values. This function is quite powerful in that besides common native CPU type sizes, it can support any integer bit depth from 1 to 32 (e.g. 13), 64-bits, as well as 32 and 64-bit float.

MagickPass is returned if the pixels are successfully transferred, otherwise MagickFail.

The format of the ImportViewPixelArea method is:

    MagickPassFail ImportViewPixelArea( ViewInfo *view, const QuantumType quantum_type,
                                        const unsigned int quantum_size,
                                        const unsigned char *source,
                                        const ImportPixelAreaOptions *options,
                                        ImportPixelAreaInfo *import_info );

status:
  Method PushImagePixels returns MagickPass if the pixels are successfully transferred, otherwise MagickFail.
view:
  The pixel view to import pixels into.
quantum_type:
  Declare which pixel components to transfer (AlphaQuantum, BlackQuantum, BlueQuantum, CMYKAQuantum, CMYKQuantum, CyanQuantum, GrayAlphaQuantum, GrayQuantum, GreenQuantum, IndexAlphaQuantum, IndexQuantum, MagentaQuantum, RGBAQuantum, RGBQuantum, RedQuantum, YellowQuantum)
quantum_size:
  Bits per quantum sample (range 1-32, and 64).
source:
  The pixel components are transferred from this buffer.
options:
  Additional options specific to quantum_type (may be NULL).
import_info :
  Populated with information regarding the pixels imported (may be NULL)

# ImportPixelAreaOptionsInit

## Synopsis

    void ImportPixelAreaOptionsInit( ImportPixelAreaOptions *options );

## Description

ImportPixelAreaOptionsInit() initializes the options structure which is optionally passed to ImportPixelArea()

The format of the ImportPixelAreaOptionsInit method is:

    void ImportPixelAreaOptionsInit( ImportPixelAreaOptions *options );

A description of each parameter follows:

options:
  Options structure to initialize.

# PingImage

## Synopsis

    Image *PingImage( const ImageInfo *image_info, ExceptionInfo *exception );

## Description

PingImage() returns all the attributes of an image or image sequence except for the pixels. It is much faster and consumes far less memory than ReadImage(). On failure, a NULL image is returned and exception describes the reason for the failure.

The format of the PingImage method is:

    Image *PingImage( const ImageInfo *image_info, ExceptionInfo *exception );

A description of each parameter follows:

image_info:
  Ping the image defined by the file or filename members of this structure.
exception:
  Return any errors or warnings in this structure.

# ReadImage

## Synopsis

    Image *ReadImage( const ImageInfo *image_info, ExceptionInfo *exception );

## Description

ReadImage() reads an image or image sequence from a file or file handle. The method returns a NULL if there is a memory shortage or if the image cannot be read. On failure, a NULL image is returned and exception describes the reason for the failure.

The format of the ReadImage method is:

    Image *ReadImage( const ImageInfo *image_info, ExceptionInfo *exception );

A description of each parameter follows:

image_info:
  Read the image defined by the file or filename members of this structure.
exception:
  Return any errors or warnings in this structure.

# ReadInlineImage

## Synopsis

    Image *ReadInlineImage( const ImageInfo *image_info, const char *content,
                            ExceptionInfo *exception );

## Description

ReadInlineImage() reads a Base64-encoded inline image or image sequence. The method returns a NULL if there is a memory shortage or if the image cannot be read. On failure, a NULL image is returned and exception describes the reason for the failure.

The format of the ReadInlineImage method is:

    Image *ReadInlineImage( const ImageInfo *image_info, const char *content,
                            ExceptionInfo *exception );

image_info:
  The image info.
content:
  The image encoded in Base64.
exception:
  Return any errors or warnings in this structure.

# WriteImage

## Synopsis

    unsigned int WriteImage( const ImageInfo *image_info, Image *image );

## Description

Use Write() to write an image or an image sequence to a file or filehandle. If writing to a file on disk, the name is defined by the filename member of the image structure. Write() returns 0 is there is a memory shortage or if the image cannot be written. Check the exception member of image to determine the cause for any failure.

The format of the WriteImage method is:

    unsigned int WriteImage( const ImageInfo *image_info, Image *image );

A description of each parameter follows:

image_info:
  The image info.
image:
  The image.

# WriteImages

## Synopsis

    unsigned int WriteImages( const ImageInfo *image_info, Image *image,
                              const char *filename, ExceptionInfo *exception );

## Description

WriteImages() writes an image sequence.

The format of the WriteImages method is:

    unsigned int WriteImages( const ImageInfo *image_info, Image *image,
                              const char *filename, ExceptionInfo *exception );

image_info:
  The image info.
images:
  The image list.
filename:
  The image filename.
exception:
  Return any errors or warnings in this structure.