blob: eb1e7e3fc14bc98333ea16e471c38bb8a77fb7c5 [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;
37struct Fl_Menu_Item;
38struct Fl_Label;
39
40/**
41 Fl_Image is the base class used for caching and
42 drawing all kinds of images in FLTK. This class keeps track of
43 common image data such as the pixels, colormap, width, height,
44 and depth. Virtual methods are used to provide type-specific
45 image handling.</P>
46
47 <P>Since the Fl_Image class does not support image
48 drawing by itself, calling the draw() method results in
49 a box with an X in it being drawn instead.
50*/
51class FL_EXPORT Fl_Image {
52 int w_, h_, d_, ld_, count_;
53 const char * const *data_;
54
55 // Forbid use of copy contructor and assign operator
56 Fl_Image & operator=(const Fl_Image &);
57 Fl_Image(const Fl_Image &);
58
59 protected:
60
61 /**
62 Sets the current image width in pixels.
63 */
64 void w(int W) {w_ = W;}
65 /**
66 Sets the current image height in pixels.
67 */
68 void h(int H) {h_ = H;}
69 /**
70 Sets the current image depth.
71 */
72 void d(int D) {d_ = D;}
73 /**
74 Sets the current line data size in bytes.
75 */
76 void ld(int LD) {ld_ = LD;}
77 /**
78 Sets the current array pointer and count of pointers in the array.
79 */
80 void data(const char * const *p, int c) {data_ = p; count_ = c;}
81 void draw_empty(int X, int Y);
82
83 static void labeltype(const Fl_Label *lo, int lx, int ly, int lw, int lh, Fl_Align la);
84 static void measure(const Fl_Label *lo, int &lw, int &lh);
85
86 public:
87
88 /**
89 Returns the current image width in pixels.
90 */
91 int w() const {return w_;}
92 /** Returns the current image height in pixels.
93 */
94 int h() const {return h_;}
95 /**
96 Returns the current image depth.
97 The return value will be 0 for bitmaps, 1 for
98 pixmaps, and 1 to 4 for color images.</P>
99 */
100 int d() const {return d_;}
101 /**
102 Returns the current line data size in bytes.
103 Line data is extra data that is included
104 after each line of color image data and is normally not present.
105 */
106 int ld() const {return ld_;}
107 /**
108 The count() method returns the number of data values
109 associated with the image. The value will be 0 for images with
110 no associated data, 1 for bitmap and color images, and greater
111 than 2 for pixmap images.
112 */
113 int count() const {return count_;}
114 /**
115 Returns a pointer to the current image data array.
116 Use the count() method to find the size of the data array.
117 */
118 const char * const *data() const {return data_;}
119
120 /**
121 The constructor creates an empty image with the specified
122 width, height, and depth. The width and height are in pixels.
123 The depth is 0 for bitmaps, 1 for pixmap (colormap) images, and
124 1 to 4 for color images.
125 */
126 Fl_Image(int W, int H, int D) {w_ = W; h_ = H; d_ = D; ld_ = 0; count_ = 0; data_ = 0;}
127 virtual ~Fl_Image();
128 virtual Fl_Image *copy(int W, int H);
129 /**
130 The copy() method creates a copy of the specified
131 image. If the width and height are provided, the image is
132 resized to the specified size. The image should be deleted (or in
133 the case of Fl_Shared_Image, released) when you are done
134 with it.
135 */
136 Fl_Image *copy() { return copy(w(), h()); }
137 virtual void color_average(Fl_Color c, float i);
138 /**
139 The inactive() method calls
140 color_average(FL_BACKGROUND_COLOR, 0.33f) to produce
141 an image that appears grayed out. <I>This method does not
142 alter the original image data.</I>
143 */
144 void inactive() { color_average(FL_GRAY, .33f); }
145 virtual void desaturate();
146 virtual void label(Fl_Widget*w);
147 virtual void label(Fl_Menu_Item*m);
148 /**
149 Draws the image with a bounding box.
150 This form specifies
151 a bounding box for the image, with the origin
152 (upper-lefthand corner) of the image offset by the cx
153 and cy arguments.
154 */
155 virtual void draw(int X, int Y, int W, int H, int cx=0, int cy=0); // platform dependent
156 /**
157 Draws the image.
158 This form specifies the upper-lefthand corner of the image.
159 */
160 void draw(int X, int Y) {draw(X, Y, w(), h(), 0, 0);} // platform dependent
161 virtual void uncache();
162};
163
164/**
165 The Fl_RGB_Image class supports caching and drawing
166 of full-color images with 1 to 4 channels of color information.
167 Images with an even number of channels are assumed to contain
168 alpha information, which is used to blend the image with the
169 contents of the screen.</P>
170
171 <P>Fl_RGB_Image is defined in
172 &lt;FL/Fl_Image.H&gt;, however for compatibility reasons
173 &lt;FL/Fl_RGB_Image.H&gt; should be included.
174*/
175class FL_EXPORT Fl_RGB_Image : public Fl_Image {
176 friend class Fl_Quartz_Graphics_Driver;
177 friend class Fl_GDI_Graphics_Driver;
178 friend class Fl_Xlib_Graphics_Driver;
179public:
180
181 const uchar *array;
182 int alloc_array; // Non-zero if array was allocated
183
184 private:
185
186#if defined(__APPLE__) || defined(WIN32)
187 void *id_; // for internal use
188 void *mask_; // for internal use (mask bitmap)
189#else
190 unsigned id_; // for internal use
191 unsigned mask_; // for internal use (mask bitmap)
192#endif // __APPLE__ || WIN32
193
194 public:
195
196/** The constructor creates a new image from the specified data. */
197 Fl_RGB_Image(const uchar *bits, int W, int H, int D=3, int LD=0) :
198 Fl_Image(W,H,D), array(bits), alloc_array(0), id_(0), mask_(0) {data((const char **)&array, 1); ld(LD);}
199 virtual ~Fl_RGB_Image();
200 virtual Fl_Image *copy(int W, int H);
201 Fl_Image *copy() { return copy(w(), h()); }
202 virtual void color_average(Fl_Color c, float i);
203 virtual void desaturate();
204 virtual void draw(int X, int Y, int W, int H, int cx=0, int cy=0);
205 void draw(int X, int Y) {draw(X, Y, w(), h(), 0, 0);}
206 virtual void label(Fl_Widget*w);
207 virtual void label(Fl_Menu_Item*m);
208 virtual void uncache();
209};
210
211#endif // !Fl_Image_H
212
213//
214// End of "$Id: Fl_Image.H 8338 2011-01-30 09:24:40Z manolo $".
215//