1998-10-19 20:46:58 +00:00
|
|
|
//
|
2005-02-24 21:55:12 +00:00
|
|
|
// "$Id$"
|
1998-10-19 20:46:58 +00:00
|
|
|
//
|
|
|
|
|
// Image drawing code for the Fast Light Tool Kit (FLTK).
|
|
|
|
|
//
|
2005-02-24 21:55:12 +00:00
|
|
|
// Copyright 1998-2005 by Bill Spitzak and others.
|
1998-10-19 20:46:58 +00: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 00:13:17 +00:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
|
//
|
|
|
|
|
// http://www.fltk.org/str.php
|
1998-10-19 20:46:58 +00:00
|
|
|
//
|
1998-10-06 18:21:25 +00:00
|
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
|
#include <FL/x.H>
|
|
|
|
|
#include <FL/Fl_Widget.H>
|
|
|
|
|
#include <FL/Fl_Menu_Item.H>
|
|
|
|
|
#include <FL/Fl_Image.H>
|
2002-04-11 11:52:43 +00:00
|
|
|
#include "flstring.h"
|
2001-11-18 20:52:28 +00:00
|
|
|
|
2005-09-12 23:03:34 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
|
void fl_release_dc(HWND, HDC); // from Fl_win32.cxx
|
|
|
|
|
#endif
|
2001-11-24 02:46:19 +00:00
|
|
|
|
2002-04-26 11:32:37 +00:00
|
|
|
void fl_restore_clip(); // from fl_rect.cxx
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Base image class...
|
|
|
|
|
//
|
1998-10-06 18:21:25 +00:00
|
|
|
|
2001-08-05 23:58:54 +00:00
|
|
|
Fl_Image::~Fl_Image() {
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-05 17:50:25 +00:00
|
|
|
void Fl_Image::uncache() {
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-24 14:19:19 +00:00
|
|
|
void Fl_Image::draw(int XP, int YP, int, int, int, int) {
|
2001-11-23 12:06:36 +00:00
|
|
|
draw_empty(XP, YP);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Fl_Image::draw_empty(int X, int Y) {
|
|
|
|
|
if (w() > 0 && h() > 0) {
|
2005-11-02 11:30:41 +00:00
|
|
|
fl_color(FL_FOREGROUND_COLOR);
|
2001-11-23 12:06:36 +00:00
|
|
|
fl_rect(X, Y, w(), h());
|
|
|
|
|
fl_line(X, Y, X + w() - 1, Y + h() - 1);
|
|
|
|
|
fl_line(X, Y + h() - 1, X + w() - 1, Y);
|
|
|
|
|
}
|
2001-08-05 23:58:54 +00: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 01:06:45 +00:00
|
|
|
Fl_Image *Fl_Image::copy(int W, int H) {
|
2001-11-22 15:35:02 +00:00
|
|
|
return new Fl_Image(W, H, 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 01:06:45 +00:00
|
|
|
}
|
|
|
|
|
|
2002-05-24 14:19:19 +00:00
|
|
|
void Fl_Image::color_average(Fl_Color, float) {
|
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 01:06:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Fl_Image::desaturate() {
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-09 01:09:49 +00:00
|
|
|
void Fl_Image::label(Fl_Widget* widget) {
|
|
|
|
|
widget->image(this);
|
2001-08-05 23:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Fl_Image::label(Fl_Menu_Item* m) {
|
2002-04-26 11:32:37 +00:00
|
|
|
Fl::set_labeltype(_FL_IMAGE_LABEL, labeltype, measure);
|
|
|
|
|
m->label(_FL_IMAGE_LABEL, (const char*)this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Fl_Image::labeltype(const Fl_Label *lo, // I - Label
|
|
|
|
|
int lx, // I - X position
|
|
|
|
|
int ly, // I - Y position
|
|
|
|
|
int lw, // I - Width of label
|
|
|
|
|
int lh, // I - Height of label
|
|
|
|
|
Fl_Align la) { // I - Alignment
|
|
|
|
|
Fl_Image *img; // Image pointer
|
|
|
|
|
int cx, cy; // Image position
|
|
|
|
|
|
|
|
|
|
img = (Fl_Image *)(lo->value);
|
|
|
|
|
|
|
|
|
|
if (la & FL_ALIGN_LEFT) cx = 0;
|
|
|
|
|
else if (la & FL_ALIGN_RIGHT) cx = img->w() - lw;
|
|
|
|
|
else cx = (img->w() - lw) / 2;
|
|
|
|
|
|
|
|
|
|
if (la & FL_ALIGN_TOP) cy = 0;
|
|
|
|
|
else if (la & FL_ALIGN_BOTTOM) cy = img->h() - lh;
|
|
|
|
|
else cy = (img->h() - lh) / 2;
|
|
|
|
|
|
|
|
|
|
fl_color((Fl_Color)lo->color);
|
|
|
|
|
|
|
|
|
|
img->draw(lx, ly, lw, lh, cx, cy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Fl_Image::measure(const Fl_Label *lo, // I - Label
|
|
|
|
|
int &lw, // O - Width of image
|
|
|
|
|
int &lh) { // O - Height of image
|
|
|
|
|
Fl_Image *img; // Image pointer
|
|
|
|
|
|
|
|
|
|
img = (Fl_Image *)(lo->value);
|
|
|
|
|
|
|
|
|
|
lw = img->w();
|
|
|
|
|
lh = img->h();
|
2001-08-05 23:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
2002-04-26 11:32:37 +00:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// RGB image class...
|
|
|
|
|
//
|
|
|
|
|
|
2001-08-05 23:58:54 +00:00
|
|
|
Fl_RGB_Image::~Fl_RGB_Image() {
|
2002-08-05 17:50:25 +00:00
|
|
|
uncache();
|
2001-11-19 20:59:59 +00:00
|
|
|
if (alloc_array) delete[] (uchar *)array;
|
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 01:06:45 +00:00
|
|
|
}
|
|
|
|
|
|
2002-08-05 17:50:25 +00:00
|
|
|
void Fl_RGB_Image::uncache() {
|
2004-08-27 21:57:18 +00:00
|
|
|
#ifdef __APPLE_QUARTZ__
|
|
|
|
|
if (id)
|
|
|
|
|
CGImageRelease((CGImageRef)id);
|
2004-08-28 13:45:27 +00:00
|
|
|
#else
|
2002-08-05 17:50:25 +00:00
|
|
|
if (id) {
|
2003-01-10 19:29:09 +00:00
|
|
|
fl_delete_offscreen((Fl_Offscreen)id);
|
2002-08-05 17:50:25 +00:00
|
|
|
id = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mask) {
|
2003-01-10 19:29:09 +00:00
|
|
|
fl_delete_bitmask((Fl_Bitmask)mask);
|
2002-08-05 17:50:25 +00:00
|
|
|
mask = 0;
|
|
|
|
|
}
|
2004-08-27 21:57:18 +00:00
|
|
|
#endif
|
2002-08-05 17:50:25 +00: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 01:06:45 +00:00
|
|
|
Fl_Image *Fl_RGB_Image::copy(int W, int H) {
|
2004-09-24 16:00:11 +00:00
|
|
|
Fl_RGB_Image *new_image; // New RGB image
|
|
|
|
|
uchar *new_array; // New array for image data
|
|
|
|
|
|
2001-12-19 18:15:34 +00:00
|
|
|
// Optimize the simple copy where the width and height are the same,
|
|
|
|
|
// or when we are copying an empty image...
|
|
|
|
|
if ((W == w() && H == h()) ||
|
|
|
|
|
!w() || !h() || !d() || !array) {
|
2004-09-24 16:00:11 +00:00
|
|
|
if (array) {
|
|
|
|
|
// Make a copy of the image data and return a new Fl_RGB_Image...
|
|
|
|
|
new_array = new uchar[w() * h() * d()];
|
|
|
|
|
memcpy(new_array, array, w() * h() * d());
|
|
|
|
|
|
|
|
|
|
new_image = new Fl_RGB_Image(new_array, w(), h(), d(), ld());
|
|
|
|
|
new_image->alloc_array = 1;
|
|
|
|
|
|
|
|
|
|
return new_image;
|
|
|
|
|
} else return new Fl_RGB_Image(array, w(), h(), d(), ld());
|
2001-12-19 18:15:34 +00:00
|
|
|
}
|
2002-10-11 13:54:10 +00:00
|
|
|
if (W <= 0 || H <= 0) return 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 01:06:45 +00:00
|
|
|
|
|
|
|
|
// OK, need to resize the image data; allocate memory and
|
2004-09-24 16:00:11 +00:00
|
|
|
uchar *new_ptr; // Pointer into new array
|
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 01:06:45 +00:00
|
|
|
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;
|
2001-11-22 15:35:02 +00:00
|
|
|
xstep = (w() / 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 01:06:45 +00:00
|
|
|
ymod = h() % H;
|
|
|
|
|
ystep = h() / H;
|
|
|
|
|
|
|
|
|
|
// Allocate memory for the new image...
|
2001-11-22 15:35:02 +00:00
|
|
|
new_array = new uchar [W * H * d()];
|
|
|
|
|
new_image = new Fl_RGB_Image(new_array, W, H, 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 01:06:45 +00:00
|
|
|
new_image->alloc_array = 1;
|
|
|
|
|
|
|
|
|
|
// Scale the image using a nearest-neighbor algorithm...
|
2002-12-19 21:34:26 +00:00
|
|
|
for (dy = H, sy = 0, yerr = H, new_ptr = new_array; dy > 0; dy --) {
|
|
|
|
|
for (dx = W, xerr = W, old_ptr = array + sy * (w() * d() + ld());
|
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 01:06:45 +00:00
|
|
|
dx > 0;
|
|
|
|
|
dx --) {
|
2001-11-22 15:35:02 +00:00
|
|
|
for (c = 0; c < d(); c ++) *new_ptr++ = old_ptr[c];
|
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 01:06:45 +00:00
|
|
|
|
|
|
|
|
old_ptr += xstep;
|
|
|
|
|
xerr -= xmod;
|
|
|
|
|
|
|
|
|
|
if (xerr <= 0) {
|
|
|
|
|
xerr += W;
|
2001-11-22 15:35:02 +00:00
|
|
|
old_ptr += 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 01:06:45 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sy += ystep;
|
|
|
|
|
yerr -= ymod;
|
|
|
|
|
if (yerr <= 0) {
|
|
|
|
|
yerr += H;
|
|
|
|
|
sy ++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new_image;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Fl_RGB_Image::color_average(Fl_Color c, float i) {
|
2001-12-19 18:15:34 +00:00
|
|
|
// Don't average an empty image...
|
|
|
|
|
if (!w() || !h() || !d() || !array) return;
|
|
|
|
|
|
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 01:06:45 +00:00
|
|
|
// Delete any existing pixmap/mask objects...
|
2002-08-05 17:50:25 +00:00
|
|
|
uncache();
|
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 01:06:45 +00:00
|
|
|
|
|
|
|
|
// Allocate memory as needed...
|
|
|
|
|
uchar *new_array,
|
|
|
|
|
*new_ptr;
|
|
|
|
|
|
2001-11-22 15:35:02 +00:00
|
|
|
if (!alloc_array) new_array = new uchar[h() * 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 01:06:45 +00:00
|
|
|
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;
|
|
|
|
|
|
2001-11-22 15:35:02 +00:00
|
|
|
if (d() < 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 01:06:45 +00:00
|
|
|
ig = (r * 31 + g * 61 + b * 8) / 100 * (256 - ia);
|
|
|
|
|
|
2001-11-25 16:38:11 +00:00
|
|
|
for (new_ptr = new_array, old_ptr = array, y = 0; y < h(); y ++, old_ptr += ld())
|
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 01:06:45 +00:00
|
|
|
for (x = 0; x < w(); x ++) {
|
|
|
|
|
*new_ptr++ = (*old_ptr++ * ia + ig) >> 8;
|
2001-11-22 15:35:02 +00:00
|
|
|
if (d() > 1) *new_ptr++ = *old_ptr++;
|
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 01:06:45 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2001-11-25 16:38:11 +00:00
|
|
|
for (new_ptr = new_array, old_ptr = array, y = 0; y < h(); y ++, old_ptr += ld())
|
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 01:06:45 +00:00
|
|
|
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;
|
2001-11-22 15:35:02 +00:00
|
|
|
if (d() > 3) *new_ptr++ = *old_ptr++;
|
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 01:06:45 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set the new pointers/values as needed...
|
|
|
|
|
if (!alloc_array) {
|
|
|
|
|
array = new_array;
|
|
|
|
|
alloc_array = 1;
|
2001-11-25 16:38:11 +00:00
|
|
|
|
|
|
|
|
ld(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 01:06:45 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Fl_RGB_Image::desaturate() {
|
2001-12-19 18:15:34 +00:00
|
|
|
// Don't desaturate an empty image...
|
|
|
|
|
if (!w() || !h() || !d() || !array) return;
|
|
|
|
|
|
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 01:06:45 +00:00
|
|
|
// Can only desaturate color images...
|
2001-11-22 15:35:02 +00:00
|
|
|
if (d() < 3) return;
|
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 01:06:45 +00:00
|
|
|
|
|
|
|
|
// Delete any existing pixmap/mask objects...
|
2002-08-05 17:50:25 +00:00
|
|
|
uncache();
|
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 01:06:45 +00:00
|
|
|
|
|
|
|
|
// Allocate memory for a grayscale image...
|
|
|
|
|
uchar *new_array,
|
|
|
|
|
*new_ptr;
|
|
|
|
|
int new_d;
|
|
|
|
|
|
2001-11-22 15:35:02 +00:00
|
|
|
new_d = d() - 2;
|
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 01:06:45 +00:00
|
|
|
new_array = new uchar[h() * w() * new_d];
|
|
|
|
|
|
|
|
|
|
// Copy the image data, converting to grayscale...
|
|
|
|
|
const uchar *old_ptr;
|
|
|
|
|
int x, y;
|
|
|
|
|
|
2001-11-25 16:38:11 +00:00
|
|
|
for (new_ptr = new_array, old_ptr = array, y = 0; y < h(); y ++, old_ptr += ld())
|
2001-11-22 15:35:02 +00:00
|
|
|
for (x = 0; x < w(); x ++, old_ptr += d()) {
|
2002-11-19 16:37:36 +00:00
|
|
|
*new_ptr++ = (uchar)((31 * old_ptr[0] + 61 * old_ptr[1] + 8 * old_ptr[2]) / 100);
|
2001-11-22 15:35:02 +00:00
|
|
|
if (d() > 3) *new_ptr++ = old_ptr[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 01:06:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Free the old array as needed, and then set the new pointers/values...
|
2001-11-19 20:59:59 +00:00
|
|
|
if (alloc_array) delete[] (uchar *)array;
|
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 01:06:45 +00:00
|
|
|
|
|
|
|
|
array = new_array;
|
|
|
|
|
alloc_array = 1;
|
2001-11-22 15:35:02 +00:00
|
|
|
|
2001-11-25 16:38:11 +00:00
|
|
|
ld(0);
|
2001-11-22 15:35:02 +00:00
|
|
|
d(new_d);
|
2001-08-05 23:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Fl_RGB_Image::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
|
2001-12-19 18:15:34 +00:00
|
|
|
// Don't draw an empty image...
|
|
|
|
|
if (!d() || !array) {
|
2001-11-23 12:06:36 +00:00
|
|
|
draw_empty(XP, YP);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
1998-10-15 14:06:16 +00:00
|
|
|
// account for current clip region (faster on Irix):
|
|
|
|
|
int X,Y,W,H; fl_clip_box(XP,YP,WP,HP,X,Y,W,H);
|
|
|
|
|
cx += X-XP; cy += Y-YP;
|
1998-10-06 18:21:25 +00:00
|
|
|
// clip the box down to the size of image, quit if empty:
|
|
|
|
|
if (cx < 0) {W += cx; X -= cx; cx = 0;}
|
2001-08-05 23:58:54 +00:00
|
|
|
if (cx+W > w()) W = w()-cx;
|
1998-10-06 18:21:25 +00:00
|
|
|
if (W <= 0) return;
|
|
|
|
|
if (cy < 0) {H += cy; Y -= cy; cy = 0;}
|
2001-08-05 23:58:54 +00:00
|
|
|
if (cy+H > h()) H = h()-cy;
|
1998-10-06 18:21:25 +00:00
|
|
|
if (H <= 0) return;
|
|
|
|
|
if (!id) {
|
2004-08-27 21:57:18 +00:00
|
|
|
#ifdef __APPLE_QUARTZ__
|
|
|
|
|
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
|
|
|
|
|
CGDataProviderRef src = CGDataProviderCreateWithData( 0L, array, w()*h()*d(), 0L);
|
|
|
|
|
id = CGImageCreate( w(), h(), 8, d()*8, ld()?ld():w()*d(),
|
|
|
|
|
lut, (d()&1)?kCGImageAlphaNone:kCGImageAlphaLast,
|
|
|
|
|
src, 0L, false, kCGRenderingIntentDefault);
|
|
|
|
|
CGColorSpaceRelease(lut);
|
|
|
|
|
CGDataProviderRelease(src);
|
|
|
|
|
#else
|
2001-11-19 20:59:59 +00:00
|
|
|
id = fl_create_offscreen(w(), h());
|
2003-01-10 19:29:09 +00:00
|
|
|
fl_begin_offscreen((Fl_Offscreen)id);
|
2001-11-25 16:38:11 +00:00
|
|
|
fl_draw_image(array, 0, 0, w(), h(), d(), ld());
|
1998-10-06 18:21:25 +00:00
|
|
|
fl_end_offscreen();
|
2001-11-22 15:35:02 +00:00
|
|
|
if (d() == 2 || d() == 4) {
|
2002-04-15 12:19:01 +00:00
|
|
|
mask = fl_create_alphamask(w(), h(), d(), ld(), array);
|
2001-11-18 20:52:28 +00:00
|
|
|
}
|
2004-08-27 21:57:18 +00:00
|
|
|
#endif
|
2001-11-18 20:52:28 +00:00
|
|
|
}
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
if (mask) {
|
|
|
|
|
HDC new_gc = CreateCompatibleDC(fl_gc);
|
2005-09-12 23:03:34 +00:00
|
|
|
int save = SaveDC(new_gc);
|
2001-11-18 20:52:28 +00:00
|
|
|
SelectObject(new_gc, (void*)mask);
|
|
|
|
|
BitBlt(fl_gc, X, Y, W, H, new_gc, cx, cy, SRCAND);
|
|
|
|
|
SelectObject(new_gc, (void*)id);
|
|
|
|
|
BitBlt(fl_gc, X, Y, W, H, new_gc, cx, cy, SRCPAINT);
|
2005-09-12 23:03:34 +00:00
|
|
|
RestoreDC(new_gc,save);
|
2001-11-18 20:52:28 +00:00
|
|
|
DeleteDC(new_gc);
|
|
|
|
|
} else {
|
2003-01-15 19:41:58 +00:00
|
|
|
fl_copy_offscreen(X, Y, W, H, (Fl_Offscreen)id, cx, cy);
|
2001-11-18 20:52:28 +00:00
|
|
|
}
|
2004-08-25 00:20:27 +00:00
|
|
|
#elif defined(__APPLE_QD__)
|
2002-04-14 21:26:06 +00:00
|
|
|
if (mask) {
|
|
|
|
|
Rect src, dst;
|
2003-07-29 02:12:36 +00:00
|
|
|
// MRS: STR #114 says we should be using cx, cy, W, and H...
|
|
|
|
|
// src.left = 0; src.right = w();
|
|
|
|
|
// src.top = 0; src.bottom = h();
|
|
|
|
|
// dst.left = X; dst.right = X+w();
|
|
|
|
|
// dst.top = Y; dst.bottom = Y+h();
|
|
|
|
|
src.left = cx; src.right = cx+W;
|
2003-08-04 19:20:50 +00:00
|
|
|
src.top = cy; src.bottom = cy+H;
|
2003-07-29 02:12:36 +00:00
|
|
|
dst.left = X; dst.right = X+W;
|
|
|
|
|
dst.top = Y; dst.bottom = Y+H;
|
2002-04-14 21:26:06 +00:00
|
|
|
RGBColor rgb;
|
|
|
|
|
rgb.red = 0xffff; rgb.green = 0xffff; rgb.blue = 0xffff;
|
|
|
|
|
RGBBackColor(&rgb);
|
|
|
|
|
rgb.red = 0x0000; rgb.green = 0x0000; rgb.blue = 0x0000;
|
|
|
|
|
RGBForeColor(&rgb);
|
2002-04-15 17:18:48 +00:00
|
|
|
|
2003-07-29 02:12:36 +00:00
|
|
|
# if 0
|
2002-04-15 17:18:48 +00:00
|
|
|
// MRS: This *should* work, but doesn't on my system (iBook); change to
|
|
|
|
|
// "#if 1" and restore the corresponding code in Fl_Bitmap.cxx
|
|
|
|
|
// to test the real alpha channel support.
|
2002-04-14 21:26:06 +00:00
|
|
|
CopyDeepMask(GetPortBitMapForCopyBits((GrafPtr)id),
|
|
|
|
|
GetPortBitMapForCopyBits((GrafPtr)mask),
|
|
|
|
|
GetPortBitMapForCopyBits(GetWindowPort(fl_window)),
|
|
|
|
|
&src, &src, &dst, blend, NULL);
|
2003-07-29 02:12:36 +00:00
|
|
|
# else // Fallback to screen-door transparency...
|
2002-04-15 17:18:48 +00:00
|
|
|
CopyMask(GetPortBitMapForCopyBits((GrafPtr)id),
|
|
|
|
|
GetPortBitMapForCopyBits((GrafPtr)mask),
|
|
|
|
|
GetPortBitMapForCopyBits(GetWindowPort(fl_window)),
|
|
|
|
|
&src, &src, &dst);
|
2003-07-29 02:12:36 +00:00
|
|
|
# endif // 0
|
2002-04-14 21:26:06 +00:00
|
|
|
} else {
|
2003-01-10 19:29:09 +00:00
|
|
|
fl_copy_offscreen(X, Y, W, H, (Fl_Offscreen)id, cx, cy);
|
2002-04-14 21:26:06 +00:00
|
|
|
}
|
2004-08-25 00:20:27 +00:00
|
|
|
#elif defined(__APPLE_QUARTZ__)
|
2004-08-27 21:57:18 +00:00
|
|
|
if (id && fl_gc) {
|
2004-08-31 00:27:40 +00:00
|
|
|
CGRect rect = { X, Y, W, H };
|
2004-08-31 22:00:49 +00:00
|
|
|
Fl_X::q_begin_image(rect, cx, cy, w(), h());
|
2004-08-27 21:57:18 +00:00
|
|
|
CGContextDrawImage(fl_gc, rect, (CGImageRef)id);
|
2004-08-31 00:27:40 +00:00
|
|
|
Fl_X::q_end_image();
|
2004-08-25 00:20:27 +00:00
|
|
|
}
|
2001-11-18 20:52:28 +00:00
|
|
|
#else
|
|
|
|
|
if (mask) {
|
|
|
|
|
// I can't figure out how to combine a mask with existing region,
|
|
|
|
|
// so cut the image down to a clipped rectangle:
|
|
|
|
|
int nx, ny; fl_clip_box(X,Y,W,H,nx,ny,W,H);
|
|
|
|
|
cx += nx-X; X = nx;
|
|
|
|
|
cy += ny-Y; Y = ny;
|
|
|
|
|
// make X use the bitmap as a mask:
|
|
|
|
|
XSetClipMask(fl_display, fl_gc, mask);
|
|
|
|
|
int ox = X-cx; if (ox < 0) ox += w();
|
|
|
|
|
int oy = Y-cy; if (oy < 0) oy += h();
|
|
|
|
|
XSetClipOrigin(fl_display, fl_gc, X-cx, Y-cy);
|
|
|
|
|
}
|
|
|
|
|
fl_copy_offscreen(X, Y, W, H, id, cx, cy);
|
|
|
|
|
if (mask) {
|
|
|
|
|
// put the old clip region back
|
|
|
|
|
XSetClipOrigin(fl_display, fl_gc, 0, 0);
|
|
|
|
|
fl_restore_clip();
|
1998-10-06 18:21:25 +00:00
|
|
|
}
|
2001-11-18 20:52:28 +00:00
|
|
|
#endif
|
1998-10-06 18:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2002-08-09 01:09:49 +00:00
|
|
|
void Fl_RGB_Image::label(Fl_Widget* widget) {
|
|
|
|
|
widget->image(this);
|
1998-10-06 18:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2001-08-05 23:58:54 +00:00
|
|
|
void Fl_RGB_Image::label(Fl_Menu_Item* m) {
|
2002-04-26 11:32:37 +00:00
|
|
|
Fl::set_labeltype(_FL_IMAGE_LABEL, labeltype, measure);
|
|
|
|
|
m->label(_FL_IMAGE_LABEL, (const char*)this);
|
1998-10-06 18:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
1998-10-19 20:46:58 +00:00
|
|
|
|
|
|
|
|
//
|
2005-02-24 21:55:12 +00:00
|
|
|
// End of "$Id$".
|
1998-10-19 20:46:58 +00:00
|
|
|
//
|