encodeJp2

fun encodeJp2(bitmap: KiteBitmap, quality: Int = 75): ByteArray(source)

Encode bitmap as a lossy JPEG 2000 file (JP2) at quality 0..100 (default 75), as Jp2EncodeOptions describes with its defaults: the 9/7 wavelet over five resolution levels, code-blocks truncated until the error meets a peak signal-to-noise ratio of 20 + 0.28 * quality dB. Gray when every pixel is gray, RGB otherwise, with an opacity channel when any pixel carries alpha. decode reads it back, and so does OpenJPEG.

Throws

if quality is outside 0..100


fun encodeJp2(bitmap: KiteBitmap, options: Jp2EncodeOptions, metadata: ImageMetadata = ImageMetadata(), cancellationCheck: () -> Unit? = null): ByteArray(source)

Encode bitmap as JPEG 2000 with every choice of options (#180): lossy at a quality or at a compression ratio a layer, or lossless with the reversible 5/3 wavelet and colour transform, in a JP2 file or as a bare codestream, in tiles, resolution levels, code-blocks, precincts and quality layers of the sizes asked for, in any progression order. Gray when every pixel is gray, RGB otherwise, with an opacity channel, which a channel definition box (cdef) describes, when any pixel carries alpha. A lossless file decodes to bitmap exactly.

A JP2 file carries metadata: the ICC profile as its colour specification when the profile is gray or RGB as the image is, else the enumerated sRGB or greyscale space; the XMP packet in the UUID box XMP assigns to JPEG 2000; and the EXIF block in the UUID box exiftool reads. A bare codestream carries none of it. cancellationCheck runs before each tile and each code-block, and what it throws comes out of this call as it is.

Throws

if options asks more than 8 bits a sample of a KiteBitmap, or tiles so small that the image needs more than 65535 of them