ktx-codec-0.0.2.0: Khronos texture format
Safe HaskellSafe-Inferred
LanguageHaskell2010

Codec.Ktx2.Read

Description

Block-by-block extraction of data from a KTX2 file.

  • Acquire a Context. Header data is available without reading the rest of the source.
  • Read levels index. An memory allocation information is available.
  • Consult supercompressionScheme and copy level data to decompression staging buffer or GPU memory directly.

Extra information is available when needed:

  • Image metadata.
  • Data Format Descriptor. Khronos Basic descriptor block is usually present, but a file may contain more.
  • Supercompression data shared between all the levels.
Synopsis

Documentation

data Context a Source #

A bundle of source data and header information used by reader functions.

Constructors

Context 

Fields

Instances

Instances details
Show (Context Handle) Source # 
Instance details

Defined in Codec.Ktx2.Read

Show (Context ByteString) Source # 
Instance details

Defined in Codec.Ktx2.Read

type FileContext = Context Handle Source #

Context for reading from a file. The file has to be seekable.

close :: MonadIO io => FileContext -> io () Source #

type BytesContext = Context ByteString Source #

Context for reading from memory. Useful when the data is embedded in a module or otherwise already available in full.

Reading blocks

Image data

levels :: (ReadChunk src, MonadIO io) => Context src -> io (Vector Level) Source #

Read the level index.

levelToPtr :: (ReadLevel src, MonadIO io) => Context src -> Level -> Ptr () -> io Bool Source #

Copy level data into a provided pointer.

The buffer must be large enough for the byteLength of the Level being accessed.

levelData :: (ReadChunk src, MonadIO io) => Context src -> Level -> io ByteString Source #

Copy level data into a managed buffer.

Supplemental information

dataFormatDescriptor :: (ReadChunk src, MonadIO io) => Context src -> io DFD Source #

Read DFD block data.

Further processing is performed according to descriptor vendortypeversion. E.g. Codec.Ktx2.DFD.Khronos.BasicV2.

keyValueData :: (ReadChunk src, MonadIO io) => Context src -> io KeyValueData Source #

Read and parse Key-Value Data block.

supercompressionGlobalData :: (ReadChunk src, MonadIO io) => Context src -> io ByteString Source #

Get a copy of global supercompression data.

Decoding internals

class ReadChunk a where Source #

Methods

readChunkAt :: MonadIO io => a -> Int -> Int -> io ByteString Source #

Get a chunk of data.

The context handle must have enough information to check whether requested region is safe to access. Throw ChunkError when it isn't possible to fullfill the request.

Instances

Instances details
ReadChunk Handle Source # 
Instance details

Defined in Codec.Ktx2.Read

Methods

readChunkAt :: MonadIO io => Handle -> Int -> Int -> io ByteString Source #

ReadChunk ByteString Source # 
Instance details

Defined in Codec.Ktx2.Read

Methods

readChunkAt :: MonadIO io => ByteString -> Int -> Int -> io ByteString Source #

newtype ChunkError Source #

Constructors

ChunkError Text 

Instances

Instances details
Exception ChunkError Source # 
Instance details

Defined in Codec.Ktx2.Read

Show ChunkError Source # 
Instance details

Defined in Codec.Ktx2.Read

Eq ChunkError Source # 
Instance details

Defined in Codec.Ktx2.Read

decodeAt :: (ReadChunk src, Show a, MonadIO io) => src -> Int -> Int -> Get a -> io a Source #

Get a chunk of data and run a decoder on it.

class ReadLevel a where Source #

Methods

readLevelTo :: MonadIO io => a -> Level -> Ptr () -> io Bool Source #

Instances

Instances details
ReadLevel Handle Source # 
Instance details

Defined in Codec.Ktx2.Read

Methods

readLevelTo :: MonadIO io => Handle -> Level -> Ptr () -> io Bool Source #

ReadLevel ByteString Source # 
Instance details

Defined in Codec.Ktx2.Read

Methods

readLevelTo :: MonadIO io => ByteString -> Level -> Ptr () -> io Bool Source #