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-25 00:55:12 +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_PNG_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:
|
2008-09-14 22:19:41 +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-12-11 19:03:13 +03:00
|
|
|
// Fl_PNG_Image::Fl_PNG_Image() - Load a PNG 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...
|
|
|
|
//
|
|
|
|
|
2003-09-16 03:52:38 +04:00
|
|
|
#include <FL/Fl.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 <FL/Fl_PNG_Image.H>
|
2011-01-24 20:04:22 +03:00
|
|
|
#include <FL/Fl_Shared_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>
|
2008-09-19 21:40:20 +04:00
|
|
|
#include <FL/fl_utf8.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
|
|
|
|
2011-01-17 23:51:12 +03:00
|
|
|
#if defined(HAVE_LIBPNG) && defined(HAVE_LIBZ)
|
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"
|
|
|
|
{
|
|
|
|
# include <zlib.h>
|
2002-04-24 22:29:06 +04:00
|
|
|
# ifdef HAVE_PNG_H
|
|
|
|
# include <png.h>
|
|
|
|
# else
|
|
|
|
# include <libpng/png.h>
|
|
|
|
# endif // HAVE_PNG_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
|
|
|
}
|
|
|
|
|
2011-01-17 23:51:12 +03:00
|
|
|
typedef struct {
|
|
|
|
png_structp pp;
|
|
|
|
const unsigned char *current;
|
|
|
|
const unsigned char *last;
|
|
|
|
} fl_png_memory;
|
|
|
|
|
|
|
|
static void png_read_data_from_mem( png_structp png_ptr, //pointer to our data
|
|
|
|
png_bytep data, // where to copy the image data for libpng computing
|
|
|
|
png_size_t length) // length of data to copy
|
|
|
|
{
|
|
|
|
fl_png_memory *png_mem_data = (fl_png_memory*)png_get_io_ptr(png_ptr); // get the pointer to our struct
|
|
|
|
if (png_mem_data->current + length > png_mem_data->last) {
|
|
|
|
png_error(png_mem_data->pp, "Invalid attempt to read row data");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* copy data from image buffer */
|
|
|
|
memcpy (data, png_mem_data->current, length);
|
|
|
|
/* advance in the memory data */
|
|
|
|
png_mem_data->current += length;
|
|
|
|
}
|
|
|
|
#endif // HAVE_LIBPNG && HAVE_LIBZ
|
|
|
|
|
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
|
|
|
|
2008-09-14 22:19:41 +04:00
|
|
|
/**
|
|
|
|
The constructor loads the named PNG image from the given png filename.
|
2011-01-18 01:42:34 +03:00
|
|
|
|
|
|
|
The destructor frees all memory and server resources that are used by
|
2008-09-14 22:19:41 +04:00
|
|
|
the image.
|
2011-01-18 01:42:34 +03:00
|
|
|
|
|
|
|
\param[in] filename Name of PNG file to read
|
2008-09-14 22:19:41 +04:00
|
|
|
*/
|
2011-01-17 23:51:12 +03:00
|
|
|
Fl_PNG_Image::Fl_PNG_Image (const char *filename): Fl_RGB_Image(0,0,0)
|
|
|
|
{
|
|
|
|
load_png_(filename, NULL, 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
|
|
|
|
2011-01-24 20:04:22 +03:00
|
|
|
/**
|
|
|
|
\brief Constructor that reads a PNG 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.
|
|
|
|
|
|
|
|
\param name_png A name given to this image or NULL
|
2011-01-18 01:42:34 +03:00
|
|
|
\param buffer Pointer to the start of the PNG image in memory
|
2011-01-24 20:04:22 +03:00
|
|
|
\param maxsize Size in bytes of the memory buffer containing the PNG image
|
2011-01-17 23:51:12 +03:00
|
|
|
*/
|
|
|
|
Fl_PNG_Image::Fl_PNG_Image (
|
|
|
|
const char *name_png, const unsigned char *buffer, int maxsize): Fl_RGB_Image(0,0,0)
|
|
|
|
{
|
|
|
|
load_png_(name_png, buffer, maxsize);
|
|
|
|
}
|
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
|
|
|
|
2011-01-17 23:51:12 +03:00
|
|
|
void Fl_PNG_Image::load_png_(const char *name_png, const unsigned char *buffer_png, int maxsize)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_LIBPNG) && defined(HAVE_LIBZ)
|
|
|
|
int i; // Looping var
|
2011-01-19 09:29:06 +03:00
|
|
|
FILE *fp = NULL; // File pointer
|
2011-01-17 23:51:12 +03:00
|
|
|
int channels; // Number of color channels
|
|
|
|
png_structp pp; // PNG read pointer
|
|
|
|
png_infop info; // PNG info pointers
|
|
|
|
png_bytep *rows;// PNG row pointers
|
|
|
|
fl_png_memory png_mem_data;
|
2011-01-24 20:04:22 +03:00
|
|
|
int from_memory = (buffer_png != NULL); // true if reading image from memory
|
2011-01-17 23:51:12 +03:00
|
|
|
|
|
|
|
if (!from_memory) {
|
|
|
|
if ((fp = fl_fopen(name_png, "rb")) == NULL) return;
|
|
|
|
}
|
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
|
|
|
// Setup the PNG data structures...
|
|
|
|
pp = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
|
|
|
info = png_create_info_struct(pp);
|
|
|
|
|
2010-11-15 00:17:31 +03:00
|
|
|
if (setjmp(png_jmpbuf(pp)))
|
2003-09-16 03:52:38 +04:00
|
|
|
{
|
2011-01-17 23:51:12 +03:00
|
|
|
Fl::warning("PNG file \"%s\" contains errors!\n", name_png);
|
2003-09-16 03:52:38 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-17 23:51:12 +03:00
|
|
|
if (from_memory) {
|
|
|
|
png_mem_data.current = buffer_png;
|
|
|
|
png_mem_data.last = buffer_png + maxsize;
|
|
|
|
png_mem_data.pp = pp;
|
|
|
|
// Initialize the function pointer to the PNG read "engine"...
|
|
|
|
png_set_read_fn (pp, (png_voidp) &png_mem_data, png_read_data_from_mem);
|
|
|
|
} else {
|
|
|
|
png_init_io(pp, fp); // Initialize the PNG file read "engine"...
|
|
|
|
}
|
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
|
|
|
|
|
|
|
// Get the image dimensions and convert to grayscale or RGB...
|
|
|
|
png_read_info(pp, info);
|
|
|
|
|
2010-11-15 00:17:31 +03:00
|
|
|
if (png_get_color_type(pp, info) == PNG_COLOR_TYPE_PALETTE)
|
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
|
|
|
png_set_expand(pp);
|
|
|
|
|
2010-11-15 00:17:31 +03:00
|
|
|
if (png_get_color_type(pp, info) & PNG_COLOR_MASK_COLOR)
|
2001-11-23 15:06:36 +03:00
|
|
|
channels = 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
|
|
|
else
|
2001-11-23 15:06:36 +03:00
|
|
|
channels = 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-11-18 23:02:27 +03:00
|
|
|
int num_trans = 0;
|
2010-11-15 00:17:31 +03:00
|
|
|
png_get_tRNS(pp, info, 0, &num_trans, 0);
|
|
|
|
if ((png_get_color_type(pp, info) & PNG_COLOR_MASK_ALPHA) || (num_trans != 0))
|
2011-01-17 23:51:12 +03:00
|
|
|
channels ++;
|
2001-11-23 15:06:36 +03:00
|
|
|
|
2010-11-15 00:17:31 +03:00
|
|
|
w((int)(png_get_image_width(pp, info)));
|
|
|
|
h((int)(png_get_image_height(pp, info)));
|
2001-11-23 15:06:36 +03:00
|
|
|
d(channels);
|
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-11-15 00:17:31 +03:00
|
|
|
if (png_get_bit_depth(pp, info) < 8)
|
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
|
|
|
{
|
|
|
|
png_set_packing(pp);
|
|
|
|
png_set_expand(pp);
|
|
|
|
}
|
2010-11-15 00:17:31 +03:00
|
|
|
else if (png_get_bit_depth(pp, info) == 16)
|
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
|
|
|
png_set_strip_16(pp);
|
|
|
|
|
2004-10-19 00:22:25 +04:00
|
|
|
# if defined(HAVE_PNG_GET_VALID) && defined(HAVE_PNG_SET_TRNS_TO_ALPHA)
|
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
|
|
|
// Handle transparency...
|
|
|
|
if (png_get_valid(pp, info, PNG_INFO_tRNS))
|
|
|
|
png_set_tRNS_to_alpha(pp);
|
2004-10-19 00:22:25 +04:00
|
|
|
# endif // HAVE_PNG_GET_VALID && HAVE_PNG_SET_TRNS_TO_ALPHA
|
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
|
|
|
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
|
|
|
|
|
|
|
// Allocate pointers...
|
2001-11-23 15:06:36 +03:00
|
|
|
rows = new png_bytep[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
|
|
|
|
2001-11-23 15:06:36 +03:00
|
|
|
for (i = 0; i < h(); i ++)
|
|
|
|
rows[i] = (png_bytep)(array + i * w() * d());
|
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
|
|
|
|
|
|
|
// Read the image, handling interlacing as needed...
|
|
|
|
for (i = png_set_interlace_handling(pp); i > 0; i --)
|
2001-11-23 15:06:36 +03:00
|
|
|
png_read_rows(pp, rows, NULL, 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
|
|
|
|
2004-10-19 00:22:25 +04:00
|
|
|
#ifdef WIN32
|
|
|
|
// Some Windows graphics drivers don't honor transparency when RGB == white
|
|
|
|
if (channels == 4) {
|
|
|
|
// Convert RGB to 0 when alpha == 0...
|
|
|
|
uchar *ptr = (uchar *)array;
|
|
|
|
for (i = w() * h(); i > 0; i --, ptr += 4)
|
|
|
|
if (!ptr[3]) ptr[0] = ptr[1] = ptr[2] = 0;
|
|
|
|
}
|
|
|
|
#endif // WIN32
|
|
|
|
|
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
|
|
|
// Free memory and return...
|
2001-12-11 19:03:13 +03:00
|
|
|
delete[] rows;
|
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
|
|
|
|
|
|
|
png_read_end(pp, info);
|
|
|
|
png_destroy_read_struct(&pp, &info, NULL);
|
|
|
|
|
2011-01-24 20:04:22 +03:00
|
|
|
if (from_memory) {
|
|
|
|
if (w() && h() && name_png) {
|
|
|
|
Fl_Shared_Image *si = new Fl_Shared_Image(name_png, this);
|
|
|
|
si->add();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fclose(fp);
|
|
|
|
}
|
2002-04-24 22:29:06 +04:00
|
|
|
#endif // HAVE_LIBPNG && HAVE_LIBZ
|
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-25 00:55:12 +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
|
|
|
//
|