Properly clear mask image, and load regular layer when a mask is present
This commit is contained in:
parent
af6890dca8
commit
9ce297bf9a
1 changed files with 38 additions and 33 deletions
|
@ -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,44 +360,46 @@ 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 {
|
|
||||||
let x = chunk.x
|
|
||||||
var y = chunk.y
|
|
||||||
|
|
||||||
let (width, height) = getTileSize(x: x, y: y)
|
for chunk in layer.data.chunks {
|
||||||
|
let x = chunk.x
|
||||||
|
var y = chunk.y
|
||||||
|
|
||||||
if y == rows {
|
let (width, height) = getTileSize(x: x, y: y)
|
||||||
y = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
let rect = NSRect(x: info.tileSize * x, y: info.height - (info.tileSize * y), width: width, height: height)
|
if y == rows {
|
||||||
|
y = 0
|
||||||
|
}
|
||||||
|
|
||||||
var op = CGBlendMode.copy
|
let rect = NSRect(x: info.tileSize * x, y: info.height - (info.tileSize * y), width: width, height: height)
|
||||||
if layer.data.blendMode == 12 {
|
|
||||||
op = .hardLight
|
|
||||||
}
|
|
||||||
|
|
||||||
layerContext?.setAlpha(CGFloat(layer.data.opacity))
|
var op = CGBlendMode.copy
|
||||||
layerContext?.setBlendMode(op)
|
if layer.data.blendMode == 12 {
|
||||||
|
op = .hardLight
|
||||||
|
}
|
||||||
|
|
||||||
if !layer.data.hidden {
|
layerContext?.setAlpha(CGFloat(layer.data.opacity))
|
||||||
layerContext?.draw(chunk.image.cgImage(forProposedRect: nil, context: NSGraphicsContext.current, hints: nil)!, in: rect)
|
layerContext?.setBlendMode(op)
|
||||||
}
|
|
||||||
|
if !layer.data.hidden {
|
||||||
|
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)
|
||||||
|
|
||||||
ccgContext?.draw(layerImage, in: CGRect(x: 0, y: 0, width: info.width, height: info.height))
|
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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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))
|
||||||
|
|
Reference in a new issue