ImageMagick Version 7 Porting Guide
ImageMagick was originally designed to display RGB images to an X Windows server. Over time we extended support to RGBA images and then to the CMYK and CMYKA image format. With ImageMagick version 7, we extend support to arbitrary colorspaces with an arbitrary number of pixel channels.
Header Files
Prior versions of ImageMagick (4-6) references the ImageMagick header files as magick/ and wand/. ImageMagick 7 instead uses MagickCore/ and MagickWand/ respectively. For example,
#include <MagickCore/MagickCore.h> #include <MagickWand/MagickWand.h>
Pixel Channels
Prior versions of ImageMagick (4-6), supports 4 to 5 pixel channels (RGBA or CMYKA). The first 4 channels are accessed with the PixelPacket data structure. The structure includes 4 members of type Quantum (typically 16-bits) of red, green, blue, and opacity. The black channel or colormap indexes are supported by a separate method and structure, IndexPacket. As an example, here is a code snippet from ImageMagick version 6 that negates image pixels:
for (y=0; y < (ssize_t) image->rows; y++) { register IndexPacket *indexes; register PixelPacket *q; q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); if (q == (PixelPacket *) NULL) { status=MagickFalse; continue; } indexes=GetCacheViewAuthenticIndexQueue(image_view); for (x=0; x < (ssize_t) image->columns; x++) { if ((channels & RedChannel) != 0) q->red=(Quantum) QuantumRange-q->red; if ((channels & GreenChannel) != 0) q->green=(Quantum) QuantumRange-q->green; if ((channels & BlueChannel) != 0) q->blue=(Quantum) QuantumRange-q->blue; if ((channels & OpacityChannel) != 0) q->opacity=(Quantum) QuantumRange-q->opacity; if (((channels & IndexChannel) != 0) && (image->colorspace == CMYKColorspace)) indexes[x]=(IndexPacket) QuantumRange-indexes[x]; q++; } if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) status=MagickFalse; }
ImageMagick version 7 supports any number of channels from 1 to 100 (and beyond) and simplifies access with a single method that returns an array of pixel channels of type Quantum. Source code that compiles against prior versions of ImageMagick will require refactoring to work with ImageMagick version 7. We illustrate with an example. Let's refactor the version 6 code snippet from above so it works with the ImageMagick version 7 API:
for (y=0; y < (ssize_t) image->rows; y++) { register Quantum *q; q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); if (q == (Quantum *) NULL) { status=MagickFalse; continue; } for (x=0; x < (ssize_t) image->columns; x++) for (channel=0; channel < GetCacheViewChannels(image_view); channel++) { if ((channels & (1 << channel)) != 0) *q=(Quantum) QuantumRange-(*q); q++; } if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) status=MagickFalse; }
Use GetImageChannels() or GetCacheViewChannels() to advance to the next set of pixel channels.
In addition to supporting any number of channels, version 7 simplifies working with channels and provides opportunity for compiler optimiziations that were previously not possible. Our benchmarking shows version 7 has increased performance for virtually all image operations.
Alpha
We support alpha now, previously opacity. With alpha, a value of 0 means that the pixel does not have any coverage information and is transparent; i.e. there was no color contribution from any geometry because the geometry did not overlap this pixel. A value of QuantumRange means that the pixel is opaque because the geometry completely overlapped the pixel. As a consquence, in version 7, the PixelPacket structure member alpha has replaced the previous opacity member.
Deprecated Features Removed
All deprecated features from ImageMagick version 6 are removed in version 7. These include the Magick-config and Wand-config configuration utilities. Instead use:
MagickCore-config MagickWand-config
In addition, all deprecated MagickCore and MagickWand methods are no longer available in version 7.
Version 7 Change Summary
Changes from ImageMagick version 6 to version 7 are summarized here: