Class MaskColors

java.lang.Object
com.itextpdf.pdfoptimizer.handlers.util.MaskColors

public final class MaskColors extends Object
Wrapper class for an array presented as /Mask entry of the image. It is implemented as immutable class.
  • Method Summary

    Modifier and Type
    Method
    Description
    static 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 provided ColorConverter.
    getConvertedColorMask(long maximumComponentValue, ColorConverter converter, ColorDecoder colorDecoder)
    Converts maskArray from one color space to another according to provided ColorConverter and ColorDecoder.
    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 mask PdfArray from provided object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • create

      public static MaskColors create (com.itextpdf.kernel.pdf.PdfArray array)
      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

      public MaskColors getConvertedColorMask (long maximumComponentValue, ColorConverter converter)
      Converts maskArray from one color space to another according to provided ColorConverter. 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 as 2 ^ (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 the maximumComponentValue
      converter - is a color converter. It is expected that its source color space which can be identified via ColorConverter.getSourceColorspace() matches the color space of the mask (at least it has the same number of components as getMin() and getMax() 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 - if maskColor and converted do not match
    • getConvertedColorMask

      public MaskColors getConvertedColorMask (long maximumComponentValue, ColorConverter converter, ColorDecoder colorDecoder)
      Converts maskArray from one color space to another according to provided ColorConverter and ColorDecoder. 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 as 2 ^ (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 the maximumComponentValue
      converter - is a color converter. It is expected that its source color space which can be identified via ColorConverter.getSourceColorspace() matches the color space of the mask (at least it has the same number of components as getMin() and getMax() 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 - if maskColor and converted 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 returns false
    • toPdfArray

      public com.itextpdf.kernel.pdf.PdfArray toPdfArray()
      Creates a mask PdfArray from provided object.
      Returns:
      a mask array