2 // "$Id: Fl_XPM_Image.cxx 7903 2010-11-28 21:06:39Z matt $"
4 // Fl_XPM_Image routines.
6 // Copyright 1997-2010 by Bill Spitzak and others.
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
32 // Include necessary header files...
36 #include <FL/Fl_XPM_Image.H>
39 #include <FL/fl_utf8.h>
44 // 'hexdigit()' - Convert a hex digit to an integer.
47 static int hexdigit(int x
) { // I - Hex digit...
48 if (isdigit(x
)) return x
-'0';
49 if (isupper(x
)) return x
-'A'+10;
50 if (islower(x
)) return x
-'a'+10;
55 #define INITIALLINES 256
57 The constructor loads the XPM image from the name filename.
58 <P>The destructor free all memory and server resources that are used by
61 Fl_XPM_Image::Fl_XPM_Image(const char *name
) : Fl_Pixmap((char *const*)0) {
64 if ((f
= fl_fopen(name
, "rb")) == NULL
) return;
66 // read all the c-strings out of the file:
67 char** new_data
= new char *[INITIALLINES
];
69 int malloc_size
= INITIALLINES
;
70 char buffer
[MAXSIZE
+20];
72 while (fgets(buffer
,MAXSIZE
+20,f
)) {
73 if (buffer
[0] != '\"') continue;
76 while (*q
!= '\"' && myp
< buffer
+MAXSIZE
) {
77 if (*q
== '\\') switch (*++q
) {
80 if (!fgets(q
,(buffer
+MAXSIZE
+20)-q
,f
)) { /* no problem if we hit EOF */ } break;
86 for (int x
= 0; x
< 3; x
++) {
87 int xd
= hexdigit(*q
);
96 if (c
>='0' && c
<='7') {
98 for (int x
=0; x
<2; x
++) {
99 int xd
= hexdigit(*q
);
112 if (i
>= malloc_size
) {
113 temp_data
= new char *[malloc_size
+ INITIALLINES
];
114 memcpy(temp_data
, new_data
, sizeof(char *) * malloc_size
);
116 new_data
= temp_data
;
117 malloc_size
+= INITIALLINES
;
119 new_data
[i
] = new char[myp
-buffer
+1];
120 memcpy(new_data
[i
], buffer
,myp
-buffer
);
121 new_data
[i
][myp
-buffer
] = 0;
127 data((const char **)new_data
, i
);
135 // End of "$Id: Fl_XPM_Image.cxx 7903 2010-11-28 21:06:39Z matt $".