You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
2.5KB

  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.
  12. //
  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.
  17. //
  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.
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. // Contents:
  28. //
  29. // Fl_XBM_Image::Fl_XBM_Image() - Load an XBM file.
  30. //
  31. //
  32. // Include necessary header files...
  33. //
  34. #include <FL/Fl.H>
  35. #include <FL/Fl_XBM_Image.H>
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <FL/fl_utf8.h>
  39. #include "flstring.h"
  40. //
  41. // 'Fl_XBM_Image::Fl_XBM_Image()' - Load an XBM file.
  42. //
  43. /**
  44. The constructor loads the named XBM file from the given name filename.
  45. <P>The destructor free all memory and server resources that are used by
  46. the image.
  47. */
  48. Fl_XBM_Image::Fl_XBM_Image(const char *name) : Fl_Bitmap((const char *)0,0,0) {
  49. FILE *f;
  50. uchar *ptr;
  51. if ((f = fl_fopen(name, "rb")) == NULL) return;
  52. char buffer[1024];
  53. char junk[1024];
  54. int wh[2]; // width and height
  55. int i;
  56. for (i = 0; i<2; i++) {
  57. for (;;) {
  58. if (!fgets(buffer,1024,f)) {
  59. fclose(f);
  60. return;
  61. }
  62. int r = sscanf(buffer,"#define %s %d",junk,&wh[i]);
  63. if (r >= 2) break;
  64. }
  65. }
  66. // skip to data array:
  67. for (;;) {
  68. if (!fgets(buffer,1024,f)) {
  69. fclose(f);
  70. return;
  71. }
  72. if (!strncmp(buffer,"static ",7)) break;
  73. }
  74. // Allocate memory...
  75. w(wh[0]);
  76. h(wh[1]);
  77. int n = ((wh[0]+7)/8)*wh[1];
  78. array = new uchar[n];
  79. // read the data:
  80. for (i = 0, ptr = (uchar *)array; i < n;) {
  81. if (!fgets(buffer,1024,f)) {
  82. fclose(f);
  83. return;
  84. }
  85. const char *a = buffer;
  86. while (*a && i<n) {
  87. unsigned int t;
  88. if (sscanf(a," 0x%x",&t)>0) {
  89. *ptr++ = (uchar)t;
  90. i ++;
  91. }
  92. while (*a && *a++ != ',');
  93. }
  94. }
  95. fclose(f);
  96. }
  97. //
  98. // End of "$Id: Fl_XBM_Image.cxx 7903 2010-11-28 21:06:39Z matt $".
  99. //