- assets/logo.png (transparent) and assets/logo-256.png for the site and README - tools/make_icon.m builds the full-bleed iOS icon from the logo
36 lines
2.3 KiB
Objective-C
36 lines
2.3 KiB
Objective-C
// Builds the 1024x1024 iOS app icon from the project logo (assets/logo.png, transparent).
|
|
// The emblem is drawn with high-quality interpolation onto an opaque, full-bleed dark background:
|
|
// iOS app icons must be opaque and square (the system applies the rounded mask).
|
|
// Usage: make_icon SOURCE_PNG OUTPUT_PNG
|
|
#import <Foundation/Foundation.h>
|
|
#import <CoreGraphics/CoreGraphics.h>
|
|
#import <ImageIO/ImageIO.h>
|
|
|
|
int main(int argc, char **argv) {
|
|
@autoreleasepool {
|
|
if (argc != 3) { fprintf(stderr, "usage: make_icon SOURCE_PNG OUTPUT_PNG\n"); return 2; }
|
|
CGImageSourceRef src = CGImageSourceCreateWithURL((__bridge CFURLRef)[NSURL fileURLWithPath:@(argv[1])], NULL);
|
|
CGImageRef gear = src ? CGImageSourceCreateImageAtIndex(src, 0, NULL) : NULL;
|
|
if (!gear) { fprintf(stderr, "cannot read %s\n", argv[1]); return 1; }
|
|
const size_t size = 1024;
|
|
CGColorSpaceRef rgb = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
|
|
CGContextRef ctx = CGBitmapContextCreate(NULL, size, size, 8, 0, rgb, (CGBitmapInfo)kCGImageAlphaNoneSkipLast);
|
|
// Dark warm gradient, close to Factorio's menu backdrop.
|
|
CGFloat stops[] = {0.20, 0.17, 0.14, 1, 0.07, 0.06, 0.05, 1};
|
|
CGGradientRef gradient = CGGradientCreateWithColorComponents(rgb, stops, NULL, 2);
|
|
CGContextDrawRadialGradient(ctx, gradient, CGPointMake(size / 2.0, size * 0.55), 0,
|
|
CGPointMake(size / 2.0, size / 2.0), size * 0.75, kCGGradientDrawsAfterEndLocation);
|
|
CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh);
|
|
CGFloat inset = size * 0.14; // keep the emblem clear of the mask's corners
|
|
CGContextDrawImage(ctx, CGRectMake(inset, inset, size - 2 * inset, size - 2 * inset), gear);
|
|
CGImageRef icon = CGBitmapContextCreateImage(ctx);
|
|
CGImageDestinationRef dst = CGImageDestinationCreateWithURL((__bridge CFURLRef)[NSURL fileURLWithPath:@(argv[2])],
|
|
CFSTR("public.png"), 1, NULL);
|
|
CGImageDestinationAddImage(dst, icon, NULL);
|
|
BOOL ok = CGImageDestinationFinalize(dst);
|
|
CFRelease(dst); CGImageRelease(icon); CGGradientRelease(gradient); CGContextRelease(ctx);
|
|
CGColorSpaceRelease(rgb); CGImageRelease(gear); CFRelease(src);
|
|
return ok ? 0 : 1;
|
|
}
|
|
}
|