FLTK 1.4.0
Loading...
Searching...
No Matches
Fl_Image.H
Go to the documentation of this file.
1//
2// Image header file for the Fast Light Tool Kit (FLTK).
3//
4// Copyright 1998-2022 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_Image_H
21#define Fl_Image_H
22
23#include "Enumerations.H"
24#include "Fl_Widget.H" // for fl_uintptr_t
25
26class Fl_Widget;
27class Fl_Pixmap;
28struct Fl_Menu_Item;
29struct Fl_Label;
30class Fl_RGB_Image;
31
32
40
41
60class FL_EXPORT Fl_Image {
61 friend class Fl_Graphics_Driver;
62public:
63 static const int ERR_NO_IMAGE = -1;
64 static const int ERR_FILE_ACCESS = -2;
65 static const int ERR_FORMAT = -3;
66 static const int ERR_MEMORY_ACCESS = -4;
67
68private:
69 int w_, h_, d_, ld_, count_;
70 int data_w_, data_h_;
71 const char * const *data_;
72 static Fl_RGB_Scaling RGB_scaling_; // method used when copying RGB images
73 static Fl_RGB_Scaling scaling_algorithm_; // method used to rescale RGB source images before drawing
74 // Forbid use of copy constructor and assign operator
75 Fl_Image & operator=(const Fl_Image &);
76 Fl_Image(const Fl_Image &);
77 // Presently redefined in Fl_SVG_Image
78 virtual void cache_size_(int &/*width*/, int &/*height*/) {}
79
80protected:
81
87 void w(int W) {w_ = W; data_w_ = W;}
93 void h(int H) {h_ = H; data_h_ = H;}
97 void d(int D) {d_ = D;}
109 void ld(int LD) {ld_ = LD;}
117 void data(const char * const *p, int c) {data_ = p; count_ = c;}
118 void draw_empty(int X, int Y);
119
120 static void labeltype(const Fl_Label *lo, int lx, int ly, int lw, int lh, Fl_Align la);
121 static void measure(const Fl_Label *lo, int &lw, int &lh);
122 int draw_scaled(int X, int Y, int W, int H);
123
124public:
125
131 int w() const {return w_;}
137 int h() const {return h_;}
141 int data_w() const {return data_w_;}
145 int data_h() const {return data_h_;}
151 int d() const {return d_;}
156 int ld() const {return ld_;}
165 int count() const {return count_;}
191 const char * const *data() const {return data_;}
192 int fail() const;
220 virtual void release() {
221 delete this;
222 }
223
234 return 0;
235 }
236
237 Fl_Image(int W, int H, int D);
238 virtual ~Fl_Image();
239 virtual Fl_Image *copy(int W, int H) const;
266 Fl_Image *copy() const { return copy(w(), h()); }
267 virtual void color_average(Fl_Color c, float i);
279 void inactive() { color_average(FL_GRAY, .33f); }
280 virtual void desaturate();
281 virtual void label(Fl_Widget*w);
282 virtual void label(Fl_Menu_Item*m);
294 virtual void draw(int X, int Y, int W, int H, int cx=0, int cy=0); // platform dependent
299 void draw(int X, int Y) {draw(X, Y, w(), h(), 0, 0);} // platform dependent
300 virtual void uncache();
301
302 // used by fl_define_FL_IMAGE_LABEL() to avoid 'friend' declaration
303 static Fl_Labeltype define_FL_IMAGE_LABEL();
304
305 // set RGB image scaling method
306 static void RGB_scaling(Fl_RGB_Scaling);
307 // get RGB image scaling method
308 static Fl_RGB_Scaling RGB_scaling();
309
310 // set the image drawing size
311 virtual void scale(int width, int height, int proportional = 1, int can_expand = 0);
320 static void scaling_algorithm(Fl_RGB_Scaling algorithm) {scaling_algorithm_ = algorithm; }
322 static Fl_RGB_Scaling scaling_algorithm() {return scaling_algorithm_;}
324};
325
326class Fl_SVG_Image;
327
339class FL_EXPORT Fl_RGB_Image : public Fl_Image {
340 friend class Fl_Graphics_Driver;
341 static size_t max_size_;
342public:
343
347 const uchar *array;
351
352private:
353 // These two variables are used to cache the image and mask for the main display graphics driver
354 fl_uintptr_t id_;
355 fl_uintptr_t mask_;
356 int cache_w_, cache_h_; // size of image when cached
357public:
358
359 Fl_RGB_Image(const uchar *bits, int W, int H, int D=3, int LD=0);
360 Fl_RGB_Image(const uchar *bits, int bits_length, int W, int H, int D, int LD);
361 Fl_RGB_Image(const Fl_Pixmap *pxm, Fl_Color bg=FL_GRAY);
363 Fl_Image *copy(int W, int H) const FL_OVERRIDE;
364 Fl_Image *copy() const { return Fl_Image::copy(); }
365 void color_average(Fl_Color c, float i) FL_OVERRIDE;
366 void desaturate() FL_OVERRIDE;
367 void draw(int X, int Y, int W, int H, int cx=0, int cy=0) FL_OVERRIDE;
368 void draw(int X, int Y) {draw(X, Y, w(), h(), 0, 0);}
369 void label(Fl_Widget*w) FL_OVERRIDE;
370 void label(Fl_Menu_Item*m) FL_OVERRIDE;
371 void uncache() FL_OVERRIDE;
372 int cache_w() {return cache_w_;}
373 int cache_h() {return cache_h_;}
383 static void max_size(size_t size) { max_size_ = size;}
388 static size_t max_size() {return max_size_;}
391 virtual Fl_SVG_Image *as_svg_image() { return NULL; }
394 virtual void normalize() {}
395};
396
397#endif // !Fl_Image_H
This file contains type definitions and general enumerations.
unsigned Fl_Align
FLTK type for alignment control.
Definition Enumerations.H:967
unsigned int Fl_Color
An FLTK color value; see also Colors
Definition Enumerations.H:1101
Fl_Labeltype
The labeltype() method sets the type of the label.
Definition Enumerations.H:816
Fl_RGB_Scaling
The scaling algorithm to use for RGB images.
Definition Fl_Image.H:36
@ FL_RGB_SCALING_NEAREST
default RGB image scaling algorithm
Definition Fl_Image.H:37
@ FL_RGB_SCALING_BILINEAR
more accurate, but slower RGB image scaling algorithm
Definition Fl_Image.H:38
Fl_Widget and Fl_Label classes.
Base class for image caching, scaling and drawing.
Definition Fl_Image.H:60
int count() const
Returns the number of data values associated with the image.
Definition Fl_Image.H:165
void d(int D)
Sets the current image depth.
Definition Fl_Image.H:97
void draw(int X, int Y)
Draws the image to the current drawing surface.
Definition Fl_Image.H:299
static void scaling_algorithm(Fl_RGB_Scaling algorithm)
Sets what algorithm is used when resizing a source image to draw it.
Definition Fl_Image.H:320
void data(const char *const *p, int c)
Sets the current data pointer and count of pointers in the array.
Definition Fl_Image.H:117
const char *const * data() const
Returns a pointer to the current image data array.
Definition Fl_Image.H:191
int data_h() const
Returns the height of the image data.
Definition Fl_Image.H:145
void h(int H)
Sets the height of the image data.
Definition Fl_Image.H:93
int w() const
Returns the current image drawing width in FLTK units.
Definition Fl_Image.H:131
virtual class Fl_Shared_Image * as_shared_image()
Returns whether an image is an Fl_Shared_Image or not.
Definition Fl_Image.H:233
void ld(int LD)
Sets the current line data size in bytes.
Definition Fl_Image.H:109
Fl_Image * copy() const
Creates a copy of the image in the same size.
Definition Fl_Image.H:266
static Fl_RGB_Scaling scaling_algorithm()
Gets what algorithm is used when resizing a source image to draw it.
Definition Fl_Image.H:322
virtual void release()
Releases an Fl_Image - the same as 'delete this'.
Definition Fl_Image.H:220
int data_w() const
Returns the width of the image data.
Definition Fl_Image.H:141
void w(int W)
Sets the width of the image data.
Definition Fl_Image.H:87
static bool register_images_done
True after fl_register_images() was called, false before.
Definition Fl_Image.H:323
int ld() const
Returns the current line data size in bytes.
Definition Fl_Image.H:156
void inactive()
The inactive() method calls color_average(FL_BACKGROUND_COLOR, 0.33f) to produce an image that appear...
Definition Fl_Image.H:279
int h() const
Returns the current image drawing height in FLTK units.
Definition Fl_Image.H:137
int d() const
Returns the image depth.
Definition Fl_Image.H:151
The Fl_Pixmap class supports caching and drawing of colormap (pixmap) images, including transparency.
Definition Fl_Pixmap.H:36
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
const uchar * array
Points to the start of the object's data array.
Definition Fl_Image.H:347
virtual Fl_SVG_Image * as_svg_image()
Returns whether an image is an Fl_SVG_Image or not.
Definition Fl_Image.H:391
static size_t max_size()
Returns the maximum allowed image size in bytes when creating an Fl_RGB_Image object.
Definition Fl_Image.H:388
int alloc_array
If non-zero, the object's data array is delete[]'d when deleting the object.
Definition Fl_Image.H:350
virtual void normalize()
Makes sure the object is fully initialized.
Definition Fl_Image.H:394
static void max_size(size_t size)
Sets the maximum allowed image size in bytes when creating an Fl_RGB_Image object.
Definition Fl_Image.H:383
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
Fl_Widget is the base class for all widgets in FLTK.
Definition Fl_Widget.H:104
#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
opaque fl_uintptr_t
An unsigned integral type large enough to store a pointer or an unsigned long value.
Definition platform_types.h:36
This struct stores all information for a text or mixed graphics label.
Definition Fl_Widget.H:49
The Fl_Menu_Item structure defines a single menu item that is used by the Fl_Menu_ class.
Definition Fl_Menu_Item.H:115