import Foundation import ImageIO import UniformTypeIdentifiers import Darwin import EquipoShareCore // Separate processes: fixture generation must not inflate the preparation peak. let args = CommandLine.arguments let input = URL(fileURLWithPath: args[2]) if args[1] == "generate" { let canvas = CGContext(data: nil, width: 8064, height: 6048, bitsPerComponent: 8, bytesPerRow: 0, space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: CGImageAlphaInfo.noneSkipLast.rawValue)! for y in stride(from: 0, to: 6048, by: 32) { for x in stride(from: 0, to: 8064, by: 32) { canvas.setFillColor(CGColor(red: CGFloat((x * 17 + y) % 255) / 255, green: CGFloat((y * 13 + x) % 255) / 255, blue: CGFloat((x + y * 19) % 255) / 255, alpha: 1)) canvas.fill(CGRect(x: x, y: y, width: 32, height: 32)) } } let destination = CGImageDestinationCreateWithURL(input as CFURL, UTType.heic.identifier as CFString, 1, nil)! CGImageDestinationAddImage(destination, canvas.makeImage()!, [kCGImagePropertyOrientation: 6, kCGImagePropertyGPSDictionary: [kCGImagePropertyGPSLatitude: 53.3, kCGImagePropertyGPSLongitude: -6.2], kCGImageDestinationLossyCompressionQuality: 0.85] as CFDictionary) guard CGImageDestinationFinalize(destination) else { fatalError("fixture encoding failed") } print("Generated 8064 x 6048 HEIC") } else { let output = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) defer { try? FileManager.default.removeItem(at: output) } var files: [FileAttachment] = [] for _ in 0..<5 { files.append(try autoreleasepool { try AttachmentFile.prepareFile(input, directory: output) }) } var usage = rusage(); getrusage(RUSAGE_SELF, &usage) print("Prepared \(files.count) images, \(files[0].width) x \(files[0].height); peak RSS \(usage.ru_maxrss) bytes") guard files.allSatisfy({ max($0.width, $0.height) == 2560 }) else { exit(2) } guard usage.ru_maxrss < 120 * 1024 * 1024 else { exit(3) } }