mirror of
https://github.com/fltk/fltk.git
synced 2026-05-28 03:15:21 +08:00
Mac OS: make clear that image capture from screen returns an image in premultiplied RGBA format.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9723 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
+14
-9
@@ -3335,7 +3335,12 @@ static NSBitmapImageRep* rect_to_NSBitmapImageRep(Fl_Window *win, int x, int y,
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *Fl_X::bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel)
|
unsigned char *Fl_X::bitmap_from_window_rect(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel)
|
||||||
// delete[] the returned pointer after use
|
/* Returns a capture of part of a mapped window as a pre-multiplied RGBA array of bytes.
|
||||||
|
At present, alpha values are always 1 (or 0 for the angles of a window title bar)
|
||||||
|
because only opaque colors are used to draw, so pre-multiplication can be ignored.
|
||||||
|
*bytesPerPixel is always set to the value 4 upon return.
|
||||||
|
delete[] the returned pointer after use
|
||||||
|
*/
|
||||||
{
|
{
|
||||||
NSBitmapImageRep *bitmap = rect_to_NSBitmapImageRep(win, x, y, w, h);
|
NSBitmapImageRep *bitmap = rect_to_NSBitmapImageRep(win, x, y, w, h);
|
||||||
*bytesPerPixel = [bitmap bitsPerPixel]/8;
|
*bytesPerPixel = [bitmap bitsPerPixel]/8;
|
||||||
@@ -3380,7 +3385,7 @@ CGImageRef Fl_X::CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, i
|
|||||||
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
|
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
|
||||||
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, bitmap, w*h*bpp, imgProviderReleaseData);
|
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, bitmap, w*h*bpp, imgProviderReleaseData);
|
||||||
img = CGImageCreate(w, h, 8, 8*bpp, w*bpp, lut,
|
img = CGImageCreate(w, h, 8, 8*bpp, w*bpp, lut,
|
||||||
bpp == 3 ? kCGImageAlphaNone : kCGImageAlphaLast,
|
bpp == 3 ? kCGImageAlphaNone : kCGImageAlphaPremultipliedLast,
|
||||||
provider, NULL, false, kCGRenderingIntentDefault);
|
provider, NULL, false, kCGRenderingIntentDefault);
|
||||||
CGColorSpaceRelease(lut);
|
CGColorSpaceRelease(lut);
|
||||||
CGDataProviderRelease(provider);
|
CGDataProviderRelease(provider);
|
||||||
@@ -3434,14 +3439,14 @@ void Fl_Paged_Device::print_window(Fl_Window *win, int x_offset, int y_offset)
|
|||||||
Fl::check();
|
Fl::check();
|
||||||
win->make_current();
|
win->make_current();
|
||||||
this->set_current(); // back to the Fl_Paged_Device
|
this->set_current(); // back to the Fl_Paged_Device
|
||||||
int bpp;
|
// capture the window title bar
|
||||||
// capture the window title bar as an RGBA image
|
CGImageRef img = Fl_X::CGImage_from_window_rect(win, 0, -bt, win->w(), bt);
|
||||||
unsigned char *top_image = Fl_X::bitmap_from_window_rect(win, 0, -bt, win->w(), bt, &bpp);
|
|
||||||
Fl_RGB_Image* rgba = new Fl_RGB_Image(top_image, win->w(), bt, bpp);
|
|
||||||
// and print it
|
// and print it
|
||||||
rgba->draw(x_offset, y_offset);
|
CGRect rect = { { x_offset, y_offset }, { win->w(), bt } };
|
||||||
delete rgba;
|
Fl_X::q_begin_image(rect, 0, 0, win->w(), bt);
|
||||||
delete[] top_image;
|
CGContextDrawImage(fl_gc, rect, img);
|
||||||
|
Fl_X::q_end_image();
|
||||||
|
CFRelease(img);
|
||||||
this->print_widget(win, x_offset, y_offset + bt); // print the window inner part
|
this->print_widget(win, x_offset, y_offset + bt); // print the window inner part
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user