Begin statistics creation
This commit is contained in:
@@ -44,6 +44,9 @@ final class ImageGenerator {
|
||||
// MARK: Image operations
|
||||
|
||||
func generate(version: ImageVersion) -> Bool {
|
||||
if version.image.type == .route {
|
||||
return generateImageForRoute(version: version)
|
||||
}
|
||||
if version.type == .avif {
|
||||
if version.image.type == .gif {
|
||||
// Skip GIFs, since they can't be converted by avifenc
|
||||
@@ -56,12 +59,15 @@ final class ImageGenerator {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
guard let data = version.image.dataContent() else {
|
||||
print("ImageGenerator: Failed to load data for image \(version.image.identifier)")
|
||||
return false
|
||||
}
|
||||
|
||||
return generate(version: version, data: data)
|
||||
}
|
||||
|
||||
private func generate(version: ImageVersion, data: Data) -> Bool {
|
||||
guard let originalImage = NSImage(data: data) else {
|
||||
print("ImageGenerator: Failed to load image \(version.image.identifier)")
|
||||
return false
|
||||
@@ -109,6 +115,34 @@ final class ImageGenerator {
|
||||
return representation
|
||||
}
|
||||
|
||||
// MARK: Routes
|
||||
|
||||
private func generateImageForRoute(version: ImageVersion) -> Bool {
|
||||
let largeImagePath = version.image.mapImagePath
|
||||
|
||||
guard storage.hasFileInOutputFolder(largeImagePath) else {
|
||||
print("ImageGenerator: No map image generated for route \(version.image.identifier)")
|
||||
return false
|
||||
}
|
||||
|
||||
let largeImageUrl = URL(fileURLWithPath: largeImagePath)
|
||||
guard let imageData = try? Data(contentsOf: largeImageUrl) else {
|
||||
print("ImageGenerator: Failed to read map image data for route \(version.image.identifier)")
|
||||
return false
|
||||
}
|
||||
|
||||
if version.type == .avif {
|
||||
let originalImagePath = version.image.outputPath(width: version.maximumWidth, height: version.maximumHeight, type: .png)
|
||||
guard createAvifUsingBash(version: version, imagePath: originalImagePath) else {
|
||||
return false
|
||||
}
|
||||
version.wasNowGenerated()
|
||||
return true
|
||||
}
|
||||
|
||||
return generate(version: version, data: imageData)
|
||||
}
|
||||
|
||||
// MARK: Avif images
|
||||
|
||||
private func create(image: NSBitmapImageRep, type: FileType, quality: CGFloat) -> Data? {
|
||||
@@ -139,19 +173,23 @@ final class ImageGenerator {
|
||||
}
|
||||
|
||||
private func createAvifUsingBash(version: ImageVersion) -> Bool {
|
||||
|
||||
let baseVersion = ImageVersion(
|
||||
image: version.image,
|
||||
type: version.image.type,
|
||||
maximumWidth: version.maximumWidth,
|
||||
maximumHeight: version.maximumHeight)
|
||||
let originalImagePath = storage.outputPath(to: baseVersion.outputPath)!.path()
|
||||
return createAvifUsingBash(version: version, imagePath: originalImagePath)
|
||||
}
|
||||
|
||||
private func createAvifUsingBash(version: ImageVersion, imagePath: String) -> Bool {
|
||||
let generatedImagePath = storage.outputPath(to: version.outputPath)!.path()
|
||||
let quality = Int(version.quality * 100)
|
||||
|
||||
let process = Process()
|
||||
#warning("TODO: Move avifenc path to settings")
|
||||
process.launchPath = "/opt/homebrew/bin/avifenc" // Adjust based on installation
|
||||
process.arguments = ["-q", "\(quality)", originalImagePath, generatedImagePath]
|
||||
process.arguments = ["-q", "\(quality)", imagePath, generatedImagePath]
|
||||
|
||||
let pipe = Pipe()
|
||||
process.standardOutput = pipe
|
||||
|
||||
Reference in New Issue
Block a user