2002-06-29 01:19:42 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
2002-06-29 01:19:42 +04:00
|
|
|
//
|
|
|
|
// FLTK images library core.
|
|
|
|
//
|
2010-11-29 00:06:39 +03:00
|
|
|
// Copyright 1997-2010 by Easy Software Products.
|
2002-06-29 01:19:42 +04: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 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
2002-06-29 01:19:42 +04:00
|
|
|
//
|
|
|
|
// Contents:
|
|
|
|
//
|
|
|
|
// fl_register_images() - Register the image formats.
|
|
|
|
// fl_check_images() - Check for a supported image format.
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// Include necessary header files...
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <FL/Fl_Shared_Image.H>
|
2002-08-09 05:09:49 +04:00
|
|
|
#include <FL/Fl_BMP_Image.H>
|
|
|
|
#include <FL/Fl_GIF_Image.H>
|
2002-06-29 01:19:42 +04:00
|
|
|
#include <FL/Fl_JPEG_Image.H>
|
|
|
|
#include <FL/Fl_PNG_Image.H>
|
2002-08-09 05:09:49 +04:00
|
|
|
#include <FL/Fl_PNM_Image.H>
|
2002-06-29 01:19:42 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "flstring.h"
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Define a simple global image registration function that registers
|
|
|
|
// the extra image formats that aren't part of the core FLTK library.
|
|
|
|
//
|
|
|
|
|
|
|
|
static Fl_Image *fl_check_images(const char *name, uchar *header, int headerlen);
|
|
|
|
|
|
|
|
|
2010-04-15 00:47:34 +04:00
|
|
|
/**
|
|
|
|
\brief Register the image formats.
|
|
|
|
*
|
|
|
|
This function is provided in the fltk_images library and
|
|
|
|
registers all of the "extra" image file formats that are not part
|
|
|
|
of the core FLTK library.
|
|
|
|
*/
|
2002-06-29 01:19:42 +04:00
|
|
|
void fl_register_images() {
|
|
|
|
Fl_Shared_Image::add_handler(fl_check_images);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// 'fl_check_images()' - Check for a supported image format.
|
|
|
|
//
|
|
|
|
|
|
|
|
Fl_Image * // O - Image, if found
|
|
|
|
fl_check_images(const char *name, // I - Filename
|
|
|
|
uchar *header, // I - Header data from file
|
2007-05-20 04:01:06 +04:00
|
|
|
int) { // I - Amount of data (not used)
|
2002-08-09 05:09:49 +04:00
|
|
|
if (memcmp(header, "GIF87a", 6) == 0 ||
|
|
|
|
memcmp(header, "GIF89a", 6) == 0) // GIF file
|
|
|
|
return new Fl_GIF_Image(name);
|
|
|
|
|
|
|
|
if (memcmp(header, "BM", 2) == 0) // BMP file
|
|
|
|
return new Fl_BMP_Image(name);
|
|
|
|
|
2002-09-18 00:27:19 +04:00
|
|
|
if (header[0] == 'P' && header[1] >= '1' && header[1] <= '7')
|
2002-08-09 05:09:49 +04:00
|
|
|
// Portable anymap
|
|
|
|
return new Fl_PNM_Image(name);
|
|
|
|
|
2002-06-29 01:19:42 +04:00
|
|
|
#ifdef HAVE_LIBPNG
|
2002-08-09 05:09:49 +04:00
|
|
|
if (memcmp(header, "\211PNG", 4) == 0)// PNG file
|
2002-06-29 01:19:42 +04:00
|
|
|
return new Fl_PNG_Image(name);
|
|
|
|
#endif // HAVE_LIBPNG
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBJPEG
|
2002-08-09 05:09:49 +04:00
|
|
|
if (memcmp(header, "\377\330\377", 3) == 0 &&
|
|
|
|
// Start-of-Image
|
2006-07-18 05:10:51 +04:00
|
|
|
header[3] >= 0xc0 && header[3] <= 0xef)
|
2002-08-09 05:09:49 +04:00
|
|
|
// APPn for JPEG file
|
2002-06-29 01:19:42 +04:00
|
|
|
return new Fl_JPEG_Image(name);
|
|
|
|
#endif // HAVE_LIBJPEG
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
2002-06-29 01:19:42 +04:00
|
|
|
//
|