summaryrefslogtreecommitdiff
path: root/src/Fl_PNG_Image.cxx
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2001-11-23 12:06:36 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>2001-11-23 12:06:36 +0000
commit4087b8cd9a139664420468c57489cae73c8b830a (patch)
treee760b9aed14a687ec0e1217676adf43cfe16d889 /src/Fl_PNG_Image.cxx
parentf5258404959cff3a299c796676b553b843a94355 (diff)
Add code for PNG and JPEG images.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1713 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_PNG_Image.cxx')
-rw-r--r--src/Fl_PNG_Image.cxx68
1 files changed, 28 insertions, 40 deletions
diff --git a/src/Fl_PNG_Image.cxx b/src/Fl_PNG_Image.cxx
index 36ede18ff..e12cd5c77 100644
--- a/src/Fl_PNG_Image.cxx
+++ b/src/Fl_PNG_Image.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_PNG_Image.cxx,v 1.1.2.1 2001/11/19 01:06:45 easysw Exp $"
+// "$Id: Fl_PNG_Image.cxx,v 1.1.2.2 2001/11/23 12:06:36 easysw Exp $"
//
// Fl_PNG_Image routines.
//
@@ -32,15 +32,9 @@
//
#include <FL/Fl_PNG_Image.H>
-#include "config.h"
+#include <config.h>
#include <stdio.h>
#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif /* HAVE_STRINGS_H */
-#include <errno.h>
extern "C"
{
@@ -51,23 +45,24 @@ extern "C"
}
-#if 0
-#ifdef HAVE_LIBPNG
//
-// 'Fl_Help_View::load_png()' - Load a PNG image file.
+// 'Fl_PNG_Image::Fl_PNG_Image()' - Load a PNG image file.
//
-int // O - 0 = success, -1 = fail
-Fl_Help_View::load_png(Fl_Help_Image *img,// I - Image pointer
- FILE *fp) // I - File to read from
-{
+Fl_PNG_Image::Fl_PNG_Image(const char *png) // I - File to read
+ : Fl_RGB_Image(0,0,0) {
+#ifdef HAVE_LIBPNG
int i; // Looping var
+ FILE *fp; // File pointer
+ int channels; // Number of color channels
png_structp pp; // PNG read pointer
png_infop info; // PNG info pointers
png_bytep *rows; // PNG row pointers
- png_color_16 bg; // Background color
+ // Open the PNG file...
+ if ((fp = fopen(png, "rb")) == NULL) return;
+
// Setup the PNG data structures...
pp = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
info = png_create_info_struct(pp);
@@ -82,12 +77,16 @@ Fl_Help_View::load_png(Fl_Help_Image *img,// I - Image pointer
png_set_expand(pp);
if (info->color_type & PNG_COLOR_MASK_COLOR)
- img->d = 3;
+ channels = 3;
else
- img->d = 1;
+ channels = 1;
if ((info->color_type & PNG_COLOR_MASK_ALPHA) || info->num_trans)
- img->d ++;
+ channels ++;
+
+ w(info->width);
+ h(info->height);
+ d(channels);
if (info->bit_depth < 8)
{
@@ -103,31 +102,20 @@ Fl_Help_View::load_png(Fl_Help_Image *img,// I - Image pointer
png_set_tRNS_to_alpha(pp);
#endif // HAVE_PNG_GET_VALID && HAVE_SET_TRNS_TO_ALPHA
- img->w = (int)info->width;
- img->h = (int)info->height;
- img->data = (unsigned char *)malloc(img->w * img->h * img->d);
-
- // Background color...
- unsigned rgba = fltk_colors[bgcolor_];
-
- bg.red = 65535 * (rgba >> 24) / 255;
- bg.green = 65535 * ((rgba >> 16) & 255) / 255;
- bg.blue = 65535 * ((rgba >> 8) & 255) / 255;
-
- png_set_background(pp, &bg, PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
+ array = new uchar[w() * h() * d()];
// Allocate pointers...
- rows = (png_bytep *)calloc(info->height, sizeof(png_bytep));
+ rows = new png_bytep[h()];
- for (i = 0; i < (int)info->height; i ++)
- rows[i] = img->data + i * img->w * img->d;
+ for (i = 0; i < h(); i ++)
+ rows[i] = (png_bytep)(array + i * w() * d());
// Read the image, handling interlacing as needed...
for (i = png_set_interlace_handling(pp); i > 0; i --)
- png_read_rows(pp, rows, NULL, img->h);
+ png_read_rows(pp, rows, NULL, h());
// Free memory and return...
- free(rows);
+ delete rows;
png_read_end(pp, info);
# ifdef HAVE_PNG_READ_DESTROY
@@ -136,11 +124,11 @@ Fl_Help_View::load_png(Fl_Help_Image *img,// I - Image pointer
png_destroy_read_struct(&pp, &info, NULL);
# endif // HAVE_PNG_READ_DESTROY
- return (1);
-}
+ fclose(fp);
#endif // HAVE_LIBPNG
-#endif // 0
+}
+
//
-// End of "$Id: Fl_PNG_Image.cxx,v 1.1.2.1 2001/11/19 01:06:45 easysw Exp $".
+// End of "$Id: Fl_PNG_Image.cxx,v 1.1.2.2 2001/11/23 12:06:36 easysw Exp $".
//