blob: 8be991a58537e385f2fe3a080c6e1c933e440e6d [file] [log] [blame]
DRC2ff39b82011-07-28 08:38:59 +00001//
2// "$Id: Fl_Image.H 8338 2011-01-30 09:24:40Z manolo $"
3//
4// Image header file for the Fast Light Tool Kit (FLTK).
5//
6// Copyright 1998-2011 by Bill Spitzak and others.
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Library General Public
10// License as published by the Free Software Foundation; either
11// version 2 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// Library General Public License for more details.
17//
18// You should have received a copy of the GNU Library General Public
19// License along with this library; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21// USA.
22//
23// Please report all bugs and problems on the following page:
24//
25// http://www.fltk.org/str.php
26//
27
28/* \file
29 Fl_Image, Fl_RGB_Image classes . */
30
31#ifndef Fl_Image_H
32# define Fl_Image_H
33
34# include "Enumerations.H"
35
36class Fl_Widget;
DRC685f17e2011-07-28 09:23:00 +000037class Fl_Pixmap;
DRC2ff39b82011-07-28 08:38:59 +000038struct Fl_Menu_Item;
39struct Fl_Label;
40
41/**
42 Fl_Image is the base class used for caching and
43 drawing all kinds of images in FLTK. This class keeps track of
44 common image data such as the pixels, colormap, width, height,
45 and depth. Virtual methods are used to provide type-specific
46 image handling.</P>
47
48 <P>Since the Fl_Image class does not support image
49 drawing by itself, calling the draw() method results in
50 a box with an X in it being drawn instead.
51*/
52class FL_EXPORT Fl_Image {
53 int w_, h_, d_, ld_, count_;
54 const char * const *data_;
55
56 // Forbid use of copy contructor and assign operator
57 Fl_Image & operator=(const Fl_Image &);
58 Fl_Image(const Fl_Image &);
59
60 protected:
61
62 /**
63 Sets the current image width in pixels.
64 */
65 void w(int W) {w_ = W;}
66 /**
67 Sets the current image height in pixels.
68 */
69 void h(int H) {h_ = H;}
70 /**
71 Sets the current image depth.
72 */
73 void d(int D) {d_ = D;}
74 /**
75 Sets the current line data size in bytes.
76 */
77 void ld(int LD) {ld_ = LD;}
78 /**
79 Sets the current array pointer and count of pointers in the array.
80 */
81 void data(const char * const *p, int c) {data_ = p; count_ = c;}
82 void draw_empty(int X, int Y);
83
84 static void labeltype(const Fl_Label *lo, int lx, int ly, int lw, int lh, Fl_Align la);
85 static void measure(const Fl_Label *lo, int &lw, int &lh);
86
87 public:
88
89 /**
90 Returns the current image width in pixels.
91 */
92 int w() const {return w_;}
93 /** Returns the current image height in pixels.
94 */
95 int h() const {return h_;}
96 /**
97 Returns the current image depth.
98 The return value will be 0 for bitmaps, 1 for
99 pixmaps, and 1 to 4 for color images.</P>
100 */
101 int d() const {return d_;}
102 /**
103 Returns the current line data size in bytes.
104 Line data is extra data that is included
105 after each line of color image data and is normally not present.
106 */
107 int ld() const {return ld_;}
108 /**
109 The count() method returns the number of data values
110 associated with the image. The value will be 0 for images with
111 no associated data, 1 for bitmap and color images, and greater
112 than 2 for pixmap images.
113 */
114 int count() const {return count_;}
115 /**
116 Returns a pointer to the current image data array.
117 Use the count() method to find the size of the data array.
118 */
119 const char * const *data() const {return data_;}
120
121 /**
122 The constructor creates an empty image with the specified
123 width, height, and depth. The width and height are in pixels.
124 The depth is 0 for bitmaps, 1 for pixmap (colormap) images, and
125 1 to 4 for color images.
126 */
127 Fl_Image(int W, int H, int D) {w_ = W; h_ = H; d_ = D; ld_ = 0; count_ = 0; data_ = 0;}
128 virtual ~Fl_Image();
129 virtual Fl_Image *copy(int W, int H);
130 /**
131 The copy() method creates a copy of the specified
132 image. If the width and height are provided, the image is
133 resized to the specified size. The image should be deleted (or in
134 the case of Fl_Shared_Image, released) when you are done
135 with it.
136 */
137 Fl_Image *copy() { return copy(w(), h()); }
138 virtual void color_average(Fl_Color c, float i);
139 /**
140 The inactive() method calls
141 color_average(FL_BACKGROUND_COLOR, 0.33f) to produce
142 an image that appears grayed out. <I>This method does not
143 alter the original image data.</I>
144 */
145 void inactive() { color_average(FL_GRAY, .33f); }
146 virtual void desaturate();
147 virtual void label(Fl_Widget*w);
148 virtual void label(Fl_Menu_Item*m);
149 /**
150 Draws the image with a bounding box.
151 This form specifies
152 a bounding box for the image, with the origin
153 (upper-lefthand corner) of the image offset by the cx
154 and cy arguments.
155 */
156 virtual void draw(int X, int Y, int W, int H, int cx=0, int cy=0); // platform dependent
157 /**
158 Draws the image.
159 This form specifies the upper-lefthand corner of the image.
160 */
161 void draw(int X, int Y) {draw(X, Y, w(), h(), 0, 0);} // platform dependent
162 virtual void uncache();
163};
164
165/**
166 The Fl_RGB_Image class supports caching and drawing
167 of full-color images with 1 to 4 channels of color information.
168 Images with an even number of channels are assumed to contain
169 alpha information, which is used to blend the image with the
170 contents of the screen.</P>
171
172 <P>Fl_RGB_Image is defined in
173 &lt;FL/Fl_Image.H&gt;, however for compatibility reasons
174 &lt;FL/Fl_RGB_Image.H&gt; should be included.
175*/
176class FL_EXPORT Fl_RGB_Image : public Fl_Image {
177 friend class Fl_Quartz_Graphics_Driver;
178 friend class Fl_GDI_Graphics_Driver;
179 friend class Fl_Xlib_Graphics_Driver;
180public:
181
182 const uchar *array;
183 int alloc_array; // Non-zero if array was allocated
184
185 private:
186
187#if defined(__APPLE__) || defined(WIN32)
188 void *id_; // for internal use
189 void *mask_; // for internal use (mask bitmap)
190#else
191 unsigned id_; // for internal use
192 unsigned mask_; // for internal use (mask bitmap)
193#endif // __APPLE__ || WIN32
194
195 public:
196
197/** The constructor creates a new image from the specified data. */
198 Fl_RGB_Image(const uchar *bits, int W, int H, int D=3, int LD=0) :
199 Fl_Image(W,H,D), array(bits), alloc_array(0), id_(0), mask_(0) {data((const char **)&array, 1); ld(LD);}
DRC685f17e2011-07-28 09:23:00 +0000200 Fl_RGB_Image(const Fl_Pixmap *pxm, Fl_Color bg=FL_GRAY);
DRC2ff39b82011-07-28 08:38:59 +0000201 virtual ~Fl_RGB_Image();
202 virtual Fl_Image *copy(int W, int H);
203 Fl_Image *copy() { return copy(w(), h()); }
204 virtual void color_average(Fl_Color c, float i);
205 virtual void desaturate();
206 virtual void draw(int X, int Y, int W, int H, int cx=0, int cy=0);
207 void draw(int X, int Y) {draw(X, Y, w(), h(), 0, 0);}
208 virtual void label(Fl_Widget*w);
209 virtual void label(Fl_Menu_Item*m);
210 virtual void uncache();
211};
212
213#endif // !Fl_Image_H
214
215//
216// End of "$Id: Fl_Image.H 8338 2011-01-30 09:24:40Z manolo $".
217//