X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fwebcollage-helper-cocoa.m;h=f85b7071f9258d6ba4d8308b2b22e9e445460a46;hb=refs%2Fremotes%2Fgithub%2Fmaster2;hp=6c6e9d2ba236039ee2deff34cb7deedaabf701c7;hpb=50be9bb40dc60130c99ffa568e6677779904ff70;p=xscreensaver diff --git a/hacks/webcollage-helper-cocoa.m b/hacks/webcollage-helper-cocoa.m index 6c6e9d2b..f85b7071 100644 --- a/hacks/webcollage-helper-cocoa.m +++ b/hacks/webcollage-helper-cocoa.m @@ -1,5 +1,5 @@ /* webcollage-helper-cocoa --- scales and pastes one image into another - * xscreensaver, Copyright (c) 2002-2009 Jamie Zawinski + * xscreensaver, Copyright (c) 2002-2014 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -105,7 +105,7 @@ load_image (const char *file) NSImage *image = [[NSImage alloc] initWithContentsOfFile: [NSString stringWithCString: file - encoding: kCFStringEncodingUTF8]]; + encoding: NSUTF8StringEncoding]]; if (! image) image = load_ppm_image (file); @@ -114,6 +114,14 @@ load_image (const char *file) exit (1); } + + // [NSImage size] defaults to the image size in points instead of pixels, + // so if an image file specified "pixels per inch" we can end up with + // absurdly sized images. Set it back to 1:1 pixel:point. + // + NSImageRep *rep = [image.representations objectAtIndex:0]; + image.size = NSMakeSize (rep.pixelsWide, rep.pixelsHigh); + return image; } @@ -382,6 +390,12 @@ main (int argc, char **argv) if (w < 0) usage(); if (h < 0) usage(); + if (w == 0 || h == 0 || + w > 10240 || h > 10240) { + fprintf (stderr, "%s: absurd size: %d x %d\n", progname, w, h); + exit (1); + } + // Much of Cocoa needs one of these to be available. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];