godot/thirdparty/cvtt/ConvectionKernels.h

/*
Convection Texture Tools
Copyright (c) 2018 Eric Lasota

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject
to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#ifndef __CVTT_CONVECTION_KERNELS__
#define __CVTT_CONVECTION_KERNELS__

#include <stddef.h>
#include <stdint.h>

namespace cvtt
{
    namespace Flags
    {
        // Use fast indexing in BC7 encoding (about 2x faster, slightly worse quality)
        const uint32_t BC7_FastIndexing         =;

        // Try precomputed single-color lookups where applicable (slightly slower, small quality increase on specific blocks)
        const uint32_t BC7_TrySingleColor       =;

        // Don't allow non-zero or non-max alpha values in blocks that only contain one or the other
        const uint32_t BC7_RespectPunchThrough  =;

        // Use fast indexing in HDR formats (faster, worse quality)
        const uint32_t BC6H_FastIndexing        =;

        // Exhaustive search RGB orderings when encoding BC1-BC3 (much slower, better quality)
        const uint32_t S3TC_Exhaustive          =;

        // Penalize distant endpoints, improving quality on inaccurate GPU decoders
        const uint32_t S3TC_Paranoid            =;

        // Uniform color channel importance
        const uint32_t Uniform                  =;

        // Use fake BT.709 color space for etc2comp compatibility (slower)
        const uint32_t ETC_UseFakeBT709         =;

        // Use accurate quantization functions when quantizing fake BT.709 (much slower, marginal improvement on specific blocks)
        const uint32_t ETC_FakeBT709Accurate    =;

        // Misc useful default flag combinations
        const uint32_t Fastest =;
        const uint32_t Faster =;
        const uint32_t Fast =;
        const uint32_t Default =;
        const uint32_t Better =;
        const uint32_t Ultra =;
    }

    const unsigned int NumParallelBlocks =;

    struct Options
    {};

    struct BC7FineTuningParams
    {};

    struct BC7EncodingPlan
    {};

    // RGBA input block for unsigned 8-bit formats
    struct PixelBlockU8
    {};

    // RGBA input block for signed 8-bit formats
    struct PixelBlockS8
    {};

    struct PixelBlockScalarS16
    {};

    // RGBA input block for half-precision float formats (bit-cast to int16_t)
    struct PixelBlockF16
    {};

    class ETC2CompressionData
    {};

    class ETC1CompressionData
    {};

    namespace Kernels
    {
        allocFunc_t;
        freeFunc_t;

        // NOTE: All functions accept and output NumParallelBlocks blocks at once
        void EncodeBC1(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options);
        void EncodeBC2(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options);
        void EncodeBC3(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options);
        void EncodeBC4U(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options);
        void EncodeBC4S(uint8_t *pBC, const PixelBlockS8 *pBlocks, const Options &options);
        void EncodeBC5U(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options);
        void EncodeBC5S(uint8_t *pBC, const PixelBlockS8 *pBlocks, const Options &options);
        void EncodeBC6HU(uint8_t *pBC, const PixelBlockF16 *pBlocks, const Options &options);
        void EncodeBC6HS(uint8_t *pBC, const PixelBlockF16 *pBlocks, const Options &options);
        void EncodeBC7(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options, const BC7EncodingPlan &encodingPlan);
        void EncodeETC1(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options, ETC1CompressionData *compressionData);
        void EncodeETC2(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options, ETC2CompressionData *compressionData);
        void EncodeETC2RGBA(uint8_t *pBC, const PixelBlockU8 *pBlocks, const cvtt::Options &options, cvtt::ETC2CompressionData *compressionData);
        void EncodeETC2PunchthroughAlpha(uint8_t *pBC, const PixelBlockU8 *pBlocks, const cvtt::Options &options, cvtt::ETC2CompressionData *compressionData);

        void EncodeETC2Alpha(uint8_t *pBC, const PixelBlockU8 *pBlocks, const cvtt::Options &options);
        void EncodeETC2Alpha11(uint8_t *pBC, const PixelBlockScalarS16 *pBlocks, bool isSigned, const cvtt::Options &options);

        // Generates a BC7 encoding plan from a quality parameter that ranges from 1 (fastest) to 100 (best)
        void ConfigureBC7EncodingPlanFromQuality(BC7EncodingPlan &encodingPlan, int quality);

        // Generates a BC7 encoding plan from fine-tuning parameters.
        bool ConfigureBC7EncodingPlanFromFineTuningParams(BC7EncodingPlan &encodingPlan, const BC7FineTuningParams &params);

        // ETC compression requires temporary storage that normally consumes a large amount of stack space.
        // To allocate and release it, use one of these functions.
        ETC2CompressionData *AllocETC2Data(allocFunc_t allocFunc, void *context, const cvtt::Options &options);
        void ReleaseETC2Data(ETC2CompressionData *compressionData, freeFunc_t freeFunc);

        ETC1CompressionData *AllocETC1Data(allocFunc_t allocFunc, void *context);
        void ReleaseETC1Data(ETC1CompressionData *compressionData, freeFunc_t freeFunc);

        void DecodeBC6HU(PixelBlockF16 *pBlocks, const uint8_t *pBC);
        void DecodeBC6HS(PixelBlockF16 *pBlocks, const uint8_t *pBC);
        void DecodeBC7(PixelBlockU8 *pBlocks, const uint8_t *pBC);
    }
}

#endif