summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2002-03-29 11:59:56 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>2002-03-29 11:59:56 +0000
commit2deb2fdfc969a925542a3c069e676426174cc07a (patch)
treee55b372893f582227766322694e28688f2df8e2d /src
parented47c6972b17941bade9cb56a5287ac22e528f50 (diff)
Add image handler to Fl_Shared_Image class to support additional file
formats. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2048 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Shared_Image.cxx78
1 files changed, 74 insertions, 4 deletions
diff --git a/src/Fl_Shared_Image.cxx b/src/Fl_Shared_Image.cxx
index 623e80967..ff7f9b8f5 100644
--- a/src/Fl_Shared_Image.cxx
+++ b/src/Fl_Shared_Image.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_Shared_Image.cxx,v 1.23.2.7 2002/01/06 17:51:12 easysw Exp $"
+// "$Id: Fl_Shared_Image.cxx,v 1.23.2.8 2002/03/29 11:59:56 easysw Exp $"
//
// Shared image code for the Fast Light Tool Kit (FLTK).
//
@@ -46,6 +46,10 @@ Fl_Shared_Image **Fl_Shared_Image::images_ = 0; // Shared images
int Fl_Shared_Image::num_images_ = 0; // Number of shared images
int Fl_Shared_Image::alloc_images_ = 0; // Allocated shared images
+Fl_Shared_Handler **Fl_Shared_Image::handlers_; // Additional format handlers
+int Fl_Shared_Image::num_handlers_; // Number of format handlers
+int Fl_Shared_Image::alloc_handlers_; // Allocated format handlers
+
//
// Typedef the C API sort function type the only way I know how...
@@ -204,6 +208,7 @@ Fl_Shared_Image::release() {
void
Fl_Shared_Image::reload() {
// Load image from disk...
+ int i; // Looping var
FILE *fp; // File pointer
uchar header[16]; // Buffer for auto-detecting files
Fl_Image *img; // New image
@@ -234,8 +239,14 @@ Fl_Shared_Image::reload() {
img = new Fl_XBM_Image(name_);
else if (memcmp(header, "/* XPM */", 9) == 0) // XPM file
img = new Fl_XPM_Image(name_);
- else
- img = 0;
+ else {
+ // Not a standard format; try an image handler...
+ for (i = 0, img = 0; i < num_handlers_; i ++) {
+ img = (*(handlers_[i]))(name_, header, sizeof(header));
+
+ if (img) break;
+ }
+ }
if (img) {
if (alloc_image_) delete image_;
@@ -385,5 +396,64 @@ Fl_Shared_Image::get(const char *n, int W, int H) {
//
-// End of "$Id: Fl_Shared_Image.cxx,v 1.23.2.7 2002/01/06 17:51:12 easysw Exp $".
+// 'Fl_Shared_Image::add_handler()' - Add a shared image handler.
+//
+
+void
+Fl_Shared_Image::add_handler(Fl_Shared_Handler *f) {
+ int i; // Looping var...
+ Fl_Shared_Handler **temp; // New image handler array...
+
+ // First see if we have already added the handler...
+ for (i = 0; i < num_handlers_; i ++) {
+ if (handlers_[i] == f) return;
+ }
+
+ if (num_handlers_ >= alloc_handlers_) {
+ // Allocate more memory...
+ temp = new Fl_Shared_Handler *[alloc_handlers_ + 32];
+
+ if (alloc_handlers_) {
+ memcpy(temp, handlers_, alloc_handlers_ * sizeof(Fl_Shared_Handler *));
+
+ delete[] handlers_;
+ }
+
+ handlers_ = temp;
+ alloc_handlers_ += 32;
+ }
+
+ handlers_[num_handlers_] = f;
+ num_handlers_ ++;
+}
+
+
+//
+// 'Fl_Shared_Image::remove_handler()' - Remove a shared image handler.
+//
+
+void
+Fl_Shared_Image::remove_handler(Fl_Shared_Handler *f) {
+ int i; // Looping var...
+
+ // First see if the handler has been added...
+ for (i = 0; i < num_handlers_; i ++) {
+ if (handlers_[i] == f) break;
+ }
+
+ if (i >= num_handlers_) return;
+
+ // OK, remove the handler from the array...
+ num_handlers_ --;
+
+ if (i < num_handlers_) {
+ // Shift later handlers down 1...
+ memcpy(handlers_ + i, handlers_ + i + 1,
+ (num_handlers_ - i) * sizeof(Fl_Shared_Handler *));
+ }
+}
+
+
+//
+// End of "$Id: Fl_Shared_Image.cxx,v 1.23.2.8 2002/03/29 11:59:56 easysw Exp $".
//