1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// Pixmap drawing code for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2009-01-02 00:28:26 +03:00
|
|
|
// Copyright 1998-2009 by Bill Spitzak and others.
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
// Implemented without using the xpm library (which I can't use because
|
|
|
|
// it interferes with the color cube used by fl_draw_image).
|
|
|
|
// Current implementation is cheap and slow, and works best on a full-color
|
|
|
|
// display. Transparency is not handled, and colors are dithered to
|
|
|
|
// the color cube. Color index is achieved by adding the id
|
|
|
|
// characters together! Also mallocs a lot of temporary memory!
|
|
|
|
// Notice that there is no pixmap file interface. This is on purpose,
|
|
|
|
// as I want to discourage programs that require support files to work.
|
|
|
|
// All data needed by a program ui should be compiled in!!!
|
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
#include <FL/x.H>
|
|
|
|
#include <stdio.h>
|
2002-04-11 15:52:43 +04:00
|
|
|
#include "flstring.h"
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
static int ncolors, chars_per_pixel;
|
|
|
|
|
2009-03-15 22:38:13 +03:00
|
|
|
/**
|
|
|
|
Get the dimensions of a pixmap.
|
|
|
|
An XPM image contains the dimensions in its data. This function
|
|
|
|
returns te width and height.
|
|
|
|
\param[in] data pointer to XPM image data.
|
|
|
|
\param[out] w,h width and height of image
|
|
|
|
\returns non-zero if the dimensions were parsed OK
|
|
|
|
\returns 0 if there were any problems
|
|
|
|
*/
|
2001-04-13 23:07:40 +04:00
|
|
|
int fl_measure_pixmap(/*const*/ char* const* data, int &w, int &h) {
|
|
|
|
return fl_measure_pixmap((const char*const*)data,w,h);
|
|
|
|
}
|
|
|
|
|
2009-03-15 22:38:13 +03:00
|
|
|
/**
|
|
|
|
Get the dimensions of a pixmap.
|
|
|
|
\see fl_measure_pixmap(char* const* data, int &w, int &h)
|
|
|
|
*/
|
|
|
|
int fl_measure_pixmap(const char * const *cdata, int &w, int &h) {
|
|
|
|
int i = sscanf(cdata[0],"%d%d%d%d",&w,&h,&ncolors,&chars_per_pixel);
|
1998-10-06 22:21:25 +04:00
|
|
|
if (i<4 || w<=0 || h<=0 ||
|
|
|
|
chars_per_pixel!=1 && chars_per_pixel!=2) return w=0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef U64
|
|
|
|
|
|
|
|
// The callback from fl_draw_image to get a row of data passes this:
|
|
|
|
struct pixmap_data {
|
|
|
|
int w, h;
|
1999-08-25 09:37:40 +04:00
|
|
|
const uchar*const* data;
|
|
|
|
union {
|
|
|
|
U64 colors[256];
|
|
|
|
U64* byte1[256];
|
|
|
|
};
|
1998-10-06 22:21:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// callback for 1 byte per pixel:
|
|
|
|
static void cb1(void*v, int x, int y, int w, uchar* buf) {
|
|
|
|
pixmap_data& d = *(pixmap_data*)v;
|
1999-08-25 09:37:40 +04:00
|
|
|
const uchar* p = d.data[y]+x;
|
1998-10-06 22:21:25 +04:00
|
|
|
U64* q = (U64*)buf;
|
2004-09-11 23:32:43 +04:00
|
|
|
for (int X=w; X>0; X-=2, p += 2) {
|
|
|
|
if (X>1) {
|
2002-01-01 16:11:29 +03:00
|
|
|
# if WORDS_BIGENDIAN
|
2004-09-11 23:32:43 +04:00
|
|
|
*q++ = (d.colors[p[0]]<<32) | d.colors[p[1]];
|
2002-01-01 16:11:29 +03:00
|
|
|
# else
|
2004-09-11 23:32:43 +04:00
|
|
|
*q++ = (d.colors[p[1]]<<32) | d.colors[p[0]];
|
2002-01-01 16:11:29 +03:00
|
|
|
# endif
|
2004-09-11 23:32:43 +04:00
|
|
|
} else {
|
|
|
|
# if WORDS_BIGENDIAN
|
|
|
|
*q++ = d.colors[p[0]]<<32;
|
|
|
|
# else
|
|
|
|
*q++ = d.colors[p[0]];
|
|
|
|
# endif
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// callback for 2 bytes per pixel:
|
|
|
|
static void cb2(void*v, int x, int y, int w, uchar* buf) {
|
|
|
|
pixmap_data& d = *(pixmap_data*)v;
|
1999-08-25 09:37:40 +04:00
|
|
|
const uchar* p = d.data[y]+2*x;
|
1998-10-06 22:21:25 +04:00
|
|
|
U64* q = (U64*)buf;
|
2004-09-11 23:32:43 +04:00
|
|
|
for (int X=w; X>0; X-=2) {
|
1999-08-25 09:37:40 +04:00
|
|
|
U64* colors = d.byte1[*p++];
|
|
|
|
int index = *p++;
|
2004-09-11 23:32:43 +04:00
|
|
|
if (X>1) {
|
|
|
|
U64* colors1 = d.byte1[*p++];
|
|
|
|
int index1 = *p++;
|
|
|
|
# if WORDS_BIGENDIAN
|
|
|
|
*q++ = (colors[index]<<32) | colors1[index1];
|
|
|
|
# else
|
|
|
|
*q++ = (colors1[index1]<<32) | colors[index];
|
|
|
|
# endif
|
|
|
|
} else {
|
2002-01-01 16:11:29 +03:00
|
|
|
# if WORDS_BIGENDIAN
|
2004-09-11 23:32:43 +04:00
|
|
|
*q++ = colors[index]<<32;
|
2002-01-01 16:11:29 +03:00
|
|
|
# else
|
2004-09-11 23:32:43 +04:00
|
|
|
*q++ = colors[index];
|
2002-01-01 16:11:29 +03:00
|
|
|
# endif
|
2004-09-11 23:32:43 +04:00
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-11 23:32:43 +04:00
|
|
|
#else // U32
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
// The callback from fl_draw_image to get a row of data passes this:
|
|
|
|
struct pixmap_data {
|
|
|
|
int w, h;
|
1999-08-25 09:37:40 +04:00
|
|
|
const uchar*const* data;
|
|
|
|
union {
|
|
|
|
U32 colors[256];
|
|
|
|
U32* byte1[256];
|
|
|
|
};
|
1998-10-06 22:21:25 +04:00
|
|
|
};
|
|
|
|
|
2004-09-11 23:32:43 +04:00
|
|
|
# ifndef __APPLE_QUARTZ__
|
2004-09-01 02:00:49 +04:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
// callback for 1 byte per pixel:
|
|
|
|
static void cb1(void*v, int x, int y, int w, uchar* buf) {
|
|
|
|
pixmap_data& d = *(pixmap_data*)v;
|
1999-08-25 09:37:40 +04:00
|
|
|
const uchar* p = d.data[y]+x;
|
1998-10-06 22:21:25 +04:00
|
|
|
U32* q = (U32*)buf;
|
1999-08-25 09:37:40 +04:00
|
|
|
for (int X=w; X--;) *q++ = d.colors[*p++];
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// callback for 2 bytes per pixel:
|
|
|
|
static void cb2(void*v, int x, int y, int w, uchar* buf) {
|
|
|
|
pixmap_data& d = *(pixmap_data*)v;
|
1999-08-25 09:37:40 +04:00
|
|
|
const uchar* p = d.data[y]+2*x;
|
1998-10-06 22:21:25 +04:00
|
|
|
U32* q = (U32*)buf;
|
|
|
|
for (int X=w; X--;) {
|
1999-08-25 09:37:40 +04:00
|
|
|
U32* colors = d.byte1[*p++];
|
|
|
|
*q++ = colors[*p++];
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-11 23:32:43 +04:00
|
|
|
# endif // !__APPLE_QUARTZ__
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2004-09-11 23:32:43 +04:00
|
|
|
#endif // U64 else U32
|
2004-09-01 02:00:49 +04:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
uchar **fl_mask_bitmap; // if non-zero, create bitmap and store pointer here
|
|
|
|
|
2009-03-15 22:38:13 +03:00
|
|
|
/**
|
|
|
|
Draw XPM image data, with the top-left corner at the given position.
|
|
|
|
The image is dithered on 8-bit displays so you won't lose color
|
|
|
|
space for programs displaying both images and pixmaps.
|
|
|
|
\param[in] data pointer to XPM image data
|
|
|
|
\param[in] x,y position of top-left corner
|
|
|
|
\param[in] bg background color
|
|
|
|
\returns 0 if there was any error decoding the XPM data.
|
|
|
|
*/
|
2001-04-13 23:07:40 +04:00
|
|
|
int fl_draw_pixmap(/*const*/ char* const* data, int x,int y,Fl_Color bg) {
|
|
|
|
return fl_draw_pixmap((const char*const*)data,x,y,bg);
|
|
|
|
}
|
|
|
|
|
2010-04-15 00:12:06 +04:00
|
|
|
#ifdef WIN32
|
|
|
|
// to compute an unused color to be used for the pixmap background
|
|
|
|
FL_EXPORT UINT win_pixmap_bg_color; // the RGB() of the pixmap background color
|
|
|
|
static int color_count; // # of non-transparent colors used in pixmap
|
|
|
|
static uchar *used_colors; // used_colors[3*i+j] j=0,1,2 are the RGB values of the ith used color
|
|
|
|
|
|
|
|
static void make_unused_color(uchar &r, uchar &g, uchar &b)
|
|
|
|
// makes an RGB triplet different from all the colors used in the pixmap
|
|
|
|
// and compute win_pixmap_bg_color from this triplet
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
r = 2; g = 3; b = 4;
|
|
|
|
while (1) {
|
|
|
|
for ( i = 0; i < color_count; i++) {
|
|
|
|
if(used_colors[3*i] == r && used_colors[3*i+1] == g && used_colors[3*i+2] == b) break;
|
|
|
|
}
|
|
|
|
if (i >= color_count) {
|
|
|
|
free(used_colors);
|
|
|
|
win_pixmap_bg_color = RGB(r, g, b);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (r < 255) r++;
|
|
|
|
else {
|
|
|
|
r = 0;
|
|
|
|
if (g < 255) g++;
|
|
|
|
else {
|
|
|
|
g = 0;
|
|
|
|
b++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-03-15 22:38:13 +03:00
|
|
|
/**
|
|
|
|
Draw XPM image data, with the top-left corner at the given position.
|
|
|
|
\see fl_draw_pixmap(char* const* data, int x, int y, Fl_Color bg)
|
|
|
|
*/
|
|
|
|
int fl_draw_pixmap(const char*const* cdata, int x, int y, Fl_Color bg) {
|
1998-10-06 22:21:25 +04:00
|
|
|
pixmap_data d;
|
2009-03-15 22:38:13 +03:00
|
|
|
if (!fl_measure_pixmap(cdata, d.w, d.h)) return 0;
|
|
|
|
const uchar*const* data = (const uchar*const*)(cdata+1);
|
1998-10-06 22:21:25 +04:00
|
|
|
int transparent_index = -1;
|
2010-05-13 11:47:30 +04:00
|
|
|
uchar *transparent_c = (uchar *)0; // such that transparent_c[0,1,2] are the RGB of the transparent color
|
2010-04-15 00:12:06 +04:00
|
|
|
#ifdef WIN32
|
|
|
|
color_count = 0;
|
|
|
|
used_colors = (uchar *)malloc(abs(ncolors)*3*sizeof(uchar));
|
|
|
|
#endif
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2001-11-18 23:52:28 +03:00
|
|
|
if (ncolors < 0) { // FLTK (non standard) compressed colormap
|
1998-10-06 22:21:25 +04:00
|
|
|
ncolors = -ncolors;
|
1999-08-25 09:37:40 +04:00
|
|
|
const uchar *p = *data++;
|
1998-10-06 22:21:25 +04:00
|
|
|
// if first color is ' ' it is transparent (put it later to make
|
|
|
|
// it not be transparent):
|
|
|
|
if (*p == ' ') {
|
2004-08-31 05:29:55 +04:00
|
|
|
uchar* c = (uchar*)&d.colors[(int)' '];
|
1998-10-06 22:21:25 +04:00
|
|
|
#ifdef U64
|
|
|
|
*(U64*)c = 0;
|
2002-01-01 16:11:29 +03:00
|
|
|
# if WORDS_BIGENDIAN
|
1998-10-06 22:21:25 +04:00
|
|
|
c += 4;
|
2002-01-01 16:11:29 +03:00
|
|
|
# endif
|
1998-10-06 22:21:25 +04:00
|
|
|
#endif
|
|
|
|
transparent_index = ' ';
|
|
|
|
Fl::get_color(bg, c[0], c[1], c[2]); c[3] = 0;
|
2010-04-15 00:12:06 +04:00
|
|
|
transparent_c = c;
|
1998-10-06 22:21:25 +04:00
|
|
|
p += 4;
|
|
|
|
ncolors--;
|
|
|
|
}
|
|
|
|
// read all the rest of the colors:
|
|
|
|
for (int i=0; i < ncolors; i++) {
|
1999-08-25 09:37:40 +04:00
|
|
|
uchar* c = (uchar*)&d.colors[*p++];
|
1998-10-06 22:21:25 +04:00
|
|
|
#ifdef U64
|
|
|
|
*(U64*)c = 0;
|
2002-01-01 16:11:29 +03:00
|
|
|
# if WORDS_BIGENDIAN
|
1998-10-06 22:21:25 +04:00
|
|
|
c += 4;
|
2002-01-01 16:11:29 +03:00
|
|
|
# endif
|
2010-04-15 00:12:06 +04:00
|
|
|
#endif
|
|
|
|
#ifdef WIN32
|
|
|
|
used_colors[3*color_count] = *p;
|
|
|
|
used_colors[3*color_count+1] = *(p+1);
|
|
|
|
used_colors[3*color_count+2] = *(p+2);
|
|
|
|
color_count++;
|
1998-10-06 22:21:25 +04:00
|
|
|
#endif
|
|
|
|
*c++ = *p++;
|
|
|
|
*c++ = *p++;
|
|
|
|
*c++ = *p++;
|
2004-09-01 02:00:49 +04:00
|
|
|
#ifdef __APPLE_QUARTZ__
|
|
|
|
*c = 255;
|
|
|
|
#else
|
1998-10-06 22:21:25 +04:00
|
|
|
*c = 0;
|
2004-09-01 02:00:49 +04:00
|
|
|
#endif
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
} else { // normal XPM colormap with names
|
1999-08-25 09:37:40 +04:00
|
|
|
if (chars_per_pixel>1) memset(d.byte1, 0, sizeof(d.byte1));
|
1998-10-06 22:21:25 +04:00
|
|
|
for (int i=0; i<ncolors; i++) {
|
1999-08-25 09:37:40 +04:00
|
|
|
const uchar *p = *data++;
|
1998-10-06 22:21:25 +04:00
|
|
|
// the first 1 or 2 characters are the color index:
|
2002-08-09 07:17:30 +04:00
|
|
|
int ind = *p++;
|
1999-08-25 09:37:40 +04:00
|
|
|
uchar* c;
|
|
|
|
if (chars_per_pixel>1) {
|
|
|
|
#ifdef U64
|
2002-08-09 07:17:30 +04:00
|
|
|
U64* colors = d.byte1[ind];
|
|
|
|
if (!colors) colors = d.byte1[ind] = new U64[256];
|
1999-08-25 09:37:40 +04:00
|
|
|
#else
|
2002-08-09 07:17:30 +04:00
|
|
|
U32* colors = d.byte1[ind];
|
|
|
|
if (!colors) colors = d.byte1[ind] = new U32[256];
|
1999-08-25 09:37:40 +04:00
|
|
|
#endif
|
|
|
|
c = (uchar*)&colors[*p];
|
2004-09-11 23:32:43 +04:00
|
|
|
ind = (ind<<8)|*p++;
|
1999-08-25 09:37:40 +04:00
|
|
|
} else {
|
2002-08-09 07:17:30 +04:00
|
|
|
c = (uchar *)&d.colors[ind];
|
1999-08-25 09:37:40 +04:00
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
// look for "c word", or last word if none:
|
1999-08-25 09:37:40 +04:00
|
|
|
const uchar *previous_word = p;
|
1998-10-06 22:21:25 +04:00
|
|
|
for (;;) {
|
OK, lots of changes to the Fl_Image, Fl_Bitmap, Fl_Pixmap, and Fl_RGB_Image
classes: new copy(), copy(w,h), desaturate(), color_average(), and
inactive() methods, alloc_xyz member for copied data, etc.
Updated test programs to use inactive() and copy() methods to create
inactive images for the test buttons, plus the inactive button to toggle
it...
Added start of separate image classes, a la 2.0, for various image formats.
FLUID will also be updated for it...
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1703 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
2001-11-19 04:06:45 +03:00
|
|
|
while (*p && isspace(*p)) p++;
|
|
|
|
uchar what = *p++;
|
1998-10-06 22:21:25 +04:00
|
|
|
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 U64
|
|
|
|
*(U64*)c = 0;
|
2002-01-01 16:11:29 +03:00
|
|
|
# if WORDS_BIGENDIAN
|
1998-10-06 22:21:25 +04:00
|
|
|
c += 4;
|
2002-01-01 16:11:29 +03:00
|
|
|
# endif
|
2004-09-01 02:00:49 +04:00
|
|
|
#endif
|
|
|
|
#ifdef __APPLE_QUARTZ__
|
|
|
|
c[3] = 255;
|
1998-10-06 22:21:25 +04:00
|
|
|
#endif
|
2010-04-15 00:12:06 +04:00
|
|
|
int parse = fl_parse_color((const char*)p, c[0], c[1], c[2]);
|
|
|
|
if (parse) {
|
|
|
|
#ifdef WIN32
|
|
|
|
used_colors[3*color_count] = c[0];
|
|
|
|
used_colors[3*color_count+1] = c[1];
|
|
|
|
used_colors[3*color_count+2] = c[2];
|
|
|
|
color_count++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
2002-01-01 16:11:29 +03:00
|
|
|
// assume "None" or "#transparent" for any errors
|
|
|
|
// "bg" should be transparent...
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl::get_color(bg, c[0], c[1], c[2]);
|
2004-09-01 02:00:49 +04:00
|
|
|
#ifdef __APPLE_QUARTZ__
|
|
|
|
c[3] = 0;
|
|
|
|
#endif
|
2002-08-09 07:17:30 +04:00
|
|
|
transparent_index = ind;
|
2010-04-15 00:12:06 +04:00
|
|
|
transparent_c = c;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
d.data = data;
|
2010-04-15 00:12:06 +04:00
|
|
|
#ifdef WIN32
|
2010-05-13 14:18:47 +04:00
|
|
|
if (transparent_c) {
|
|
|
|
make_unused_color(transparent_c[0], transparent_c[1], transparent_c[2]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uchar r, g, b;
|
|
|
|
make_unused_color(r, g, b);
|
2010-05-13 11:47:30 +04:00
|
|
|
}
|
2010-04-15 00:12:06 +04:00
|
|
|
#endif
|
2004-09-01 02:00:49 +04:00
|
|
|
#ifndef __APPLE_QUARTZ__
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
// build the mask bitmap used by Fl_Pixmap:
|
|
|
|
if (fl_mask_bitmap && transparent_index >= 0) {
|
|
|
|
int W = (d.w+7)/8;
|
1999-08-25 09:37:40 +04:00
|
|
|
uchar* bitmap = new uchar[W * d.h];
|
1998-10-06 22:21:25 +04:00
|
|
|
*fl_mask_bitmap = bitmap;
|
2002-08-09 07:17:30 +04:00
|
|
|
for (int Y = 0; Y < d.h; Y++) {
|
|
|
|
const uchar* p = data[Y];
|
1998-10-06 22:21:25 +04:00
|
|
|
if (chars_per_pixel <= 1) {
|
2005-12-30 13:13:17 +03:00
|
|
|
int dw = d.w;
|
2002-08-09 07:17:30 +04:00
|
|
|
for (int X = 0; X < W; X++) {
|
2005-12-30 13:13:17 +03:00
|
|
|
uchar b = (dw-->0 && *p++ != transparent_index);
|
|
|
|
if (dw-->0 && *p++ != transparent_index) b |= 2;
|
|
|
|
if (dw-->0 && *p++ != transparent_index) b |= 4;
|
|
|
|
if (dw-->0 && *p++ != transparent_index) b |= 8;
|
|
|
|
if (dw-->0 && *p++ != transparent_index) b |= 16;
|
|
|
|
if (dw-->0 && *p++ != transparent_index) b |= 32;
|
|
|
|
if (dw-->0 && *p++ != transparent_index) b |= 64;
|
|
|
|
if (dw-->0 && *p++ != transparent_index) b |= 128;
|
1998-10-06 22:21:25 +04:00
|
|
|
*bitmap++ = b;
|
|
|
|
}
|
|
|
|
} else {
|
2004-09-11 23:32:43 +04:00
|
|
|
uchar b = 0, bit = 1;
|
|
|
|
for (int X = 0; X < d.w; X++) {
|
|
|
|
int ind = *p++;
|
|
|
|
ind = (ind<<8) | (*p++);
|
|
|
|
if (ind != transparent_index) b |= bit;
|
|
|
|
|
|
|
|
if (bit < 128) bit <<= 1;
|
|
|
|
else {
|
|
|
|
*bitmap++ = b;
|
|
|
|
b = 0;
|
|
|
|
bit = 1;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
}
|
2004-09-11 23:32:43 +04:00
|
|
|
|
|
|
|
if (bit > 1) *bitmap++ = b;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fl_draw_image(chars_per_pixel==1 ? cb1 : cb2, &d, x, y, d.w, d.h, 4);
|
2004-09-01 02:00:49 +04:00
|
|
|
|
|
|
|
#else // __APPLE_QUARTZ__
|
|
|
|
|
|
|
|
bool transparent = (transparent_index>=0);
|
|
|
|
transparent = true;
|
|
|
|
U32 *array = new U32[d.w * d.h], *q = array;
|
|
|
|
for (int Y = 0; Y < d.h; Y++) {
|
|
|
|
const uchar* p = data[Y];
|
|
|
|
if (chars_per_pixel <= 1) {
|
|
|
|
for (int X = 0; X < d.w; X++) {
|
|
|
|
*q++ = d.colors[*p++];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int X = 0; X < d.w; X++) {
|
2010-01-24 13:13:03 +03:00
|
|
|
U32* colors = (U32*)d.byte1[*p++];
|
2004-09-01 02:00:49 +04:00
|
|
|
*q++ = colors[*p++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
|
|
|
|
CGDataProviderRef src = CGDataProviderCreateWithData( 0L, array, d.w * d.h * 4, 0L);
|
|
|
|
CGImageRef img = CGImageCreate(d.w, d.h, 8, 4*8, 4*d.w,
|
|
|
|
lut, transparent?kCGImageAlphaLast:kCGImageAlphaNoneSkipLast,
|
|
|
|
src, 0L, false, kCGRenderingIntentDefault);
|
|
|
|
CGColorSpaceRelease(lut);
|
|
|
|
CGDataProviderRelease(src);
|
2006-06-04 14:21:45 +04:00
|
|
|
CGRect rect = { { x, y} , { d.w, d.h } };
|
2008-02-14 21:17:06 +03:00
|
|
|
Fl_X::q_begin_image(rect, 0, 0, d.w, d.h);
|
2004-09-01 02:00:49 +04:00
|
|
|
CGContextDrawImage(fl_gc, rect, img);
|
|
|
|
Fl_X::q_end_image();
|
|
|
|
CGImageRelease(img);
|
|
|
|
delete array;
|
|
|
|
|
2004-09-11 23:32:43 +04:00
|
|
|
#endif // !__APPLE_QUARTZ__
|
2004-09-01 02:00:49 +04:00
|
|
|
|
2001-12-03 21:29:49 +03:00
|
|
|
if (chars_per_pixel > 1) for (int i = 0; i < 256; i++) delete[] d.byte1[i];
|
1998-10-06 22:21:25 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|