Class AutoDetectColorType
- java.lang.Object
-
- net.sourceforge.jiu.ops.Operation
-
- net.sourceforge.jiu.color.reduction.AutoDetectColorType
-
public class AutoDetectColorType extends Operation
Detects the minimum (in terms of memory) color type of an image. Can convert the original image to that new input type on demand.Input parameters: image to be examined, boolean that specifies whether conversion will be performed (default is true, conversion is performed). Output parameters: converted image, boolean that expresses whether a conversion was possible.
Supported types for input image: RGB24Image, Gray8Image, Paletted8Image.
BilevelImage is not supported because there is no smaller image type, so bilevel images cannot be reduced.
This operation is not a
ImageToImageOperation
because this class need not necessarily produce a new image (withsetConversion(boolean)
(false)).Usage example
This code snippet loads an image and attempts to reduce it to the minimum color type that will hold it.PixelImage image = ImageLoader.load("test.bmp"); AutoDetectColorType op = new AutoDetectColorType(); op.setInputImage(image); op.process(); if (op.isReducible()) { image = op.getOutputImage(); }
- Author:
- Marco Schmidt
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
doConvert
private Histogram3D
hist
private PixelImage
inputImage
private PixelImage
outputImage
private int
type
static int
TYPE_BILEVEL
static int
TYPE_GRAY16
static int
TYPE_GRAY8
static int
TYPE_PALETTED8
static int
TYPE_RGB24
static int
TYPE_RGB48
static int
TYPE_UNKNOWN
-
Constructor Summary
Constructors Constructor Description AutoDetectColorType()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
createBilevelFromGrayOrRgb(IntegerImage in)
Creates a bilevel image from any grayscale (or RGB) image that has been checked to be bilevel.private void
createBilevelFromPaletted(Paletted8Image in)
private void
createGray8FromGray16(Gray16Image in)
private void
createGray8FromPaletted8(Paletted8Image in, Gray8Image out)
private void
createGrayFromRgb(IntegerImage in, IntegerImage out)
private void
createPaletted8FromRgb24(RGB24Image in)
private void
createPaletted8FromRgb48(RGB48Image in)
private void
createRgb24FromRgb48(RGB48Image in, RGB24Image out)
PixelImage
getOutputImage()
Returns the reduced output image if one was created inprocess()
.int
getType()
Returns the type of the minimum image type found (one of the TYPE_xyz constants of this class).private boolean
isGray16Gray8(Gray16Image in)
private boolean
isGrayBilevel(IntegerImage in)
boolean
isReducible()
This method can be called afterprocess()
to find out if the input image in fact can be reduced to a "smaller" image type.private boolean
isRgb24Paletted8(RGB24Image in)
private boolean
isRgb48Gray8(RGB48Image in)
private boolean
isRgb48Paletted8(RGB48Image in)
Assumes that it has already been verified that the input 48 bpp RGB image is also a 24 bpp RGB image.private boolean
isRgb48Rgb24(RGB48Image in)
private boolean
isRgbBilevel(IntegerImage in)
private boolean
isRgbGray(RGBIntegerImage in)
Returns if the input RGB image can be losslessly converted to a grayscale image.void
process()
This method does the actual work of the operation.void
setConversion(boolean convert)
This method can be used to specify whether the input image is to be converted to the minimum image type if it is clear that such a conversion is possible.void
setInputImage(PixelImage image)
This method must be used to specify the mandatory input image.-
Methods inherited from class net.sourceforge.jiu.ops.Operation
addProgressListener, addProgressListeners, getAbort, removeProgressListener, setAbort, setProgress, setProgress
-
-
-
-
Field Detail
-
TYPE_UNKNOWN
public static final int TYPE_UNKNOWN
- See Also:
- Constant Field Values
-
TYPE_BILEVEL
public static final int TYPE_BILEVEL
- See Also:
- Constant Field Values
-
TYPE_GRAY16
public static final int TYPE_GRAY16
- See Also:
- Constant Field Values
-
TYPE_GRAY8
public static final int TYPE_GRAY8
- See Also:
- Constant Field Values
-
TYPE_PALETTED8
public static final int TYPE_PALETTED8
- See Also:
- Constant Field Values
-
TYPE_RGB24
public static final int TYPE_RGB24
- See Also:
- Constant Field Values
-
TYPE_RGB48
public static final int TYPE_RGB48
- See Also:
- Constant Field Values
-
inputImage
private PixelImage inputImage
-
outputImage
private PixelImage outputImage
-
doConvert
private boolean doConvert
-
type
private int type
-
hist
private Histogram3D hist
-
-
Method Detail
-
createBilevelFromGrayOrRgb
private void createBilevelFromGrayOrRgb(IntegerImage in)
Creates a bilevel image from any grayscale (or RGB) image that has been checked to be bilevel.
-
createBilevelFromPaletted
private void createBilevelFromPaletted(Paletted8Image in)
-
createGrayFromRgb
private void createGrayFromRgb(IntegerImage in, IntegerImage out)
-
createGray8FromGray16
private void createGray8FromGray16(Gray16Image in)
-
createGray8FromPaletted8
private void createGray8FromPaletted8(Paletted8Image in, Gray8Image out)
-
createPaletted8FromRgb24
private void createPaletted8FromRgb24(RGB24Image in)
-
createPaletted8FromRgb48
private void createPaletted8FromRgb48(RGB48Image in)
-
createRgb24FromRgb48
private void createRgb24FromRgb48(RGB48Image in, RGB24Image out)
-
getOutputImage
public PixelImage getOutputImage()
Returns the reduced output image if one was created inprocess()
.- Returns:
- newly-created output image
-
getType
public int getType()
Returns the type of the minimum image type found (one of the TYPE_xyz constants of this class). Can only be called after a successful call to process.
-
isReducible
public boolean isReducible()
This method can be called afterprocess()
to find out if the input image in fact can be reduced to a "smaller" image type. If this method returnstrue
and if conversion was desired by the user (can be specified viasetConversion(boolean)
), the reduced image can be retrieved viagetOutputImage()
.- Returns:
- if image was found to be reducible in process()
-
isGrayBilevel
private boolean isGrayBilevel(IntegerImage in)
-
isGray16Gray8
private boolean isGray16Gray8(Gray16Image in)
-
isRgb48Gray8
private boolean isRgb48Gray8(RGB48Image in)
-
isRgb48Paletted8
private boolean isRgb48Paletted8(RGB48Image in)
Assumes that it has already been verified that the input 48 bpp RGB image is also a 24 bpp RGB image.- Parameters:
in
- input image to be checked- Returns:
- if this image can be losslessly converted to a Paletted8Image
-
isRgb48Rgb24
private boolean isRgb48Rgb24(RGB48Image in)
-
isRgbBilevel
private boolean isRgbBilevel(IntegerImage in)
-
isRgbGray
private boolean isRgbGray(RGBIntegerImage in)
Returns if the input RGB image can be losslessly converted to a grayscale image.- Parameters:
in
- RGB image to be checked- Returns:
- true if input is gray, false otherwise
-
isRgb24Paletted8
private boolean isRgb24Paletted8(RGB24Image in)
-
process
public void process() throws MissingParameterException, WrongParameterException
Description copied from class:Operation
This method does the actual work of the operation. It must be called after all parameters have been given to the operation object.- Overrides:
process
in classOperation
- Throws:
MissingParameterException
- if any mandatory parameter was not given to the operationWrongParameterException
- if at least one of the input parameters was not initialized appropriately (values out of the valid interval, etc.)
-
setConversion
public void setConversion(boolean convert)
This method can be used to specify whether the input image is to be converted to the minimum image type if it is clear that such a conversion is possible. The default value istrue
. If this is set tofalse
, it can still be- Parameters:
convert
- if true, the conversion will be performed
-
setInputImage
public void setInputImage(PixelImage image)
This method must be used to specify the mandatory input image.- Parameters:
image
- PixelImage object to be examined
-
-