Fast implementations of toLinear() and toGamma() for default gamma=2.2

This commit is contained in:
Ken Cooke
2017-06-01 13:44:28 -07:00
parent e85d851cd9
commit 96b73af196
4 changed files with 503 additions and 2 deletions

View File

@ -8,6 +8,7 @@
#include "nvmath/Vector.inl"
#include "nvmath/Matrix.inl"
#include "nvmath/ftoi.h"
#include "nvmath/Gamma.h"
#include "nvcore/Utils.h" // max
#include "nvcore/Ptr.h"
@ -243,13 +244,29 @@ void FloatImage::clamp(uint baseComponent, uint num, float low, float high)
/// From gamma to linear space.
void FloatImage::toLinear(uint baseComponent, uint num, float gamma /*= 2.2f*/)
{
exponentiate(baseComponent, num, gamma);
if (gamma == 2.2f) {
for (uint c = 0; c < num; c++) {
float * ptr = this->channel(baseComponent + c);
powf_11_5(ptr, ptr, m_pixelCount);
}
} else {
exponentiate(baseComponent, num, gamma);
}
}
/// From linear to gamma space.
void FloatImage::toGamma(uint baseComponent, uint num, float gamma /*= 2.2f*/)
{
exponentiate(baseComponent, num, 1.0f/gamma);
if (gamma == 2.2f) {
for (uint c = 0; c < num; c++) {
float * ptr = this->channel(baseComponent + c);
powf_5_11(ptr, ptr, m_pixelCount);
}
} else {
exponentiate(baseComponent, num, 1.0f/gamma);
}
}
/// Exponentiate the elements of the image.