Fix range in Image* classes (#3429)

This commit is contained in:
Flössie
2016-09-17 17:32:46 +02:00
parent cb034284be
commit 309b823f93
3 changed files with 32 additions and 32 deletions

View File

@@ -28,9 +28,9 @@ namespace
void getScanline8 (const uint16_t *red, const uint16_t *green, const uint16_t *blue, int width, unsigned char* buffer) 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++) { for (int i = 0, ix = 0; i < width; i++) {
buffer[ix++] = red[i] >> 8; buffer[ix++] = red[i] / 257;
buffer[ix++] = green[i] >> 8; buffer[ix++] = green[i] / 257;
buffer[ix++] = blue[i] >> 8; 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): { case (IIOSF_UNSIGNED_CHAR): {
int ix = 0; int ix = 0;
for (int i = 0; i < width; i++) { for (int i = 0; i < width; ++i) {
r(row, i) = (unsigned short)(buffer[ix++]) << 8; r(row, i) = static_cast<unsigned short>(buffer[ix++]) * 257;
g(row, i) = (unsigned short)(buffer[ix++]) << 8; g(row, i) = static_cast<unsigned short>(buffer[ix++]) * 257;
b(row, i) = (unsigned short)(buffer[ix++]) << 8; b(row, i) = static_cast<unsigned short>(buffer[ix++]) * 257;
} }
break; break;
@@ -105,7 +105,7 @@ void Image16::setScanline (int row, unsigned char* buffer, int bps, float *minVa
unsigned short* sbuffer = (unsigned short*) buffer; unsigned short* sbuffer = (unsigned short*) buffer;
int ix = 0; int ix = 0;
for (int i = 0; i < width; i++) { for (int i = 0; i < width; ++i) {
r(row, i) = sbuffer[ix++]; r(row, i) = sbuffer[ix++];
g(row, i) = sbuffer[ix++]; g(row, i) = sbuffer[ix++];
b(row, i) = sbuffer[ix++]; b(row, i) = sbuffer[ix++];
@@ -300,9 +300,9 @@ Image16::to8()
for (int h = 0; h < height; ++h) { for (int h = 0; h < height; ++h) {
for (int w = 0; w < width; ++w) { for (int w = 0; w < width; ++w) {
img8->r(h, w) = (unsigned char)( r(h, w) >> 8); img8->r(h, w) = r(h, w) / 257;
img8->g(h, w) = (unsigned char)( g(h, w) >> 8); img8->g(h, w) = g(h, w) / 257;
img8->b(h, w) = (unsigned char)( b(h, w) >> 8); img8->b(h, w) = b(h, w) / 257;
} }
} }
@@ -316,9 +316,9 @@ Image16::tofloat()
for (int h = 0; h < height; ++h) { for (int h = 0; h < height; ++h) {
for (int w = 0; w < width; ++w) { for (int w = 0; w < width; ++w) {
imgfloat->r(h, w) = (float)r(h, w); imgfloat->r(h, w) = r(h, w);
imgfloat->g(h, w) = (float)g(h, w); imgfloat->g(h, w) = g(h, w);
imgfloat->b(h, w) = (float)b(h, w); imgfloat->b(h, w) = b(h, w);
} }
} }

View File

@@ -49,8 +49,8 @@ void Image8::getScanline (int row, unsigned char* buffer, int bps)
} else if (bps == 16) { } else if (bps == 16) {
unsigned short* sbuffer = (unsigned short*) buffer; unsigned short* sbuffer = (unsigned short*) buffer;
for (int i = 0, ix = row * width * 3; i < width * 3; i++, ix++) { for (int i = 0, ix = row * width * 3; i < width * 3; ++i, ++ix) {
sbuffer[i] = (unsigned short)(data[ix]) << 8; sbuffer[i] = static_cast<unsigned short>(data[ix]) * 257;
} }
} }
} }
@@ -73,8 +73,8 @@ void Image8::setScanline (int row, unsigned char* buffer, int bps, float *minVal
case (IIOSF_UNSIGNED_SHORT): { case (IIOSF_UNSIGNED_SHORT): {
unsigned short* sbuffer = (unsigned short*) buffer; unsigned short* sbuffer = (unsigned short*) buffer;
for (int i = 0, ix = row * width * 3; i < width * 3; i++, ix++) { for (int i = 0, ix = row * width * 3; i < width * 3; ++i, ++ix) {
data[ix] = sbuffer[i] >> 8; data[ix] = sbuffer[i] / 257;
} }
break; break;

View File

@@ -335,9 +335,9 @@ Imagefloat::to8()
for (int h = 0; h < height; ++h) { for (int h = 0; h < height; ++h) {
for (int w = 0; w < width; ++w) { for (int w = 0; w < width; ++w) {
img8->r(h, w) = (unsigned char)( (unsigned short)(r(h, w)) >> 8); img8->r(h, w) = static_cast<unsigned short>(r(h, w)) / 257;
img8->g(h, w) = (unsigned char)( (unsigned short)(g(h, w)) >> 8); img8->g(h, w) = static_cast<unsigned short>(g(h, w)) / 257;
img8->b(h, w) = (unsigned char)( (unsigned short)(b(h, w)) >> 8); img8->b(h, w) = static_cast<unsigned short>(b(h, w)) / 257;
} }
} }
@@ -354,9 +354,9 @@ Imagefloat::to16()
for (int h = 0; h < height; ++h) { for (int h = 0; h < height; ++h) {
for (int w = 0; w < width; ++w) { for (int w = 0; w < width; ++w) {
img16->r( h, w) = (unsigned short)(r(h, w)); img16->r(h, w) = r(h, w);
img16->g( h, w) = (unsigned short)(g(h, w)); img16->g(h, w) = g(h, w);
img16->b( h, w) = (unsigned short)(b(h, w)); img16->b(h, w) = b(h, w);
} }
} }