mirror of
https://github.com/fltk/fltk.git
synced 2026-06-01 06:14:28 +08:00
Implementation of Fl_Shared_Image::scale(width, height) for scaled image drawing - cont'd
Shorter implementation based on Fl_Graphics_Driver::draw_scaled(Fl_Image *,...). git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10616 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
+3
-9
@@ -405,11 +405,7 @@ public:
|
|||||||
#if FLTK_ABI_VERSION >= 10304 || defined(FL_DOXYGEN)
|
#if FLTK_ABI_VERSION >= 10304 || defined(FL_DOXYGEN)
|
||||||
virtual
|
virtual
|
||||||
#endif
|
#endif
|
||||||
int draw_scaled(Fl_RGB_Image *img, int X, int Y, int W, int H);
|
int draw_scaled(Fl_Image *img, int X, int Y, int W, int H);
|
||||||
#if FLTK_ABI_VERSION >= 10304 || defined(FL_DOXYGEN)
|
|
||||||
virtual
|
|
||||||
#endif
|
|
||||||
int draw_scaled(Fl_Pixmap *img, int X, int Y, int W, int H);
|
|
||||||
/** \brief The destructor */
|
/** \brief The destructor */
|
||||||
virtual ~Fl_Graphics_Driver() { if (p) free(p); }
|
virtual ~Fl_Graphics_Driver() { if (p) free(p); }
|
||||||
};
|
};
|
||||||
@@ -436,8 +432,7 @@ public:
|
|||||||
void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
|
void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
|
||||||
void draw(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
|
void draw(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
|
||||||
void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy);
|
void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy);
|
||||||
int draw_scaled(Fl_RGB_Image *img, int XP, int YP, int WP, int HP);
|
int draw_scaled(Fl_Image *img, int XP, int YP, int WP, int HP);
|
||||||
int draw_scaled(Fl_Pixmap *img, int XP, int YP, int WP, int HP);
|
|
||||||
void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0);
|
void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0);
|
||||||
void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3);
|
void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3);
|
||||||
void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0);
|
void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0);
|
||||||
@@ -498,8 +493,7 @@ public:
|
|||||||
const char *class_name() {return class_id;};
|
const char *class_name() {return class_id;};
|
||||||
void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
|
void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
|
||||||
void draw(Fl_Bitmap *bm, int XP, int YP, int WP, int HP, int cx, int cy);
|
void draw(Fl_Bitmap *bm, int XP, int YP, int WP, int HP, int cx, int cy);
|
||||||
int draw_scaled(Fl_RGB_Image *img, int X, int Y, int W, int H);
|
int draw_scaled(Fl_Image *img, int XP, int YP, int WP, int HP);
|
||||||
int draw_scaled(Fl_Pixmap *img, int X, int Y, int W, int H);
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
#if !(defined(__APPLE__) || defined(WIN32))
|
#if !(defined(__APPLE__) || defined(WIN32))
|
||||||
|
|||||||
+1
-2
@@ -213,8 +213,7 @@ class Clip {
|
|||||||
void draw(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy);
|
void draw(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy);
|
||||||
void draw(Fl_Bitmap * bitmap,int XP, int YP, int WP, int HP, int cx, int cy);
|
void draw(Fl_Bitmap * bitmap,int XP, int YP, int WP, int HP, int cx, int cy);
|
||||||
void draw(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy);
|
void draw(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy);
|
||||||
int draw_scaled(Fl_RGB_Image *img, int XP, int YP, int WP, int HP);
|
int draw_scaled(Fl_Image *img, int XP, int YP, int WP, int HP);
|
||||||
int draw_scaled(Fl_Pixmap *img, int XP, int YP, int WP, int HP);
|
|
||||||
int clocale_printf(const char *format, ...);
|
int clocale_printf(const char *format, ...);
|
||||||
~Fl_PostScript_Graphics_Driver();
|
~Fl_PostScript_Graphics_Driver();
|
||||||
};
|
};
|
||||||
|
|||||||
+7
-15
@@ -548,21 +548,13 @@ static int start(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int w, int h
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Draws an Fl_RGB_Image scaled to width \p W & height \p H with top-left corner at \em X,Y
|
/** Draws an Fl_Image scaled to width \p W & height \p H with top-left corner at \em X,Y
|
||||||
\return zero when the graphics driver doesn't implement scaled drawing, non-zero if it does implement it.
|
\return zero when the graphics driver doesn't implement scaled drawing, non-zero if it does implement it.
|
||||||
*/
|
*/
|
||||||
int Fl_Graphics_Driver::draw_scaled(Fl_RGB_Image *img, int X, int Y, int W, int H) {
|
int Fl_Graphics_Driver::draw_scaled(Fl_Image *img, int X, int Y, int W, int H) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Draws an Fl_Pixmap scaled to width \p W & height \p H with top-left corner at \em X,Y
|
|
||||||
\return zero when the graphics driver doesn't implement scaled drawing, non-zero if it does implement it.
|
|
||||||
*/
|
|
||||||
int Fl_Graphics_Driver::draw_scaled(Fl_Pixmap *img, int X, int Y, int W, int H) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
static void imgProviderReleaseData (void *info, const void *data, size_t size)
|
static void imgProviderReleaseData (void *info, const void *data, size_t size)
|
||||||
{
|
{
|
||||||
@@ -627,7 +619,7 @@ void Fl_Quartz_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Fl_Quartz_Graphics_Driver::draw_scaled(Fl_RGB_Image *img, int XP, int YP, int WP, int HP) {
|
int Fl_Quartz_Graphics_Driver::draw_scaled(Fl_Image *img, int XP, int YP, int WP, int HP) {
|
||||||
int X, Y, W, H;
|
int X, Y, W, H;
|
||||||
fl_clip_box(XP,YP,WP,HP,X,Y,W,H); // X,Y,W,H will give the unclipped area of XP,YP,WP,HP
|
fl_clip_box(XP,YP,WP,HP,X,Y,W,H); // X,Y,W,H will give the unclipped area of XP,YP,WP,HP
|
||||||
if (W == 0 || H == 0) return 1;
|
if (W == 0 || H == 0) return 1;
|
||||||
@@ -636,7 +628,7 @@ int Fl_Quartz_Graphics_Driver::draw_scaled(Fl_RGB_Image *img, int XP, int YP, in
|
|||||||
CGContextClipToRect(fl_gc, CGRectMake(X, Y, W, H)); // this clip path will be rescaled & translated
|
CGContextClipToRect(fl_gc, CGRectMake(X, Y, W, H)); // this clip path will be rescaled & translated
|
||||||
CGContextTranslateCTM(fl_gc, XP, YP);
|
CGContextTranslateCTM(fl_gc, XP, YP);
|
||||||
CGContextScaleCTM(fl_gc, float(WP)/img->w(), float(HP)/img->h());
|
CGContextScaleCTM(fl_gc, float(WP)/img->w(), float(HP)/img->h());
|
||||||
draw(img, 0, 0, img->w(), img->h(), 0, 0);
|
img->draw(0, 0, img->w(), img->h(), 0, 0);
|
||||||
CGContextRestoreGState(fl_gc);
|
CGContextRestoreGState(fl_gc);
|
||||||
fl_pop_clip(); // restore FLTK's clip
|
fl_pop_clip(); // restore FLTK's clip
|
||||||
return 1;
|
return 1;
|
||||||
@@ -688,7 +680,7 @@ void Fl_GDI_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Fl_GDI_Printer_Graphics_Driver::draw_scaled(Fl_RGB_Image *img, int XP, int YP, int WP, int HP) {
|
int Fl_GDI_Printer_Graphics_Driver::draw_scaled(Fl_Image *img, int XP, int YP, int WP, int HP) {
|
||||||
XFORM old_tr, tr;
|
XFORM old_tr, tr;
|
||||||
GetWorldTransform(fl_gc, &old_tr); // storing old transform
|
GetWorldTransform(fl_gc, &old_tr); // storing old transform
|
||||||
tr.eM11 = float(WP)/float(img->w());
|
tr.eM11 = float(WP)/float(img->w());
|
||||||
@@ -697,9 +689,9 @@ int Fl_GDI_Printer_Graphics_Driver::draw_scaled(Fl_RGB_Image *img, int XP, int Y
|
|||||||
tr.eDx = XP;
|
tr.eDx = XP;
|
||||||
tr.eDy = YP;
|
tr.eDy = YP;
|
||||||
ModifyWorldTransform(fl_gc, &tr, MWT_LEFTMULTIPLY);
|
ModifyWorldTransform(fl_gc, &tr, MWT_LEFTMULTIPLY);
|
||||||
Fl_GDI_Graphics_Driver::draw(img, 0, 0, img->w(), img->h(), 0, 0);
|
img->draw(0, 0, img->w(), img->h(), 0, 0);
|
||||||
SetWorldTransform(fl_gc, &old_tr);
|
SetWorldTransform(fl_gc, &old_tr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -135,21 +135,6 @@ void Fl_Quartz_Graphics_Driver::draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int
|
|||||||
copy_offscreen(X, Y, W, H, (Fl_Offscreen)pxm->id_, cx, cy);
|
copy_offscreen(X, Y, W, H, (Fl_Offscreen)pxm->id_, cx, cy);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Fl_Quartz_Graphics_Driver::draw_scaled(Fl_Pixmap *img, int XP, int YP, int WP, int HP) {
|
|
||||||
int X, Y, W, H;
|
|
||||||
fl_clip_box(XP,YP,WP,HP,X,Y,W,H); // X,Y,W,H will give the unclipped area of XP,YP,WP,HP
|
|
||||||
if (W == 0 || H == 0) return 1;
|
|
||||||
fl_push_no_clip(); // remove the FLTK clip that can't be rescaled
|
|
||||||
CGContextSaveGState(fl_gc);
|
|
||||||
CGContextClipToRect(fl_gc, CGRectMake(X, Y, W, H)); // this clip path will be rescaled & translated
|
|
||||||
CGContextTranslateCTM(fl_gc, XP, YP);
|
|
||||||
CGContextScaleCTM(fl_gc, float(WP)/img->w(), float(HP)/img->h());
|
|
||||||
draw(img, 0, 0, img->w(), img->h(), 0, 0);
|
|
||||||
CGContextRestoreGState(fl_gc);
|
|
||||||
fl_pop_clip(); // restore FLTK's clip
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif defined(WIN32)
|
#elif defined(WIN32)
|
||||||
void Fl_GDI_Graphics_Driver::draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy) {
|
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;
|
int X, Y, W, H;
|
||||||
@@ -196,20 +181,6 @@ void Fl_GDI_Printer_Graphics_Driver::draw(Fl_Pixmap *pxm, int XP, int YP, int WP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Fl_GDI_Printer_Graphics_Driver::draw_scaled(Fl_Pixmap *img, int XP, int YP, int WP, int HP) {
|
|
||||||
XFORM old_tr, tr;
|
|
||||||
GetWorldTransform(fl_gc, &old_tr); // storing old transform
|
|
||||||
tr.eM11 = float(WP)/float(img->w());
|
|
||||||
tr.eM22 = float(HP)/float(img->h());
|
|
||||||
tr.eM12 = tr.eM21 = 0;
|
|
||||||
tr.eDx = XP;
|
|
||||||
tr.eDy = YP;
|
|
||||||
ModifyWorldTransform(fl_gc, &tr, MWT_LEFTMULTIPLY);
|
|
||||||
draw(img, 0, 0, img->w(), img->h(), 0, 0);
|
|
||||||
SetWorldTransform(fl_gc, &old_tr);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#else // Xlib
|
#else // Xlib
|
||||||
void Fl_Xlib_Graphics_Driver::draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy) {
|
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;
|
int X, Y, W, H;
|
||||||
|
|||||||
+2
-13
@@ -338,19 +338,8 @@ void Fl_Shared_Image::draw(int X, int Y, int W, int H, int cx, int cy) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fl_push_clip(X, Y, W, H);
|
fl_push_clip(X, Y, W, H);
|
||||||
int use_scaled_image = 0, done;
|
int done = fl_graphics_driver->draw_scaled(image_, X-cx, Y-cy, w(), h());
|
||||||
if (image_->d() == 0) { // handles Fl_Bitmap
|
if (!done) {
|
||||||
use_scaled_image = 1;
|
|
||||||
}
|
|
||||||
else if (image_->count() >= 2) { // handles Fl_Pixmap
|
|
||||||
done = fl_graphics_driver->draw_scaled((Fl_Pixmap*)image_, X-cx, Y-cy, w(), h());
|
|
||||||
if (done == 0) use_scaled_image = 1;
|
|
||||||
}
|
|
||||||
else { // handles Fl_RGB_Image
|
|
||||||
done = fl_graphics_driver->draw_scaled((Fl_RGB_Image*)image_, X-cx, Y-cy, w(), h());
|
|
||||||
if (done == 0) use_scaled_image = 1;
|
|
||||||
}
|
|
||||||
if (use_scaled_image) {
|
|
||||||
if (scaled_image_ && (scaled_image_->w() != w() || scaled_image_->h() != h())) {
|
if (scaled_image_ && (scaled_image_->w() != w() || scaled_image_->h() != h())) {
|
||||||
delete scaled_image_;
|
delete scaled_image_;
|
||||||
scaled_image_ = NULL;
|
scaled_image_ = NULL;
|
||||||
|
|||||||
+2
-15
@@ -602,27 +602,14 @@ void Fl_PostScript_Graphics_Driver::draw(Fl_RGB_Image * rgb,int XP, int YP, int
|
|||||||
mask=0;
|
mask=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Fl_PostScript_Graphics_Driver::draw_scaled(Fl_RGB_Image *rgb, int XP, int YP, int WP, int HP){
|
int Fl_PostScript_Graphics_Driver::draw_scaled(Fl_Image *img, int XP, int YP, int WP, int HP){
|
||||||
int X, Y, W, H;
|
|
||||||
clip_box(XP,YP,WP,HP,X,Y,W,H); // X,Y,W,H will give the unclipped area of XP,YP,WP,HP
|
|
||||||
if (W == 0 || H == 0) return 1;
|
|
||||||
push_no_clip(); // remove the FLTK clip that can't be rescaled
|
|
||||||
clocale_printf("%d %d %i %i CL\n", X, Y, W, H);
|
|
||||||
clocale_printf("GS %d %d TR %f %f SC GS\n", XP, YP, float(WP)/rgb->w(), float(HP)/rgb->h());
|
|
||||||
draw(rgb, 0, 0, rgb->w(), rgb->h(), 0, 0);
|
|
||||||
clocale_printf("GR GR\n");
|
|
||||||
pop_clip(); // restore FLTK's clip
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Fl_PostScript_Graphics_Driver::draw_scaled(Fl_Pixmap *img, int XP, int YP, int WP, int HP){
|
|
||||||
int X, Y, W, H;
|
int X, Y, W, H;
|
||||||
clip_box(XP,YP,WP,HP,X,Y,W,H); // X,Y,W,H will give the unclipped area of XP,YP,WP,HP
|
clip_box(XP,YP,WP,HP,X,Y,W,H); // X,Y,W,H will give the unclipped area of XP,YP,WP,HP
|
||||||
if (W == 0 || H == 0) return 1;
|
if (W == 0 || H == 0) return 1;
|
||||||
push_no_clip(); // remove the FLTK clip that can't be rescaled
|
push_no_clip(); // remove the FLTK clip that can't be rescaled
|
||||||
clocale_printf("%d %d %i %i CL\n", X, Y, W, H);
|
clocale_printf("%d %d %i %i CL\n", X, Y, W, H);
|
||||||
clocale_printf("GS %d %d TR %f %f SC GS\n", XP, YP, float(WP)/img->w(), float(HP)/img->h());
|
clocale_printf("GS %d %d TR %f %f SC GS\n", XP, YP, float(WP)/img->w(), float(HP)/img->h());
|
||||||
draw(img, 0, 0, img->w(), img->h(), 0, 0);
|
img->draw(0, 0, img->w(), img->h(), 0, 0);
|
||||||
clocale_printf("GR GR\n");
|
clocale_printf("GR GR\n");
|
||||||
pop_clip(); // restore FLTK's clip
|
pop_clip(); // restore FLTK's clip
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user