2001-11-24 18:07:58 +00:00
|
|
|
//
|
2005-02-24 21:55:12 +00:00
|
|
|
// "$Id$"
|
2001-11-24 18:07:58 +00:00
|
|
|
//
|
|
|
|
// Fl_XBM_Image routines.
|
|
|
|
//
|
2010-11-28 21:06:39 +00:00
|
|
|
// Copyright 1997-2010 by Bill Spitzak and others.
|
2001-11-24 18:07:58 +00:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
2005-04-16 00:13:17 +00:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
2001-11-24 18:07:58 +00:00
|
|
|
//
|
|
|
|
// Contents:
|
|
|
|
//
|
2001-12-11 16:03:13 +00:00
|
|
|
// Fl_XBM_Image::Fl_XBM_Image() - Load an XBM file.
|
2001-11-24 18:07:58 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// Include necessary header files...
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_XBM_Image.H>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2008-09-19 17:40:20 +00:00
|
|
|
#include <FL/fl_utf8.h>
|
2002-04-11 11:52:43 +00:00
|
|
|
#include "flstring.h"
|
2001-11-24 18:07:58 +00:00
|
|
|
|
2001-12-11 16:03:13 +00:00
|
|
|
//
|
|
|
|
// 'Fl_XBM_Image::Fl_XBM_Image()' - Load an XBM file.
|
|
|
|
//
|
|
|
|
|
2008-09-14 18:19:41 +00:00
|
|
|
/**
|
|
|
|
The constructor loads the named XBM file from the given name filename.
|
|
|
|
<P>The destructor free all memory and server resources that are used by
|
|
|
|
the image.
|
|
|
|
*/
|
2001-11-24 18:07:58 +00:00
|
|
|
Fl_XBM_Image::Fl_XBM_Image(const char *name) : Fl_Bitmap((const char *)0,0,0) {
|
|
|
|
FILE *f;
|
2002-08-09 03:17:30 +00:00
|
|
|
uchar *ptr;
|
2001-11-24 18:07:58 +00:00
|
|
|
|
2008-09-10 23:56:49 +00:00
|
|
|
if ((f = fl_fopen(name, "rb")) == NULL) return;
|
2001-11-24 18:07:58 +00:00
|
|
|
|
|
|
|
char buffer[1024];
|
|
|
|
char junk[1024];
|
|
|
|
int wh[2]; // width and height
|
|
|
|
int i;
|
|
|
|
for (i = 0; i<2; i++) {
|
|
|
|
for (;;) {
|
2001-12-11 16:03:13 +00:00
|
|
|
if (!fgets(buffer,1024,f)) {
|
|
|
|
fclose(f);
|
|
|
|
return;
|
|
|
|
}
|
2001-11-24 18:07:58 +00:00
|
|
|
int r = sscanf(buffer,"#define %s %d",junk,&wh[i]);
|
|
|
|
if (r >= 2) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip to data array:
|
|
|
|
for (;;) {
|
2001-12-11 16:03:13 +00:00
|
|
|
if (!fgets(buffer,1024,f)) {
|
|
|
|
fclose(f);
|
|
|
|
return;
|
|
|
|
}
|
2001-11-24 18:07:58 +00:00
|
|
|
if (!strncmp(buffer,"static ",7)) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate memory...
|
|
|
|
w(wh[0]);
|
|
|
|
h(wh[1]);
|
|
|
|
|
|
|
|
int n = ((wh[0]+7)/8)*wh[1];
|
2002-06-28 15:23:03 +00:00
|
|
|
array = new uchar[n];
|
2001-11-24 18:07:58 +00:00
|
|
|
|
|
|
|
// read the data:
|
2002-08-09 03:17:30 +00:00
|
|
|
for (i = 0, ptr = (uchar *)array; i < n;) {
|
2001-12-11 16:03:13 +00:00
|
|
|
if (!fgets(buffer,1024,f)) {
|
|
|
|
fclose(f);
|
|
|
|
return;
|
|
|
|
}
|
2001-11-24 18:07:58 +00:00
|
|
|
const char *a = buffer;
|
|
|
|
while (*a && i<n) {
|
2005-08-29 20:11:48 +00:00
|
|
|
unsigned int t;
|
2002-06-28 15:23:03 +00:00
|
|
|
if (sscanf(a," 0x%x",&t)>0) {
|
2002-11-19 16:37:36 +00:00
|
|
|
*ptr++ = (uchar)t;
|
2002-06-28 15:23:03 +00:00
|
|
|
i ++;
|
|
|
|
}
|
2001-11-24 18:07:58 +00:00
|
|
|
while (*a && *a++ != ',');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2005-02-24 21:55:12 +00:00
|
|
|
// End of "$Id$".
|
2001-11-24 18:07:58 +00:00
|
|
|
//
|