-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Khronos texture format -- -- This package implements low-level encoding and decoding for .ktx and -- .ktx2 files. -- -- A framework-specific wrapper may be needed to work with the decoded -- data and/or supercompression. Check out test/Spec.hs for usage -- examples. -- -- KTX 1: -- https://registry.khronos.org/KTX/specs/1.0/ktxspec.v1.html -- -- KTX 2: -- https://registry.khronos.org/KTX/specs/2.0/ktxspec.v2.html#_abstract @package ktx-codec @version 0.0.2.1 module Codec.Ktx.KeyValue type KeyValueData = Map Text Value pattern KTXcubemapIncomplete :: Text pattern KTXanimData :: Text pattern KTXastcDecodeMode :: Text pattern KTXwriterScParams :: Text pattern KTXwriter :: Text pattern KTXswizzle :: Text pattern KTXmetalPixelFormat :: Text pattern KTXdxgiFormat__ :: Text pattern KTXglFormat :: Text pattern KTXorientation :: Text -- | A wrapper for raw data. -- -- Use FromValue/ToValue to process. newtype Value Value :: ByteString -> Value text :: Text -> Value bytes :: ByteString -> Value number :: (Num a, Show a) => a -> Value class FromValue a fromValue :: FromValue a => Value -> Maybe a -- | Extract all valid (null-terminated utf8) values. textual :: KeyValueData -> Map Text Text getDataLe :: Int -> Get KeyValueData getData :: Get Word32 -> Int -> Get KeyValueData putDataLe :: KeyValueData -> Put putData :: (Word32 -> Put) -> KeyValueData -> Put instance GHC.Generics.Generic Codec.Ktx.KeyValue.Value instance GHC.Show.Show Codec.Ktx.KeyValue.Value instance GHC.Classes.Eq Codec.Ktx.KeyValue.Value instance Codec.Ktx.KeyValue.FromValue Data.Text.Internal.Text instance Codec.Ktx.KeyValue.FromValue Data.ByteString.Internal.ByteString module Codec.Ktx fromByteStringLazy :: ByteString -> Either (ByteOffset, String) Ktx fromByteString :: ByteString -> Either (ByteOffset, String) Ktx fromFile :: FilePath -> IO (Either (ByteOffset, String) Ktx) toBuilder :: Ktx -> Builder toFile :: FilePath -> Ktx -> IO () data Ktx Ktx :: Header -> KeyValueData -> MipLevels -> Ktx [header] :: Ktx -> Header [kvs] :: Ktx -> KeyValueData [images] :: Ktx -> MipLevels data Header Header :: ByteString -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Header [identifier] :: Header -> ByteString [endianness] :: Header -> Word32 [glType] :: Header -> Word32 [glTypeSize] :: Header -> Word32 [glFormat] :: Header -> Word32 [glInternalFormat] :: Header -> Word32 [glBaseInternalFormat] :: Header -> Word32 [pixelWidth] :: Header -> Word32 [pixelHeight] :: Header -> Word32 [pixelDepth] :: Header -> Word32 [numberOfArrayElements] :: Header -> Word32 [numberOfFaces] :: Header -> Word32 [numberOfMipmapLevels] :: Header -> Word32 [bytesOfKeyValueData] :: Header -> Word32 endiannessLE :: Word32 canonicalIdentifier :: ByteString type MipLevels = Vector MipLevel data MipLevel MipLevel :: Word32 -> Vector ArrayElement -> MipLevel [imageSize] :: MipLevel -> Word32 [arrayElements] :: MipLevel -> Vector ArrayElement newtype ArrayElement ArrayElement :: Vector Face -> ArrayElement [faces] :: ArrayElement -> Vector Face newtype Face Face :: Vector ZSlice -> Face [zSlices] :: Face -> Vector ZSlice newtype ZSlice ZSlice :: ByteString -> ZSlice [block] :: ZSlice -> ByteString getImages :: Header -> Get MipLevels putImages :: (Word32 -> Put) -> MipLevels -> Put mkGetWord32 :: Word32 -> Get Word32 mkPutWord32 :: Word32 -> Word32 -> Put instance GHC.Generics.Generic Codec.Ktx.Header instance GHC.Show.Show Codec.Ktx.Header instance GHC.Generics.Generic Codec.Ktx.ZSlice instance GHC.Generics.Generic Codec.Ktx.Face instance GHC.Show.Show Codec.Ktx.Face instance GHC.Generics.Generic Codec.Ktx.ArrayElement instance GHC.Show.Show Codec.Ktx.ArrayElement instance GHC.Generics.Generic Codec.Ktx.MipLevel instance GHC.Show.Show Codec.Ktx.MipLevel instance GHC.Generics.Generic Codec.Ktx.Ktx instance GHC.Show.Show Codec.Ktx.Ktx instance Data.Binary.Class.Binary Codec.Ktx.Ktx instance GHC.Show.Show Codec.Ktx.ZSlice instance Data.Binary.Class.Binary Codec.Ktx.Header module Codec.Ktx2.DFD data DFD DFD :: Word32 -> Vector Block -> DFD [dfdTotalSize] :: DFD -> Word32 [dfdBlocks] :: DFD -> Vector Block data Block Block :: Word32 -> Word32 -> Word32 -> Word32 -> ByteString -> Block [descriptorType] :: Block -> Word32 [vendorId] :: Block -> Word32 [descriptorBlockSize] :: Block -> Word32 [versionNumber] :: Block -> Word32 [body] :: Block -> ByteString instance GHC.Generics.Generic Codec.Ktx2.DFD.Block instance GHC.Show.Show Codec.Ktx2.DFD.Block instance GHC.Classes.Eq Codec.Ktx2.DFD.Block instance GHC.Generics.Generic Codec.Ktx2.DFD.DFD instance GHC.Show.Show Codec.Ktx2.DFD.DFD instance GHC.Classes.Eq Codec.Ktx2.DFD.DFD instance Data.Binary.Class.Binary Codec.Ktx2.DFD.DFD instance Data.Binary.Class.Binary Codec.Ktx2.DFD.Block module Codec.Ktx2.DFD.Khronos.BasicV2 -- | Khronos pattern VENDOR_ID :: (Eq a, Num a) => a -- | Basic DFD Block pattern DESCRIPTOR_TYPE :: (Eq a, Num a) => a -- | KDF v1.3 pattern VERSION :: (Eq a, Num a) => a -- | A basic descriptor block is designed to encode common metadata -- associated with bulk data — especially image or texture data. -- -- While this descriptor holds more information about the data -- interpretation than is needed by many applications, a comprehensive -- encoding reduces the risk of metadata needed by different APIs being -- lost in translation. -- -- The format is described in terms of a repeating axis-aligned texel -- block composed of samples. Each sample contains a single channel of -- information with a single spatial offset within the texel block, and -- consists of an amount of contiguous data. This descriptor block -- consists of information about the interpretation of the texel block as -- a whole, supplemented by a description of a number of samples taken -- from one or more planes of contiguous memory. -- -- -- https://registry.khronos.org/DataFormat/specs/1.3/dataformat.1.3.html data BasicV2 BasicV2 :: Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Vector Sample -> BasicV2 [colorModel] :: BasicV2 -> Word8 [colorPrimaries] :: BasicV2 -> Word8 [transferFunction] :: BasicV2 -> Word8 [flags] :: BasicV2 -> Word8 -- | The value held in each of these fields is one fewer than the size of -- the block in that dimension — that is, a value of 0 represents a size -- of 1, a value of 1 represents a size of 2, etc. -- -- A texel block which covers fewer than four dimensions should have a -- size of 1 in each dimension that it lacks, and therefore the -- corresponding fields in the representation should be 0. [texelBlockDimension0] :: BasicV2 -> Word8 [texelBlockDimension1] :: BasicV2 -> Word8 [texelBlockDimension2] :: BasicV2 -> Word8 [texelBlockDimension3] :: BasicV2 -> Word8 [bytesPlane0] :: BasicV2 -> Word8 [bytesPlane1] :: BasicV2 -> Word8 [bytesPlane2] :: BasicV2 -> Word8 [bytesPlane3] :: BasicV2 -> Word8 [bytesPlane4] :: BasicV2 -> Word8 [bytesPlane5] :: BasicV2 -> Word8 [bytesPlane6] :: BasicV2 -> Word8 [bytesPlane7] :: BasicV2 -> Word8 [samples] :: BasicV2 -> Vector Sample getter :: Int -> Get BasicV2 putter :: BasicV2 -> PutM () data Sample Sample :: Word16 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word8 -> Word32 -> Word32 -> Sample [bitOffset] :: Sample -> Word16 [bitLength] :: Sample -> Word8 [channelType] :: Sample -> Word8 [samplePosition0] :: Sample -> Word8 [samplePosition1] :: Sample -> Word8 [samplePosition2] :: Sample -> Word8 [samplePosition3] :: Sample -> Word8 [sampleLower] :: Sample -> Word32 [sampleUpper] :: Sample -> Word32 fromBlock :: Block -> Maybe BasicV2 toBlock :: BasicV2 -> Block unspecified :: BasicV2 pattern KHR_DF_MODEL_UNSPECIFIED :: Word8 pattern KHR_DF_MODEL_RGBSDA :: Word8 pattern KHR_DF_MODEL_YUVSDA :: Word8 pattern KHR_DF_MODEL_YIQSDA :: Word8 pattern KHR_DF_MODEL_LABSDA :: Word8 pattern KHR_DF_MODEL_CMYKA :: Word8 pattern KHR_DF_MODEL_XYZW :: Word8 pattern KHR_DF_MODEL_HSVA_ANG :: Word8 pattern KHR_DF_MODEL_HSLA_ANG :: Word8 pattern KHR_DF_MODEL_HSVA_HEX :: Word8 pattern KHR_DF_MODEL_HSLA_HEX :: Word8 pattern KHR_DF_MODEL_YCGCOA :: Word8 pattern KHR_DF_MODEL_YCCBCCRC :: Word8 pattern KHR_DF_MODEL_ICTCP :: Word8 pattern KHR_DF_MODEL_CIEXYZ :: Word8 pattern KHR_DF_MODEL_CIEXYY :: Word8 pattern KHR_DF_MODEL_DXT1A :: Word8 pattern KHR_DF_MODEL_BC1A :: Word8 pattern KHR_DF_MODEL_DXT2 :: Word8 pattern KHR_DF_MODEL_DXT3 :: Word8 pattern KHR_DF_MODEL_BC2 :: Word8 pattern KHR_DF_MODEL_DXT4 :: Word8 pattern KHR_DF_MODEL_DXT5 :: Word8 pattern KHR_DF_MODEL_BC3 :: Word8 pattern KHR_DF_MODEL_BC4 :: Word8 pattern KHR_DF_MODEL_BC5 :: Word8 pattern KHR_DF_MODEL_BC6H :: Word8 pattern KHR_DF_MODEL_BC7 :: Word8 pattern KHR_DF_MODEL_ETC1 :: Word8 pattern KHR_DF_MODEL_ETC2 :: Word8 pattern KHR_DF_MODEL_ASTC2 :: Word8 pattern KHR_DF_MODEL_ETC1S :: Word8 pattern KHR_DF_MODEL_PVRTC :: Word8 pattern KHR_DF_MODEL_PVRTC2 :: Word8 pattern KHR_DF_PRIMARIES_UNSPECIFIED :: Word8 pattern KHR_DF_PRIMARIES_BT709 :: Word8 pattern KHR_DF_PRIMARIES_SRGB :: Word8 pattern KHR_DF_PRIMARIES_BT601_EBU :: Word8 pattern KHR_DF_PRIMARIES_BT601_SMPTE :: Word8 pattern KHR_DF_PRIMARIES_BT2020 :: Word8 pattern KHR_DF_PRIMARIES_CIEXYZ :: Word8 pattern KHR_DF_PRIMARIES_ACES :: Word8 pattern KHR_DF_PRIMARIES_ACESCC :: Word8 pattern KHR_DF_PRIMARIES_NTSC1953 :: Word8 pattern KHR_DF_PRIMARIES_PAL525 :: Word8 pattern KHR_DF_PRIMARIES_DISPLAYP3 :: Word8 pattern KHR_DF_PRIMARIES_ADOBERGB :: Word8 pattern KHR_DF_TRANSFER_UNSPECIFIED :: Word8 pattern KHR_DF_TRANSFER_LINEAR :: Word8 pattern KHR_DF_TRANSFER_SRGB :: Word8 pattern KHR_DF_TRANSFER_ITU :: Word8 pattern KHR_DF_TRANSFER_NTSC :: Word8 pattern KHR_DF_TRANSFER_SLOG :: Word8 pattern KHR_DF_TRANSFER_SLOG2 :: Word8 pattern KHR_DF_TRANSFER_BT1886 :: Word8 pattern KHR_DF_TRANSFER_HLG_OETF :: Word8 pattern KHR_DF_TRANSFER_HLG_EOTF :: Word8 pattern KHR_DF_TRANSFER_PQ_EOTF :: Word8 pattern KHR_DF_TRANSFER_PQ_OETF :: Word8 pattern KHR_DF_TRANSFER_DCIP3 :: Word8 pattern KHR_DF_TRANSFER_PAL_OETF :: Word8 pattern KHR_DF_TRANSFER_PAL625_EOTF :: Word8 pattern KHR_DF_TRANSFER_ST240 :: Word8 pattern KHR_DF_TRANSFER_ACESCC :: Word8 pattern KHR_DF_TRANSFER_ACESCCT :: Word8 pattern KHR_DF_TRANSFER_ADOBERGB :: Word8 pattern KHR_DF_FLAG_ALPHA_STRAIGHT :: Word8 pattern KHR_DF_FLAG_ALPHA_PREMULTIPLIED :: Word8 pattern KHR_DF_SAMPLE_DATATYPE_FLOAT :: (Eq a, Num a) => a pattern KHR_DF_SAMPLE_DATATYPE_SIGNED :: (Eq a, Num a) => a pattern KHR_DF_SAMPLE_DATATYPE_EXPONENT :: (Eq a, Num a) => a pattern KHR_DF_SAMPLE_DATATYPE_LINEAR :: (Eq a, Num a) => a instance GHC.Generics.Generic Codec.Ktx2.DFD.Khronos.BasicV2.Sample instance GHC.Show.Show Codec.Ktx2.DFD.Khronos.BasicV2.Sample instance GHC.Classes.Eq Codec.Ktx2.DFD.Khronos.BasicV2.Sample instance GHC.Generics.Generic Codec.Ktx2.DFD.Khronos.BasicV2.BasicV2 instance GHC.Show.Show Codec.Ktx2.DFD.Khronos.BasicV2.BasicV2 instance GHC.Classes.Eq Codec.Ktx2.DFD.Khronos.BasicV2.BasicV2 instance Data.Binary.Class.Binary Codec.Ktx2.DFD.Khronos.BasicV2.Sample module Codec.Ktx2.Header data Header Header :: Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word32 -> Word64 -> Word64 -> Header -- | Specifies the image format using Vulkan VkFormat enum values. -- It can be any value defined in core Vulkan 1.2, future core versions -- or registered Vulkan extensions, except for values listed in Table 1, -- “Prohibited Formats” and any *SCALED* or -- *[2-9]PLANE* formats added in future. [vkFormat] :: Header -> Word32 -- | Specifies the size of the data type in bytes used to upload the data -- to a graphics API. When typeSize is greater than 1, software -- on big-endian systems must endian convert all image data since it is -- little-endian. When format is VK_FORMAT_UNDEFINED, typeSize -- must equal 1. [typeSize] :: Header -> Word32 [pixelWidth] :: Header -> Word32 [pixelHeight] :: Header -> Word32 [pixelDepth] :: Header -> Word32 -- | Specifies the number of array elements. If the texture is not an array -- texture, layerCount must equal 0. [layerCount] :: Header -> Word32 -- | If faceCount is equal to 6, pixelHeight must be -- equal to pixelWidth, and pixelDepth must be 0. [faceCount] :: Header -> Word32 -- | Specifies the number of levels in the Mip Level Array and, by -- extension, the number of indices in the Level Index array. A KTX file -- does not need to contain a complete mipmap pyramid. [levelCount] :: Header -> Word32 -- | Indicates if a supercompression scheme has been applied to the data in -- levelImages. It must be one of the values from Table 2, -- “Supercompression Schemes”. A value of 0 indicates no -- supercompression. [supercompressionScheme] :: Header -> Word32 -- | The offset from the start of the file of the dfdTotalSize -- field of the Data Format Descriptor. [dfdByteOffset] :: Header -> Word32 -- | The total number of bytes in the Data Format Descriptor including the -- dfdTotalSize field. dfdByteLength must equal -- dfdTotalSize. [dfdByteLength] :: Header -> Word32 -- | An arbitrary number of keyvalue pairs may follow the Index. These -- can be used to encode any arbitrary data. The kvdByteOffset field -- gives the offset of this data, i.e. that of first keyvalue pair, -- from the start of the file. The value must be 0 when kvdByteLength = -- 0. [kvdByteOffset] :: Header -> Word32 -- | The total number of bytes of key/value data including all -- keyAndValueByteLength fields, all keyAndValue fields and all -- valuePadding fields. [kvdByteLength] :: Header -> Word32 -- | The offset from the start of the file of supercompressionGlobalData. -- The value must be 0 when sgdByteLength = 0. [sgdByteOffset] :: Header -> Word64 -- | The number of bytes of supercompressionGlobalData. For -- supercompression schemes for which no reference is provided in the -- Global Data Format column of Table 2, “Supercompression Schemes”. the -- value must be 0. [sgdByteLength] :: Header -> Word64 prepare :: Integral dims => Word32 -> Word32 -> dims -> dims -> dims -> Word32 -> Header canonicalIdentifier :: ByteString pattern SC_NONE :: (Eq a, Num a) => a pattern SC_BASISLZ :: (Eq a, Num a) => a pattern SC_ZSTANDARD :: (Eq a, Num a) => a pattern SC_ZLIB :: (Eq a, Num a) => a instance GHC.Generics.Generic Codec.Ktx2.Header.Header instance GHC.Show.Show Codec.Ktx2.Header.Header instance GHC.Classes.Eq Codec.Ktx2.Header.Header instance Data.Binary.Class.Binary Codec.Ktx2.Header.Header module Codec.Ktx2.Level data Level Level :: Word64 -> Word64 -> Word64 -> Level -- | The offset from the start of the file of the first byte of image data -- for mip level. It is the offset of the first byte after any -- mipPadding. [byteOffset] :: Level -> Word64 -- | The total size of the data for supercompressed mip level. [byteLength] :: Level -> Word64 -- | the number of bytes of pixel data in LOD level after reflation from -- supercompression. This includes all z slices, all faces, all rows (or -- rows of blocks) and all pixels (or blocks) in each row for the mipmap -- level. When supercompressionScheme == 0, byteLength -- must have the same value as this. When supercompressionScheme == -- 1 (BasisLZ) the value must be 0. [uncompressedByteLength] :: Level -> Word64 -- | Build a level index from level data. -- -- Levels should be placed from largest (mip 0) to smallest. index :: Word64 -> [(Maybe Word64, ByteString)] -> Vector Level instance GHC.Generics.Generic Codec.Ktx2.Level.Level instance GHC.Show.Show Codec.Ktx2.Level.Level instance GHC.Classes.Eq Codec.Ktx2.Level.Level instance Data.Binary.Class.Binary Codec.Ktx2.Level.Level -- | Block-by-block extraction of data from a KTX2 file. -- -- -- -- Extra information is available when needed: -- -- module Codec.Ktx2.Read -- | A bundle of source data and header information used by reader -- functions. data Context a Context :: a -> Header -> Context a [context] :: Context a -> a [header] :: Context a -> Header -- | Context for reading from a file. The file has to be seekable. type FileContext = Context Handle open :: MonadIO io => FilePath -> io FileContext close :: MonadIO io => FileContext -> io () -- | Context for reading from memory. Useful when the data is embedded in a -- module or otherwise already available in full. type BytesContext = Context ByteString bytes :: MonadIO io => ByteString -> io BytesContext -- | Read the level index. levels :: (ReadChunk src, MonadIO io) => Context src -> io (Vector Level) -- | Copy level data into a provided pointer. -- -- The buffer must be large enough for the byteLength of the -- Level being accessed. levelToPtr :: (ReadLevel src, MonadIO io) => Context src -> Level -> Ptr () -> io Bool -- | Copy level data into a managed buffer. levelData :: (ReadChunk src, MonadIO io) => Context src -> Level -> io ByteString -- | Read DFD block data. -- -- Further processing is performed according to descriptor -- vendortypeversion. E.g. Codec.Ktx2.DFD.Khronos.BasicV2. dataFormatDescriptor :: (ReadChunk src, MonadIO io) => Context src -> io DFD -- | Read and parse Key-Value Data block. keyValueData :: (ReadChunk src, MonadIO io) => Context src -> io KeyValueData -- | Get a copy of global supercompression data. supercompressionGlobalData :: (ReadChunk src, MonadIO io) => Context src -> io ByteString class ReadChunk a -- | 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. readChunkAt :: (ReadChunk a, MonadIO io) => a -> Int -> Int -> io ByteString newtype ChunkError ChunkError :: Text -> ChunkError -- | Get a chunk of data and run a decoder on it. decodeAt :: forall a src io. (ReadChunk src, Show a, Typeable a, MonadIO io) => src -> Int -> Int -> Get a -> io a data DecodeError DecodeError :: ByteOffset -> Text -> DecodeError class ReadLevel a readLevelTo :: (ReadLevel a, MonadIO io) => a -> Level -> Ptr () -> io Bool instance GHC.Show.Show Codec.Ktx2.Read.ChunkError instance GHC.Classes.Eq Codec.Ktx2.Read.ChunkError instance GHC.Show.Show Codec.Ktx2.Read.DecodeError instance GHC.Classes.Eq Codec.Ktx2.Read.DecodeError instance Codec.Ktx2.Read.ReadLevel GHC.IO.Handle.Types.Handle instance Codec.Ktx2.Read.ReadLevel Data.ByteString.Internal.ByteString instance GHC.Exception.Type.Exception Codec.Ktx2.Read.DecodeError instance Codec.Ktx2.Read.ReadChunk Data.ByteString.Internal.ByteString instance GHC.Exception.Type.Exception Codec.Ktx2.Read.ChunkError instance Codec.Ktx2.Read.ReadChunk GHC.IO.Handle.Types.Handle instance GHC.Show.Show (Codec.Ktx2.Read.Context GHC.IO.Handle.Types.Handle) instance GHC.Show.Show (Codec.Ktx2.Read.Context Data.ByteString.Internal.ByteString) module Codec.Ktx2.Write toFile :: MonadIO io => FilePath -> Header -> Vector Block -> KeyValueData -> ByteString -> [(Maybe Word64, ByteString)] -> io () toChunks :: Header -> Vector Block -> KeyValueData -> ByteString -> [(Maybe Word64, ByteString)] -> ByteString