X-Git-Url: http://git.rot13.org/?p=zxing.git;a=blobdiff_plain;f=cpp%2Fmagick%2Fsrc%2FMagickBitmapSource.cpp;fp=cpp%2Fmagick%2Fsrc%2FMagickBitmapSource.cpp;h=f805487e890d397549e779d08c5302b3a95c84cf;hp=fd2980ab50940116979d52e31ba1a1e9976daf72;hb=472b8baaf68b96a7b030a19631f9c3250c1dadc5;hpb=af2a2146f0a0f79f9196501bd38f9ac2e9a6d061 diff --git a/cpp/magick/src/MagickBitmapSource.cpp b/cpp/magick/src/MagickBitmapSource.cpp index fd2980ab..f805487e 100644 --- a/cpp/magick/src/MagickBitmapSource.cpp +++ b/cpp/magick/src/MagickBitmapSource.cpp @@ -52,7 +52,9 @@ unsigned char* MagickBitmapSource::getRow(int y, unsigned char* row) { for (int x = 0; x < width; x++) { const PixelPacket* p = pixel_cache + y * width + x; // We assume 16 bit values here - row[x] = (unsigned char)((306 * ((int)p->red >> 8) + 601 * ((int)p->green >> 8) + 117 * ((int)p->blue >> 8)) >> 10); + // 0x200 = 1<<9, half an lsb of the result to force rounding + row[x] = (unsigned char)((306 * ((int)p->red >> 8) + 601 * ((int)p->green >> 8) + + 117 * ((int)p->blue >> 8) + 0x200) >> 10); } return row; @@ -67,7 +69,8 @@ unsigned char* MagickBitmapSource::getMatrix() { const Magick::PixelPacket* p = pixel_cache; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { - *m = (unsigned char)((306 * ((int)p->red >> 8) + 601 * ((int)p->green >> 8) + 117 * ((int)p->blue >> 8)) >> 10); + *m = (unsigned char)((306 * ((int)p->red >> 8) + 601 * ((int)p->green >> 8) + + 117 * ((int)p->blue >> 8) + 0x200) >> 10); m++; p++; }