1
Fork 0

Properly clear mask image, and load regular layer when a mask is present

This commit is contained in:
Joshua Goins 2021-09-16 18:28:56 -04:00
parent af6890dca8
commit 9ce297bf9a

View file

@ -340,6 +340,9 @@ class Document: NSDocument {
let maskContext = CGContext(data: nil, width: info.width, height: info.height, bitsPerComponent: 16, bytesPerRow: 0, space: grayColorSpace, bitmapInfo: maskBitmapInfo.rawValue) let maskContext = CGContext(data: nil, width: info.width, height: info.height, bitsPerComponent: 16, bytesPerRow: 0, space: grayColorSpace, bitmapInfo: maskBitmapInfo.rawValue)
maskContext?.setFillColor(.white)
maskContext?.fill(CGRect(origin: .zero, size: CGSize(width: info.width, height: info.height)))
if layer.mask != nil { if layer.mask != nil {
for chunk in layer.mask!.chunks { for chunk in layer.mask!.chunks {
let x = chunk.x let x = chunk.x
@ -357,7 +360,8 @@ class Document: NSDocument {
maskContext?.draw(chunk.image.cgImage(forProposedRect: nil, context: NSGraphicsContext.current, hints: nil)!, in: rect) maskContext?.draw(chunk.image.cgImage(forProposedRect: nil, context: NSGraphicsContext.current, hints: nil)!, in: rect)
} }
} }
} else { }
for chunk in layer.data.chunks { for chunk in layer.data.chunks {
let x = chunk.x let x = chunk.x
var y = chunk.y var y = chunk.y
@ -382,20 +386,21 @@ class Document: NSDocument {
layerContext?.draw(chunk.image.cgImage(forProposedRect: nil, context: NSGraphicsContext.current, hints: nil)!, in: rect) layerContext?.draw(chunk.image.cgImage(forProposedRect: nil, context: NSGraphicsContext.current, hints: nil)!, in: rect)
} }
} }
}
var layerImage = (layerContext?.makeImage())! let layerImage = (layerContext?.makeImage())!
if layer.mask != nil {
let maskImage = (maskContext?.makeImage())!
layerImage = layerImage.masking(maskImage)!
}
ccgContext?.setAlpha(1.0) ccgContext?.setAlpha(1.0)
ccgContext?.setBlendMode(.sourceAtop) ccgContext?.setBlendMode(.sourceAtop)
if layer.mask != nil {
let maskImage = (maskContext?.makeImage())!
let newImage = layerImage.masking(maskImage)!
ccgContext?.draw(newImage, in: CGRect(x: 0, y: 0, width: info.width, height: info.height))
} else {
ccgContext?.draw(layerImage, in: CGRect(x: 0, y: 0, width: info.width, height: info.height)) ccgContext?.draw(layerImage, in: CGRect(x: 0, y: 0, width: info.width, height: info.height))
} }
}
var image = NSImage(cgImage: (ccgContext?.makeImage())!, size: NSSize(width: info.width, height: info.height)) var image = NSImage(cgImage: (ccgContext?.makeImage())!, size: NSSize(width: info.width, height: info.height))