FLTK logo

[master] fa49d29 - macOS: fix paste of image for macOS 11.x

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] fa49d29 - macOS: fix paste of image for macOS 11.x "ManoloFLTK" Aug 03, 2021  
 
commit fa49d29ec863f6a9a24d8f58099f94628922609e
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Tue Aug 3 18:08:23 2021 +0200
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Tue Aug 3 18:08:33 2021 +0200

    macOS: fix paste of image for macOS 11.x
    
    With macOS 11.x, the pasteboard image can be found with floating point pixel values.
    This changes makes FLTK process adequately such image data.

 src/Fl_cocoa.mm | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git src/Fl_cocoa.mm src/Fl_cocoa.mm
index d7d8158..d57de05 100644
--- src/Fl_cocoa.mm
+++ src/Fl_cocoa.mm
@@ -76,6 +76,7 @@ static NSBitmapImageRep* rect_to_NSBitmapImageRep_subwins(Fl_Window *win, int x,
 static void drain_dropped_files_list(void);
 static NSPoint FLTKtoCocoa(Fl_Window *win, int x, int y, int H);
 static int get_window_frame_sizes(Fl_Window *win, int *pbx = NULL, int *pby = NULL);
+static NSBitmapImageRep *scale_nsbitmapimagerep(NSBitmapImageRep *img, float scale);
 
 int fl_mac_os_version = Fl_Darwin_System_Driver::calc_mac_os_version();         // the version number of the running Mac OS X (e.g., 100604 for 10.6.4)
 
@@ -106,6 +107,9 @@ static bool in_nsapp_run = false; // true during execution of [NSApp run]
 static NSMutableArray *dropped_files_list = nil; // list of files dropped at app launch
 typedef void (*open_cb_f_type)(const char *);
 static Fl_Window *starting_moved_window = NULL; // the moved window which brings its subwins with it
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 && MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12
+#  define NSBitmapFormatFloatingPointSamples NSFloatingPointSamplesBitmapFormat
+#endif
 
 #if CONSOLIDATE_MOTION
 static Fl_Window* send_motion;
@@ -3602,6 +3606,12 @@ static Fl_RGB_Image* get_image_from_clipboard(Fl_Widget *receiver)
     [nsimg release];
   }
   if (!bitmap) return NULL;
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
+  if (fl_mac_os_version >= 100400 && ([bitmap bitmapFormat] & NSBitmapFormatFloatingPointSamples)) {
+    // this may happen with macOS â?¥ 11.x
+    bitmap = scale_nsbitmapimagerep(bitmap, 1); // transform from floating point to integer pixel values
+  }
+#endif
   int bytesPerPixel([bitmap bitsPerPixel]/8);
   int bpr([bitmap bytesPerRow]);
   int hh([bitmap pixelsHigh]);
@@ -4118,7 +4128,7 @@ int Fl_Cocoa_Screen_Driver::dnd(int use_selection)
   return true;
 }
 
-// rescales an NSBitmapImageRep
+// rescales an NSBitmapImageRep (and also rewrites it with integer pixels)
 static NSBitmapImageRep *scale_nsbitmapimagerep(NSBitmapImageRep *img, float scale)
 {
   int w = [img pixelsWide];
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.