diff --git a/rtengine/iimage.h b/rtengine/iimage.h index 2eded8208..4362f369a 100644 --- a/rtengine/iimage.h +++ b/rtengine/iimage.h @@ -103,27 +103,27 @@ public: template<> inline void ImageDatas::convertTo(unsigned short src, unsigned char& dst) const { - dst = src / 257; + dst = (src + 128) / 257; } template<> inline void ImageDatas::convertTo(unsigned char src, int& dst) const { - dst = static_cast(src) * 257; + dst = src * 257; } template<> inline void ImageDatas::convertTo(unsigned char src, unsigned short& dst) const { - dst = static_cast(src) * 257; + dst = src * 257; } template<> inline void ImageDatas::convertTo(float src, unsigned char& dst) const { - dst = static_cast(src) / 257; + dst = (static_cast(src) + 128) / 257; } template<> inline void ImageDatas::convertTo(unsigned char src, float& dst) const { - dst = static_cast(src) * 257; + dst = src * 257; } // -------------------------------------------------------------------- diff --git a/rtengine/image16.cc b/rtengine/image16.cc index 9d41f96c5..11a05902f 100644 --- a/rtengine/image16.cc +++ b/rtengine/image16.cc @@ -28,9 +28,9 @@ namespace void getScanline8 (const uint16_t *red, const uint16_t *green, const uint16_t *blue, int width, unsigned char* buffer) { for (int i = 0, ix = 0; i < width; i++) { - buffer[ix++] = red[i] / 257; - buffer[ix++] = green[i] / 257; - buffer[ix++] = blue[i] / 257; + buffer[ix++] = (red[i] + 128) / 257; + buffer[ix++] = (green[i] + 128) / 257; + buffer[ix++] = (blue[i] + 128) / 257; } } @@ -300,9 +300,9 @@ Image16::to8() for (int h = 0; h < height; ++h) { for (int w = 0; w < width; ++w) { - img8->r(h, w) = r(h, w) / 257; - img8->g(h, w) = g(h, w) / 257; - img8->b(h, w) = b(h, w) / 257; + img8->r(h, w) = (r(h, w) + 128) / 257; + img8->g(h, w) = (g(h, w) + 128) / 257; + img8->b(h, w) = (b(h, w) + 128) / 257; } } diff --git a/rtengine/image8.cc b/rtengine/image8.cc index 1cc648eb5..41589993d 100644 --- a/rtengine/image8.cc +++ b/rtengine/image8.cc @@ -74,7 +74,7 @@ void Image8::setScanline (int row, unsigned char* buffer, int bps, float *minVal unsigned short* sbuffer = (unsigned short*) buffer; for (int i = 0, ix = row * width * 3; i < width * 3; ++i, ++ix) { - data[ix] = sbuffer[i] / 257; + data[ix] = (sbuffer[i] + 128) / 257; } break; diff --git a/rtengine/imagefloat.cc b/rtengine/imagefloat.cc index fb4ccae2e..7f84f1cab 100644 --- a/rtengine/imagefloat.cc +++ b/rtengine/imagefloat.cc @@ -335,9 +335,9 @@ Imagefloat::to8() for (int h = 0; h < height; ++h) { for (int w = 0; w < width; ++w) { - img8->r(h, w) = static_cast(r(h, w)) / 257; - img8->g(h, w) = static_cast(g(h, w)) / 257; - img8->b(h, w) = static_cast(b(h, w)) / 257; + img8->r(h, w) = (static_cast(r(h, w)) + 128) / 257; + img8->g(h, w) = (static_cast(g(h, w)) + 128) / 257; + img8->b(h, w) = (static_cast(b(h, w)) + 128) / 257; } } diff --git a/rtengine/iplab2rgb.cc b/rtengine/iplab2rgb.cc index 489ca60bc..843bdaa9c 100644 --- a/rtengine/iplab2rgb.cc +++ b/rtengine/iplab2rgb.cc @@ -117,9 +117,9 @@ void ImProcFunctions::lab2monitorRgb (LabImage* lab, Image8* image) /* copy RGB */ //int R1=((int)gamma2curve[(R)]) - data[ix++] = ((int)Color::gamma2curve[R]) >> 8; - data[ix++] = ((int)Color::gamma2curve[G]) >> 8; - data[ix++] = ((int)Color::gamma2curve[B]) >> 8; + data[ix++] = (static_cast(Color::gamma2curve[R]) + 128) / 257; + data[ix++] = (static_cast(Color::gamma2curve[G]) + 128) / 257; + data[ix++] = (static_cast(Color::gamma2curve[B]) + 128) / 257; } } } @@ -229,9 +229,9 @@ Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch, Color::xyz2rgb(x_, y_, z_, R, G, B, xyz_rgb); - image->data[ix++] = (int)Color::gamma2curve[R] >> 8; - image->data[ix++] = (int)Color::gamma2curve[G] >> 8; - image->data[ix++] = (int)Color::gamma2curve[B] >> 8; + image->data[ix++] = (static_cast(Color::gamma2curve[R]) + 128) / 257; + image->data[ix++] = (static_cast(Color::gamma2curve[G]) + 128) / 257; + image->data[ix++] = (static_cast(Color::gamma2curve[B]) + 128) / 257; } } }