Path: blob/master/thirdparty/cvtt/ConvectionKernels_UnfinishedEndpoints.h
9902 views
#pragma once12#include "ConvectionKernels_Util.h"34namespace cvtt5{6namespace Internal7{8template<int TVectorSize>9class UnfinishedEndpoints10{11public:12typedef ParallelMath::Float MFloat;13typedef ParallelMath::UInt16 MUInt16;14typedef ParallelMath::UInt15 MUInt15;15typedef ParallelMath::SInt16 MSInt16;16typedef ParallelMath::SInt32 MSInt32;1718UnfinishedEndpoints()19{20}2122UnfinishedEndpoints(const MFloat *base, const MFloat *offset)23{24for (int ch = 0; ch < TVectorSize; ch++)25m_base[ch] = base[ch];26for (int ch = 0; ch < TVectorSize; ch++)27m_offset[ch] = offset[ch];28}2930UnfinishedEndpoints(const UnfinishedEndpoints& other)31{32for (int ch = 0; ch < TVectorSize; ch++)33m_base[ch] = other.m_base[ch];34for (int ch = 0; ch < TVectorSize; ch++)35m_offset[ch] = other.m_offset[ch];36}3738void FinishHDRUnsigned(int tweak, int range, MSInt16 *outEP0, MSInt16 *outEP1, ParallelMath::RoundTowardNearestForScope *roundingMode)39{40float tweakFactors[2];41Util::ComputeTweakFactors(tweak, range, tweakFactors);4243for (int ch = 0; ch < TVectorSize; ch++)44{45MUInt15 channelEPs[2];46for (int epi = 0; epi < 2; epi++)47{48MFloat f = ParallelMath::Clamp(m_base[ch] + m_offset[ch] * tweakFactors[epi], 0.0f, 31743.0f);49channelEPs[epi] = ParallelMath::RoundAndConvertToU15(f, roundingMode);50}5152outEP0[ch] = ParallelMath::LosslessCast<MSInt16>::Cast(channelEPs[0]);53outEP1[ch] = ParallelMath::LosslessCast<MSInt16>::Cast(channelEPs[1]);54}55}5657void FinishHDRSigned(int tweak, int range, MSInt16* outEP0, MSInt16* outEP1, ParallelMath::RoundTowardNearestForScope* roundingMode)58{59float tweakFactors[2];60Util::ComputeTweakFactors(tweak, range, tweakFactors);6162for (int ch = 0; ch < TVectorSize; ch++)63{64MSInt16 channelEPs[2];65for (int epi = 0; epi < 2; epi++)66{67MFloat f = ParallelMath::Clamp(m_base[ch] + m_offset[ch] * tweakFactors[epi], -31743.0f, 31743.0f);68channelEPs[epi] = ParallelMath::RoundAndConvertToS16(f, roundingMode);69}7071outEP0[ch] = channelEPs[0];72outEP1[ch] = channelEPs[1];73}74}7576void FinishLDR(int tweak, int range, MUInt15* outEP0, MUInt15* outEP1)77{78ParallelMath::RoundTowardNearestForScope roundingMode;7980float tweakFactors[2];81Util::ComputeTweakFactors(tweak, range, tweakFactors);8283for (int ch = 0; ch < TVectorSize; ch++)84{85MFloat ep0f = ParallelMath::Clamp(m_base[ch] + m_offset[ch] * tweakFactors[0], 0.0f, 255.0f);86MFloat ep1f = ParallelMath::Clamp(m_base[ch] + m_offset[ch] * tweakFactors[1], 0.0f, 255.0f);87outEP0[ch] = ParallelMath::RoundAndConvertToU15(ep0f, &roundingMode);88outEP1[ch] = ParallelMath::RoundAndConvertToU15(ep1f, &roundingMode);89}90}9192template<int TNewVectorSize>93UnfinishedEndpoints<TNewVectorSize> ExpandTo(float filler)94{95MFloat newBase[TNewVectorSize];96MFloat newOffset[TNewVectorSize];9798for (int ch = 0; ch < TNewVectorSize && ch < TVectorSize; ch++)99{100newBase[ch] = m_base[ch];101newOffset[ch] = m_offset[ch];102}103104MFloat fillerV = ParallelMath::MakeFloat(filler);105106for (int ch = TVectorSize; ch < TNewVectorSize; ch++)107{108newBase[ch] = fillerV;109newOffset[ch] = ParallelMath::MakeFloatZero();110}111112return UnfinishedEndpoints<TNewVectorSize>(newBase, newOffset);113}114115private:116MFloat m_base[TVectorSize];117MFloat m_offset[TVectorSize];118};119}120}121122123