Class MagickUtil

java.lang.Object
com.twelvemonkeys.image.MagickUtil

public final class MagickUtil extends Object
Utility for converting JMagick MagickImages to standard Java BufferedImages and back.

NOTE: This class is considered an implementation detail and not part of the public API. This class is subject to change without further notice. You have been warned. :-)

Version:
$Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/image/MagickUtil.java#4 $
  • Field Details

    • CM_MONOCHROME

      private static final IndexColorModel CM_MONOCHROME
      Color Model usesd for bilevel (B/W)
    • CM_COLOR_ALPHA

      private static final ColorModel CM_COLOR_ALPHA
      Color Model usesd for raw ABGR
    • CM_COLOR_OPAQUE

      private static final ColorModel CM_COLOR_OPAQUE
      Color Model usesd for raw BGR
    • CM_GRAY_ALPHA

      private static final ColorModel CM_GRAY_ALPHA
      Color Model usesd for raw GRAY + ALPHA
    • CM_GRAY_OPAQUE

      private static final ColorModel CM_GRAY_OPAQUE
      Color Model usesd for raw GRAY
    • BAND_OFF_TRANS

      private static final int[] BAND_OFF_TRANS
      Band offsets for raw ABGR
    • BAND_OFF_OPAQUE

      private static final int[] BAND_OFF_OPAQUE
      Band offsets for raw BGR
    • LOCATION_UPPER_LEFT

      private static final Point LOCATION_UPPER_LEFT
      The point at 0, 0
    • DEBUG

      private static final boolean DEBUG
  • Constructor Details

    • MagickUtil

      private MagickUtil()
  • Method Details

    • toBuffered

      public static BufferedImage toBuffered(magick.MagickImage pImage) throws magick.MagickException
      Converts a MagickImage to a BufferedImage.

      The conversion depends on pImage's ImageType:

      ImageType.BilevelType
      BufferedImage of type TYPE_BYTE_BINARY
      ImageType.GrayscaleType
      BufferedImage of type TYPE_BYTE_GRAY
      ImageType.GrayscaleAlphaType
      BufferedImage of type TYPE_USHORT_GRAY
      ImageType.PaletteType
      BufferedImage of type TYPE_BYTE_BINARY (for images with a palette of <= 16 colors) or TYPE_BYTE_INDEXED
      ImageType.PaletteAlphaType
      BufferedImage of type TYPE_BYTE_BINARY (for images with a palette of <= 16 colors) or TYPE_BYTE_INDEXED
      ImageType.TrueColorType
      BufferedImage of type TYPE_3BYTE_BGR
      ImageType.TrueColorPaletteType
      BufferedImage of type TYPE_4BYTE_ABGR
      Parameters:
      pImage - the original MagickImage
      Returns:
      a new BufferedImage
      Throws:
      IllegalArgumentException - if pImage is null or if the ImageType is not one mentioned above.
      magick.MagickException - if an exception occurs during conversion
      See Also:
    • toMagick

      public static magick.MagickImage toMagick(BufferedImage pImage) throws magick.MagickException
      Converts a BufferedImage to a MagickImage.

      The conversion depends on pImage's ColorModel:

      IndexColorModel with 1 bit b/w
      MagickImage of type ImageType.BilevelType
      IndexColorModel > 1 bit,
      MagickImage of type ImageType.PaletteType or MagickImage of type ImageType.PaletteAlphaType depending on ColorModel.getAlpha()
      ColorModel.getColorSpace().getType() == ColorSpace.TYPE_GRAY
      MagickImage of type ImageType.GrayscaleType or MagickImage of type ImageType.GrayscaleAlphaType depending on ColorModel.getAlpha()
      ColorModel.getColorSpace().getType() == ColorSpace.TYPE_RGB
      MagickImage of type ImageType.TrueColorType or MagickImage of type ImageType.TrueColorPaletteType
      Parameters:
      pImage - the original BufferedImage
      Returns:
      a new MagickImage
      Throws:
      IllegalArgumentException - if pImage is null or if the ColorModel is not one mentioned above.
      magick.MagickException - if an exception occurs during conversion
      See Also:
    • rgbToMagic

      private static magick.MagickImage rgbToMagic(BufferedImage pImage, boolean pAlpha) throws magick.MagickException
      Throws:
      magick.MagickException
    • grayToMagick

      private static magick.MagickImage grayToMagick(BufferedImage pImage, boolean pAlpha) throws magick.MagickException
      Throws:
      magick.MagickException
    • indexedToMagick

      private static magick.MagickImage indexedToMagick(BufferedImage pImage, IndexColorModel pColorModel, boolean pAlpha) throws magick.MagickException
      Throws:
      magick.MagickException
    • bilevelToBuffered

      private static BufferedImage bilevelToBuffered(magick.MagickImage pImage) throws magick.MagickException
      Converts a bi-level MagickImage to a BufferedImage, of type TYPE_BYTE_BINARY.
      Parameters:
      pImage - the original MagickImage
      Returns:
      a new BufferedImage
      Throws:
      magick.MagickException - if an exception occurs during conversion
      See Also:
    • grayToBuffered

      private static BufferedImage grayToBuffered(magick.MagickImage pImage, boolean pAlpha) throws magick.MagickException
      Converts a gray MagickImage to a BufferedImage, of type TYPE_USHORT_GRAY or TYPE_BYTE_GRAY.
      Parameters:
      pImage - the original MagickImage
      pAlpha - keep alpha channel
      Returns:
      a new BufferedImage
      Throws:
      magick.MagickException - if an exception occurs during conversion
      See Also:
    • paletteToBuffered

      private static BufferedImage paletteToBuffered(magick.MagickImage pImage, boolean pAlpha) throws magick.MagickException
      Converts a palette-based MagickImage to a BufferedImage, of type TYPE_BYTE_BINARY (for images with a palette of <= 16 colors) or TYPE_BYTE_INDEXED.
      Parameters:
      pImage - the original MagickImage
      pAlpha - keep alpha channel
      Returns:
      a new BufferedImage
      Throws:
      magick.MagickException - if an exception occurs during conversion
      See Also:
    • createIndexColorModel

      public static IndexColorModel createIndexColorModel(magick.PixelPacket[] pColormap, boolean pAlpha)
      Creates an IndexColorModel from an array of PixelPackets.
      Parameters:
      pColormap - the original colormap as a PixelPacket array
      pAlpha - keep alpha channel
      Returns:
      a new IndexColorModel
    • rgbToBuffered

      private static BufferedImage rgbToBuffered(magick.MagickImage pImage, boolean pAlpha) throws magick.MagickException
      Converts an (A)RGB MagickImage to a BufferedImage, of type TYPE_4BYTE_ABGR or TYPE_3BYTE_BGR.
      Parameters:
      pImage - the original MagickImage
      pAlpha - keep alpha channel
      Returns:
      a new BufferedImage
      Throws:
      magick.MagickException - if an exception occurs during conversion
      See Also:
    • cmykToBuffered

      private static BufferedImage cmykToBuffered(magick.MagickImage pImage, boolean pAlpha) throws magick.MagickException
      Converts an MagickImage to a BufferedImage which holds an CMYK ICC profile
      Parameters:
      pImage - the original MagickImage
      pAlpha - keep alpha channel
      Returns:
      a new BufferedImage
      Throws:
      magick.MagickException - if an exception occurs during conversion
      See Also: