From 244501ad3c23a00a004121ee99ca36eaf6b8abb4 Mon Sep 17 00:00:00 2001 From: Lode Date: Thu, 20 Nov 2014 22:04:11 +0100 Subject: small tweaks --- lodepng.cpp | 11 ++++++----- lodepng_unittest.cpp | 4 ++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lodepng.cpp b/lodepng.cpp index 09bb5e6..3179e0a 100644 --- a/lodepng.cpp +++ b/lodepng.cpp @@ -3494,7 +3494,7 @@ void lodepng_color_profile_init(LodePNGColorProfile* profile) }*/ /*Returns how many bits needed to represent given value (max 8 bit)*/ -unsigned getValueRequiredBits(unsigned char value) +static unsigned getValueRequiredBits(unsigned char value) { if(value == 0 || value == 255) return 1; /*The scaling of 2-bit and 4-bit values uses multiples of 85 and 17*/ @@ -3531,7 +3531,8 @@ unsigned lodepng_get_color_profile(LodePNGColorProfile* profile, for(i = 0; i < numpixels; i++) { getPixelColorRGBA16(&r, &g, &b, &a, in, i, mode); - if(r % 257u != 0 || g % 257u != 0 || b % 257u != 0 || a % 257u != 0) /*first and second byte differ*/ + if((r & 255u) != ((r >> 8) & 255u) || (g & 255u) != ((g >> 8) & 255u) || + (b & 255u) != ((b >> 8) & 255u) || (a & 255u) != ((a >> 8) & 255u)) /*first and second byte differ*/ { sixteen = 1; break; @@ -3652,9 +3653,9 @@ unsigned lodepng_get_color_profile(LodePNGColorProfile* profile, } /*make the profile's key always 16-bit for consistency - repeat each byte twice*/ - profile->key_r *= 257; - profile->key_g *= 257; - profile->key_b *= 257; + profile->key_r += (profile->key_r << 8); + profile->key_g += (profile->key_g << 8); + profile->key_b += (profile->key_b << 8); } color_tree_cleanup(&tree); diff --git a/lodepng_unittest.cpp b/lodepng_unittest.cpp index f2b1cf7..e3dbc10 100644 --- a/lodepng_unittest.cpp +++ b/lodepng_unittest.cpp @@ -1754,6 +1754,10 @@ void testAutoColorModels() std::vector not16; addColor16(not16, 257, 257, 257, 0); testAutoColorModel(not16, 16, LCT_PALETTE, 1, false); + + std::vector alpha16; + addColor16(alpha16, 257, 0, 0, 10000); + testAutoColorModel(alpha16, 16, LCT_RGBA, 16, false); } void doMain() -- cgit v1.2.3