Lars Gullik Bjønnes wrote:

> Herbert Voss <[EMAIL PROTECTED]> writes:
> 
> | +        long long asLong;
> 
> Well... we cannot really use long long, not standard C++.


I see, here is another one. but this is nearly the same
than yours ...

Herbert



-- 
http://www.lyx.org/help/
Index: src/graphics/GraphicsImageXPM.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/graphics/GraphicsImageXPM.C,v
retrieving revision 1.10
diff -u -r1.10 GraphicsImageXPM.C
--- src/graphics/GraphicsImageXPM.C     17 Apr 2002 16:08:31 -0000      1.10
+++ src/graphics/GraphicsImageXPM.C     18 Apr 2002 14:16:17 -0000
@@ -558,50 +558,28 @@
                // Can't deal with it.
                return input;
 
-       int nbytes;
-       double factor;
-       switch (size) {
-       case 13: // #rrrrggggbbbb
-           nbytes = 4;
-           factor = 1.0 / 256.0;
-           break;
+        int hexNo;
+        ostringstream oss;
+        oss << '#';
+        for (int i=0; i < 3; i++) {
+               switch (size) {
+               case 13: // #rrrrggggbbbb
+                       istringstream rss(input.substr(i*4+1,4).c_str());
+                       rss >> std::hex >> hexNo;
+                       oss << std::hex << std::setfill('0') << (hexNo & 0xff);
+               break;
 
-       case 10: // #rrrgggbbb
-           nbytes = 3;
-           factor = 1.0 / 16.0;
-           break;
+               case 10: // #rrrgggbbb
+                       istringstream rss(input.substr(i*3+1,3).c_str());
+                       rss >> std::hex >> hexNo;
+                       oss << std::hex << std::setfill('0') << (hexNo & 0xff);
+               break;
 
-       case 4:  // #rgb
-           nbytes = 1;
-           factor = 16.0;
-           break;
-       }
-
-       int r, g, b;
-       int const pos1 = 1;
-       int const pos2 = pos1 + nbytes;
-       int const pos3 = pos2 + nbytes;
-       
-       stringstream ss;
-       ss << input.substr(pos1, nbytes) << ' '
-          << input.substr(pos2, nbytes) << ' '
-          << input.substr(pos3, nbytes);
-       ss >> std::hex >> r >> g >> b;
-       if (ss.fail())
-               // Oh, you're on your own.
-               return input;
-       
-       // The existing r,g,b values are multiplied by these factors
-       // to end up with values in the range 0 <= c <= 255
-       r = int(factor * double(r));
-       g = int(factor * double(g));
-       b = int(factor * double(b));
-
-       ostringstream oss;
-       oss << '#' << std::hex << std::setfill('0')
-           << std::setw(2) << r
-           << std::setw(2) << g
-           << std::setw(2) << b;
+               case 4:  // #rgb
+                       oss << input[i] << '0';
+               break;
+               }
+        }
 
        return oss.str().c_str();
 }

Reply via email to