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.
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// Copyright 1997-2005 by Easy Software Products.
|
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
|
|
|
// Image support donated by Matthias Melcher, Copyright 2000.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// Please report all bugs and problems to "fltk-bugs@fltk.org".
|
|
|
|
//
|
|
|
|
// 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>
|
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
|
2003-09-16 03:52:38 +04:00
|
|
|
static void
|
2005-02-12 05:41:52 +03:00
|
|
|
fl_jpeg_error_handler(j_common_ptr dinfo) { // I - Decompressor info
|
2005-03-05 18:25:30 +03:00
|
|
|
longjmp(((fl_jpeg_error_mgr *)(dinfo->err))->errhand_, 1);
|
2005-02-12 05:41:52 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fl_jpeg_output_handler(j_common_ptr dinfo) { // I - Decompressor info
|
2003-09-16 03:52:38 +04:00
|
|
|
return;
|
|
|
|
}
|
2003-09-18 00:22:12 +04:00
|
|
|
#endif // HAVE_LIBJPEG
|
2003-09-16 03:52:38 +04: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
|
|
|
//
|
2001-11-23 15:06:36 +03: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
|
|
|
//
|
|
|
|
|
2001-11-23 15:06:36 +03:00
|
|
|
Fl_JPEG_Image::Fl_JPEG_Image(const char *jpeg) // I - File to load
|
|
|
|
: Fl_RGB_Image(0,0,0) {
|
|
|
|
#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
|
|
|
|
|
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-12 05:41:52 +03:00
|
|
|
// Clear data...
|
|
|
|
alloc_array = 0;
|
|
|
|
array = (uchar *)0;
|
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-12 05:41:52 +03:00
|
|
|
// Open the image file...
|
2001-11-23 15:06:36 +03:00
|
|
|
if ((fp = fopen(jpeg, "rb")) == NULL) return;
|
|
|
|
|
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;
|
2005-03-05 18:25:30 +03:00
|
|
|
|
|
|
|
if (setjmp(jerr.errhand_))
|
|
|
|
{
|
|
|
|
// JPEG error handling...
|
|
|
|
if (array) jpeg_finish_decompress(&dinfo);
|
|
|
|
jpeg_destroy_decompress(&dinfo);
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
w(0);
|
|
|
|
h(0);
|
|
|
|
d(0);
|
|
|
|
|
|
|
|
if (array) {
|
|
|
|
delete[] (uchar *)array;
|
|
|
|
array = 0;
|
|
|
|
alloc_array = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2005-02-12 05:41:52 +03:00
|
|
|
|
|
|
|
jpeg_create_decompress(&dinfo);
|
|
|
|
jpeg_stdio_src(&dinfo, fp);
|
|
|
|
jpeg_read_header(&dinfo, 1);
|
2003-09-16 03:52:38 +04: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;
|
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-12 05:41:52 +03:00
|
|
|
jpeg_calc_output_dimensions(&dinfo);
|
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-12 05:41:52 +03:00
|
|
|
w(dinfo.output_width);
|
|
|
|
h(dinfo.output_height);
|
|
|
|
d(dinfo.output_components);
|
|
|
|
|
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;
|
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-12 05:41:52 +03:00
|
|
|
jpeg_start_decompress(&dinfo);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2005-02-12 05:41:52 +03:00
|
|
|
jpeg_finish_decompress(&dinfo);
|
|
|
|
jpeg_destroy_decompress(&dinfo);
|
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
|
|
|
|
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
|
|
|
|
|
|
|
//
|
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
|
|
|
//
|