From d24a6b2633664959d0b0ab5fd1ab3aa140ab877f Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Tue, 14 Oct 2014 11:53:51 +0000 Subject: Move RGB image scaling algorithm methods in base class Fl_Image. See also discussion in fltk.coredev of Sept 07, 2014 and later with subject "Fixing the nearest-neighbour scaling". git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10377 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Image.cxx | 29 +++++++++++++++++------------ src/Fl_cocoa.mm | 8 ++++---- 2 files changed, 21 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/Fl_Image.cxx b/src/Fl_Image.cxx index 71e117799..73eec41b8 100644 --- a/src/Fl_Image.cxx +++ b/src/Fl_Image.cxx @@ -3,7 +3,7 @@ // // Image drawing code for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2012 by Bill Spitzak and others. +// Copyright 1998-2014 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -34,6 +34,8 @@ void fl_restore_clip(); // from fl_rect.cxx // Base image class... // +Fl_RGB_Scaling Fl_Image::RGB_scaling_ = FL_RGB_SCALING_NEAREST; + /** The destructor is a virtual method that frees all memory used by the image. @@ -159,12 +161,23 @@ Fl_Image::measure(const Fl_Label *lo, // I - Label lh = img->h(); } +/** Sets the RGB image scaling method used for copy(int, int). + Applies to all RGB images, defaults to FL_RGB_SCALING_NEAREST. +*/ +void Fl_Image::RGB_scaling(Fl_RGB_Scaling method) { + RGB_scaling_ = method; +} + +/** Returns the currently used RGB image scaling method. */ +Fl_RGB_Scaling Fl_Image::RGB_scaling() { + return RGB_scaling_; +} + // // RGB image class... // size_t Fl_RGB_Image::max_size_ = ~((size_t)0); -Fl_RGB_Scaling Fl_RGB_Image::scaling_ = FL_SCALING_NEAREST; int fl_convert_pixmap(const char*const* cdata, uchar* out, Fl_Color bg); @@ -261,7 +274,7 @@ Fl_Image *Fl_RGB_Image::copy(int W, int H) { new_image = new Fl_RGB_Image(new_array, W, H, d()); new_image->alloc_array = 1; - if (scaling_ == FL_SCALING_NEAREST) { + if (Fl_Image::RGB_scaling() == FL_RGB_SCALING_NEAREST) { // Scale the image using a nearest-neighbor algorithm... for (dy = H, sy = 0, yerr = H, new_ptr = new_array; dy > 0; dy --) { for (dx = W, xerr = W, old_ptr = array + sy * line_d; dx > 0; dx --) { @@ -284,7 +297,7 @@ Fl_Image *Fl_RGB_Image::copy(int W, int H) { } } } else { - // Bilinear scaling + // Bilinear scaling (FL_RGB_SCALING_BILINEAR) const float xscale = (w() - 1) / (float) W; const float yscale = (h() - 1) / (float) H; for (dy = 0; dy < H; dy++) { @@ -679,14 +692,6 @@ void Fl_RGB_Image::label(Fl_Menu_Item* m) { m->label(_FL_IMAGE_LABEL, (const char*)this); } -void Fl_RGB_Image::scaling(Fl_RGB_Scaling method) { - scaling_ = method; -} - -Fl_RGB_Scaling Fl_RGB_Image::scaling() { - return scaling_; -} - // // End of "$Id$". // diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 3f26f3342..fee2ed45a 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -3,7 +3,7 @@ // // MacOS-Cocoa specific code for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2013 by Bill Spitzak and others. +// Copyright 1998-2014 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -3857,10 +3857,10 @@ unsigned char *Fl_X::bitmap_from_window_rect(Fl_Window *win, int x, int y, int w unsigned char *data; if (ww > w) { // with a retina display Fl_RGB_Image *rgb = new Fl_RGB_Image([bitmap bitmapData], ww, hh, 4); - Fl_RGB_Scaling save_scaling =Fl_RGB_Image::scaling(); - Fl_RGB_Image::scaling(FL_SCALING_BILINEAR); + Fl_RGB_Scaling save_scaling = Fl_Image::RGB_scaling(); + Fl_Image::RGB_scaling(FL_RGB_SCALING_BILINEAR); Fl_RGB_Image *rgb2 = (Fl_RGB_Image*)rgb->copy(w, h); - Fl_RGB_Image::scaling(save_scaling); + Fl_Image::RGB_scaling(save_scaling); delete rgb; rgb2->alloc_array = 0; data = (uchar*)rgb2->array; -- cgit v1.2.3