diff --git a/rtengine/image16.cc b/rtengine/image16.cc index 937e2d19d..9d41f96c5 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] >> 8; - buffer[ix++] = green[i] >> 8; - buffer[ix++] = blue[i] >> 8; + buffer[ix++] = red[i] / 257; + buffer[ix++] = green[i] / 257; + buffer[ix++] = blue[i] / 257; } } @@ -92,10 +92,10 @@ void Image16::setScanline (int row, unsigned char* buffer, int bps, float *minVa case (IIOSF_UNSIGNED_CHAR): { int ix = 0; - for (int i = 0; i < width; i++) { - r(row, i) = (unsigned short)(buffer[ix++]) << 8; - g(row, i) = (unsigned short)(buffer[ix++]) << 8; - b(row, i) = (unsigned short)(buffer[ix++]) << 8; + for (int i = 0; i < width; ++i) { + r(row, i) = static_cast(buffer[ix++]) * 257; + g(row, i) = static_cast(buffer[ix++]) * 257; + b(row, i) = static_cast(buffer[ix++]) * 257; } break; @@ -105,7 +105,7 @@ void Image16::setScanline (int row, unsigned char* buffer, int bps, float *minVa unsigned short* sbuffer = (unsigned short*) buffer; int ix = 0; - for (int i = 0; i < width; i++) { + for (int i = 0; i < width; ++i) { r(row, i) = sbuffer[ix++]; g(row, i) = sbuffer[ix++]; b(row, i) = sbuffer[ix++]; @@ -298,11 +298,11 @@ Image16::to8() { Image8* img8 = new Image8(width, height); - for ( int h = 0; h < height; ++h ) { - for ( int w = 0; w < width; ++w ) { - img8->r(h, w) = (unsigned char)( r(h, w) >> 8); - img8->g(h, w) = (unsigned char)( g(h, w) >> 8); - img8->b(h, w) = (unsigned char)( b(h, w) >> 8); + 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; } } @@ -314,11 +314,11 @@ Image16::tofloat() { Imagefloat* imgfloat = new Imagefloat(width, height); - for ( int h = 0; h < height; ++h ) { - for ( int w = 0; w < width; ++w ) { - imgfloat->r(h, w) = (float)r(h, w); - imgfloat->g(h, w) = (float)g(h, w); - imgfloat->b(h, w) = (float)b(h, w); + for (int h = 0; h < height; ++h) { + for (int w = 0; w < width; ++w) { + imgfloat->r(h, w) = r(h, w); + imgfloat->g(h, w) = g(h, w); + imgfloat->b(h, w) = b(h, w); } } diff --git a/rtengine/image8.cc b/rtengine/image8.cc index b27851a76..1cc648eb5 100644 --- a/rtengine/image8.cc +++ b/rtengine/image8.cc @@ -49,8 +49,8 @@ void Image8::getScanline (int row, unsigned char* buffer, int bps) } else if (bps == 16) { unsigned short* sbuffer = (unsigned short*) buffer; - for (int i = 0, ix = row * width * 3; i < width * 3; i++, ix++) { - sbuffer[i] = (unsigned short)(data[ix]) << 8; + for (int i = 0, ix = row * width * 3; i < width * 3; ++i, ++ix) { + sbuffer[i] = static_cast(data[ix]) * 257; } } } @@ -73,8 +73,8 @@ void Image8::setScanline (int row, unsigned char* buffer, int bps, float *minVal case (IIOSF_UNSIGNED_SHORT): { unsigned short* sbuffer = (unsigned short*) buffer; - for (int i = 0, ix = row * width * 3; i < width * 3; i++, ix++) { - data[ix] = sbuffer[i] >> 8; + for (int i = 0, ix = row * width * 3; i < width * 3; ++i, ++ix) { + data[ix] = sbuffer[i] / 257; } break; diff --git a/rtengine/imagefloat.cc b/rtengine/imagefloat.cc index 26ea8ae6e..fb4ccae2e 100644 --- a/rtengine/imagefloat.cc +++ b/rtengine/imagefloat.cc @@ -333,11 +333,11 @@ Imagefloat::to8() #pragma omp parallel for schedule(static) #endif - for ( int h = 0; h < height; ++h ) { - for ( int w = 0; w < width; ++w ) { - img8->r(h, w) = (unsigned char)( (unsigned short)(r(h, w)) >> 8); - img8->g(h, w) = (unsigned char)( (unsigned short)(g(h, w)) >> 8); - img8->b(h, w) = (unsigned char)( (unsigned short)(b(h, w)) >> 8); + 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; } } @@ -352,11 +352,11 @@ Imagefloat::to16() #pragma omp parallel for schedule(static) #endif - for ( int h = 0; h < height; ++h ) { - for ( int w = 0; w < width; ++w ) { - img16->r( h, w) = (unsigned short)(r(h, w)); - img16->g( h, w) = (unsigned short)(g(h, w)); - img16->b( h, w) = (unsigned short)(b(h, w)); + for (int h = 0; h < height; ++h) { + for (int w = 0; w < width; ++w) { + img16->r(h, w) = r(h, w); + img16->g(h, w) = g(h, w); + img16->b(h, w) = b(h, w); } }