themes: Workaround for bug where a background color of RGB 0,0,0 in Black color schem...
[ntk.git] / src / Fl_XBM_Image.cxx
blobcb35c1b5caa270ddc91b968a032293eedbe221c7
1 //
2 // "$Id: Fl_XBM_Image.cxx 7903 2010-11-28 21:06:39Z matt $"
3 //
4 // Fl_XBM_Image routines.
5 //
6 // Copyright 1997-2010 by Bill Spitzak and others.
7 //
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
21 // USA.
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
27 // Contents:
29 // Fl_XBM_Image::Fl_XBM_Image() - Load an XBM file.
33 // Include necessary header files...
36 #include <FL/Fl.H>
37 #include <FL/Fl_XBM_Image.H>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <FL/fl_utf8.h>
41 #include "flstring.h"
44 // 'Fl_XBM_Image::Fl_XBM_Image()' - Load an XBM file.
47 /**
48 The constructor loads the named XBM file from the given name filename.
49 <P>The destructor free all memory and server resources that are used by
50 the image.
52 Fl_XBM_Image::Fl_XBM_Image(const char *name) : Fl_Bitmap((const char *)0,0,0) {
53 FILE *f;
54 uchar *ptr;
56 if ((f = fl_fopen(name, "rb")) == NULL) return;
58 char buffer[1024];
59 char junk[1024];
60 int wh[2]; // width and height
61 int i;
62 for (i = 0; i<2; i++) {
63 for (;;) {
64 if (!fgets(buffer,1024,f)) {
65 fclose(f);
66 return;
68 int r = sscanf(buffer,"#define %s %d",junk,&wh[i]);
69 if (r >= 2) break;
73 // skip to data array:
74 for (;;) {
75 if (!fgets(buffer,1024,f)) {
76 fclose(f);
77 return;
79 if (!strncmp(buffer,"static ",7)) break;
82 // Allocate memory...
83 w(wh[0]);
84 h(wh[1]);
86 int n = ((wh[0]+7)/8)*wh[1];
87 array = new uchar[n];
89 // read the data:
90 for (i = 0, ptr = (uchar *)array; i < n;) {
91 if (!fgets(buffer,1024,f)) {
92 fclose(f);
93 return;
95 const char *a = buffer;
96 while (*a && i<n) {
97 unsigned int t;
98 if (sscanf(a," 0x%x",&t)>0) {
99 *ptr++ = (uchar)t;
100 i ++;
102 while (*a && *a++ != ',');
106 fclose(f);
111 // End of "$Id: Fl_XBM_Image.cxx 7903 2010-11-28 21:06:39Z matt $".