Class MaskColors
java.lang.Object
com.itextpdf.pdfoptimizer.handlers.util.MaskColors
Wrapper class for an array presented as /Mask entry of the image. It is implemented as immutable class.
-
Method Summary
Modifier and TypeMethodDescriptionstatic MaskColors
create
(com.itextpdf.kernel.pdf.PdfArray array) Creates an instance of MaskArray based on /Mask entry of the image dictionary.getConvertedColorMask
(long maximumComponentValue, ColorConverter converter) Converts maskArray from one color space to another according to providedColorConverter
.getConvertedColorMask
(long maximumComponentValue, ColorConverter converter, ColorDecoder colorDecoder) Converts maskArray from one color space to another according to providedColorConverter
andColorDecoder
.long[]
getMax()
Gets maximum color to mask out which is defined by the elements at odd positions of the original array (considering the array as 0-indexed).long[]
getMin()
Gets minimum color to mask out which is defined by the elements at even positions of the original array (considering the array as 0-indexed).boolean
isColorMasked
(long[] color) Checks if provided color is masked by the current mask because all its components are in the range defined by the min and max arrays of the mask.com.itextpdf.kernel.pdf.PdfArray
Creates a maskPdfArray
from provided object.
-
Method Details
-
create
Creates an instance of MaskArray based on /Mask entry of the image dictionary.- Parameters:
-
array
- is a Mask array, may be null - Returns:
-
a MaskArray wrapper or null if
array
is null - Throws:
-
com.itextpdf.kernel.exceptions.PdfException
- if provided MaskArray is invalid: empty or contains odd number of elements
-
getConvertedColorMask
Converts maskArray from one color space to another according to providedColorConverter
. It is expected that source color space of the converter matches the color space of the mask. Otherwise exception will be thrown.- Parameters:
-
maximumComponentValue
- is a maximum value of each component. Unlike double representing of the color components, long components depend on the color depth and may represent different colors when used with different bits per component. Maximum component value notifies the maximum possible value for each component which usually is calculated as2 ^ (bitsPerComponent) - 1
. However it is possible to use the method in another setting with any other maximum component value. It is expected that every value of the mask represented by this instance is not negative and does not exceed themaximumComponentValue
-
converter
- is a color converter. It is expected that its source color space which can be identified viaColorConverter.getSourceColorspace()
matches the color space of the mask (at least it has the same number of components asgetMin()
andgetMax()
arrays). Otherwise, exception will be thrown - Returns:
-
new instance of
MaskColors
representing the same mask in new color space. For converted arrays it is expected that each element of one of them is not greater then the corresponding element of the second one. - Throws:
-
com.itextpdf.kernel.exceptions.PdfException
- ifmaskColor
andconverted
do not match
-
getConvertedColorMask
public MaskColors getConvertedColorMask(long maximumComponentValue, ColorConverter converter, ColorDecoder colorDecoder) Converts maskArray from one color space to another according to providedColorConverter
andColorDecoder
. It is expected that source color space of the converter matches the color space of the mask. Otherwise, exception will be thrown.- Parameters:
-
maximumComponentValue
- is a maximum value of each component. Unlike double representing of the color components, long components depend on the color depth and may represent different colors when used with different bits per component. Maximum component value notifies the maximum possible value for each component which usually is calculated as2 ^ (bitsPerComponent) - 1
. However it is possible to use the method in another setting with any other maximum component value. It is expected that every value of the mask represented by this instance is not negative and does not exceed themaximumComponentValue
-
converter
- is a color converter. It is expected that its source color space which can be identified viaColorConverter.getSourceColorspace()
matches the color space of the mask (at least it has the same number of components asgetMin()
andgetMax()
arrays). Otherwise exception will be thrown -
colorDecoder
-ColorDecoder
- Returns:
-
new instance of
MaskColors
representing the same mask in new color space. For converted arrays it is expected that each element of one of them is not greater then the corresponding element of the second one. - Throws:
-
com.itextpdf.kernel.exceptions.PdfException
- ifmaskColor
andconverted
do not match
-
getMin
public long[] getMin()Gets minimum color to mask out which is defined by the elements at even positions of the original array (considering the array as 0-indexed).- Returns:
- minimum color of mask out
-
getMax
public long[] getMax()Gets maximum color to mask out which is defined by the elements at odd positions of the original array (considering the array as 0-indexed).- Returns:
- minimum color of mask out
-
isColorMasked
public boolean isColorMasked(long[] color) Checks if provided color is masked by the current mask because all its components are in the range defined by the min and max arrays of the mask.- Parameters:
-
color
- is a color to check - Returns:
-
true
if check is valid (provided color has the expected number of components) and all color should be masked. Otherwise returnsfalse
-
toPdfArray
public com.itextpdf.kernel.pdf.PdfArray toPdfArray()Creates a maskPdfArray
from provided object.- Returns:
- a mask array
-