JpegEncodeOptions

class JpegEncodeOptions(val quality: Int = 90, val subsampling: JpegSubsampling = JpegSubsampling.Auto, val progressive: Boolean = false, val optimizeHuffman: Boolean = false, val arithmetic: Boolean = false, val arithmeticDcLower: Int = 0, val arithmeticDcUpper: Int = 1, val arithmeticAcThreshold: Int = 5, val grayscale: JpegGrayscale = JpegGrayscale.Auto, val restartInterval: Int = 0, val encoder: JpegEncoderKind = JpegEncoderKind.Fast, val precision: Int = 8, val lossless: Boolean = false, val predictor: Int = 1, val pointTransform: Int = 0)(source)

How ImageKodec.encodeJpeg and ImageKodec.encodeJpeg16 write a JPEG (#183): the process of ITU-T T.81, the entropy coding, the components and their sampling. Every parameter has a default, and the defaults write what ImageKodec.encodeJpeg writes from a quality alone: an 8-bit baseline file with the example Huffman tables of T.81 Annex K. The one change is grayscale, which by default writes a gray picture as one component.

The processes: a sequential DCT file (baseline SOF0 at 8 bits, extended SOF1 at 12), a progressive one (SOF2), the arithmetic-coded forms of both (SOF9, SOF10), and a lossless one (SOF3, or SOF11 with arithmetic). Hierarchical files are not written.

Throws

if a value is outside its range, or two options exclude each other, each named in the message

Constructors

Link copied to clipboard
constructor(quality: Int = 90, subsampling: JpegSubsampling = JpegSubsampling.Auto, progressive: Boolean = false, optimizeHuffman: Boolean = false, arithmetic: Boolean = false, arithmeticDcLower: Int = 0, arithmeticDcUpper: Int = 1, arithmeticAcThreshold: Int = 5, grayscale: JpegGrayscale = JpegGrayscale.Auto, restartInterval: Int = 0, encoder: JpegEncoderKind = JpegEncoderKind.Fast, precision: Int = 8, lossless: Boolean = false, predictor: Int = 1, pointTransform: Int = 0)

Properties

Link copied to clipboard

arithmetic coding by T.81 Annex D's QM coder with the models of F.1.4, G.1.3 and H.1.2.3, in place of Huffman coding: commonly a tenth smaller than Huffman coding with tables built for the file, and read by fewer programs (no browser reads it).

Link copied to clipboard

the AC conditioning Kx, 1 to 63 (T.81 F.1.4.4.2). The three are written in a DAC segment, and set only with arithmetic.

Link copied to clipboard

the lower conditioning bound L of the DAC segment, 0 to 15, for the DC coefficients or the lossless differences (T.81 F.1.4.4.1.2). The default is T.81's.

Link copied to clipboard

the upper bound U, arithmeticDcLower to 15.

Link copied to clipboard

which encoder makes the coefficients. JpegEncoderKind.Jpegli honours every option of an 8-bit DCT file: its progressive, arithmetic and optimized files hold the coefficients of its baseline file, and its gray file is the luma of its colour one.

Link copied to clipboard

one component or three; see JpegGrayscale.

Link copied to clipboard

a lossless file of T.81 Annex H: the difference of each sample from the prediction of predictor, so ImageKodec.decode16 returns every bit. Three components are stored as RGB, with no colour transform, and none is subsampled.

Link copied to clipboard

Huffman tables built from the file's own symbol counts (T.81 K.2, limited to 16 bits by K.3), in a second pass, in place of the example tables: smaller and slower. A 12-bit or lossless Huffman file always gets them, since the example tables do not hold its larger categories. Not with arithmetic, which has no Huffman tables.

Link copied to clipboard

the low bits a lossless file drops, 0 to precision - 1: they come back as zeros. Set only with lossless.

Link copied to clipboard

the bits a sample: 8, or 12 for a DCT file, which only ImageKodec.encodeJpeg16 writes; 2 to 16 for a lossless file. Each sample is the top precision bits of the 16-bit sample, which ImageKodec.decode16 widens back.

Link copied to clipboard

the lossless predictor of T.81 Table H.1, 1 to 7: 1 the sample to the left, 2 above, 3 above left, 4 left + above - above left, 5 and 6 halfway forms of 4, and 7 the mean of left and above. Set only with lossless.

Link copied to clipboard

a progressive file by the scan script libjpeg uses by default: a first DC scan of every component at half precision, the AC coefficients of each component in bands by spectral selection and two steps of successive approximation, then the refinements. Its Huffman tables are always built for the file, since the example ones have no end-of-band runs.

Link copied to clipboard

0 to 100, higher is better, as each encoder maps it to its tables. 0 writes what 1 writes, as libjpeg reads 0. A lossless file ignores it.

Link copied to clipboard

the number of MCUs between restart markers, 0 for none, up to 65535. A lossless interval must hold whole rows of MCUs, as T.81 H.1.1 asks and libjpeg-turbo requires, which the encode checks against the width.

Link copied to clipboard

the chroma sampling of a three-component DCT file. A lossless file takes JpegSubsampling.Auto or JpegSubsampling.S444 only, and JpegEncoderKind.Jpegli JpegSubsampling.Auto or JpegSubsampling.S420 only, its matrices being tuned for 4:2:0.

Functions

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