]>
git.saurik.com Git - wxWidgets.git/blob - src/common/xpmdecod.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxXPMDecoder
4 // Author: John Cristy, Vaclav Slavik
6 // Copyright: (c) John Cristy, Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
12 This file is partially based on source code of ImageMagick by John Cristy. Its
13 license is as follows:
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26 % Read/Write ImageMagick Image Format. %
34 % Copyright (C) 2001 ImageMagick Studio, a non-profit organization dedicated %
35 % to making software imaging solutions freely available. %
37 % Permission is hereby granted, free of charge, to any person obtaining a %
38 % copy of this software and associated documentation files ("ImageMagick"), %
39 % to deal in ImageMagick without restriction, including without limitation %
40 % the rights to use, copy, modify, merge, publish, distribute, sublicense, %
41 % and/or sell copies of ImageMagick, and to permit persons to whom the %
42 % ImageMagick is furnished to do so, subject to the following conditions: %
44 % The above copyright notice and this permission notice shall be included in %
45 % all copies or substantial portions of ImageMagick. %
47 % The software is provided "as is", without warranty of any kind, express or %
48 % implied, including but not limited to the warranties of merchantability, %
49 % fitness for a particular purpose and noninfringement. In no event shall %
50 % ImageMagick Studio be liable for any claim, damages or other liability, %
51 % whether in an action of contract, tort or otherwise, arising from, out of %
52 % or in connection with ImageMagick or the use or other dealings in %
55 % Except as contained in this notice, the name of the ImageMagick Studio %
56 % shall not be used in advertising or otherwise to promote the sale, use or %
57 % other dealings in ImageMagick without prior written authorization from the %
58 % ImageMagick Studio. %
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 * Also contains some pieces from libxpm and its modification for win32 by
67 * HeDu <hedu@cul-ipn.uni-kiel.de>:
69 * Copyright (C) 1989-95 GROUPE BULL
71 * Permission is hereby granted, free of charge, to any person obtaining a copy
72 * of this software and associated documentation files (the "Software"), to
73 * deal in the Software without restriction, including without limitation the
74 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
75 * sell copies of the Software, and to permit persons to whom the Software is
76 * furnished to do so, subject to the following conditions:
78 * The above copyright notice and this permission notice shall be included in
79 * all copies or substantial portions of the Software.
81 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
82 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
83 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
84 * GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
85 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
86 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
88 * Except as contained in this notice, the name of GROUPE BULL shall not be
89 * used in advertising or otherwise to promote the sale, use or other dealings
90 * in this Software without prior written authorization from GROUPE BULL.
94 #pragma implementation "xpmdecod.h"
97 // For compilers that support precompilation, includes "wx.h".
98 #include "wx/wxprec.h"
105 # include "wx/defs.h"
108 #if wxUSE_IMAGE && wxUSE_XPM
110 #include "wx/stream.h"
111 #include "wx/image.h"
112 #include "wx/utils.h"
117 #include "wx/xpmdecod.h"
120 bool wxXPMDecoder::CanRead(wxInputStream
& stream
)
122 unsigned char buf
[9];
125 stream
.SeekI(-9, wxFromCurrent
);
127 return (memcmp(buf
, "/* XPM */", 9) == 0);
130 wxImage
wxXPMDecoder::ReadFile(wxInputStream
& stream
)
132 size_t length
= stream
.GetSize();
133 wxCHECK_MSG(length
!= 0, wxNullImage
, wxT("Cannot read XPM from stream of unknown size"));
135 char *xpm_buffer
= new char[length
];
139 if ( stream
.Read(xpm_buffer
, length
).LastError() == wxSTREAM_READ_ERROR
)
143 * Remove comments from the file:
145 for (p
= xpm_buffer
; *p
!= '\0'; p
++)
147 if ( (*p
== '"') || (*p
== '\'') )
151 for (p
++; *p
!= '\0'; p
++)
152 if ( (*p
== '"') && (*(p
- 1) != '\\') )
157 for (p
++; *p
!= '\0'; p
++)
158 if ( (*p
== '\'') && (*(p
- 1) != '\\') )
165 if ( (*p
!= '/') || (*(p
+ 1) != '*') )
167 for (q
= p
+ 2; *q
!= '\0'; q
++)
169 if ( (*q
== '*') && (*(q
+ 1) == '/') )
176 * Remove unquoted characters:
179 for (p
= xpm_buffer
; *p
!= '\0'; p
++)
183 for (q
= p
+ 1; *q
!= '\0'; q
++)
186 strncpy(xpm_buffer
+ i
, p
+ 1, q
- p
- 1);
188 xpm_buffer
[i
++] = '\n';
191 xpm_buffer
[i
] = '\0';
194 * Create array of lines and convert \n's to \0's:
196 const char **xpm_lines
;
197 size_t lines_cnt
= 0;
200 for (p
= xpm_buffer
; *p
!= '\0'; p
++)
206 xpm_lines
= new const char*[lines_cnt
];
207 xpm_lines
[0] = xpm_buffer
;
209 for (p
= xpm_buffer
; (*p
!= '\0') && (line
< lines_cnt
); p
++)
213 xpm_lines
[line
] = p
+ 1;
222 wxImage img
= ReadData(xpm_lines
);
226 delete[] (char**) xpm_lines
;
232 #endif // wxUSE_STREAMS
235 /*****************************************************************************\
238 * A hard coded rgb.txt. To keep it short I removed all colornames with *
239 * trailing numbers, Blue3 etc, except the GrayXX. Sorry Grey-lovers I prefer *
240 * Gray ;-). But Grey is recognized on lookups, only on save Gray will be *
241 * used, maybe you want to do some substitue there too. *
243 * To save memory the RGBs are coded in one long value, as done by the RGB *
246 * Developed by HeDu 3/94 (hedu@cul-ipn.uni-kiel.de) *
247 \*****************************************************************************/
256 #define myRGB(r,g,b) ((wxUint32)r<<16|(wxUint32)g<<8|(wxUint32)b)
258 static rgbRecord theRGBRecords
[] =
260 {"aliceblue", myRGB(240, 248, 255)},
261 {"antiquewhite", myRGB(250, 235, 215)},
262 {"aquamarine", myRGB(50, 191, 193)},
263 {"azure", myRGB(240, 255, 255)},
264 {"beige", myRGB(245, 245, 220)},
265 {"bisque", myRGB(255, 228, 196)},
266 {"black", myRGB(0, 0, 0)},
267 {"blanchedalmond", myRGB(255, 235, 205)},
268 {"blue", myRGB(0, 0, 255)},
269 {"blueviolet", myRGB(138, 43, 226)},
270 {"brown", myRGB(165, 42, 42)},
271 {"burlywood", myRGB(222, 184, 135)},
272 {"cadetblue", myRGB(95, 146, 158)},
273 {"chartreuse", myRGB(127, 255, 0)},
274 {"chocolate", myRGB(210, 105, 30)},
275 {"coral", myRGB(255, 114, 86)},
276 {"cornflowerblue", myRGB(34, 34, 152)},
277 {"cornsilk", myRGB(255, 248, 220)},
278 {"cyan", myRGB(0, 255, 255)},
279 {"darkgoldenrod", myRGB(184, 134, 11)},
280 {"darkgreen", myRGB(0, 86, 45)},
281 {"darkkhaki", myRGB(189, 183, 107)},
282 {"darkolivegreen", myRGB(85, 86, 47)},
283 {"darkorange", myRGB(255, 140, 0)},
284 {"darkorchid", myRGB(139, 32, 139)},
285 {"darksalmon", myRGB(233, 150, 122)},
286 {"darkseagreen", myRGB(143, 188, 143)},
287 {"darkslateblue", myRGB(56, 75, 102)},
288 {"darkslategray", myRGB(47, 79, 79)},
289 {"darkturquoise", myRGB(0, 166, 166)},
290 {"darkviolet", myRGB(148, 0, 211)},
291 {"deeppink", myRGB(255, 20, 147)},
292 {"deepskyblue", myRGB(0, 191, 255)},
293 {"dimgray", myRGB(84, 84, 84)},
294 {"dodgerblue", myRGB(30, 144, 255)},
295 {"firebrick", myRGB(142, 35, 35)},
296 {"floralwhite", myRGB(255, 250, 240)},
297 {"forestgreen", myRGB(80, 159, 105)},
298 {"gainsboro", myRGB(220, 220, 220)},
299 {"ghostwhite", myRGB(248, 248, 255)},
300 {"gold", myRGB(218, 170, 0)},
301 {"goldenrod", myRGB(239, 223, 132)},
302 {"gray", myRGB(126, 126, 126)},
303 {"gray0", myRGB(0, 0, 0)},
304 {"gray1", myRGB(3, 3, 3)},
305 {"gray10", myRGB(26, 26, 26)},
306 {"gray100", myRGB(255, 255, 255)},
307 {"gray11", myRGB(28, 28, 28)},
308 {"gray12", myRGB(31, 31, 31)},
309 {"gray13", myRGB(33, 33, 33)},
310 {"gray14", myRGB(36, 36, 36)},
311 {"gray15", myRGB(38, 38, 38)},
312 {"gray16", myRGB(41, 41, 41)},
313 {"gray17", myRGB(43, 43, 43)},
314 {"gray18", myRGB(46, 46, 46)},
315 {"gray19", myRGB(48, 48, 48)},
316 {"gray2", myRGB(5, 5, 5)},
317 {"gray20", myRGB(51, 51, 51)},
318 {"gray21", myRGB(54, 54, 54)},
319 {"gray22", myRGB(56, 56, 56)},
320 {"gray23", myRGB(59, 59, 59)},
321 {"gray24", myRGB(61, 61, 61)},
322 {"gray25", myRGB(64, 64, 64)},
323 {"gray26", myRGB(66, 66, 66)},
324 {"gray27", myRGB(69, 69, 69)},
325 {"gray28", myRGB(71, 71, 71)},
326 {"gray29", myRGB(74, 74, 74)},
327 {"gray3", myRGB(8, 8, 8)},
328 {"gray30", myRGB(77, 77, 77)},
329 {"gray31", myRGB(79, 79, 79)},
330 {"gray32", myRGB(82, 82, 82)},
331 {"gray33", myRGB(84, 84, 84)},
332 {"gray34", myRGB(87, 87, 87)},
333 {"gray35", myRGB(89, 89, 89)},
334 {"gray36", myRGB(92, 92, 92)},
335 {"gray37", myRGB(94, 94, 94)},
336 {"gray38", myRGB(97, 97, 97)},
337 {"gray39", myRGB(99, 99, 99)},
338 {"gray4", myRGB(10, 10, 10)},
339 {"gray40", myRGB(102, 102, 102)},
340 {"gray41", myRGB(105, 105, 105)},
341 {"gray42", myRGB(107, 107, 107)},
342 {"gray43", myRGB(110, 110, 110)},
343 {"gray44", myRGB(112, 112, 112)},
344 {"gray45", myRGB(115, 115, 115)},
345 {"gray46", myRGB(117, 117, 117)},
346 {"gray47", myRGB(120, 120, 120)},
347 {"gray48", myRGB(122, 122, 122)},
348 {"gray49", myRGB(125, 125, 125)},
349 {"gray5", myRGB(13, 13, 13)},
350 {"gray50", myRGB(127, 127, 127)},
351 {"gray51", myRGB(130, 130, 130)},
352 {"gray52", myRGB(133, 133, 133)},
353 {"gray53", myRGB(135, 135, 135)},
354 {"gray54", myRGB(138, 138, 138)},
355 {"gray55", myRGB(140, 140, 140)},
356 {"gray56", myRGB(143, 143, 143)},
357 {"gray57", myRGB(145, 145, 145)},
358 {"gray58", myRGB(148, 148, 148)},
359 {"gray59", myRGB(150, 150, 150)},
360 {"gray6", myRGB(15, 15, 15)},
361 {"gray60", myRGB(153, 153, 153)},
362 {"gray61", myRGB(156, 156, 156)},
363 {"gray62", myRGB(158, 158, 158)},
364 {"gray63", myRGB(161, 161, 161)},
365 {"gray64", myRGB(163, 163, 163)},
366 {"gray65", myRGB(166, 166, 166)},
367 {"gray66", myRGB(168, 168, 168)},
368 {"gray67", myRGB(171, 171, 171)},
369 {"gray68", myRGB(173, 173, 173)},
370 {"gray69", myRGB(176, 176, 176)},
371 {"gray7", myRGB(18, 18, 18)},
372 {"gray70", myRGB(179, 179, 179)},
373 {"gray71", myRGB(181, 181, 181)},
374 {"gray72", myRGB(184, 184, 184)},
375 {"gray73", myRGB(186, 186, 186)},
376 {"gray74", myRGB(189, 189, 189)},
377 {"gray75", myRGB(191, 191, 191)},
378 {"gray76", myRGB(194, 194, 194)},
379 {"gray77", myRGB(196, 196, 196)},
380 {"gray78", myRGB(199, 199, 199)},
381 {"gray79", myRGB(201, 201, 201)},
382 {"gray8", myRGB(20, 20, 20)},
383 {"gray80", myRGB(204, 204, 204)},
384 {"gray81", myRGB(207, 207, 207)},
385 {"gray82", myRGB(209, 209, 209)},
386 {"gray83", myRGB(212, 212, 212)},
387 {"gray84", myRGB(214, 214, 214)},
388 {"gray85", myRGB(217, 217, 217)},
389 {"gray86", myRGB(219, 219, 219)},
390 {"gray87", myRGB(222, 222, 222)},
391 {"gray88", myRGB(224, 224, 224)},
392 {"gray89", myRGB(227, 227, 227)},
393 {"gray9", myRGB(23, 23, 23)},
394 {"gray90", myRGB(229, 229, 229)},
395 {"gray91", myRGB(232, 232, 232)},
396 {"gray92", myRGB(235, 235, 235)},
397 {"gray93", myRGB(237, 237, 237)},
398 {"gray94", myRGB(240, 240, 240)},
399 {"gray95", myRGB(242, 242, 242)},
400 {"gray96", myRGB(245, 245, 245)},
401 {"gray97", myRGB(247, 247, 247)},
402 {"gray98", myRGB(250, 250, 250)},
403 {"gray99", myRGB(252, 252, 252)},
404 {"green", myRGB(0, 255, 0)},
405 {"greenyellow", myRGB(173, 255, 47)},
406 {"honeydew", myRGB(240, 255, 240)},
407 {"hotpink", myRGB(255, 105, 180)},
408 {"indianred", myRGB(107, 57, 57)},
409 {"ivory", myRGB(255, 255, 240)},
410 {"khaki", myRGB(179, 179, 126)},
411 {"lavender", myRGB(230, 230, 250)},
412 {"lavenderblush", myRGB(255, 240, 245)},
413 {"lawngreen", myRGB(124, 252, 0)},
414 {"lemonchiffon", myRGB(255, 250, 205)},
415 {"lightblue", myRGB(176, 226, 255)},
416 {"lightcoral", myRGB(240, 128, 128)},
417 {"lightcyan", myRGB(224, 255, 255)},
418 {"lightgoldenrod", myRGB(238, 221, 130)},
419 {"lightgoldenrodyellow", myRGB(250, 250, 210)},
420 {"lightgray", myRGB(168, 168, 168)},
421 {"lightpink", myRGB(255, 182, 193)},
422 {"lightsalmon", myRGB(255, 160, 122)},
423 {"lightseagreen", myRGB(32, 178, 170)},
424 {"lightskyblue", myRGB(135, 206, 250)},
425 {"lightslateblue", myRGB(132, 112, 255)},
426 {"lightslategray", myRGB(119, 136, 153)},
427 {"lightsteelblue", myRGB(124, 152, 211)},
428 {"lightyellow", myRGB(255, 255, 224)},
429 {"limegreen", myRGB(0, 175, 20)},
430 {"linen", myRGB(250, 240, 230)},
431 {"magenta", myRGB(255, 0, 255)},
432 {"maroon", myRGB(143, 0, 82)},
433 {"mediumaquamarine", myRGB(0, 147, 143)},
434 {"mediumblue", myRGB(50, 50, 204)},
435 {"mediumforestgreen", myRGB(50, 129, 75)},
436 {"mediumgoldenrod", myRGB(209, 193, 102)},
437 {"mediumorchid", myRGB(189, 82, 189)},
438 {"mediumpurple", myRGB(147, 112, 219)},
439 {"mediumseagreen", myRGB(52, 119, 102)},
440 {"mediumslateblue", myRGB(106, 106, 141)},
441 {"mediumspringgreen", myRGB(35, 142, 35)},
442 {"mediumturquoise", myRGB(0, 210, 210)},
443 {"mediumvioletred", myRGB(213, 32, 121)},
444 {"midnightblue", myRGB(47, 47, 100)},
445 {"mintcream", myRGB(245, 255, 250)},
446 {"mistyrose", myRGB(255, 228, 225)},
447 {"moccasin", myRGB(255, 228, 181)},
448 {"navajowhite", myRGB(255, 222, 173)},
449 {"navy", myRGB(35, 35, 117)},
450 {"navyblue", myRGB(35, 35, 117)},
451 {"oldlace", myRGB(253, 245, 230)},
452 {"olivedrab", myRGB(107, 142, 35)},
453 {"orange", myRGB(255, 135, 0)},
454 {"orangered", myRGB(255, 69, 0)},
455 {"orchid", myRGB(239, 132, 239)},
456 {"palegoldenrod", myRGB(238, 232, 170)},
457 {"palegreen", myRGB(115, 222, 120)},
458 {"paleturquoise", myRGB(175, 238, 238)},
459 {"palevioletred", myRGB(219, 112, 147)},
460 {"papayawhip", myRGB(255, 239, 213)},
461 {"peachpuff", myRGB(255, 218, 185)},
462 {"peru", myRGB(205, 133, 63)},
463 {"pink", myRGB(255, 181, 197)},
464 {"plum", myRGB(197, 72, 155)},
465 {"powderblue", myRGB(176, 224, 230)},
466 {"purple", myRGB(160, 32, 240)},
467 {"red", myRGB(255, 0, 0)},
468 {"rosybrown", myRGB(188, 143, 143)},
469 {"royalblue", myRGB(65, 105, 225)},
470 {"saddlebrown", myRGB(139, 69, 19)},
471 {"salmon", myRGB(233, 150, 122)},
472 {"sandybrown", myRGB(244, 164, 96)},
473 {"seagreen", myRGB(82, 149, 132)},
474 {"seashell", myRGB(255, 245, 238)},
475 {"sienna", myRGB(150, 82, 45)},
476 {"skyblue", myRGB(114, 159, 255)},
477 {"slateblue", myRGB(126, 136, 171)},
478 {"slategray", myRGB(112, 128, 144)},
479 {"snow", myRGB(255, 250, 250)},
480 {"springgreen", myRGB(65, 172, 65)},
481 {"steelblue", myRGB(84, 112, 170)},
482 {"tan", myRGB(222, 184, 135)},
483 {"thistle", myRGB(216, 191, 216)},
484 {"tomato", myRGB(255, 99, 71)},
485 {"transparent", myRGB(0, 0, 1)},
486 {"turquoise", myRGB(25, 204, 223)},
487 {"violet", myRGB(156, 62, 206)},
488 {"violetred", myRGB(243, 62, 150)},
489 {"wheat", myRGB(245, 222, 179)},
490 {"white", myRGB(255, 255, 255)},
491 {"whitesmoke", myRGB(245, 245, 245)},
492 {"yellow", myRGB(255, 255, 0)},
493 {"yellowgreen", myRGB(50, 216, 56)},
494 {NULL
, myRGB(0, 0, 0)}
496 static int numTheRGBRecords
= 234;
498 static unsigned char ParseHexadecimal(char digit1
, char digit2
)
500 unsigned char i1
, i2
;
503 i1
= digit1
- 'a' + 0x0A;
504 else if (digit1
>= 'A')
505 i1
= digit1
- 'A' + 0x0A;
509 i2
= digit2
- 'a' + 0x0A;
510 else if (digit2
>= 'A')
511 i2
= digit2
- 'A' + 0x0A;
514 return (0x10 * i1
+ i2
);
517 static bool GetRGBFromName(const char *inname
, bool *isNone
,
518 unsigned char *r
, unsigned char*g
, unsigned char *b
)
520 int left
, right
, middle
;
526 // Neither #rrggbb nor #rrrrggggbbbb are in database, we parse them directly
527 size_t inname_len
= strlen(inname
);
528 if ( *inname
== '#' && (inname_len
== 7 || inname_len
== 13))
530 size_t ofs
= (inname_len
== 7) ? 2 : 4;
531 *r
= ParseHexadecimal(inname
[1], inname
[2]);
532 *g
= ParseHexadecimal(inname
[1*ofs
+1], inname
[1*ofs
+2]);
533 *b
= ParseHexadecimal(inname
[2*ofs
+1], inname
[2*ofs
+2]);
538 name
= strdup(inname
);
540 // theRGBRecords[] has no names with spaces, and no grey, but a
543 // so first extract ' '
544 while ((p
= strchr(name
, ' ')) != NULL
)
546 while (*(p
)) // till eof of string
548 *p
= *(p
+ 1); // copy to the left
552 // fold to lower case
560 // substitute Grey with Gray, else rgbtab.h would have more than 100
561 // 'duplicate' entries
562 if ( (grey
= strstr(name
, "grey")) != NULL
)
565 // check for special 'none' colour:
567 if ( strcmp(name
, "none") == 0 )
578 right
= numTheRGBRecords
- 1;
581 middle
= (left
+ right
) / 2;
582 cmp
= strcmp(name
, theRGBRecords
[middle
].name
);
585 rgbVal
= theRGBRecords
[middle
].rgb
;
586 *r
= (unsigned char)((rgbVal
>> 16) & 0xFF);
587 *g
= (unsigned char)((rgbVal
>> 8) & 0xFF);
588 *b
= (unsigned char)((rgbVal
) & 0xFF);
601 } while (left
<= right
);
609 static const char *ParseColor(const char *data
)
611 static const char *targets
[] =
612 {"c ", "g ", "g4 ", "m ", "b ", "s ", NULL
};
618 for (i
= 0; targets
[i
] != NULL
; i
++)
621 for (q
= targets
[i
]; *r
!= '\0'; r
++)
625 if ( !isspace((int) (*(r
- 1))) )
641 class wxXPMColourMapData
: public wxObject
647 wxImage
wxXPMDecoder::ReadData(const char **xpm_data
)
651 unsigned width
, height
, colors_cnt
, chars_per_pixel
;
656 wxXPMColourMapData
*clr_data
;
657 wxHashTable
clr_tbl(wxKEY_STRING
);
660 * Read hints and initialize structures:
663 count
= sscanf(xpm_data
[0], "%u %u %u %u",
664 &width
, &height
, &colors_cnt
, &chars_per_pixel
);
665 if ( count
!= 4 || width
* height
* colors_cnt
== 0 )
667 wxLogError(_T("XPM: Not XPM data!"));
671 // VS: XPM color map this large would be insane, since XPMs are encoded with
672 // 92 possible values on each position, 92^64 is *way* larger space than
674 wxCHECK_MSG(chars_per_pixel
< 64, wxNullImage
, wxT("XPM colormaps this large not supported."));
676 img
.Create(width
, height
);
677 if ( !img
.Ok() ) return img
;
680 key
[chars_per_pixel
] = wxT('\0');
682 clr_tbl
.DeleteContents(TRUE
);
687 for (i
= 0; i
< colors_cnt
; i
++)
689 for (i_key
= 0; i_key
< chars_per_pixel
; i_key
++)
690 key
[i_key
] = (wxChar
)xpm_data
[1 + i
][i_key
];
691 clr_def
= ParseColor(xpm_data
[1 + i
]);
692 clr_data
= new wxXPMColourMapData
;
694 if ( clr_def
== NULL
)
696 wxLogError(_("XPM: malformed colour definition '%s'!"), xpm_data
[1+i
]);
697 clr_data
->R
= 255, clr_data
->G
= 0, clr_data
->B
= 255;
702 if ( !GetRGBFromName(clr_def
, &isNone
,
703 &clr_data
->R
, &clr_data
->G
, &clr_data
->B
) )
705 wxLogError(_("XPM: malformed colour definition '%s'!"), xpm_data
[1+i
]);
706 clr_data
->R
= 255, clr_data
->G
= 0, clr_data
->B
= 255;
713 img
.SetMaskColour(255, 0, 255);
715 clr_data
->R
= 255, clr_data
->G
= 0, clr_data
->B
= 255;
719 if ( hasMask
&& clr_data
->R
== 255 &&
720 clr_data
->G
== 0 && clr_data
->B
== 255 )
725 clr_tbl
.Put(key
, clr_data
);
732 unsigned char *img_data
= img
.GetData();
733 for (j
= 0; j
< height
; j
++)
735 for (i
= 0; i
< width
; i
++, img_data
+= 3)
737 for (i_key
= 0; i_key
< chars_per_pixel
; i_key
++)
738 key
[i_key
] = (wxChar
)xpm_data
[1 + colors_cnt
+ j
]
739 [chars_per_pixel
* i
+ i_key
];
740 clr_data
= (wxXPMColourMapData
*) clr_tbl
.Get(key
);
741 if ( clr_data
== NULL
)
743 wxLogError(_("XPM: Malformed pixel data!"));
747 img_data
[0] = clr_data
->R
;
748 img_data
[1] = clr_data
->G
;
749 img_data
[2] = clr_data
->B
;
757 #endif // wxUSE_IMAGE && wxUSE_XPM