X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=hacks%2Fwebcollage-helper-cocoa.m;h=fde1f0d9add7ee2824537293c078ca8e2d10ebd8;hp=ffebfa6c33e6a783496a100bcd2136c9367d0a6f;hb=78add6e627ee5f10e1fa6f3852602ea5066eee5a;hpb=39809ded547bdbb08207d3e514950425215b4410 diff --git a/hacks/webcollage-helper-cocoa.m b/hacks/webcollage-helper-cocoa.m index ffebfa6c..fde1f0d9 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-2017 Jamie Zawinski + * xscreensaver, Copyright (c) 2002-2018 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 @@ -344,9 +344,34 @@ write_image (NSImage *img, const char *file) { float jpeg_quality = .85; - // Load the NSImage's contents into an NSBitmapImageRep: + // Load the NSImage's contents into an NSBitmapImageRep. + +#if 0 + // If the local display is Retina, this doubles the size of the output JPEG. NSBitmapImageRep *bit_rep = [NSBitmapImageRep imageRepWithData:[img TIFFRepresentation]]; +#else + // Render the image into a rep using pixels instead of points. + NSBitmapImageRep *bit_rep = [[NSBitmapImageRep alloc] + initWithBitmapDataPlanes:NULL + pixelsWide:[img size].width + pixelsHigh:[img size].height + bitsPerSample:8 + samplesPerPixel:4 + hasAlpha:YES + isPlanar:NO + colorSpaceName:NSCalibratedRGBColorSpace + bytesPerRow:0 + bitsPerPixel:0]; + bit_rep.size = [img size]; + [NSGraphicsContext saveGraphicsState]; + [NSGraphicsContext setCurrentContext: + [NSGraphicsContext + graphicsContextWithBitmapImageRep:bit_rep]]; + [img drawInRect:NSMakeRect(0, 0, [img size].width, [img size].height) + fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0]; + [NSGraphicsContext restoreGraphicsState]; +#endif // Write the bitmapImageRep to a JPEG file. if (bit_rep == nil) @@ -359,13 +384,10 @@ write_image (NSImage *img, const char *file) fprintf (stderr, "%s: writing %s (q=%d%%) ", progname, file, (int) (jpeg_quality * 100)); - NSDictionary *props = [NSDictionary - dictionaryWithObject: - [NSNumber numberWithFloat:jpeg_quality] - forKey:NSImageCompressionFactor]; NSData *jpeg_data = [bit_rep representationUsingType:NSJPEGFileType - properties:props]; - + properties:@{ NSImageCompressionFactor: + [NSNumber numberWithFloat: + jpeg_quality] }]; [jpeg_data writeToFile: [NSString stringWithCString:file encoding:NSISOLatin1StringEncoding]