Concurrently process reading chunk data
This commit is contained in:
parent
338cec2076
commit
2134cbc6a8
1 changed files with 51 additions and 34 deletions
|
@ -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
|
||||
}
|
||||
|
|
Reference in a new issue