FLTK 1.4.0
Loading...
Searching...
No Matches
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-2024 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#undef SHIM_DEBUG
26
71typedef Fl_Image *(*Fl_Shared_Handler)(const char *name,
72 uchar *header,
73 int headerlen);
74
94class FL_EXPORT Fl_Shared_Image : public Fl_Image {
95
96 friend class Fl_JPEG_Image;
97 friend class Fl_PNG_Image;
98 friend class Fl_SVG_Image;
99 friend class Fl_Graphics_Driver;
100
101protected:
102
103 static Fl_Shared_Image **images_; // Shared images
104 static int num_images_; // Number of shared images
105 static int alloc_images_; // Allocated shared images
106 static Fl_Shared_Handler *handlers_; // Additional format handlers
107 static int num_handlers_; // Number of format handlers
108 static int alloc_handlers_; // Allocated format handlers
109
110 const char *name_; // Name of image file
111 int original_; // Original image?
112 int refcount_; // Number of times this image has been used
113 Fl_Image *image_; // The image that is shared
114 int alloc_image_; // Was the image allocated?
115
116 static int compare(Fl_Shared_Image **i0, Fl_Shared_Image **i1);
117
118 // Use get() and release() to load/delete images in memory...
120 Fl_Shared_Image(const char *n, Fl_Image *img = 0);
121 virtual ~Fl_Shared_Image();
122 void add();
123 void update();
124 Fl_Shared_Image *copy_(int W, int H) const;
125
126public:
127#ifdef SHIM_DEBUG
128 static void print_pool();
129#endif
130
132 const char *name() { return name_; }
133
137 int refcount() { return refcount_; }
138
146 int original() { return original_; }
147
148 void release() FL_OVERRIDE;
149 virtual void reload();
150
151 Fl_Shared_Image *as_shared_image() FL_OVERRIDE {
152 return this;
153 }
154
155 Fl_Image *copy(int W, int H) const FL_OVERRIDE;
156 Fl_Image *copy() const;
157 Fl_Image *copy();
158
159 void color_average(Fl_Color c, float i) FL_OVERRIDE;
160 void desaturate() FL_OVERRIDE;
161 void draw(int X, int Y, int W, int H, int cx = 0, int cy = 0) FL_OVERRIDE;
162 void draw(int X, int Y) { draw(X, Y, w(), h(), 0, 0); }
163 void uncache() FL_OVERRIDE;
164
165 static Fl_Shared_Image *find(const char *name, int W = 0, int H = 0);
166 static Fl_Shared_Image *get(const char *name, int W = 0, int H = 0);
167 static Fl_Shared_Image *get(Fl_RGB_Image *rgb, int own_it = 1);
168 static Fl_Shared_Image **images();
169 static int num_images();
170 static void add_handler(Fl_Shared_Handler f);
171 static void remove_handler(Fl_Shared_Handler f);
172
194 const Fl_Image *image() const { return image_; }
195
196}; // class Fl_Shared_Image
197
198//
199// The following function is provided in the fltk_images library and
200// registers all of the "extra" image file formats that are not part
201// of the core FLTK library...
202//
203
204FL_EXPORT extern void fl_register_images();
205
206#endif // !Fl_Shared_Image_H
unsigned int Fl_Color
An FLTK color value; see also Colors
Definition Enumerations.H:1101
Fl_Image, Fl_RGB_Image classes.
void fl_register_images()
Register the known image formats.
Definition fl_images_core.cxx:61
Fl_Image *(* Fl_Shared_Handler)(const char *name, uchar *header, int headerlen)
Test function (typedef) for adding new shared image formats.
Definition Fl_Shared_Image.H:71
Base class for image caching, scaling and drawing.
Definition Fl_Image.H:60
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:62
virtual void desaturate()
The desaturate() method converts an image to grayscale.
Definition Fl_Image.cxx:140
virtual void color_average(Fl_Color c, float i)
The color_average() method averages the colors in the image with the provided FLTK color value.
Definition Fl_Image.cxx:128
int w() const
Returns the current image drawing width in FLTK units.
Definition Fl_Image.H:131
Fl_Image * copy() const
Creates a copy of the image in the same size.
Definition Fl_Image.H:266
virtual void release()
Releases an Fl_Image - the same as 'delete this'.
Definition Fl_Image.H:220
int h() const
Returns the current image drawing height in FLTK units.
Definition Fl_Image.H:137
virtual void uncache()
If the image has been cached for display, delete the cache data.
Definition Fl_Image.cxx:59
The Fl_JPEG_Image class supports loading, caching, and drawing of Joint Photographic Experts Group (J...
Definition Fl_JPEG_Image.H:30
The Fl_PNG_Image class supports loading, caching, and drawing of Portable Network Graphics (PNG) imag...
Definition Fl_PNG_Image.H:30
The Fl_RGB_Image class supports caching and drawing of full-color images with 1 to 4 channels of colo...
Definition Fl_Image.H:339
The Fl_SVG_Image class supports loading, caching and drawing of scalable vector graphics (SVG) images...
Definition Fl_SVG_Image.H:135
This class supports caching, loading, and drawing of image files.
Definition Fl_Shared_Image.H:94
const char * name()
Returns the filename of the shared image.
Definition Fl_Shared_Image.H:132
int original()
Returns whether this is an original image.
Definition Fl_Shared_Image.H:146
int refcount()
Returns the number of references of this shared image.
Definition Fl_Shared_Image.H:137
#define FL_OVERRIDE
This macro makes it safe to use the C++11 keyword override with older compilers.
Definition fl_attr.h:46
unsigned char uchar
unsigned char
Definition fl_types.h:30