Minor cleanups

This commit is contained in:
Flössie 2020-07-02 17:38:59 +02:00
parent cf0ccc26ca
commit af4b17ac84
2 changed files with 46 additions and 44 deletions

View File

@ -58,6 +58,7 @@
#pragma once
#include <algorithm>
#include <cstring>
#include <cstdint>
#include <cassert>
@ -98,8 +99,8 @@ protected:
unsigned int size;
unsigned int upperBound; // always equals size-1, parameter created for performance reason
private:
unsigned int owner;
#ifdef __SSE2__
unsigned int owner;
alignas(16) vfloat maxsv;
alignas(16) vfloat sizev;
alignas(16) vint sizeiv;
@ -140,35 +141,30 @@ public:
}
}
LUT(const std::vector<T> input, int flags = LUT_CLIP_BELOW | LUT_CLIP_ABOVE)
LUT(const std::vector<T>& input, int flags = LUT_CLIP_BELOW | LUT_CLIP_ABOVE) :
maxs(input.size() - 2),
maxsf(maxs),
data(new T[input.size() + 3]), // Add a few extra elements so [](vfloat) won't access out-of-bounds memory.
clip(flags),
size(input.size()),
upperBound(size - 1),
owner(1),
#ifdef __SSE2__
maxsv(F2V(maxs)),
sizev(F2V(size - 1)),
sizeiv(_mm_set1_epi32(size - 1)),
#endif
dirty(true)
{
#ifndef NDEBUG
if (input.size() <= 0) {
printf("s<=0!\n");
if (input.empty()) {
printf("s=0!\n");
}
assert (input.size() > 0);
assert(!input.empty());
#endif
dirty = true;
clip = flags;
// Add a few extra elements so [](vfloat) won't access out-of-bounds memory.
// The routine would still produce the right answer, but might cause issues
// with address/heap checking programs.
data = new T[input.size() + 3];
owner = 1;
size = input.size();
upperBound = size - 1;
maxs = size - 2;
maxsf = (float)maxs;
#ifdef __SSE2__
maxsv = F2V( maxs );
sizeiv = _mm_set1_epi32( (int)(size - 1) );
sizev = F2V( size - 1 );
#endif
for (size_t i = 0; i < input.size(); ++i) {
data[i] = input[i];
}
std::copy_n(input.begin(), input.size(), data);
}
void operator ()(int s, int flags = LUT_CLIP_BELOW | LUT_CLIP_ABOVE, bool initZero = false)
@ -514,19 +510,19 @@ public:
return (p1 + p2 * diff);
}
operator bool (void) const
operator bool() const // FIXME: Should be explicit
{
return size > 0;
}
void clear(void)
void clear()
{
if (data && size) {
memset(data, 0, size * sizeof(T));
}
}
void reset(void)
void reset()
{
if (data) {
delete[] data;

View File

@ -57,6 +57,7 @@
namespace
{
constexpr int limscope = 80;
constexpr int mSPsharp = 39; //minimum size Spot Sharp due to buildblendmask
constexpr int mSPwav = 32; //minimum size Spot Wavelet
@ -68,14 +69,16 @@ constexpr int TS = 64; // Tile size
constexpr float epsilonw = 0.001f / (TS * TS); //tolerance
constexpr int offset = 25; // shift between tiles
std::unique_ptr<LUTf> buildMeaLut(const float inVals[11], const float mea[10], float &lutFactor) {
std::unique_ptr<LUTf> buildMeaLut(const float inVals[11], const float mea[10], float& lutFactor)
{
constexpr int lutSize = 100;
const float lutMax = ceil(mea[9]);
const float lutMax = std::ceil(mea[9]);
const float lutDiff = lutMax / lutSize;
std::vector<float> lutVals(lutSize);
int jStart = 1;
for (int i = 0; i < 100; ++i) {
for (int i = 0; i < lutSize; ++i) {
const float val = i * lutDiff;
if (val < mea[0]) {
// still < first value => no interpolation
@ -87,35 +90,38 @@ std::unique_ptr<LUTf> buildMeaLut(const float inVals[11], const float mea[10], f
lutVals[i] = inVals[j];
++jStart;
break;
} else if (val < mea[j]) {
}
if (val < mea[j]) {
// interpolate
const float dist = (val - mea[j - 1]) / (mea[j] - mea[j - 1]);
lutVals[i] = rtengine::intp(dist, inVals[j], inVals[j - 1]);
break;
} else {
lutVals[i] = inVals[10];
}
lutVals[i] = inVals[10];
}
}
}
lutFactor = 1.f / lutDiff;
return std::unique_ptr<LUTf>(new LUTf(lutVals));
}
constexpr float clipLoc(float x) {
constexpr float clipLoc(float x)
{
return rtengine::LIM(x, 0.f, 32767.f);
}
constexpr float clipDE(float x) {
constexpr float clipDE(float x)
{
return rtengine::LIM(x, 0.3f, 1.f);
}
constexpr float clipC(float x) {
constexpr float clipC(float x)
{
return rtengine::LIM(x, -42000.f, 42000.f);
}
constexpr float clipChro(float x) {
constexpr float clipChro(float x)
{
return rtengine::LIM(x, 0.f, 140.f);
}