Package-level declarations

Types

Link copied to clipboard

An auxiliary image of the primary image of a HEIC or AVIF file (#154): an image item that an auxl reference ties to the primary image, of the kind its auxC property names. ImageKodec.auxiliaryImages lists them and ImageKodec.decodeAuxiliaryImage decodes one.

Link copied to clipboard
class BmpEncodeOptions(val bitsPerPixel: Int? = null, val rle: Boolean = false)

The settings of a BMP encode (#184), for ImageKodec.encodeBmp. The defaults give the bytes the call without options gives.

Link copied to clipboard
class CcittEncodeOptions(val k: Int = -1, val encodedByteAlign: Boolean = false, val blackIs1: Boolean = false, val endOfLine: Boolean = false, val endOfBlock: Boolean = true)

How ImageKodec.encodeCcitt writes fax data. The parameters are the ones PDF's CCITTFaxDecode filter and io.github.yuroyami.imagekodec.codec.CcittFax.decode take, with PDF's defaults except for k, so a reader given the same values reads the data back.

Link copied to clipboard
class ColorProfile(val icc: ByteArray? = null, val iccName: String? = null, val srgbIntent: Int? = null, val gamma: Int? = null, val chromaticities: IntArray? = null, val cicp: IntArray? = null, val contentLight: IntArray? = null, val masteringDisplay: IntArray? = null)

What a file declares about the color space of its samples, as it declares it: ImageInfo.colorProfile reports it, and a decode with ColorTarget.Srgb or ImageKodec.convertToSrgb converts through it. Nearly every image is sRGB and says so or says nothing; the rest, such as a Display P3 photo or an Adobe RGB scan, draw with the wrong colors unless they are converted.

Link copied to clipboard
sealed class ColorTarget

Where a decode leaves the colours of its samples, as Android's ImageDecoder.setTargetColorSpace sets it.

Link copied to clipboard
@RequiresOptIn(message = "The HEIF codec interface may change between releases.", level = RequiresOptIn.Level.ERROR)
annotation class ExperimentalHeifCodecApi

Marks the interface through which a module adds the codec of a HEIF item type. It may still change between releases, so a caller opts in to use it.

Link copied to clipboard
class GainMap(val jpeg: ByteArray, val primaryIso: ByteArray? = null)

The gain map of an Ultra HDR JPEG (#130): a second, small JPEG after the main image that tells an HDR screen how much brighter each area of the photo may be drawn. ImageKodec.readMetadata finds it through the Multi-Picture Format segment of the main image, and an encodeJpeg with the metadata writes it again after the new main image, with an MPF segment that points to it.

Link copied to clipboard

The gain map metadata of ISO 21496-1, as the payload of a tmap item holds it (GainMapMetadata, read as libavif's avifParseToneMappedImageBox reads it). Each fraction of the payload is given as its numerator divided by its denominator; raw keeps the payload as stored.

Link copied to clipboard
enum class HeifChroma : Enum<HeifChroma>

How the chroma of a HEIF picture is stored: at half the luma's width and height (Yuv420), at half its width (Yuv422), or at full size (Yuv444). A gray picture stores no chroma at all, whatever this says.

Link copied to clipboard
interface HeifCodec

The codec of one coded item type of HEIF (ISO/IEC 23008-12), such as hvc1 for HEVC. The core reads the container: it finds the items, joins grids, applies alpha, crops, turns and converts to RGB. A codec only turns the coded data of one item, or of one sample of a track, into planes.

Link copied to clipboard
class HeifCodecInfo(val width: Int, val height: Int, val bitDepthLuma: Int, val bitDepthChroma: Int, val chromaFormat: Int, val colorPrimaries: Int? = null, val transferCharacteristics: Int? = null, val matrixCoefficients: Int? = null, val fullRange: Boolean? = null, val unsupportedReason: String? = null)

What a codec reads from the configuration and the coded data of an item.

Link copied to clipboard

Decodes the coded samples of one item or one track.

Link copied to clipboard
class HeifCodedPicture(val configuration: ByteArray, val data: ByteArray, val width: Int, val height: Int, val brand: String)

One coded picture: configuration is the payload of the encoder's configuration property, without its box header, and data the coded data of the item. The picture decodes to width by height, the size of the planes. brand is the brand of ISO/IEC 23008-12 Annex B, or of the codec's own HEIF specification, that the coded picture conforms to, such as heic, heix or avif, for the ftyp box.

Link copied to clipboard
class HeifCodedSample(val data: ByteArray, val frameIndex: Int, val sync: Boolean)

One coded sample of an image sequence: its data, the index from 0 in display order of the picture it codes, and whether it is a sync sample, decodable without the samples before it. A sequence's first sample is one.

Link copied to clipboard
class HeifEncodeOptions(val quality: Int = 50, val lossless: Boolean = false, val chroma: HeifChroma = HeifChroma.Yuv420, val bitDepth: Int? = null, val effort: Int = 2, val tileSize: Int? = 512, val thumbnailSize: Int? = null, val orientation: Orientation = Orientation.Normal, val keyFrameInterval: Int = 0)

The settings of a HEIF encode (#174), for ImageKodec.encodeHeic, ImageKodec.encodeHeic16, ImageKodec.encodeAvif and ImageKodec.encodeAvif16 (#176). Every parameter has a default, so name only the ones to change:

Link copied to clipboard
class HeifEncodeParameters(val quality: Int, val lossless: Boolean, val effort: Int, val colorPrimaries: Int? = null, val transferCharacteristics: Int? = null, val matrixCoefficients: Int? = null)

What a HeifEncoder makes of one picture. quality runs from 0 to 100, higher better, and is ignored when lossless asks for the planes to decode exactly as given. effort runs from 1 (fast) to 3 (thorough). The colour fields are the code points of ITU-T H.273 for the codec to signal in its own headers, or null to signal none, as for an alpha plane; HeifPlanes.fullRange gives the range.

Link copied to clipboard
interface HeifEncoder

The encoder of one coded item type of HEIF, such as hvc1 for HEVC (#174). The core writes the container: it converts RGB to planes, cuts a large picture into the tiles of a grid, and writes the items, their properties and their references. An encoder only turns the planes of one picture into the payload of its configuration property and the coded data of its item.

Link copied to clipboard

The HDR gain map of a HEIC or AVIF file (#153), as ImageKodec.decodeGainMap returns it: the decoded map and what the file says of it. It is returned, not applied. GainMap stays the gain map of an Ultra HDR JPEG, which holds JPEG bytes; this one holds decoded samples.

Link copied to clipboard
class HeifPlanes(val width: Int, val height: Int, val bitDepthLuma: Int, val bitDepthChroma: Int, val subX: Int, val subY: Int, val planes: Array<ShortArray>, val strides: IntArray, val fullRange: Boolean)

The decoded planes of one picture: luma width by height, then chroma subsampled by subX and subY (each 0 or 1), or luma alone when planes holds one plane. Each plane's rows are strides samples apart. Samples are unsigned in the low bitDepthLuma or bitDepthChroma bits of each Short. fullRange is false for the limited range of studio video.

Link copied to clipboard

The encoder of one image sequence (#177), which a HeifEncoder opens. The core hands it the pictures of the track in display order and writes the samples it returns into the track in the order they come, which is decoding order: an encoder that reorders pictures, as HEVC does with B pictures, holds a picture back and returns it later, each sample naming the picture it codes by HeifCodedSample.frameIndex. The core then writes the composition offsets (ctts) that put each picture back at its display time.

Link copied to clipboard
open class ImageDecodeException(message: String, cause: Throwable? = null) : Exception

Thrown when input claims to be an image but can't be decoded: truncated data, corrupt structures, failed checksums, dimension overflow, or no recognisable format at all.

Link copied to clipboard

Image container formats ImageKodec can identify from magic bytes. Sniffing intentionally recognises more formats than ImageKodec.decode currently handles: "that's a WebP we can't decode yet" is a far better error than "unknown format".

Link copied to clipboard
class ImageInfo(val format: ImageFormat, val width: Int, val height: Int, val bitDepth: Int, val hasAlpha: Boolean, val frameCount: Int, val loopCount: Long, val orientation: Orientation, val isDecodable: Boolean, val unsupportedReason: String? = null, val pageCount: Int = 1, val colorProfile: ColorProfile? = null)

What a file says about itself, read from its header alone: no pixel decode, no multi-megabyte allocation. This is what you want for laying out a grid before the images arrive, rejecting an upload that's 20000 px wide, or deciding whether a decoder should claim a file at all.

Link copied to clipboard
object ImageKodec

The ImageKodec facade. Everything is pure computation on byte arrays: no I/O and no platform types, so it behaves identically on every KMP target. It starts no threads of its own; a caller can hand the tiles of a grid image to its own threads through setTileRunner.

Link copied to clipboard
class ImageMetadata(val exif: ByteArray? = null, val xmp: String? = null, val icc: ByteArray? = null, val gainMap: GainMap? = null)

The metadata of a photo that a re-encode can carry over (#129): the exif block, the xmp packet and the icc colour profile. ImageKodec.readMetadata reads them from every format that carries them, and the encoders that take an ImageMetadata write what their format has a place for (#186), so a re-encoded camera photo keeps its capture date, its place, its camera and its colours. A GIF keeps no EXIF, and a BMP only the profile.

Link copied to clipboard
class Jbig2EncodeOptions(val template: Int = 0, val typicalPrediction: Boolean = true, val mmr: Boolean = false, val standalone: Boolean = false)

How ImageKodec.encodeJbig2 writes a page. Every choice is lossless: it changes the size and the time, never the pixels.

Link copied to clipboard
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)

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.

Link copied to clipboard

The order in which a JPEG 2000 codestream lays out its packets (T.800 B.12.1): by quality layer, resolution, component and precinct, in the order of the letters. LRCP gives a file that sharpens as it loads, RLCP and RPCL one that grows in size, PCRL one that fills in by area, and CPRL one component after another.

Link copied to clipboard
class JpegComponents(val width: Int, val height: Int, val componentCount: Int, val samples: ByteArray, val adobeTransform: Int)

The samples of a JPEG as the file stores them: every component after the inverse DCT and the upsampling, before any color conversion. ImageKodec.decodeJpegComponents returns it.

Link copied to clipboard
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)

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.

Link copied to clipboard

Which encoder ImageKodec.encodeJpeg uses.

Link copied to clipboard

Whether ImageKodec.encodeJpeg writes one component, the gray level, or three.

Link copied to clipboard

The chroma subsampling of a JPEG that ImageKodec.encodeJpeg writes in YCbCr.

Link copied to clipboard
class JpxColorSpecification(val method: Int, val enumerated: Int, val iccProfile: ByteArray?)

A JP2 colour specification box (T.800, I.5.3.3), as JpxComponents.colorSpecification reports it.

Link copied to clipboard
class JpxComponents(val width: Int, val height: Int, val componentCount: Int, val samples: ByteArray, val bitDepths: IntArray, val colorSpecification: JpxColorSpecification?)

The samples of a JPEG 2000 image as the codestream stores them: every component after the inverse wavelet, the multiple component transform and the DC level shift, sampled onto the image grid, and before the JP2 palette, channel definitions and colour space. ImageKodec.decodeJpxComponents returns it.

Link copied to clipboard
class JxlEncodeOptions(val quality: Int = 90, val distance: Double? = null, val lossless: Boolean = false, val effort: Int = 2, val container: Boolean = false)

How ImageKodec.encodeJxl writes a JPEG XL file (#179).

Link copied to clipboard
enum class JxrChroma : Enum<JxrChroma>

How a JPEG XR encode stores the colour of each macroblock (T.832 INTERNAL_CLR_FMT).

Link copied to clipboard
class JxrEncodeOptions(val quality: Int = 90, val lossless: Boolean = false, val chroma: JxrChroma = JxrChroma.Auto, val overlap: Int? = null, val chromaQuality: Int? = null, val planarAlpha: Boolean = true, val alphaLossless: Boolean = true, val alphaQuality: Int = 90, val tileSize: Int = 0, tileQualities: List<Int>? = null, val frequencyOrder: Boolean = false)

The settings of a JPEG XR encode (#181), for ImageKodec.encodeJxr, ImageKodec.encodeJxr16 and ImageKodec.encodeJxrCmyk.

Link copied to clipboard
class KiteAnimation(val width: Int, val height: Int, val frames: List<KiteFrame>, val loopCount: Long)

A decoded animation: GIF, APNG, animated WebP, animated AVIF and animated JPEG XL all arrive in this shape. Static images decode as a single frame, so ImageKodec.decodeAnimation is total over every supported format.

Link copied to clipboard
class KiteBitmap(val width: Int, val height: Int, val argb: IntArray)

A decoded raster image: width × height pixels, packed as non-premultiplied ARGB_8888 in a row-major argb array (argb[y * width + x], alpha in the top byte). One layout for every source format: decoders normalise grayscale, palette, BGR and 16-bit inputs into this on the way out, so consumers and the Compose interop never branch on the source format.

Link copied to clipboard
class KiteBitmap16(val width: Int, val height: Int, val channels: Int, val samples: ShortArray)

A decoded image at 16 bits a sample, for the files whose low byte matters: depth maps, scientific and medical images, heavily graded photographs. KiteBitmap keeps 8 bits a channel and is what drawing wants; this keeps every bit a 16-bit PNG or TIFF stores, and ImageKodec.decode16 is where it comes from.

Link copied to clipboard
class KiteFrame(val bitmap: KiteBitmap, val delayMillis: Int, val delayRawCentiseconds: Int)

One presented frame of an animation: the fully composited canvas (disposal methods, transparency overlay and frame offsets already applied), plus its display duration.

Link copied to clipboard
class MotionPhotoInfo(val videoOffset: Int, val videoLength: Int, val format: MotionPhotoInfo.Format)

Where the video of a Motion Photo sits in its file (#131): videoOffset bytes from the start, videoLength bytes long. format says how the file named it.

Link copied to clipboard

How a decoded image relates to the scene it was captured from: the EXIF Orientation tag (TIFF tag 274), which phone cameras write instead of physically rotating pixels. A portrait photo is usually stored landscape with Rotate90 set, so anything that draws raw decoded pixels shows it sideways.

Link copied to clipboard

The colour type a PNG is written in (PNG, Third Edition, 6.1), for PngEncodeOptions.

Link copied to clipboard
class PngEncodeOptions(val colorType: PngColorType = PngColorType.Auto, val bitDepth: Int? = null, val interlace: Boolean = false, val effort: Int = 2)

How ImageKodec.encodePng writes a PNG (#182). Every choice is lossless: the file decodes to exactly the pixels it was given, so a colorType or bitDepth that cannot hold the image makes the encode throw rather than change a pixel.

Link copied to clipboard

How a colour outside the target's gamut, or a source white that is not the target's, is mapped (ICC.1 Annex D). Perceptual and saturation use the profile's own tables when it has them; a matrix profile maps them as relative colorimetric, with black point compensation as lcms2 applies it. Absolute colorimetric keeps the source's media white instead of adapting it.

Link copied to clipboard

How ImageKodec.encodeTiff compresses each strip or tile (TIFF 6.0 Compression, tag 259).

Link copied to clipboard
class TiffEncodeOptions(val compression: TiffCompression = TiffCompression.Deflate, val photometric: TiffPhotometric = TiffPhotometric.Auto, val predictor: Boolean = true, val quality: Int = 90, val rowsPerStrip: Int = 0, val tileWidth: Int = 0, val tileLength: Int = 0)

The settings of a TIFF encode (#184), for ImageKodec.encodeTiff, ImageKodec.encodeTiff16 and ImageKodec.encodeTiffCmyk. The defaults give the bytes the calls without options give.

Link copied to clipboard

The kind of samples ImageKodec.encodeTiff writes (TIFF 6.0 PhotometricInterpretation, tag 262).

Link copied to clipboard
fun interface TileJob

One job of a TileRunner: the decode of one tile. It never throws.

Link copied to clipboard
fun interface TileRunner

Runs the independent jobs of a decode, the tiles of a HEIC or AVIF grid, on the threads it chooses (#152), and the tiles of a grid that encodeHeic codes (#174). ImageKodec.setTileRunner sets the one runner that every decode uses; the default, Serial, runs the jobs in order on the calling thread.

Link copied to clipboard

The input is a well-formed image in a format, or a format feature, ImageKodec doesn't decode: an AVIF of SMPTE ST 2085 colour, a JPEG XR of N channels. The message always names the specific feature, and ImageKodec.probe reports the same thing up front through ImageInfo.unsupportedReason, so a caller can route the file elsewhere instead of catching this.

Link copied to clipboard

The prediction filter of a lossy WebP's alpha plane (the ALPH chunk's filtering method).

Link copied to clipboard
class WebpEncodeOptions(val lossless: Boolean = false, val quality: Int = 75, val effort: Int = 2, val sharpYuv: Boolean = false, val alphaQuality: Int = 100, val alphaFilter: WebpAlphaFilter = WebpAlphaFilter.Fast, val background: Int = 0)

How ImageKodec.encodeWebp writes a WebP (#178).

Functions

Link copied to clipboard
fun KiteAnimation.cropped(x: Int, y: Int, width: Int, height: Int): KiteAnimation

cropped applied to every frame, preserving delays and loop count.

fun KiteBitmap.cropped(x: Int, y: Int, width: Int, height: Int): KiteBitmap

Return the width×height region whose top-left corner is (x, y). A full-size rectangle returns this bitmap and shares its pixel array; every smaller rectangle allocates and copies the selected pixels.

Link copied to clipboard
fun KiteAnimation.downscaledTo(targetWidth: Int, targetHeight: Int): KiteAnimation

Downscale every frame to exactly targetWidth×targetHeight with KiteBitmap.downscaledTo, preserving delays and the play count. Equal canvas dimensions return this instance.

fun KiteBitmap.downscaledTo(targetWidth: Int, targetHeight: Int): KiteBitmap

Downscale to exactly targetWidth×targetHeight with scaled's alpha-weighted box filter. The caller chooses the aspect ratio; this operation does not fit the requested dimensions inside another box. Equal dimensions return this instance.

Link copied to clipboard
Link copied to clipboard

flippedVertical applied to every frame.

Mirror top-to-bottom.

Link copied to clipboard

oriented applied to every frame, preserving delays and loop count.

Apply an EXIF orientation so the result is oriented the way the camera meant it to be seen. Orientation.Normal returns the same instance.

Link copied to clipboard

rotated180 applied to every frame.

Rotate a half turn. Dimensions are unchanged.

Link copied to clipboard

rotated270 applied to every frame.

Rotate a quarter turn counter-clockwise. Width and height swap.

Link copied to clipboard

rotated90 applied to every frame.

Rotate a quarter turn clockwise. Width and height swap.

Link copied to clipboard
fun KiteAnimation.scaled(maxWidth: Int, maxHeight: Int): KiteAnimation

Downscale every frame of an animation to fit inside maxWidth×maxHeight (same box filter and aspect handling as KiteBitmap.scaled), preserving delays and the loop count. This is where animated memory goes: a full-screen GIF shown as an avatar keeps W×H×4 bytes per frame unless scaled down.

fun KiteBitmap.scaled(maxWidth: Int, maxHeight: Int): KiteBitmap

Downscale to fit inside maxWidth×maxHeight, preserving aspect ratio, using box (area-average) filtering: each destination pixel averages the source pixels under it, each weighted by the part of it that lies in the bin, so a thin line keeps the same contrast wherever it falls and thumbnails don't shimmer the way nearest-neighbor ones do.

Link copied to clipboard

transposed applied to every frame.

Mirror across the main diagonal: dst(x, y) = src(y, x). Axes swap.

Link copied to clipboard

transversed applied to every frame.

Mirror across the anti-diagonal. Axes swap.