Jp2EncodeOptions

class Jp2EncodeOptions(val quality: Int = 75, val lossless: Boolean = false, val ratios: List<Double> = emptyList(), val layers: Int = 1, val codestreamOnly: Boolean = false, val tileWidth: Int = 0, val tileHeight: Int = 0, val levels: Int = 5, val codeBlockWidth: Int = 64, val codeBlockHeight: Int = 64, val precinctSize: Int = 0, val progression: Jp2Progression = Jp2Progression.LRCP, val effort: Int = 2, val bypass: Boolean = false, val resetContexts: Boolean = false, val terminateEachPass: Boolean = false, val verticalCausal: Boolean = false, val segmentationSymbols: Boolean = false, val sopMarkers: Boolean = false, val ephMarkers: Boolean = false, val bitsPerSample: Int = 0, val highThroughput: Boolean = false)(source)

How ImageKodec.encodeJp2 writes a JPEG 2000 file (#180). Every parameter has a default, so name only those to change. The defaults write a lossy JP2 file at quality 75: the 9/7 wavelet over five resolution levels, one tile, code-blocks of 64 by 64, one quality layer in Jp2Progression.LRCP order.

Throws

if a parameter is out of the range given here, ratios and a layers other than 1 disagree on the number of layers, or highThroughput meets more than one layer or an arithmetic coder style

Constructors

Link copied to clipboard
constructor(quality: Int = 75, lossless: Boolean = false, ratios: List<Double> = emptyList(), layers: Int = 1, codestreamOnly: Boolean = false, tileWidth: Int = 0, tileHeight: Int = 0, levels: Int = 5, codeBlockWidth: Int = 64, codeBlockHeight: Int = 64, precinctSize: Int = 0, progression: Jp2Progression = Jp2Progression.LRCP, effort: Int = 2, bypass: Boolean = false, resetContexts: Boolean = false, terminateEachPass: Boolean = false, verticalCausal: Boolean = false, segmentationSymbols: Boolean = false, sopMarkers: Boolean = false, ephMarkers: Boolean = false, bitsPerSample: Int = 0, highThroughput: Boolean = false)

Properties

Link copied to clipboard

the bit depth of each component, 1 to 16, or 0 for the bitmap's own: 8 for a KiteBitmap, 16 for a KiteBitmap16. A sample is scaled to it and rounded, so a KiteBitmap16 that ImageKodec.decode16 read from a 12-bit file encodes losslessly at 12 bits. At most 8 for a KiteBitmap.

Link copied to clipboard

the selective arithmetic coding bypass (code-block style 0x01): the significance and refinement passes below the fourth bit plane are written raw, which is faster to decode

Link copied to clipboard

the height of a code-block, a power of two from 4 to 1024; the two together at most 4096 samples

Link copied to clipboard

the width of a code-block, a power of two from 4 to 1024

Link copied to clipboard

true for a bare codestream (J2K), as a PDF embeds one, without the JP2 boxes; the metadata, the colour space and the channel definitions are then not written.

Link copied to clipboard
val effort: Int

1 to 3, higher is slower. 1 sizes the layers from the code-block bytes alone and quantizes more coarsely. 2 sizes each layer exactly, packet headers included. 3 does what 2 does and, for a lossless tile of three or more components, also codes the tile without the colour transform and keeps the smaller.

Link copied to clipboard

an EPH marker after each packet header

Link copied to clipboard

the high-throughput block coder of HTJ2K (ITU-T T.814, code-block style 0x40) in place of Part 1's arithmetic coder. On photo-like pictures ImageKodec decodes such a file 1.3 to 4 times as fast, and it is 4 to 35 percent larger at the same PSNR. A lossless one encodes about three times as fast; a lossy one takes up to twice as long, since the encoder codes every HT set a block could take before it picks one. The codestream gets a CAP segment, and a JP2 file the jph brand, so a reader of Part 1 alone refuses it. Each code-block is one HT set: a cleanup pass and, lossy, the SigProp and MagRef passes below it. The file has one quality layer, and bypass, resetContexts, terminateEachPass and segmentationSymbols, which only the arithmetic coder has, stay off; verticalCausal still applies.

Link copied to clipboard
val layers: Int

the quality layers when ratios is empty, 1 to 100: the last meets quality or holds the lossless image, and each one before it is about half the size of the next.

Link copied to clipboard
val levels: Int

the wavelet decomposition levels, 0 to 32. A tile too small for them gets as many as its shorter side allows, so ImageKodec.decodeReduced can drop each one.

Link copied to clipboard

true for the reversible 5/3 wavelet and colour transform with nothing truncated: the decode returns every sample exactly. quality is then not used.

Link copied to clipboard

the side of a precinct on each resolution, a power of two from 2 to 32768, or 0 for one precinct a resolution

Link copied to clipboard

the packet order

Link copied to clipboard

0 to 100, higher is better: the lossy target when ratios is empty. The encoder aims at a peak signal-to-noise ratio of 20 + 0.28 * quality dB over all components, as opj_compress -q aims at the ratio it is given: 34 dB at 50, 41 dB at 75, 48 dB at 100. It truncates code-block passes after a rate and distortion sort (T.800 Annex J) until the estimated error reaches the target.

Link copied to clipboard

the compression ratio of each quality layer, raw size over coded size, the first layer the most compressed, as opj_compress -r 40,20,10 takes them; each at least 1 and none larger than the one before. The raw size is width times height times components times bits a sample over 8. Empty for the quality target. With lossless, they give the layers before a last one that holds everything.

Link copied to clipboard

reset the coding contexts after each pass (code-block style 0x02)

Link copied to clipboard

a segmentation symbol after each cleanup pass (code-block style 0x20)

Link copied to clipboard

an SOP marker before each packet, for resynchronisation

Link copied to clipboard

end the arithmetic coder after each pass (code-block style 0x04)

Link copied to clipboard

the height of a tile, or 0 for one tile as tall as the image

Link copied to clipboard

the width of a tile, or 0 for one tile as wide as the image

Link copied to clipboard

vertically causal contexts (code-block style 0x08)

Functions

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