1
Fork 0

Concurrently process reading chunk data

This commit is contained in:
Joshua Goins 2020-03-11 22:44:52 -04:00 committed by redstrate
parent 338cec2076
commit 2134cbc6a8

View file

@ -19,6 +19,8 @@ func objectRefGetValue(_ objectRef : CFTypeRef) -> UInt32 {
}
class Document: NSDocument {
var data: Data? // oh no...
var dict: NSDictionary?
let DocumentClassName = "SilicaDocument"
@ -64,14 +66,27 @@ class Document: NSDocument {
if getDocumentClassName(dict: dict) == LayerClassName {
var layer = SilicaLayer()
dump(dict, maxDepth: 2)
let UUIDKey = dict["UUID"]
let UUIDClassID = objectRefGetValue(UUIDKey as CFTypeRef)
let UUIDClass = objectsArray[Int(UUIDClassID)] as! NSString
var chunkPaths: [Entry] = []
archive.forEach { (entry: Entry) in
if entry.path.contains(String(UUIDClass)) {
chunkPaths.append(entry)
}
}
layer.chunks = Array(repeating: NSImage(), count: chunkPaths.count)
DispatchQueue.concurrentPerform(iterations: chunkPaths.count) { (i: Int) in
let entry = chunkPaths[i]
guard let archive = Archive(data: self.data!, accessMode: Archive.AccessMode.read) else {
return
}
var lzo_data = Data()
do {
@ -101,8 +116,8 @@ class Document: NSDocument {
let cgimage: CGImage? = CGImage(width: info.tileSize, height: info.tileSize, bitsPerComponent: 8, bitsPerPixel: 32, bytesPerRow: info.tileSize * 4, space: rgbColorSpace, bitmapInfo: bitmapInfo, provider: providerRef!, decode: nil, shouldInterpolate: true, intent: render)
if cgimage != nil {
let image = NSImage(cgImage: cgimage!, size: NSZeroSize)
layer.chunks.append(image)
}
layer.chunks[i] = image
}
}
@ -153,6 +168,8 @@ class Document: NSDocument {
}
override func read(from data: Data, ofType typeName: String) throws {
self.data = data
guard let archive = Archive(data: data, accessMode: Archive.AccessMode.read) else {
return
}