Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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
- data Context a = Context {}
- type FileContext = Context Handle
- open :: MonadIO io => FilePath -> io FileContext
- close :: MonadIO io => FileContext -> io ()
- type BytesContext = Context ByteString
- bytes :: MonadIO io => ByteString -> io BytesContext
- levels :: (ReadChunk src, MonadIO io) => Context src -> io (Vector Level)
- levelToPtr :: (ReadLevel src, MonadIO io) => Context src -> Level -> Ptr () -> io Bool
- levelData :: (ReadChunk src, MonadIO io) => Context src -> Level -> io ByteString
- dataFormatDescriptor :: (ReadChunk src, MonadIO io) => Context src -> io DFD
- keyValueData :: (ReadChunk src, MonadIO io) => Context src -> io KeyValueData
- supercompressionGlobalData :: (ReadChunk src, MonadIO io) => Context src -> io ByteString
- class ReadChunk a where
- readChunkAt :: MonadIO io => a -> Int -> Int -> io ByteString
- newtype ChunkError = ChunkError Text
- decodeAt :: (ReadChunk src, Show a, MonadIO io) => src -> Int -> Int -> Get a -> io a
- data DecodeError = DecodeError ByteOffset Text
- class ReadLevel a where
- readLevelTo :: MonadIO io => a -> Level -> Ptr () -> io Bool
Documentation
A bundle of source data and header information used by reader functions.
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.
bytes :: MonadIO io => ByteString -> io BytesContext Source #
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 #
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
ReadChunk Handle Source # | |
Defined in Codec.Ktx2.Read readChunkAt :: MonadIO io => Handle -> Int -> Int -> io ByteString Source # | |
ReadChunk ByteString Source # | |
Defined in Codec.Ktx2.Read readChunkAt :: MonadIO io => ByteString -> Int -> Int -> io ByteString Source # |
newtype ChunkError Source #
Instances
Exception ChunkError Source # | |
Defined in Codec.Ktx2.Read toException :: ChunkError -> SomeException # fromException :: SomeException -> Maybe ChunkError # displayException :: ChunkError -> String # | |
Show ChunkError Source # | |
Defined in Codec.Ktx2.Read showsPrec :: Int -> ChunkError -> ShowS # show :: ChunkError -> String # showList :: [ChunkError] -> ShowS # | |
Eq ChunkError Source # | |
Defined in Codec.Ktx2.Read (==) :: ChunkError -> ChunkError -> Bool # (/=) :: ChunkError -> ChunkError -> Bool # |
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.
data DecodeError Source #
Instances
Exception DecodeError Source # | |
Defined in Codec.Ktx2.Read | |
Show DecodeError Source # | |
Defined in Codec.Ktx2.Read showsPrec :: Int -> DecodeError -> ShowS # show :: DecodeError -> String # showList :: [DecodeError] -> ShowS # | |
Eq DecodeError Source # | |
Defined in Codec.Ktx2.Read (==) :: DecodeError -> DecodeError -> Bool # (/=) :: DecodeError -> DecodeError -> Bool # |
class ReadLevel a where Source #
Instances
ReadLevel Handle Source # | |
Defined in Codec.Ktx2.Read | |
ReadLevel ByteString Source # | |
Defined in Codec.Ktx2.Read readLevelTo :: MonadIO io => ByteString -> Level -> Ptr () -> io Bool Source # |