X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fbin%2Fjp2%2Fconvertbmp.c;h=b49e7a080882ae59511e66bb0522122b3c266a4b;hb=0b4c3ce75d11600ebc6675bd871f78ca3c95bc60;hp=a636ddc53efb2bee5cdf529b081209433d084993;hpb=00f45684a8339e69ed55df2397f3c19d09fecaed;p=openjpeg.git diff --git a/src/bin/jp2/convertbmp.c b/src/bin/jp2/convertbmp.c index a636ddc5..b49e7a08 100644 --- a/src/bin/jp2/convertbmp.c +++ b/src/bin/jp2/convertbmp.c @@ -929,7 +929,9 @@ int imagetobmp(opj_image_t * image, const char *outfile) r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - r = ((r >> adjustR) + ((r >> (adjustR - 1)) % 2)); + if (adjustR > 0) { + r = ((r >> adjustR) + ((r >> (adjustR - 1)) % 2)); + } if (r > 255) { r = 255; } else if (r < 0) { @@ -939,7 +941,9 @@ int imagetobmp(opj_image_t * image, const char *outfile) g = image->comps[1].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); - g = ((g >> adjustG) + ((g >> (adjustG - 1)) % 2)); + if (adjustG > 0) { + g = ((g >> adjustG) + ((g >> (adjustG - 1)) % 2)); + } if (g > 255) { g = 255; } else if (g < 0) { @@ -949,7 +953,9 @@ int imagetobmp(opj_image_t * image, const char *outfile) b = image->comps[2].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); - b = ((b >> adjustB) + ((b >> (adjustB - 1)) % 2)); + if (adjustB > 0) { + b = ((b >> adjustB) + ((b >> (adjustB - 1)) % 2)); + } if (b > 255) { b = 255; } else if (b < 0) { @@ -1044,7 +1050,9 @@ int imagetobmp(opj_image_t * image, const char *outfile) r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - r = ((r >> adjustR) + ((r >> (adjustR - 1)) % 2)); + if (adjustR > 0) { + r = ((r >> adjustR) + ((r >> (adjustR - 1)) % 2)); + } if (r > 255) { r = 255; } else if (r < 0) {