Path: blob/master/thirdparty/libktx/external/dfdutils/dfd.h
9912 views
/* -*- tab-width: 4; -*- */1/* vi: set sw=2 ts=4 expandtab: */23/* Copyright 2019-2020 The Khronos Group Inc.4* SPDX-License-Identifier: Apache-2.05*/67/**8* @file9* @~English10* @brief Header file defining the data format descriptor utilities API.11*/1213/*14* Author: Andrew Garrard15*/1617#ifndef _DFD_H_18#define _DFD_H_1920#include <KHR/khr_df.h>21#include <stdbool.h>2223#ifdef __cplusplus24extern "C" {25#endif2627/** Qualifier suffix to the format, in Vulkan terms. */28enum VkSuffix {29s_UNORM, /*!< Unsigned normalized format. */30s_SNORM, /*!< Signed normalized format. */31s_USCALED, /*!< Unsigned scaled format. */32s_SSCALED, /*!< Signed scaled format. */33s_UINT, /*!< Unsigned integer format. */34s_SINT, /*!< Signed integer format. */35s_SFLOAT, /*!< Signed float format. */36s_UFLOAT, /*!< Unsigned float format. */37s_SRGB, /*!< sRGB normalized format. */38s_SFIXED5 /*!< 2's complement fixed-point; 5 fractional bits. */39};4041/** Compression scheme, in Vulkan terms. */42enum VkCompScheme {43c_BC1_RGB, /*!< BC1, aka DXT1, no alpha. */44c_BC1_RGBA, /*!< BC1, aka DXT1, punch-through alpha. */45c_BC2, /*!< BC2, aka DXT2 and DXT3. */46c_BC3, /*!< BC3, aka DXT4 and DXT5. */47c_BC4, /*!< BC4. */48c_BC5, /*!< BC5. */49c_BC6H, /*!< BC6h HDR format. */50c_BC7, /*!< BC7. */51c_ETC2_R8G8B8, /*!< ETC2 no alpha. */52c_ETC2_R8G8B8A1, /*!< ETC2 punch-through alpha. */53c_ETC2_R8G8B8A8, /*!< ETC2 independent alpha. */54c_EAC_R11, /*!< R11 ETC2 single-channel. */55c_EAC_R11G11, /*!< R11G11 ETC2 dual-channel. */56c_ASTC, /*!< ASTC. */57c_ETC1S, /*!< ETC1S. */58c_PVRTC, /*!< PVRTC(1). */59c_PVRTC2 /*!< PVRTC2. */60};6162typedef unsigned int uint32_t;6364#if !defined(LIBKTX)65#include <vulkan/vulkan_core.h>66#else67#include "../../lib/vkformat_enum.h"68#endif6970uint32_t* vk2dfd(enum VkFormat format);71enum VkFormat dfd2vk(uint32_t* dfd);7273/* Create a Data Format Descriptor for an unpacked format. */74uint32_t *createDFDUnpacked(int bigEndian, int numChannels, int bytes,75int redBlueSwap, enum VkSuffix suffix);7677/* Create a Data Format Descriptor for a packed padded format. */78uint32_t *createDFDPackedShifted(int bigEndian, int numChannels,79int bits[], int shiftBits[],80int channels[], enum VkSuffix suffix);8182/* Create a Data Format Descriptor for a packed format. */83uint32_t *createDFDPacked(int bigEndian, int numChannels,84int bits[], int channels[],85enum VkSuffix suffix);8687/* Create a Data Format Descriptor for a 4:2:2 format. */88uint32_t *createDFD422(int bigEndian, int numChannels,89int bits[], int shiftBits[], int channels[],90int position_xs[], int position_ys[],91enum VkSuffix suffix);9293/* Create a Data Format Descriptor for a compressed format. */94uint32_t *createDFDCompressed(enum VkCompScheme compScheme,95int bwidth, int bheight, int bdepth,96enum VkSuffix suffix);9798/* Create a Data Format Descriptor for a depth/stencil format. */99uint32_t *createDFDDepthStencil(int depthBits,100int stencilBits,101int sizeBytes);102103/* Create a Data Format Descriptor for an alpha-only format */104uint32_t *createDFDAlpha(int bigEndian, int bytes,105enum VkSuffix suffix);106107/** @brief Result of interpreting the data format descriptor. */108enum InterpretDFDResult {109i_LITTLE_ENDIAN_FORMAT_BIT = 0, /*!< Confirmed little-endian (default for 8bpc). */110i_BIG_ENDIAN_FORMAT_BIT = 1u << 0u, /*!< Confirmed big-endian. */111i_PACKED_FORMAT_BIT = 1u << 1u, /*!< Packed format. */112i_SRGB_FORMAT_BIT = 1u << 2u, /*!< sRGB transfer function. */113i_NORMALIZED_FORMAT_BIT = 1u << 3u, /*!< Normalized (UNORM or SNORM). */114i_SIGNED_FORMAT_BIT = 1u << 4u, /*!< Format is signed. */115i_FIXED_FORMAT_BIT = 1u << 5u, /*!< Format is a fixed-point representation. */116i_FLOAT_FORMAT_BIT = 1u << 6u, /*!< Format is floating point. */117i_COMPRESSED_FORMAT_BIT = 1u << 7u, /*!< Format is block compressed (422). */118i_YUVSDA_FORMAT_BIT = 1u << 8u, /*!< Color model is YUVSDA. */119i_UNSUPPORTED_ERROR_BIT = 1u << 9u, /*!< Format not successfully interpreted. */120/** "NONTRIVIAL_ENDIANNESS" means not big-endian, not little-endian121* (a channel has bits that are not consecutive in either order). **/122i_UNSUPPORTED_NONTRIVIAL_ENDIANNESS = i_UNSUPPORTED_ERROR_BIT,123/** "MULTIPLE_SAMPLE_LOCATIONS" is an error because only single-sample124* texel blocks (with coordinates 0,0,0,0 for all samples) are supported. **/125i_UNSUPPORTED_MULTIPLE_SAMPLE_LOCATIONS = i_UNSUPPORTED_ERROR_BIT + 1,126/** "MULTIPLE_PLANES" is an error because only contiguous data is supported. */127i_UNSUPPORTED_MULTIPLE_PLANES = i_UNSUPPORTED_ERROR_BIT + 2,128/** Only channels R, G, B and A are supported. */129i_UNSUPPORTED_CHANNEL_TYPES = i_UNSUPPORTED_ERROR_BIT + 3,130/** Only channels with the same flags are supported131* (e.g. we don't support float red with integer green). */132i_UNSUPPORTED_MIXED_CHANNELS = i_UNSUPPORTED_ERROR_BIT + 4,133/** Only 2x1 block is supported for YUVSDA model. */134i_UNSUPPORTED_BLOCK_DIMENSIONS = i_UNSUPPORTED_ERROR_BIT + 5,135};136137/** @brief Interpretation of a channel from the data format descriptor. */138typedef struct _InterpretedDFDChannel {139uint32_t offset; /*!< Offset in bits for packed, bytes for unpacked. */140uint32_t size; /*!< Size in bits for packed, bytes for unpacked. */141} InterpretedDFDChannel;142143/* Interpret a Data Format Descriptor. */144enum InterpretDFDResult interpretDFD(const uint32_t *DFD,145InterpretedDFDChannel *R,146InterpretedDFDChannel *G,147InterpretedDFDChannel *B,148InterpretedDFDChannel *A,149uint32_t *wordBytes);150151/* Returns the string representation.152* If there is no direct match or the value is invalid returns NULL */153const char* dfdToStringVendorID(khr_df_vendorid_e value);154155/* Returns the string representation.156* If there is no direct match or the value is invalid returns NULL */157const char* dfdToStringDescriptorType(khr_df_khr_descriptortype_e value);158159/* Returns the string representation.160* If there is no direct match or the value is invalid returns NULL */161const char* dfdToStringVersionNumber(khr_df_versionnumber_e value);162163/* Returns the string representation of a bit in a khr_df_flags_e.164* If there is no direct match or the value is invalid returns NULL */165const char* dfdToStringFlagsBit(uint32_t bit_index, bool bit_value);166167/* Returns the string representation.168* If there is no direct match or the value is invalid returns NULL */169const char* dfdToStringTransferFunction(khr_df_transfer_e value);170171/* Returns the string representation.172* If there is no direct match or the value is invalid returns NULL */173const char* dfdToStringColorPrimaries(khr_df_primaries_e value);174175/* Returns the string representation.176* If there is no direct match or the value is invalid returns NULL */177const char* dfdToStringColorModel(khr_df_model_e value);178179/* Returns the string representation of a bit in a khr_df_sample_datatype_qualifiers_e.180* If there is no direct match or the value is invalid returns NULL */181const char* dfdToStringSampleDatatypeQualifiersBit(uint32_t bit_index, bool bit_value);182183/* Returns the string representation.184* If there is no direct match or the value is invalid returns NULL */185const char* dfdToStringChannelId(khr_df_model_e model, khr_df_model_channels_e value);186187/* Print a human-readable interpretation of a data format descriptor. */188void printDFD(uint32_t *DFD, uint32_t dataSize);189190/* Print a JSON interpretation of a data format descriptor. */191void printDFDJSON(uint32_t *DFD, uint32_t dataSize, uint32_t base_indent, uint32_t indent_width, bool minified);192193/* Get the number of components & component size from a DFD for an194* unpacked format.195*/196void getDFDComponentInfoUnpacked(const uint32_t* DFD, uint32_t* numComponents,197uint32_t* componentByteLength);198199/* Return the number of components described by a DFD. */200uint32_t getDFDNumComponents(const uint32_t* DFD);201202/* Reconstruct and update the bytesPlane[0-4] fields of an unsized DFD to what203* they were before supercompression.204*/205void reconstructDFDBytesPlanesFromSamples(uint32_t* DFD);206/* Deprecated. For backward compatibility. */207uint32_t reconstructDFDBytesPlane0FromSamples(const uint32_t* DFD);208/* Deprecated. For backward compatibility. */209void recreateBytesPlane0FromSampleInfo(const uint32_t* DFD,210uint32_t* bytesPlane0);211212/** @brief Colourspace primaries information.213*214* Structure to store the 1931 CIE x,y chromaticities of the red, green, and blue215* display primaries and the reference white point of a colourspace.216*/217typedef struct _Primaries {218float Rx; /*!< Red x. */219float Ry; /*!< Red y. */220float Gx; /*!< Green x. */221float Gy; /*!< Green y. */222float Bx; /*!< Blue x. */223float By; /*!< Blue y. */224float Wx; /*!< White x. */225float Wy; /*!< White y. */226} Primaries;227228khr_df_primaries_e findMapping(const Primaries *p, float latitude);229bool getPrimaries(khr_df_primaries_e primaries, Primaries *p);230231#ifdef __cplusplus232}233#endif234235#endif /* _DFD_H_ */236237238