PngEncodeOptions

class PngEncodeOptions(val colorType: PngColorType = PngColorType.Auto, val bitDepth: Int? = null, val interlace: Boolean = false, val effort: Int = 2)(source)

How ImageKodec.encodePng writes a PNG (#182). Every choice is lossless: the file decodes to exactly the pixels it was given, so a colorType or bitDepth that cannot hold the image makes the encode throw rather than change a pixel.

  • colorType: PngColorType.Auto (the default) picks the smallest type that holds the image; another value fixes the type.

  • bitDepth: bits a sample, or null for the fewest that hold the image. Gray takes 1, 2, 4, 8 or 16; a palette 1, 2, 4 or 8; gray with alpha, RGB and RGBA 8 or 16. PngColorType.Auto takes null only.

  • interlace: writes Adam7 interlace (PNG, Third Edition, 8.2), which a browser draws coarse first. The file is usually a little larger.

  • effort: from 1 (fast) to 3 (thorough), default 2. At 1, PngColorType.Auto takes the type of fewest bytes before compression, and the rows are filtered by the rule of PNG, Third Edition, 12.8 (no filter for a palette or samples under 8 bits, one chosen a row otherwise) and compressed with a short match search: two to four times as fast as 2, and 5 to 10 percent larger on photographs. At 2, Auto also tries the best type without a palette, and each type is compressed three ways, filtered a row at a time and unfiltered with the usual search, and filtered with Huffman coding alone, the smallest kept: never larger than the call without options. At 3, every type that holds the image, both palette orders (by frequency and by luminance), and six filter choices with three match searches are tried, and the best three are compressed again with a long lazy search: 7 to 24 times slower than 2, and 3 to 9 percent smaller on photographs. The output is the same on every platform at every effort.

Throws

if bitDepth is not one colorType takes, or effort is outside 1..3

Constructors

Link copied to clipboard
constructor(colorType: PngColorType = PngColorType.Auto, bitDepth: Int? = null, interlace: Boolean = false, effort: Int = 2)

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val effort: Int
Link copied to clipboard

Functions

Link copied to clipboard
open override fun toString(): String