Fl_Shared_Image.H 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // "$Id: Fl_Shared_Image.H 8864 2011-07-19 04:49:30Z greg.ercolano $"
  3. //
  4. // Shared 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. Distribution and use rights are outlined in
  9. // the file "COPYING" which should have been included with this file. If this
  10. // file is missing or damaged, see the license at:
  11. //
  12. // http://www.fltk.org/COPYING.php
  13. //
  14. // Please report all bugs and problems on the following page:
  15. //
  16. // http://www.fltk.org/str.php
  17. //
  18. /** \file
  19. Fl_Shared_Image class. */
  20. #ifndef Fl_Shared_Image_H
  21. # define Fl_Shared_Image_H
  22. # include "Fl_Image.H"
  23. // Test function for adding new formats
  24. typedef Fl_Image *(*Fl_Shared_Handler)(const char *name, uchar *header,
  25. int headerlen);
  26. // Shared images class.
  27. /**
  28. This class supports caching, loading,
  29. and drawing of image files. Most applications will also want to
  30. link against the fltk_images library and call the
  31. fl_register_images()
  32. function to support standard image formats such as BMP, GIF, JPEG, and PNG.
  33. */
  34. class FL_EXPORT Fl_Shared_Image : public Fl_Image {
  35. friend class Fl_JPEG_Image;
  36. friend class Fl_PNG_Image;
  37. protected:
  38. static Fl_Shared_Image **images_; // Shared images
  39. static int num_images_; // Number of shared images
  40. static int alloc_images_; // Allocated shared images
  41. static Fl_Shared_Handler *handlers_; // Additional format handlers
  42. static int num_handlers_; // Number of format handlers
  43. static int alloc_handlers_; // Allocated format handlers
  44. const char *name_; // Name of image file
  45. int original_; // Original image?
  46. int refcount_; // Number of times this image has been used
  47. Fl_Image *image_; // The image that is shared
  48. int alloc_image_; // Was the image allocated?
  49. static int compare(Fl_Shared_Image **i0, Fl_Shared_Image **i1);
  50. // Use get() and release() to load/delete images in memory...
  51. Fl_Shared_Image();
  52. Fl_Shared_Image(const char *n, Fl_Image *img = 0);
  53. virtual ~Fl_Shared_Image();
  54. void add();
  55. void update();
  56. public:
  57. /** Returns the filename of the shared image */
  58. const char *name() { return name_; }
  59. /** Returns the number of references of this shared image. When reference is below 1, the image is deleted. */
  60. int refcount() { return refcount_; }
  61. void release();
  62. void reload();
  63. virtual Fl_Image *copy(int W, int H);
  64. Fl_Image *copy() { return copy(w(), h()); }
  65. virtual void color_average(Fl_Color c, float i);
  66. virtual void desaturate();
  67. virtual void draw(int X, int Y, int W, int H, int cx, int cy);
  68. void draw(int X, int Y) { draw(X, Y, w(), h(), 0, 0); }
  69. virtual void uncache();
  70. static Fl_Shared_Image *find(const char *n, int W = 0, int H = 0);
  71. static Fl_Shared_Image *get(const char *n, int W = 0, int H = 0);
  72. static Fl_Shared_Image **images();
  73. static int num_images();
  74. static void add_handler(Fl_Shared_Handler f);
  75. static void remove_handler(Fl_Shared_Handler f);
  76. DECLARE_CLASS_CHEAP_RTTI_2(Fl_Shared_Image, Fl_Image)
  77. };
  78. //
  79. // The following function is provided in the fltk_images library and
  80. // registers all of the "extra" image file formats that are not part
  81. // of the core FLTK library...
  82. //
  83. FL_EXPORT extern void fl_register_images();
  84. #endif // !Fl_Shared_Image_H
  85. //
  86. // End of "$Id: Fl_Shared_Image.H 8864 2011-07-19 04:49:30Z greg.ercolano $"
  87. //