Fixed fl_copy_offscreen when output goes to a Quartz printer context.

Output to a PostScript context still needs to be fixed.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7665 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2010-07-03 10:13:22 +00:00
parent 3e52876736
commit c835c08bb3

View File

@ -188,6 +188,13 @@ Fl_Offscreen fl_create_offscreen_with_alpha(int w, int h) {
return (Fl_Offscreen)ctx;
}
static void bmProviderRelease (void *src, const void *data, size_t size)
{
CFIndex count = CFGetRetainCount(src);
CFRelease(src);
if(count == 1) free((void*)data);
}
void fl_copy_offscreen(int x,int y,int w,int h,Fl_Offscreen osrc,int srcx,int srcy) {
CGContextRef src = (CGContextRef)osrc;
void *data = CGBitmapContextGetData(src);
@ -195,7 +202,10 @@ void fl_copy_offscreen(int x,int y,int w,int h,Fl_Offscreen osrc,int srcx,int sr
int sh = CGBitmapContextGetHeight(src);
CGImageAlphaInfo alpha = CGBitmapContextGetAlphaInfo(src);
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
CGDataProviderRef src_bytes = CGDataProviderCreateWithData( 0L, data, sw*sh*4, 0L);
// when output goes to a Quartz printercontext, release of the bitmap must be
// delayed after the end of the print page
CFRetain(src);
CGDataProviderRef src_bytes = CGDataProviderCreateWithData( src, data, sw*sh*4, bmProviderRelease);
CGImageRef img = CGImageCreate( sw, sh, 8, 4*8, 4*sw, lut, alpha,
src_bytes, 0L, false, kCGRenderingIntentDefault);
// fl_push_clip();
@ -211,9 +221,9 @@ void fl_copy_offscreen(int x,int y,int w,int h,Fl_Offscreen osrc,int srcx,int sr
void fl_delete_offscreen(Fl_Offscreen ctx) {
if (!ctx) return;
void *data = CGBitmapContextGetData((CGContextRef)ctx);
CFIndex count = CFGetRetainCount(ctx);
CGContextRelease((CGContextRef)ctx);
if (!data) return;
free(data);
if(count == 1) free(data);
}
const int stack_max = 16;