summaryrefslogtreecommitdiff
path: root/FL
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2001-11-24 02:46:19 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>2001-11-24 02:46:19 +0000
commit70abac1b8b995dc78ec312eb52f8724161b11b75 (patch)
tree4bf4d24e190a2a49e98c8fe3fdbecabe8c9cd2fa /FL
parent4087b8cd9a139664420468c57489cae73c8b830a (diff)
Fix bugs in copy() methods.
Add Fl_Shared_Image class, with get() and release() methods. Update Fl_Help_View to use Fl_Shared_Image class. Update image demo to accept a filename, and to use the Fl_Shared_Image class. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1714 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'FL')
-rw-r--r--FL/Fl_Help_View.H49
-rw-r--r--FL/Fl_Image.H6
-rw-r--r--FL/Fl_Shared_Image.H216
3 files changed, 60 insertions, 211 deletions
diff --git a/FL/Fl_Help_View.H b/FL/Fl_Help_View.H
index c81bb059c..d2d226121 100644
--- a/FL/Fl_Help_View.H
+++ b/FL/Fl_Help_View.H
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Help_View.H,v 1.1.2.3 2001/10/29 03:44:31 easysw Exp $"
+// "$Id: Fl_Help_View.H,v 1.1.2.4 2001/11/24 02:46:19 easysw Exp $"
//
// Help Viewer widget definitions.
//
@@ -24,18 +24,19 @@
// Please report all bugs and problems to "fltk-bugs@fltk.org".
//
-#ifndef _Fl_Help_View_H_
-# define _Fl_Help_View_H_
+#ifndef Fl_Help_View_H
+# define Fl_Help_View_H
//
// Include necessary header files...
//
# include <stdio.h>
-# include <FL/Fl.H>
-# include <FL/Fl_Group.H>
-# include <FL/Fl_Scrollbar.H>
-# include <FL/fl_draw.H>
+# include "Fl.H"
+# include "Fl_Group.H"
+# include "Fl_Scrollbar.H"
+# include "fl_draw.H"
+# include "Fl_Shared_Image.H"
//
@@ -89,23 +90,6 @@ struct Fl_Help_Target
};
//
-// Fl_Help_Image structure...
-//
-
-class Fl_Image;
-
-struct Fl_Help_Image
-{
- char *name, // Path and name of the image
- wattr[8], // Width attribute
- hattr[8]; // Height attribute
- Fl_Image *image; // FLTK image representation
- unsigned char *data; // Raw image data
- int copy; // Data is a copy?
- int w, h, d; // Image size & depth
-};
-
-//
// Fl_Help_View class...
//
@@ -145,18 +129,6 @@ class Fl_Help_View : public Fl_Group //// Help viewer widget
size_; // Total document length
Fl_Scrollbar scrollbar_; // Vertical scrollbar for document
- int nimage_, // Number of images in a page
- aimage_; // Allocated blocks
- Fl_Help_Image *image_; // list of image descriptors
-
- Fl_Help_Image *add_image(const char *name, const char *wattr,
- const char *hattr, int make = 1);
- Fl_Help_Image *find_image(const char *name, const char *wattr,
- const char *hattr);
- int load_gif(Fl_Help_Image *img, FILE *fp);
- int load_jpeg(Fl_Help_Image *img, FILE *fp);
- int load_png(Fl_Help_Image *img, FILE *fp);
-
Fl_Help_Block *add_block(const char *s, int xx, int yy, int ww, int hh, uchar border = 0);
static int compare_blocks(const void *a, const void *b);
void add_link(const char *n, int xx, int yy, int ww, int hh);
@@ -169,6 +141,7 @@ class Fl_Help_View : public Fl_Group //// Help viewer widget
int get_align(const char *p, int a);
const char *get_attr(const char *p, const char *n, char *buf, int bufsize);
Fl_Color get_color(const char *n, Fl_Color c);
+ Fl_Shared_Image *get_image(const char *name, int W, int H);
int handle(int);
void initfont(uchar &f, uchar &s) { nfonts_ = 0;
@@ -207,8 +180,8 @@ class Fl_Help_View : public Fl_Group //// Help viewer widget
const char *value() const { return (value_); }
};
-#endif // !_Fl_Help_View_H_
+#endif // !Fl_Help_View_H
//
-// End of "$Id: Fl_Help_View.H,v 1.1.2.3 2001/10/29 03:44:31 easysw Exp $".
+// End of "$Id: Fl_Help_View.H,v 1.1.2.4 2001/11/24 02:46:19 easysw Exp $".
//
diff --git a/FL/Fl_Image.H b/FL/Fl_Image.H
index 8432aaa5e..37298411d 100644
--- a/FL/Fl_Image.H
+++ b/FL/Fl_Image.H
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Image.H,v 1.5.2.3.2.5 2001/11/23 12:06:35 easysw Exp $"
+// "$Id: Fl_Image.H,v 1.5.2.3.2.6 2001/11/24 02:46:19 easysw Exp $"
//
// Image header file for the Fast Light Tool Kit (FLTK).
//
@@ -74,7 +74,7 @@ class FL_EXPORT Fl_RGB_Image : public Fl_Image {
Fl_Bitmask mask; // for internal use (mask bitmap)
Fl_RGB_Image(const uchar *bits, int W, int H, int D=3, int LD=0) :
- Fl_Image(W,H,D), array(bits), alloc_array(0), ld(LD), id(0) {data(&((char *)array), 1);}
+ Fl_Image(W,H,D), array(bits), alloc_array(0), ld(LD), id(0), mask(0) {data(&((char *)array), 1);}
virtual ~Fl_RGB_Image();
virtual Fl_Image *copy(int W, int H);
Fl_Image *copy() { return copy(w(), h()); }
@@ -89,5 +89,5 @@ class FL_EXPORT Fl_RGB_Image : public Fl_Image {
#endif
//
-// End of "$Id: Fl_Image.H,v 1.5.2.3.2.5 2001/11/23 12:06:35 easysw Exp $".
+// End of "$Id: Fl_Image.H,v 1.5.2.3.2.6 2001/11/24 02:46:19 easysw Exp $".
//
diff --git a/FL/Fl_Shared_Image.H b/FL/Fl_Shared_Image.H
index 11c5ce794..3aee366cd 100644
--- a/FL/Fl_Shared_Image.H
+++ b/FL/Fl_Shared_Image.H
@@ -1,9 +1,9 @@
//
-// "$Id: Fl_Shared_Image.H,v 1.22 2001/07/16 19:38:17 robertk Exp $"
+// "$Id: Fl_Shared_Image.H,v 1.22.2.1 2001/11/24 02:46:19 easysw Exp $"
//
-// Image file header file for the Fast Light Tool Kit (FLTK).
+// Shared image header file for the Fast Light Tool Kit (FLTK).
//
-// Copyright 1998-1999 by Bill Spitzak and others.
+// Copyright 1998-2001 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
@@ -20,184 +20,60 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
-// Please report all bugs and problems to "fltk-bugs@easysw.com".
+// Please report all bugs and problems to "fltk-bugs@fltk.org".
//
#ifndef Fl_Shared_Image_H
-#define Fl_Shared_Image_H
+# define Fl_Shared_Image_H
-#include <FL/Fl_Image.H>
-#include <stddef.h>
+# include "Fl_Image.H"
-struct FL_IMAGES_API Fl_Image_Type;
// Shared images class.
-class FL_IMAGES_API Fl_Shared_Image : public Fl_Image {
-protected:
- static const char* fl_shared_image_root;
-
- static int image_used;
- static size_t mem_usage_limit;
-
- static size_t mem_used;
- static int forbid_delete;
-
- Fl_Shared_Image* l1; // Left leaf in the binary tree
- Fl_Shared_Image* l2; // Right leaf in the binary tree
- const char* name; // Used to indentify the image, and as filename
- const uchar* datas; // If non zero, pointers on inlined compressed datas
- unsigned int used; // Last time used, for cache handling purpose
- int refcount; // Number of time this image has been get
-
- Fl_Shared_Image() { }; // Constructor is private on purpose,
- // use the get function rather
- ~Fl_Shared_Image();
-
- void find_less_used();
- static void check_mem_usage();
-
- const char* get_filename();// Return the filename obtained from the concatenation
- // of the image root directory and this image name
- // WARNING : the returned pointer will be
- // available only until next call to get_filename
-
- static const char* get_filename(const char*);
-
- virtual void read() = 0;// decompress the image and create its pixmap
-
- static void insert(Fl_Shared_Image*& p, Fl_Shared_Image* image);
- static Fl_Shared_Image* find(Fl_Shared_Image* image, const char* name);
- void remove_from_tree(Fl_Shared_Image*& p, Fl_Shared_Image* image);
-
-
-public:
- static Fl_Shared_Image *first_image;
-
- // Return an Fl_Shared_Image, using the create function if an image with
- // the given name doesn't already exist. Use datas, or read from the
- // file with filename name if datas==0.
- static Fl_Shared_Image* get(Fl_Shared_Image* (*create)(),
- const char* name, const uchar* datas=0);
-
- // Reload the image, useful if it has changed on disk, or if the datas
- // in memory have changed (you can also give a new pointer on datas)
- void reload(const uchar* datas=0);
- static void reload(const char* name, const uchar* datas=0);
-
- // Remove an image from the database and delete it if its refcount has
- // fallen to zero
- // Each remove decrement the refcount, each get increment it
- // Return 1 if it has been really deleted.
- int remove();
- static int remove(const char* name);
-
- // Clear the cache for this image and all of its children in the binary tree
- void clear_cache();
-
- // Try to guess the filetype
- // Beware that calling this force you to link in all image types !
- static Fl_Image_Type* guess(const char* name, const uchar* datas=0);
-
- // Set the position where images are looked for on disk
- static void set_root_directory(const char* d);
-
- // Set the size of the cache (0 = unlimited is the default)
- static void set_cache_size(size_t l);
-
+class Fl_Shared_Image : public Fl_Image {
+ protected:
+
+ static Fl_Shared_Image **images_; // Shared images
+ static int num_images_; // Number of shared images
+ static int alloc_images_; // Allocated shared images
+
+ const char *name_; // Name of image file
+ int original_; // Original image?
+ int refcount_; // Number of times this image has been used
+ Fl_Image *image_; // The image that is shared
+ int alloc_image_; // Was the image allocated?
+
+ static int compare(Fl_Shared_Image **i0, Fl_Shared_Image **i1);
+
+ // Use get() and release() to load/delete images in memory...
+ Fl_Shared_Image();
+ Fl_Shared_Image(const char *n, Fl_Image *img = 0);
+ virtual ~Fl_Shared_Image();
+ void add();
+ void update();
+
+ public:
+
+ const char *name() { return name_; }
+ int refcount() { return refcount_; }
+ void release();
+ void reload();
+
+ virtual Fl_Image *copy(int W, int H);
+ Fl_Image *copy() { return copy(w(), h()); }
+ virtual void color_average(Fl_Color c, float i);
+ virtual void desaturate();
virtual void draw(int X, int Y, int W, int H, int cx, int cy);
-};
-
-
-
-// Description of a file format
-struct FL_IMAGES_API Fl_Image_Type {
- // Name of the filetype as it appear in the source code (uppercase)
- const char* name;
- // Function to test the filetype
- int (*test)(const uchar* datas, size_t size=0);
- // Function to get/create an image of this type
- Fl_Shared_Image* (*get)(const char* name, const uchar* datas=0);
-};
-extern FL_IMAGES_API Fl_Image_Type fl_image_filetypes[];
-
-/* Specific image format functions. Add you own file format here. */
-
-// PNG image class
-class FL_IMAGES_API Fl_PNG_Image : public Fl_Shared_Image {
- void read(); // Uncompress PNG datas
- Fl_PNG_Image() { }
- static Fl_Shared_Image* create() { return new Fl_PNG_Image; } // Instantiate
-public:
-// Check the given buffer if it is in PNG format
- static int test(const uchar* datas, size_t size=0);
- void measure(int& W, int& H); // Return width and heigth
- static Fl_Shared_Image* get(const char* name, const uchar* datas = 0) {
- return Fl_Shared_Image::get(create, name, datas);
- }
-};
-
-class FL_IMAGES_API Fl_GIF_Image : public Fl_Shared_Image {
- void read();
- Fl_GIF_Image() { }
- static Fl_Shared_Image* create() { return new Fl_GIF_Image; }
-public:
- static int test(const uchar* datas, size_t size=0);
- void measure(int& W, int& H);
- static Fl_Shared_Image* get(const char* name, const uchar* datas = 0) {
- return Fl_Shared_Image::get(create, name, datas);
- }
-};
-
-class FL_IMAGES_API Fl_XPM_Image : public Fl_Shared_Image {
- void read();
- Fl_XPM_Image() { }
- static Fl_Shared_Image* create() { return new Fl_XPM_Image; }
-public:
- static int test(const uchar* datas, size_t size=0);
- void measure(int& W, int& H);
- static Fl_Shared_Image* get(const char* name, const uchar* datas = 0) {
- return Fl_Shared_Image::get(create, name, datas);
- }
-};
-
-class FL_IMAGES_API Fl_BMP_Image : public Fl_Shared_Image {
- void read();
- Fl_BMP_Image() { }
- static Fl_Shared_Image* create() { return new Fl_BMP_Image; }
-public:
- static int test(const uchar* datas, size_t size=0);
- void measure(int& W, int& H);
- static Fl_Shared_Image* get(const char* name, const uchar* datas = 0) {
- return Fl_Shared_Image::get(create, name, datas);
- }
-};
-
-class FL_IMAGES_API Fl_JPEG_Image : public Fl_Shared_Image {
- void read();
- Fl_JPEG_Image() { }
- static Fl_Shared_Image* create() { return new Fl_JPEG_Image; }
-public:
- static int test(const uchar* datas, size_t size=0);
- void measure(int& W, int& H);
- static Fl_Shared_Image* get(const char* name, const uchar* datas = 0) {
- return Fl_Shared_Image::get(create, name, datas);
- }
-};
-
-//class FL_API Fl_Bitmap;
-class Fl_Bitmap;
-extern FL_IMAGES_API Fl_Bitmap nosuch_bitmap;
+ void draw(int X, int Y) { draw(X, Y, w(), h(), 0, 0); }
-class FL_IMAGES_API Fl_UNKNOWN_Image {
-public:
- static int test(const uchar*, size_t =0) { return 1; };
- static Fl_Shared_Image* get(const char*, const uchar* = 0) {
- return (Fl_Shared_Image*) &nosuch_bitmap;
- };
+ static Fl_Shared_Image *find(const char *n, int W = 0, int H = 0);
+ static Fl_Shared_Image *get(const char *n, int W = 0, int H = 0);
+ static Fl_Shared_Image **images() { return images_; }
+ static int num_images() { return num_images_; }
};
-#endif
+#endif // !Fl_Shared_Image_H
//
-// End of "$Id: Fl_Shared_Image.H,v 1.22 2001/07/16 19:38:17 robertk Exp $"
+// End of "$Id: Fl_Shared_Image.H,v 1.22.2.1 2001/11/24 02:46:19 easysw Exp $"
//