Jp2EncodeOptions
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
Properties
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.
the height of a code-block, a power of two from 4 to 1024; the two together at most 4096 samples
the width of a code-block, a power of two from 4 to 1024
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.
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.
an EPH marker after each packet header
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.
the side of a precinct on each resolution, a power of two from 2 to 32768, or 0 for one precinct a resolution
the packet order
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.
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.
reset the coding contexts after each pass (code-block style 0x02)
a segmentation symbol after each cleanup pass (code-block style 0x20)
an SOP marker before each packet, for resynchronisation
end the arithmetic coder after each pass (code-block style 0x04)
the height of a tile, or 0 for one tile as tall as the image
vertically causal contexts (code-block style 0x08)