encodeTiff

Encode bitmap as a TIFF: 8-bit gray when every pixel is gray, RGB otherwise, with an unassociated alpha sample when any pixel carries alpha. Lossless: decoding the result returns the exact same pixels.

The file is little endian, in strips of about 8 KiB compressed with Deflate after the horizontal differencing predictor, as libtiff writes with -c zip -p 2. The overload with TiffEncodeOptions writes the other compressions, tiles, bi-level and palette pages, and encodeTiffCmyk writes CMYK.


Encode pages as one multi-page TIFF, a directory a page in order, each written as encodeTiff writes a single bitmap and marked with its page number. probe reports their count as pageCount, and decodePage reads each back.

Throws


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

Encode bitmap as a TIFF as options says (#184): the compression (none, PackBits, LZW, Deflate, CCITT Group 3 or 4, or JPEG), strips or tiles, and the samples (bi-level, gray, palette or RGB). TiffEncodeOptions() gives what encodeTiff without options gives, byte for byte. Every combination is lossless but JPEG, a bi-level page, and a gray page made from colour: decoding the result returns the exact same pixels.

metadata's ICC profile goes in InterColorProfile (tag 34675) and its XMP packet in tag 700. Its EXIF block is taken apart (#186): the descriptive tags of its IFD0 (make, model, date, orientation, resolution and the like) join the page's directory in place of the writer's own resolution, and its EXIF and GPS directories follow, rewritten little endian at new offsets, behind tags 34665 and 34853. Its thumbnail directory (IFD1) is left out.

cancellationCheck, when given, runs before each strip or tile and every 64 rows of fax coding, and may throw to stop the encode; what it throws comes out of this call as it is.

Throws

if options do not fit bitmap: a CCITT compression with samples other than bi-level, or wider than 65536 pixels a strip or tile; JPEG with alpha or with bi-level or palette samples; a palette for a bitmap with alpha or more than 256 colours; or a JPEG strip of rows that is not a whole number of blocks


fun encodeTiff(pages: List<KiteBitmap>, options: TiffEncodeOptions, metadata: ImageMetadata = ImageMetadata(), cancellationCheck: () -> Unit? = null): ByteArray(source)

Encode pages as one multi-page TIFF, each page as encodeTiff with options writes one and marked with its page number. Every page carries metadata's ICC profile; the XMP packet and the EXIF block go with the first.

Throws

if pages is empty, or as encodeTiff with options does