diff options
| -rw-r--r-- | FL/Fl_Bitmap.H | 6 | ||||
| -rw-r--r-- | FL/Fl_Graphics_Driver.H | 21 | ||||
| -rw-r--r-- | FL/Fl_Image.H | 4 | ||||
| -rw-r--r-- | FL/Fl_Pixmap.H | 2 | ||||
| -rw-r--r-- | src/Fl_Graphics_Driver.cxx | 39 | ||||
| -rw-r--r-- | src/Fl_Image.cxx | 4 | ||||
| -rw-r--r-- | src/Fl_Pixmap.cxx | 2 | ||||
| -rw-r--r-- | src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx | 20 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H | 1 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx | 18 |
10 files changed, 79 insertions, 38 deletions
diff --git a/FL/Fl_Bitmap.H b/FL/Fl_Bitmap.H index 03f1a62e8..79eba0a4b 100644 --- a/FL/Fl_Bitmap.H +++ b/FL/Fl_Bitmap.H @@ -44,15 +44,15 @@ private: int &X, int &Y, int &W, int &H); /** for internal use */ fl_uintptr_t id_; - float cache_scale_; // graphics scaling value when id_ was computed + int cache_w_, cache_h_; // size of bitmap when cached public: /** The constructors create a new bitmap from the specified bitmap data */ Fl_Bitmap(const uchar *bits, int W, int H) : - Fl_Image(W,H,0), array(bits), alloc_array(0), id_(0), cache_scale_(1) {data((const char **)&array, 1);} + Fl_Image(W,H,0), array(bits), alloc_array(0), id_(0), cache_w_(0),cache_h_(0) {data((const char **)&array, 1);} /** The constructors create a new bitmap from the specified bitmap data */ Fl_Bitmap(const char *bits, int W, int H) : - Fl_Image(W,H,0), array((const uchar *)bits), alloc_array(0), id_(0), cache_scale_(1) {data((const char **)&array, 1);} + Fl_Image(W,H,0), array((const uchar *)bits), alloc_array(0), id_(0), cache_w_(0),cache_h_(0) {data((const char **)&array, 1);} virtual ~Fl_Bitmap(); virtual Fl_Image *copy(int W, int H); Fl_Image *copy() { return Fl_Image::copy(); } diff --git a/FL/Fl_Graphics_Driver.H b/FL/Fl_Graphics_Driver.H index c1588703b..fbd1b71ed 100644 --- a/FL/Fl_Graphics_Driver.H +++ b/FL/Fl_Graphics_Driver.H @@ -199,12 +199,21 @@ protected: static fl_uintptr_t* mask(Fl_RGB_Image *rgb) {return &(rgb->mask_);} /** Accessor to a private member variable of Fl_Pixmap */ static fl_uintptr_t* mask(Fl_Pixmap *pm) {return &(pm->mask_);} - /** Accessor to a private member variable of Fl_Pixmap */ - static float* cache_scale(Fl_Pixmap *pm) {return &(pm->cache_scale_);} - /** Accessor to a private member variable of Fl_Bitmap */ - static float* cache_scale(Fl_Bitmap *bm) {return &(bm->cache_scale_);} - /** Accessor to a private member variable of Fl_RGB_Image */ - static float* cache_scale(Fl_RGB_Image *rgb) {return &(rgb->cache_scale_);} + /** Accessor to private member variables of Fl_Pixmap */ + static void cache_w_h(Fl_Pixmap *pm, int*& pwidth, int*& pheight) { + pwidth = &(pm->cache_w_); + pheight = &(pm->cache_h_); + } + /** Accessor to private member variables of Fl_Bitmap */ + static void cache_w_h(Fl_Bitmap *bm, int*& pwidth, int*& pheight) { + pwidth = &(bm->cache_w_); + pheight = &(bm->cache_h_); + } + /** Accessor to private member variables of Fl_RGB_Image */ + static void cache_w_h(Fl_RGB_Image *rgb, int*& pwidth, int*& pheight) { + pwidth = &(rgb->cache_w_); + pheight = &(rgb->cache_h_); + } /** Accessor to a private member variable of Fl_Pixmap */ static Fl_Color* pixmap_bg_color(Fl_Pixmap *pm) {return &(pm->pixmap_bg_color);} /** For internal library use only */ diff --git a/FL/Fl_Image.H b/FL/Fl_Image.H index 41783639d..0a590a1af 100644 --- a/FL/Fl_Image.H +++ b/FL/Fl_Image.H @@ -262,8 +262,8 @@ private: // These two variables are used to cache the image and mask for the main display graphics driver fl_uintptr_t id_; fl_uintptr_t mask_; - float cache_scale_; // graphics scaling value when id_ was computed - + int cache_w_, cache_h_; // size of image when cached + public: Fl_RGB_Image(const uchar *bits, int W, int H, int D=3, int LD=0); diff --git a/FL/Fl_Pixmap.H b/FL/Fl_Pixmap.H index fa45b3fbb..d5c0612db 100644 --- a/FL/Fl_Pixmap.H +++ b/FL/Fl_Pixmap.H @@ -55,7 +55,7 @@ private: fl_uintptr_t id_; fl_uintptr_t mask_; Fl_Color pixmap_bg_color; - float cache_scale_; // graphics scaling value when id_ was computed + int cache_w_, cache_h_; // size of pixmap when cached public: diff --git a/src/Fl_Graphics_Driver.cxx b/src/Fl_Graphics_Driver.cxx index e1045b460..cbabda596 100644 --- a/src/Fl_Graphics_Driver.cxx +++ b/src/Fl_Graphics_Driver.cxx @@ -326,16 +326,18 @@ void Fl_Scalable_Graphics_Driver::draw(Fl_Pixmap *pxm, int XP, int YP, int WP, i return; } // to allow rescale at runtime - if (*id(pxm) && *cache_scale(pxm) != scale_) { + int w2=pxm->w(), h2=pxm->h(); + cache_size(pxm, w2, h2); // after this, w2 x h2 is size of desired cached image + int *pw, *ph; + cache_w_h(pxm, pw, ph); // after this, *pw x *ph is current size of cached form of bitmap + if (*id(pxm) && (*pw != w2 || *ph != h2)) { pxm->uncache(); } if (!*id(pxm)) { - int w2=pxm->w(), h2=pxm->h(); - cache_size(pxm, w2, h2); // after this, w2 x h2 is size of desired cached image - if (pxm->data_w() != w2 || pxm->data_h() != h2) { // build a scaled id_ & pixmap_ for pxm + if (pxm->data_w() != w2 || pxm->data_h() != h2) { // build a scaled id_ & mask_ for pxm Fl_Pixmap *pxm2 = (Fl_Pixmap*)pxm->copy(w2, h2); *id(pxm) = cache(pxm2); - *cache_scale(pxm) = scale_; + *pw = w2; *ph = h2; // memorize size of cached form of pixmap *mask(pxm) = *mask(pxm2); *mask(pxm2) = 0; delete pxm2; @@ -351,16 +353,18 @@ void Fl_Scalable_Graphics_Driver::draw(Fl_Bitmap *bm, int XP, int YP, int WP, in if (Fl_Graphics_Driver::start_image(bm, XP, YP, WP, HP, cx, cy, X, Y, W, H)) { return; } - if (*id(bm) && *cache_scale(bm) != scale_) { + int w2 = bm->w(), h2 = bm->h(); + cache_size(bm, w2, h2); // after this, w2 x h2 is size of desired cached image + int *pw, *ph; + cache_w_h(bm, pw, ph); // after this, *pw x *ph is current size of cached form of bitmap + if (*id(bm) && (*pw != w2 || *ph != h2)) { bm->uncache(); } if (!*id(bm)) { - int w2 = bm->w(), h2 = bm->h(); - cache_size(bm, w2, h2); // after this, w2 x h2 is size of desired cached image if (bm->data_w() != w2 || bm->data_h() != h2) { // build a scaled id_ for bm Fl_Bitmap *bm2 = (Fl_Bitmap*)bm->copy(w2, h2); *id(bm) = cache(bm2); - *cache_scale(bm) = scale_; + *pw = w2; *ph = h2; // memorize size of cached form of bitmap delete bm2; } else *id(bm) = cache(bm); } @@ -387,12 +391,18 @@ void Fl_Scalable_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP if (done) return; } // to allow rescale at runtime - if (*id(img) && *cache_scale(img) != scale_) { + int w2, h2, *pw, *ph; + if (need_scaled_drawing) { + w2 = img->w(); h2 = img->h(); + cache_size(img, w2, h2); + } else { + w2 = img->data_w(); h2 = img->data_h(); + } // after this, w2 x h2 is desired cached image size + cache_w_h(img, pw, ph); // after this, *pw x *ph is current size of cached image + if (*id(img) && (w2 != *pw || h2 != *ph )) { img->uncache(); } - if (!*id(img) && need_scaled_drawing ) { // build and draw a scaled id_ for img - int w2=img->w(), h2=img->h(); - cache_size(img, w2, h2); + if (!*id(img) && need_scaled_drawing) { // build and draw a scaled id_ for img Fl_RGB_Scaling keep = Fl_Image::RGB_scaling(); Fl_Image::RGB_scaling(Fl_Image::scaling_algorithm()); Fl_RGB_Image *img2 = (Fl_RGB_Image*)img->copy(w2, h2); @@ -400,7 +410,8 @@ void Fl_Scalable_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP draw_unscaled(img2, scale_, XP, YP, WP, HP, cx, cy); *id(img) = *id(img2); *id(img2) = 0; - *cache_scale(img) = scale_; + *pw = w2; + *ph = h2; delete img2; } else { // draw img using its scaled id_ diff --git a/src/Fl_Image.cxx b/src/Fl_Image.cxx index 4cc6a8603..b1b8b64d7 100644 --- a/src/Fl_Image.cxx +++ b/src/Fl_Image.cxx @@ -349,7 +349,7 @@ Fl_RGB_Image::Fl_RGB_Image(const uchar *bits, int W, int H, int D, int LD) : alloc_array(0), id_(0), mask_(0), - cache_scale_(1) + cache_w_(0), cache_h_(0) { data((const char **)&array, 1); ld(LD); @@ -372,7 +372,7 @@ Fl_RGB_Image::Fl_RGB_Image(const Fl_Pixmap *pxm, Fl_Color bg): alloc_array(0), id_(0), mask_(0), - cache_scale_(1) + cache_w_(0), cache_h_(0) { if (pxm && pxm->w() > 0 && pxm->h() > 0) { array = new uchar[w() * h() * d()]; diff --git a/src/Fl_Pixmap.cxx b/src/Fl_Pixmap.cxx index ca76362de..33c76233d 100644 --- a/src/Fl_Pixmap.cxx +++ b/src/Fl_Pixmap.cxx @@ -42,7 +42,7 @@ void Fl_Pixmap::measure() { if (w()<0 && data()) { fl_measure_pixmap(data(), W, H); w(W); h(H); - cache_scale_ = 1; + cache_w_ = cache_h_ = 0; } } diff --git a/src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx b/src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx index 5c00198f0..6b9cb6d87 100644 --- a/src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx +++ b/src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx @@ -498,7 +498,10 @@ void Fl_GDI_Graphics_Driver::draw_unscaled(Fl_RGB_Image *img, float s, int X, in if (H + cy > img->data_h()) H = img->data_h() - cy; if (!*Fl_Graphics_Driver::id(img)) { *Fl_Graphics_Driver::id(img) = (fl_uintptr_t)build_id(img, (void**)(Fl_Graphics_Driver::mask(img))); - *cache_scale(img) = 1; + int *pw, *ph; + cache_w_h(img, pw, ph); + *pw = img->data_w(); + *ph = img->data_h(); } Fl_Region r2 = scale_clip(s); if (*Fl_Graphics_Driver::mask(img)) { @@ -541,7 +544,10 @@ int Fl_GDI_Graphics_Driver::draw_scaled(Fl_Image *img, int XP, int YP, int WP, i if (!*Fl_Graphics_Driver::id(rgb)) { *Fl_Graphics_Driver::id(rgb) = (fl_uintptr_t)build_id(rgb, (void**)(Fl_Graphics_Driver::mask(rgb))); - *cache_scale(rgb) = 1; + int *pw, *ph; + cache_w_h(rgb, pw, ph); + *pw = rgb->data_w(); + *ph = rgb->data_h(); } cache_size(img, WP, HP); HDC new_gc = CreateCompatibleDC(gc_); @@ -600,7 +606,10 @@ static Fl_Bitmask fl_create_bitmap(int w, int h, const uchar *data) { } fl_uintptr_t Fl_GDI_Graphics_Driver::cache(Fl_Bitmap *bm) { - *cache_scale(bm) = Fl_Scalable_Graphics_Driver::scale(); + int *pw, *ph; + cache_w_h(bm, pw, ph); + *pw = bm->data_w(); + *ph = bm->data_h(); return (fl_uintptr_t)fl_create_bitmap(bm->data_w(), bm->data_h(), bm->array); } @@ -660,7 +669,10 @@ fl_uintptr_t Fl_GDI_Graphics_Driver::cache(Fl_Pixmap *img) { Fl_Surface_Device::pop_current(); Fl_Offscreen id = surf->get_offscreen_before_delete(); delete surf; - *cache_scale(img) = 1; + int *pw, *ph; + cache_w_h(img, pw, ph); + *pw = img->data_w(); + *ph = img->data_h(); return (fl_uintptr_t)id; } diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H index 7d74b70e1..785c76369 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H @@ -101,6 +101,7 @@ protected: static Window draw_window; static struct _XftDraw* draw_; #endif + Fl_Offscreen cache_rgb(Fl_RGB_Image *img); public: Fl_Xlib_Graphics_Driver(void); virtual ~Fl_Xlib_Graphics_Driver(); diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx index 902cb5e45..c271dae53 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx @@ -696,7 +696,7 @@ static void alpha_blend(Fl_RGB_Image *img, int X, int Y, int W, int H, int cx, i delete[] dst; } -static Fl_Offscreen cache_rgb(Fl_RGB_Image *img) { +Fl_Offscreen Fl_Xlib_Graphics_Driver::cache_rgb(Fl_RGB_Image *img) { Fl_Image_Surface *surface; int depth = img->d(); if (depth == 1 || depth == 3) { @@ -713,6 +713,10 @@ static Fl_Offscreen cache_rgb(Fl_RGB_Image *img) { Fl_Surface_Device::pop_current(); Fl_Offscreen off = surface->get_offscreen_before_delete(); delete surface; + int *pw, *ph; + cache_w_h(img, pw, ph); + *pw = img->data_w(); + *ph = img->data_h(); return off; } @@ -728,7 +732,6 @@ void Fl_Xlib_Graphics_Driver::draw_unscaled(Fl_RGB_Image *img, float s, int X, i if (H + cy > img->data_h()) H = img->data_h() - cy; if (!*Fl_Graphics_Driver::id(img)) { *Fl_Graphics_Driver::id(img) = cache_rgb(img); - *cache_scale(img) = 1; } Fl_Region r2 = scale_clip(s); if (*Fl_Graphics_Driver::id(img)) { @@ -767,7 +770,10 @@ void Fl_Xlib_Graphics_Driver::uncache(Fl_RGB_Image*, fl_uintptr_t &id_, fl_uintp } fl_uintptr_t Fl_Xlib_Graphics_Driver::cache(Fl_Bitmap *bm) { - *cache_scale(bm) = Fl_Scalable_Graphics_Driver::scale(); + int *pw, *ph; + cache_w_h(bm, pw, ph); + *pw = bm->data_w(); + *ph = bm->data_h(); return (fl_uintptr_t)create_bitmask(bm->data_w(), bm->data_h(), bm->array); } @@ -830,7 +836,10 @@ fl_uintptr_t Fl_Xlib_Graphics_Driver::cache(Fl_Pixmap *pxm) { Fl_Surface_Device::pop_current(); Fl_Offscreen id = surf->get_offscreen_before_delete(); delete surf; - *cache_scale(pxm) = 1; + int *pw, *ph; + cache_w_h(pxm, pw, ph); + *pw = pxm->data_w(); + *ph = pxm->data_h(); return (fl_uintptr_t)id; } @@ -881,7 +890,6 @@ int Fl_Xlib_Graphics_Driver::draw_scaled(Fl_Image *img, int XP, int YP, int WP, if (!rgb || !can_do_alpha_blending()) return 0; if (!*Fl_Graphics_Driver::id(rgb)) { *Fl_Graphics_Driver::id(rgb) = cache_rgb(rgb); - *cache_scale(rgb) = 1; } cache_size(img, WP, HP); return scale_and_render_pixmap( *Fl_Graphics_Driver::id(rgb), rgb->d(), |
