Fl_Image.H 7.5 KB

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