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
This commit is contained in:
parent
f1bf759c64
commit
d24a6b2633
@ -3,7 +3,7 @@
|
||||
//
|
||||
// Image header file for the Fast Light Tool Kit (FLTK).
|
||||
//
|
||||
// Copyright 1998-2011 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
|
||||
@ -30,22 +30,31 @@ class Fl_Pixmap;
|
||||
struct Fl_Menu_Item;
|
||||
struct Fl_Label;
|
||||
|
||||
/** \enum Fl_RGB_Scaling.
|
||||
The scaling algorithm to use for RGB images.
|
||||
*/
|
||||
enum Fl_RGB_Scaling {
|
||||
FL_RGB_SCALING_NEAREST = 0, ///< default RGB image scaling algorithm
|
||||
FL_RGB_SCALING_BILINEAR ///< more accurate, but slower RGB image scaling algorithm
|
||||
};
|
||||
|
||||
/**
|
||||
Fl_Image is the base class used for caching and
|
||||
drawing all kinds of images in FLTK. This class keeps track of
|
||||
common image data such as the pixels, colormap, width, height,
|
||||
and depth. Virtual methods are used to provide type-specific
|
||||
image handling.</P>
|
||||
image handling.
|
||||
|
||||
<P>Since the Fl_Image class does not support image
|
||||
Since the Fl_Image class does not support image
|
||||
drawing by itself, calling the draw() method results in
|
||||
a box with an X in it being drawn instead.
|
||||
*/
|
||||
class FL_EXPORT Fl_Image {
|
||||
int w_, h_, d_, ld_, count_;
|
||||
const char * const *data_;
|
||||
static Fl_RGB_Scaling RGB_scaling_;
|
||||
|
||||
// Forbid use of copy contructor and assign operator
|
||||
// Forbid use of copy constructor and assign operator
|
||||
Fl_Image & operator=(const Fl_Image &);
|
||||
Fl_Image(const Fl_Image &);
|
||||
|
||||
@ -152,15 +161,12 @@ class FL_EXPORT Fl_Image {
|
||||
*/
|
||||
void draw(int X, int Y) {draw(X, Y, w(), h(), 0, 0);} // platform dependent
|
||||
virtual void uncache();
|
||||
};
|
||||
|
||||
/** \enum Fl_RGB_Scaling
|
||||
The image-scaling algorithm to use.
|
||||
*/
|
||||
// set RGB image scaling method
|
||||
static void RGB_scaling(Fl_RGB_Scaling);
|
||||
|
||||
enum Fl_RGB_Scaling {
|
||||
FL_SCALING_NEAREST = 0, ///< default RGB image-scaling algorithm
|
||||
FL_SCALING_BILINEAR ///< alternative, slower and more accurate RGB image-scaling algorithm
|
||||
// get RGB image scaling method
|
||||
static Fl_RGB_Scaling RGB_scaling();
|
||||
};
|
||||
|
||||
/**
|
||||
@ -168,9 +174,9 @@ enum Fl_RGB_Scaling {
|
||||
of full-color images with 1 to 4 channels of color information.
|
||||
Images with an even number of channels are assumed to contain
|
||||
alpha information, which is used to blend the image with the
|
||||
contents of the screen.</P>
|
||||
contents of the screen.
|
||||
|
||||
<P>Fl_RGB_Image is defined in
|
||||
Fl_RGB_Image is defined in
|
||||
<FL/Fl_Image.H>, however for compatibility reasons
|
||||
<FL/Fl_RGB_Image.H> should be included.
|
||||
*/
|
||||
@ -179,7 +185,6 @@ class FL_EXPORT Fl_RGB_Image : public Fl_Image {
|
||||
friend class Fl_GDI_Graphics_Driver;
|
||||
friend class Fl_Xlib_Graphics_Driver;
|
||||
static size_t max_size_;
|
||||
static Fl_RGB_Scaling scaling_;
|
||||
public:
|
||||
|
||||
const uchar *array;
|
||||
@ -240,14 +245,6 @@ public:
|
||||
\sa void Fl_RGB_Image::max_size(size_t)
|
||||
*/
|
||||
static size_t max_size() {return max_size_;}
|
||||
|
||||
/** Sets the scaling method used for copy(int, int).
|
||||
Applies to all RGB images, defaults to FL_SCALING_NEAREST.
|
||||
*/
|
||||
static void scaling(Fl_RGB_Scaling);
|
||||
|
||||
/** Returns the currently used scaling method. */
|
||||
static Fl_RGB_Scaling scaling();
|
||||
};
|
||||
|
||||
#endif // !Fl_Image_H
|
||||
|
@ -162,6 +162,8 @@ int main(int argc, char **argv)
|
||||
clip_callback(1, tabs); // use clipboard content at start
|
||||
#endif
|
||||
Fl::add_clipboard_notify(clip_callback, tabs); // will update with new clipboard content immediately or at application activation
|
||||
|
||||
Fl_Image::RGB_scaling(FL_RGB_SCALING_BILINEAR); // set bilinear image scaling method
|
||||
return Fl::run();
|
||||
}
|
||||
|
||||
|
@ -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$".
|
||||
//
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user