Add support for more blend modes
This commit is contained in:
parent
6ad06a1360
commit
93dc48c1ca
1 changed files with 91 additions and 7 deletions
|
@ -11,6 +11,7 @@ struct SilicaChunk {
|
|||
|
||||
struct SilicaLayerData {
|
||||
var blendMode: Int = 0
|
||||
var extendedBlend: Int = 0
|
||||
var chunks: [SilicaChunk] = []
|
||||
var opacity: Double = 1.0
|
||||
var hidden: Bool = false
|
||||
|
@ -140,6 +141,7 @@ class Document: NSDocument {
|
|||
let maskClass = objectsArray[maskClassID]
|
||||
|
||||
layer.data.blendMode = (dict["blend"] as? NSNumber)!.intValue
|
||||
layer.data.extendedBlend = (dict["extendedBlend"] as? NSNumber)!.intValue
|
||||
layer.data.opacity = (dict["opacity"] as? NSNumber)!.doubleValue
|
||||
layer.data.hidden = (dict["hidden"] as? Bool)!
|
||||
layer.clipped = (dict["clipped"] as? Bool)!
|
||||
|
@ -365,6 +367,93 @@ class Document: NSDocument {
|
|||
maskContext?.setFillColor(.white)
|
||||
maskContext?.fill(CGRect(origin: .zero, size: CGSize(width: info.width, height: info.height)))
|
||||
|
||||
var op = CGBlendMode.sourceAtop
|
||||
NSLog("----")
|
||||
NSLog("blend Mode: %i", layer.data.blendMode)
|
||||
NSLog("extend blend mode: %i", layer.data.extendedBlend)
|
||||
if layer.data.blendMode == 1 {
|
||||
op = .multiply
|
||||
}
|
||||
if layer.data.blendMode == 10 {
|
||||
op = .colorBurn
|
||||
}
|
||||
if layer.data.blendMode == 19 {
|
||||
op = .darken
|
||||
}
|
||||
if layer.data.blendMode == 8 {
|
||||
//op = .linearBurn
|
||||
}
|
||||
if layer.data.blendMode == 4 {
|
||||
op = .lighten
|
||||
}
|
||||
if layer.data.blendMode == 2 {
|
||||
op = .screen
|
||||
}
|
||||
if layer.data.blendMode == 13 {
|
||||
op = .hardLight
|
||||
}
|
||||
if layer.data.blendMode == 9 {
|
||||
op = .colorDodge
|
||||
}
|
||||
if layer.data.blendMode == 3 {
|
||||
op = .plusLighter
|
||||
}
|
||||
|
||||
if layer.data.blendMode == 0 && layer.data.blendMode != layer.data.extendedBlend {
|
||||
if layer.data.extendedBlend == 25 {
|
||||
//op = .darkerColor
|
||||
}
|
||||
if layer.data.extendedBlend == 24 {
|
||||
//op = .lighterColor
|
||||
}
|
||||
if layer.data.extendedBlend == 21 {
|
||||
//op = .vividLight
|
||||
}
|
||||
if layer.data.extendedBlend == 22 {
|
||||
//op = .linearLight
|
||||
}
|
||||
if layer.data.extendedBlend == 23 {
|
||||
//op = .pinLight
|
||||
}
|
||||
if layer.data.extendedBlend == 20 {
|
||||
//op = .hardMix
|
||||
}
|
||||
if layer.data.extendedBlend == 26 {
|
||||
//op = .divide
|
||||
}
|
||||
}
|
||||
|
||||
if layer.data.blendMode == 11 {
|
||||
op = .overlay
|
||||
}
|
||||
if layer.data.blendMode == 17 {
|
||||
op = .softLight
|
||||
}
|
||||
if layer.data.blendMode == 12 {
|
||||
op = .hardLight
|
||||
}
|
||||
if layer.data.blendMode == 6 {
|
||||
op = .difference
|
||||
}
|
||||
if layer.data.blendMode == 5 {
|
||||
op = .exclusion
|
||||
}
|
||||
if layer.data.blendMode == 7 {
|
||||
op = .plusDarker
|
||||
}
|
||||
if layer.data.blendMode == 15 {
|
||||
op = .hue
|
||||
}
|
||||
if layer.data.blendMode == 16 {
|
||||
op = .saturation
|
||||
}
|
||||
if layer.data.blendMode == 13 {
|
||||
op = .color
|
||||
}
|
||||
if layer.data.blendMode == 14 {
|
||||
op = .luminosity
|
||||
}
|
||||
|
||||
if layer.mask != nil {
|
||||
for chunk in layer.mask!.chunks {
|
||||
let x = chunk.x
|
||||
|
@ -396,13 +485,8 @@ class Document: NSDocument {
|
|||
|
||||
let rect = NSRect(x: info.tileSize * x, y: info.height - (info.tileSize * y), width: width, height: height)
|
||||
|
||||
var op = CGBlendMode.copy
|
||||
if layer.data.blendMode == 12 {
|
||||
op = .hardLight
|
||||
}
|
||||
|
||||
layerContext?.setAlpha(CGFloat(layer.data.opacity))
|
||||
layerContext?.setBlendMode(op)
|
||||
layerContext?.setBlendMode(.copy)
|
||||
|
||||
if !layer.data.hidden {
|
||||
layerContext?.draw(chunk.image.cgImage(forProposedRect: nil, context: NSGraphicsContext.current, hints: nil)!, in: rect)
|
||||
|
@ -412,7 +496,7 @@ class Document: NSDocument {
|
|||
let layerImage = (layerContext?.makeImage())!
|
||||
|
||||
ccgContext?.setAlpha(1.0)
|
||||
ccgContext?.setBlendMode(.sourceAtop)
|
||||
ccgContext?.setBlendMode(op)
|
||||
|
||||
if layer.clipped {
|
||||
guard let result = previousImage?.toGrayscale() else {
|
||||
|
|
Reference in a new issue