summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2011-01-24 17:04:22 +0000
committerMatthias Melcher <fltk@matthiasm.com>2011-01-24 17:04:22 +0000
commitfe25f19767f1cd2393c4d1796fb42d5aa82b194c (patch)
tree229437962da4fa67acf27bf171d6124f5631c34e /src
parentf9363c16d0e6518ba82d05f1f7f415e9224a8e35 (diff)
Adding embedded documentation to Fluid if installed odcs are not found. Falls back to the internet if that does not exist either. Also, adds JPEG and PNG images to the Shared Image list if they were loaded from memory - see example use in fluid.cxx which loads and embedded html document containing an embedded PNG image.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8306 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_JPEG_Image.cxx14
-rw-r--r--src/Fl_PNG_Image.cxx24
-rw-r--r--src/Fl_Shared_Image.cxx23
3 files changed, 49 insertions, 12 deletions
diff --git a/src/Fl_JPEG_Image.cxx b/src/Fl_JPEG_Image.cxx
index fa93cf441..330618013 100644
--- a/src/Fl_JPEG_Image.cxx
+++ b/src/Fl_JPEG_Image.cxx
@@ -35,6 +35,7 @@
//
#include <FL/Fl_JPEG_Image.H>
+#include <FL/Fl_Shared_Image.H>
#include <FL/fl_utf8.h>
#include <config.h>
#include <stdio.h>
@@ -268,14 +269,18 @@ static void jpeg_mem_src(j_decompress_ptr cinfo, const unsigned char *data)
/**
\brief The constructor loads the JPEG image from memory.
+ Construct an image from a block of memory inside the application. Fluid offers
+ "binary Data" chunks as a great way to add image data into the C++ source code.
+ name_png can be NULL. If a name is givem the image is added to the the list of
+ shared images (see: Fl_Shared_Image) and will be available by that name.
+
The inherited destructor frees all memory and server resources that are used
by the image.
There is no error function in this class. If the image has loaded correctly,
w(), h(), and d() should return values greater zero.
- \param name The developer should provide a unique name for this image.
- Note: currently this is not used!
+ \param name A unique name or NULL
\param data A pointer to the memory location of the JPEG image
*/
Fl_JPEG_Image::Fl_JPEG_Image(const char *name, const unsigned char *data)
@@ -363,6 +368,11 @@ Fl_JPEG_Image::Fl_JPEG_Image(const char *name, const unsigned char *data)
free(max_destroy_decompress_err);
free(max_finish_decompress_err);
+
+ if (w() && h() && name) {
+ Fl_Shared_Image *si = new Fl_Shared_Image(name, this);
+ si->add();
+ }
#endif // HAVE_LIBJPEG
}
diff --git a/src/Fl_PNG_Image.cxx b/src/Fl_PNG_Image.cxx
index 6bf39b28c..798c08854 100644
--- a/src/Fl_PNG_Image.cxx
+++ b/src/Fl_PNG_Image.cxx
@@ -37,6 +37,7 @@
#include <FL/Fl.H>
#include <FL/Fl_PNG_Image.H>
+#include <FL/Fl_Shared_Image.H>
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
@@ -89,11 +90,17 @@ Fl_PNG_Image::Fl_PNG_Image (const char *filename): Fl_RGB_Image(0,0,0)
load_png_(filename, NULL, 0);
}
-/** Constructor that reads a PNG image from memory.
+/**
+ \brief Constructor that reads a PNG image from memory.
- \param name_png A name given to this image
+ Construct an image from a block of memory inside the application. Fluid offers
+ "binary Data" chunks as a great way to add image data into the C++ source code.
+ name_png can be NULL. If a name is givem the image is added to the the list of
+ shared images (see: Fl_Shared_Image) and will be available by that name.
+
+ \param name_png A name given to this image or NULL
\param buffer Pointer to the start of the PNG image in memory
- \param maxsize Size in bytes of the memory buffer containing the PNG image
+ \param maxsize Size in bytes of the memory buffer containing the PNG image
*/
Fl_PNG_Image::Fl_PNG_Image (
const char *name_png, const unsigned char *buffer, int maxsize): Fl_RGB_Image(0,0,0)
@@ -111,7 +118,7 @@ void Fl_PNG_Image::load_png_(const char *name_png, const unsigned char *buffer_p
png_infop info; // PNG info pointers
png_bytep *rows;// PNG row pointers
fl_png_memory png_mem_data;
- int from_memory = (buffer_png != NULL); // true iff reading image from memory
+ int from_memory = (buffer_png != NULL); // true if reading image from memory
if (!from_memory) {
if ((fp = fl_fopen(name_png, "rb")) == NULL) return;
@@ -200,7 +207,14 @@ void Fl_PNG_Image::load_png_(const char *name_png, const unsigned char *buffer_p
png_read_end(pp, info);
png_destroy_read_struct(&pp, &info, NULL);
- if (!from_memory) fclose(fp);
+ if (from_memory) {
+ if (w() && h() && name_png) {
+ Fl_Shared_Image *si = new Fl_Shared_Image(name_png, this);
+ si->add();
+ }
+ } else {
+ fclose(fp);
+ }
#endif // HAVE_LIBPNG && HAVE_LIBZ
}
diff --git a/src/Fl_Shared_Image.cxx b/src/Fl_Shared_Image.cxx
index 7c08eb846..da30d6ff7 100644
--- a/src/Fl_Shared_Image.cxx
+++ b/src/Fl_Shared_Image.cxx
@@ -374,11 +374,24 @@ Fl_Shared_Image* Fl_Shared_Image::find(const char *n, int W, int H) {
/**
- Gets a shared image, if it exists already ; it will return it.
- If it does not exist or if it exist but with other size,
- then the existing image is deleted and replaced
- by a new image from the n filename of the proper dimension.
- If n is not a valid image filename, then get() will return NULL.
+ \brief Find or load an image that can be shared by multiple widgets.
+
+ Gets a shared image, if it exists already ; it will return it.
+ If it does not exist or if it exist but with other size,
+ then the existing image is deleted and replaced
+ by a new image from the n filename of the proper dimension.
+ If n is not a valid image filename, then get() will return NULL.
+
+ Shared JPEG and PNG images can also be created from memory by using their
+ named memory access constructor.
+
+ \param n name of the image
+ \param W, H desired size
+
+ \see Fl_Shared_Image::find(const char *n, int W, int H)
+ \see Fl_Shared_Image::release()
+ \see Fl_JPEG_Image::Fl_JPEG_Image(const char *name, const unsigned char *data)
+ \see Fl_PNG_Image::Fl_PNG_Image (const char *name_png, const unsigned char *buffer, int maxsize)
*/
Fl_Shared_Image* Fl_Shared_Image::get(const char *n, int W, int H) {
Fl_Shared_Image *temp; // Image