Use spice-3d das1 source list for nowjalview/gui/DasSourceBrowser.java
[jalview.git] / src / org / biojava / dasobert / das / Xpm.java
1 //@(#) Xpm.java 1.9@(#)
2 //Copyright (c) 2001, Phil Brown, phil@bolthole.com
3 //licensed under GNU LGPL version 2
4
5 /* A library class to convert Xpm data into an image.
6  * It also has nice little utilities like converting
7  * color NAMES to rgb values (based on X11 rgb.txt)
8  *
9  * Note1: There might be a slight conflict of copyright,
10  *  If the rgb.txt data from the X11 distribution has nasty copyright
11  *  stuff attached to it. If so... my apologies to the X11 folk.
12  *
13  * This is an improved version, that is not hardcoded so much for
14  * "crossfire". It should hopefully handle all xpm types.
15  * If it doesnt, please send me email, with a sample xpm image
16  * that it fails under, and I'll try to fix it.
17  */
18 package org.biojava.dasobert.das;
19
20
21 import java.awt.Image;
22 import java.util.Hashtable;
23 import java.awt.Toolkit;
24 import java.awt.image.*;
25
26 //rgb data originally from
27 //! $XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp $
28
29
30
31 //Note: This class is huge, and has icky large static initializers.
32 //They are also ARRAY-based, which means poor lookup speed.
33 //While that is kinda annoying, it shouldn't be TOO bad.
34 //And it should greatly improve STARTUP time, which I consider
35 //at this point to be more important
36
37 public class Xpm
38 {
39     static String VersionString="Phil@bolthole.com Xpm v1.1";
40     static final int rgbents[][] = {
41             {255, 250, 250},
42             {248, 248, 255},
43             {248, 248, 255},
44             {245, 245, 245},
45             {245, 245, 245},
46             {220, 220, 220},
47             {255, 250, 240},
48             {255, 250, 240},
49             {253, 245, 230},
50             {253, 245, 230},
51             {250, 240, 230},
52             {250, 235, 215},
53             {250, 235, 215},
54             {255, 239, 213},
55             {255, 239, 213},
56             {255, 235, 205},
57             {255, 235, 205},
58             {255, 228, 196},
59             {255, 218, 185},
60             {255, 218, 185},
61             {255, 222, 173},
62             {255, 222, 173},
63             {255, 228, 181},
64             {255, 248, 220},
65             {255, 255, 240},
66             {255, 250, 205},
67             {255, 250, 205},
68             {255, 245, 238},
69             {240, 255, 240},
70             {245, 255, 250},
71             {245, 255, 250},
72             {240, 255, 255},
73             {240, 248, 255},
74             {240, 248, 255},
75             {230, 230, 250},
76             {255, 240, 245},
77             {255, 240, 245},
78             {255, 228, 225},
79             {255, 228, 225},
80             {255, 255, 255},
81             {  0,   0,   0},
82             { 47,  79,  79},
83             { 47,  79,  79},
84             { 47,  79,  79},
85             { 47,  79,  79},
86             {105, 105, 105},
87             {105, 105, 105},
88             {105, 105, 105},
89             {105, 105, 105},
90             {112, 128, 144},
91             {112, 128, 144},
92             {112, 128, 144},
93             {112, 128, 144},
94             {119, 136, 153},
95             {119, 136, 153},
96             {119, 136, 153},
97             {119, 136, 153},
98             {190, 190, 190},
99             {190, 190, 190},
100             {211, 211, 211},
101             {211, 211, 211},
102             {211, 211, 211},
103             {211, 211, 211},
104             { 25,  25, 112},
105             { 25,  25, 112},
106             {  0,   0, 128},
107             {  0,   0, 128},
108             {  0,   0, 128},
109             {100, 149, 237},
110             {100, 149, 237},
111             { 72,  61, 139},
112             { 72,  61, 139},
113             {106,  90, 205},
114             {106,  90, 205},
115             {123, 104, 238},
116             {123, 104, 238},
117             {132, 112, 255},
118             {132, 112, 255},
119             {  0,   0, 205},
120             {  0,   0, 205},
121             { 65, 105, 225},
122             { 65, 105, 225},
123             {  0,   0, 255},
124             { 30, 144, 255},
125             { 30, 144, 255},
126             {  0, 191, 255},
127             {  0, 191, 255},
128             {135, 206, 235},
129             {135, 206, 235},
130             {135, 206, 250},
131             {135, 206, 250},
132             { 70, 130, 180},
133             { 70, 130, 180},
134             {176, 196, 222},
135             {176, 196, 222},
136             {173, 216, 230},
137             {173, 216, 230},
138             {176, 224, 230},
139             {176, 224, 230},
140             {175, 238, 238},
141             {175, 238, 238},
142             {  0, 206, 209},
143             {  0, 206, 209},
144             { 72, 209, 204},
145             { 72, 209, 204},
146             { 64, 224, 208},
147             {  0, 255, 255},
148             {224, 255, 255},
149             {224, 255, 255},
150             { 95, 158, 160},
151             { 95, 158, 160},
152             {102, 205, 170},
153             {102, 205, 170},
154             {127, 255, 212},
155             {  0, 100,   0},
156             {  0, 100,   0},
157             { 85, 107,  47},
158             { 85, 107,  47},
159             {143, 188, 143},
160             {143, 188, 143},
161             { 46, 139,  87},
162             { 46, 139,  87},
163             { 60, 179, 113},
164             { 60, 179, 113},
165             { 32, 178, 170},
166             { 32, 178, 170},
167             {152, 251, 152},
168             {152, 251, 152},
169             {  0, 255, 127},
170             {  0, 255, 127},
171             {124, 252,   0},
172             {124, 252,   0},
173             {  0, 255,   0},
174             {127, 255,   0},
175             {  0, 250, 154},
176             {  0, 250, 154},
177             {173, 255,  47},
178             {173, 255,  47},
179             { 50, 205,  50},
180             { 50, 205,  50},
181             {154, 205,  50},
182             {154, 205,  50},
183             { 34, 139,  34},
184             { 34, 139,  34},
185             {107, 142,  35},
186             {107, 142,  35},
187             {189, 183, 107},
188             {189, 183, 107},
189             {240, 230, 140},
190             {238, 232, 170},
191             {238, 232, 170},
192             {250, 250, 210},
193             {250, 250, 210},
194             {255, 255, 224},
195             {255, 255, 224},
196             {255, 255,   0},
197             {255, 215,   0},
198             {238, 221, 130},
199             {238, 221, 130},
200             {218, 165,  32},
201             {184, 134,  11},
202             {184, 134,  11},
203             {188, 143, 143},
204             {188, 143, 143},
205             {205,  92,  92},
206             {205,  92,  92},
207             {139,  69,  19},
208             {139,  69,  19},
209             {160,  82,  45},
210             {205, 133,  63},
211             {222, 184, 135},
212             {245, 245, 220},
213             {245, 222, 179},
214             {244, 164,  96},
215             {244, 164,  96},
216             {210, 180, 140},
217             {210, 105,  30},
218             {178,  34,  34},
219             {165,  42,  42},
220             {233, 150, 122},
221             {233, 150, 122},
222             {250, 128, 114},
223             {255, 160, 122},
224             {255, 160, 122},
225             {255, 165,   0},
226             {255, 140,   0},
227             {255, 140,   0},
228             {255, 127,  80},
229             {240, 128, 128},
230             {240, 128, 128},
231             {255,  99,  71},
232             {255,  69,   0},
233             {255,  69,   0},
234             {255,   0,   0},
235             {255, 105, 180},
236             {255, 105, 180},
237             {255,  20, 147},
238             {255,  20, 147},
239             {255, 192, 203},
240             {255, 182, 193},
241             {255, 182, 193},
242             {219, 112, 147},
243             {219, 112, 147},
244             {176,  48,  96},
245             {199,  21, 133},
246             {199,  21, 133},
247             {208,  32, 144},
248             {208,  32, 144},
249             {255,   0, 255},
250             {238, 130, 238},
251             {221, 160, 221},
252             {218, 112, 214},
253             {186,  85, 211},
254             {186,  85, 211},
255             {153,  50, 204},
256             {153,  50, 204},
257             {148,   0, 211},
258             {148,   0, 211},
259             {138,  43, 226},
260             {138,  43, 226},
261             {160,  32, 240},
262             {147, 112, 219},
263             {147, 112, 219},
264             {216, 191, 216},
265             {255, 250, 250},
266             {238, 233, 233},
267             {205, 201, 201},
268             {139, 137, 137},
269             {255, 245, 238},
270             {238, 229, 222},
271             {205, 197, 191},
272             {139, 134, 130},
273             {255, 239, 219},
274             {238, 223, 204},
275             {205, 192, 176},
276             {139, 131, 120},
277             {255, 228, 196},
278             {238, 213, 183},
279             {205, 183, 158},
280             {139, 125, 107},
281             {255, 218, 185},
282             {238, 203, 173},
283             {205, 175, 149},
284             {139, 119, 101},
285             {255, 222, 173},
286             {238, 207, 161},
287             {205, 179, 139},
288             {139, 121, 94},
289             {255, 250, 205},
290             {238, 233, 191},
291             {205, 201, 165},
292             {139, 137, 112},
293             {255, 248, 220},
294             {238, 232, 205},
295             {205, 200, 177},
296             {139, 136, 120},
297             {255, 255, 240},
298             {238, 238, 224},
299             {205, 205, 193},
300             {139, 139, 131},
301             {240, 255, 240},
302             {224, 238, 224},
303             {193, 205, 193},
304             {131, 139, 131},
305             {255, 240, 245},
306             {238, 224, 229},
307             {205, 193, 197},
308             {139, 131, 134},
309             {255, 228, 225},
310             {238, 213, 210},
311             {205, 183, 181},
312             {139, 125, 123},
313             {240, 255, 255},
314             {224, 238, 238},
315             {193, 205, 205},
316             {131, 139, 139},
317             {131, 111, 255},
318             {122, 103, 238},
319             {105,  89, 205},
320             { 71,  60, 139},
321             { 72, 118, 255},
322             { 67, 110, 238},
323             { 58,  95, 205},
324             { 39,  64, 139},
325             {  0,   0, 255},
326             {  0,   0, 238},
327             {  0,   0, 205},
328             {  0,   0, 139},
329             { 30, 144, 255},
330             { 28, 134, 238},
331             { 24, 116, 205},
332             { 16,  78, 139},
333             { 99, 184, 255},
334             { 92, 172, 238},
335             { 79, 148, 205},
336             { 54, 100, 139},
337             {  0, 191, 255},
338             {  0, 178, 238},
339             {  0, 154, 205},
340             {  0, 104, 139},
341             {135, 206, 255},
342             {126, 192, 238},
343             {108, 166, 205},
344             { 74, 112, 139},
345             {176, 226, 255},
346             {164, 211, 238},
347             {141, 182, 205},
348             { 96, 123, 139},
349             {198, 226, 255},
350             {185, 211, 238},
351             {159, 182, 205},
352             {108, 123, 139},
353             {202, 225, 255},
354             {188, 210, 238},
355             {162, 181, 205},
356             {110, 123, 139},
357             {191, 239, 255},
358             {178, 223, 238},
359             {154, 192, 205},
360             {104, 131, 139},
361             {224, 255, 255},
362             {209, 238, 238},
363             {180, 205, 205},
364             {122, 139, 139},
365             {187, 255, 255},
366             {174, 238, 238},
367             {150, 205, 205},
368             {102, 139, 139},
369             {152, 245, 255},
370             {142, 229, 238},
371             {122, 197, 205},
372             { 83, 134, 139},
373             {  0, 245, 255},
374             {  0, 229, 238},
375             {  0, 197, 205},
376             {  0, 134, 139},
377             {  0, 255, 255},
378             {  0, 238, 238},
379             {  0, 205, 205},
380             {  0, 139, 139},
381             {151, 255, 255},
382             {141, 238, 238},
383             {121, 205, 205},
384             { 82, 139, 139},
385             {127, 255, 212},
386             {118, 238, 198},
387             {102, 205, 170},
388             { 69, 139, 116},
389             {193, 255, 193},
390             {180, 238, 180},
391             {155, 205, 155},
392             {105, 139, 105},
393             { 84, 255, 159},
394             { 78, 238, 148},
395             { 67, 205, 128},
396             { 46, 139, 87},
397             {154, 255, 154},
398             {144, 238, 144},
399             {124, 205, 124},
400             { 84, 139, 84},
401             {  0, 255, 127},
402             {  0, 238, 118},
403             {  0, 205, 102},
404             {  0, 139, 69},
405             {  0, 255,  0},
406             {  0, 238,  0},
407             {  0, 205,  0},
408             {  0, 139,  0},
409             {127, 255,  0},
410             {118, 238,  0},
411             {102, 205,  0},
412             { 69, 139,  0},
413             {192, 255, 62},
414             {179, 238, 58},
415             {154, 205, 50},
416             {105, 139, 34},
417             {202, 255, 112},
418             {188, 238, 104},
419             {162, 205, 90},
420             {110, 139, 61},
421             {255, 246, 143},
422             {238, 230, 133},
423             {205, 198, 115},
424             {139, 134, 78},
425             {255, 236, 139},
426             {238, 220, 130},
427             {205, 190, 112},
428             {139, 129, 76},
429             {255, 255, 224},
430             {238, 238, 209},
431             {205, 205, 180},
432             {139, 139, 122},
433             {255, 255,  0},
434             {238, 238,  0},
435             {205, 205,  0},
436             {139, 139,  0},
437             {255, 215,  0},
438             {238, 201,  0},
439             {205, 173,  0},
440             {139, 117,  0},
441             {255, 193, 37},
442             {238, 180, 34},
443             {205, 155, 29},
444             {139, 105, 20},
445             {255, 185, 15},
446             {238, 173, 14},
447             {205, 149, 12},
448             {139, 101,  8},
449             {255, 193, 193},
450             {238, 180, 180},
451             {205, 155, 155},
452             {139, 105, 105},
453             {255, 106, 106},
454             {238,  99, 99},
455             {205,  85, 85},
456             {139,  58, 58},
457             {255, 130, 71},
458             {238, 121, 66},
459             {205, 104, 57},
460             {139,  71, 38},
461             {255, 211, 155},
462             {238, 197, 145},
463             {205, 170, 125},
464             {139, 115, 85},
465             {255, 231, 186},
466             {238, 216, 174},
467             {205, 186, 150},
468             {139, 126, 102},
469             {255, 165, 79},
470             {238, 154, 73},
471             {205, 133, 63},
472             {139,  90, 43},
473             {255, 127, 36},
474             {238, 118, 33},
475             {205, 102, 29},
476             {139,  69, 19},
477             {255,  48, 48},
478             {238,  44, 44},
479             {205,  38, 38},
480             {139,  26, 26},
481             {255,  64, 64},
482             {238,  59, 59},
483             {205,  51, 51},
484             {139,  35, 35},
485             {255, 140, 105},
486             {238, 130,   98},
487             {205, 112,   84},
488             {139,  76,   57},
489             {255, 160, 122},
490             {238, 149, 114},
491             {205, 129,   98},
492             {139,  87,   66},
493             {255, 165,    0},
494             {238, 154,    0},
495             {205, 133,    0},
496             {139,  90,    0},
497             {255, 127,    0},
498             {238, 118,    0},
499             {205, 102,    0},
500             {139,  69,    0},
501             {255, 114,   86},
502             {238, 106,   80},
503             {205,  91,   69},
504             {139,  62,   47},
505             {255,  99,   71},
506             {238,  92,   66},
507             {205,  79,   57},
508             {139,  54,   38},
509             {255,  69,    0},
510             {238,  64,    0},
511             {205,  55,    0},
512             {139,  37,    0},
513             {255,   0,    0},
514             {238,   0,    0},
515             {205,   0,    0},
516             {139,   0,    0},
517             {255,  20, 147},
518             {238,  18, 137},
519             {205,  16, 118},
520             {139,  10,   80},
521             {255, 110, 180},
522             {238, 106, 167},
523             {205,  96, 144},
524             {139,  58,  98},
525             {255, 181, 197},
526             {238, 169, 184},
527             {205, 145, 158},
528             {139,  99, 108},
529             {255, 174, 185},
530             {238, 162, 173},
531             {205, 140, 149},
532             {139,  95, 101},
533             {255, 130, 171},
534             {238, 121, 159},
535             {205, 104, 137},
536             {139,  71,   93},
537             {255,  52, 179},
538             {238,  48, 167},
539             {205,  41, 144},
540             {139,  28,   98},
541             {255,  62, 150},
542             {238,  58, 140},
543             {205,  50, 120},
544             {139,  34,   82},
545             {255,   0, 255},
546             {238,   0, 238},
547             {205,   0, 205},
548             {139,   0, 139},
549             {255, 131, 250},
550             {238, 122, 233},
551             {205, 105, 201},
552             {139,  71, 137},
553             {255, 187, 255},
554             {238, 174, 238},
555             {205, 150, 205},
556             {139, 102, 139},
557             {224, 102, 255},
558             {209,  95, 238},
559             {180,  82, 205},
560             {122,  55, 139},
561             {191,  62, 255},
562             {178,  58, 238},
563             {154,  50, 205},
564             {104,  34, 139},
565             {155,  48, 255},
566             {145,  44, 238},
567             {125,  38, 205},
568             { 85,  26, 139},
569             {171, 130, 255},
570             {159, 121, 238},
571             {137, 104, 205},
572             { 93,  71, 139},
573             {255, 225, 255},
574             {238, 210, 238},
575             {205, 181, 205},
576             {139, 123, 139},
577             {  0,   0,   0},
578             {  0,   0,   0},
579             {  3,   3,   3},
580             {  3,   3,   3},
581             {  5,   5,   5},
582             {  5,   5,   5},
583             {  8,   8,   8},
584             {  8,   8,   8},
585             { 10,  10,  10},
586             { 10,  10,  10},
587             { 13,  13,  13},
588             { 13,  13,  13},
589             { 15,  15,  15},
590             { 15,  15,  15},
591             { 18,  18,  18},
592             { 18,  18,  18},
593             { 20,  20,  20},
594             { 20,  20,  20},
595             { 23,  23,  23},
596             { 23,  23,  23},
597             { 26,  26,  26},
598             { 26,  26,  26},
599             { 28,  28,  28},
600             { 28,  28,  28},
601             { 31,  31,  31},
602             { 31,  31,  31},
603             { 33,  33,  33},
604             { 33,  33,  33},
605             { 36,  36,  36},
606             { 36,  36,  36},
607             { 38,  38,  38},
608             { 38,  38,  38},
609             { 41,  41,  41},
610             { 41,  41,  41},
611             { 43,  43,  43},
612             { 43,  43,  43},
613             { 46,  46,  46},
614             { 46,  46,  46},
615             { 48,  48,  48},
616             { 48,  48,  48},
617             { 51,  51,  51},
618             { 51,  51,  51},
619             { 54,  54,  54},
620             { 54,  54,  54},
621             { 56,  56,  56},
622             { 56,  56,  56},
623             { 59,  59,  59},
624             { 59,  59,  59},
625             { 61,  61,  61},
626             { 61,  61,  61},
627             { 64,  64,  64},
628             { 64,  64,  64},
629             { 66,  66,  66},
630             { 66,  66,  66},
631             { 69,  69,  69},
632             { 69,  69,  69},
633             { 71,  71,  71},
634             { 71,  71,  71},
635             { 74,  74,  74},
636             { 74,  74,  74},
637             { 77,  77,  77},
638             { 77,  77,  77},
639             { 79,  79,  79},
640             { 79,  79,  79},
641             { 82,  82,  82},
642             { 82,  82,  82},
643             { 84,  84,  84},
644             { 84,  84,  84},
645             { 87,  87,  87},
646             { 87,  87,  87},
647             { 89,  89,  89},
648             { 89,  89,  89},
649             { 92,  92,  92},
650             { 92,  92,  92},
651             { 94,  94,  94},
652             { 94,  94,  94},
653             { 97,  97,  97},
654             { 97,  97,  97},
655             { 99,  99,  99},
656             { 99,  99,  99},
657             {102, 102, 102},
658             {102, 102, 102},
659             {105, 105, 105},
660             {105, 105, 105},
661             {107, 107, 107},
662             {107, 107, 107},
663             {110, 110, 110},
664             {110, 110, 110},
665             {112, 112, 112},
666             {112, 112, 112},
667             {115, 115, 115},
668             {115, 115, 115},
669             {117, 117, 117},
670             {117, 117, 117},
671             {120, 120, 120},
672             {120, 120, 120},
673             {122, 122, 122},
674             {122, 122, 122},
675             {125, 125, 125},
676             {125, 125, 125},
677             {127, 127, 127},
678             {127, 127, 127},
679             {130, 130, 130},
680             {130, 130, 130},
681             {133, 133, 133},
682             {133, 133, 133},
683             {135, 135, 135},
684             {135, 135, 135},
685             {138, 138, 138},
686             {138, 138, 138},
687             {140, 140, 140},
688             {140, 140, 140},
689             {143, 143, 143},
690             {143, 143, 143},
691             {145, 145, 145},
692             {145, 145, 145},
693             {148, 148, 148},
694             {148, 148, 148},
695             {150, 150, 150},
696             {150, 150, 150},
697             {153, 153, 153},
698             {153, 153, 153},
699             {156, 156, 156},
700             {156, 156, 156},
701             {158, 158, 158},
702             {158, 158, 158},
703             {161, 161, 161},
704             {161, 161, 161},
705             {163, 163, 163},
706             {163, 163, 163},
707             {166, 166, 166},
708             {166, 166, 166},
709             {168, 168, 168},
710             {168, 168, 168},
711             {171, 171, 171},
712             {171, 171, 171},
713             {173, 173, 173},
714             {173, 173, 173},
715             {176, 176, 176},
716             {176, 176, 176},
717             {179, 179, 179},
718             {179, 179, 179},
719             {181, 181, 181},
720             {181, 181, 181},
721             {184, 184, 184},
722             {184, 184, 184},
723             {186, 186, 186},
724             {186, 186, 186},
725             {189, 189, 189},
726             {189, 189, 189},
727             {191, 191, 191},
728             {191, 191, 191},
729             {194, 194, 194},
730             {194, 194, 194},
731             {196, 196, 196},
732             {196, 196, 196},
733             {199, 199, 199},
734             {199, 199, 199},
735             {201, 201, 201},
736             {201, 201, 201},
737             {204, 204, 204},
738             {204, 204, 204},
739             {207, 207, 207},
740             {207, 207, 207},
741             {209, 209, 209},
742             {209, 209, 209},
743             {212, 212, 212},
744             {212, 212, 212},
745             {214, 214, 214},
746             {214, 214, 214},
747             {217, 217, 217},
748             {217, 217, 217},
749             {219, 219, 219},
750             {219, 219, 219},
751             {222, 222, 222},
752             {222, 222, 222},
753             {224, 224, 224},
754             {224, 224, 224},
755             {227, 227, 227},
756             {227, 227, 227},
757             {229, 229, 229},
758             {229, 229, 229},
759             {232, 232, 232},
760             {232, 232, 232},
761             {235, 235, 235},
762             {235, 235, 235},
763             {237, 237, 237},
764             {237, 237, 237},
765             {240, 240, 240},
766             {240, 240, 240},
767             {242, 242, 242},
768             {242, 242, 242},
769             {245, 245, 245},
770             {245, 245, 245},
771             {247, 247, 247},
772             {247, 247, 247},
773             {250, 250, 250},
774             {250, 250, 250},
775             {252, 252, 252},
776             {252, 252, 252},
777             {255, 255, 255},
778             {255, 255, 255},
779             {169, 169, 169},
780             {169, 169, 169},
781             {169, 169, 169},
782             {169, 169, 169},
783             {0,     0, 139},
784             {0,     0, 139},
785             {0,   139, 139},
786             {0,   139, 139},
787             {139,   0, 139},
788             {139,   0, 139},
789             {139,   0,   0},
790             {139,   0,   0},
791             {144, 238, 144},
792             {144, 238, 144}
793     };
794     
795     static String rgbnames[] = {
796             "snow",
797             "ghost white",
798             "GhostWhite",
799             "white smoke",
800             "WhiteSmoke",
801             "gainsboro",
802             "floral white",
803             "FloralWhite",
804             "old lace",
805             "OldLace",
806             "linen",
807             "antique white",
808             "AntiqueWhite",
809             "papaya whip",
810             "PapayaWhip",
811             "blanched almond",
812             "BlanchedAlmond",
813             "bisque",
814             "peach puff",
815             "PeachPuff",
816             "navajo white",
817             "NavajoWhite",
818             "moccasin",
819             "cornsilk",
820             "ivory",
821             "lemon chiffon",
822             "LemonChiffon",
823             "seashell",
824             "honeydew",
825             "mint cream",
826             "MintCream",
827             "azure",
828             "alice blue",
829             "AliceBlue",
830             "lavender",
831             "lavender blush",
832             "LavenderBlush",
833             "misty rose",
834             "MistyRose",
835             "white",
836             "black",
837             "dark slate gray",
838             "DarkSlateGray",
839             "dark slate grey",
840             "DarkSlateGrey",
841             "dim gray",
842             "DimGray",
843             "dim grey",
844             "DimGrey",
845             "slate gray",
846             "SlateGray",
847             "slate grey",
848             "SlateGrey",
849             "light slate gray",
850             "LightSlateGray",
851             "light slate grey",
852             "LightSlateGrey",
853             "gray",
854             "grey",
855             "light grey",
856             "LightGrey",
857             "light gray",
858             "LightGray",
859             "midnight blue",
860             "MidnightBlue",
861             "navy",
862             "navy blue",
863             "NavyBlue",
864             "cornflower blue",
865             "CornflowerBlue",
866             "dark slate blue",
867             "DarkSlateBlue",
868             "slate blue",
869             "SlateBlue",
870             "medium slate blue",
871             "MediumSlateBlue",
872             "light slate blue",
873             "LightSlateBlue",
874             "medium blue",
875             "MediumBlue",
876             "royal blue",
877             "RoyalBlue",
878             "blue",
879             "dodger blue",
880             "DodgerBlue",
881             "deep sky blue",
882             "DeepSkyBlue",
883             "sky blue",
884             "SkyBlue",
885             "light sky blue",
886             "LightSkyBlue",
887             "steel blue",
888             "SteelBlue",
889             "light steel blue",
890             "LightSteelBlue",
891             "light blue",
892             "LightBlue",
893             "powder blue",
894             "PowderBlue",
895             "pale turquoise",
896             "PaleTurquoise",
897             "dark turquoise",
898             "DarkTurquoise",
899             "medium turquoise",
900             "MediumTurquoise",
901             "turquoise",
902             "cyan",
903             "light cyan",
904             "LightCyan",
905             "cadet blue",
906             "CadetBlue",
907             "medium aquamarine",
908             "MediumAquamarine",
909             "aquamarine",
910             "dark green",
911             "DarkGreen",
912             "dark olive green",
913             "DarkOliveGreen",
914             "dark sea green",
915             "DarkSeaGreen",
916             "sea green",
917             "SeaGreen",
918             "medium sea green",
919             "MediumSeaGreen",
920             "light sea green",
921             "LightSeaGreen",
922             "pale green",
923             "PaleGreen",
924             "spring green",
925             "SpringGreen",
926             "lawn green",
927             "LawnGreen",
928             "green",
929             "chartreuse",
930             "medium spring green",
931             "MediumSpringGreen",
932             "green yellow",
933             "GreenYellow",
934             "lime green",
935             "LimeGreen",
936             "yellow green",
937             "YellowGreen",
938             "forest green",
939             "ForestGreen",
940             "olive drab",
941             "OliveDrab",
942             "dark khaki",
943             "DarkKhaki",
944             "khaki",
945             "pale goldenrod",
946             "PaleGoldenrod",
947             "light goldenrod yellow",
948             "LightGoldenrodYellow",
949             "light yellow",
950             "LightYellow",
951             "yellow",
952             "gold",
953             "light goldenrod",
954             "LightGoldenrod",
955             "goldenrod",
956             "dark goldenrod",
957             "DarkGoldenrod",
958             "rosy brown",
959             "RosyBrown",
960             "indian red",
961             "IndianRed",
962             "saddle brown",
963             "SaddleBrown",
964             "sienna",
965             "peru",
966             "burlywood",
967             "beige",
968             "wheat",
969             "sandy brown",
970             "SandyBrown",
971             "tan",
972             "chocolate",
973             "firebrick",
974             "brown",
975             "dark salmon",
976             "DarkSalmon",
977             "salmon",
978             "light salmon",
979             "LightSalmon",
980             "orange",
981             "dark orange",
982             "DarkOrange",
983             "coral",
984             "light coral",
985             "LightCoral",
986             "tomato",
987             "orange red",
988             "OrangeRed",
989             "red",
990             "hot pink",
991             "HotPink",
992             "deep pink",
993             "DeepPink",
994             "pink",
995             "light pink",
996             "LightPink",
997             "pale violet red",
998             "PaleVioletRed",
999             "maroon",
1000             "medium violet red",
1001             "MediumVioletRed",
1002             "violet red",
1003             "VioletRed",
1004             "magenta",
1005             "violet",
1006             "plum",
1007             "orchid",
1008             "medium orchid",
1009             "MediumOrchid",
1010             "dark orchid",
1011             "DarkOrchid",
1012             "dark violet",
1013             "DarkViolet",
1014             "blue violet",
1015             "BlueViolet",
1016             "purple",
1017             "medium purple",
1018             "MediumPurple",
1019             "thistle",
1020             "snow1",
1021             "snow2",
1022             "snow3",
1023             "snow4",
1024             "seashell1",
1025             "seashell2",
1026             "seashell3",
1027             "seashell4",
1028             "AntiqueWhite1",
1029             "AntiqueWhite2",
1030             "AntiqueWhite3",
1031             "AntiqueWhite4",
1032             "bisque1",
1033             "bisque2",
1034             "bisque3",
1035             "bisque4",
1036             "PeachPuff1",
1037             "PeachPuff2",
1038             "PeachPuff3",
1039             "PeachPuff4",
1040             "NavajoWhite1",
1041             "NavajoWhite2",
1042             "NavajoWhite3",
1043             "NavajoWhite4",
1044             "LemonChiffon1",
1045             "LemonChiffon2",
1046             "LemonChiffon3",
1047             "LemonChiffon4",
1048             "cornsilk1",
1049             "cornsilk2",
1050             "cornsilk3",
1051             "cornsilk4",
1052             "ivory1",
1053             "ivory2",
1054             "ivory3",
1055             "ivory4",
1056             "honeydew1",
1057             "honeydew2",
1058             "honeydew3",
1059             "honeydew4",
1060             "LavenderBlush1",
1061             "LavenderBlush2",
1062             "LavenderBlush3",
1063             "LavenderBlush4",
1064             "MistyRose1",
1065             "MistyRose2",
1066             "MistyRose3",
1067             "MistyRose4",
1068             "azure1",
1069             "azure2",
1070             "azure3",
1071             "azure4",
1072             "SlateBlue1",
1073             "SlateBlue2",
1074             "SlateBlue3",
1075             "SlateBlue4",
1076             "RoyalBlue1",
1077             "RoyalBlue2",
1078             "RoyalBlue3",
1079             "RoyalBlue4",
1080             "blue1",
1081             "blue2",
1082             "blue3",
1083             "blue4",
1084             "DodgerBlue1",
1085             "DodgerBlue2",
1086             "DodgerBlue3",
1087             "DodgerBlue4",
1088             "SteelBlue1",
1089             "SteelBlue2",
1090             "SteelBlue3",
1091             "SteelBlue4",
1092             "DeepSkyBlue1",
1093             "DeepSkyBlue2",
1094             "DeepSkyBlue3",
1095             "DeepSkyBlue4",
1096             "SkyBlue1",
1097             "SkyBlue2",
1098             "SkyBlue3",
1099             "SkyBlue4",
1100             "LightSkyBlue1",
1101             "LightSkyBlue2",
1102             "LightSkyBlue3",
1103             "LightSkyBlue4",
1104             "SlateGray1",
1105             "SlateGray2",
1106             "SlateGray3",
1107             "SlateGray4",
1108             "LightSteelBlue1",
1109             "LightSteelBlue2",
1110             "LightSteelBlue3",
1111             "LightSteelBlue4",
1112             "LightBlue1",
1113             "LightBlue2",
1114             "LightBlue3",
1115             "LightBlue4",
1116             "LightCyan1",
1117             "LightCyan2",
1118             "LightCyan3",
1119             "LightCyan4",
1120             "PaleTurquoise1",
1121             "PaleTurquoise2",
1122             "PaleTurquoise3",
1123             "PaleTurquoise4",
1124             "CadetBlue1",
1125             "CadetBlue2",
1126             "CadetBlue3",
1127             "CadetBlue4",
1128             "turquoise1",
1129             "turquoise2",
1130             "turquoise3",
1131             "turquoise4",
1132             "cyan1",
1133             "cyan2",
1134             "cyan3",
1135             "cyan4",
1136             "DarkSlateGray1",
1137             "DarkSlateGray2",
1138             "DarkSlateGray3",
1139             "DarkSlateGray4",
1140             "aquamarine1",
1141             "aquamarine2",
1142             "aquamarine3",
1143             "aquamarine4",
1144             "DarkSeaGreen1",
1145             "DarkSeaGreen2",
1146             "DarkSeaGreen3",
1147             "DarkSeaGreen4",
1148             "SeaGreen1",
1149             "SeaGreen2",
1150             "SeaGreen3",
1151             "SeaGreen4",
1152             "PaleGreen1",
1153             "PaleGreen2",
1154             "PaleGreen3",
1155             "PaleGreen4",
1156             "SpringGreen1",
1157             "SpringGreen2",
1158             "SpringGreen3",
1159             "SpringGreen4",
1160             "green1",
1161             "green2",
1162             "green3",
1163             "green4",
1164             "chartreuse1",
1165             "chartreuse2",
1166             "chartreuse3",
1167             "chartreuse4",
1168             "OliveDrab1",
1169             "OliveDrab2",
1170             "OliveDrab3",
1171             "OliveDrab4",
1172             "DarkOliveGreen1",
1173             "DarkOliveGreen2",
1174             "DarkOliveGreen3",
1175             "DarkOliveGreen4",
1176             "khaki1",
1177             "khaki2",
1178             "khaki3",
1179             "khaki4",
1180             "LightGoldenrod1",
1181             "LightGoldenrod2",
1182             "LightGoldenrod3",
1183             "LightGoldenrod4",
1184             "LightYellow1",
1185             "LightYellow2",
1186             "LightYellow3",
1187             "LightYellow4",
1188             "yellow1",
1189             "yellow2",
1190             "yellow3",
1191             "yellow4",
1192             "gold1",
1193             "gold2",
1194             "gold3",
1195             "gold4",
1196             "goldenrod1",
1197             "goldenrod2",
1198             "goldenrod3",
1199             "goldenrod4",
1200             "DarkGoldenrod1",
1201             "DarkGoldenrod2",
1202             "DarkGoldenrod3",
1203             "DarkGoldenrod4",
1204             "RosyBrown1",
1205             "RosyBrown2",
1206             "RosyBrown3",
1207             "RosyBrown4",
1208             "IndianRed1",
1209             "IndianRed2",
1210             "IndianRed3",
1211             "IndianRed4",
1212             "sienna1",
1213             "sienna2",
1214             "sienna3",
1215             "sienna4",
1216             "burlywood1",
1217             "burlywood2",
1218             "burlywood3",
1219             "burlywood4",
1220             "wheat1",
1221             "wheat2",
1222             "wheat3",
1223             "wheat4",
1224             "tan1",
1225             "tan2",
1226             "tan3",
1227             "tan4",
1228             "chocolate1",
1229             "chocolate2",
1230             "chocolate3",
1231             "chocolate4",
1232             "firebrick1",
1233             "firebrick2",
1234             "firebrick3",
1235             "firebrick4",
1236             "brown1",
1237             "brown2",
1238             "brown3",
1239             "brown4",
1240             "salmon1",
1241             "salmon2",
1242             "salmon3",
1243             "salmon4",
1244             "LightSalmon1",
1245             "LightSalmon2",
1246             "LightSalmon3",
1247             "LightSalmon4",
1248             "orange1",
1249             "orange2",
1250             "orange3",
1251             "orange4",
1252             "DarkOrange1",
1253             "DarkOrange2",
1254             "DarkOrange3",
1255             "DarkOrange4",
1256             "coral1",
1257             "coral2",
1258             "coral3",
1259             "coral4",
1260             "tomato1",
1261             "tomato2",
1262             "tomato3",
1263             "tomato4",
1264             "OrangeRed1",
1265             "OrangeRed2",
1266             "OrangeRed3",
1267             "OrangeRed4",
1268             "red1",
1269             "red2",
1270             "red3",
1271             "red4",
1272             "DeepPink1",
1273             "DeepPink2",
1274             "DeepPink3",
1275             "DeepPink4",
1276             "HotPink1",
1277             "HotPink2",
1278             "HotPink3",
1279             "HotPink4",
1280             "pink1",
1281             "pink2",
1282             "pink3",
1283             "pink4",
1284             "LightPink1",
1285             "LightPink2",
1286             "LightPink3",
1287             "LightPink4",
1288             "PaleVioletRed1",
1289             "PaleVioletRed2",
1290             "PaleVioletRed3",
1291             "PaleVioletRed4",
1292             "maroon1",
1293             "maroon2",
1294             "maroon3",
1295             "maroon4",
1296             "VioletRed1",
1297             "VioletRed2",
1298             "VioletRed3",
1299             "VioletRed4",
1300             "magenta1",
1301             "magenta2",
1302             "magenta3",
1303             "magenta4",
1304             "orchid1",
1305             "orchid2",
1306             "orchid3",
1307             "orchid4",
1308             "plum1",
1309             "plum2",
1310             "plum3",
1311             "plum4",
1312             "MediumOrchid1",
1313             "MediumOrchid2",
1314             "MediumOrchid3",
1315             "MediumOrchid4",
1316             "DarkOrchid1",
1317             "DarkOrchid2",
1318             "DarkOrchid3",
1319             "DarkOrchid4",
1320             "purple1",
1321             "purple2",
1322             "purple3",
1323             "purple4",
1324             "MediumPurple1",
1325             "MediumPurple2",
1326             "MediumPurple3",
1327             "MediumPurple4",
1328             "thistle1",
1329             "thistle2",
1330             "thistle3",
1331             "thistle4",
1332             "gray0",
1333             "grey0",
1334             "gray1",
1335             "grey1",
1336             "gray2",
1337             "grey2",
1338             "gray3",
1339             "grey3",
1340             "gray4",
1341             "grey4",
1342             "gray5",
1343             "grey5",
1344             "gray6",
1345             "grey6",
1346             "gray7",
1347             "grey7",
1348             "gray8",
1349             "grey8",
1350             "gray9",
1351             "grey9",
1352             "gray10",
1353             "grey10",
1354             "gray11",
1355             "grey11",
1356             "gray12",
1357             "grey12",
1358             "gray13",
1359             "grey13",
1360             "gray14",
1361             "grey14",
1362             "gray15",
1363             "grey15",
1364             "gray16",
1365             "grey16",
1366             "gray17",
1367             "grey17",
1368             "gray18",
1369             "grey18",
1370             "gray19",
1371             "grey19",
1372             "gray20",
1373             "grey20",
1374             "gray21",
1375             "grey21",
1376             "gray22",
1377             "grey22",
1378             "gray23",
1379             "grey23",
1380             "gray24",
1381             "grey24",
1382             "gray25",
1383             "grey25",
1384             "gray26",
1385             "grey26",
1386             "gray27",
1387             "grey27",
1388             "gray28",
1389             "grey28",
1390             "gray29",
1391             "grey29",
1392             "gray30",
1393             "grey30",
1394             "gray31",
1395             "grey31",
1396             "gray32",
1397             "grey32",
1398             "gray33",
1399             "grey33",
1400             "gray34",
1401             "grey34",
1402             "gray35",
1403             "grey35",
1404             "gray36",
1405             "grey36",
1406             "gray37",
1407             "grey37",
1408             "gray38",
1409             "grey38",
1410             "gray39",
1411             "grey39",
1412             "gray40",
1413             "grey40",
1414             "gray41",
1415             "grey41",
1416             "gray42",
1417             "grey42",
1418             "gray43",
1419             "grey43",
1420             "gray44",
1421             "grey44",
1422             "gray45",
1423             "grey45",
1424             "gray46",
1425             "grey46",
1426             "gray47",
1427             "grey47",
1428             "gray48",
1429             "grey48",
1430             "gray49",
1431             "grey49",
1432             "gray50",
1433             "grey50",
1434             "gray51",
1435             "grey51",
1436             "gray52",
1437             "grey52",
1438             "gray53",
1439             "grey53",
1440             "gray54",
1441             "grey54",
1442             "gray55",
1443             "grey55",
1444             "gray56",
1445             "grey56",
1446             "gray57",
1447             "grey57",
1448             "gray58",
1449             "grey58",
1450             "gray59",
1451             "grey59",
1452             "gray60",
1453             "grey60",
1454             "gray61",
1455             "grey61",
1456             "gray62",
1457             "grey62",
1458             "gray63",
1459             "grey63",
1460             "gray64",
1461             "grey64",
1462             "gray65",
1463             "grey65",
1464             "gray66",
1465             "grey66",
1466             "gray67",
1467             "grey67",
1468             "gray68",
1469             "grey68",
1470             "gray69",
1471             "grey69",
1472             "gray70",
1473             "grey70",
1474             "gray71",
1475             "grey71",
1476             "gray72",
1477             "grey72",
1478             "gray73",
1479             "grey73",
1480             "gray74",
1481             "grey74",
1482             "gray75",
1483             "grey75",
1484             "gray76",
1485             "grey76",
1486             "gray77",
1487             "grey77",
1488             "gray78",
1489             "grey78",
1490             "gray79",
1491             "grey79",
1492             "gray80",
1493             "grey80",
1494             "gray81",
1495             "grey81",
1496             "gray82",
1497             "grey82",
1498             "gray83",
1499             "grey83",
1500             "gray84",
1501             "grey84",
1502             "gray85",
1503             "grey85",
1504             "gray86",
1505             "grey86",
1506             "gray87",
1507             "grey87",
1508             "gray88",
1509             "grey88",
1510             "gray89",
1511             "grey89",
1512             "gray90",
1513             "grey90",
1514             "gray91",
1515             "grey91",
1516             "gray92",
1517             "grey92",
1518             "gray93",
1519             "grey93",
1520             "gray94",
1521             "grey94",
1522             "gray95",
1523             "grey95",
1524             "gray96",
1525             "grey96",
1526             "gray97",
1527             "grey97",
1528             "gray98",
1529             "grey98",
1530             "gray99",
1531             "grey99",
1532             "gray100",
1533             "grey100",
1534             "dark grey",
1535             "DarkGrey",
1536             "dark gray",
1537             "DarkGray",
1538             "dark blue",
1539             "DarkBlue",
1540             "dark cyan",
1541             "DarkCyan",
1542             "dark magenta",
1543             "DarkMagenta",
1544             "dark red",
1545             "DarkRed",
1546             "light"
1547     };
1548     
1549     // rgbents, rgbnames
1550     public static boolean debugflag=false;
1551     
1552     static void debug(String msg)
1553     {
1554         if(debugflag)
1555             System.out.println(msg);
1556     }
1557     
1558     // look up string name of color. return int[3] of rgb, or
1559     // null if color not found
1560     public static int[] NameToRGB3(String str)
1561     {
1562         int rsize=rgbnames.length;
1563         
1564         for(int count=0;count<rsize; count++)
1565         {
1566             if(str.equalsIgnoreCase(rgbnames[count]))
1567             {
1568                 return rgbents[count];
1569             }
1570         }
1571         
1572         return null;
1573     }
1574     
1575     // This returns an int. If the int were represented as
1576     // 0xffffffff, then the format would match data as
1577     // 0x00rrggbb
1578     //BUT.. returns 0xffffffff if color not found
1579     public static int NameToRGB(String str)
1580     {
1581         int rsize=rgbnames.length;
1582         
1583         if(str.charAt(0)=='#'){
1584             // Have to deal with rrggbb, OR rrrrggggbbbb
1585             // Erm.. except this only deals with
1586             // #rrggbb, it looks like... ?!!
1587             String Substr=str.substring(1,7);
1588             int rgb=Integer.parseInt(Substr,16);
1589             rgb|=0xff000000;
1590             return rgb;
1591         }
1592         
1593         for(int count=0;count<rsize; count++)
1594         {
1595             if(str.equalsIgnoreCase(rgbnames[count]))
1596             {
1597                 int ret;
1598                 ret =   0xff000000 |
1599                 (rgbents[count][0]<<16) |
1600                 (rgbents[count][1]<<8) |
1601                 rgbents[count][2];
1602                 
1603                 return ret;
1604             }
1605         }
1606         if(!str.equalsIgnoreCase("None"))
1607             debug("NameToRGB: Could not find match for color "+str);
1608         return 0x00000000;
1609     }
1610     
1611     public static String RGB3ToName(int val[])
1612     {
1613         if(val.length != 3)
1614             return null;
1615         
1616         int rsize=rgbnames.length;
1617         for(int count=0; count<rsize; count++)
1618         {
1619             if(val[0] ==rgbents[count][0])
1620                 if(val[1] ==rgbents[count][1])
1621                     if(val[2] ==rgbents[count][2])
1622                         return rgbnames[count];
1623         }
1624         
1625         return null;
1626     }
1627     
1628     
1629     /************************************************************
1630      * This part implements reading in xpm data, and doing something
1631      * USEFUL with it. This is the only public routine that people
1632      * will probably care about.
1633      * xpm is possibly copyright/trademarked by Arnaud LE HORS,
1634      * BULL Research, France. lehors@sophia.inria.fr
1635      ************************************************************/
1636     
1637     // we dont care/try to deal with mono conversion
1638     public static Image XpmToImage(String xpm) {
1639         debug(xpm);
1640         /* general rules I'm going to follow:
1641          *
1642          * skip all  (* xxxx*) but possibly insist on initial
1643          *    (* XPM *)
1644          * skip static char .....
1645          * read "<width> <height> <colors> <charsperpixel>" <hotx,hoty>?
1646          * Then in main reading;
1647          * take c FIRST. fall back to s. fall back to g. fall back to g4.
1648          *      fall back to m.
1649          *
1650          *
1651          */
1652         
1653         if (xpm == null) {
1654             debug("XpmToImage : Provided xpm is null!");
1655             return null;
1656         }
1657         
1658         int parse, parseend;
1659         int width, height,colcount,charsperpixel;
1660         Hashtable colorlookup = new Hashtable();
1661         // add default val for "transparent"
1662         // the initial 0xff should mean it should not show up
1663         
1664         
1665         if(! xpm.startsWith("/* XPM */"))
1666         {
1667             debug("xpm data doesn't start with XPM magic. exit");
1668             debug(xpm.substring(0,10));
1669             return null;
1670         }
1671         
1672         /*********************************************
1673          * Do initial width/size,etc parsing
1674          **********************************************/
1675         parse           =       xpm.indexOf('"', 9);
1676         parse+=1;
1677         
1678         parseend=xpm.indexOf(' ', parse);
1679         width=Integer.parseInt(xpm.substring(parse,parseend));
1680         
1681         parse=parseend+1;
1682         parseend=xpm.indexOf(' ', parse);
1683         height=Integer.parseInt(xpm.substring(parse,parseend));
1684         
1685         parse=parseend+1;
1686         parseend=xpm.indexOf(' ', parse);
1687         colcount=Integer.parseInt(xpm.substring(parse,parseend));
1688         
1689         parse=parseend+1;
1690         parseend=xpm.indexOf('"',parse);
1691         if(parseend==-1){
1692             return null;
1693         }
1694         charsperpixel=Integer.parseInt(xpm.substring(parse,parseend));
1695         
1696         debug("width="+width+",height="+height+
1697                 ",colcount="+colcount+",cpp="+charsperpixel);
1698         
1699         
1700         
1701         if(charsperpixel==1){
1702             colorlookup.put(new Integer(' '),
1703                     new Integer(0x00000000));
1704         } else {
1705             int tmpchar=(' ' &0xff) <<8;
1706             tmpchar |=  (' '&0xff);
1707             colorlookup.put(new Integer((tmpchar&0xffff)),
1708                     new Integer(0x00000000));
1709             
1710         }
1711         
1712         /**************************************************
1713          * Now do parsing of color naming/indexing
1714          **************************************************/
1715         Image image;
1716         int imageb[];
1717         
1718         imageb = new int[width * height];
1719         int bytecount=0; // counting bytes into image array
1720         
1721         parse=xpm.indexOf('"', parseend+1)+1;
1722         
1723         while(colcount-->0)
1724         {
1725             if(parse==0){
1726                 debug("ERROR: expecting color def");
1727                 return null;
1728             }
1729             
1730             Integer colref;
1731             Integer rgb;
1732             parseend=xpm.indexOf('"', parse+1);
1733             
1734             String colorname =
1735                 getColorName(xpm.substring(parse, parseend));
1736             
1737             if(debugflag){
1738                 debug("colorname on line is "+colorname);
1739                 debug("now parsing "+
1740                         xpm.substring(parse,parse+charsperpixel));
1741                 
1742             }
1743             
1744             if(charsperpixel==1){
1745                 colref=new Integer(xpm.charAt(parse++));
1746             } else{
1747                 int tmpchar=xpm.charAt(parse++);
1748                 tmpchar = (tmpchar&0xff)<<8;
1749                 tmpchar |= xpm.charAt(parse++) & 0xff;
1750                 
1751                 if(debugflag){
1752                     debug("two charsperpixel: substre==" +
1753                             xpm.substring(parse-2,parse)+
1754                             " which generates char "+
1755                             (tmpchar&0xffff));
1756                 }
1757                 
1758                 colref=new Integer(tmpchar&0xffff);
1759             }
1760             
1761             
1762             
1763             rgb = new Integer(NameToRGB(colorname));
1764             
1765             if(debugflag){
1766                 debug("Color num parsed for \"" +colorname+"\"("+
1767                         Integer.toHexString(colref.intValue())+
1768                         ") is #"+
1769                         Integer.toHexString(rgb.intValue()) );
1770             }
1771             
1772             
1773             colorlookup.put(colref, rgb);
1774             parse=xpm.indexOf('"', parseend+1)+1;
1775             
1776             
1777         }
1778         
1779         debug("Done with color defs");
1780         
1781         /****************************************************
1782          * Finally, now that we have all the data,
1783          * fully interpret the actual image
1784          ***************************************************/
1785         
1786         parse = xpm.indexOf("\n\"", parseend+1);
1787         if(parse==-1)
1788         {
1789             debug("ERROR; incomplete Xpm data");
1790             return null;
1791         }
1792         parse+=1;
1793         
1794         debug("Xpm starting image parse");
1795         while(xpm.charAt(parse) =='"')
1796         {
1797             parse++;
1798             parseend = xpm.indexOf('"', parse);
1799             
1800             debug("Xpm; parsing \""+xpm.substring(parse, parseend)+"\"");
1801             
1802             for(int pix=parse; pix<parseend;pix++)
1803             {
1804                 int tmpchar;
1805                 Integer pixchar;
1806                 Integer pixval;
1807                 
1808                 if(charsperpixel==1){
1809                     tmpchar=xpm.charAt(pix);
1810                 } else{
1811                     tmpchar=xpm.charAt(pix++);
1812                     tmpchar = (tmpchar&0xff)<<8;
1813                     tmpchar |= xpm.charAt(pix) & 0xff;
1814                     
1815                 }
1816                 pixchar=new Integer(tmpchar&0xffff);
1817                 
1818                 
1819                 pixval = (Integer)colorlookup.get(pixchar);
1820                 if(pixval==null){
1821                     if(debugflag){
1822                         debug("HEY MORON: no value stored "+
1823                                 " for int "+
1824                                 Integer.toHexString(tmpchar)+
1825                                 ", char substring "+
1826                                 xpm.substring(pix-charsperpixel,
1827                                         pix));
1828                     }
1829                     
1830                 }
1831                 imageb[bytecount++]=pixval.intValue();
1832             }
1833             
1834             parse=xpm.indexOf('"', parseend+1);
1835             if(parse==-1)
1836                 break;
1837         }
1838         
1839         if(bytecount<(width * height -1))
1840         {
1841             debug("Warning.. pixmap truncated!");
1842         }
1843         
1844         //printbytes(imageb);
1845         image=BytesToImage(imageb, width, height);
1846         
1847         return image;
1848         
1849         
1850     }
1851     
1852     static Image BytesToImage(int bytes[], int width, int height)
1853     {
1854         Image myimage;
1855         Toolkit tk = Toolkit.getDefaultToolkit();
1856         myimage=tk.createImage(new MemoryImageSource(width, height, bytes, 0, width));
1857         
1858         return myimage;
1859         
1860     }
1861     
1862     // debug routine
1863     static void printbytes(int b[])
1864     {
1865         int index;
1866         for(index=0; index<b.length; index++)
1867         {
1868             System.out.print(" "+Integer.toHexString(b[index]));
1869         }
1870         System.out.println(" ");
1871     }
1872     
1873     // This just parses out the string that defines the colorname
1874     // we do NOT interpret. we just split it out from the rest of
1875     // the line. Call NameToRGB() on the result.
1876     // We make the assumption that our string does NOT
1877     // have a trailing '"'
1878     static String getColorName(String xpmline)
1879     {
1880         //debug("getColorName passed: "+xpmline);
1881         
1882         int parsemid, parsemidend;
1883         parsemid = xpmline.indexOf("\tc");
1884         if(parsemid <=0)
1885             parsemid = xpmline.indexOf(" c");
1886         if(parsemid <=0)
1887         {
1888             debug("Xpm: oops. no c found, in: "+xpmline);
1889             return null;
1890         }
1891         parsemid+=3;
1892         parsemidend=xpmline.indexOf('\t',parsemid);
1893         if(parsemidend==-1)
1894             parsemidend=xpmline.length();
1895         
1896         return xpmline.substring(parsemid, parsemidend);
1897         
1898         
1899     }
1900     
1901     
1902     
1903 }