fltk  1.3.5-source
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X.
  Fossies Dox: fltk-1.3.5-source.tar.bz2  ("inofficial" and yet experimental doxygen-generated source code documentation)  

fl_images_core.cxx
Go to the documentation of this file.
1 //
2 // "$Id$"
3 //
4 // FLTK images library core.
5 //
6 // Copyright 1997-2010 by Easy Software Products.
7 //
8 // This library is free software. Distribution and use rights are outlined in
9 // the file "COPYING" which should have been included with this file. If this
10 // file is missing or damaged, see the license at:
11 //
12 // http://www.fltk.org/COPYING.php
13 //
14 // Please report all bugs and problems on the following page:
15 //
16 // http://www.fltk.org/str.php
17 //
18 // Contents:
19 //
20 // fl_register_images() - Register the image formats.
21 // fl_check_images() - Check for a supported image format.
22 //
23 
24 //
25 // Include necessary header files...
26 //
27 
28 #include <FL/Fl_Shared_Image.H>
29 #include <FL/Fl_BMP_Image.H>
30 #include <FL/Fl_GIF_Image.H>
31 #include <FL/Fl_JPEG_Image.H>
32 #include <FL/Fl_PNG_Image.H>
33 #include <FL/Fl_PNM_Image.H>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include "flstring.h"
37 
38 
39 //
40 // Define a simple global image registration function that registers
41 // the extra image formats that aren't part of the core FLTK library.
42 //
43 
44 static Fl_Image *fl_check_images(const char *name, uchar *header, int headerlen);
45 
46 
56 }
57 
58 
59 //
60 // 'fl_check_images()' - Check for a supported image format.
61 //
62 
63 Fl_Image * // O - Image, if found
64 fl_check_images(const char *name, // I - Filename
65  uchar *header, // I - Header data from file
66  int) { // I - Amount of data (not used)
67  if (memcmp(header, "GIF87a", 6) == 0 ||
68  memcmp(header, "GIF89a", 6) == 0) // GIF file
69  return new Fl_GIF_Image(name);
70 
71  if (memcmp(header, "BM", 2) == 0) // BMP file
72  return new Fl_BMP_Image(name);
73 
74  if (header[0] == 'P' && header[1] >= '1' && header[1] <= '7')
75  // Portable anymap
76  return new Fl_PNM_Image(name);
77 
78 #ifdef HAVE_LIBPNG
79  if (memcmp(header, "\211PNG", 4) == 0)// PNG file
80  return new Fl_PNG_Image(name);
81 #endif // HAVE_LIBPNG
82 
83 #ifdef HAVE_LIBJPEG
84  if (memcmp(header, "\377\330\377", 3) == 0 &&
85  // Start-of-Image
86  header[3] >= 0xc0 && header[3] <= 0xef)
87  // APPn for JPEG file
88  return new Fl_JPEG_Image(name);
89 #endif // HAVE_LIBJPEG
90 
91  return 0;
92 }
93 
94 
95 //
96 // End of "$Id$".
97 //
Fl_Image
Base class for image caching and drawing.
Definition: Fl_Image.H:55
Fl_JPEG_Image.H
Fl_GIF_Image.H
Fl_JPEG_Image
Definition: Fl_JPEG_Image.H:32
fl_check_images
static Fl_Image * fl_check_images(const char *name, uchar *header, int headerlen)
Definition: fl_images_core.cxx:64
Fl_PNM_Image
Definition: Fl_PNM_Image.H:32
Fl_BMP_Image.H
Fl_Shared_Image::add_handler
static void add_handler(Fl_Shared_Handler f)
Definition: Fl_Shared_Image.cxx:585
Fl_Shared_Image.H
fl_register_images
void fl_register_images()
Register the image formats.
Definition: fl_images_core.cxx:54
Fl_BMP_Image
Definition: Fl_BMP_Image.H:30
Fl_GIF_Image
Definition: Fl_GIF_Image.H:31
flstring.h
Fl_PNG_Image.H
uchar
unsigned char uchar
Definition: fl_types.h:30
name
static const char * name
Definition: Fl_arg.cxx:53
Fl_PNG_Image
Definition: Fl_PNG_Image.H:32
Fl_PNM_Image.H