Angus Leeming wrote:
>
> Feel free to patch.
here it is
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 13:53:43 -0000
@@ -558,50 +558,33 @@
// Can't deal with it.
return input;
- int nbytes;
- double factor;
- switch (size) {
- case 13: // #rrrrggggbbbb
- nbytes = 4;
- factor = 1.0 / 256.0;
- break;
-
- case 10: // #rrrgggbbb
- nbytes = 3;
- factor = 1.0 / 16.0;
- 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())
+ long long asLong;
+ istringstream rss(input.str());
+ rss >> std::hex >> asLong;
+ if (rss.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 << '#';
+ for (int i=0; i < 3; i++) {
+ switch (size) {
+ case 13: // #rrrrggggbbbb
+ oss << std::hex << std::setfill('0') << (asLong & 0xff);
+ asLong = asLong >> 16;
+ break;
+
+ case 10: // #rrrgggbbb
+ oss << std::hex << std::setfill('0') << (asLong & 0xff);
+ asLong = asLong >> 12;
+ break;
- ostringstream oss;
- oss << '#' << std::hex << std::setfill('0')
- << std::setw(2) << r
- << std::setw(2) << g
- << std::setw(2) << b;
+ case 4: // #rgb
+ oss << std::hex << ((asLong & 0xf) << 4);
+ asLong = asLong >> 4;
+ break;
+ }
+ }
return oss.str().c_str();
}