123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- /*
- Convection Texture Tools
- Copyright (c) 2018-2019 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.
- */
- #include "ConvectionKernels_Config.h"
- #if !defined(CVTT_SINGLE_FILE) || defined(CVTT_SINGLE_FILE_IMPL)
- #include <stdint.h>
- #include "ConvectionKernels.h"
- #include "ConvectionKernels_Util.h"
- #include "ConvectionKernels_BC67.h"
- #include "ConvectionKernels_ETC.h"
- #include "ConvectionKernels_S3TC.h"
- #include <assert.h>
- namespace cvtt
- {
- namespace Kernels
- {
- void EncodeBC7(uint8_t *pBC, const PixelBlockU8 *pBlocks, const cvtt::Options &options, const BC7EncodingPlan &encodingPlan)
- {
- assert(pBlocks);
- assert(pBC);
- float channelWeights[4];
- Util::FillWeights(options, channelWeights);
- for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase += ParallelMath::ParallelSize)
- {
- Internal::BC7Computer::Pack(options.flags, pBlocks + blockBase, pBC, channelWeights, encodingPlan, options.refineRoundsBC7);
- pBC += ParallelMath::ParallelSize * 16;
- }
- }
- void EncodeBC6HU(uint8_t *pBC, const PixelBlockF16 *pBlocks, const cvtt::Options &options)
- {
- assert(pBlocks);
- assert(pBC);
- float channelWeights[4];
- Util::FillWeights(options, channelWeights);
- for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase += ParallelMath::ParallelSize)
- {
- Internal::BC6HComputer::Pack(options.flags, pBlocks + blockBase, pBC, channelWeights, false, options.seedPoints, options.refineRoundsBC6H);
- pBC += ParallelMath::ParallelSize * 16;
- }
- }
- void EncodeBC6HS(uint8_t *pBC, const PixelBlockF16 *pBlocks, const cvtt::Options &options)
- {
- assert(pBlocks);
- assert(pBC);
- float channelWeights[4];
- Util::FillWeights(options, channelWeights);
- for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase += ParallelMath::ParallelSize)
- {
- Internal::BC6HComputer::Pack(options.flags, pBlocks + blockBase, pBC, channelWeights, true, options.seedPoints, options.refineRoundsBC6H);
- pBC += ParallelMath::ParallelSize * 16;
- }
- }
- void EncodeBC1(uint8_t *pBC, const PixelBlockU8 *pBlocks, const cvtt::Options &options)
- {
- assert(pBlocks);
- assert(pBC);
- float channelWeights[4];
- Util::FillWeights(options, channelWeights);
- for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase += ParallelMath::ParallelSize)
- {
- Internal::S3TCComputer::PackRGB(options.flags, pBlocks + blockBase, pBC, 8, channelWeights, true, options.threshold, (options.flags & Flags::S3TC_Exhaustive) != 0, options.seedPoints, options.refineRoundsS3TC);
- pBC += ParallelMath::ParallelSize * 8;
- }
- }
- void EncodeBC2(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options)
- {
- assert(pBlocks);
- assert(pBC);
- float channelWeights[4];
- Util::FillWeights(options, channelWeights);
- for (size_t blockBase = 0; blockBase < NumParallelBlocks; blockBase += ParallelMath::ParallelSize)
- {
- Internal::S3TCComputer::PackRGB(options.flags, pBlocks + blockBase, pBC + 8, 16, channelWeights, false, 1.0f, (options.flags & Flags::S3TC_Exhaustive) != 0, options.seedPoints, options.refineRoundsS3TC);
- Internal::S3TCComputer::PackExplicitAlpha(options.flags, pBlocks + blockBase, 3, pBC, 16);
- pBC += ParallelMath::ParallelSize * 16;
- }
- }
- void EncodeBC3(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options)
- {
- assert(pBlocks);
- assert(pBC);
- float channelWeights[4];
- Util::FillWeights(options, channelWeights);
- for (size_t blockBase = 0; blockBase < NumParallelBlocks; blockBase += ParallelMath::ParallelSize)
- {
- Internal::S3TCComputer::PackRGB(options.flags, pBlocks + blockBase, pBC + 8, 16, channelWeights, false, 1.0f, (options.flags & Flags::S3TC_Exhaustive) != 0, options.seedPoints, options.refineRoundsS3TC);
- Internal::S3TCComputer::PackInterpolatedAlpha(options.flags, pBlocks + blockBase, 3, pBC, 16, false, options.seedPoints, options.refineRoundsIIC);
- pBC += ParallelMath::ParallelSize * 16;
- }
- }
- void EncodeBC4U(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options)
- {
- assert(pBlocks);
- assert(pBC);
- float channelWeights[4];
- Util::FillWeights(options, channelWeights);
- for (size_t blockBase = 0; blockBase < NumParallelBlocks; blockBase += ParallelMath::ParallelSize)
- {
- Internal::S3TCComputer::PackInterpolatedAlpha(options.flags, pBlocks + blockBase, 0, pBC, 8, false, options.seedPoints, options.refineRoundsIIC);
- pBC += ParallelMath::ParallelSize * 8;
- }
- }
- void EncodeBC4S(uint8_t *pBC, const PixelBlockS8 *pBlocks, const Options &options)
- {
- assert(pBlocks);
- assert(pBC);
- float channelWeights[4];
- Util::FillWeights(options, channelWeights);
- for (size_t blockBase = 0; blockBase < NumParallelBlocks; blockBase += ParallelMath::ParallelSize)
- {
- PixelBlockU8 inputBlocks[ParallelMath::ParallelSize];
- Util::BiasSignedInput(inputBlocks, pBlocks + blockBase);
- Internal::S3TCComputer::PackInterpolatedAlpha(options.flags, inputBlocks, 0, pBC, 8, true, options.seedPoints, options.refineRoundsIIC);
- pBC += ParallelMath::ParallelSize * 8;
- }
- }
- void EncodeBC5U(uint8_t *pBC, const PixelBlockU8 *pBlocks, const Options &options)
- {
- assert(pBlocks);
- assert(pBC);
- float channelWeights[4];
- Util::FillWeights(options, channelWeights);
- for (size_t blockBase = 0; blockBase < NumParallelBlocks; blockBase += ParallelMath::ParallelSize)
- {
- Internal::S3TCComputer::PackInterpolatedAlpha(options.flags, pBlocks + blockBase, 0, pBC, 16, false, options.seedPoints, options.refineRoundsIIC);
- Internal::S3TCComputer::PackInterpolatedAlpha(options.flags, pBlocks + blockBase, 1, pBC + 8, 16, false, options.seedPoints, options.refineRoundsIIC);
- pBC += ParallelMath::ParallelSize * 16;
- }
- }
- void EncodeBC5S(uint8_t *pBC, const PixelBlockS8 *pBlocks, const Options &options)
- {
- assert(pBlocks);
- assert(pBC);
- float channelWeights[4];
- Util::FillWeights(options, channelWeights);
- for (size_t blockBase = 0; blockBase < NumParallelBlocks; blockBase += ParallelMath::ParallelSize)
- {
- PixelBlockU8 inputBlocks[ParallelMath::ParallelSize];
- Util::BiasSignedInput(inputBlocks, pBlocks + blockBase);
- Internal::S3TCComputer::PackInterpolatedAlpha(options.flags, inputBlocks, 0, pBC, 16, true, options.seedPoints, options.refineRoundsIIC);
- Internal::S3TCComputer::PackInterpolatedAlpha(options.flags, inputBlocks, 1, pBC + 8, 16, true, options.seedPoints, options.refineRoundsIIC);
- pBC += ParallelMath::ParallelSize * 16;
- }
- }
- void EncodeETC1(uint8_t *pBC, const PixelBlockU8 *pBlocks, const cvtt::Options &options, cvtt::ETC1CompressionData *compressionData)
- {
- assert(pBlocks);
- assert(pBC);
- float channelWeights[4];
- Util::FillWeights(options, channelWeights);
- for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase += ParallelMath::ParallelSize)
- {
- Internal::ETCComputer::CompressETC1Block(pBC, pBlocks + blockBase, compressionData, options);
- pBC += ParallelMath::ParallelSize * 8;
- }
- }
- void EncodeETC2(uint8_t *pBC, const PixelBlockU8 *pBlocks, const cvtt::Options &options, cvtt::ETC2CompressionData *compressionData)
- {
- assert(pBlocks);
- assert(pBC);
- float channelWeights[4];
- Util::FillWeights(options, channelWeights);
- for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase += ParallelMath::ParallelSize)
- {
- Internal::ETCComputer::CompressETC2Block(pBC, pBlocks + blockBase, compressionData, options, false);
- pBC += ParallelMath::ParallelSize * 8;
- }
- }
- void EncodeETC2PunchthroughAlpha(uint8_t *pBC, const PixelBlockU8 *pBlocks, const cvtt::Options &options, cvtt::ETC2CompressionData *compressionData)
- {
- assert(pBlocks);
- assert(pBC);
- float channelWeights[4];
- Util::FillWeights(options, channelWeights);
- for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase += ParallelMath::ParallelSize)
- {
- Internal::ETCComputer::CompressETC2Block(pBC, pBlocks + blockBase, compressionData, options, true);
- pBC += ParallelMath::ParallelSize * 8;
- }
- }
- void EncodeETC2Alpha(uint8_t *pBC, const PixelBlockU8 *pBlocks, const cvtt::Options &options)
- {
- assert(pBlocks);
- assert(pBC);
- for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase += ParallelMath::ParallelSize)
- {
- Internal::ETCComputer::CompressETC2AlphaBlock(pBC, pBlocks + blockBase, options);
- pBC += ParallelMath::ParallelSize * 8;
- }
- }
- void EncodeETC2Alpha11(uint8_t *pBC, const PixelBlockScalarS16 *pBlocks, bool isSigned, const cvtt::Options &options)
- {
- assert(pBlocks);
- assert(pBC);
- for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase += ParallelMath::ParallelSize)
- {
- Internal::ETCComputer::CompressEACBlock(pBC, pBlocks + blockBase, isSigned, options);
- pBC += ParallelMath::ParallelSize * 8;
- }
- }
- void EncodeETC2RGBA(uint8_t *pBC, const PixelBlockU8 *pBlocks, const cvtt::Options &options, cvtt::ETC2CompressionData *compressionData)
- {
- uint8_t alphaBlockData[cvtt::NumParallelBlocks * 8];
- uint8_t colorBlockData[cvtt::NumParallelBlocks * 8];
- EncodeETC2(colorBlockData, pBlocks, options, compressionData);
- EncodeETC2Alpha(alphaBlockData, pBlocks, options);
- for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase++)
- {
- for (size_t blockData = 0; blockData < 8; blockData++)
- pBC[blockBase * 16 + blockData] = alphaBlockData[blockBase * 8 + blockData];
- for (size_t blockData = 0; blockData < 8; blockData++)
- pBC[blockBase * 16 + 8 + blockData] = colorBlockData[blockBase * 8 + blockData];
- }
- }
- void DecodeBC7(PixelBlockU8 *pBlocks, const uint8_t *pBC)
- {
- assert(pBlocks);
- assert(pBC);
- for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase++)
- {
- Internal::BC7Computer::UnpackOne(pBlocks[blockBase], pBC);
- pBC += 16;
- }
- }
- void DecodeBC6HU(PixelBlockF16 *pBlocks, const uint8_t *pBC)
- {
- assert(pBlocks);
- assert(pBC);
- for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase++)
- {
- Internal::BC6HComputer::UnpackOne(pBlocks[blockBase], pBC, false);
- pBC += 16;
- }
- }
- void DecodeBC6HS(PixelBlockF16 *pBlocks, const uint8_t *pBC)
- {
- assert(pBlocks);
- assert(pBC);
- for (size_t blockBase = 0; blockBase < cvtt::NumParallelBlocks; blockBase++)
- {
- Internal::BC6HComputer::UnpackOne(pBlocks[blockBase], pBC, true);
- pBC += 16;
- }
- }
- ETC1CompressionData *AllocETC1Data(allocFunc_t allocFunc, void *context)
- {
- return cvtt::Internal::ETCComputer::AllocETC1Data(allocFunc, context);
- }
- void ReleaseETC1Data(ETC1CompressionData *compressionData, freeFunc_t freeFunc)
- {
- cvtt::Internal::ETCComputer::ReleaseETC1Data(compressionData, freeFunc);
- }
- ETC2CompressionData *AllocETC2Data(allocFunc_t allocFunc, void *context, const cvtt::Options &options)
- {
- return cvtt::Internal::ETCComputer::AllocETC2Data(allocFunc, context, options);
- }
- void ReleaseETC2Data(ETC2CompressionData *compressionData, freeFunc_t freeFunc)
- {
- cvtt::Internal::ETCComputer::ReleaseETC2Data(compressionData, freeFunc);
- }
- }
- }
- #endif
|