ImageMagick Logo ImageMagick Sprite
Unix
Mac OS X
iOS
Windows
Processing
Options
Usage
MagickWand
MagickCore
PerlMagick
Magick++
Unix
Windows
Links

ImageMagick Version 7 Porting Guide

The design of ImageMagick is an evolutionary process, with the design and implementation efforts serving to influence and guide further progress in the other. With ImageMagick version 7 we aim to improve the design based on lessons learned from the version 6 implementation. 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 components. Other design changes are in the works and we will document them here so be sure to revisit periodically.

To support variable pixel components in the MagickCore API, pixel handling has changed and now requires accessors to get or set the pixel components. There are some modest changes to the MagickWand API. Magick++ and PerlMagick should behave exactly as it does for ImageMagick version 6.

We intend to make ImageMagick version 7 available as an Alpha release by the end-of-year 2011. Look for a Beta release sometime in 2012. An official ImageMagick version 7 release will depend on how smoothly the Beta cycle progresses. During the Beta cycle, version 6 developers can attempt to port their software to version 7.

During the ImageMagick version 7 development cycle and release, we will continue to support and enhance version 6 for a minimum of 10 years.

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 Components

A pixel is comprised of one or more color values we call components (e.g. red pixel component). However, when we discuss a pixel component across more than one pixel, we call these channels (i.e. the red pixel channel).

Prior versions of ImageMagick (4-6), supports 4 to 5 pixel components (RGBA or CMYKA). The first 4 components 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 component 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 ((channel & RedChannel) != 0)
        q->red=(Quantum) QuantumRange-q->red;
      if ((channel & GreenChannel) != 0)
        q->green=(Quantum) QuantumRange-q->green;
      if ((channel & BlueChannel) != 0)
        q->blue=(Quantum) QuantumRange-q->blue;
      if ((channel & OpacityChannel) != 0)
        q->opacity=(Quantum) QuantumRange-q->opacity;
      if (((channel & 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 components from 1 to 100 (and beyond) and simplifies access with a single method that returns an array of pixel components 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 naively 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++)
    {
      if ((GetPixelRedTraits(image) & ActivePixelTrait) != 0)
        SetPixelRed(image,QuantumRange-GetPixelRed(image,q),q);
      if ((GetPixelGreenTraits(image) & ActivePixelTrait) != 0)
        SetPixelGreen(image,QuantumRange-GetPixelGreen(image,q),q);
      if ((GetPixelBlueTraits(image) & ActivePixelTrait) != 0)
        SetPixelBlue(image,QuantumRange-GetPixelBlue(image,q),q);
      if ((GetPixelBlackTraits(image) & BlackPixelTrait) != 0)
        SetPixelBlack(image,QuantumRange-GetPixelBlack(image,q),q);
      if ((GetPixelAlphaTraits(image) & ActivePixelTrait) != 0)
        SetPixelAlpha(image,QuantumRange-GetPixelAlpha(image,q),q);
      q+=GetPixelComponents(image);
    }
    if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
      status=MagickFalse;
  }

Let's do that again but take full advantage of the new variable pixel component support:

  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 (component=0; component < GetPixelComponents(image); component++)
      {
        if ((GetPixelComponentTraits(image,component) & ActivePixelTrait) != 0)
          *q=(Quantum) QuantumRange-(*q);
        q++;
      }
    if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
      status=MagickFalse;
  }

Use GetPixelComponents() to advance to the next set of pixel components.

The colormap indexes and black pixel component (for the CMYK colorspace) are no longer stored in the index component, previously accessed with GetAuthenticIndexQueue() and GetCacheViewAuthenticIndexQueue((). Instead they are now a pixel component and accessed with the convenience pixel macros GetPixelIndex(), SetPixelIndex(), GetPixelBlack(), and SetPixelBlack().

In addition to supporting any number of components, version 7 simplifies working with components and provides opportunity for compiler optimiziations that were previously not possible. Our benchmarking shows version 7 has increased performance for virtually all image operations.

Pixel Accessors

Use accessors to get or set pixel components:

  GetPixelAlpha()
  GetPixelBlack()
  GetPixelBlue()
  GetPixelCb()
  GetPixelComponents()
  GetPixelCr()
  GetPixelCyan()
  GetPixelGray()
  GetPixelGreen()
  GetPixelIndex()
  GetPixelInfoIntensity()
  GetPixelInfoLuminance()
  GetPixelMagenta()
  GetPixelRed()
  GetPixelPacket()
  GetPixelPacketIntensity()
  GetPixelY()
  GetPixelYellow()
  GetPixelIntensity()
  SetPixelAlpha()
  SetPixelBlack()
  SetPixelBlue()
  SetPixelCb()
  SetPixelComponents()
  SetPixelCr()
  SetPixelCyan()
  SetPixelGray()
  SetPixelGreen()
  SetPixelIndex()
  SetPixelInfo()
  SetPixelInfoBias()
  SetPixelInfoPacket()
  SetPixelMagenta()
  SetPixelRed()
  SetPixelPacket()
  SetPixelPixelInfo()
  SetPixelYellow()
  SetPixelY()

You can find these accessors defined in the header file, MagickCore/pixel-accessor.h

Pixel Traits

Each pixel component includes one or more of these traits:

Undefined
no traits associated with this pixel component
Active
an image processing algorithm operates on this pixel component if this trait is enabled, conversely if this trait is not enabled, the pixel component is skipped (e.g. negate red pixel component but not blue or green)
Blend
blend this pixel component with the alpha mask if it's enabled

We provide these methods to set and get pixel traits:

  GetPixelAlphaTraits()
  GetPixelBlackTraits()
  GetPixelBlueTraits()
  GetPixelCbTraits()
  GetPixelCrTraits()
  GetPixelCyanTraits()
  GetPixelGrayTraits()
  GetPixelGreenTraits()
  GetPixelIndexTraits()
  GetPixelMagentaTraits()
  GetPixelRedTraits()
  GetPixelComponentTraits()
  GetPixelYTraits()
  GetPixelYellowTraits()
  SetPixelAlphaTraits()
  SetPixelBlackTraits()
  SetPixelBlueTraits()
  SetPixelCbTraits()
  SetPixelComponentTraits()
  SetPixelCrTraits()
  SetPixelGrayTraits()
  SetPixelGreenTraits()
  SetPixelIndexTraits()
  SetPixelMagentaTraits()
  SetPixelRedTraits()
  SetPixelYellowTraits()
  SetPixelYTraits()

For convenience you can set the active trait for a set of pixel components with a channel mask and these methods:

  PopPixelComponentMap()
  PushPixelComponentMap()
  SetPixelComponentMap()

Previously MagickCore methods had channel analogs, for example, NegateImage() and NegateImageChannels(). The channel analog methods are no longer necessary because the pixel component traits specify whether to act on a particular pixel component and whether to blend with the alpha mask. For example, instead of

  NegateImageChannel(image,channel);

we use:

  PushPixelComponentMap(image,channel);
  NegateImage(image);
  PopPixelComponentMap(image);

Pixel Metacontent

In version 7, we introduce pixel metacontent. Metacontent is content about content. So rather than being the content itself, it's something that describes or amplifies the content. Here the content is a pixel. The pixel metacontent is for your exclusive use and is accessed with these MagickCore API methods:

  SetImageMetacontentExtent()
  GetImageMetacontentExtent()
  GetVirtualMetacontent()
  GetAuthenticMetacontent()
  GetCacheViewAuthenticMetacontent()
  GetCacheViewVirtualMetacontent()

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 consequence, in version 7, the PixelPacket structure member alpha has replaced the previous opacity member.

Grayscale

Previously, grayscale images consumed 4 components: red, green, blue, and alpha. With version 7, grayscale consumes only 1 component consuming far less resources as a result. However, there may be unintended consequences. With 1 component, all image processing algorithms write to this one component. Drawing yellow text on a grayscale image will produce gray lettering. To get the expected results, simply modify the colorspace to RGB (e.g. -colorspace rgb).

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:

Pixels
  • Pixels are no longer addressed with PixelPacket structure members (e.g. red, green, blue, opacity) but as an array of components (e.g. pixel[PixelRedComponent]).
  • Use convenience macros to access pixel components (e.g. GetPixelRed(), SetPixelRed()).
  • The black component for the CMYK colorspace is no longer stored in the index component, previously accessed with GetAuthenticIndexQueue() and GetCacheViewAuthenticIndexQueue((). Instead it is now a pixel component and accessed with the convenience pixel macros GetPixelBlack() and SetPixelBlack().
  • The index component for colormapped images are no longer stored in the index component, previously accessed with GetAuthenticIndexQueue() and GetCacheViewAuthenticIndexQueue((). Instead it is now a pixel component and accessed with the convenience pixel macros GetPixelIndex() and SetPixelIndex().
  • Use GetPixelComponents() to advance to the next set of pixel components.
  • Use the metacontent component to associate metacontent with each pixel.
  • Alpha
  • We support alpha rather than opacity (0 transparent; QuantumRange opaque).
  • Use GetPixelAlpha() or SetPixelAlpha() to get or set the alpha pixel component value.
  • Grayscale
  • Grayscale images consume one pixel component in ImageMagick version 7. To process RGB, set the colorspace to RGB (e.g. -colorspace rgb).
  • Deprecated Methods
  • All ImageMagick version 6 MagickCore and MagickWand deprecated methods are removed and no longer available in ImageMagick version 7.
  • All MagickCore channel method analogs are removed (e.g. NegateImageChannels()). For version 7, use pixel traits instead.