From 6bbc07ed1dc8f617222f229df083c8cca60d1608 Mon Sep 17 00:00:00 2001
From: mrwastl <mrwastl@users.sourceforge.net>
Date: Sun, 23 Sep 2012 22:42:23 +0200
Subject: extformats.c: use scaleQuantumToDouble() to get colour values in
 range 0 to 255; avoid MaxRGB/QuantumRange at all

---
 glcdgraphics/extformats.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/glcdgraphics/extformats.c b/glcdgraphics/extformats.c
index afc47d6..3a0ab36 100644
--- a/glcdgraphics/extformats.c
+++ b/glcdgraphics/extformats.c
@@ -28,8 +28,6 @@
 //#include <Imlib2.h>
 #endif
 
-#include <math.h>
-
 
 namespace GLCD
 {
@@ -131,17 +129,20 @@ bool cExtFormatFile::LoadScaled(cImage & image, const string & fileName, uint16_
         //Dprintf("this image has %d colors\n", (*it).totalColors());
 
         bool isMatte = (*it).matte();
-        size_t qrange = (size_t)pow(2.0, (*it).depth()) - 1;
         //bool isMonochrome = ((*it).totalColors() <= 2) ? true : false;
         const Magick::PixelPacket *pix = (*it).getConstPixels(0, 0, (int)width, (int)height);
 
         for (int iy = 0; iy < (int)height; ++iy) {
           for (int ix = 0; ix < (int)width; ++ix) {
-            if ( isMatte && pix->opacity == qrange ) {
+            if ( isMatte && Magick::Color::scaleQuantumToDouble(pix->opacity) * 255 == 255 ) {
                 bmpdata[iy*width+ix] = cColor::Transparent;
             } else {
-                //bmpdata[iy*width+ix] = (uint32_t)( 0xFF000000 | (int(pix->red * 255 / MaxRGB) << 16) | (int(pix->green * 255 / MaxRGB) << 8) | int(pix->blue * 255 / MaxRGB));
-                bmpdata[iy*width+ix] = (uint32_t)( (int(255 - (pix->opacity * 255 / qrange)) << 24)  | (int(pix->red * 255 / qrange) << 16) | (int(pix->green * 255 / qrange) << 8) | int(pix->blue * 255 / qrange));
+                bmpdata[iy*width+ix] = (uint32_t)(
+                                        (uint32_t(255 - (Magick::Color::scaleQuantumToDouble(pix->opacity) * 255)) << 24)  |
+                                        (uint32_t( Magick::Color::scaleQuantumToDouble(pix->red) * 255) << 16) |
+                                        (uint32_t( Magick::Color::scaleQuantumToDouble(pix->green) * 255) << 8) |
+                                         uint32_t( Magick::Color::scaleQuantumToDouble(pix->blue) * 255)
+                                       );
                 //if ( isMonochrome ) {  // if is monochrome: exchange black and white
                 //    uint32_t c = bmpdata[iy*width+ix];
                 //    switch(c) {
-- 
cgit v1.2.3