fltk
1.3.5-source
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Fossies Dox: fltk-1.3.5-source.tar.bz2 ("inofficial" and yet experimental doxygen-generated source code documentation) 
|
Go to the documentation of this file. 48 w_(W), h_(
H), d_(D), ld_(0), count_(0), data_(0L)
76 if (
w() > 0 &&
h() > 0) {
172 if ( (
w_<=0) || (
h_<=0) || (
d_<=0) ) {
195 else cx = (img->
w() - lw) / 2;
199 else cy = (img->
h() - lh) / 2;
203 img->
draw(lx, ly, lw, lh, cx, cy);
302 if (pxm && pxm->
w() > 0 && pxm->
h() > 0) {
352 if ((W ==
w() &&
H ==
h()) ||
356 new_array =
new uchar[
w() *
h() *
d()];
357 if (
ld() &&
ld()!=
w()*
d()) {
359 uchar *dst = new_array;
360 int dy,
dh =
h(), wd =
w()*
d(), wld =
ld();
362 memcpy(dst, src, wd);
367 memcpy(new_array,
array,
w() *
h() *
d());
377 if (W <= 0 ||
H <= 0)
return 0;
381 const uchar *old_ptr;
386 new_array =
new uchar [W *
H *
d()];
390 line_d =
ld() ?
ld() :
w() *
d();
402 xstep = (
w() / W) *
d();
407 for (
dy =
H, sy = 0, yerr =
H, new_ptr = new_array;
dy > 0;
dy --) {
408 for (
dx = W, xerr = W, old_ptr =
array + sy * line_d;
dx > 0;
dx --) {
409 for (c = 0; c <
d(); c ++) *new_ptr++ = old_ptr[c];
429 const float xscale = (
w() - 1) / (
float) W;
430 const float yscale = (
h() - 1) / (
float)
H;
432 float oldy =
dy * yscale;
434 oldy =
float(
h() - 1);
435 const float yfract = oldy - (unsigned) oldy;
437 for (
dx = 0;
dx < W;
dx++) {
438 new_ptr = new_array +
dy * W *
d() +
dx *
d();
440 float oldx =
dx * xscale;
442 oldx = float(
w() - 1);
443 const float xfract = oldx - (unsigned) oldx;
445 const unsigned leftx = (unsigned)oldx;
446 const unsigned lefty = (unsigned)oldy;
447 const unsigned rightx = (unsigned)(oldx + 1 >=
w() ? oldx : oldx + 1);
448 const unsigned righty = (unsigned)oldy;
449 const unsigned dleftx = (unsigned)oldx;
450 const unsigned dlefty = (unsigned)(oldy + 1 >=
h() ? oldy : oldy + 1);
451 const unsigned drightx = (unsigned)rightx;
452 const unsigned drighty = (unsigned)dlefty;
454 uchar left[4], right[4], downleft[4], downright[4];
455 memcpy(left,
array + lefty * line_d + leftx *
d(),
d());
456 memcpy(right,
array + righty * line_d + rightx *
d(),
d());
457 memcpy(downleft,
array + dlefty * line_d + dleftx *
d(),
d());
458 memcpy(downright,
array + drighty * line_d + drightx *
d(),
d());
462 for (i = 0; i < 3; i++) {
463 left[i] = (
uchar)(left[i] * left[3] / 255.0
f);
464 right[i] = (
uchar)(right[i] * right[3] / 255.0
f);
465 downleft[i] = (
uchar)(downleft[i] * downleft[3] / 255.0
f);
466 downright[i] = (
uchar)(downright[i] * downright[3] / 255.0
f);
470 const float leftf = 1 - xfract;
471 const float rightf = xfract;
472 const float upf = 1 - yfract;
473 const float downf = yfract;
475 for (i = 0; i <
d(); i++) {
476 new_ptr[i] = (
uchar)((left[i] * leftf +
477 right[i] * rightf) * upf +
478 (downleft[i] * leftf +
479 downright[i] * rightf) * downf);
482 if (
d() == 4 && new_ptr[3]) {
483 for (i = 0; i < 3; i++) {
484 new_ptr[i] = (
uchar)(new_ptr[i] / (new_ptr[3] / 255.0
f));
496 if (!
w() || !
h() || !
d() || !
array)
return;
510 unsigned ia, ir, ig, ib;
513 if (i < 0.0
f) i = 0.0f;
514 else if (i > 1.0
f) i = 1.0f;
516 ia = (unsigned)(256 * i);
522 const uchar *old_ptr;
524 int line_i =
ld() ?
ld() - (
w()*
d()) : 0;
527 ig = (r * 31 + g * 61 +
b * 8) / 100 * (256 - ia);
529 for (new_ptr = new_array, old_ptr =
array,
y = 0;
y <
h();
y ++, old_ptr += line_i)
530 for (
x = 0;
x <
w();
x ++) {
531 *new_ptr++ = (*old_ptr++ * ia + ig) >> 8;
532 if (
d() > 1) *new_ptr++ = *old_ptr++;
535 for (new_ptr = new_array, old_ptr =
array,
y = 0;
y <
h();
y ++, old_ptr += line_i)
536 for (
x = 0;
x <
w();
x ++) {
537 *new_ptr++ = (*old_ptr++ * ia + ir) >> 8;
538 *new_ptr++ = (*old_ptr++ * ia + ig) >> 8;
539 *new_ptr++ = (*old_ptr++ * ia + ib) >> 8;
540 if (
d() > 3) *new_ptr++ = *old_ptr++;
555 if (!
w() || !
h() || !
d() || !
array)
return;
569 new_array =
new uchar[
h() *
w() * new_d];
572 const uchar *old_ptr;
574 int line_i =
ld() ?
ld() - (
w()*
d()) : 0;
576 for (new_ptr = new_array, old_ptr =
array,
y = 0;
y <
h();
y ++, old_ptr += line_i)
577 for (
x = 0;
x <
w();
x ++, old_ptr +=
d()) {
578 *new_ptr++ = (
uchar)((31 * old_ptr[0] + 61 * old_ptr[1] + 8 * old_ptr[2]) / 100);
579 if (
d() > 3) *new_ptr++ = old_ptr[3];
592 #if !defined(WIN32) && !defined(__APPLE__) 597 if (ld == 0) ld = img->
w() * img->
d();
599 int srcskip = ld - img->
d() * W;
606 uchar srcr, srcg, srcb, srca;
607 uchar dstr, dstg, dstb, dsta;
611 for (
int y =
H;
y > 0;
y--, srcptr+=srcskip)
612 for (
int x = W;
x > 0;
x--) {
621 *dstptr++ = (srcg * srca + dstr * dsta) >> 8;
622 *dstptr++ = (srcg * srca + dstg * dsta) >> 8;
623 *dstptr++ = (srcg * srca + dstb * dsta) >> 8;
627 for (
int y =
H;
y > 0;
y--, srcptr+=srcskip)
628 for (
int x = W;
x > 0;
x--) {
639 *dstptr++ = (srcr * srca + dstr * dsta) >> 8;
640 *dstptr++ = (srcg * srca + dstg * dsta) >> 8;
641 *dstptr++ = (srcb * srca + dstb * dsta) >> 8;
649 #endif // !WIN32 && !__APPLE__ 655 static int start(
Fl_RGB_Image *img,
int XP,
int YP,
int WP,
int HP,
int w,
int h,
int &cx,
int &cy,
656 int &X,
int &
Y,
int &W,
int &
H)
660 cx += X-XP; cy +=
Y-YP;
662 if (cx < 0) {W += cx; X -= cx; cx = 0;}
663 if (cx+W > w) W = w-cx;
664 if (W <= 0)
return 1;
665 if (cy < 0) {
H += cy;
Y -= cy; cy = 0;}
666 if (cy+
H > h)
H = h-cy;
667 if (
H <= 0)
return 1;
679 static void imgProviderReleaseData (
void *
info,
const void *data,
size_t size)
681 if (!
info || *(
bool*)
info)
delete[] (
unsigned char *)data;
688 if (!img->
d() || !img->
array) {
692 if (
start(img, XP, YP, WP, HP, img->
w(), img->
h(), cx, cy, X,
Y, W,
H)) {
696 CGColorSpaceRef lut = img->
d()<=2 ? CGColorSpaceCreateDeviceGray() : CGColorSpaceCreateDeviceRGB();
698 if (!ld) ld = img->
w() * img->
d();
707 CGDataProviderRef src = CGDataProviderCreateWithData(img->
mask_, img->
array, ld * img->
h(),
709 img->
id_ = CGImageCreate(img->
w(), img->
h(), 8, img->
d()*8, ld,
710 lut, (img->
d()&1)?kCGImageAlphaNone:kCGImageAlphaLast,
711 src, 0L,
false, kCGRenderingIntentDefault);
712 CGColorSpaceRelease(lut);
713 CGDataProviderRelease(src);
724 if (!ld) ld = img2->
w() * img2->
d();
727 CGColorSpaceRef lut = img->
d()<=2 ? CGColorSpaceCreateDeviceGray() : CGColorSpaceCreateDeviceRGB();
728 CGDataProviderRef src = CGDataProviderCreateWithData(
NULL, img_bytes, ld * img->
h(), imgProviderReleaseData);
729 img->
id_ = CGImageCreate(img->
w(), img->
h(), 8, img->
d()*8, ld,
730 lut, (img->
d()&1)?kCGImageAlphaNone:kCGImageAlphaLast,
731 src, 0L,
true, kCGRenderingIntentDefault);
732 CGColorSpaceRelease(lut);
733 CGDataProviderRelease(src);
735 CGRect
rect = CGRectMake(X,
Y, W,
H);
736 Fl_X::q_begin_image(
rect, cx, cy, img->
w(), img->
h());
742 int Fl_Quartz_Graphics_Driver::draw_scaled(
Fl_Image *img,
int XP,
int YP,
int WP,
int HP) {
745 if (W == 0 ||
H == 0)
return 1;
749 CGContextTranslateCTM(
fl_gc, XP, YP);
750 CGContextScaleCTM(
fl_gc,
float(WP)/img->
w(), float(HP)/img->
h());
751 img->
draw(0, 0, img->
w(), img->
h(), 0, 0);
769 if (img->
d() == 2 || img->
d() == 4) {
779 if (!img->
d() || !img->
array) {
783 if (
start(img, XP, YP, WP, HP, img->
w(), img->
h(), cx, cy, X,
Y, W,
H)) {
786 if (!img->
id_) img->
id_ = build_id(img, &(img->
mask_));
788 HDC new_gc = CreateCompatibleDC(
fl_gc);
789 int save = SaveDC(new_gc);
790 SelectObject(new_gc, (
void*)img->
mask_);
791 BitBlt(
fl_gc, X,
Y, W,
H, new_gc, cx, cy, SRCAND);
792 SelectObject(new_gc, (
void*)img->
id_);
793 BitBlt(
fl_gc, X,
Y, W,
H, new_gc, cx, cy, SRCPAINT);
794 RestoreDC(new_gc,save);
796 }
else if (img->
d()==2 || img->
d()==4) {
803 int Fl_GDI_Printer_Graphics_Driver::draw_scaled(
Fl_Image *img,
int XP,
int YP,
int WP,
int HP) {
805 GetWorldTransform(
fl_gc, &old_tr);
806 tr.eM11 = float(WP)/float(img->
w());
807 tr.eM22 = float(HP)/float(img->
h());
808 tr.eM12 =
tr.eM21 = 0;
811 ModifyWorldTransform(
fl_gc, &
tr, MWT_LEFTMULTIPLY);
812 img->
draw(0, 0, img->
w(), img->
h(), 0, 0);
813 SetWorldTransform(
fl_gc, &old_tr);
821 if (!img->
d() || !img->
array) {
825 if (
start(img, XP, YP, WP, HP, img->
w(), img->
h(), cx, cy, X,
Y, W,
H)) {
829 if (img->
d() == 1 || img->
d() == 3) {
851 int ox = X-cx;
if (ox < 0) ox += img->
w();
852 int oy =
Y-cy;
if (oy < 0) oy += img->
h();
const Fl_Align FL_ALIGN_LEFT
void fl_line(int x, int y, int x1, int y1)
int draw_scaled(Fl_Image *img, int X, int Y, int W, int H)
void data(const char *const *p, int c)
#define fl_create_offscreen_with_alpha(w, h)
const char *const * data() const
const char * class_name()
Base class for image caching and drawing.
FL_EXPORT char fl_can_do_alpha_blending()
void fl_color(Fl_Color c)
#define FL_IMAGE_WITH_ALPHA
default RGB image scaling algorithm
void copy_offscreen_with_alpha(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy)
#define CGContextRestoreGState(a)
Fl_Image(const Fl_Image &)
friend void fl_restore_clip()
friend int fl_clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H)
void copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy)
void fl_draw_image(const uchar *buf, int X, int Y, int W, int H, int D=3, int L=0)
const Fl_Color FL_FOREGROUND_COLOR
the default foreground color (0) used for labels and text
friend void fl_draw_image(const uchar *buf, int X, int Y, int W, int H, int D, int L)
Fl_RGB_Image(const uchar *bits, int W, int H, int D=3, int LD=0)
virtual void color_average(Fl_Color c, float i)
virtual void draw(const char *str, int n, int x, int y)
see fl_draw(const char *str, int n, int x, int y).
static Fl_RGB_Scaling RGB_scaling_
static unsigned get_color(Fl_Color i)
static void measure(const Fl_Label *lo, int &lw, int &lh)
void fl_delete_bitmask(Fl_Bitmask bm)
static void labeltype(const Fl_Label *lo, int lx, int ly, int lw, int lh, Fl_Align la)
virtual void color_average(Fl_Color c, float i)
static void draw(int which, int x, int y, int w, int h, int inset)
utility header to pull drawing functions together
void draw_empty(int X, int Y)
int fl_clip_box(int x, int y, int w, int h, int &X, int &Y, int &W, int &H)
FL_EXPORT uchar * fl_read_image(uchar *p, int X, int Y, int W, int H, int alpha=0)
static Fl_Surface_Device * surface()
virtual Fl_Image * copy(int W, int H)
#define CGContextSaveGState(a)
static Fl_RGB_Scaling RGB_scaling()
FL_EXPORT HINSTANCE fl_display
END TIMERS.
virtual void label(Fl_Widget *w)
struct CGImage * CGImageRef
declaration of classes Fl_Printer, Fl_System_Printer and Fl_PostScript_Printer.
FL_EXPORT Fl_Graphics_Driver * fl_graphics_driver
Points to the driver that currently receives all graphics requests.
const Fl_Align FL_ALIGN_BOTTOM
virtual void draw(int X, int Y, int W, int H, int cx=0, int cy=0)
void fl_delete_offscreen(Fl_Offscreen gWorld)
#define CGContextClipToRect(a, b)
void draw(const char *str, int n, int x, int y)
see fl_draw(const char *str, int n, int x, int y).
static void set_labeltype(Fl_Labeltype, Fl_Label_Draw_F *, Fl_Label_Measure_F *)
virtual void desaturate()
void fl_begin_offscreen(Fl_Offscreen gWorld)
static const char * class_id
void fl_release_dc(HWND w, HDC dc)
virtual void draw(int X, int Y, int W, int H, int cx=0, int cy=0)
const Fl_Align FL_ALIGN_TOP
CGContextRef Fl_Offscreen
Fl_Offscreen fl_create_offscreen(int w, int h)
virtual void label(Fl_Widget *w)
static const int ERR_NO_IMAGE
the label displays an "icon" based on a Fl_Image
void rect(int x, int y, int r, int t)
const Fl_Align FL_ALIGN_RIGHT
static int start(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int w, int h, int &cx, int &cy, int &X, int &Y, int &W, int &H)
Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data)
int fl_convert_pixmap(const char *const *cdata, uchar *out, Fl_Color bg)
static void alpha_blend(Fl_RGB_Image *img, int X, int Y, int W, int H, int cx, int cy)
virtual void desaturate()
void fl_rect(int x, int y, int w, int h)