public class IMGUtils
extends java.lang.Object
Changed checkColorDepth method to remove potential problems with alpha.
| Modifier and Type | Method and Description |
|---|---|
static int[] |
checkColorDepth(int[] rgbTriplets,
byte[] newPixels,
int[] colorPalette)
Check the color depth of the image and if the color depth is within 8 bits, (i.e.,
a indexed color image), a color map and an index array for the image are also created.
|
static void |
correctGamma(int[] rgbColorPalette,
byte[] gammaTable) |
static byte[] |
createGammaTable(float gamma,
float displayExponent) |
static java.awt.image.BufferedImage |
createThumbnail(java.io.InputStream is)
Creates a thumbnail from image input stream
|
static _8BIM |
createThumbnail8BIM(java.awt.image.BufferedImage thumbnail)
Wraps a BufferedImage inside a Photoshop _8BIM
|
static void |
dither_Bayer(byte[] gray,
byte[] mask,
int width,
int height,
int[][] threshold)
Dither gray-scale image using Bayer threshold matrix
|
static void |
dither_Bayer(int[] rgbTriplet,
int width,
int height,
byte[] newPixels,
int no_of_color,
int[] colorPalette,
int transparent_index,
int[][] threshold)
Dither color image using Bayer threshold matrix.
|
static void |
dither_FloydSteinberg(byte[] gray,
byte[] mask,
int width,
int height,
int threshold)
Dither gray-scale image using Floyd-Steinberg error diffusion
|
static void |
dither_FloydSteinberg(int[] rgbTriplet,
int width,
int height,
byte[] newPixels,
int no_of_color,
int[] colorPalette,
int transparent_index)
Floyd-Steinberg dithering, based on PPMQuant.c by Jef Poskanzer
|
static byte[] |
easyRGB2CMYK(int[] rgb,
boolean hasAlpha) |
static java.awt.image.BufferedImage |
filterImage(java.awt.image.BufferedImageOp bufferedImageOp,
java.awt.image.BufferedImage srcImg,
java.awt.image.BufferedImage dstImg)
Entry point for image filtering operation.
|
static int |
getBitDepth(byte[] input,
boolean hasAlpha) |
static java.awt.color.ICC_ColorSpace |
getICCColorSpace(java.lang.String pathToICCProfile) |
static java.awt.color.ICC_Profile |
getICCProfile(java.lang.String pathToICCProfile) |
static int[] |
getRGB(java.awt.image.BufferedImage image)
Retrieves RGB values from Raster.
|
static int[] |
getRGB2(java.awt.image.BufferedImage image)
Retrieves RGB values from DataBuffer.
|
static java.awt.image.BufferedImage |
getScaledInstance(java.awt.image.BufferedImage img,
int targetWidth,
int targetHeight,
java.lang.Object hint,
boolean higherQuality)
Convenience method that returns a scaled instance of the
provided
BufferedImage. |
static ImageType |
guessImageType(byte[] magicNumber) |
static ImageType |
guessImageType(PeekHeadInputStream is) |
static ImageType |
guessImageType(RandomAccessInputStream is) |
static java.awt.image.WritableRaster |
iccp2rgbRaster(java.awt.image.WritableRaster raster,
java.awt.image.ColorModel cm)
Convert ICC_ColorSpace raster to RGB raster w/o alpha
|
static void |
invertBits(byte[] input,
int pixelStride) |
static void |
invertBits(short[] input,
int pixelStride) |
static int[] |
reduceColors(QuantMethod quantMethod,
int[] rgbTriplets,
int colorDepth,
byte[] newPixels,
int[] colorPalette,
boolean fullAlpha) |
static int[] |
reduceColorsDiffusionDither(int[] rgbTriplets,
int width,
int height,
int colorDepth,
byte[] newPixels,
int[] colorPalette)
Reduces a true color image to an indexed-color image with no_of_color using "Popularity algorithm"
followed by Floyd-Steinberg error diffusion dithering.
|
static int[] |
reduceColorsDiffusionDither(QuantMethod quantMethod,
int[] rgbTriplets,
int width,
int height,
int colorDepth,
byte[] newPixels,
int[] colorPalette) |
static int[] |
reduceColorsOrderedDither(int[] rgbTriplet,
int width,
int height,
int colorDepth,
byte[] newPixels,
int[] colorPalette,
int[][] threshold) |
static int[] |
reduceColorsOrderedDither(QuantMethod quantMethod,
int[] rgbTriplets,
int width,
int height,
int colorDepth,
byte[] newPixels,
int[] colorPalette,
int[][] threshold) |
static byte[] |
rgb2bilevel(int[] rgb) |
static byte[] |
rgb2bilevelDiffusionDither(int[] rgb,
int imageWidth,
int imageHeight)
RGB to bilevel image conversion with Floyd-Steinberg dither
|
static byte[] |
rgb2bilevelOrderedDither(int[] rgb,
int imageWidth,
int imageHeight,
int[][] threshold) |
static void |
RGB2CMYK_Inverted(java.awt.color.ICC_ColorSpace cmykColorSpace,
int[] rgb,
float[][] C,
float[][] M,
float[][] Y,
float[][] K,
int imageWidth,
int imageHeight) |
static void |
RGB2CMYK(java.awt.color.ICC_ColorSpace cmykColorSpace,
int[] rgb,
float[][] C,
float[][] M,
float[][] Y,
float[][] K,
int imageWidth,
int imageHeight) |
static byte[] |
RGB2CMYK(java.awt.color.ICC_ColorSpace cmykColorSpace,
int[] rgb,
int imageWidth,
int imageHeight,
boolean hasAlpha) |
static byte[] |
rgb2grayscale(int[] rgb) |
static float[][] |
rgb2grayscale(int[] rgb,
int imageWidth,
int imageHeight) |
static byte[] |
rgb2grayscaleA(int[] rgb) |
static byte[] |
RGB2YCbCr(int[] rgb) |
static void |
RGB2YCbCr(int[][] red,
int[][] green,
int[][] blue,
float[][] Y,
float[][] Cb,
float[][] Cr,
int imageWidth,
int imageHeight) |
static void |
RGB2YCbCr(int[] rgb,
float[][] Y,
float[][] Cb,
float[][] Cr,
int imageWidth,
int imageHeight) |
static byte[] |
RGB2YCbCrA(int[] rgba) |
static void |
RGB2YCCK_Inverted(java.awt.color.ICC_ColorSpace cmykColorSpace,
int[] rgb,
float[][] Y,
float[][] Cb,
float[][] Cr,
float[][] K,
int imageWidth,
int imageHeight) |
public static int[] checkColorDepth(int[] rgbTriplets,
byte[] newPixels,
int[] colorPalette)
This method is not yet completely finished. The colorPalette is currently not ordered. A sorting method could be used to find the most used color from the colorFreq array, but more tricks will have to be done in order to re-map the newPixels array to the ordered colorPalette.
rgbTriplets - an int array of RGB triplets for the imagenewPixels - a byte array to hold the color map indexes for the imagecolorPalette - the color map for the imagepublic static byte[] createGammaTable(float gamma,
float displayExponent)
public static void correctGamma(int[] rgbColorPalette,
byte[] gammaTable)
public static java.awt.image.BufferedImage createThumbnail(java.io.InputStream is)
throws java.io.IOException
is - InputStream for the imagejava.io.IOExceptionpublic static _8BIM createThumbnail8BIM(java.awt.image.BufferedImage thumbnail) throws java.io.IOException
thumbnail - input thumbnail imagejava.io.IOExceptionpublic static void dither_Bayer(byte[] gray,
byte[] mask,
int width,
int height,
int[][] threshold)
gray - input gray-scale image array - also as output BW image arraymask - a mask array for transparent pixels - 0 transparent, 1 opaquewidth - image widthheight - image heightthreshold - Bayer threshold matrix used to convert to BW imagepublic static void dither_FloydSteinberg(byte[] gray,
byte[] mask,
int width,
int height,
int threshold)
gray - input gray-scale image array - also as output BW image arraymask - a mask array for transparent pixels - 0 transparent, 1 opaquewidth - image widthheight - image heightthreshold - gray-scale threshold to convert to BW imagepublic static void dither_Bayer(int[] rgbTriplet,
int width,
int height,
byte[] newPixels,
int no_of_color,
int[] colorPalette,
int transparent_index,
int[][] threshold)
rgbTriplet - input pixels in ARGB formatwidth - image widthheight - image heightnewPixels - pixel array after ditherno_of_color - actual number of colors used by the color palettecolorPalette - color palettetransparent_index - transparent color index for the color palettethreshold - Bayer threshold matrixpublic static void dither_FloydSteinberg(int[] rgbTriplet,
int width,
int height,
byte[] newPixels,
int no_of_color,
int[] colorPalette,
int transparent_index)
rgbTriplet - input pixels in ARGB formatwidth - width of the imageheight - height of the imagenewPixels - output pixelsno_of_color - number of colors usedcolorPalette - color palettetransparent_index - transparent color index of the color palettepublic static byte[] easyRGB2CMYK(int[] rgb,
boolean hasAlpha)
public static java.awt.image.BufferedImage filterImage(java.awt.image.BufferedImageOp bufferedImageOp,
java.awt.image.BufferedImage srcImg,
java.awt.image.BufferedImage dstImg)
public static int getBitDepth(byte[] input,
boolean hasAlpha)
public static java.awt.color.ICC_ColorSpace getICCColorSpace(java.lang.String pathToICCProfile)
throws java.io.IOException
java.io.IOExceptionpublic static java.awt.color.ICC_Profile getICCProfile(java.lang.String pathToICCProfile)
throws java.io.IOException
java.io.IOExceptionpublic static int[] getRGB(java.awt.image.BufferedImage image)
image - input BufferedImagepublic static int[] getRGB2(java.awt.image.BufferedImage image)
image - input BufferedImagepublic static java.awt.image.BufferedImage getScaledInstance(java.awt.image.BufferedImage img,
int targetWidth,
int targetHeight,
java.lang.Object hint,
boolean higherQuality)
BufferedImage.img - the original image to be scaledtargetWidth - the desired width of the scaled instance,
in pixelstargetHeight - the desired height of the scaled instance,
in pixelshint - one of the rendering hints that corresponds to
RenderingHints.KEY_INTERPOLATION (e.g.
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR,
RenderingHints.VALUE_INTERPOLATION_BILINEAR,
RenderingHints.VALUE_INTERPOLATION_BICUBIC)higherQuality - if true, this method will use a multi-step
scaling technique that provides higher quality than the usual
one-step technique (only useful in down-scaling cases, where
targetWidth or targetHeight is
smaller than the original dimensions, and generally only when
the BILINEAR hint is specified)BufferedImagepublic static ImageType guessImageType(byte[] magicNumber)
public static ImageType guessImageType(PeekHeadInputStream is) throws java.io.IOException
java.io.IOExceptionpublic static ImageType guessImageType(RandomAccessInputStream is) throws java.io.IOException
java.io.IOExceptionpublic static java.awt.image.WritableRaster iccp2rgbRaster(java.awt.image.WritableRaster raster,
java.awt.image.ColorModel cm)
raster - WritableRaster for ICC_Profile ColorSpacecm - ColorModel for ICC_Profile ColorSpacepublic static void invertBits(byte[] input,
int pixelStride)
public static void invertBits(short[] input,
int pixelStride)
public static int[] reduceColors(QuantMethod quantMethod, int[] rgbTriplets, int colorDepth, byte[] newPixels, int[] colorPalette, boolean fullAlpha)
public static int[] reduceColorsDiffusionDither(int[] rgbTriplets,
int width,
int height,
int colorDepth,
byte[] newPixels,
int[] colorPalette)
public static int[] reduceColorsDiffusionDither(QuantMethod quantMethod, int[] rgbTriplets, int width, int height, int colorDepth, byte[] newPixels, int[] colorPalette)
public static int[] reduceColorsOrderedDither(int[] rgbTriplet,
int width,
int height,
int colorDepth,
byte[] newPixels,
int[] colorPalette,
int[][] threshold)
public static int[] reduceColorsOrderedDither(QuantMethod quantMethod, int[] rgbTriplets, int width, int height, int colorDepth, byte[] newPixels, int[] colorPalette, int[][] threshold)
public static byte[] rgb2bilevel(int[] rgb)
public static byte[] rgb2bilevelOrderedDither(int[] rgb,
int imageWidth,
int imageHeight,
int[][] threshold)
public static byte[] rgb2bilevelDiffusionDither(int[] rgb,
int imageWidth,
int imageHeight)
rgb - input RGB image array (format: ARGBARGBARGB...)imageWidth - image widthimageHeight - image heightpublic static void RGB2CMYK(java.awt.color.ICC_ColorSpace cmykColorSpace,
int[] rgb,
float[][] C,
float[][] M,
float[][] Y,
float[][] K,
int imageWidth,
int imageHeight)
public static byte[] RGB2CMYK(java.awt.color.ICC_ColorSpace cmykColorSpace,
int[] rgb,
int imageWidth,
int imageHeight,
boolean hasAlpha)
public static void RGB2CMYK_Inverted(java.awt.color.ICC_ColorSpace cmykColorSpace,
int[] rgb,
float[][] C,
float[][] M,
float[][] Y,
float[][] K,
int imageWidth,
int imageHeight)
public static byte[] rgb2grayscale(int[] rgb)
public static float[][] rgb2grayscale(int[] rgb,
int imageWidth,
int imageHeight)
public static byte[] rgb2grayscaleA(int[] rgb)
public static byte[] RGB2YCbCr(int[] rgb)
public static void RGB2YCbCr(int[] rgb,
float[][] Y,
float[][] Cb,
float[][] Cr,
int imageWidth,
int imageHeight)
public static void RGB2YCbCr(int[][] red,
int[][] green,
int[][] blue,
float[][] Y,
float[][] Cb,
float[][] Cr,
int imageWidth,
int imageHeight)
public static byte[] RGB2YCbCrA(int[] rgba)
public static void RGB2YCCK_Inverted(java.awt.color.ICC_ColorSpace cmykColorSpace,
int[] rgb,
float[][] Y,
float[][] Cb,
float[][] Cr,
float[][] K,
int imageWidth,
int imageHeight)