diff options
| author | Matthias Melcher <github@matthiasm.com> | 2025-07-01 13:22:09 +0200 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2025-07-01 13:22:14 +0200 |
| commit | 66dde2646915ccf679658485e15ee33c3011087b (patch) | |
| tree | 3c474ac35d225f7b5198d59d65849010940b758a /src | |
| parent | a34711daeb92fb1c3cb18d5f9d23cf23f37969ce (diff) | |
Better handling of special case when scaling image
When scaling image down by 2, 4, 8, etc., there is no
sense in calling the bilinear scaling.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_Image.cxx | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/Fl_Image.cxx b/src/Fl_Image.cxx index 6499441d1..ffdb1c7f7 100644 --- a/src/Fl_Image.cxx +++ b/src/Fl_Image.cxx @@ -734,24 +734,32 @@ Fl_Image *Fl_RGB_Image::copy(int W, int H) const { // much larger, divide it by two in either direction first. This is not // perfect, but relatively fast. const Fl_RGB_Image *img = this; - while ((img->data_w() > 2*W) || (img->data_h() > 2*H)) { + while ((img->data_w() >= 2*W) || (img->data_h() >= 2*H)) { // Coarse scaling horizontally - if (img->data_w()>2*W) { + if (img->data_w()>=2*W) { const Fl_RGB_Image *scaled_img = img->copy_scale_down_2h_(); if (img != this) delete img; img = scaled_img; } // Coarse scaling vertically - if (img->data_h()>2*H) { + if (img->data_h()>=2*H) { const Fl_RGB_Image *scaled_img = img->copy_scale_down_2v_(); if (img != this) delete img; img = scaled_img; } } // Fine scaling the smaller image - Fl_RGB_Image *fine_scaled_img = img->copy_bilinear_(W, H); - if (img != this) delete img; - return fine_scaled_img; + if ((img->data_w() != W) || (img->data_h() != H)) { + Fl_RGB_Image *fine_scaled_img = img->copy_bilinear_(W, H); + if (img != this) delete img; + return fine_scaled_img; + } else { + if (img == this) { // this should not happen, but just in case + return copy(); + } else { + return (Fl_Image*)img; + } + } } } |
