-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpdn.py
More file actions
58 lines (50 loc) · 1.64 KB
/
pdn.py
File metadata and controls
58 lines (50 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Do file io - PDN."""
from __future__ import annotations
from blendmodes.blend import BlendType
from loguru import logger
from PIL import Image
from layeredimage.io.common import blendModeLookup
from layeredimage.layeredimage import LayeredImage
from layeredimage.layergroup import Layer
#### PDN ####
def openLayer_PDN(file: str) -> LayeredImage:
"""Open a .pdn file into a layered image."""
from pypdn.reader import BlendType as PDNBlend
from pypdn.reader import read
blendLookup = {
PDNBlend.Normal: BlendType.NORMAL,
PDNBlend.Multiply: BlendType.MULTIPLY,
PDNBlend.Additive: BlendType.ADDITIVE,
PDNBlend.ColorBurn: BlendType.COLOURBURN,
PDNBlend.ColorDodge: BlendType.COLOURDODGE,
PDNBlend.Reflect: BlendType.REFLECT,
PDNBlend.Glow: BlendType.GLOW,
PDNBlend.Overlay: BlendType.OVERLAY,
PDNBlend.Difference: BlendType.DIFFERENCE,
PDNBlend.Negation: BlendType.NEGATION,
PDNBlend.Lighten: BlendType.LIGHTEN,
PDNBlend.Darken: BlendType.DARKEN,
PDNBlend.Screen: BlendType.SCREEN,
PDNBlend.XOR: BlendType.XOR,
}
project = read(file)
layers = []
for layer in project.layers:
image = Image.fromarray(layer.image)
layers.append(
Layer(
name=layer.name,
image=image,
dimensions=image.size,
offsets=(0, 0),
opacity=layer.opacity / 255,
visible=layer.visible,
blendmode=blendModeLookup(layer.blendMode, blendLookup),
)
)
return LayeredImage(layers, (project.width, project.height))
def saveLayer_PDN(fileName: str, layeredImage: LayeredImage) -> None:
"""Save a layered image as .pdn."""
del fileName, layeredImage
logger.error("Saving PDNs is not implemented in pypdn")
raise NotImplementedError