Class PngConfig.Builder

java.lang.Object
com.sixlegs.png.PngConfig.Builder
Enclosing class:
PngConfig

public static final class PngConfig.Builder extends Object
Builder class used to construct PngConfig instances. Each "setter" method returns an reference to the instance to enable chaining multiple calls. Call build() to construct a new PngConfig instance using the current Builder settings. Example:
PngConfig config = new PngConfig.Builder()
        .readLimit(PngConfig.READ_EXCEPT_METADATA)
        .warningsFatal(true)
        .build();
  • Constructor Details

    • Builder

      public Builder()
      Create a new builder using default values.
    • Builder

      public Builder(PngConfig cfg)
      Create a builder using values from the given configuration.
      Parameters:
      cfg - the configuration to copy
  • Method Details

    • build

      public PngConfig build()
      Create a configuration using the current values of this builder.
    • reduce16

      public PngConfig.Builder reduce16(boolean reduce16)
      Enables or disables 16-bit reduction. If enabled, 16-bit samples are reduced to 8-bit samples by shifting to the right by 8 bits. Default is true.
      Parameters:
      reduce16 - enable 16-bit reduction
    • defaultGamma

      public PngConfig.Builder defaultGamma(float defaultGamma)
      Sets the default gamma value. This value is used unless the image contains an explicit gamma value. Initial value is 1/45455.
      Parameters:
      defaultGamma - the default gamma value
    • displayExponent

      public PngConfig.Builder displayExponent(float displayExponent)
      Sets the default display exponent. The proper setting depends on monitor and OS gamma lookup table settings, if any. The default value of 2.2 should work well with most PC displays. If the operating system has a gamma lookup table (e.g. Macintosh) the display exponent should be lower.
      Parameters:
      displayExponent - the display exponent
    • gammaCorrect

      public PngConfig.Builder gammaCorrect(boolean gammaCorrect)
      Enables or disables gamma correction. If enabled, decoded images will be gamma corrected. Sets to false if your application will perform gamma correctly manually. Default is true.
      Parameters:
      gammaCorrect - use gamma correction
      See Also:
    • progressive

      public PngConfig.Builder progressive(boolean progressive)
      Enables or disables progressive display for interlaced images. If enabled, each received pixel is expanded (replicated) to fill a rectangle covering the yet-to-be-transmitted pixel positions below and to the right of the received pixel. This produces a "fade-in" effect as the new image gradually replaces the old, at the cost of some additional processing time. Default is false.
      Parameters:
      progressive - use progressive display
      See Also:
    • readLimit

      public PngConfig.Builder readLimit(int readLimit)
      Configures how much of the image to read. Useful when one is interested in only a portion of the image metadata, and would like to avoid reading and/or decoding the actual image data.
      Parameters:
      readLimit - READ_ALL,
      READ_HEADER,
      READ_UNTIL_DATA,
      READ_EXCEPT_DATA,
      or READ_EXCEPT_METADATA
    • warningsFatal

      public PngConfig.Builder warningsFatal(boolean warningsFatal)
      Configures whether warnings should be treated as fatal errors. All non-fatal PngException exceptions are caught and passed to the PngImage.handleWarning(com.sixlegs.png.PngException) method. If warnings are configured as fatal, that method will re-throw the exception, which will abort image processing. Default is false.
      Parameters:
      warningsFatal - true if warnings should be treated as fatal errors
      See Also:
    • sourceRegion

      public PngConfig.Builder sourceRegion(Rectangle sourceRegion)
      Decode only a particular region of the source image. See the equivalent ImageIO method for full documentation.
    • sourceSubsampling

      public PngConfig.Builder sourceSubsampling(int xsub, int ysub, int xoff, int yoff)
      Reduce the size of the decoded image (or source region) by only using periodic rows and/or columns of the image. See the equivalent ImageIO method for full documentation.
    • convertIndexed

      public PngConfig.Builder convertIndexed(boolean convertIndexed)
      Whether to convert images with an indexed color model (paletted and 1/2/4/8-bit grayscale) to use a component color model.