themes: Workaround for bug where a background color of RGB 0,0,0 in Black color schem...
[ntk.git] / src / fl_images_core.cxx
blob0ba10e52ce3caff4667ed4b1f7534417ffdfe6b5
1 //
2 // "$Id: fl_images_core.cxx 7903 2010-11-28 21:06:39Z matt $"
3 //
4 // FLTK images library core.
5 //
6 // Copyright 1997-2010 by Easy Software Products.
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_register_images() - Register the image formats.
30 // fl_check_images() - Check for a supported image format.
34 // Include necessary header files...
37 #include <FL/Fl_Shared_Image.H>
38 #include <FL/Fl_BMP_Image.H>
39 #include <FL/Fl_GIF_Image.H>
40 #include <FL/Fl_JPEG_Image.H>
41 #include <FL/Fl_PNG_Image.H>
42 #include <FL/Fl_PNM_Image.H>
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include "flstring.h"
49 // Define a simple global image registration function that registers
50 // the extra image formats that aren't part of the core FLTK library.
53 static Fl_Image *fl_check_images(const char *name, uchar *header, int headerlen);
56 /**
57 \brief Register the image formats.
59 This function is provided in the fltk_images library and
60 registers all of the "extra" image file formats that are not part
61 of the core FLTK library.
63 void fl_register_images() {
64 Fl_Shared_Image::add_handler(fl_check_images);
69 // 'fl_check_images()' - Check for a supported image format.
72 Fl_Image * // O - Image, if found
73 fl_check_images(const char *name, // I - Filename
74 uchar *header, // I - Header data from file
75 int) { // I - Amount of data (not used)
76 if (memcmp(header, "GIF87a", 6) == 0 ||
77 memcmp(header, "GIF89a", 6) == 0) // GIF file
78 return new Fl_GIF_Image(name);
80 if (memcmp(header, "BM", 2) == 0) // BMP file
81 return new Fl_BMP_Image(name);
83 if (header[0] == 'P' && header[1] >= '1' && header[1] <= '7')
84 // Portable anymap
85 return new Fl_PNM_Image(name);
87 #ifdef HAVE_LIBPNG
88 if (memcmp(header, "\211PNG", 4) == 0)// PNG file
89 return new Fl_PNG_Image(name);
90 #endif // HAVE_LIBPNG
92 #ifdef HAVE_LIBJPEG
93 if (memcmp(header, "\377\330\377", 3) == 0 &&
94 // Start-of-Image
95 header[3] >= 0xc0 && header[3] <= 0xef)
96 // APPn for JPEG file
97 return new Fl_JPEG_Image(name);
98 #endif // HAVE_LIBJPEG
100 return 0;
105 // End of "$Id: fl_images_core.cxx 7903 2010-11-28 21:06:39Z matt $".