OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 04:06:45 +03:00
|
|
|
//
|
2005-02-06 04:52:15 +03:00
|
|
|
// "$Id$"
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 04:06:45 +03:00
|
|
|
//
|
|
|
|
// Fl_JPEG_Image routines.
|
|
|
|
//
|
2011-01-18 01:42:34 +03:00
|
|
|
// Copyright 1997-2011 by Easy Software Products.
|
2009-01-02 00:28:26 +03:00
|
|
|
// Image support by Matthias Melcher, Copyright 2000-2009.
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 04:06:45 +03:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 04:06:45 +03:00
|
|
|
//
|
|
|
|
// Contents:
|
|
|
|
//
|
2002-07-26 18:22:02 +04:00
|
|
|
// Fl_JPEG_Image::Fl_JPEG_Image() - Load a JPEG image file.
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 04:06:45 +03:00
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// Include necessary header files...
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <FL/Fl_JPEG_Image.H>
|
2011-01-24 20:04:22 +03:00
|
|
|
#include <FL/Fl_Shared_Image.H>
|
2010-11-18 23:00:01 +03:00
|
|
|
#include <FL/fl_utf8.h>
|
2001-11-23 15:06:36 +03:00
|
|
|
#include <config.h>
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 04:06:45 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2005-03-05 18:25:30 +03:00
|
|
|
#include <setjmp.h>
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 04:06:45 +03:00
|
|
|
|
2002-07-26 18:22:02 +04:00
|
|
|
|
|
|
|
// Some releases of the Cygwin JPEG libraries don't have a correctly
|
|
|
|
// updated header file for the INT32 data type; the following define
|
|
|
|
// from Shane Hill seems to be a usable workaround...
|
|
|
|
|
|
|
|
#if defined(WIN32) && defined(__CYGWIN__)
|
|
|
|
# define XMD_H
|
|
|
|
#endif // WIN32 && __CYGWIN__
|
|
|
|
|
|
|
|
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 04:06:45 +03:00
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#ifdef HAVE_LIBJPEG
|
|
|
|
# include <jpeglib.h>
|
|
|
|
#endif // HAVE_LIBJPEG
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-12 05:41:52 +03:00
|
|
|
//
|
|
|
|
// Custom JPEG error handling structure...
|
|
|
|
//
|
|
|
|
|
2005-02-24 23:28:49 +03:00
|
|
|
#ifdef HAVE_LIBJPEG
|
2005-02-12 05:41:52 +03:00
|
|
|
struct fl_jpeg_error_mgr {
|
|
|
|
jpeg_error_mgr pub_; // Destination manager...
|
2005-03-05 18:25:30 +03:00
|
|
|
jmp_buf errhand_; // Error handler
|
2005-02-12 05:41:52 +03:00
|
|
|
};
|
2005-02-24 23:28:49 +03:00
|
|
|
#endif // HAVE_LIBJPEG
|
2005-02-12 05:41:52 +03:00
|
|
|
|
|
|
|
|
2003-09-16 03:52:38 +04:00
|
|
|
//
|
|
|
|
// Error handler for JPEG files...
|
|
|
|
//
|
|
|
|
|
2003-09-18 00:22:12 +04:00
|
|
|
#ifdef HAVE_LIBJPEG
|
2005-04-14 16:29:51 +04:00
|
|
|
extern "C" {
|
|
|
|
static void
|
|
|
|
fl_jpeg_error_handler(j_common_ptr dinfo) { // I - Decompressor info
|
|
|
|
longjmp(((fl_jpeg_error_mgr *)(dinfo->err))->errhand_, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-05-20 04:01:06 +04:00
|
|
|
fl_jpeg_output_handler(j_common_ptr) { // I - Decompressor info (not used)
|
2005-04-14 16:29:51 +04:00
|
|
|
}
|
2003-09-16 03:52:38 +04:00
|
|
|
}
|
2003-09-18 00:22:12 +04:00
|
|
|
#endif // HAVE_LIBJPEG
|
2003-09-16 03:52:38 +04:00
|
|
|
|
|
|
|
|
2008-09-14 22:19:41 +04:00
|
|
|
/**
|
2010-02-18 14:38:42 +03:00
|
|
|
\brief The constructor loads the JPEG image from the given jpeg filename.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2011-01-13 19:50:36 +03:00
|
|
|
\param[in] filename a full path and name pointing to a valid jpeg file.
|
2010-02-18 14:38:42 +03:00
|
|
|
*/
|
|
|
|
Fl_JPEG_Image::Fl_JPEG_Image(const char *filename) // I - File to load
|
|
|
|
: Fl_RGB_Image(0,0,0) {
|
2001-11-23 15:06:36 +03:00
|
|
|
#ifdef HAVE_LIBJPEG
|
2005-02-12 05:41:52 +03:00
|
|
|
FILE *fp; // File pointer
|
|
|
|
jpeg_decompress_struct dinfo; // Decompressor info
|
|
|
|
fl_jpeg_error_mgr jerr; // Error handler info
|
|
|
|
JSAMPROW row; // Sample row pointer
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2005-08-29 23:36:59 +04:00
|
|
|
// the following variables are pointers allocating some private space that
|
|
|
|
// is not reset by 'setjmp()'
|
|
|
|
char* max_finish_decompress_err; // count errors and give up afer a while
|
|
|
|
char* max_destroy_decompress_err; // to avoid recusion and deadlock
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2005-02-12 05:41:52 +03:00
|
|
|
// Clear data...
|
|
|
|
alloc_array = 0;
|
|
|
|
array = (uchar *)0;
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2005-02-12 05:41:52 +03:00
|
|
|
// Open the image file...
|
2010-11-18 23:00:01 +03:00
|
|
|
if ((fp = fl_fopen(filename, "rb")) == NULL) return;
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2005-02-12 05:41:52 +03:00
|
|
|
// Setup the decompressor info and read the header...
|
|
|
|
dinfo.err = jpeg_std_error((jpeg_error_mgr *)&jerr);
|
|
|
|
jerr.pub_.error_exit = fl_jpeg_error_handler;
|
|
|
|
jerr.pub_.output_message = fl_jpeg_output_handler;
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2005-08-29 23:36:59 +04:00
|
|
|
// Setup error loop variables
|
|
|
|
max_finish_decompress_err = (char*)malloc(1); // allocate space on the frame for error counters
|
|
|
|
max_destroy_decompress_err = (char*)malloc(1); // otherwise, the variables are reset on the longjmp
|
|
|
|
*max_finish_decompress_err=10;
|
|
|
|
*max_destroy_decompress_err=10;
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2005-03-05 18:25:30 +03:00
|
|
|
if (setjmp(jerr.errhand_))
|
|
|
|
{
|
|
|
|
// JPEG error handling...
|
2005-07-12 00:31:59 +04:00
|
|
|
// if any of the cleanup routines hits another error, we would end up
|
|
|
|
// in a loop. So instead, we decrement max_err for some upper cleanup limit.
|
2005-08-29 23:36:59 +04:00
|
|
|
if ( ((*max_finish_decompress_err)-- > 0) && array)
|
2005-07-12 00:31:59 +04:00
|
|
|
jpeg_finish_decompress(&dinfo);
|
2005-08-29 23:36:59 +04:00
|
|
|
if ( (*max_destroy_decompress_err)-- > 0)
|
2005-07-12 00:31:59 +04:00
|
|
|
jpeg_destroy_decompress(&dinfo);
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2005-03-05 18:25:30 +03:00
|
|
|
fclose(fp);
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2005-03-05 18:25:30 +03:00
|
|
|
w(0);
|
|
|
|
h(0);
|
|
|
|
d(0);
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2005-03-05 18:25:30 +03:00
|
|
|
if (array) {
|
|
|
|
delete[] (uchar *)array;
|
|
|
|
array = 0;
|
|
|
|
alloc_array = 0;
|
|
|
|
}
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2005-08-29 23:36:59 +04:00
|
|
|
free(max_destroy_decompress_err);
|
|
|
|
free(max_finish_decompress_err);
|
|
|
|
|
2005-03-05 18:25:30 +03:00
|
|
|
return;
|
|
|
|
}
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2005-02-12 05:41:52 +03:00
|
|
|
jpeg_create_decompress(&dinfo);
|
|
|
|
jpeg_stdio_src(&dinfo, fp);
|
|
|
|
jpeg_read_header(&dinfo, 1);
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2005-02-12 05:41:52 +03:00
|
|
|
dinfo.quantize_colors = (boolean)FALSE;
|
|
|
|
dinfo.out_color_space = JCS_RGB;
|
|
|
|
dinfo.out_color_components = 3;
|
|
|
|
dinfo.output_components = 3;
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2005-02-12 05:41:52 +03:00
|
|
|
jpeg_calc_output_dimensions(&dinfo);
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2005-08-29 23:39:02 +04:00
|
|
|
w(dinfo.output_width);
|
2005-02-12 05:41:52 +03:00
|
|
|
h(dinfo.output_height);
|
|
|
|
d(dinfo.output_components);
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2001-11-23 15:06:36 +03:00
|
|
|
array = new uchar[w() * h() * d()];
|
2002-05-25 06:56:59 +04:00
|
|
|
alloc_array = 1;
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2005-02-12 05:41:52 +03:00
|
|
|
jpeg_start_decompress(&dinfo);
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2005-02-12 05:41:52 +03:00
|
|
|
while (dinfo.output_scanline < dinfo.output_height) {
|
2001-11-23 15:06:36 +03:00
|
|
|
row = (JSAMPROW)(array +
|
2005-02-12 05:41:52 +03:00
|
|
|
dinfo.output_scanline * dinfo.output_width *
|
|
|
|
dinfo.output_components);
|
|
|
|
jpeg_read_scanlines(&dinfo, &row, (JDIMENSION)1);
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 04:06:45 +03:00
|
|
|
}
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2005-02-12 05:41:52 +03:00
|
|
|
jpeg_finish_decompress(&dinfo);
|
|
|
|
jpeg_destroy_decompress(&dinfo);
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2005-08-29 23:36:59 +04:00
|
|
|
free(max_destroy_decompress_err);
|
|
|
|
free(max_finish_decompress_err);
|
2010-02-18 14:38:42 +03:00
|
|
|
|
2001-11-23 15:06:36 +03:00
|
|
|
fclose(fp);
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 04:06:45 +03:00
|
|
|
#endif // HAVE_LIBJPEG
|
2001-11-23 15:06:36 +03:00
|
|
|
}
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 04:06:45 +03:00
|
|
|
|
2010-02-18 14:38:42 +03:00
|
|
|
|
|
|
|
// data source manager for reading jpegs from memory
|
|
|
|
// init_source (j_decompress_ptr cinfo)
|
|
|
|
// fill_input_buffer (j_decompress_ptr cinfo)
|
|
|
|
// skip_input_data (j_decompress_ptr cinfo, long num_bytes)
|
|
|
|
// resync_to_restart (j_decompress_ptr cinfo, int desired)
|
|
|
|
// term_source (j_decompress_ptr cinfo)
|
|
|
|
// JOCTET * next_output_byte; /* => next byte to write in buffer */
|
|
|
|
// size_t free_in_buffer; /* # of byte spaces remaining in buffer */
|
|
|
|
|
2010-10-31 00:01:16 +04:00
|
|
|
#ifdef HAVE_LIBJPEG
|
2010-02-18 14:38:42 +03:00
|
|
|
typedef struct {
|
|
|
|
struct jpeg_source_mgr pub;
|
|
|
|
const unsigned char *data, *s;
|
|
|
|
// JOCTET * buffer; /* start of buffer */
|
|
|
|
// boolean start_of_file; /* have we gotten any data yet? */
|
|
|
|
} my_source_mgr;
|
|
|
|
|
|
|
|
typedef my_source_mgr *my_src_ptr;
|
|
|
|
|
|
|
|
|
|
|
|
void init_source (j_decompress_ptr cinfo) {
|
|
|
|
my_src_ptr src = (my_src_ptr)cinfo->src;
|
|
|
|
src->s = src->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean fill_input_buffer(j_decompress_ptr cinfo) {
|
|
|
|
my_src_ptr src = (my_src_ptr)cinfo->src;
|
|
|
|
size_t nbytes = 4096;
|
|
|
|
src->pub.next_input_byte = src->s;
|
|
|
|
src->pub.bytes_in_buffer = nbytes;
|
|
|
|
src->s += nbytes;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void term_source(j_decompress_ptr cinfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void skip_input_data(j_decompress_ptr cinfo, long num_bytes) {
|
|
|
|
my_src_ptr src = (my_src_ptr)cinfo->src;
|
|
|
|
if (num_bytes > 0) {
|
|
|
|
while (num_bytes > (long)src->pub.bytes_in_buffer) {
|
|
|
|
num_bytes -= (long)src->pub.bytes_in_buffer;
|
|
|
|
fill_input_buffer(cinfo);
|
|
|
|
}
|
|
|
|
src->pub.next_input_byte += (size_t) num_bytes;
|
|
|
|
src->pub.bytes_in_buffer -= (size_t) num_bytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void jpeg_mem_src(j_decompress_ptr cinfo, const unsigned char *data)
|
|
|
|
{
|
|
|
|
my_src_ptr src;
|
|
|
|
cinfo->src = (struct jpeg_source_mgr *)malloc(sizeof(my_source_mgr));
|
|
|
|
src = (my_src_ptr)cinfo->src;
|
|
|
|
src->pub.init_source = init_source;
|
|
|
|
src->pub.fill_input_buffer = fill_input_buffer;
|
|
|
|
src->pub.skip_input_data = skip_input_data;
|
|
|
|
src->pub.resync_to_restart = jpeg_resync_to_restart;
|
|
|
|
src->pub.term_source = term_source;
|
|
|
|
src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
|
|
|
|
src->pub.next_input_byte = NULL; /* until buffer loaded */
|
|
|
|
src->data = data;
|
|
|
|
src->s = data;
|
|
|
|
}
|
2010-10-31 00:01:16 +04:00
|
|
|
#endif // HAVE_LIBJPEG
|
2010-02-18 14:38:42 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief The constructor loads the JPEG image from memory.
|
2011-01-18 01:42:34 +03:00
|
|
|
|
2011-01-24 20:04:22 +03:00
|
|
|
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.
|
2011-02-22 12:41:26 +03:00
|
|
|
name_png can be NULL. If a name is given, the image is added to the list of
|
2011-01-24 20:04:22 +03:00
|
|
|
shared images (see: Fl_Shared_Image) and will be available by that name.
|
|
|
|
|
2010-02-18 14:38:42 +03:00
|
|
|
The inherited destructor frees all memory and server resources that are used
|
|
|
|
by the image.
|
2011-01-18 01:42:34 +03:00
|
|
|
|
2010-02-18 14:38:42 +03:00
|
|
|
There is no error function in this class. If the image has loaded correctly,
|
|
|
|
w(), h(), and d() should return values greater zero.
|
2011-01-18 01:42:34 +03:00
|
|
|
|
2011-01-24 20:04:22 +03:00
|
|
|
\param name A unique name or NULL
|
2011-01-18 01:42:34 +03:00
|
|
|
\param data A pointer to the memory location of the JPEG image
|
2010-02-18 14:38:42 +03:00
|
|
|
*/
|
|
|
|
Fl_JPEG_Image::Fl_JPEG_Image(const char *name, const unsigned char *data)
|
|
|
|
: Fl_RGB_Image(0,0,0) {
|
|
|
|
#ifdef HAVE_LIBJPEG
|
|
|
|
jpeg_decompress_struct dinfo; // Decompressor info
|
|
|
|
fl_jpeg_error_mgr jerr; // Error handler info
|
|
|
|
JSAMPROW row; // Sample row pointer
|
|
|
|
|
|
|
|
// the following variables are pointers allocating some private space that
|
|
|
|
// is not reset by 'setjmp()'
|
|
|
|
char* max_finish_decompress_err; // count errors and give up afer a while
|
|
|
|
char* max_destroy_decompress_err; // to avoid recusion and deadlock
|
|
|
|
|
|
|
|
// Clear data...
|
|
|
|
alloc_array = 0;
|
|
|
|
array = (uchar *)0;
|
|
|
|
|
|
|
|
// Setup the decompressor info and read the header...
|
|
|
|
dinfo.err = jpeg_std_error((jpeg_error_mgr *)&jerr);
|
|
|
|
jerr.pub_.error_exit = fl_jpeg_error_handler;
|
|
|
|
jerr.pub_.output_message = fl_jpeg_output_handler;
|
|
|
|
|
|
|
|
// Setup error loop variables
|
|
|
|
max_finish_decompress_err = (char*)malloc(1); // allocate space on the frame for error counters
|
|
|
|
max_destroy_decompress_err = (char*)malloc(1); // otherwise, the variables are reset on the longjmp
|
|
|
|
*max_finish_decompress_err=10;
|
|
|
|
*max_destroy_decompress_err=10;
|
|
|
|
|
|
|
|
if (setjmp(jerr.errhand_))
|
|
|
|
{
|
|
|
|
// JPEG error handling...
|
|
|
|
// if any of the cleanup routines hits another error, we would end up
|
|
|
|
// in a loop. So instead, we decrement max_err for some upper cleanup limit.
|
|
|
|
if ( ((*max_finish_decompress_err)-- > 0) && array)
|
|
|
|
jpeg_finish_decompress(&dinfo);
|
|
|
|
if ( (*max_destroy_decompress_err)-- > 0)
|
|
|
|
jpeg_destroy_decompress(&dinfo);
|
|
|
|
|
|
|
|
w(0);
|
|
|
|
h(0);
|
|
|
|
d(0);
|
|
|
|
|
|
|
|
if (array) {
|
|
|
|
delete[] (uchar *)array;
|
|
|
|
array = 0;
|
|
|
|
alloc_array = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(max_destroy_decompress_err);
|
|
|
|
free(max_finish_decompress_err);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
jpeg_create_decompress(&dinfo);
|
|
|
|
jpeg_mem_src(&dinfo, data);
|
|
|
|
jpeg_read_header(&dinfo, 1);
|
|
|
|
|
|
|
|
dinfo.quantize_colors = (boolean)FALSE;
|
|
|
|
dinfo.out_color_space = JCS_RGB;
|
|
|
|
dinfo.out_color_components = 3;
|
|
|
|
dinfo.output_components = 3;
|
|
|
|
|
|
|
|
jpeg_calc_output_dimensions(&dinfo);
|
|
|
|
|
|
|
|
w(dinfo.output_width);
|
|
|
|
h(dinfo.output_height);
|
|
|
|
d(dinfo.output_components);
|
|
|
|
|
|
|
|
array = new uchar[w() * h() * d()];
|
|
|
|
alloc_array = 1;
|
|
|
|
|
|
|
|
jpeg_start_decompress(&dinfo);
|
|
|
|
|
|
|
|
while (dinfo.output_scanline < dinfo.output_height) {
|
|
|
|
row = (JSAMPROW)(array +
|
|
|
|
dinfo.output_scanline * dinfo.output_width *
|
|
|
|
dinfo.output_components);
|
|
|
|
jpeg_read_scanlines(&dinfo, &row, (JDIMENSION)1);
|
|
|
|
}
|
|
|
|
|
|
|
|
jpeg_finish_decompress(&dinfo);
|
|
|
|
jpeg_destroy_decompress(&dinfo);
|
|
|
|
|
|
|
|
free(max_destroy_decompress_err);
|
|
|
|
free(max_finish_decompress_err);
|
2011-01-24 20:04:22 +03:00
|
|
|
|
|
|
|
if (w() && h() && name) {
|
|
|
|
Fl_Shared_Image *si = new Fl_Shared_Image(name, this);
|
|
|
|
si->add();
|
|
|
|
}
|
2010-02-18 14:38:42 +03:00
|
|
|
#endif // HAVE_LIBJPEG
|
|
|
|
}
|
|
|
|
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 04:06:45 +03:00
|
|
|
//
|
2005-02-06 04:52:15 +03:00
|
|
|
// End of "$Id$".
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 04:06:45 +03:00
|
|
|
//
|