Rename Fl_Image::pixel_w() and pixel_h() to Fl_Image::data_w() and data_h().

The docs of class Fl_Image and of Fl_Image::scale() are beefed up.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12784 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2018-03-22 16:38:38 +00:00
parent 0b8116ff72
commit 9f9631e685
10 changed files with 119 additions and 106 deletions

View File

@ -19,10 +19,10 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2017
- (add new items here)
- New member function Fl_Image::scale(int width, int height) to set
the drawing size of an image independently from its pixel size. The
the drawing size of an image independently from its data size. The
same function was previously available only for class Fl_Shared_Image
and with FL_ABI_VERSION >= 10304. New member functions Fl_Image::pixel_w()
and Fl_Image::pixel_h() give the size in pixels of an image.
and with FL_ABI_VERSION >= 10304. New member functions Fl_Image::data_w()
and Fl_Image::data_h() give the width and height of the image data.
- OpenGL draws text using textures on all platforms, when the necessary
hardware support is present (a backup mechanism is available in absence
of this support). Thus, all text drawable in Fl_Window's can be drawn

View File

@ -49,6 +49,13 @@ enum Fl_RGB_Scaling {
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.
Each image possesses two (width, height) pairs. 1) The width and height of the
image raw data are returned by data_w() and data_h(). These values are set
when the image is created and remain unchanged. 2) The width and height
of the area filled by the image when it gets drawn are returned by w() and h().
The values are equal to data_w() and data_h() when the image is created,
and can be changed by the scale() member function.
Since the Fl_Image class does not support image
drawing by itself, calling the draw() method results in
@ -63,7 +70,7 @@ public:
private:
int w_, h_, d_, ld_, count_;
int pixel_w_, pixel_h_;
int data_w_, data_h_;
const char * const *data_;
static Fl_RGB_Scaling RGB_scaling_; // method used when copying RGB images
static Fl_RGB_Scaling scaling_algorithm_; // method used to rescale RGB source images before drawing
@ -74,13 +81,13 @@ private:
protected:
/**
Sets the current image width in pixels.
Sets the width of the image data.
*/
void w(int W) {w_ = W; pixel_w_ = W;}
void w(int W) {w_ = W; data_w_ = W;}
/**
Sets the current image height in pixels.
Sets the height of the image data.
*/
void h(int H) {h_ = H; pixel_h_ = H;}
void h(int H) {h_ = H; data_h_ = H;}
/**
Sets the current image depth.
*/
@ -111,24 +118,24 @@ public:
/**
Returns the current image width in FLTK units.
The values of w() and pixel_w() are identical unless scale() has been called
The values of w() and data_w() are identical unless scale() has been called
after which they may differ.
*/
int w() const {return w_;}
/**
Returns the current image height in FLTK units.
The values of h() and pixel_h() are identical unless scale() has been called
The values of h() and data_h() are identical unless scale() has been called
after which they may differ.
*/
int h() const {return h_;}
/**
Returns the image width in pixels.
Returns the width of the image data.
*/
int pixel_w() {return pixel_w_;}
int data_w() const {return data_w_;}
/**
Returns the image height in pixels.
Returns the height of the image data.
*/
int pixel_h() {return pixel_h_;}
int data_h() const {return data_h_;}
/**
Returns the current image depth.
The return value will be 0 for bitmaps, 1 for

View File

@ -158,7 +158,7 @@ Fl_Image *Fl_Bitmap::copy(int W, int H) {
uchar *new_array; // New array for image data
// Optimize the simple copy where the width and height are the same...
if (W == pixel_w() && H == pixel_h()) {
if (W == data_w() && H == data_h()) {
new_array = new uchar [H * ((W + 7) / 8)];
memcpy(new_array, array, H * ((W + 7) / 8));
@ -182,10 +182,10 @@ Fl_Image *Fl_Bitmap::copy(int W, int H) {
// Figure out Bresenham step/modulus values...
xmod = pixel_w() % W;
xstep = pixel_w() / W;
ymod = pixel_h() % H;
ystep = pixel_h() / H;
xmod = data_w() % W;
xstep = data_w() / W;
ymod = data_h() % H;
ystep = data_h() / H;
// Allocate memory for the new image...
new_array = new uchar [H * ((W + 7) / 8)];
@ -196,7 +196,7 @@ Fl_Image *Fl_Bitmap::copy(int W, int H) {
// 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 * ((pixel_w() + 7) / 8), sx = 0, new_bit = 1;
for (dx = W, xerr = W, old_ptr = array + sy * ((data_w() + 7) / 8), sx = 0, new_bit = 1;
dx > 0;
dx --) {
old_bit = (uchar)(1 << (sx & 7));

View File

@ -332,7 +332,7 @@ void Fl_Scalable_Graphics_Driver::draw(Fl_Pixmap *pxm, int XP, int YP, int WP, i
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->pixel_w() != w2 || pxm->pixel_h() != h2) { // build a scaled id_ & pixmap_ for pxm
if (pxm->data_w() != w2 || pxm->data_h() != h2) { // build a scaled id_ & pixmap_ for pxm
Fl_Pixmap *pxm2 = (Fl_Pixmap*)pxm->copy(w2, h2);
*id(pxm) = cache(pxm2);
*cache_scale(pxm) = scale_;
@ -357,7 +357,7 @@ void Fl_Scalable_Graphics_Driver::draw(Fl_Bitmap *bm, int XP, int YP, int WP, in
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->pixel_w() != w2 || bm->pixel_h() != h2) { // build a scaled id_ for bm
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_;
@ -378,8 +378,8 @@ void Fl_Scalable_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP
if (start_image(img, XP, YP, WP, HP, cx, cy, XP, YP, WP, HP)) {
return;
}
int need_scaled_drawing = fabs(img->w() - img->pixel_w()/scale_)/img->w() > 0.05 ||
fabs(img->h() - img->pixel_h()/scale_)/img->h() > 0.05;
int need_scaled_drawing = fabs(img->w() - img->data_w()/scale_)/img->w() > 0.05 ||
fabs(img->h() - img->data_h()/scale_)/img->h() > 0.05;
if (need_scaled_drawing && can_do_alpha_blending()) { // try and use the system's scaled image drawing
push_clip(XP, YP, WP, HP);
int done = draw_scaled(img, XP-cx, YP-cy, img->w(), img->h());

View File

@ -42,7 +42,7 @@ Fl_RGB_Scaling Fl_Image::scaling_algorithm_ = FL_RGB_SCALING_BILINEAR;
1 to 4 for color images.
*/
Fl_Image::Fl_Image(int W, int H, int D) :
w_(W), h_(H), d_(D), ld_(0), count_(0), pixel_w_(W), pixel_h_(H), data_(0L)
w_(W), h_(H), d_(D), ld_(0), count_(0), data_w_(W), data_h_(H), data_(0L)
{}
/**
@ -234,39 +234,45 @@ Fl_RGB_Scaling Fl_Image::RGB_scaling() {
}
/** Sets the drawing size of the image.
This function gives the image its own drawing size, independently from its pixel size.
This can be useful to draw an image on a drawing surface with more than 1 pixel per
FLTK unit: all pixels of the original image become available to fill an area of the drawing surface
sized at <tt>width,height</tt> FLTK units.
This function controls the values returned by member functions w() and h()
which in turn control how the image is drawn: the full image data (whose size
is given by data_w() and data_h()) are drawn scaled
to an area of the drawing surface sized at w() x h() FLTK units.
This can make a difference if the drawing surface has more than 1 pixel per
FLTK unit because the image can be drawn at the full resolution of the drawing surface.
Examples of such drawing surfaces: HiDPI displays, laser printers, PostScript files, PDF printers.
\param width,height maximum width and height (in FLTK units) to use when drawing the image
\param proportional if not null, keep the width and height of the image proportional to those of the original size
\param can_expand if null, the width and height of the image will not exceed those of the original size
\note This function may change the values returned by the w() and h() member functions. In contrast,
the values returned by pixel_w() and pixel_h() remain unchanged after scale() was called.
\param width,height maximum values, in FLTK units, that w() and h() should return
\param proportional if not null, keep the values returned by w() and h() proportional to
data_w() and data_h()
\param can_expand if null, the values returned by w() and h() will not be larger than
data_w() and data_h(), respectively
\note This function generally changes the values returned by the w() and h() member functions.
In contrast, the values returned by data_w() and data_h() remain unchanged.
\version 1.4 (1.3.4 and FL_ABI_VERSION for Fl_Shared_Image only)
Example code: scale an image to fit in a box
\code
Fl_Box *b = ... // a box
Fl_Image *img = Fl_Shared_Image::get("/path/to/picture.jpeg"); // read a picture file
img->scale(b->w(), b->h()); // set the drawing size of the image to the size of the box
Fl_Image *img = new Fl_PNG_Image("/path/to/picture.png"); // read a picture file
// set the drawing size of the image to the size of the box keeping its aspect ratio
img->scale(b->w(), b->h());
b->image(img); // use the image as the box image
b->align(FL_ALIGN_INSIDE | FL_ALIGN_CENTER | FL_ALIGN_CLIP); // the image is to be drawn centered in the box
// the image is to be drawn centered in the box
b->align(FL_ALIGN_INSIDE | FL_ALIGN_CENTER | FL_ALIGN_CLIP);
\endcode
*/
void Fl_Image::scale(int width, int height, int proportional, int can_expand)
{
if ((width <= pixel_w() && height <= pixel_h()) || can_expand) {
if ((width <= data_w() && height <= data_h()) || can_expand) {
w_ = width;
h_ = height;
}
if (fail()) return;
if (!proportional && can_expand) return;
if (!proportional && width <= pixel_w() && height <= pixel_h()) return;
float fw = pixel_w() / float(width);
float fh = pixel_h() / float(height);
if (!proportional && width <= data_w() && height <= data_h()) return;
float fw = data_w() / float(width);
float fh = data_h() / float(height);
if (proportional) {
if (fh > fw) fw = fh;
else fh = fw;
@ -275,8 +281,8 @@ void Fl_Image::scale(int width, int height, int proportional, int can_expand)
if (fw < 1) fw = 1;
if (fh < 1) fh = 1;
}
w_ = int(pixel_w() / fw);
h_ = int(pixel_h() / fh);
w_ = int(data_w() / fw);
h_ = int(data_h() / fh);
}
/** Draw the image to the current drawing surface rescaled to a given width and height.
@ -397,29 +403,29 @@ Fl_Image *Fl_RGB_Image::copy(int W, int H) {
// Optimize the simple copy where the width and height are the same,
// or when we are copying an empty image...
if ((W == pixel_w() && H == pixel_h()) ||
if ((W == data_w() && H == data_h()) ||
!w() || !h() || !d() || !array) {
if (array) {
// Make a copy of the image data and return a new Fl_RGB_Image...
new_array = new uchar[pixel_w() * pixel_h() * d()];
if (ld() && ld()!=pixel_w()*d()) {
new_array = new uchar[data_w() * data_h() * d()];
if (ld() && ld()!=data_w()*d()) {
const uchar *src = array;
uchar *dst = new_array;
int dy, dh = h(), wd = pixel_w()*d(), wld = ld();
int dy, dh = h(), wd = data_w()*d(), wld = ld();
for (dy=0; dy<dh; dy++) {
memcpy(dst, src, wd);
src += wld;
dst += wd;
}
} else {
memcpy(new_array, array, pixel_w() * pixel_h() * d());
memcpy(new_array, array, data_w() * data_h() * d());
}
new_image = new Fl_RGB_Image(new_array, pixel_w(), pixel_h(), d());
new_image = new Fl_RGB_Image(new_array, data_w(), data_h(), d());
new_image->alloc_array = 1;
return new_image;
} else {
return new Fl_RGB_Image(array, pixel_w(), pixel_h(), d(), ld());
return new Fl_RGB_Image(array, data_w(), data_h(), d(), ld());
}
}
if (W <= 0 || H <= 0) return 0;
@ -435,7 +441,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;
line_d = ld() ? ld() : pixel_w() * d();
line_d = ld() ? ld() : data_w() * d();
if (Fl_Image::RGB_scaling() == FL_RGB_SCALING_NEAREST) {
@ -446,10 +452,10 @@ Fl_Image *Fl_RGB_Image::copy(int W, int H) {
xstep, ystep; // X & Y step increments
// Figure out Bresenham step/modulus values...
xmod = pixel_w() % W;
xstep = (pixel_w() / W) * d();
ymod = pixel_h() % H;
ystep = pixel_h() / H;
xmod = data_w() % W;
xstep = (data_w() / W) * d();
ymod = data_h() % H;
ystep = data_h() / H;
// Scale the image using a nearest-neighbor algorithm...
for (dy = H, sy = 0, yerr = H, new_ptr = new_array; dy > 0; dy --) {
@ -474,28 +480,28 @@ Fl_Image *Fl_RGB_Image::copy(int W, int H) {
}
} else {
// Bilinear scaling (FL_RGB_SCALING_BILINEAR)
const float xscale = (pixel_w() - 1) / (float) W;
const float yscale = (pixel_h() - 1) / (float) H;
const float xscale = (data_w() - 1) / (float) W;
const float yscale = (data_h() - 1) / (float) H;
for (dy = 0; dy < H; dy++) {
float oldy = dy * yscale;
if (oldy >= pixel_h())
oldy = float(pixel_h() - 1);
if (oldy >= data_h())
oldy = float(data_h() - 1);
const float yfract = oldy - (unsigned) oldy;
for (dx = 0; dx < W; dx++) {
new_ptr = new_array + dy * W * d() + dx * d();
float oldx = dx * xscale;
if (oldx >= pixel_w())
oldx = float(pixel_w() - 1);
if (oldx >= data_w())
oldx = float(data_w() - 1);
const float xfract = oldx - (unsigned) oldx;
const unsigned leftx = (unsigned)oldx;
const unsigned lefty = (unsigned)oldy;
const unsigned rightx = (unsigned)(oldx + 1 >= pixel_w() ? oldx : oldx + 1);
const unsigned rightx = (unsigned)(oldx + 1 >= data_w() ? oldx : oldx + 1);
const unsigned righty = (unsigned)oldy;
const unsigned dleftx = (unsigned)oldx;
const unsigned dlefty = (unsigned)(oldy + 1 >= pixel_h() ? oldy : oldy + 1);
const unsigned dlefty = (unsigned)(oldy + 1 >= data_h() ? oldy : oldy + 1);
const unsigned drightx = (unsigned)rightx;
const unsigned drighty = (unsigned)dlefty;

View File

@ -153,7 +153,7 @@ Fl_Image *Fl_Pixmap::copy(int W, int H) {
return new Fl_Pixmap((char *const*)0);
}
// Optimize the simple copy where the width and height are the same...
if (W == pixel_w() && H == pixel_h()) {
if (W == data_w() && H == data_h()) {
// Make an exact copy of the image and return it...
new_image = new Fl_Pixmap(data());
new_image->copy_data();
@ -185,10 +185,10 @@ Fl_Image *Fl_Pixmap::copy(int W, int H) {
sprintf(new_info, "%d %d %d %d", W, H, ncolors, chars_per_pixel);
// Figure out Bresenham step/modulus values...
xmod = pixel_w() % W;
xstep = (pixel_w() / W) * chars_per_pixel;
ymod = pixel_h() % H;
ystep = pixel_h() / H;
xmod = data_w() % W;
xstep = (data_w() / W) * chars_per_pixel;
ymod = data_h() % H;
ystep = data_h() / H;
// Allocate memory for the new array...
if (ncolors < 0) new_data = new char *[H + 2];

View File

@ -463,7 +463,7 @@ void Fl_GDI_Printer_Graphics_Driver::draw_unscaled(Fl_Bitmap *bm, float s, int X
fl_end_offscreen(); // offscreen data is in tmp_id
SelectObject(tempdc, (HGDIOBJ)tmp_id); // use offscreen data
// draw it to printer context with background color as transparent
fl_TransparentBlt(gc_, X,Y,W,H, tempdc, cx, cy, bm->pixel_w(), bm->pixel_h(), RGB(r, g, b) );
fl_TransparentBlt(gc_, X,Y,W,H, tempdc, cx, cy, bm->data_w(), bm->data_h(), RGB(r, g, b) );
fl_delete_offscreen(tmp_id);
RestoreDC(tempdc, save);
DeleteDC(tempdc);
@ -472,14 +472,14 @@ void Fl_GDI_Printer_Graphics_Driver::draw_unscaled(Fl_Bitmap *bm, float s, int X
static Fl_Offscreen build_id(Fl_RGB_Image *img, void **pmask)
{
Fl_Image_Surface *surface = new Fl_Image_Surface(img->pixel_w(), img->pixel_h());
Fl_Image_Surface *surface = new Fl_Image_Surface(img->data_w(), img->data_h());
Fl_Surface_Device::push_current(surface);
if ((img->d() == 2 || img->d() == 4) && fl_can_do_alpha_blending()) {
fl_draw_image(img->array, 0, 0, img->pixel_w(), img->pixel_h(), img->d()|FL_IMAGE_WITH_ALPHA, img->ld());
fl_draw_image(img->array, 0, 0, img->data_w(), img->data_h(), img->d()|FL_IMAGE_WITH_ALPHA, img->ld());
} else {
fl_draw_image(img->array, 0, 0, img->pixel_w(), img->pixel_h(), img->d(), img->ld());
fl_draw_image(img->array, 0, 0, img->data_w(), img->data_h(), img->d(), img->ld());
if (img->d() == 2 || img->d() == 4) {
*pmask = fl_create_alphamask(img->pixel_w(), img->pixel_h(), img->d(), img->ld(), img->array);
*pmask = fl_create_alphamask(img->data_w(), img->data_h(), img->d(), img->ld(), img->array);
}
}
Fl_Surface_Device::pop_current();
@ -494,8 +494,8 @@ void Fl_GDI_Graphics_Driver::draw_unscaled(Fl_RGB_Image *img, float s, int X, in
Y = Y*s;
cache_size(img, W, H);
cx *= s; cy *= s;
if (W + cx > img->pixel_w()) W = img->pixel_w() - cx;
if (H + cy > img->pixel_h()) H = img->pixel_h() - cy;
if (W + cx > img->data_w()) W = img->data_w() - cx;
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;
@ -521,13 +521,13 @@ void Fl_GDI_Graphics_Driver::draw_unscaled(Fl_RGB_Image *img, float s, int X, in
int Fl_GDI_Printer_Graphics_Driver::draw_scaled(Fl_Image *img, int XP, int YP, int WP, int HP) {
XFORM old_tr, tr;
GetWorldTransform(gc_, &old_tr); // storing old transform
tr.eM11 = float(WP)/float(img->pixel_w());
tr.eM22 = float(HP)/float(img->pixel_h());
tr.eM11 = float(WP)/float(img->data_w());
tr.eM22 = float(HP)/float(img->data_h());
tr.eM12 = tr.eM21 = 0;
tr.eDx = float(XP);
tr.eDy = float(YP);
ModifyWorldTransform(gc_, &tr, MWT_LEFTMULTIPLY);
img->draw(0, 0, img->pixel_w(), img->pixel_h(), 0, 0);
img->draw(0, 0, img->data_w(), img->data_h(), 0, 0);
SetWorldTransform(gc_, &old_tr);
return 1;
}
@ -548,10 +548,10 @@ int Fl_GDI_Graphics_Driver::draw_scaled(Fl_Image *img, int XP, int YP, int WP, i
int save = SaveDC(new_gc);
SelectObject(new_gc, (HBITMAP)*Fl_Graphics_Driver::id(rgb));
if ( (rgb->d() % 2) == 0 ) {
alpha_blend_(XP*scale_, YP*scale_, WP, HP, new_gc, 0, 0, rgb->pixel_w(), rgb->pixel_h());
alpha_blend_(XP*scale_, YP*scale_, WP, HP, new_gc, 0, 0, rgb->data_w(), rgb->data_h());
} else {
SetStretchBltMode(gc_, HALFTONE);
StretchBlt(gc_, XP*scale_, YP*scale_, WP, HP, new_gc, 0, 0, rgb->pixel_w(), rgb->pixel_h(), SRCCOPY);
StretchBlt(gc_, XP*scale_, YP*scale_, WP, HP, new_gc, 0, 0, rgb->data_w(), rgb->data_h(), SRCCOPY);
}
RestoreDC(new_gc, save);
DeleteDC(new_gc);
@ -601,7 +601,7 @@ 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();
return (fl_uintptr_t)fl_create_bitmap(bm->pixel_w(), bm->pixel_h(), bm->array);
return (fl_uintptr_t)fl_create_bitmap(bm->data_w(), bm->data_h(), bm->array);
}
void Fl_GDI_Graphics_Driver::draw_unscaled(Fl_Pixmap *pxm, float s, int X, int Y, int W, int H, int cx, int cy) {
@ -646,7 +646,7 @@ void Fl_GDI_Printer_Graphics_Driver::draw_unscaled(Fl_Pixmap *pxm, float s, int
fl_uintptr_t Fl_GDI_Graphics_Driver::cache(Fl_Pixmap *img) {
Fl_Image_Surface *surf = new Fl_Image_Surface(img->pixel_w(), img->pixel_h());
Fl_Image_Surface *surf = new Fl_Image_Surface(img->data_w(), img->data_h());
Fl_Surface_Device::push_current(surf);
uchar *bitmap = 0;
Fl_Surface_Device::surface()->driver()->mask_bitmap(&bitmap);
@ -654,7 +654,7 @@ fl_uintptr_t Fl_GDI_Graphics_Driver::cache(Fl_Pixmap *img) {
*Fl_Graphics_Driver::pixmap_bg_color(img) = Fl_WinAPI_System_Driver::win_pixmap_bg_color; // computed by fl_draw_pixmap()
Fl_Surface_Device::surface()->driver()->mask_bitmap(0);
if (bitmap) {
*Fl_Graphics_Driver::mask(img) = (fl_uintptr_t)fl_create_bitmask(img->pixel_w(), img->pixel_h(), bitmap);
*Fl_Graphics_Driver::mask(img) = (fl_uintptr_t)fl_create_bitmask(img->data_w(), img->data_h(), bitmap);
delete[] bitmap;
}
Fl_Surface_Device::pop_current();

View File

@ -574,7 +574,7 @@ void Fl_PostScript_Graphics_Driver::draw_image_mono(Fl_Draw_Image_Cb call, void
void Fl_PostScript_Graphics_Driver::draw(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy){
int need_clip = cx || cy || WP != pxm->w() || HP != pxm->h();
if (need_clip) push_clip(XP, YP, WP, HP);
if (pxm->w() != pxm->pixel_w() || pxm->h() != pxm->pixel_h()) {
if (pxm->w() != pxm->data_w() || pxm->h() != pxm->data_h()) {
draw_scaled(pxm, XP-cx, YP-cy, pxm->w(), pxm->h());
} else {
const char * const * di =pxm->data();
@ -596,7 +596,7 @@ void Fl_PostScript_Graphics_Driver::draw(Fl_RGB_Image * rgb,int XP, int YP, int
{
int need_clip = cx || cy || WP != rgb->w() || HP != rgb->h();
if (need_clip) push_clip(XP, YP, WP, HP);
if (rgb->w() != rgb->pixel_w() || rgb->h() != rgb->pixel_h()) {
if (rgb->w() != rgb->data_w() || rgb->h() != rgb->data_h()) {
draw_scaled(rgb, XP-cx, YP-cy, rgb->w(), rgb->h());
} else {
const uchar * di = rgb->array;
@ -618,10 +618,10 @@ int Fl_PostScript_Graphics_Driver::draw_scaled(Fl_Image *img, int XP, int YP, in
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)/img->pixel_w(), float(HP)/img->pixel_h());
clocale_printf("GS %d %d TR %f %f SC GS\n", XP, YP, float(WP)/img->data_w(), float(HP)/img->data_h());
int keep_w = img->w(), keep_h = img->h();
img->scale(img->pixel_w(), img->pixel_h(), 0, 1);
img->draw(0, 0, img->pixel_w(), img->pixel_h(), 0, 0);
img->scale(img->data_w(), img->data_h(), 0, 1);
img->draw(0, 0, img->data_w(), img->data_h(), 0, 0);
clocale_printf("GR GR\n");
img->scale(keep_w, keep_h, 0, 1);
pop_clip(); // restore FLTK's clip
@ -631,7 +631,7 @@ int Fl_PostScript_Graphics_Driver::draw_scaled(Fl_Image *img, int XP, int YP, in
void Fl_PostScript_Graphics_Driver::draw(Fl_Bitmap * bitmap,int XP, int YP, int WP, int HP, int cx, int cy) {
int need_clip = cx || cy || WP != bitmap->w() || HP != bitmap->h();
if (need_clip) push_clip(XP, YP, WP, HP);
if (bitmap->w() != bitmap->pixel_w() || bitmap->h() != bitmap->pixel_h()) {
if (bitmap->w() != bitmap->data_w() || bitmap->h() != bitmap->data_h()) {
draw_scaled(bitmap, XP-cx, YP-cy, bitmap->w(), bitmap->h());
} else {
const uchar * di = bitmap->array;

View File

@ -162,7 +162,7 @@ void Fl_Quartz_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP,
if (!cgimg) {
CGColorSpaceRef lut = img->d()<=2 ? CGColorSpaceCreateDeviceGray() : CGColorSpaceCreateDeviceRGB();
int ld = img->ld();
if (!ld) ld = img->pixel_w() * img->d();
if (!ld) ld = img->data_w() * img->d();
CGDataProviderRef src;
if ( has_feature(PRINTER) ) {
// When printing, the data at img->array are used when the printed page is completed,
@ -172,16 +172,16 @@ void Fl_Quartz_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP,
// is used to avoid repeating the copy operation if img is printed again.
// The CGImage data provider deletes the copy at the latest of these two events:
// deletion of img, and completion of the page where img was printed.
size_t total = ld * img->pixel_h();
size_t total = ld * img->data_h();
uchar *copy = new uchar[total];
memcpy(copy, img->array, total);
src = CGDataProviderCreateWithData(NULL, copy, total, dataReleaseCB);
*Fl_Graphics_Driver::mask(img) = 1;
} else {
// the CGImage data provider must not release the image data.
src = CGDataProviderCreateWithData(NULL, img->array, ld * img->pixel_h(), NULL);
src = CGDataProviderCreateWithData(NULL, img->array, ld * img->data_h(), NULL);
}
cgimg = CGImageCreate(img->pixel_w(), img->pixel_h(), 8, img->d()*8, ld,
cgimg = CGImageCreate(img->data_w(), img->data_h(), 8, img->d()*8, ld,
lut, (img->d()&1)?kCGImageAlphaNone:kCGImageAlphaLast,
src, 0L, false, kCGRenderingIntentDefault);
*Fl_Graphics_Driver::id(img) = (fl_uintptr_t)cgimg;
@ -230,7 +230,7 @@ void Fl_Quartz_Graphics_Driver::uncache(Fl_RGB_Image*, fl_uintptr_t &id_, fl_uin
}
fl_uintptr_t Fl_Quartz_Graphics_Driver::cache(Fl_Bitmap *bm) {
return (fl_uintptr_t)create_bitmask(bm->pixel_w(), bm->pixel_h(), bm->array);
return (fl_uintptr_t)create_bitmask(bm->data_w(), bm->data_h(), bm->array);
}
@ -239,7 +239,7 @@ static void pmProviderRelease (void *ctxt, const void *data, size_t size) {
}
fl_uintptr_t Fl_Quartz_Graphics_Driver::cache(Fl_Pixmap *img) {
Fl_Image_Surface *surf = new Fl_Image_Surface(img->pixel_w(), img->pixel_h());
Fl_Image_Surface *surf = new Fl_Image_Surface(img->data_w(), img->data_h());
Fl_Surface_Device::push_current(surf);
fl_draw_pixmap(img->data(), 0, 0, FL_BLACK);
CGContextRef src = surf->get_offscreen_before_delete();

View File

@ -643,7 +643,7 @@ void Fl_Xlib_Graphics_Driver::draw_unscaled(Fl_Bitmap *bm, float s, int X, int Y
// alpha compositing...
static void alpha_blend(Fl_RGB_Image *img, int X, int Y, int W, int H, int cx, int cy) {
int ld = img->ld();
if (ld == 0) ld = img->pixel_w() * img->d();
if (ld == 0) ld = img->data_w() * img->d();
uchar *srcptr = (uchar*)img->array + cy * ld + cx * img->d();
int srcskip = ld - img->d() * W;
@ -700,16 +700,16 @@ static Fl_Offscreen cache_rgb(Fl_RGB_Image *img) {
Fl_Image_Surface *surface;
int depth = img->d();
if (depth == 1 || depth == 3) {
surface = new Fl_Image_Surface(img->pixel_w(), img->pixel_h());
surface = new Fl_Image_Surface(img->data_w(), img->data_h());
} else if (fl_can_do_alpha_blending()) {
Fl_Offscreen pixmap = XCreatePixmap(fl_display, RootWindow(fl_display, fl_screen), img->pixel_w(), img->pixel_h(), 32);
surface = new Fl_Image_Surface(img->pixel_w(), img->pixel_h(), 0, pixmap);
Fl_Offscreen pixmap = XCreatePixmap(fl_display, RootWindow(fl_display, fl_screen), img->data_w(), img->data_h(), 32);
surface = new Fl_Image_Surface(img->data_w(), img->data_h(), 0, pixmap);
depth |= FL_IMAGE_WITH_ALPHA;
} else {
return 0;
}
Fl_Surface_Device::push_current(surface);
fl_draw_image(img->array, 0, 0, img->pixel_w(), img->pixel_h(), depth, img->ld());
fl_draw_image(img->array, 0, 0, img->data_w(), img->data_h(), depth, img->ld());
Fl_Surface_Device::pop_current();
Fl_Offscreen off = surface->get_offscreen_before_delete();
delete surface;
@ -724,8 +724,8 @@ void Fl_Xlib_Graphics_Driver::draw_unscaled(Fl_RGB_Image *img, float s, int X, i
Y = (Y+offset_y_)*s;
cache_size(img, W, H);
cx *= s; cy *= s;
if (W + cx > img->pixel_w()) W = img->pixel_w() - cx;
if (H + cy > img->pixel_h()) H = img->pixel_h() - cy;
if (W + cx > img->data_w()) W = img->data_w() - cx;
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;
@ -768,7 +768,7 @@ 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();
return (fl_uintptr_t)create_bitmask(bm->pixel_w(), bm->pixel_h(), bm->array);
return (fl_uintptr_t)create_bitmask(bm->data_w(), bm->data_h(), bm->array);
}
void Fl_Xlib_Graphics_Driver::draw_unscaled(Fl_Pixmap *pxm, float s, int X, int Y, int W, int H, int cx, int cy) {
@ -817,14 +817,14 @@ void Fl_Xlib_Graphics_Driver::draw_unscaled(Fl_Pixmap *pxm, float s, int X, int
fl_uintptr_t Fl_Xlib_Graphics_Driver::cache(Fl_Pixmap *pxm) {
Fl_Image_Surface *surf = new Fl_Image_Surface(pxm->pixel_w(), pxm->pixel_h());
Fl_Image_Surface *surf = new Fl_Image_Surface(pxm->data_w(), pxm->data_h());
Fl_Surface_Device::push_current(surf);
uchar *bitmap = 0;
Fl_Surface_Device::surface()->driver()->mask_bitmap(&bitmap);
fl_draw_pixmap(pxm->data(), 0, 0, FL_BLACK);
Fl_Surface_Device::surface()->driver()->mask_bitmap(0);
if (bitmap) {
*Fl_Graphics_Driver::mask(pxm) = (fl_uintptr_t)create_bitmask(pxm->pixel_w(), pxm->pixel_h(), bitmap);
*Fl_Graphics_Driver::mask(pxm) = (fl_uintptr_t)create_bitmask(pxm->data_w(), pxm->data_h(), bitmap);
delete[] bitmap;
}
Fl_Surface_Device::pop_current();
@ -885,7 +885,7 @@ int Fl_Xlib_Graphics_Driver::draw_scaled(Fl_Image *img, int XP, int YP, int WP,
}
cache_size(img, WP, HP);
return scale_and_render_pixmap( *Fl_Graphics_Driver::id(rgb), rgb->d(),
rgb->pixel_w() / double(WP), rgb->pixel_h() / double(HP), 0, 0, (XP + offset_x_)*scale_, (YP + offset_y_)*scale_, WP, HP);
rgb->data_w() / double(WP), rgb->data_h() / double(HP), 0, 0, (XP + offset_x_)*scale_, (YP + offset_y_)*scale_, WP, HP);
}
#endif // HAVE_XRENDER