Skip to content

Fix-Macos TIFF #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions clipboard_darwin.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,28 @@ unsigned int clipboard_read_string(void **out) {
}

unsigned int clipboard_read_image(void **out) {
NSPasteboard * pasteboard = [NSPasteboard generalPasteboard];
NSData *data = [pasteboard dataForType:NSPasteboardTypePNG];
if (data == nil) {
return 0;
}
NSUInteger siz = [data length];
*out = malloc(siz);
[data getBytes: *out length: siz];
return siz;
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
NSData *tiffData = [pasteboard dataForType:NSPasteboardTypeTIFF];
if (tiffData == nil) {
return 0;
}
NSImage *image = [[NSImage alloc] initWithData:tiffData];
if (!image) {
return 0;
}

CGImageRef cgRef = [image CGImageForProposedRect:NULL context:nil hints:nil];
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithCGImage:cgRef];
NSData *pngData = [bitmap representationUsingType:NSBitmapImageFileTypePNG properties:@{}];

if (!pngData) {
return 0;
}

NSUInteger siz = [pngData length];
*out = malloc(siz);
[pngData getBytes:*out length:siz];
return siz;
}

int clipboard_write_string(const void *bytes, NSInteger n) {
Expand Down