FLTK 1.4.4: Fl_Shared_Image.H Source File

FLTK 1.4.4

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
19
20#ifndef Fl_Shared_Image_H
21# define Fl_Shared_Image_H
22
23# include "Fl_Image.H"
24
25#undef SHIM_DEBUG
26
71 typedef Fl_Image *(*Fl_Shared_Handler)(const char *name,
72 uchar *header,
73 int headerlen);
74
94 class 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...
119 Fl_Shared_Image();
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
Fl_Color
unsigned int Fl_Color
An FLTK color value; see also Colors.
Definition Enumerations.H:1120
Fl_Image.H
Fl_Image, Fl_RGB_Image classes.
fl_register_images
void fl_register_images()
Register the known image formats.
Definition fl_images_core.cxx:61
Fl_Shared_Handler
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
Fl_Image
Base class for image caching, scaling and drawing.
Definition Fl_Image.H:60
Fl_Image::draw
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
Fl_Image::desaturate
virtual void desaturate()
The desaturate() method converts an image to grayscale.
Definition Fl_Image.cxx:144
Fl_Image::color_average
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:132
Fl_Image::w
int w() const
Returns the current image drawing width in FLTK units.
Definition Fl_Image.H:131
Fl_Image::copy
Fl_Image * copy() const
Creates a copy of the image in the same size.
Definition Fl_Image.H:266
Fl_Image::release
virtual void release()
Releases an Fl_Image - the same as 'delete this'.
Definition Fl_Image.H:220
Fl_Image::h
int h() const
Returns the current image drawing height in FLTK units.
Definition Fl_Image.H:137
Fl_Image::uncache
virtual void uncache()
If the image has been cached for display, delete the cache data.
Definition Fl_Image.cxx:59
Fl_Shared_Image::add
void add()
Adds a shared image to the image pool.
Definition Fl_Shared_Image.cxx:159
Fl_Shared_Image::update
void update()
Update the dimensions of the shared images.
Definition Fl_Shared_Image.cxx:191
Fl_Shared_Image::compare
static int compare(Fl_Shared_Image **i0, Fl_Shared_Image **i1)
Compares two shared images.
Definition Fl_Shared_Image.cxx:95
Fl_Shared_Image::name
const char * name()
Returns the filename of the shared image.
Definition Fl_Shared_Image.H:132
Fl_Shared_Image::copy_
Fl_Shared_Image * copy_(int W, int H) const
Create a resized copy of the image and wrap it into the share image class.
Definition Fl_Shared_Image.cxx:335
Fl_Shared_Image::Fl_Shared_Image
Fl_Shared_Image()
Creates an empty shared image.
Definition Fl_Shared_Image.cxx:114
Fl_Shared_Image::original
int original()
Returns whether this is an original image.
Definition Fl_Shared_Image.H:146
Fl_Shared_Image::as_shared_image
Fl_Shared_Image * as_shared_image() FL_OVERRIDE
Returns whether an image is an Fl_Shared_Image or not.
Definition Fl_Shared_Image.H:151
Fl_Shared_Image::image
const Fl_Image * image() const
Returns a pointer to the internal Fl_Image object.
Definition Fl_Shared_Image.H:194
Fl_Shared_Image::refcount
int refcount()
Returns the number of references of this shared image.
Definition Fl_Shared_Image.H:137
FL_OVERRIDE
#define FL_OVERRIDE
This macro makes it safe to use the C++11 keyword override with older compilers.
Definition fl_attr.h:46
uchar
unsigned char uchar
unsigned char
Definition fl_types.h:30