summaryrefslogtreecommitdiffstats
path: root/macosx
diff options
context:
space:
mode:
authorculler <culler>2018-11-07 21:17:25 (GMT)
committerculler <culler>2018-11-07 21:17:25 (GMT)
commit6a78e0b7fc7c69f35442f490812e5265db8e8470 (patch)
tree86af0c57abcf76c8e38e1e180055bed0a93187e8 /macosx
parent52bdce0ef2fe1a7ad9884d739ccab438740b4db1 (diff)
downloadtk-6a78e0b7fc7c69f35442f490812e5265db8e8470.zip
tk-6a78e0b7fc7c69f35442f490812e5265db8e8470.tar.gz
tk-6a78e0b7fc7c69f35442f490812e5265db8e8470.tar.bz2
Fix two image bugs. BitmapImageReps may have bytesPerRow > 4*width. Do not copy
from a window to a bitmap if the contentView does not have a valid graphics context.
Diffstat (limited to 'macosx')
-rw-r--r--macosx/tkMacOSXDraw.c22
-rw-r--r--macosx/tkMacOSXImage.c6
2 files changed, 22 insertions, 6 deletions
diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c
index 42c9059..bff2f93 100644
--- a/macosx/tkMacOSXDraw.c
+++ b/macosx/tkMacOSXDraw.c
@@ -155,16 +155,32 @@ TkMacOSXBitmapRepFromDrawableRect(
CGImageRelease(cg_image);
}
} else if ( (view = TkMacOSXDrawableView(mac_drawable)) ) {
+
/*
* Convert Tk top-left to NSView bottom-left coordinates.
*/
+
int view_height = [view bounds].size.height;
NSRect view_rect = NSMakeRect(x + mac_drawable->xOff,
view_height - height - y - mac_drawable->yOff,
width, height);
- bitmap_rep = [view bitmapImageRepForCachingDisplayInRect: view_rect];
- [bitmap_rep retain];
- [view cacheDisplayInRect:view_rect toBitmapImageRep:bitmap_rep];
+
+ /*
+ * Attempt to copy from the view to a bitmapImageRep. If the view does
+ * not have a valid CGContext, doing this will silently corrupt memory
+ * and make a big mess. So, in that case, we mark the view as needing
+ * display and return NULL.
+ */
+
+ if (view == [NSView focusView]) {
+ bitmap_rep = [view bitmapImageRepForCachingDisplayInRect: view_rect];
+ [bitmap_rep retain];
+ [view cacheDisplayInRect:view_rect toBitmapImageRep:bitmap_rep];
+ } else {
+ TkMacOSXDbgMsg("No CGContext - cannot copy from screen to bitmap.");
+ [view setNeedsDisplay:YES];
+ return NULL;
+ }
} else {
TkMacOSXDbgMsg("Invalid source drawable");
}
diff --git a/macosx/tkMacOSXImage.c b/macosx/tkMacOSXImage.c
index 096faac..861b7ab 100644
--- a/macosx/tkMacOSXImage.c
+++ b/macosx/tkMacOSXImage.c
@@ -206,7 +206,7 @@ XGetImage(
(bitmap_fmt != 0 && bitmap_fmt != 1) ||
[bitmap_rep samplesPerPixel] != 4 ||
[bitmap_rep isPlanar] != 0 ||
- bytes_per_row != 4 * scaled_width ||
+ bytes_per_row < 4 * scaled_width ||
size != bytes_per_row*scaled_height ) {
TkMacOSXDbgMsg("XGetImage: Unrecognized bitmap format");
CFRelease(bitmap_rep);
@@ -237,8 +237,8 @@ XGetImage(
*/
struct pixel_fmt pixel = bitmap_fmt == 0 ? bgra : abgr;
- for (row=0, n=0; row<scaled_height; row++, n+=bytes_per_row) {
- for (m=n; m<n+bytes_per_row; m+=4) {
+ for (row = 0, n = 0; row < scaled_height; row++, n += bytes_per_row) {
+ for (m = n; m < n + 4*scaled_width; m += 4) {
R = *(bitmap + m + pixel.r);
G = *(bitmap + m + pixel.g);
B = *(bitmap + m + pixel.b);