FLTK
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-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_Image_H
21 #define Fl_Image_H
22 
23 #include "Enumerations.H"
24 #include <stdlib.h>
25 #include "Fl_Widget.H" // for fl_uintptr_t
26 
27 class Fl_Widget;
28 class Fl_Pixmap;
29 struct Fl_Menu_Item;
30 struct Fl_Label;
31 class Fl_RGB_Image;
32 
33 
40 };
41 
42 
62 class FL_EXPORT Fl_Image {
63  friend class Fl_Graphics_Driver;
64 public:
65  static const int ERR_NO_IMAGE = -1;
66  static const int ERR_FILE_ACCESS = -2;
67  static const int ERR_FORMAT = -3;
68 
69 private:
70  int w_, h_, d_, ld_, count_;
71  int data_w_, data_h_;
72  const char * const *data_;
73  static Fl_RGB_Scaling RGB_scaling_; // method used when copying RGB images
74  static Fl_RGB_Scaling scaling_algorithm_; // method used to rescale RGB source images before drawing
75  // Forbid use of copy constructor and assign operator
76  Fl_Image & operator=(const Fl_Image &);
77  Fl_Image(const Fl_Image &);
78 
79 protected:
80 
86  void w(int W) {w_ = W; data_w_ = W;}
92  void h(int H) {h_ = H; data_h_ = H;}
96  void d(int D) {d_ = D;}
108  void ld(int LD) {ld_ = LD;}
112  void data(const char * const *p, int c) {data_ = p; count_ = c;}
113  void draw_empty(int X, int Y);
114 
115  static void labeltype(const Fl_Label *lo, int lx, int ly, int lw, int lh, Fl_Align la);
116  static void measure(const Fl_Label *lo, int &lw, int &lh);
117  int draw_scaled(int X, int Y, int W, int H);
118 
119 public:
120 
126  int w() const {return w_;}
132  int h() const {return h_;}
136  int data_w() const {return data_w_;}
140  int data_h() const {return data_h_;}
146  int d() const {return d_;}
151  int ld() const {return ld_;}
158  int count() const {return count_;}
163  const char * const *data() const {return data_;}
164  int fail();
192  virtual void release() {
193  delete this;
194  }
195 
205  virtual class Fl_Shared_Image *as_shared_image() {
206  return 0;
207  }
208 
209  Fl_Image(int W, int H, int D);
210  virtual ~Fl_Image();
211  virtual Fl_Image *copy(int W, int H);
217  Fl_Image *copy() { Fl_Image *img = copy(data_w(), data_h()); img->scale(w(), h(), 0, 1); return img;}
218  virtual void color_average(Fl_Color c, float i);
227  void inactive() { color_average(FL_GRAY, .33f); }
228  virtual void desaturate();
229  virtual void label(Fl_Widget*w);
230  virtual void label(Fl_Menu_Item*m);
242  virtual void draw(int X, int Y, int W, int H, int cx=0, int cy=0); // platform dependent
247  void draw(int X, int Y) {draw(X, Y, w(), h(), 0, 0);} // platform dependent
248  virtual void uncache();
249 
250  // used by fl_define_FL_IMAGE_LABEL() to avoid 'friend' declaration
251  static Fl_Labeltype define_FL_IMAGE_LABEL();
252 
253  // set RGB image scaling method
254  static void RGB_scaling(Fl_RGB_Scaling);
255  // get RGB image scaling method
256  static Fl_RGB_Scaling RGB_scaling();
257 
258  // set the image drawing size
259  virtual void scale(int width, int height, int proportional = 1, int can_expand = 0);
268  static void scaling_algorithm(Fl_RGB_Scaling algorithm) {scaling_algorithm_ = algorithm; }
270  static Fl_RGB_Scaling scaling_algorithm() {return scaling_algorithm_;}
271  static bool register_images_done;
272 };
273 
274 class Fl_SVG_Image;
275 
287 class FL_EXPORT Fl_RGB_Image : public Fl_Image {
288  friend class Fl_Graphics_Driver;
289  static size_t max_size_;
290 public:
291 
295  const uchar *array;
299 
300 private:
301  // These two variables are used to cache the image and mask for the main display graphics driver
302  fl_uintptr_t id_;
303  fl_uintptr_t mask_;
304  int cache_w_, cache_h_; // size of image when cached
305 
306 public:
307 
308  Fl_RGB_Image(const uchar *bits, int W, int H, int D=3, int LD=0);
309  Fl_RGB_Image(const Fl_Pixmap *pxm, Fl_Color bg=FL_GRAY);
310  virtual ~Fl_RGB_Image();
311  virtual Fl_Image *copy(int W, int H);
312  Fl_Image *copy() { return Fl_Image::copy(); }
313  virtual void color_average(Fl_Color c, float i);
314  virtual void desaturate();
315  virtual void draw(int X, int Y, int W, int H, int cx=0, int cy=0);
316  void draw(int X, int Y) {draw(X, Y, w(), h(), 0, 0);}
317  virtual void label(Fl_Widget*w);
318  virtual void label(Fl_Menu_Item*m);
319  virtual void uncache();
329  static void max_size(size_t size) { max_size_ = size;}
334  static size_t max_size() {return max_size_;}
337  virtual Fl_SVG_Image *as_svg_image() { return NULL; }
340  virtual void normalize() {}
341 };
342 
343 #endif // !Fl_Image_H
Fl_Widget is the base class for all widgets in FLTK.
Definition: Fl_Widget.H:85
void d(int D)
Sets the current image depth.
Definition: Fl_Image.H:96
virtual void desaturate()
The desaturate() method converts an image to grayscale.
Definition: Fl_Image.cxx:110
default RGB image scaling algorithm
Definition: Fl_Image.H:38
The Fl_Pixmap class supports caching and drawing of colormap (pixmap) images, including transparency...
Definition: Fl_Pixmap.H:36
int data_h() const
Returns the height of the image data.
Definition: Fl_Image.H:140
int h() const
Returns the current image drawing height in FLTK units.
Definition: Fl_Image.H:132
virtual void scale(int width, int height, int proportional=1, int can_expand=0)
Sets the drawing size of the image.
Definition: Fl_Image.cxx:259
virtual void label(Fl_Widget *w)
The label() methods are an obsolete way to set the image attribute of a widget or menu item...
Definition: Fl_Image.cxx:130
static bool register_images_done
True after fl_register_images() was called, false before.
Definition: Fl_Image.H:271
void ld(int LD)
Sets the current line data size in bytes.
Definition: Fl_Image.H:108
const char *const * data() const
Returns a pointer to the current image data array.
Definition: Fl_Image.H:163
virtual void uncache()
If the image has been cached for display, delete the cache data.
Definition: Fl_Shared_Image.cxx:377
virtual void normalize()
Makes sure the object is fully initialized.
Definition: Fl_Image.H:340
The Fl_SVG_Image class supports loading, caching and drawing of scalable vector graphics (SVG) images...
Definition: Fl_SVG_Image.H:135
virtual ~Fl_Image()
The destructor is a virtual method that frees all memory used by the image.
Definition: Fl_Image.cxx:49
Base class for image caching, scaling and drawing.
Definition: Fl_Image.H:62
int w() const
Returns the current image drawing width in FLTK units.
Definition: Fl_Image.H:126
static Fl_RGB_Scaling scaling_algorithm()
Gets what algorithm is used when resizing a source image to draw it.
Definition: Fl_Image.H:270
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
int d() const
Returns the image depth.
Definition: Fl_Image.H:146
more accurate, but slower RGB image scaling algorithm
Definition: Fl_Image.H:39
static size_t max_size()
Returns the maximum allowed image size in bytes when creating an Fl_RGB_Image object.
Definition: Fl_Image.H:334
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_Shared_Image.cxx:334
int data_w() const
Returns the width of the image data.
Definition: Fl_Image.H:136
void inactive()
The inactive() method calls color_average(FL_BACKGROUND_COLOR, 0.33f) to produce an image that appear...
Definition: Fl_Image.H:227
This file contains type definitions and general enumerations.
Fl_Image * copy()
Creates a copy of the specified image.
Definition: Fl_Image.H:217
int alloc_array
If non-zero, the object&#39;s data array is delete[]&#39;d when deleting the object.
Definition: Fl_Image.H:298
int ld() const
Returns the current line data size in bytes.
Definition: Fl_Image.H:151
opaque fl_uintptr_t
An unsigned integral type large enough to store a pointer or an unsigned long value.
Definition: platform_types.h:33
virtual class Fl_Shared_Image * as_shared_image()
Returns whether an image is an Fl_Shared_Image or not.
Definition: Fl_Image.H:205
Fl_Widget, Fl_Label classes .
int count() const
The count() method returns the number of data values associated with the image.
Definition: Fl_Image.H:158
void w(int W)
Sets the width of the image data.
Definition: Fl_Image.H:86
This struct stores all information for a text or mixed graphics label.
Definition: Fl_Widget.H:48
void h(int H)
Sets the height of the image data.
Definition: Fl_Image.H:92
virtual void release()
Releases an Fl_Image - the same as &#39;delete this&#39;.
Definition: Fl_Image.H:192
The Fl_Menu_Item structure defines a single menu item that is used by the Fl_Menu_ class...
Definition: Fl_Menu_Item.H:107
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_Labeltype
The labeltype() method sets the type of the label.
Definition: Enumerations.H:757
unsigned Fl_Align
FLTK type for alignment control.
Definition: Enumerations.H:908
void data(const char *const *p, int c)
Sets the current array pointer and count of pointers in the array.
Definition: Fl_Image.H:112
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:329
This class supports caching, loading, and drawing of image files.
Definition: Fl_Shared_Image.H:49
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:268
virtual void uncache()
If the image has been cached for display, delete the cache data.
Definition: Fl_Image.cxx:57
virtual void desaturate()
The desaturate() method converts an image to grayscale.
Definition: Fl_Shared_Image.cxx:348
static Fl_RGB_Scaling RGB_scaling()
Returns the currently used RGB image scaling method.
Definition: Fl_Image.cxx:228
void draw(int X, int Y)
Draws the image to the current drawing surface.
Definition: Fl_Image.H:247
const uchar * array
Points to the start of the object&#39;s data array.
Definition: Fl_Image.H:295
unsigned char uchar
unsigned char
Definition: fl_types.h:28
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_Shared_Image.cxx:358
Fl_RGB_Scaling
The scaling algorithm to use for RGB images.
Definition: Fl_Image.H:37
virtual Fl_SVG_Image * as_svg_image()
Returns whether an image is an Fl_SVG_Image or not.
Definition: Fl_Image.H:337