feat: finished all open things up to and including phase 6

This commit is contained in:
2026-03-21 08:41:13 +01:00
parent 0325fa8964
commit 107ac0524b
9 changed files with 457 additions and 33 deletions

View File

@@ -1,3 +1,4 @@
import AppKit
import Foundation
enum TestImageFixtures {
@@ -22,9 +23,66 @@ enum TestImageFixtures {
return data.base64EncodedString()
}
private static func generatedBitmapData(
width: Int,
height: Int,
fileType: NSBitmapImageRep.FileType,
compressionFactor: Double? = nil
) -> Data {
let bytesPerRow = width * 4
guard let rep = NSBitmapImageRep(
bitmapDataPlanes: nil,
pixelsWide: width,
pixelsHigh: height,
bitsPerSample: 8,
samplesPerPixel: 4,
hasAlpha: true,
isPlanar: false,
colorSpaceName: .deviceRGB,
bytesPerRow: bytesPerRow,
bitsPerPixel: 32
) else {
fatalError("Failed to create bitmap fixture")
}
NSGraphicsContext.saveGraphicsState()
NSGraphicsContext.current = NSGraphicsContext(bitmapImageRep: rep)
let imageRect = NSRect(x: 0, y: 0, width: CGFloat(width), height: CGFloat(height))
NSColor(calibratedRed: 0.18, green: 0.45, blue: 0.87, alpha: 1).setFill()
imageRect.fill()
NSColor.white.setStroke()
let inset = CGFloat(max(8, min(width, height) / 16))
NSBezierPath(rect: imageRect.insetBy(dx: inset, dy: inset)).stroke()
NSGraphicsContext.restoreGraphicsState()
var properties: [NSBitmapImageRep.PropertyKey: Any] = [:]
if let compressionFactor {
properties[.compressionFactor] = compressionFactor
}
guard let data = rep.representation(using: fileType, properties: properties) else {
fatalError("Failed to encode bitmap fixture")
}
return data
}
static let primaryPNGBase64 = loadBase64(named: "icon_16x16.png")
static let alternatePNGBase64 = loadBase64(named: "icon_32x32.png")
static let primaryJPEGBase64 = generatedBitmapData(
width: 64,
height: 64,
fileType: .jpeg,
compressionFactor: 0.85
).base64EncodedString()
static let largePNGBase64 = generatedBitmapData(
width: 4_096,
height: 4_096,
fileType: .png
).base64EncodedString()
static let primaryDataURI = "data:image/png;base64,\(primaryPNGBase64)"
static let alternateDataURI = "data:image/png;base64,\(alternatePNGBase64)"
static let primaryJPEGDataURI = "data:image/jpeg;base64,\(primaryJPEGBase64)"
static let largeDataURI = "data:image/png;base64,\(largePNGBase64)"
}