/* webcollage-helper-cocoa --- scales and pastes one image into another
- * xscreensaver, Copyright (c) 2002-2009 Jamie Zawinski <jwz@jwz.org>
+ * xscreensaver, Copyright (c) 2002-2014 Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
NSImage *image = [[NSImage alloc]
initWithContentsOfFile:
[NSString stringWithCString: file
- encoding: kCFStringEncodingUTF8]];
+ encoding: NSUTF8StringEncoding]];
if (! image)
image = load_ppm_image (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;
}
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];