From 1acc39c5d8d5b3db88abfd008699dadb8aade2b9 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Mon, 19 Nov 2001 01:06:45 +0000 Subject: [PATCH] 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 --- CHANGES | 4 + FL/Fl_Bitmap.H | 11 +- FL/Fl_GIF_Image.H | 42 ++++ FL/Fl_Image.H | 16 +- FL/Fl_JPEG_Image.H | 42 ++++ FL/Fl_PNG_Image.H | 42 ++++ FL/Fl_Pixmap.H | 19 +- makeinclude.in | 6 +- src/Fl_Bitmap.cxx | 73 +++++- src/Fl_GIF_Image.cxx | 510 +++++++++++++++++++++++++++++++++++++++++ src/Fl_Image.cxx | 176 +++++++++++++- src/Fl_JPEG_Image.cxx | 126 ++++++++++ src/Fl_PNG_Image.cxx | 146 ++++++++++++ src/Fl_Pixmap.cxx | 317 ++++++++++++++++++++++++- src/Makefile | 7 +- src/fl_draw_pixmap.cxx | 11 +- src/makedepend | 9 + test/Makefile | 6 +- test/bitmap.cxx | 22 +- test/image.cxx | 31 ++- test/pixmap.cxx | 31 ++- 21 files changed, 1585 insertions(+), 62 deletions(-) create mode 100644 FL/Fl_GIF_Image.H create mode 100644 FL/Fl_JPEG_Image.H create mode 100644 FL/Fl_PNG_Image.H create mode 100644 src/Fl_GIF_Image.cxx create mode 100644 src/Fl_JPEG_Image.cxx create mode 100644 src/Fl_PNG_Image.cxx diff --git a/CHANGES b/CHANGES index a2b7caf1f..56ff98a28 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,10 @@ CHANGES IN FLTK 1.1.0b6 environment. - Added new fl_beep() function to do audible notifications of various types. + - Added new Fl_GIF_Image, Fl_PNG_Image, and + Fl_JPEG_Image classes. + - Added new copy(), desaturate(), inactive(), and + color_average() methods to the Fl_Image classes. - Fl_Float_Input and Fl_Int_Input no longer accept pasted text that is not a floating point or integer value. Pasted numbers now replace text in these diff --git a/FL/Fl_Bitmap.H b/FL/Fl_Bitmap.H index 3d9ac5411..f4dc0bdf3 100644 --- a/FL/Fl_Bitmap.H +++ b/FL/Fl_Bitmap.H @@ -1,5 +1,5 @@ // -// "$Id: Fl_Bitmap.H,v 1.5.2.3.2.2 2001/11/18 20:52:27 easysw Exp $" +// "$Id: Fl_Bitmap.H,v 1.5.2.3.2.3 2001/11/19 01:06:45 easysw Exp $" // // Bitmap header file for the Fast Light Tool Kit (FLTK). // @@ -34,13 +34,16 @@ class FL_EXPORT Fl_Bitmap : public Fl_Image { public: const uchar *array; + int alloc_array; // Non-zero if data was allocated Fl_Bitmask id; // for internal use Fl_Bitmap(const uchar *bits, int W, int H) : - Fl_Image(W,H), array(bits), id(0) {} + Fl_Image(W,H), array(bits), alloc_array(0), id(0) {} Fl_Bitmap(const char *bits, int W, int H) : - Fl_Image(W,H), array((const uchar *)bits), id(0) {} + Fl_Image(W,H), array((const uchar *)bits), alloc_array(0), id(0) {} virtual ~Fl_Bitmap(); + virtual Fl_Image *copy(int W, int H); + Fl_Image *copy() { return copy(w(), h()); } virtual void draw(int X, int Y, int W, int H, int cx=0, int cy=0); void draw(int X, int Y) {draw(X, Y, w(), h(), 0, 0);} virtual void label(Fl_Widget*w); @@ -50,5 +53,5 @@ class FL_EXPORT Fl_Bitmap : public Fl_Image { #endif // -// End of "$Id: Fl_Bitmap.H,v 1.5.2.3.2.2 2001/11/18 20:52:27 easysw Exp $". +// End of "$Id: Fl_Bitmap.H,v 1.5.2.3.2.3 2001/11/19 01:06:45 easysw Exp $". // diff --git a/FL/Fl_GIF_Image.H b/FL/Fl_GIF_Image.H new file mode 100644 index 000000000..53d01262a --- /dev/null +++ b/FL/Fl_GIF_Image.H @@ -0,0 +1,42 @@ +// +// "$Id: Fl_GIF_Image.H,v 1.1.2.1 2001/11/19 01:06:45 easysw Exp $" +// +// GIF image header file for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2001 by Bill Spitzak and others. +// +// 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". +// + +#ifndef Fl_GIF_Image_H +#define Fl_GIF_Image_H +# include "Fl_Pixmap.H" + +class FL_EXPORT Fl_GIF_Image : public Fl_Pixmap { + + public: + + Fl_GIF_Image(const char* filename); + virtual ~Fl_GIF_Image(); +}; + +#endif + +// +// End of "$Id: Fl_GIF_Image.H,v 1.1.2.1 2001/11/19 01:06:45 easysw Exp $". +// diff --git a/FL/Fl_Image.H b/FL/Fl_Image.H index e277eb34b..77de42652 100644 --- a/FL/Fl_Image.H +++ b/FL/Fl_Image.H @@ -1,5 +1,5 @@ // -// "$Id: Fl_Image.H,v 1.5.2.3.2.2 2001/11/18 20:52:27 easysw Exp $" +// "$Id: Fl_Image.H,v 1.5.2.3.2.3 2001/11/19 01:06:45 easysw Exp $" // // Image header file for the Fast Light Tool Kit (FLTK). // @@ -43,6 +43,11 @@ class FL_EXPORT Fl_Image { Fl_Image(int W, int H) {w_ = W; h_ = H;} virtual ~Fl_Image(); + virtual Fl_Image *copy(int W, int H); + Fl_Image *copy() { return copy(w(), h()); } + virtual void color_average(Fl_Color c, float i); + void inactive() { color_average(FL_GRAY, .33f); } + virtual void desaturate(); virtual void label(Fl_Widget*w); virtual void label(Fl_Menu_Item*m); virtual void draw(int X, int Y, int W, int H, int cx=0, int cy=0); @@ -53,13 +58,18 @@ class FL_EXPORT Fl_RGB_Image : public Fl_Image { public: const uchar *array; + int alloc_array; // Non-zero if array was allocated int d, ld; Fl_Offscreen id; // for internal use Fl_Bitmask mask; // for internal use (mask bitmap) Fl_RGB_Image(const uchar *bits, int W, int H, int D=3, int LD=0) : - Fl_Image(W,H), array(bits), d(D), ld(LD), id(0) {} + Fl_Image(W,H), array(bits), alloc_array(0), d(D), ld(LD), id(0) {} virtual ~Fl_RGB_Image(); + virtual Fl_Image *copy(int W, int H); + Fl_Image *copy() { return copy(w(), h()); } + virtual void color_average(Fl_Color c, float i); + virtual void desaturate(); virtual void draw(int X, int Y, int W, int H, int cx=0, int cy=0); void draw(int X, int Y) {draw(X, Y, w(), h(), 0, 0);} virtual void label(Fl_Widget*w); @@ -69,5 +79,5 @@ class FL_EXPORT Fl_RGB_Image : public Fl_Image { #endif // -// End of "$Id: Fl_Image.H,v 1.5.2.3.2.2 2001/11/18 20:52:27 easysw Exp $". +// End of "$Id: Fl_Image.H,v 1.5.2.3.2.3 2001/11/19 01:06:45 easysw Exp $". // diff --git a/FL/Fl_JPEG_Image.H b/FL/Fl_JPEG_Image.H new file mode 100644 index 000000000..ff53136f6 --- /dev/null +++ b/FL/Fl_JPEG_Image.H @@ -0,0 +1,42 @@ +// +// "$Id: Fl_JPEG_Image.H,v 1.1.2.1 2001/11/19 01:06:45 easysw Exp $" +// +// JPEG image header file for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2001 by Bill Spitzak and others. +// +// 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". +// + +#ifndef Fl_JPEG_Image_H +#define Fl_JPEG_Image_H +# include "Fl_Image.H" + +class FL_EXPORT Fl_JPEG_Image : public Fl_RGB_Image { + + public: + + Fl_JPEG_Image(const char* filename); + virtual ~Fl_JPEG_Image(); +}; + +#endif + +// +// End of "$Id: Fl_JPEG_Image.H,v 1.1.2.1 2001/11/19 01:06:45 easysw Exp $". +// diff --git a/FL/Fl_PNG_Image.H b/FL/Fl_PNG_Image.H new file mode 100644 index 000000000..f578c8549 --- /dev/null +++ b/FL/Fl_PNG_Image.H @@ -0,0 +1,42 @@ +// +// "$Id: Fl_PNG_Image.H,v 1.1.2.1 2001/11/19 01:06:45 easysw Exp $" +// +// PNG image header file for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2001 by Bill Spitzak and others. +// +// 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". +// + +#ifndef Fl_PNG_Image_H +#define Fl_PNG_Image_H +# include "Fl_Image.H" + +class FL_EXPORT Fl_PNG_Image : public Fl_RGB_Image { + + public: + + Fl_PNG_Image(const char* filename); + virtual ~Fl_PNG_Image(); +}; + +#endif + +// +// End of "$Id: Fl_PNG_Image.H,v 1.1.2.1 2001/11/19 01:06:45 easysw Exp $". +// diff --git a/FL/Fl_Pixmap.H b/FL/Fl_Pixmap.H index 9d448afa8..609753016 100644 --- a/FL/Fl_Pixmap.H +++ b/FL/Fl_Pixmap.H @@ -1,5 +1,5 @@ // -// "$Id: Fl_Pixmap.H,v 1.6.2.8.2.3 2001/11/18 20:52:27 easysw Exp $" +// "$Id: Fl_Pixmap.H,v 1.6.2.8.2.4 2001/11/19 01:06:45 easysw Exp $" // // Pixmap header file for the Fast Light Tool Kit (FLTK). // @@ -36,19 +36,26 @@ struct Fl_Menu_Item; # endif // __sgi && !_COMPILER_VERSION class FL_EXPORT Fl_Pixmap : public Fl_Image { + void copy_data(); + void delete_data(); void measure(); public: const char * const * data; + int alloc_data; // Non-zero if data was allocated Fl_Offscreen id; // for internal use Fl_Bitmask mask; // for internal use (mask bitmap) - explicit Fl_Pixmap(char * const * d) : Fl_Image(-1,0), data((const char*const*)d), id(0),mask(0) {measure();} - explicit Fl_Pixmap(uchar* const * d) : Fl_Image(-1,0), data((const char*const*)d), id(0),mask(0) {measure();} - explicit Fl_Pixmap(const char * const * d) : Fl_Image(-1,0), data(d), id(0),mask(0) {measure();} - explicit Fl_Pixmap(const uchar* const * d) : Fl_Image(-1,0), data((const char*const*)d), id(0),mask(0) {measure();} + explicit Fl_Pixmap(char * const * d) : Fl_Image(-1,0), data((const char*const*)d), alloc_data(0), id(0), mask(0) {measure();} + explicit Fl_Pixmap(uchar* const * d) : Fl_Image(-1,0), data((const char*const*)d), alloc_data(0), id(0), mask(0) {measure();} + explicit Fl_Pixmap(const char * const * d) : Fl_Image(-1,0), data(d), alloc_data(0), id(0), mask(0) {measure();} + explicit Fl_Pixmap(const uchar* const * d) : Fl_Image(-1,0), data((const char*const*)d), alloc_data(0), id(0), mask(0) {measure();} virtual ~Fl_Pixmap(); + virtual Fl_Image *copy(int W, int H); + Fl_Image *copy() { return copy(w(), h()); } + virtual void color_average(Fl_Color c, float i); + virtual void desaturate(); virtual void draw(int X, int Y, int W, int H, int cx=0, int cy=0); void draw(int X, int Y) {draw(X, Y, w(), h(), 0, 0);} virtual void label(Fl_Widget*w); @@ -58,5 +65,5 @@ class FL_EXPORT Fl_Pixmap : public Fl_Image { #endif // -// End of "$Id: Fl_Pixmap.H,v 1.6.2.8.2.3 2001/11/18 20:52:27 easysw Exp $". +// End of "$Id: Fl_Pixmap.H,v 1.6.2.8.2.4 2001/11/19 01:06:45 easysw Exp $". // diff --git a/makeinclude.in b/makeinclude.in index ba6219151..79700bbd8 100644 --- a/makeinclude.in +++ b/makeinclude.in @@ -1,5 +1,5 @@ # -# "$Id: makeinclude.in,v 1.7.2.11.2.6 2001/11/18 12:48:38 easysw Exp $" +# "$Id: makeinclude.in,v 1.7.2.11.2.7 2001/11/19 01:06:45 easysw Exp $" # # Make include file for the Fast Light Tool Kit (FLTK). # @configure_input@ @@ -80,7 +80,7 @@ CAT3EXT =@CAT3EXT@ # Build commands and filename extensions... .SUFFIXES: .0 .1 .3 .c .cxx .h .fl .man .o .z $(EXEEXT) -$(EXEEXT).cxx: +.cxx$(EXEEXT): echo Compiling and linking $@... $(CXX) -I.. $(CXXFLAGS) $< $(LINKFLTK) $(LDLIBS) -o $@ @@ -105,5 +105,5 @@ $(EXEEXT).cxx: mv t.z $@ # -# End of "$Id: makeinclude.in,v 1.7.2.11.2.6 2001/11/18 12:48:38 easysw Exp $". +# End of "$Id: makeinclude.in,v 1.7.2.11.2.7 2001/11/19 01:06:45 easysw Exp $". # diff --git a/src/Fl_Bitmap.cxx b/src/Fl_Bitmap.cxx index c20bfeabf..18d474fb7 100644 --- a/src/Fl_Bitmap.cxx +++ b/src/Fl_Bitmap.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Bitmap.cxx,v 1.5.2.4.2.2 2001/11/18 20:52:27 easysw Exp $" +// "$Id: Fl_Bitmap.cxx,v 1.5.2.4.2.3 2001/11/19 01:06:45 easysw Exp $" // // Bitmap drawing routines for the Fast Light Tool Kit (FLTK). // @@ -29,6 +29,7 @@ #include #include #include +#include #ifdef WIN32 // Windows bitmask functions... Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data) { @@ -105,6 +106,7 @@ void Fl_Bitmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) { Fl_Bitmap::~Fl_Bitmap() { if (id) fl_delete_bitmask(id); + if (alloc_array) delete[] array; } void Fl_Bitmap::label(Fl_Widget* w) { @@ -114,6 +116,73 @@ void Fl_Bitmap::label(Fl_Widget* w) { void Fl_Bitmap::label(Fl_Menu_Item* m) { } +Fl_Image *Fl_Bitmap::copy(int W, int H) { + // Optimize the simple copy where the width and height are the same... + if (W == w() && H == h()) return new Fl_Bitmap(array, w(), h()); + + // OK, need to resize the image data; allocate memory and + Fl_Bitmap *new_image; // New RGB image + uchar *new_array, // New array for image data + *new_ptr, // Pointer into new array + new_bit, // Bit for new array + old_bit; // Bit for old array + const uchar *old_ptr; // Pointer into old array + int sx, sy, // Source coordinates + dx, dy, // Destination coordinates + xerr, yerr, // X & Y errors + xmod, ymod, // X & Y moduli + xstep, ystep; // X & Y step increments + + + // Figure out Bresenheim step/modulus values... + xmod = w() % W; + xstep = w() / W; + ymod = h() % H; + ystep = h() / H; + + // Allocate memory for the new image... + new_array = new uchar [H * (W + 7) / 8]; + new_image = new Fl_Bitmap(new_array, W, H); + new_image->alloc_array = 1; + + memset(new_array, 0, H * (W + 7) / 8); + + // Scale the image using a nearest-neighbor algorithm... + for (dy = h(), sy = 0, yerr = H / 2, new_ptr = new_array; dy > 0; dy --) { + for (dx = w(), xerr = W / 2, old_ptr = array + sy * (w() + 7) / 8, sx = 0, new_bit = 128; + dx > 0; + dx --) { + old_bit = 128 >> (sx & 7); + if (old_ptr[sx / 8] & old_bit) *new_ptr |= new_bit; + + if (new_bit > 1) new_bit >>= 1; + else { + new_bit = 128; + new_ptr ++; + } + + sx += xstep; + xerr -= xmod; + + if (xerr <= 0) { + xerr += W; + sx ++; + } + } + + if (new_bit < 128) new_ptr ++; + + sy += ystep; + yerr -= ymod; + if (yerr <= 0) { + yerr += H; + sy ++; + } + } + + return new_image; +} + // -// End of "$Id: Fl_Bitmap.cxx,v 1.5.2.4.2.2 2001/11/18 20:52:27 easysw Exp $". +// End of "$Id: Fl_Bitmap.cxx,v 1.5.2.4.2.3 2001/11/19 01:06:45 easysw Exp $". // diff --git a/src/Fl_GIF_Image.cxx b/src/Fl_GIF_Image.cxx new file mode 100644 index 000000000..7005363f3 --- /dev/null +++ b/src/Fl_GIF_Image.cxx @@ -0,0 +1,510 @@ +// +// "$Id: Fl_GIF_Image.cxx,v 1.1.2.1 2001/11/19 01:06:45 easysw Exp $" +// +// Fl_GIF_Image routines. +// +// Copyright 1997-2001 by Easy Software Products. +// 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: +// +// + +// +// Include necessary header files... +// + +#include +#include "config.h" +#include +#include +#include +#include +#ifdef HAVE_STRINGS_H +# include +#endif /* HAVE_STRINGS_H */ +#include + +#if defined(WIN32) && ! defined(__CYGWIN__) +# include +# include +# define strcasecmp(s,t) stricmp((s), (t)) +# define strncasecmp(s,t,n) strnicmp((s), (t), (n)) +#elif defined(__EMX__) +# define strcasecmp(s,t) stricmp((s), (t)) +# define strncasecmp(s,t,n) strnicmp((s), (t), (n)) +#else +# include +#endif // WIN32 + + +// +// GIF definitions... +// + +#define GIF_INTERLACE 0x40 +#define GIF_COLORMAP 0x80 + +typedef unsigned char gif_cmap_t[256][3]; + + +// +// Local functions... +// + +#if 0 +static int gif_read_cmap(FILE *fp, int ncolors, gif_cmap_t cmap); +static int gif_get_block(FILE *fp, unsigned char *buffer); +static int gif_get_code (FILE *fp, int code_size, int first_time); +static int gif_read_lzw(FILE *fp, int first_time, int input_code_size); +static int gif_read_image(FILE *fp, Fl_Help_Image *img, gif_cmap_t cmap, + int interlace); + + +// +// 'Fl_Help_View::load_gif()' - Load a GIF image file... +// + +int // O - 0 = success, -1 = fail +Fl_Help_View::load_gif(Fl_Help_Image *img,// I - Image pointer + FILE *fp)// I - File to load from +{ + unsigned char buf[1024]; // Input buffer + gif_cmap_t cmap; // Colormap + int ncolors, // Bits per pixel + transparent; // Transparent color index + + + // Read the header; we already know it is a GIF file... + fread(buf, 13, 1, fp); + + img->w = (buf[7] << 8) | buf[6]; + img->h = (buf[9] << 8) | buf[8]; + ncolors = 2 << (buf[10] & 0x07); + + if (buf[10] & GIF_COLORMAP) + if (!gif_read_cmap(fp, ncolors, cmap)) + return (0); + + transparent = -1; + + for (;;) + { + switch (getc(fp)) + { + case ';' : // End of image + return (0); // Early end of file + + case '!' : // Extension record + buf[0] = getc(fp); + if (buf[0] == 0xf9) // Graphic Control Extension + { + gif_get_block(fp, buf); + if (buf[0] & 1) // Get transparent color index + transparent = buf[3]; + } + + while (gif_get_block(fp, buf) != 0); + break; + + case ',' : // Image data + fread(buf, 9, 1, fp); + + if (buf[8] & GIF_COLORMAP) + { + ncolors = 2 << (buf[8] & 0x07); + + if (!gif_read_cmap(fp, ncolors, cmap)) + return (0); + } + + if (transparent >= 0) + { + unsigned rgba = fltk_colors[bgcolor_]; + + + // Map transparent color to background color... + cmap[transparent][0] = rgba >> 24; + cmap[transparent][1] = rgba >> 16; + cmap[transparent][2] = rgba >> 8; + } + + img->w = (buf[5] << 8) | buf[4]; + img->h = (buf[7] << 8) | buf[6]; + img->d = 3; + img->data = (unsigned char *)malloc(img->w * img->h * img->d); + if (img->data == NULL) + return (0); + + return (gif_read_image(fp, img, cmap, buf[8] & GIF_INTERLACE)); + } + } +} + + +// +// 'gif_read_cmap()' - Read the colormap from a GIF file... +// + +static int // O - -1 = error, 0 = success +gif_read_cmap(FILE *fp, // I - File to read from + int ncolors, // I - Number of colors + gif_cmap_t cmap) // O - Colormap +{ + // Read the colormap... + if (fread(cmap, 3, ncolors, fp) < (size_t)ncolors) + return (0); + + return (1); +} + + +// +// 'gif_get_block()' - Read a GIF data block... +// + +static int // O - Number characters read +gif_get_block(FILE *fp, // I - File to read from + unsigned char *buf) // I - Input buffer +{ + int count; // Number of character to read + + + // Read the count byte followed by the data from the file... + if ((count = getc(fp)) == EOF) + { + gif_eof = 1; + return (-1); + } + else if (count == 0) + gif_eof = 1; + else if (fread(buf, 1, count, fp) < (size_t)count) + { + gif_eof = 1; + return (-1); + } + else + gif_eof = 0; + + return (count); +} + + +// +// 'gif_get_code()' - Get a LZW code from the file... +// + +static int // O - LZW code +gif_get_code(FILE *fp, // I - File to read from + int code_size, // I - Size of code in bits + int first_time) // I - 1 = first time, 0 = not first time +{ + unsigned i, j, // Looping vars + ret; // Return value + int count; // Number of bytes read + static unsigned char buf[280]; // Input buffer + static unsigned curbit, // Current bit + lastbit, // Last bit in buffer + done, // Done with this buffer? + last_byte; // Last byte in buffer + static unsigned bits[8] = // Bit masks for codes + { + 0x01, 0x02, 0x04, 0x08, + 0x10, 0x20, 0x40, 0x80 + }; + + + if (first_time) + { + // Just initialize the input buffer... + curbit = 0; + lastbit = 0; + done = 0; + + return (0); + } + + + if ((curbit + code_size) >= lastbit) + { + // Don't have enough bits to hold the code... + if (done) + return (-1); // Sorry, no more... + + // Move last two bytes to front of buffer... + if (last_byte > 1) + { + buf[0] = buf[last_byte - 2]; + buf[1] = buf[last_byte - 1]; + last_byte = 2; + } + else if (last_byte == 1) + { + buf[0] = buf[last_byte - 1]; + last_byte = 1; + } + + // Read in another buffer... + if ((count = gif_get_block (fp, buf + last_byte)) <= 0) + { + // Whoops, no more data! + done = 1; + return (-1); + } + + // Update buffer state... + curbit = (curbit - lastbit) + 8 * last_byte; + last_byte += count; + lastbit = last_byte * 8; + } + + ret = 0; + for (ret = 0, i = curbit + code_size - 1, j = code_size; + j > 0; + i --, j --) + ret = (ret << 1) | ((buf[i / 8] & bits[i & 7]) != 0); + + curbit += code_size; + + return ret; +} + + +// +// 'gif_read_lzw()' - Read a byte from the LZW stream... +// + +static int // I - Byte from stream +gif_read_lzw(FILE *fp, // I - File to read from + int first_time, // I - 1 = first time, 0 = not first time + int input_code_size) // I - Code size in bits +{ + int i, // Looping var + code, // Current code + incode; // Input code + static short fresh = 0, // 1 = empty buffers + code_size, // Current code size + set_code_size, // Initial code size set + max_code, // Maximum code used + max_code_size, // Maximum code size + firstcode, // First code read + oldcode, // Last code read + clear_code, // Clear code for LZW input + end_code, // End code for LZW input + table[2][4096], // String table + stack[8192], // Output stack + *sp; // Current stack pointer + + + if (first_time) + { + // Setup LZW state... + set_code_size = input_code_size; + code_size = set_code_size + 1; + clear_code = 1 << set_code_size; + end_code = clear_code + 1; + max_code_size = 2 * clear_code; + max_code = clear_code + 2; + + // Initialize input buffers... + gif_get_code(fp, 0, 1); + + // Wipe the decompressor table... + fresh = 1; + + for (i = 0; i < clear_code; i ++) + { + table[0][i] = 0; + table[1][i] = i; + } + + for (; i < 4096; i ++) + table[0][i] = table[1][0] = 0; + + sp = stack; + + return (0); + } + else if (fresh) + { + fresh = 0; + + do + firstcode = oldcode = gif_get_code(fp, code_size, 0); + while (firstcode == clear_code); + + return (firstcode); + } + + if (sp > stack) + return (*--sp); + + while ((code = gif_get_code (fp, code_size, 0)) >= 0) + { + if (code == clear_code) + { + for (i = 0; i < clear_code; i ++) + { + table[0][i] = 0; + table[1][i] = i; + } + + for (; i < 4096; i ++) + table[0][i] = table[1][i] = 0; + + code_size = set_code_size + 1; + max_code_size = 2 * clear_code; + max_code = clear_code + 2; + + sp = stack; + + firstcode = oldcode = gif_get_code(fp, code_size, 0); + + return (firstcode); + } + else if (code == end_code) + { + unsigned char buf[260]; + + + if (!gif_eof) + while (gif_get_block(fp, buf) > 0); + + return (-2); + } + + incode = code; + + if (code >= max_code) + { + *sp++ = firstcode; + code = oldcode; + } + + while (code >= clear_code) + { + *sp++ = table[1][code]; + if (code == table[0][code]) + return (255); + + code = table[0][code]; + } + + *sp++ = firstcode = table[1][code]; + code = max_code; + + if (code < 4096) + { + table[0][code] = oldcode; + table[1][code] = firstcode; + max_code ++; + + if (max_code >= max_code_size && max_code_size < 4096) + { + max_code_size *= 2; + code_size ++; + } + } + + oldcode = incode; + + if (sp > stack) + return (*--sp); + } + + return (code); +} + + +// +// 'gif_read_image()' - Read a GIF image stream... +// + +static int // I - 0 = success, -1 = failure +gif_read_image(FILE *fp, // I - Input file + Fl_Help_Image *img, // I - Image pointer + gif_cmap_t cmap, // I - Colormap + int interlace) // I - Non-zero = interlaced image +{ + unsigned char code_size, // Code size + *temp; // Current pixel + int xpos, // Current X position + ypos, // Current Y position + pass; // Current pass + int pixel; // Current pixel + static int xpasses[4] = { 8, 8, 4, 2 }, + ypasses[5] = { 0, 4, 2, 1, 999999 }; + + + xpos = 0; + ypos = 0; + pass = 0; + code_size = getc(fp); + + if (gif_read_lzw(fp, 1, code_size) < 0) + return (0); + + temp = img->data; + + while ((pixel = gif_read_lzw(fp, 0, code_size)) >= 0) + { + temp[0] = cmap[pixel][0]; + + if (img->d > 1) + { + temp[1] = cmap[pixel][1]; + temp[2] = cmap[pixel][2]; + } + + xpos ++; + temp += img->d; + if (xpos == img->w) + { + xpos = 0; + + if (interlace) + { + ypos += xpasses[pass]; + temp += (xpasses[pass] - 1) * img->w * img->d; + + if (ypos >= img->h) + { + pass ++; + + ypos = ypasses[pass]; + temp = img->data + ypos * img->w * img->d; + } + } + else + ypos ++; + } + + if (ypos >= img->h) + break; + } + + return (1); +} +#endif + + +// +// End of "$Id: Fl_GIF_Image.cxx,v 1.1.2.1 2001/11/19 01:06:45 easysw Exp $". +// diff --git a/src/Fl_Image.cxx b/src/Fl_Image.cxx index e2e7bd843..3663e4224 100644 --- a/src/Fl_Image.cxx +++ b/src/Fl_Image.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Image.cxx,v 1.5.2.3.2.2 2001/11/18 20:52:28 easysw Exp $" +// "$Id: Fl_Image.cxx,v 1.5.2.3.2.3 2001/11/19 01:06:45 easysw Exp $" // // Image drawing code for the Fast Light Tool Kit (FLTK). // @@ -39,6 +39,16 @@ Fl_Image::~Fl_Image() { void Fl_Image::draw(int XP, int YP, int WP, int HP, int cx, int cy) { } +Fl_Image *Fl_Image::copy(int W, int H) { + return new Fl_Image(W, H); +} + +void Fl_Image::color_average(Fl_Color c, float i) { +} + +void Fl_Image::desaturate() { +} + void Fl_Image::label(Fl_Widget* w) { w->image(this); } @@ -48,6 +58,166 @@ void Fl_Image::label(Fl_Menu_Item* m) { Fl_RGB_Image::~Fl_RGB_Image() { if (id) fl_delete_offscreen((Fl_Offscreen)id); + if (alloc_array) delete[] array; +} + +Fl_Image *Fl_RGB_Image::copy(int W, int H) { + // Optimize the simple copy where the width and height are the same... + if (W == w() && H == h()) return new Fl_RGB_Image(array, w(), h(), d, ld); + + // OK, need to resize the image data; allocate memory and + Fl_RGB_Image *new_image; // New RGB image + uchar *new_array, // New array for image data + *new_ptr; // Pointer into new array + const uchar *old_ptr; // Pointer into old array + int c, // Channel number + sy, // Source coordinate + dx, dy, // Destination coordinates + xerr, yerr, // X & Y errors + xmod, ymod, // X & Y moduli + xstep, ystep; // X & Y step increments + + + // Figure out Bresenheim step/modulus values... + xmod = w() % W; + xstep = (w() / W) * d; + ymod = h() % H; + ystep = h() / H; + + // Allocate memory for the new image... + new_array = new uchar [W * H * d]; + new_image = new Fl_RGB_Image(new_array, W, H, d); + new_image->alloc_array = 1; + + // Scale the image using a nearest-neighbor algorithm... + for (dy = h(), sy = 0, yerr = H / 2, new_ptr = new_array; dy > 0; dy --) { + for (dx = w(), xerr = W / 2, old_ptr = array + sy * (w() * d + ld); + dx > 0; + dx --) { + for (c = 0; c < d; c ++) *new_ptr++ = old_ptr[c]; + + old_ptr += xstep; + xerr -= xmod; + + if (xerr <= 0) { + xerr += W; + old_ptr += d; + } + } + + sy += ystep; + yerr -= ymod; + if (yerr <= 0) { + yerr += H; + sy ++; + } + } + + return new_image; +} + +void Fl_RGB_Image::color_average(Fl_Color c, float i) { + // Delete any existing pixmap/mask objects... + if (id) { + fl_delete_offscreen(id); + id = 0; + } + + if (mask) { + fl_delete_bitmask(mask); + mask = 0; + } + + // Allocate memory as needed... + uchar *new_array, + *new_ptr; + + if (!alloc_array) new_array = new uchar[h() * w() * d]; + else new_array = (uchar *)array; + + // Get the color to blend with... + uchar r, g, b; + unsigned ia, ir, ig, ib; + + Fl::get_color(c, r, g, b); + if (i < 0.0f) i = 0.0f; + else if (i > 1.0f) i = 1.0f; + + ia = (unsigned)(256 * i); + ir = r * (256 - ia); + ig = g * (256 - ia); + ib = b * (256 - ia); + + // Update the image data to do the blend... + const uchar *old_ptr; + int x, y; + + if (d < 3) { + ig = (r * 31 + g * 61 + b * 8) / 100 * (256 - ia); + + for (new_ptr = new_array, old_ptr = array, y = 0; y < h(); y ++, old_ptr += ld) + for (x = 0; x < w(); x ++) { + *new_ptr++ = (*old_ptr++ * ia + ig) >> 8; + if (d > 1) *new_ptr++ = *old_ptr++; + } + } else { + for (new_ptr = new_array, old_ptr = array, y = 0; y < h(); y ++, old_ptr += ld) + for (x = 0; x < w(); x ++) { + *new_ptr++ = (*old_ptr++ * ia + ir) >> 8; + *new_ptr++ = (*old_ptr++ * ia + ig) >> 8; + *new_ptr++ = (*old_ptr++ * ia + ib) >> 8; + if (d > 3) *new_ptr++ = *old_ptr++; + } + } + + // Set the new pointers/values as needed... + if (!alloc_array) { + array = new_array; + alloc_array = 1; + ld = 0; + } +} + +void Fl_RGB_Image::desaturate() { + // Can only desaturate color images... + if (d < 3) return; + + // Delete any existing pixmap/mask objects... + if (id) { + fl_delete_offscreen(id); + id = 0; + } + + if (mask) { + fl_delete_bitmask(mask); + mask = 0; + } + + // Allocate memory for a grayscale image... + uchar *new_array, + *new_ptr; + int new_d; + + new_d = d - 2; + new_array = new uchar[h() * w() * new_d]; + + // Copy the image data, converting to grayscale... + const uchar *old_ptr; + int x, y; + + for (new_ptr = new_array, old_ptr = array, y = 0; y < h(); y ++, old_ptr += ld) + for (x = 0; x < w(); x ++, old_ptr += d) { + *new_ptr++ = (31 * old_ptr[0] + 61 * old_ptr[1] + 8 * old_ptr[2]) / 100; + if (d > 3) *new_ptr++ = old_ptr[3]; + } + + // Free the old array as needed, and then set the new pointers/values... + if (alloc_array) delete[] array; + + array = new_array; + alloc_array = 1; + d = new_d; + ld = 0; } void Fl_RGB_Image::draw(int XP, int YP, int WP, int HP, int cx, int cy) { @@ -113,7 +283,7 @@ void Fl_RGB_Image::draw(int XP, int YP, int WP, int HP, int cx, int cy) { // definitely fast... memset(bitmap, 0, bmw * h()); - for (dataptr = array + d - 1, y = 0; y < h(); y ++) + for (dataptr = array + d - 1, y = 0; y < h(); y ++, dataptr += ld) for (bitptr = bitmap + y * bmw, bit = 128, x = 0; x < w(); x ++, dataptr += d) { if (*dataptr > dither[x & 15][y & 15]) *bitptr |= bit; @@ -224,5 +394,5 @@ void Fl_RGB_Image::label(Fl_Menu_Item* m) { // -// End of "$Id: Fl_Image.cxx,v 1.5.2.3.2.2 2001/11/18 20:52:28 easysw Exp $". +// End of "$Id: Fl_Image.cxx,v 1.5.2.3.2.3 2001/11/19 01:06:45 easysw Exp $". // diff --git a/src/Fl_JPEG_Image.cxx b/src/Fl_JPEG_Image.cxx new file mode 100644 index 000000000..0c38b4709 --- /dev/null +++ b/src/Fl_JPEG_Image.cxx @@ -0,0 +1,126 @@ +// +// "$Id: Fl_JPEG_Image.cxx,v 1.1.2.1 2001/11/19 01:06:45 easysw Exp $" +// +// Fl_JPEG_Image routines. +// +// Copyright 1997-2001 by Easy Software Products. +// 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: +// +// + +// +// Include necessary header files... +// + +#include +#include "config.h" +#include +#include +#include +#include +#ifdef HAVE_STRINGS_H +# include +#endif /* HAVE_STRINGS_H */ +#include + +#if defined(WIN32) && ! defined(__CYGWIN__) +# include +# include +# define strcasecmp(s,t) stricmp((s), (t)) +# define strncasecmp(s,t,n) strnicmp((s), (t), (n)) +#elif defined(__EMX__) +# define strcasecmp(s,t) stricmp((s), (t)) +# define strncasecmp(s,t,n) strnicmp((s), (t), (n)) +#else +# include +#endif // WIN32 + +extern "C" +{ +#ifdef HAVE_LIBJPEG +# include +#endif // HAVE_LIBJPEG +} + +#define MAX_COLUMNS 200 + + +#if 0 +#ifdef HAVE_LIBJPEG +// +// 'Fl_Help_View::load_jpeg()' - Load a JPEG image file. +// + +int // O - 0 = success, -1 = fail +Fl_Help_View::load_jpeg(Fl_Help_Image *img, // I - Image pointer + FILE *fp) // I - File to load from +{ + struct jpeg_decompress_struct cinfo; // Decompressor info + struct jpeg_error_mgr jerr; // Error handler info + JSAMPROW row; // Sample row pointer + + + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_decompress(&cinfo); + jpeg_stdio_src(&cinfo, fp); + jpeg_read_header(&cinfo, 1); + + cinfo.quantize_colors = 0; + cinfo.out_color_space = JCS_RGB; + cinfo.out_color_components = 3; + cinfo.output_components = 3; + + jpeg_calc_output_dimensions(&cinfo); + + img->w = cinfo.output_width; + img->h = cinfo.output_height; + img->d = cinfo.output_components; + img->data = (unsigned char *)malloc(img->w * img->h * img->d); + + if (img->data == NULL) + { + jpeg_destroy_decompress(&cinfo); + return (0); + } + + jpeg_start_decompress(&cinfo); + + while (cinfo.output_scanline < cinfo.output_height) + { + row = (JSAMPROW)(img->data + + cinfo.output_scanline * cinfo.output_width * + cinfo.output_components); + jpeg_read_scanlines(&cinfo, &row, (JDIMENSION)1); + } + + jpeg_finish_decompress(&cinfo); + jpeg_destroy_decompress(&cinfo); + + return (1); +} +#endif // HAVE_LIBJPEG + +#endif // 0 + +// +// End of "$Id: Fl_JPEG_Image.cxx,v 1.1.2.1 2001/11/19 01:06:45 easysw Exp $". +// diff --git a/src/Fl_PNG_Image.cxx b/src/Fl_PNG_Image.cxx new file mode 100644 index 000000000..36ede18ff --- /dev/null +++ b/src/Fl_PNG_Image.cxx @@ -0,0 +1,146 @@ +// +// "$Id: Fl_PNG_Image.cxx,v 1.1.2.1 2001/11/19 01:06:45 easysw Exp $" +// +// Fl_PNG_Image routines. +// +// Copyright 1997-2001 by Easy Software Products. +// 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: +// +// + +// +// Include necessary header files... +// + +#include +#include "config.h" +#include +#include +#include +#include +#ifdef HAVE_STRINGS_H +# include +#endif /* HAVE_STRINGS_H */ +#include + +extern "C" +{ +#ifdef HAVE_LIBPNG +# include +# include +#endif // HAVE_LIBPNG +} + + +#if 0 +#ifdef HAVE_LIBPNG +// +// 'Fl_Help_View::load_png()' - 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 +{ + int i; // Looping var + png_structp pp; // PNG read pointer + png_infop info; // PNG info pointers + png_bytep *rows; // PNG row pointers + png_color_16 bg; // Background color + + + // Setup the PNG data structures... + pp = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + info = png_create_info_struct(pp); + + // Initialize the PNG read "engine"... + png_init_io(pp, fp); + + // Get the image dimensions and convert to grayscale or RGB... + png_read_info(pp, info); + + if (info->color_type == PNG_COLOR_TYPE_PALETTE) + png_set_expand(pp); + + if (info->color_type & PNG_COLOR_MASK_COLOR) + img->d = 3; + else + img->d = 1; + + if ((info->color_type & PNG_COLOR_MASK_ALPHA) || info->num_trans) + img->d ++; + + if (info->bit_depth < 8) + { + png_set_packing(pp); + png_set_expand(pp); + } + else if (info->bit_depth == 16) + png_set_strip_16(pp); + +#if defined(HAVE_PNG_GET_VALID) && defined(HAVE_SET_TRNS_TO_ALPHA) + // Handle transparency... + if (png_get_valid(pp, info, PNG_INFO_tRNS)) + 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); + + // Allocate pointers... + rows = (png_bytep *)calloc(info->height, sizeof(png_bytep)); + + for (i = 0; i < (int)info->height; i ++) + rows[i] = img->data + i * img->w * img->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); + + // Free memory and return... + free(rows); + + png_read_end(pp, info); +# ifdef HAVE_PNG_READ_DESTROY + png_read_destroy(pp, info, NULL); +# else + png_destroy_read_struct(&pp, &info, NULL); +# endif // HAVE_PNG_READ_DESTROY + + return (1); +} +#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 $". +// diff --git a/src/Fl_Pixmap.cxx b/src/Fl_Pixmap.cxx index cf3b65465..67a584238 100644 --- a/src/Fl_Pixmap.cxx +++ b/src/Fl_Pixmap.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Pixmap.cxx,v 1.9.2.4.2.3 2001/11/18 20:52:28 easysw Exp $" +// "$Id: Fl_Pixmap.cxx,v 1.9.2.4.2.4 2001/11/19 01:06:45 easysw Exp $" // // Pixmap drawing code for the Fast Light Tool Kit (FLTK). // @@ -38,6 +38,8 @@ #include #include +#include +#include extern uchar **fl_mask_bitmap; // used by fl_draw_pixmap.cxx to store mask void fl_restore_clip(); // in fl_rect.cxx @@ -172,6 +174,7 @@ void Fl_Pixmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) { Fl_Pixmap::~Fl_Pixmap() { if (id) fl_delete_offscreen(id); if (mask) fl_delete_bitmask(mask); + delete_data(); } void Fl_Pixmap::label(Fl_Widget* w) { @@ -181,6 +184,316 @@ void Fl_Pixmap::label(Fl_Widget* w) { void Fl_Pixmap::label(Fl_Menu_Item* m) { } +void Fl_Pixmap::copy_data() { + if (alloc_data) return; + + char **new_data, // New data array + **new_row; // Current row in image + int i, // Looping var + ncolors, // Number of colors in image + chars_per_pixel,// Characters per color + chars_per_line; // Characters per line + + // Figure out how many colors there are, and how big they are... + sscanf(data[0],"%*d%*d%d%d", &ncolors, &chars_per_pixel); + chars_per_line = chars_per_pixel * w() + 1; + + // Allocate memory for the new array... + new_data = new char *[h() + ncolors + 1]; + new_data[0] = new char[strlen(data[0]) + 1]; + strcpy(new_data[0], data[0]); + + // Copy colors... + if (ncolors < 0) { + // Copy FLTK colormap values... + ncolors = -ncolors; + for (i = 0, new_row = new_data + 1; i < ncolors; i ++, new_row ++) { + *new_row = new char[4]; + memcpy(*new_row, data[i + 1], 4); + } + } else { + // Copy standard XPM colormap values... + for (i = 0, new_row = new_data + 1; i < ncolors; i ++, new_row ++) { + *new_row = new char[strlen(data[i + 1]) + 1]; + strcpy(*new_row, data[i + 1]); + } + } + + // Copy image data... + for (i = 0; i < h(); i ++, new_row ++) { + *new_row = new char[chars_per_line]; + memcpy(*new_row, data[i + ncolors + 1], chars_per_line); + } + + // Update pointers... + data = new_data; + alloc_data = 1; +} + +Fl_Image *Fl_Pixmap::copy(int W, int H) { + // Optimize the simple copy where the width and height are the same... + if (W == w() && H == h()) return new Fl_Pixmap(data); + + // OK, need to resize the image data; allocate memory and + Fl_Pixmap *new_image; // New pixmap + char **new_data, // New array for image data + **new_row, // Pointer to row in image data + *new_ptr, // Pointer into new array + new_info[255]; // New information line + const char *old_ptr; // Pointer into old array + int i, // Looping var + c, // Channel number + sy, // Source coordinate + dx, dy, // Destination coordinates + xerr, yerr, // X & Y errors + xmod, ymod, // X & Y moduli + xstep, ystep; // X & Y step increments + int ncolors, // Number of colors in image + chars_per_pixel,// Characters per color + chars_per_line; // Characters per line + + // Figure out how many colors there are, and how big they are... + sscanf(data[0],"%*d%*d%d%d", &ncolors, &chars_per_pixel); + chars_per_line = chars_per_pixel * W + 1; + + sprintf(new_info, "%d %d %d %d", W, H, ncolors, chars_per_pixel); + + // Figure out Bresenheim step/modulus values... + xmod = w() % W; + xstep = (w() / W) * chars_per_pixel; + ymod = h() % H; + ystep = h() / H; + + // Allocate memory for the new array... + new_data = new char *[H + ncolors + 1]; + new_data[0] = new char[strlen(new_info) + 1]; + strcpy(new_data[0], new_info); + + // Copy colors... + if (ncolors < 0) { + // Copy FLTK colormap values... + ncolors = -ncolors; + for (i = 0, new_row = new_data + 1; i < ncolors; i ++, new_row ++) { + *new_row = new char[4]; + memcpy(*new_row, data[i + 1], 4); + } + } else { + // Copy standard XPM colormap values... + for (i = 0, new_row = new_data + 1; i < ncolors; i ++, new_row ++) { + *new_row = new char[strlen(data[i + 1]) + 1]; + strcpy(*new_row, data[i + 1]); + } + } + + // Copy image data... + for (i = 0; i < h(); i ++, new_row ++) { + *new_row = new char[chars_per_line]; + memcpy(*new_row, data[i + ncolors + 1], chars_per_line); + } + // Scale the image using a nearest-neighbor algorithm... + for (dy = h(), sy = 0, yerr = H / 2; dy > 0; dy --, new_row ++) { + *new_row = new char[chars_per_line]; + new_ptr = *new_row; + + for (dx = w(), xerr = W / 2, old_ptr = data[sy + ncolors + 1]; + dx > 0; + dx --) { + for (c = 0; c < chars_per_pixel; c ++) *new_ptr++ = old_ptr[c]; + + old_ptr += xstep; + xerr -= xmod; + + if (xerr <= 0) { + xerr += W; + old_ptr += chars_per_pixel; + } + } + + *new_ptr = '\0'; + sy += ystep; + yerr -= ymod; + if (yerr <= 0) { + yerr += H; + sy ++; + } + } + + new_image = new Fl_Pixmap((const char * const *)data); + new_image->alloc_data = 1; + + return new_image; +} + +void Fl_Pixmap::color_average(Fl_Color c, float i) { + // Delete any existing pixmap/mask objects... + if (id) { + fl_delete_offscreen(id); + id = 0; + } + + if (mask) { + fl_delete_bitmask(mask); + mask = 0; + } + + // Allocate memory as needed... + copy_data(); + + // Get the color to blend with... + uchar r, g, b; + unsigned ia, ir, ig, ib; + + Fl::get_color(c, r, g, b); + if (i < 0.0f) i = 0.0f; + else if (i > 1.0f) i = 1.0f; + + ia = (unsigned)(256 * i); + ir = r * (256 - ia); + ig = g * (256 - ia); + ib = b * (256 - ia); + + // Update the colormap to do the blend... + char line[255]; // New colormap line + int color, // Looping var + ncolors, // Number of colors in image + chars_per_pixel;// Characters per color + + + sscanf(data[0],"%*d%*d%d%d", &ncolors, &chars_per_pixel); + + if (ncolors < 0) { + // Update FLTK colormap... + ncolors = -ncolors; + for (color = 0; color < ncolors; color ++) { + ((char *)data[color + 1])[1] = (ia * data[color + 1][1] + ir) >> 8; + ((char *)data[color + 1])[2] = (ia * data[color + 1][2] + ig) >> 8; + ((char *)data[color + 1])[3] = (ia * data[color + 1][3] + ib) >> 8; + } + } else { + // Update standard XPM colormap... + for (color = 0; color < ncolors; color ++) { + // look for "c word", or last word if none: + const char *p = data[color + 1] + chars_per_pixel + 1; + const char *previous_word = p; + for (;;) { + while (*p && isspace(*p)) p++; + char what = *p++; + while (*p && !isspace(*p)) p++; + while (*p && isspace(*p)) p++; + if (!*p) {p = previous_word; break;} + if (what == 'c') break; + previous_word = p; + while (*p && !isspace(*p)) p++; + } + +#ifdef WIN32 + if (fl_parse_color(p, r, g, b) { +#else + XColor x; + if (XParseColor(fl_display, fl_colormap, p, &x)) { + r = x.red>>8; + g = x.green>>8; + b = x.blue>>8; +#endif + + r = (ia * r + ir) >> 8; + g = (ia * g + ig) >> 8; + b = (ia * b + ib) >> 8; + + if (chars_per_pixel > 1) sprintf(line, "%c%c c #%02X%02X%02X", + data[color + 1][0], + data[color + 1][1], r, g, b); + else sprintf(line, "%c c #%02X%02X%02X", data[color + 1][0], r, g, b); + + delete[] data[color + 1]; + ((char **)data)[color + 1] = new char[strlen(line) + 1]; + strcpy((char *)data[color + 1], line); + } + } + } +} + +void Fl_Pixmap::delete_data() { + if (alloc_data) { + for (int i = 0; data[i]; i ++) delete[] data[i]; + delete[] data; + } +} + +void Fl_Pixmap::desaturate() { + // Delete any existing pixmap/mask objects... + if (id) { + fl_delete_offscreen(id); + id = 0; + } + + if (mask) { + fl_delete_bitmask(mask); + mask = 0; + } + + // Allocate memory as needed... + copy_data(); + + // Update the colormap to grayscale... + char line[255]; // New colormap line + int i, // Looping var + ncolors, // Number of colors in image + chars_per_pixel;// Characters per color + uchar r, g, b; + + sscanf(data[0],"%*d%*d%d%d", &ncolors, &chars_per_pixel); + + if (ncolors < 0) { + // Update FLTK colormap... + ncolors = -ncolors; + for (i = 0; i < ncolors; i ++) { + g = (data[i + 1][1] * 31 + data[i + 1][2] * 61 + data[i + 1][3] * 8) / 100; + ((char *)data[i + 1])[1] = + ((char *)data[i + 1])[2] = + ((char *)data[i + 1])[3] = g; + } + } else { + // Update standard XPM colormap... + for (i = 0; i < ncolors; i ++) { + // look for "c word", or last word if none: + const char *p = data[i + 1] + chars_per_pixel + 1; + const char *previous_word = p; + for (;;) { + while (*p && isspace(*p)) p++; + char what = *p++; + while (*p && !isspace(*p)) p++; + while (*p && isspace(*p)) p++; + if (!*p) {p = previous_word; break;} + if (what == 'c') break; + previous_word = p; + while (*p && !isspace(*p)) p++; + } + +#ifdef WIN32 + if (fl_parse_color(p, r, g, b) { +#else + XColor x; + if (XParseColor(fl_display, fl_colormap, p, &x)) { + r = x.red>>8; + g = x.green>>8; + b = x.blue>>8; +#endif + + g = (r * 31 + g * 61 + b * 8) / 100; + + if (chars_per_pixel > 1) sprintf(line, "%c%c c #%02X%02X%02X", data[i + 1][0], + data[i + 1][1], g, g, g); + else sprintf(line, "%c c #%02X%02X%02X", data[i + 1][0], g, g, g); + + delete[] data[i + 1]; + ((char **)data)[i + 1] = new char[strlen(line) + 1]; + strcpy((char *)data[i + 1], line); + } + } + } +} + // -// End of "$Id: Fl_Pixmap.cxx,v 1.9.2.4.2.3 2001/11/18 20:52:28 easysw Exp $". +// End of "$Id: Fl_Pixmap.cxx,v 1.9.2.4.2.4 2001/11/19 01:06:45 easysw Exp $". // diff --git a/src/Makefile b/src/Makefile index bac65c5ad..44b851c84 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ # -# "$Id: Makefile,v 1.18.2.14.2.16 2001/11/17 15:27:15 easysw Exp $" +# "$Id: Makefile,v 1.18.2.14.2.17 2001/11/19 01:06:45 easysw Exp $" # # Library makefile for the Fast Light Tool Kit (FLTK). # @@ -46,12 +46,14 @@ CPPFILES = \ Fl_File_Chooser2.cxx \ Fl_File_Icon.cxx \ Fl_File_Icon2.cxx \ + Fl_GIF_Image.cxx \ Fl_Group.cxx \ Fl_Help_Dialog.cxx \ Fl_Help_View.cxx \ Fl_Image.cxx \ Fl_Input.cxx \ Fl_Input_.cxx \ + Fl_JPEG_Image.cxx \ Fl_Light_Button.cxx \ Fl_Menu.cxx \ Fl_Menu_.cxx \ @@ -65,6 +67,7 @@ CPPFILES = \ Fl_Overlay_Window.cxx \ Fl_Pack.cxx \ Fl_Pixmap.cxx \ + Fl_PNG_Image.cxx \ Fl_Positioner.cxx \ Fl_Progress.cxx \ Fl_Repeat_Button.cxx \ @@ -268,5 +271,5 @@ install: $(LIBNAME) $(DSONAME) $(GLLIBNAME) $(GLDSONAME) ln -s FL $(includedir)/Fl # -# End of "$Id: Makefile,v 1.18.2.14.2.16 2001/11/17 15:27:15 easysw Exp $". +# End of "$Id: Makefile,v 1.18.2.14.2.17 2001/11/19 01:06:45 easysw Exp $". # diff --git a/src/fl_draw_pixmap.cxx b/src/fl_draw_pixmap.cxx index 37fed65c9..853078d69 100644 --- a/src/fl_draw_pixmap.cxx +++ b/src/fl_draw_pixmap.cxx @@ -1,5 +1,5 @@ // -// "$Id: fl_draw_pixmap.cxx,v 1.4.2.8.2.1 2001/11/18 20:52:28 easysw Exp $" +// "$Id: fl_draw_pixmap.cxx,v 1.4.2.8.2.2 2001/11/19 01:06:45 easysw Exp $" // // Pixmap drawing code for the Fast Light Tool Kit (FLTK). // @@ -48,7 +48,7 @@ int fl_measure_pixmap(/*const*/ char* const* data, int &w, int &h) { } int fl_measure_pixmap(const char * const *data, int &w, int &h) { - int i = sscanf(data[0],"%d %d %d %d",&w,&h,&ncolors,&chars_per_pixel); + int i = sscanf(data[0],"%d%d%d%d",&w,&h,&ncolors,&chars_per_pixel); if (i<4 || w<=0 || h<=0 || chars_per_pixel!=1 && chars_per_pixel!=2) return w=0; return 1; @@ -203,7 +203,8 @@ int fl_draw_pixmap(const char*const* di, int x, int y, Fl_Color bg) { // look for "c word", or last word if none: const uchar *previous_word = p; for (;;) { - while (*p && isspace(*p)) p++; uchar what = *p++; + while (*p && isspace(*p)) p++; + uchar what = *p++; while (*p && !isspace(*p)) p++; while (*p && isspace(*p)) p++; if (!*p) {p = previous_word; break;} @@ -224,7 +225,7 @@ int fl_draw_pixmap(const char*const* di, int x, int y, Fl_Color bg) { if (XParseColor(fl_display, fl_colormap, (const char*)p, &x)) { c[0] = x.red>>8; c[1] = x.green>>8; c[2] = x.blue>>8; #endif - } else { // assumme "None" or "#transparent" for any errors + } else { // assume "None" or "#transparent" for any errors // this should be transparent... Fl::get_color(bg, c[0], c[1], c[2]); transparent_index = index; @@ -272,5 +273,5 @@ int fl_draw_pixmap(const char*const* di, int x, int y, Fl_Color bg) { } // -// End of "$Id: fl_draw_pixmap.cxx,v 1.4.2.8.2.1 2001/11/18 20:52:28 easysw Exp $". +// End of "$Id: fl_draw_pixmap.cxx,v 1.4.2.8.2.2 2001/11/19 01:06:45 easysw Exp $". // diff --git a/src/makedepend b/src/makedepend index 5ec30ec5e..44f6089d2 100644 --- a/src/makedepend +++ b/src/makedepend @@ -90,6 +90,9 @@ Fl_File_Icon.o: ../FL/fl_draw.H ../FL/filename.H Fl_File_Icon2.o: ../config.h ../FL/Fl_File_Icon.H ../FL/Fl.H Fl_File_Icon2.o: ../FL/Enumerations.H ../FL/Fl_Export.H ../FL/Fl_Widget.H Fl_File_Icon2.o: ../FL/fl_draw.H ../FL/filename.H +Fl_GIF_Image.o: ../FL/Fl_GIF_Image.H ../FL/Fl_Pixmap.H ../FL/Fl_Image.H +Fl_GIF_Image.o: ../FL/x.H ../FL/Enumerations.H ../FL/Fl_Export.H +Fl_GIF_Image.o: ../FL/Fl_Window.H ../config.h Fl_Group.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H Fl_Group.o: ../FL/Fl_Group.H ../FL/Fl_Window.H ../FL/Fl_Group.H Fl_Group.o: ../FL/Fl_Widget.H ../FL/fl_draw.H ../FL/Fl_Tooltip.H @@ -112,6 +115,9 @@ Fl_Input.o: ../FL/Fl_Input.H ../FL/Fl_Input_.H ../FL/fl_draw.H Fl_Input_.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H Fl_Input_.o: ../FL/Fl_Input_.H ../FL/Fl_Widget.H ../FL/fl_draw.H Fl_Input_.o: ../FL/fl_ask.H +Fl_JPEG_Image.o: ../FL/Fl_JPEG_Image.H ../FL/Fl_Image.H ../FL/x.H +Fl_JPEG_Image.o: ../FL/Enumerations.H ../FL/Fl_Export.H ../FL/Fl_Window.H +Fl_JPEG_Image.o: ../config.h Fl_Light_Button.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H Fl_Light_Button.o: ../FL/Fl_Light_Button.H ../FL/Fl_Button.H Fl_Light_Button.o: ../FL/Fl_Widget.H ../FL/fl_draw.H @@ -150,6 +156,9 @@ Fl_Pixmap.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H Fl_Pixmap.o: ../FL/fl_draw.H ../FL/x.H ../FL/Fl_Window.H ../FL/Fl_Widget.H Fl_Pixmap.o: ../FL/Fl_Menu_Item.H ../FL/Fl_Widget.H ../FL/Fl_Pixmap.H Fl_Pixmap.o: ../FL/Fl_Image.H ../FL/x.H +Fl_PNG_Image.o: ../FL/Fl_PNG_Image.H ../FL/Fl_Image.H ../FL/x.H +Fl_PNG_Image.o: ../FL/Enumerations.H ../FL/Fl_Export.H ../FL/Fl_Window.H +Fl_PNG_Image.o: ../config.h Fl_Positioner.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H Fl_Positioner.o: ../FL/Fl_Positioner.H ../FL/Fl_Widget.H ../FL/fl_draw.H Fl_Progress.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H diff --git a/test/Makefile b/test/Makefile index af484dc04..4d622fb35 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,5 +1,5 @@ # -# "$Id: Makefile,v 1.19.2.7.2.8 2001/11/18 12:48:38 easysw Exp $" +# "$Id: Makefile,v 1.19.2.7.2.9 2001/11/19 01:06:45 easysw Exp $" # # Test/example program makefile for the Fast Light Tool Kit (FLTK). # @@ -111,7 +111,7 @@ gldemos: $(GLALL) echo Generating $<... ../fluid/fluid -c $< -$(EXEEXT).fl: +.fl$(EXEEXT): echo Generating, compiling, and linking $@... ../fluid/fluid -c $< $(CXX) -I.. $(CXXFLAGS) $@.cxx $(LINKFLTK) $(LDLIBS) -o $@ @@ -186,5 +186,5 @@ install: @echo Nothing to install in test directory. # -# End of "$Id: Makefile,v 1.19.2.7.2.8 2001/11/18 12:48:38 easysw Exp $". +# End of "$Id: Makefile,v 1.19.2.7.2.9 2001/11/19 01:06:45 easysw Exp $". # diff --git a/test/bitmap.cxx b/test/bitmap.cxx index a033a84c6..e2bdecf31 100644 --- a/test/bitmap.cxx +++ b/test/bitmap.cxx @@ -1,5 +1,5 @@ // -// "$Id: bitmap.cxx,v 1.4.2.3.2.1 2001/08/05 23:58:54 easysw Exp $" +// "$Id: bitmap.cxx,v 1.4.2.3.2.2 2001/11/19 01:06:45 easysw Exp $" // // Bitmap label test program for the Fast Light Tool Kit (FLTK). // @@ -98,7 +98,7 @@ static uchar sorceress_bits[] = { #include -Fl_Toggle_Button *leftb,*rightb,*topb,*bottomb,*insideb,*overb; +Fl_Toggle_Button *leftb,*rightb,*topb,*bottomb,*insideb,*overb,*inactb; Fl_Button *b; Fl_Window *w; @@ -111,6 +111,8 @@ void button_cb(Fl_Widget *,void *) { if (insideb->value()) i |= FL_ALIGN_INSIDE; if (overb->value()) i |= FL_ALIGN_TEXT_OVER_IMAGE; b->align(i); + if (inactb->value()) b->deactivate(); + else b->activate(); w->redraw(); } @@ -118,18 +120,20 @@ int main(int argc, char **argv) { Fl_Window window(400,400); ::w = &window; Fl_Button b(140,160,120,120,"Bitmap"); ::b = &b; (new Fl_Bitmap(sorceress_bits,sorceress_width,sorceress_height))->label(&b); - leftb = new Fl_Toggle_Button(25,75,50,25,"left"); + leftb = new Fl_Toggle_Button(25,50,50,25,"left"); leftb->callback(button_cb); - rightb = new Fl_Toggle_Button(75,75,50,25,"right"); + rightb = new Fl_Toggle_Button(75,50,50,25,"right"); rightb->callback(button_cb); - topb = new Fl_Toggle_Button(125,75,50,25,"top"); + topb = new Fl_Toggle_Button(125,50,50,25,"top"); topb->callback(button_cb); - bottomb = new Fl_Toggle_Button(175,75,50,25,"bottom"); + bottomb = new Fl_Toggle_Button(175,50,50,25,"bottom"); bottomb->callback(button_cb); - insideb = new Fl_Toggle_Button(225,75,50,25,"inside"); + insideb = new Fl_Toggle_Button(225,50,50,25,"inside"); insideb->callback(button_cb); - overb = new Fl_Toggle_Button(275,75,100,25,"text over"); + overb = new Fl_Toggle_Button(25,75,100,25,"text over"); overb->callback(button_cb); + inactb = new Fl_Toggle_Button(125,75,100,25,"inactive"); + inactb->callback(button_cb); window.resizable(window); window.end(); window.show(argc, argv); @@ -137,5 +141,5 @@ int main(int argc, char **argv) { } // -// End of "$Id: bitmap.cxx,v 1.4.2.3.2.1 2001/08/05 23:58:54 easysw Exp $". +// End of "$Id: bitmap.cxx,v 1.4.2.3.2.2 2001/11/19 01:06:45 easysw Exp $". // diff --git a/test/image.cxx b/test/image.cxx index 565353cdb..fe70b73cd 100644 --- a/test/image.cxx +++ b/test/image.cxx @@ -1,5 +1,5 @@ // -// "$Id: image.cxx,v 1.6.2.3.2.2 2001/11/18 20:52:28 easysw Exp $" +// "$Id: image.cxx,v 1.6.2.3.2.3 2001/11/19 01:06:45 easysw Exp $" // // Fl_Image test program for the Fast Light Tool Kit (FLTK). // @@ -61,7 +61,7 @@ void make_image() { #include -Fl_Toggle_Button *leftb,*rightb,*topb,*bottomb,*insideb,*overb; +Fl_Toggle_Button *leftb,*rightb,*topb,*bottomb,*insideb,*overb,*inactb; Fl_Button *b; Fl_Window *w; @@ -74,6 +74,8 @@ void button_cb(Fl_Widget *,void *) { if (insideb->value()) i |= FL_ALIGN_INSIDE; if (overb->value()) i |= FL_ALIGN_TEXT_OVER_IMAGE; b->align(i); + if (inactb->value()) b->deactivate(); + else b->activate(); w->redraw(); } @@ -124,19 +126,28 @@ int main(int argc, char **argv) { window.color(FL_WHITE); Fl_Button b(140,160,120,120,"Image w/Alpha"); ::b = &b; make_image(); - b.image(new Fl_RGB_Image(image, width, height,4)); - leftb = new Fl_Toggle_Button(25,75,50,25,"left"); + Fl_RGB_Image *rgb = new Fl_RGB_Image(image, width, height,4); + Fl_RGB_Image *dergb; + dergb = (Fl_RGB_Image *)rgb->copy(); + dergb->inactive(); + + b.image(rgb); + b.deimage(dergb); + + leftb = new Fl_Toggle_Button(25,50,50,25,"left"); leftb->callback(button_cb); - rightb = new Fl_Toggle_Button(75,75,50,25,"right"); + rightb = new Fl_Toggle_Button(75,50,50,25,"right"); rightb->callback(button_cb); - topb = new Fl_Toggle_Button(125,75,50,25,"top"); + topb = new Fl_Toggle_Button(125,50,50,25,"top"); topb->callback(button_cb); - bottomb = new Fl_Toggle_Button(175,75,50,25,"bottom"); + bottomb = new Fl_Toggle_Button(175,50,50,25,"bottom"); bottomb->callback(button_cb); - insideb = new Fl_Toggle_Button(225,75,50,25,"inside"); + insideb = new Fl_Toggle_Button(225,50,50,25,"inside"); insideb->callback(button_cb); - overb = new Fl_Toggle_Button(275,75,100,25,"text over"); + overb = new Fl_Toggle_Button(25,75,100,25,"text over"); overb->callback(button_cb); + inactb = new Fl_Toggle_Button(125,75,100,25,"inactive"); + inactb->callback(button_cb); window.resizable(window); window.end(); window.show(argc, argv); @@ -144,5 +155,5 @@ int main(int argc, char **argv) { } // -// End of "$Id: image.cxx,v 1.6.2.3.2.2 2001/11/18 20:52:28 easysw Exp $". +// End of "$Id: image.cxx,v 1.6.2.3.2.3 2001/11/19 01:06:45 easysw Exp $". // diff --git a/test/pixmap.cxx b/test/pixmap.cxx index a6143cc73..52698bd48 100644 --- a/test/pixmap.cxx +++ b/test/pixmap.cxx @@ -1,5 +1,5 @@ // -// "$Id: pixmap.cxx,v 1.4.2.3.2.1 2001/08/05 23:58:54 easysw Exp $" +// "$Id: pixmap.cxx,v 1.4.2.3.2.2 2001/11/19 01:06:45 easysw Exp $" // // Pixmap label test program for the Fast Light Tool Kit (FLTK). // @@ -33,7 +33,7 @@ #include -Fl_Toggle_Button *leftb,*rightb,*topb,*bottomb,*insideb,*overb; +Fl_Toggle_Button *leftb,*rightb,*topb,*bottomb,*insideb,*overb,*inactb; Fl_Button *b; Fl_Window *w; @@ -46,6 +46,8 @@ void button_cb(Fl_Widget *,void *) { if (insideb->value()) i |= FL_ALIGN_INSIDE; if (overb->value()) i |= FL_ALIGN_TEXT_OVER_IMAGE; b->align(i); + if (inactb->value()) b->deactivate(); + else b->activate(); w->redraw(); } @@ -64,19 +66,28 @@ int main(int argc, char **argv) { Fl_Window window(400,400); ::w = &window; Fl_Button b(140,160,120,120,"Pixmap"); ::b = &b; - (new Fl_Pixmap(porsche_xpm))->label(&b); - leftb = new Fl_Toggle_Button(25,75,50,25,"left"); + Fl_Pixmap *pixmap = new Fl_Pixmap(porsche_xpm); + Fl_Pixmap *depixmap; + depixmap = (Fl_Pixmap *)pixmap->copy(); + depixmap->inactive(); + + b.image(pixmap); + b.deimage(depixmap); + + leftb = new Fl_Toggle_Button(25,50,50,25,"left"); leftb->callback(button_cb); - rightb = new Fl_Toggle_Button(75,75,50,25,"right"); + rightb = new Fl_Toggle_Button(75,50,50,25,"right"); rightb->callback(button_cb); - topb = new Fl_Toggle_Button(125,75,50,25,"top"); + topb = new Fl_Toggle_Button(125,50,50,25,"top"); topb->callback(button_cb); - bottomb = new Fl_Toggle_Button(175,75,50,25,"bottom"); + bottomb = new Fl_Toggle_Button(175,50,50,25,"bottom"); bottomb->callback(button_cb); - insideb = new Fl_Toggle_Button(225,75,50,25,"inside"); + insideb = new Fl_Toggle_Button(225,50,50,25,"inside"); insideb->callback(button_cb); - overb = new Fl_Toggle_Button(275,75,100,25,"text over"); + overb = new Fl_Toggle_Button(25,75,100,25,"text over"); overb->callback(button_cb); + inactb = new Fl_Toggle_Button(125,75,100,25,"inactive"); + inactb->callback(button_cb); if (!dvisual) Fl::visual(FL_RGB); window.resizable(window); window.end(); @@ -85,5 +96,5 @@ int main(int argc, char **argv) { } // -// End of "$Id: pixmap.cxx,v 1.4.2.3.2.1 2001/08/05 23:58:54 easysw Exp $". +// End of "$Id: pixmap.cxx,v 1.4.2.3.2.2 2001/11/19 01:06:45 easysw Exp $". //