Primary sync: replace PersistenceActor JSON file with SwiftData + CloudKit - Add SavedCardModel (@Model class) and PersistenceController (ModelContainer with .automatic CloudKit, fallback to local). BackgroundPersistenceActor (@ModelActor) handles all DB I/O off the main thread. - One-time migration imports user_collection.json into SwiftData and renames the original file to prevent re-import. - Inject modelContainer into SwiftUI environment in IYmtgApp. Image storage: Documents/UserContent/ subfolder (blueprint requirement) - ImageManager.dir now targets iCloud Documents/UserContent/ (or local equiv). - migrateImagesToUserContent() moves existing JPGs to the new subfolder on first launch; called during the SwiftData migration. Firebase: demoted to optional manual backup (metadata only, no images) - Remove all automatic CloudEngine.save/delete/batchUpdatePrices calls from CollectionViewModel mutations. - Add backupAllToFirebase() for user-triggered metadata sync. - Add isFirebaseBackupEnabled to AppConfig (default false). - Add Cloud Backup section in Library settings with iCloud vs Firebase explanation and "Backup Metadata to Firebase Now" button. Also: full modular refactor (Data/, Features/, Services/ directories) and README updated with CloudKit setup steps and revised release checklist. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
31 lines
1.3 KiB
Swift
31 lines
1.3 KiB
Swift
import CoreImage
|
|
import CoreGraphics
|
|
|
|
// MARK: - SATURATION DETECTOR (Unlimited vs Revised)
|
|
class SaturationDetector {
|
|
static func analyze(image: CGImage, orientation: CGImagePropertyOrientation = .up) -> Double {
|
|
// Crop to center 50% to analyze artwork saturation, ignoring borders
|
|
let ciImage = CIImage(cgImage: image).oriented(orientation)
|
|
let width = ciImage.extent.width
|
|
let height = ciImage.extent.height
|
|
let cropRect = CGRect(x: width * 0.25, y: height * 0.25, width: width * 0.5, height: height * 0.5)
|
|
|
|
let vector = CIVector(cgRect: cropRect)
|
|
guard let filter = CIFilter(name: "CIAreaAverage", parameters: [kCIInputImageKey: ciImage, kCIInputExtentKey: vector]),
|
|
let output = filter.outputImage else { return 0 }
|
|
|
|
var bitmap = [UInt8](repeating: 0, count: 4)
|
|
let context = SharedEngineResources.context
|
|
context.render(output, toBitmap: &bitmap, rowBytes: 4, bounds: CGRect(x: 0, y: 0, width: 1, height: 1), format: .RGBA8, colorSpace: nil)
|
|
|
|
// Simple Saturation approximation: (Max - Min) / Max
|
|
let r = Double(bitmap[0]) / 255.0
|
|
let g = Double(bitmap[1]) / 255.0
|
|
let b = Double(bitmap[2]) / 255.0
|
|
let maxC = max(r, max(g, b))
|
|
let minC = min(r, min(g, b))
|
|
|
|
return maxC == 0 ? 0 : (maxC - minC) / maxC
|
|
}
|
|
}
|