FLTK
Fl_Shared_Image.H
Go to the documentation of this file.
1 //
2 // Shared image header file for the Fast Light Tool Kit (FLTK).
3 //
4 // Copyright 1998-2017 by Bill Spitzak and others.
5 //
6 // This library is free software. Distribution and use rights are outlined in
7 // the file "COPYING" which should have been included with this file. If this
8 // file is missing or damaged, see the license at:
9 //
10 // https://www.fltk.org/COPYING.php
11 //
12 // Please see the following page on how to report bugs and issues:
13 //
14 // https://www.fltk.org/bugs.php
15 //
16 
20 #ifndef Fl_Shared_Image_H
21 # define Fl_Shared_Image_H
22 
23 # include "Fl_Image.H"
24 
25 
26 // Test function for adding new formats
27 typedef Fl_Image *(*Fl_Shared_Handler)(const char *name, uchar *header,
28  int headerlen);
29 
30 // Shared images class.
49 class FL_EXPORT Fl_Shared_Image : public Fl_Image {
50 
51  friend class Fl_JPEG_Image;
52  friend class Fl_PNG_Image;
53  friend class Fl_Graphics_Driver;
54 
55 protected:
56 
57  static Fl_Shared_Image **images_; // Shared images
58  static int num_images_; // Number of shared images
59  static int alloc_images_; // Allocated shared images
60  static Fl_Shared_Handler *handlers_; // Additional format handlers
61  static int num_handlers_; // Number of format handlers
62  static int alloc_handlers_; // Allocated format handlers
63 
64  const char *name_; // Name of image file
65  int original_; // Original image?
66  int refcount_; // Number of times this image has been used
67  Fl_Image *image_; // The image that is shared
68  int alloc_image_; // Was the image allocated?
69 
70  static int compare(Fl_Shared_Image **i0, Fl_Shared_Image **i1);
71 
72  // Use get() and release() to load/delete images in memory...
74  Fl_Shared_Image(const char *n, Fl_Image *img = 0);
75  virtual ~Fl_Shared_Image();
76  void add();
77  void update();
78 
79 public:
81  const char *name() { return name_; }
82 
86  int refcount() { return refcount_; }
87 
95  int original() { return original_; }
96 
97  void release();
98  void reload();
99 
101  return this;
102  }
103 
104  virtual Fl_Image *copy(int W, int H);
105  Fl_Image *copy() { return Fl_Image::copy(); }
106  virtual void color_average(Fl_Color c, float i);
107  virtual void desaturate();
108  virtual void draw(int X, int Y, int W, int H, int cx = 0, int cy = 0);
109  void draw(int X, int Y) { draw(X, Y, w(), h(), 0, 0); }
110  virtual void uncache();
111 
112  static Fl_Shared_Image *find(const char *name, int W = 0, int H = 0);
113  static Fl_Shared_Image *get(const char *name, int W = 0, int H = 0);
114  static Fl_Shared_Image *get(Fl_RGB_Image *rgb, int own_it = 1);
115  static Fl_Shared_Image **images();
116  static int num_images();
117  static void add_handler(Fl_Shared_Handler f);
118  static void remove_handler(Fl_Shared_Handler f);
119 };
120 
121 //
122 // The following function is provided in the fltk_images library and
123 // registers all of the "extra" image file formats that are not part
124 // of the core FLTK library...
125 //
126 
127 FL_EXPORT extern void fl_register_images();
128 
129 #endif // !Fl_Shared_Image_H
virtual void desaturate()
The desaturate() method converts an image to grayscale.
Definition: Fl_Image.cxx:110
int h() const
Returns the current image drawing height in FLTK units.
Definition: Fl_Image.H:132
The Fl_PNG_Image class supports loading, caching, and drawing of Portable Network Graphics (PNG) imag...
Definition: Fl_PNG_Image.H:30
virtual Fl_Shared_Image * as_shared_image()
Returns whether an image is an Fl_Shared_Image or not.
Definition: Fl_Shared_Image.H:100
Base class for image caching, scaling and drawing.
Definition: Fl_Image.H:62
Fl_Image, Fl_RGB_Image classes.
int w() const
Returns the current image drawing width in FLTK units.
Definition: Fl_Image.H:126
The Fl_RGB_Image class supports caching and drawing of full-color images with 1 to 4 channels of colo...
Definition: Fl_Image.H:287
virtual void draw(int X, int Y, int W, int H, int cx=0, int cy=0)
Draws the image to the current drawing surface with a bounding box.
Definition: Fl_Image.cxx:60
const char * name()
Returns the filename of the shared image.
Definition: Fl_Shared_Image.H:81
The Fl_JPEG_Image class supports loading, caching, and drawing of Joint Photographic Experts Group (J...
Definition: Fl_JPEG_Image.H:30
Fl_Image * copy()
Creates a copy of the specified image.
Definition: Fl_Image.H:217
int original()
Returns whether this is an original image.
Definition: Fl_Shared_Image.H:95
int refcount()
Returns the number of references of this shared image.
Definition: Fl_Shared_Image.H:86
virtual void release()
Releases an Fl_Image - the same as 'delete this'.
Definition: Fl_Image.H:192
virtual void color_average(Fl_Color c, float i)
The color_average() method averages the colors in the image with the FLTK color value c...
Definition: Fl_Image.cxx:99
unsigned int Fl_Color
An FLTK color value; see also Colors.
Definition: Enumerations.H:1042
FL_EXPORT void fl_register_images()
Register the image formats.
Definition: fl_images_core.cxx:56
This class supports caching, loading, and drawing of image files.
Definition: Fl_Shared_Image.H:49
virtual void uncache()
If the image has been cached for display, delete the cache data.
Definition: Fl_Image.cxx:57
unsigned char uchar
unsigned char
Definition: fl_types.h:28