GifDecoder

actual class GifDecoder(data: RandomAccessData, cacheFrameInterval: Int) : AutoCloseable(source)

A class for decoding GIF files. Other than cached frames, configured with cacheFrameInterval, all frames are decoded only when requested, minimizing memory usage.

Usage:

// Obtain a Path to read the GIF data from
val path: Path = ...
val data = path.asRandomAccess()
val decoder = GifDecoder(data)

// Read a single frame by index
val frame1 = decoder[0]

// Read a single frame by timestamp
val frame2 = decoder[2.seconds]

// Read all frames
decoder.asSequence().forEach { frame ->
// Process each frame
}

decoder.close()

Parameters

data

The RandomAccessData to read the GIF data from.

cacheFrameInterval

The interval at which frames are cached. Setting this to a higher value can improve random access speed with get, but increases memory usage.

Set to 1 to cache every frame, making random access speed similar to that of Array. Warning: this can cause the decoder to use a large amount of memory.

Set to 0 to disable caching, which will decrease the initial load time and minimize memory usage. Disable caching if you only need to read frames sequentially using asSequence or get in increasing order of their index or timestamp.

Throws

If the GIF data is invalid and cannot be decoded.

If an I/O error occurs.

expect class GifDecoder(data: RandomAccessData, cacheFrameInterval: Int = DEFAULT_GIF_CACHE_FRAME_INTERVAL) : AutoCloseable(source)

A class for decoding GIF files. Other than cached frames, configured with cacheFrameInterval, all frames are decoded only when requested, minimizing memory usage.

Usage:

// Obtain a Path to read the GIF data from
val path: Path = ...
val data = path.asRandomAccess()
val decoder = GifDecoder(data)

// Read a single frame by index
val frame1 = decoder[0]

// Read a single frame by timestamp
val frame2 = decoder[2.seconds]

// Read all frames
decoder.asSequence().forEach { frame ->
// Process each frame
}

decoder.close()

Parameters

data

The RandomAccessData to read the GIF data from.

cacheFrameInterval

The interval at which frames are cached. Setting this to a higher value can improve random access speed with get, but increases memory usage.

Set to 1 to cache every frame, making random access speed similar to that of Array. Warning: this can cause the decoder to use a large amount of memory.

Set to 0 to disable caching, which will decrease the initial load time and minimize memory usage. Disable caching if you only need to read frames sequentially using asSequence or get in increasing order of their index or timestamp.

Throws

If the GIF data is invalid and cannot be decoded.

If an I/O error occurs.

actual class GifDecoder(data: RandomAccessData, cacheFrameInterval: Int) : AutoCloseable(source)

A class for decoding GIF files. Other than cached frames, configured with cacheFrameInterval, all frames are decoded only when requested, minimizing memory usage.

Usage:

// Obtain a Path to read the GIF data from
val path: Path = ...
val data = path.asRandomAccess()
val decoder = GifDecoder(data)

// Read a single frame by index
val frame1 = decoder[0]

// Read a single frame by timestamp
val frame2 = decoder[2.seconds]

// Read all frames
decoder.asSequence().forEach { frame ->
// Process each frame
}

decoder.close()

Parameters

data

The RandomAccessData to read the GIF data from.

cacheFrameInterval

The interval at which frames are cached. Setting this to a higher value can improve random access speed with get, but increases memory usage.

Set to 1 to cache every frame, making random access speed similar to that of Array. Warning: this can cause the decoder to use a large amount of memory.

Set to 0 to disable caching, which will decrease the initial load time and minimize memory usage. Disable caching if you only need to read frames sequentially using asSequence or get in increasing order of their index or timestamp.

Throws

If the GIF data is invalid and cannot be decoded.

If an I/O error occurs.

Constructors

Link copied to clipboard
constructor(path: ERROR CLASS: Symbol not found for JavaPath, cacheFrameInterval: Int = DEFAULT_GIF_CACHE_FRAME_INTERVAL)

Constructs a GifDecoder, reading GIF data from a file.

constructor(file: ERROR CLASS: Symbol not found for File, cacheFrameInterval: Int = DEFAULT_GIF_CACHE_FRAME_INTERVAL)

Constructs a GifDecoder, reading GIF data from a file.

actual constructor(data: RandomAccessData, cacheFrameInterval: Int)
actual constructor(bytes: ByteArray, cacheFrameInterval: Int)

Constructs a GifDecoder, reading GIF data from a byte array.

expect constructor(data: RandomAccessData, cacheFrameInterval: Int = DEFAULT_GIF_CACHE_FRAME_INTERVAL)
expect constructor(bytes: ByteArray, cacheFrameInterval: Int = DEFAULT_GIF_CACHE_FRAME_INTERVAL)

Constructs a GifDecoder, reading GIF data from a byte array.

actual constructor(data: RandomAccessData, cacheFrameInterval: Int)
actual constructor(bytes: ByteArray, cacheFrameInterval: Int)

Constructs a GifDecoder, reading GIF data from a byte array.

Properties

Link copied to clipboard
actual val comment: String

The comment in the GIF comment block metadata. This can be an empty string if no comment is present.

expect val comment: String

The comment in the GIF comment block metadata. This can be an empty string if no comment is present.

actual val comment: String

The comment in the GIF comment block metadata. This can be an empty string if no comment is present.

Link copied to clipboard
actual val duration: Duration

The total duration of the GIF, which is the sum of all frame durations.

expect val duration: Duration

The total duration of the GIF, which is the sum of all frame durations.

actual val duration: Duration

The total duration of the GIF, which is the sum of all frame durations.

Link copied to clipboard
actual val frameCount: Int

The total number of frames in the GIF.

expect val frameCount: Int

The total number of frames in the GIF.

actual val frameCount: Int

The total number of frames in the GIF.

Link copied to clipboard

A list of FrameInfos, containing the duration and timestamp of each frame.

A list of FrameInfos, containing the duration and timestamp of each frame.

A list of FrameInfos, containing the duration and timestamp of each frame.

Link copied to clipboard
actual val height: Int

The height of the GIF in pixels.

expect val height: Int

The height of the GIF in pixels.

actual val height: Int

The height of the GIF in pixels.

Link copied to clipboard
val javaDuration: ERROR CLASS: Symbol not found for JavaDuration

The total duration of the GIF, which is the sum of all frame durations.

Link copied to clipboard
actual val loopCount: Int

The number of times the GIF is set to loop.

expect val loopCount: Int

The number of times the GIF is set to loop.

actual val loopCount: Int

The number of times the GIF is set to loop.

Link copied to clipboard
actual val width: Int

The width of the GIF in pixels.

expect val width: Int

The width of the GIF in pixels.

actual val width: Int

The width of the GIF in pixels.

Functions

Link copied to clipboard
actual fun asList(): List<ImageFrame>

Returns a List view of all frames in the GIF. The returned list's random access speed depends on the cacheFrameInterval.

expect fun asList(): List<ImageFrame>

Returns a List view of all frames in the GIF. The returned list's random access speed depends on the cacheFrameInterval.

actual fun asList(): List<ImageFrame>

Returns a List view of all frames in the GIF. The returned list's random access speed depends on the cacheFrameInterval.

Link copied to clipboard

Returns a Sequence view of all frames in the GIF.

Returns a Sequence view of all frames in the GIF.

Returns a Sequence view of all frames in the GIF.

Link copied to clipboard
actual open override fun close()

Closes the decoder, closing the underlying data.

expect open override fun close()

Closes the decoder, closing the underlying data.

actual open override fun close()

Closes the decoder, closing the underlying data.

Link copied to clipboard
operator fun get(timestamp: ERROR CLASS: Symbol not found for JavaDuration): ImageFrame
actual operator fun get(timestamp: Duration): ImageFrame

Reads a frame by its timestamp.

actual operator fun get(index: Int): ImageFrame

Reads a frame by its index.

expect operator fun get(index: Int): ImageFrame

Reads a frame by its index.

expect operator fun get(timestamp: Duration): ImageFrame

Reads a frame by its timestamp.

actual operator fun get(index: Int): ImageFrame

Reads a frame by its index.

actual operator fun get(timestamp: Duration): ImageFrame

Reads a frame by its timestamp.

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