From 795b2c6356af2ef7e26c39faa309d566c4bf62f6 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Thu, 18 Feb 2010 11:38:42 +0000 Subject: 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 --- fluid/Fluid_Image.cxx | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'fluid') 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 \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"); -- cgit v1.2.3