mirror of
https://github.com/fltk/fltk.git
synced 2026-05-24 08:16:04 +08:00
After r.12653, it is also necessary to remove Fl_Cocoa_Window_Driver::bitmap_from_window_rect()
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12657 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
@@ -4248,80 +4248,6 @@ static NSBitmapImageRep* rect_to_NSBitmapImageRep(Fl_Window *win, int x, int y,
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
||||
unsigned char *Fl_Cocoa_Window_Driver::bitmap_from_window_rect(int x, int y, int w, int h, int *bytesPerPixel)
|
||||
/* Returns a capture of a rectangle of a mapped window as a pre-multiplied RGBA array of bytes.
|
||||
Alpha values are always 1 (except for the angles of a window title bar)
|
||||
so pre-multiplication can be ignored.
|
||||
*bytesPerPixel is set to the value 3 or 4 upon return.
|
||||
delete[] the returned pointer after use
|
||||
*/
|
||||
{
|
||||
Fl_Window *win = pWindow;
|
||||
NSBitmapImageRep *bitmap = rect_to_NSBitmapImageRep(win, x, y, w, h);
|
||||
if (bitmap == nil) return NULL;
|
||||
*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, and hh = 2*h with retina
|
||||
int ww = bpr/(*bytesPerPixel); // sometimes ww = w-1, and ww = 2*w with retina
|
||||
const uchar *start = [bitmap bitmapData]; // start of the bitmap data
|
||||
bool convert = false;
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
||||
if (fl_mac_os_version >= 100400 && ([bitmap bitmapFormat] & NSAlphaFirstBitmapFormat)) {
|
||||
// bitmap is ARGB --> convert it to RGBA (ARGB happens with Mac OS 10.11)
|
||||
// it is enough to offset reading by one byte because A is always 0xFF
|
||||
// so ARGBARGB becomes RGBARGBA as needed
|
||||
start++;
|
||||
convert = true;
|
||||
}
|
||||
#endif
|
||||
unsigned char *data;
|
||||
size_t tocopy;
|
||||
if (ww > w) { // with a retina display, we have to scale the image by a factor of 2
|
||||
uchar *data2 = [bitmap bitmapData];
|
||||
if (convert) { // duplicate the NSBitmapImageRep data taking care not to access beyond its end
|
||||
tocopy = ww*hh*4;
|
||||
data2 = new uchar[tocopy];
|
||||
memcpy(data2, start, --tocopy);
|
||||
data2[tocopy] = 0xFF; // set the last A byte
|
||||
}
|
||||
Fl_RGB_Image *rgb = new Fl_RGB_Image(data2, ww, hh, 4);
|
||||
rgb->alloc_array = (convert ? 1 : 0);
|
||||
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_Image::RGB_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) { // the NSBitmapImageRep data can be copied in one step
|
||||
tocopy = w * hh * (*bytesPerPixel);
|
||||
if (convert) { // take care not to access beyond the image end
|
||||
data[--tocopy] = 0xFF; // set the last A byte
|
||||
}
|
||||
memcpy(data, start, tocopy);
|
||||
} else { // copy the NSBitmapImageRep data line by line
|
||||
const uchar *p = start;
|
||||
unsigned char *q = data;
|
||||
tocopy = bpr;
|
||||
for (int i = 0; i < hh; i++) {
|
||||
if (i == hh-1 && convert) tocopy--; // take care not to access beyond the image end
|
||||
memcpy(q, p, tocopy);
|
||||
p += bpr;
|
||||
q += w * (*bytesPerPixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
[bitmap release];
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
static void nsbitmapProviderReleaseData (void *info, const void *data, size_t size)
|
||||
{
|
||||
[(NSBitmapImageRep*)info release];
|
||||
|
||||
Reference in New Issue
Block a user