Fix small bug in downsampling that causes artifacts

This commit is contained in:
Pavel Krajcevski 2013-09-20 12:48:56 -04:00
parent 1093447055
commit e9a9988a56

View File

@ -52,6 +52,7 @@
#include "Image.h"
#include <algorithm>
#include <cassert>
#include <cstring>
#include <cstdio>
@ -62,6 +63,11 @@
#include "Core/include/Image.h"
#include "IO/include/ImageFile.h"
template <typename T>
inline T Clamp(const T &v, const T &a, const T &b) {
return ::std::min(::std::max(a, v), b);
}
static float ConvertChannelToFloat(uint8 channel, uint8 bitDepth) {
float denominator = static_cast<float>((1 << bitDepth) - 1);
return static_cast<float>(channel) / denominator;
@ -346,7 +352,7 @@ void Image::ContentAwareDownscale(uint32 xtimes, uint32 ytimes,
Iysq * Iyy[c][idx]) / denom;
}
float scale = static_cast<float>((1 << bitDepth[c]) - 1);
result.Component(c) = static_cast<uint8>((I0 + 0.25*It) * scale + 0.5);
result.Component(c) = static_cast<uint8>(Clamp(I0 + 0.25f*It, 0.0f, 1.0f) * scale + 0.5);
}
downscaledPixels[j * newHeight + i] = result;