summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2014-10-11 13:43:06 +0000
committerManolo Gouy <Manolo>2014-10-11 13:43:06 +0000
commit6232a298f38bf77fa7cc4983b20dd43ad68a18c0 (patch)
treeb4ac7050119e031ff6838e20cb2919326449f4c3 /src
parent982e6ffb2c9a21ccde85e477d98e5cfae43044cd (diff)
Fixed errors in fl_read_image() and Fl_Paged_Device::print_window_part()
when using Apple computers with retina displays. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10371 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_cocoa.mm38
1 files changed, 26 insertions, 12 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index 134a677f4..1c76831f1 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -3852,19 +3852,33 @@ unsigned char *Fl_X::bitmap_from_window_rect(Fl_Window *win, int x, int y, int w
*bytesPerPixel = [bitmap bitsPerPixel]/8;
int bpp = (int)[bitmap bytesPerPlane];
int bpr = (int)[bitmap bytesPerRow];
- int hh = bpp/bpr; // sometimes hh = h-1 for unclear reason
- int ww = bpr/(*bytesPerPixel); // sometimes ww = w-1
- unsigned char *data = new unsigned char[w * h * *bytesPerPixel];
- if (w == ww) {
- memcpy(data, [bitmap bitmapData], w * hh * *bytesPerPixel);
- } else {
- unsigned char *p = [bitmap bitmapData];
- unsigned char *q = data;
- for(int i = 0;i < hh; i++) {
- memcpy(q, p, *bytesPerPixel * ww);
- p += bpr;
- q += w * *bytesPerPixel;
+ int hh = bpp/bpr; // sometimes hh = h-1 for unclear reason, and hh = 2*h with retina
+ int ww = bpr/(*bytesPerPixel); // sometimes ww = w-1, and ww = 2*w with retina
+ 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_Image *rgb2 = (Fl_RGB_Image*)rgb->copy(w, h);
+ Fl_RGB_Image::scaling(save_scaling);
+ delete rgb;
+ rgb2->alloc_array = 0;
+ data = (uchar*)rgb2->array;
+ delete rgb2;
+ }
+ else {
+ data = new unsigned char[w * h * *bytesPerPixel];
+ if (w == ww) {
+ memcpy(data, [bitmap bitmapData], w * hh * *bytesPerPixel);
+ } else {
+ unsigned char *p = [bitmap bitmapData];
+ unsigned char *q = data;
+ for(int i = 0;i < hh; i++) {
+ memcpy(q, p, *bytesPerPixel * ww);
+ p += bpr;
+ q += w * *bytesPerPixel;
}
+ }
}
return data;
}