Path: blob/master/thirdparty/cvtt/ConvectionKernels_Util.cpp
9896 views
/*1Convection Texture Tools2Copyright (c) 2018-2019 Eric Lasota34Permission is hereby granted, free of charge, to any person obtaining5a copy of this software and associated documentation files (the6"Software"), to deal in the Software without restriction, including7without limitation the rights to use, copy, modify, merge, publish,8distribute, sublicense, and/or sell copies of the Software, and to9permit persons to whom the Software is furnished to do so, subject10to the following conditions:1112The above copyright notice and this permission notice shall be included13in all copies or substantial portions of the Software.1415THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS16OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF17MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.18IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY19CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,20TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE21SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.2223-------------------------------------------------------------------------------------2425Portions based on DirectX Texture Library (DirectXTex)2627Copyright (c) Microsoft Corporation. All rights reserved.28Licensed under the MIT License.2930http://go.microsoft.com/fwlink/?LinkId=24892631*/32#include "ConvectionKernels_Config.h"3334#if !defined(CVTT_SINGLE_FILE) || defined(CVTT_SINGLE_FILE_IMPL)3536#include "ConvectionKernels.h"37#include "ConvectionKernels_ParallelMath.h"3839#include <algorithm>4041namespace cvtt42{43namespace Util44{45// Signed input blocks are converted into unsigned space, with the maximum value being 25446void BiasSignedInput(PixelBlockU8 inputNormalized[ParallelMath::ParallelSize], const PixelBlockS8 inputSigned[ParallelMath::ParallelSize])47{48for (size_t block = 0; block < ParallelMath::ParallelSize; block++)49{50const PixelBlockS8& inputSignedBlock = inputSigned[block];51PixelBlockU8& inputNormalizedBlock = inputNormalized[block];5253for (size_t px = 0; px < 16; px++)54{55for (size_t ch = 0; ch < 4; ch++)56inputNormalizedBlock.m_pixels[px][ch] = static_cast<uint8_t>(std::max<int>(inputSignedBlock.m_pixels[px][ch], -127) + 127);57}58}59}6061void FillWeights(const Options &options, float channelWeights[4])62{63if (options.flags & Flags::Uniform)64channelWeights[0] = channelWeights[1] = channelWeights[2] = channelWeights[3] = 1.0f;65else66{67channelWeights[0] = options.redWeight;68channelWeights[1] = options.greenWeight;69channelWeights[2] = options.blueWeight;70channelWeights[3] = options.alphaWeight;71}72}7374void ComputeTweakFactors(int tweak, int range, float *outFactors)75{76int totalUnits = range - 1;77int minOutsideUnits = ((tweak >> 1) & 1);78int maxOutsideUnits = (tweak & 1);79int insideUnits = totalUnits - minOutsideUnits - maxOutsideUnits;8081outFactors[0] = -static_cast<float>(minOutsideUnits) / static_cast<float>(insideUnits);82outFactors[1] = static_cast<float>(maxOutsideUnits) / static_cast<float>(insideUnits) + 1.0f;83}84}85}8687#endif888990