Package com.twelvemonkeys.image
Class MagickUtil
java.lang.Object
com.twelvemonkeys.image.MagickUtil
Utility for converting JMagick
MagickImage
s to standard Java
BufferedImage
s 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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final int[]
Band offsets for raw BGRprivate static final int[]
Band offsets for raw ABGRprivate static final ColorModel
Color Model usesd for raw ABGRprivate static final ColorModel
Color Model usesd for raw BGRprivate static final ColorModel
Color Model usesd for raw GRAY + ALPHAprivate static final ColorModel
Color Model usesd for raw GRAYprivate static final IndexColorModel
Color Model usesd for bilevel (B/W)private static final boolean
private static final Point
The point at0, 0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static BufferedImage
bilevelToBuffered
(magick.MagickImage pImage) Converts a bi-levelMagickImage
to aBufferedImage
, of typeTYPE_BYTE_BINARY
.private static BufferedImage
cmykToBuffered
(magick.MagickImage pImage, boolean pAlpha) Converts anMagickImage
to aBufferedImage
which holds an CMYK ICC profilestatic IndexColorModel
createIndexColorModel
(magick.PixelPacket[] pColormap, boolean pAlpha) Creates anIndexColorModel
from an array ofPixelPacket
s.private static BufferedImage
grayToBuffered
(magick.MagickImage pImage, boolean pAlpha) Converts a grayMagickImage
to aBufferedImage
, of typeTYPE_USHORT_GRAY
orTYPE_BYTE_GRAY
.private static magick.MagickImage
grayToMagick
(BufferedImage pImage, boolean pAlpha) private static magick.MagickImage
indexedToMagick
(BufferedImage pImage, IndexColorModel pColorModel, boolean pAlpha) private static BufferedImage
paletteToBuffered
(magick.MagickImage pImage, boolean pAlpha) Converts a palette-basedMagickImage
to aBufferedImage
, of typeTYPE_BYTE_BINARY
(for images with a palette of <= 16 colors) orTYPE_BYTE_INDEXED
.private static BufferedImage
rgbToBuffered
(magick.MagickImage pImage, boolean pAlpha) Converts an (A)RGBMagickImage
to aBufferedImage
, of typeTYPE_4BYTE_ABGR
orTYPE_3BYTE_BGR
.private static magick.MagickImage
rgbToMagic
(BufferedImage pImage, boolean pAlpha) static BufferedImage
toBuffered
(magick.MagickImage pImage) Converts aMagickImage
to aBufferedImage
.static magick.MagickImage
toMagick
(BufferedImage pImage) Converts aBufferedImage
to aMagickImage
.
-
Field Details
-
CM_MONOCHROME
Color Model usesd for bilevel (B/W) -
CM_COLOR_ALPHA
Color Model usesd for raw ABGR -
CM_COLOR_OPAQUE
Color Model usesd for raw BGR -
CM_GRAY_ALPHA
Color Model usesd for raw GRAY + ALPHA -
CM_GRAY_OPAQUE
Color Model usesd for raw GRAY -
BAND_OFF_TRANS
private static final int[] BAND_OFF_TRANSBand offsets for raw ABGR -
BAND_OFF_OPAQUE
private static final int[] BAND_OFF_OPAQUEBand offsets for raw BGR -
LOCATION_UPPER_LEFT
The point at0, 0
-
DEBUG
private static final boolean DEBUG
-
-
Constructor Details
-
MagickUtil
private MagickUtil()
-
-
Method Details
-
toBuffered
Converts aMagickImage
to aBufferedImage
.The conversion depends on
pImage
'sImageType
:ImageType.BilevelType
BufferedImage
of typeTYPE_BYTE_BINARY
ImageType.GrayscaleType
BufferedImage
of typeTYPE_BYTE_GRAY
ImageType.GrayscaleAlphaType
BufferedImage
of typeTYPE_USHORT_GRAY
ImageType.PaletteType
BufferedImage
of typeTYPE_BYTE_BINARY
(for images with a palette of <= 16 colors) orTYPE_BYTE_INDEXED
ImageType.PaletteAlphaType
BufferedImage
of typeTYPE_BYTE_BINARY
(for images with a palette of <= 16 colors) orTYPE_BYTE_INDEXED
ImageType.TrueColorType
BufferedImage
of typeTYPE_3BYTE_BGR
ImageType.TrueColorPaletteType
BufferedImage
of typeTYPE_4BYTE_ABGR
- Parameters:
pImage
- the originalMagickImage
- Returns:
- a new
BufferedImage
- Throws:
IllegalArgumentException
- ifpImage
isnull
or if theImageType
is not one mentioned above.magick.MagickException
- if an exception occurs during conversion- See Also:
-
toMagick
Converts aBufferedImage
to aMagickImage
.The conversion depends on
pImage
'sColorModel
:IndexColorModel
with 1 bit b/wMagickImage
of typeImageType.BilevelType
IndexColorModel
> 1 bit,MagickImage
of typeImageType.PaletteType
orMagickImage
of typeImageType.PaletteAlphaType
depending on ColorModel.getAlpha()ColorModel.getColorSpace().getType() == ColorSpace.TYPE_GRAY
MagickImage
of typeImageType.GrayscaleType
orMagickImage
of typeImageType.GrayscaleAlphaType
depending on ColorModel.getAlpha()ColorModel.getColorSpace().getType() == ColorSpace.TYPE_RGB
MagickImage
of typeImageType.TrueColorType
orMagickImage
of typeImageType.TrueColorPaletteType
- Parameters:
pImage
- the originalBufferedImage
- Returns:
- a new
MagickImage
- Throws:
IllegalArgumentException
- ifpImage
isnull
or if theColorModel
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-levelMagickImage
to aBufferedImage
, of typeTYPE_BYTE_BINARY
.- Parameters:
pImage
- the originalMagickImage
- 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 grayMagickImage
to aBufferedImage
, of typeTYPE_USHORT_GRAY
orTYPE_BYTE_GRAY
.- Parameters:
pImage
- the originalMagickImage
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-basedMagickImage
to aBufferedImage
, of typeTYPE_BYTE_BINARY
(for images with a palette of <= 16 colors) orTYPE_BYTE_INDEXED
.- Parameters:
pImage
- the originalMagickImage
pAlpha
- keep alpha channel- Returns:
- a new
BufferedImage
- Throws:
magick.MagickException
- if an exception occurs during conversion- See Also:
-
createIndexColorModel
Creates anIndexColorModel
from an array ofPixelPacket
s.- Parameters:
pColormap
- the original colormap as aPixelPacket
arraypAlpha
- keep alpha channel- Returns:
- a new
IndexColorModel
-
rgbToBuffered
private static BufferedImage rgbToBuffered(magick.MagickImage pImage, boolean pAlpha) throws magick.MagickException Converts an (A)RGBMagickImage
to aBufferedImage
, of typeTYPE_4BYTE_ABGR
orTYPE_3BYTE_BGR
.- Parameters:
pImage
- the originalMagickImage
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 anMagickImage
to aBufferedImage
which holds an CMYK ICC profile- Parameters:
pImage
- the originalMagickImage
pAlpha
- keep alpha channel- Returns:
- a new
BufferedImage
- Throws:
magick.MagickException
- if an exception occurs during conversion- See Also:
-