1998-10-19 20:46:58 +00:00
|
|
|
//
|
2005-02-05 20:28:31 +00:00
|
|
|
// "$Id$"
|
1998-10-19 20:46:58 +00:00
|
|
|
//
|
|
|
|
|
// Pixmap drawing code for the Fast Light Tool Kit (FLTK).
|
|
|
|
|
//
|
2015-06-15 13:41:07 +00:00
|
|
|
// Copyright 1998-2015 by Bill Spitzak and others.
|
1998-10-19 20:46:58 +00:00
|
|
|
//
|
2011-07-19 04:49:30 +00:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
|
//
|
|
|
|
|
// http://www.fltk.org/COPYING.php
|
1998-10-19 20:46:58 +00:00
|
|
|
//
|
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
|
|
|
|
|
|
|
|
// Draws X pixmap data, keeping it stashed in a server pixmap so it
|
|
|
|
|
// redraws fast.
|
|
|
|
|
|
2001-11-22 15:35:02 +00:00
|
|
|
// See fl_draw_pixmap.cxx for code used to get the actual data into pixmap.
|
1998-10-06 18:21:25 +00:00
|
|
|
// Implemented without using the xpm library (which I can't use because
|
|
|
|
|
// it interferes with the color cube used by fl_draw_image).
|
|
|
|
|
|
2015-06-21 12:08:15 +00:00
|
|
|
#include <config.h>
|
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_Pixmap.H>
|
2010-05-27 17:20:18 +00:00
|
|
|
#include <FL/Fl_Printer.H>
|
1998-10-06 18:21:25 +00:00
|
|
|
|
2015-06-21 12:08:15 +00:00
|
|
|
#if defined(USE_X11)
|
2015-12-30 12:10:15 +00:00
|
|
|
# if HAVE_X11_XREGION_H
|
|
|
|
|
# include <X11/Xregion.h>
|
|
|
|
|
# else // if the X11/Xregion.h header is not available, we assume this is the layout of an X11 Region:
|
2015-12-12 15:33:56 +00:00
|
|
|
typedef struct {
|
|
|
|
|
short x1, x2, y1, y2;
|
|
|
|
|
} BOX;
|
|
|
|
|
struct _XRegion {
|
|
|
|
|
long size;
|
|
|
|
|
long numRects;
|
|
|
|
|
BOX *rects;
|
|
|
|
|
BOX extents;
|
|
|
|
|
};
|
2015-12-30 12:10:15 +00:00
|
|
|
# endif // HAVE_X11_XREGION_H
|
|
|
|
|
#endif // USE_X11
|
2015-06-21 12:08:15 +00:00
|
|
|
|
1998-12-15 15:42:35 +00:00
|
|
|
#include <stdio.h>
|
2002-04-11 11:52:43 +00:00
|
|
|
#include "flstring.h"
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 01:06:45 +00:00
|
|
|
#include <ctype.h>
|
1998-12-15 15:42:35 +00:00
|
|
|
|
2005-09-12 23:03:34 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
|
extern void fl_release_dc(HWND, HDC); // located in Fl_win32.cxx
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-11-18 20:52:28 +00:00
|
|
|
extern uchar **fl_mask_bitmap; // used by fl_draw_pixmap.cxx to store mask
|
|
|
|
|
void fl_restore_clip(); // in fl_rect.cxx
|
1998-10-06 18:21:25 +00:00
|
|
|
|
2001-08-05 23:58:54 +00:00
|
|
|
void Fl_Pixmap::measure() {
|
|
|
|
|
int W, H;
|
|
|
|
|
|
|
|
|
|
// ignore empty or bad pixmap data:
|
2001-11-22 15:35:02 +00:00
|
|
|
if (w()<0 && data()) {
|
|
|
|
|
fl_measure_pixmap(data(), W, H);
|
2001-08-05 23:58:54 +00:00
|
|
|
w(W); h(H);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1998-10-15 14:06:16 +00:00
|
|
|
void Fl_Pixmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
|
2010-07-01 13:21:32 +00:00
|
|
|
fl_graphics_driver->draw(this, XP, YP, WP, HP, cx, cy);
|
2010-04-14 13:07:34 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-29 13:45:11 +00:00
|
|
|
static int start(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int w, int h, int &cx, int &cy,
|
2010-05-27 17:20:18 +00:00
|
|
|
int &X, int &Y, int &W, int &H)
|
|
|
|
|
{
|
1998-10-15 14:06:16 +00:00
|
|
|
// ignore empty or bad pixmap data:
|
2010-05-27 17:20:18 +00:00
|
|
|
if (!pxm->data()) {
|
|
|
|
|
return 2;
|
2001-11-23 12:06:36 +00:00
|
|
|
}
|
2010-05-27 17:20:18 +00:00
|
|
|
if (WP == -1) {
|
|
|
|
|
WP = w;
|
|
|
|
|
HP = h;
|
1998-12-03 13:28:21 +00:00
|
|
|
}
|
2010-05-27 17:20:18 +00:00
|
|
|
if (!w) {
|
|
|
|
|
return 2;
|
2001-11-23 12:06:36 +00:00
|
|
|
}
|
1998-10-15 14:06:16 +00:00
|
|
|
// account for current clip region (faster on Irix):
|
2010-05-27 17:20:18 +00:00
|
|
|
fl_clip_box(XP,YP,WP,HP,X,Y,W,H);
|
1998-10-15 14:06:16 +00:00
|
|
|
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;}
|
2010-05-27 17:20:18 +00:00
|
|
|
if (cx+W > w) W = w-cx;
|
|
|
|
|
if (W <= 0) return 1;
|
1998-10-06 18:21:25 +00:00
|
|
|
if (cy < 0) {H += cy; Y -= cy; cy = 0;}
|
2010-05-27 17:20:18 +00:00
|
|
|
if (cy+H > h) H = h-cy;
|
|
|
|
|
if (H <= 0) return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-01 14:33:30 +00:00
|
|
|
int Fl_Pixmap::prepare(int XP, int YP, int WP, int HP, int &cx, int &cy,
|
2012-03-18 18:48:29 +00:00
|
|
|
int &X, int &Y, int &W, int &H) {
|
|
|
|
|
if (w() < 0) measure();
|
|
|
|
|
int code = start(this, XP, YP, WP, HP, w(), h(), cx, cy, X, Y, W, H);
|
2010-05-27 17:20:18 +00:00
|
|
|
if (code) {
|
2012-03-18 18:48:29 +00:00
|
|
|
if (code == 2) draw_empty(XP, YP);
|
|
|
|
|
return 1;
|
2010-05-27 17:20:18 +00:00
|
|
|
}
|
2012-03-18 18:48:29 +00:00
|
|
|
if (!id_) {
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
id_ = Fl_Quartz_Graphics_Driver::create_offscreen_with_alpha(w(), h());
|
|
|
|
|
#else
|
|
|
|
|
id_ = fl_create_offscreen(w(), h());
|
|
|
|
|
#endif
|
|
|
|
|
fl_begin_offscreen((Fl_Offscreen)id_);
|
|
|
|
|
#ifndef __APPLE__
|
1998-10-06 18:21:25 +00:00
|
|
|
uchar *bitmap = 0;
|
|
|
|
|
fl_mask_bitmap = &bitmap;
|
2012-03-18 18:48:29 +00:00
|
|
|
#endif
|
|
|
|
|
fl_draw_pixmap(data(), 0, 0, FL_BLACK);
|
|
|
|
|
#ifndef __APPLE__
|
2012-03-28 13:19:33 +00:00
|
|
|
#if defined(WIN32)
|
|
|
|
|
extern UINT win_pixmap_bg_color; // computed by fl_draw_pixmap()
|
|
|
|
|
this->pixmap_bg_color = win_pixmap_bg_color;
|
|
|
|
|
#endif
|
1998-10-06 18:21:25 +00:00
|
|
|
fl_mask_bitmap = 0;
|
1998-12-06 15:12:23 +00:00
|
|
|
if (bitmap) {
|
2012-03-18 18:48:29 +00:00
|
|
|
mask_ = fl_create_bitmask(w(), h(), bitmap);
|
1998-10-06 18:21:25 +00:00
|
|
|
delete[] bitmap;
|
|
|
|
|
}
|
2012-03-18 18:48:29 +00:00
|
|
|
#endif
|
1998-10-06 18:21:25 +00:00
|
|
|
fl_end_offscreen();
|
|
|
|
|
}
|
2012-03-18 18:48:29 +00:00
|
|
|
return 0;
|
2012-03-29 13:45:11 +00:00
|
|
|
}
|
2012-03-18 18:48:29 +00:00
|
|
|
|
2015-06-15 13:41:07 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
#ifdef __APPLE__ // Apple, Mac OS X
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
2012-03-18 18:48:29 +00:00
|
|
|
void Fl_Quartz_Graphics_Driver::draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy) {
|
|
|
|
|
int X, Y, W, H;
|
|
|
|
|
if (pxm->prepare(XP, YP, WP, HP, cx, cy, X, Y, W, H)) return;
|
|
|
|
|
copy_offscreen(X, Y, W, H, (Fl_Offscreen)pxm->id_, cx, cy);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-15 13:41:07 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
#elif defined(WIN32) // Windows GDI
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
2012-03-18 18:48:29 +00:00
|
|
|
void Fl_GDI_Graphics_Driver::draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy) {
|
|
|
|
|
int X, Y, W, H;
|
|
|
|
|
if (pxm->prepare(XP, YP, WP, HP, cx, cy, X, Y, W, H)) return;
|
|
|
|
|
if (pxm->mask_) {
|
2008-10-13 23:10:43 +00:00
|
|
|
HDC new_gc = CreateCompatibleDC(fl_gc);
|
|
|
|
|
int save = SaveDC(new_gc);
|
2010-05-27 17:20:18 +00:00
|
|
|
SelectObject(new_gc, (void*)pxm->mask_);
|
2008-10-13 23:10:43 +00:00
|
|
|
BitBlt(fl_gc, X, Y, W, H, new_gc, cx, cy, SRCAND);
|
2010-05-27 17:20:18 +00:00
|
|
|
SelectObject(new_gc, (void*)pxm->id_);
|
2008-10-13 23:10:43 +00:00
|
|
|
BitBlt(fl_gc, X, Y, W, H, new_gc, cx, cy, SRCPAINT);
|
|
|
|
|
RestoreDC(new_gc,save);
|
|
|
|
|
DeleteDC(new_gc);
|
|
|
|
|
} else {
|
2012-03-18 18:48:29 +00:00
|
|
|
copy_offscreen(X, Y, W, H, (Fl_Offscreen)pxm->id_, cx, cy);
|
2010-04-16 20:19:09 +00:00
|
|
|
}
|
2010-04-18 06:57:37 +00:00
|
|
|
}
|
2010-04-16 20:19:09 +00:00
|
|
|
|
2012-11-06 20:46:14 +00:00
|
|
|
#if FLTK_ABI_VERSION < 10301
|
2012-03-29 13:45:11 +00:00
|
|
|
UINT Fl_Pixmap::pixmap_bg_color = 0;
|
2012-03-28 13:19:33 +00:00
|
|
|
#endif
|
|
|
|
|
|
2012-03-18 18:48:29 +00:00
|
|
|
void Fl_GDI_Printer_Graphics_Driver::draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy) {
|
2010-05-27 17:20:18 +00:00
|
|
|
int X, Y, W, H;
|
2012-03-18 18:48:29 +00:00
|
|
|
if (pxm->prepare(XP, YP, WP, HP, cx, cy, X, Y, W, H)) return;
|
|
|
|
|
typedef BOOL (WINAPI* fl_transp_func) (HDC,int,int,int,int,HDC,int,int,int,int,UINT);
|
|
|
|
|
static HMODULE hMod = NULL;
|
|
|
|
|
static fl_transp_func fl_TransparentBlt = NULL;
|
|
|
|
|
if (!hMod) {
|
|
|
|
|
hMod = LoadLibrary("MSIMG32.DLL");
|
|
|
|
|
if(hMod) fl_TransparentBlt = (fl_transp_func)GetProcAddress(hMod, "TransparentBlt");
|
2010-05-27 17:20:18 +00:00
|
|
|
}
|
2012-03-18 18:48:29 +00:00
|
|
|
if (fl_TransparentBlt) {
|
|
|
|
|
HDC new_gc = CreateCompatibleDC(fl_gc);
|
|
|
|
|
int save = SaveDC(new_gc);
|
|
|
|
|
SelectObject(new_gc, (void*)pxm->id_);
|
|
|
|
|
// print all of offscreen but its parts in background color
|
2015-02-23 08:54:57 +00:00
|
|
|
fl_TransparentBlt(fl_gc, X, Y, W, H, new_gc, cx, cy, W, H, pxm->pixmap_bg_color );
|
2012-03-18 18:48:29 +00:00
|
|
|
RestoreDC(new_gc,save);
|
|
|
|
|
DeleteDC(new_gc);
|
2010-05-27 17:20:18 +00:00
|
|
|
}
|
2012-03-18 18:48:29 +00:00
|
|
|
else {
|
|
|
|
|
copy_offscreen(X, Y, W, H, (Fl_Offscreen)pxm->id_, cx, cy);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-15 13:41:07 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
#else // X11, Xlib
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
2012-03-18 18:48:29 +00:00
|
|
|
void Fl_Xlib_Graphics_Driver::draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy) {
|
|
|
|
|
int X, Y, W, H;
|
|
|
|
|
if (pxm->prepare(XP, YP, WP, HP, cx, cy, X, Y, W, H)) return;
|
2010-05-27 17:20:18 +00:00
|
|
|
if (pxm->mask_) {
|
|
|
|
|
// make X use the bitmap as a mask:
|
|
|
|
|
XSetClipMask(fl_display, fl_gc, pxm->mask_);
|
|
|
|
|
XSetClipOrigin(fl_display, fl_gc, X-cx, Y-cy);
|
2015-06-21 12:08:15 +00:00
|
|
|
if (clip_region()) {
|
|
|
|
|
// At this point, XYWH is the bounding box of the intersection between
|
|
|
|
|
// the current clip region and the (portion of the) pixmap we have to draw.
|
|
|
|
|
// The current clip region is often a rectangle. But, when a window with rounded
|
|
|
|
|
// corners is moved above another window, expose events may create a complex clip
|
|
|
|
|
// region made of several (e.g., 10) rectangles. We have to draw only in the clip
|
|
|
|
|
// region, and also to mask out the transparent pixels of the image. This can't
|
|
|
|
|
// be done in a single Xlib call for a multi-rectangle clip region. Thus, we
|
|
|
|
|
// process each rectangle of the intersection between the clip region and XYWH.
|
|
|
|
|
// See also STR #3206.
|
|
|
|
|
Region r = XRectangleRegion(X,Y,W,H);
|
|
|
|
|
XIntersectRegion(r, clip_region(), r);
|
|
|
|
|
int X1, Y1, W1, H1;
|
|
|
|
|
for (int i = 0; i < r->numRects; i++) {
|
2015-06-22 05:15:42 +00:00
|
|
|
X1 = r->rects[i].x1;
|
|
|
|
|
Y1 = r->rects[i].y1;
|
|
|
|
|
W1 = r->rects[i].x2 - r->rects[i].x1;
|
|
|
|
|
H1 = r->rects[i].y2 - r->rects[i].y1;
|
|
|
|
|
copy_offscreen(X1, Y1, W1, H1, pxm->id_, cx + (X1 - X), cy + (Y1 - Y));
|
2015-06-21 12:08:15 +00:00
|
|
|
}
|
|
|
|
|
XDestroyRegion(r);
|
|
|
|
|
} else {
|
|
|
|
|
copy_offscreen(X, Y, W, H, pxm->id_, cx, cy);
|
|
|
|
|
}
|
2010-05-27 17:20:18 +00:00
|
|
|
// put the old clip region back
|
|
|
|
|
XSetClipOrigin(fl_display, fl_gc, 0, 0);
|
2015-06-21 12:08:15 +00:00
|
|
|
restore_clip();
|
2010-05-27 17:20:18 +00:00
|
|
|
}
|
2015-06-21 12:08:15 +00:00
|
|
|
else copy_offscreen(X, Y, W, H, pxm->id_, cx, cy);
|
2010-05-27 17:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
2015-06-15 13:41:07 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
#endif // (platform-specific)
|
|
|
|
|
//------------------------------------------------------------------------------
|
2010-05-27 17:20:18 +00:00
|
|
|
|
2008-09-14 18:19:41 +00:00
|
|
|
/**
|
2015-06-15 13:41:07 +00:00
|
|
|
The destructor frees all memory and server resources that are used by
|
2008-09-14 18:19:41 +00:00
|
|
|
the pixmap.
|
|
|
|
|
*/
|
1998-10-06 18:21:25 +00:00
|
|
|
Fl_Pixmap::~Fl_Pixmap() {
|
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
|
|
|
delete_data();
|
1998-10-06 18:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2002-08-05 17:50:25 +00:00
|
|
|
void Fl_Pixmap::uncache() {
|
2010-03-15 23:47:47 +00:00
|
|
|
if (id_) {
|
|
|
|
|
fl_delete_offscreen((Fl_Offscreen)id_);
|
|
|
|
|
id_ = 0;
|
2002-08-05 17:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-15 23:47:47 +00:00
|
|
|
if (mask_) {
|
|
|
|
|
fl_delete_bitmask((Fl_Bitmask)mask_);
|
|
|
|
|
mask_ = 0;
|
2002-08-05 17:50:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-09 01:09:49 +00:00
|
|
|
void Fl_Pixmap::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_Pixmap::label(Fl_Menu_Item* m) {
|
2002-04-26 11:32:37 +00:00
|
|
|
Fl::set_labeltype(_FL_IMAGE_LABEL, labeltype, Fl_Image::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
|
|
|
|
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_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
|
2012-03-29 13:45:11 +00:00
|
|
|
chars_per_line; // Characters per line
|
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
|
|
|
|
|
|
|
|
// Figure out how many colors there are, and how big they are...
|
2001-11-22 15:35:02 +00:00
|
|
|
sscanf(data()[0],"%*d%*d%d%d", &ncolors, &chars_per_pixel);
|
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
|
|
|
chars_per_line = chars_per_pixel * w() + 1;
|
|
|
|
|
|
|
|
|
|
// Allocate memory for the new array...
|
2001-11-20 05:13:23 +00:00
|
|
|
if (ncolors < 0) new_data = new char *[h() + 2];
|
|
|
|
|
else new_data = new char *[h() + ncolors + 1];
|
|
|
|
|
|
2001-11-22 15:35:02 +00:00
|
|
|
new_data[0] = new char[strlen(data()[0]) + 1];
|
|
|
|
|
strcpy(new_data[0], data()[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
|
|
|
|
|
|
|
|
// Copy colors...
|
|
|
|
|
if (ncolors < 0) {
|
|
|
|
|
// Copy FLTK colormap values...
|
|
|
|
|
ncolors = -ncolors;
|
2001-11-20 05:13:23 +00:00
|
|
|
new_row = new_data + 1;
|
|
|
|
|
*new_row = new char[ncolors * 4];
|
2001-11-22 15:35:02 +00:00
|
|
|
memcpy(*new_row, data()[1], ncolors * 4);
|
2001-11-20 05:13:23 +00:00
|
|
|
ncolors = 1;
|
|
|
|
|
new_row ++;
|
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 {
|
|
|
|
|
// Copy standard XPM colormap values...
|
|
|
|
|
for (i = 0, new_row = new_data + 1; i < ncolors; i ++, new_row ++) {
|
2001-11-22 15:35:02 +00:00
|
|
|
*new_row = new char[strlen(data()[i + 1]) + 1];
|
|
|
|
|
strcpy(*new_row, data()[i + 1]);
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 01:06:45 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Copy image data...
|
|
|
|
|
for (i = 0; i < h(); i ++, new_row ++) {
|
|
|
|
|
*new_row = new char[chars_per_line];
|
2001-11-22 15:35:02 +00:00
|
|
|
memcpy(*new_row, data()[i + ncolors + 1], chars_per_line);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update pointers...
|
2001-12-21 20:45:43 +00:00
|
|
|
data((const char **)new_data, h() + ncolors + 1);
|
2012-03-29 13:45:11 +00:00
|
|
|
alloc_data = 1;
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 01:06:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Fl_Image *Fl_Pixmap::copy(int W, int H) {
|
2004-09-24 16:00:11 +00:00
|
|
|
Fl_Pixmap *new_image; // New pixmap
|
|
|
|
|
|
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
|
|
|
// Optimize the simple copy where the width and height are the same...
|
2004-09-24 16:00:11 +00:00
|
|
|
if (W == w() && H == h()) {
|
|
|
|
|
// Make an exact copy of the image and return it...
|
|
|
|
|
new_image = new Fl_Pixmap(data());
|
|
|
|
|
new_image->copy_data();
|
|
|
|
|
return new_image;
|
|
|
|
|
}
|
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
|
|
|
|
2012-03-29 13:45:11 +00:00
|
|
|
// OK, need to resize the image data; allocate memory and
|
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
|
|
|
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
|
2012-03-29 13:45:11 +00:00
|
|
|
chars_per_line; // Characters per line
|
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
|
|
|
|
|
|
|
|
// Figure out how many colors there are, and how big they are...
|
2001-11-22 15:35:02 +00:00
|
|
|
sscanf(data()[0],"%*d%*d%d%d", &ncolors, &chars_per_pixel);
|
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
|
|
|
chars_per_line = chars_per_pixel * W + 1;
|
|
|
|
|
|
|
|
|
|
sprintf(new_info, "%d %d %d %d", W, H, ncolors, chars_per_pixel);
|
|
|
|
|
|
2016-08-09 15:19:46 +00:00
|
|
|
// Figure out Bresenham step/modulus values...
|
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
|
|
|
xmod = w() % W;
|
|
|
|
|
xstep = (w() / W) * chars_per_pixel;
|
|
|
|
|
ymod = h() % H;
|
|
|
|
|
ystep = h() / H;
|
|
|
|
|
|
|
|
|
|
// Allocate memory for the new array...
|
2001-11-20 05:13:23 +00:00
|
|
|
if (ncolors < 0) new_data = new char *[H + 2];
|
|
|
|
|
else new_data = new char *[H + ncolors + 1];
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 01:06:45 +00:00
|
|
|
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;
|
2001-11-20 05:13:23 +00:00
|
|
|
new_row = new_data + 1;
|
|
|
|
|
*new_row = new char[ncolors * 4];
|
2001-11-22 15:35:02 +00:00
|
|
|
memcpy(*new_row, data()[1], ncolors * 4);
|
2001-11-20 05:13:23 +00:00
|
|
|
ncolors = 1;
|
|
|
|
|
new_row ++;
|
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 {
|
|
|
|
|
// Copy standard XPM colormap values...
|
|
|
|
|
for (i = 0, new_row = new_data + 1; i < ncolors; i ++, new_row ++) {
|
2001-11-22 15:35:02 +00:00
|
|
|
*new_row = new char[strlen(data()[i + 1]) + 1];
|
|
|
|
|
strcpy(*new_row, data()[i + 1]);
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 01:06:45 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Scale the image using a nearest-neighbor algorithm...
|
2002-12-19 21:34:26 +00:00
|
|
|
for (dy = H, sy = 0, yerr = H; dy > 0; dy --, new_row ++) {
|
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_row = new char[chars_per_line];
|
|
|
|
|
new_ptr = *new_row;
|
|
|
|
|
|
2002-12-19 21:34:26 +00:00
|
|
|
for (dx = W, xerr = W, old_ptr = data()[sy + ncolors + 1];
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 01:06:45 +00:00
|
|
|
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 ++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-29 00:10:05 +00:00
|
|
|
new_image = new Fl_Pixmap((char*const*)new_data);
|
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_data = 1;
|
|
|
|
|
|
|
|
|
|
return new_image;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Fl_Pixmap::color_average(Fl_Color c, float i) {
|
|
|
|
|
// 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...
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2001-11-22 15:35:02 +00:00
|
|
|
sscanf(data()[0],"%*d%*d%d%d", &ncolors, &chars_per_pixel);
|
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
|
|
|
|
|
|
|
|
if (ncolors < 0) {
|
|
|
|
|
// Update FLTK colormap...
|
|
|
|
|
ncolors = -ncolors;
|
2001-11-22 15:35:02 +00:00
|
|
|
uchar *cmap = (uchar *)(data()[1]);
|
2001-11-20 05:13:23 +00:00
|
|
|
for (color = 0; color < ncolors; color ++, cmap += 4) {
|
|
|
|
|
cmap[1] = (ia * cmap[1] + ir) >> 8;
|
|
|
|
|
cmap[2] = (ia * cmap[2] + ig) >> 8;
|
|
|
|
|
cmap[3] = (ia * cmap[3] + ib) >> 8;
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 01:06:45 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Update standard XPM colormap...
|
|
|
|
|
for (color = 0; color < ncolors; color ++) {
|
|
|
|
|
// look for "c word", or last word if none:
|
2001-11-22 15:35:02 +00:00
|
|
|
const char *p = data()[color + 1] + chars_per_pixel + 1;
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 01:06:45 +00:00
|
|
|
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++;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-19 20:59:59 +00:00
|
|
|
if (fl_parse_color(p, r, g, b)) {
|
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
|
|
|
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",
|
2001-11-22 15:35:02 +00:00
|
|
|
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);
|
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
|
|
|
|
2001-11-22 15:35:02 +00:00
|
|
|
delete[] (char *)data()[color + 1];
|
|
|
|
|
((char **)data())[color + 1] = new char[strlen(line) + 1];
|
|
|
|
|
strcpy((char *)data()[color + 1], line);
|
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_Pixmap::delete_data() {
|
|
|
|
|
if (alloc_data) {
|
2001-11-22 15:35:02 +00:00
|
|
|
for (int i = 0; i < count(); i ++) delete[] (char *)data()[i];
|
|
|
|
|
delete[] (char **)data();
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-22 15:35:02 +00:00
|
|
|
void Fl_Pixmap::set_data(const char * const * p) {
|
|
|
|
|
int height, // Number of lines in image
|
|
|
|
|
ncolors; // Number of colors in image
|
|
|
|
|
|
|
|
|
|
if (p) {
|
|
|
|
|
sscanf(p[0],"%*d%d%d", &height, &ncolors);
|
|
|
|
|
if (ncolors < 0) data(p, height + 2);
|
|
|
|
|
else data(p, height + ncolors + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 01:06:45 +00:00
|
|
|
void Fl_Pixmap::desaturate() {
|
|
|
|
|
// 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...
|
|
|
|
|
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;
|
|
|
|
|
|
2001-11-22 15:35:02 +00:00
|
|
|
sscanf(data()[0],"%*d%*d%d%d", &ncolors, &chars_per_pixel);
|
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
|
|
|
|
|
|
|
|
if (ncolors < 0) {
|
|
|
|
|
// Update FLTK colormap...
|
|
|
|
|
ncolors = -ncolors;
|
2001-11-22 15:35:02 +00:00
|
|
|
uchar *cmap = (uchar *)(data()[1]);
|
2001-11-20 05:13:23 +00:00
|
|
|
for (i = 0; i < ncolors; i ++, cmap += 4) {
|
2002-11-19 16:37:36 +00:00
|
|
|
g = (uchar)((cmap[1] * 31 + cmap[2] * 61 + cmap[3] * 8) / 100);
|
2001-11-20 05:13:23 +00:00
|
|
|
cmap[1] = cmap[2] = cmap[3] = g;
|
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 {
|
|
|
|
|
// Update standard XPM colormap...
|
|
|
|
|
for (i = 0; i < ncolors; i ++) {
|
|
|
|
|
// look for "c word", or last word if none:
|
2001-11-22 15:35:02 +00:00
|
|
|
const char *p = data()[i + 1] + chars_per_pixel + 1;
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 01:06:45 +00:00
|
|
|
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++;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-19 20:59:59 +00:00
|
|
|
if (fl_parse_color(p, r, g, b)) {
|
2002-11-19 16:37:36 +00:00
|
|
|
g = (uchar)((r * 31 + g * 61 + b * 8) / 100);
|
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
|
|
|
|
2001-11-22 15:35:02 +00:00
|
|
|
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);
|
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
|
|
|
|
2001-11-22 15:35:02 +00:00
|
|
|
delete[] (char *)data()[i + 1];
|
|
|
|
|
((char **)data())[i + 1] = new char[strlen(line) + 1];
|
|
|
|
|
strcpy((char *)data()[i + 1], line);
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1998-10-19 20:46:58 +00:00
|
|
|
//
|
2005-02-05 20:28:31 +00:00
|
|
|
// End of "$Id$".
|
1998-10-19 20:46:58 +00:00
|
|
|
//
|