summaryrefslogtreecommitdiff
path: root/fluid
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2010-02-18 11:38:42 +0000
committerMatthias Melcher <fltk@matthiasm.com>2010-02-18 11:38:42 +0000
commit795b2c6356af2ef7e26c39faa309d566c4bf62f6 (patch)
treede516e395ea1cb66f4c204792d12666b52c801c7 /fluid
parentb434df6061c5436685d2fd6f24e8ebeaf619311f (diff)
Added jpeg loading from memory. Added jpeg Fl_Widget->image() support for Fluid - but linking to fltk_images is required if this feature is used!
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7092 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'fluid')
-rw-r--r--fluid/Fluid_Image.cxx32
1 files changed, 32 insertions, 0 deletions
diff --git a/fluid/Fluid_Image.cxx b/fluid/Fluid_Image.cxx
index e421a6e42..afd959c4d 100644
--- a/fluid/Fluid_Image.cxx
+++ b/fluid/Fluid_Image.cxx
@@ -49,6 +49,7 @@ void Fluid_Image::deimage(Fl_Widget *o) {
static int pixmap_header_written = 0;
static int bitmap_header_written = 0;
static int image_header_written = 0;
+static int jpeg_header_written = 0;
void Fluid_Image::write_static() {
if (!img) return;
@@ -100,6 +101,37 @@ void Fluid_Image::write_static() {
unique_id(this, "image", fl_filename_name(name()), 0),
unique_id(this, "idata", fl_filename_name(name()), 0),
img->w(), img->h());
+ } else if (strcmp(fl_filename_ext(name()), ".jpg")==0) {
+ // Write jpeg image data...
+ write_c("\n");
+ if (jpeg_header_written != write_number) {
+ write_c("#include <FL/Fl_JPEG_Image.H>\n");
+ jpeg_header_written = write_number;
+ }
+ write_c("static unsigned char %s[] =\n",
+ unique_id(this, "idata", fl_filename_name(name()), 0));
+
+ FILE *f = fopen(name(), "rb");
+ if (!f) {
+ // message = "Can't include binary file. Can't open";
+ } else {
+ fseek(f, 0, SEEK_END);
+ size_t nData = ftell(f);
+ fseek(f, 0, SEEK_SET);
+ if (nData) {
+ char *data = (char*)calloc(nData, 1);
+ fread(data, nData, 1, f);
+ write_cdata(data, nData);
+ free(data);
+ }
+ fclose(f);
+ }
+
+ write_c(";\n");
+ write_c("static Fl_JPEG_Image %s(\"%s\", %s);\n",
+ unique_id(this, "image", fl_filename_name(name()), 0),
+ fl_filename_name(name()),
+ unique_id(this, "idata", fl_filename_name(name()), 0));
} else {
// Write image data...
write_c("\n");