2001-11-24 21:07:58 +03:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
2001-11-24 21:07:58 +03:00
|
|
|
//
|
|
|
|
// Fl_XBM_Image routines.
|
|
|
|
//
|
2010-11-29 00:06:39 +03:00
|
|
|
// Copyright 1997-2010 by Bill Spitzak and others.
|
2001-11-24 21:07:58 +03:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/COPYING.php
|
2001-11-24 21:07:58 +03:00
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
2001-11-24 21:07:58 +03:00
|
|
|
//
|
|
|
|
// Contents:
|
|
|
|
//
|
2001-12-11 19:03:13 +03:00
|
|
|
// Fl_XBM_Image::Fl_XBM_Image() - Load an XBM file.
|
2001-11-24 21:07:58 +03:00
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// Include necessary header files...
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_XBM_Image.H>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2008-09-19 21:40:20 +04:00
|
|
|
#include <FL/fl_utf8.h>
|
2002-04-11 15:52:43 +04:00
|
|
|
#include "flstring.h"
|
2001-11-24 21:07:58 +03:00
|
|
|
|
2001-12-11 19:03:13 +03:00
|
|
|
//
|
|
|
|
// 'Fl_XBM_Image::Fl_XBM_Image()' - Load an XBM file.
|
|
|
|
//
|
|
|
|
|
2008-09-14 22:19:41 +04: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 21:07:58 +03:00
|
|
|
Fl_XBM_Image::Fl_XBM_Image(const char *name) : Fl_Bitmap((const char *)0,0,0) {
|
|
|
|
FILE *f;
|
2002-08-09 07:17:30 +04:00
|
|
|
uchar *ptr;
|
2001-11-24 21:07:58 +03:00
|
|
|
|
2008-09-11 03:56:49 +04:00
|
|
|
if ((f = fl_fopen(name, "rb")) == NULL) return;
|
2001-11-24 21:07:58 +03: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 19:03:13 +03:00
|
|
|
if (!fgets(buffer,1024,f)) {
|
|
|
|
fclose(f);
|
|
|
|
return;
|
|
|
|
}
|
2001-11-24 21:07:58 +03:00
|
|
|
int r = sscanf(buffer,"#define %s %d",junk,&wh[i]);
|
|
|
|
if (r >= 2) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip to data array:
|
|
|
|
for (;;) {
|
2001-12-11 19:03:13 +03:00
|
|
|
if (!fgets(buffer,1024,f)) {
|
|
|
|
fclose(f);
|
|
|
|
return;
|
|
|
|
}
|
2001-11-24 21:07:58 +03: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 19:23:03 +04:00
|
|
|
array = new uchar[n];
|
2001-11-24 21:07:58 +03:00
|
|
|
|
|
|
|
// read the data:
|
2002-08-09 07:17:30 +04:00
|
|
|
for (i = 0, ptr = (uchar *)array; i < n;) {
|
2001-12-11 19:03:13 +03:00
|
|
|
if (!fgets(buffer,1024,f)) {
|
|
|
|
fclose(f);
|
|
|
|
return;
|
|
|
|
}
|
2001-11-24 21:07:58 +03:00
|
|
|
const char *a = buffer;
|
|
|
|
while (*a && i<n) {
|
2005-08-30 00:11:48 +04:00
|
|
|
unsigned int t;
|
2002-06-28 19:23:03 +04:00
|
|
|
if (sscanf(a," 0x%x",&t)>0) {
|
2002-11-19 19:37:36 +03:00
|
|
|
*ptr++ = (uchar)t;
|
2002-06-28 19:23:03 +04:00
|
|
|
i ++;
|
|
|
|
}
|
2001-11-24 21:07:58 +03:00
|
|
|
while (*a && *a++ != ',');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
2001-11-24 21:07:58 +03:00
|
|
|
//
|