/* -*- tab-width: 4; -*- */ /* vi: set sw=2 ts=4 expandtab: */ /* Copyright 2019-2020 The Khronos Group Inc. * SPDX-License-Identifier: Apache-2.0 */ /** * @file * @~English * @brief Utility for interpreting a data format descriptor. * @author Andrew Garrard */ #include <stdint.h> #include <stdio.h> #include <KHR/khr_df.h> #include "dfd.h" static uint32_t bit_ceil(uint32_t x) { … } /** * @~English * @brief Interpret a Data Format Descriptor for a simple format. * * Handles "simple" cases that can be translated to things a GPU can access. * For simplicity, it ignores the compressed formats, which are generally a * single sample (and I believe are all defined to be little-endian in their * in-memory layout, even if some documentation confuses this). Focuses on * the layout and ignores sRGB except for reporting if that is the transfer * function by way of a bit in the returned value. * * @param[in] DFD Pointer to a Data Format Descriptor to interpret, * described as 32-bit words in native endianness. * Note that this is the whole descriptor, not just * the basic descriptor block. * @param R[in,out] Pointer to struct to receive information about the decoded * red channel, the Y channel, if YUV, or the depth channel, * if any. * @param G[in,out] Pointer to struct to receive information about the decoded * green channel, the U (Cb) channel, if YUV, or the stencil * channel, if any. * @param B[in,out] Pointer to struct to receive information about the decoded * blue channel, if any or the V (Cr) channel, if YUV. * @param A[in,out] Pointer to struct to receive information about the decoded * alpha channel, if any or the second Y channel, if YUV and * any. * @param wordBytes[in,out] Pointer to a uint32_t to receive the byte size of * the channels (unpacked) or total size (packed). * * @return An enumerant describing the decoded value, * or an error code in case of failure. * * The mapping of YUV channels to the parameter names used here is based on * the channel ids in @c khr_df.h and is different from the convention used * in format names in the Vulkan specification where G == Y, R = Cr and B = Cb. **/ enum InterpretDFDResult interpretDFD(const uint32_t *DFD, InterpretedDFDChannel *R, InterpretedDFDChannel *G, InterpretedDFDChannel *B, InterpretedDFDChannel *A, uint32_t *wordBytes) { … }