-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgimpParasites.py
104 lines (90 loc) · 2.57 KB
/
gimpParasites.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env
# -*- coding: utf-8 -*-
"""
Parasites are arbitrary (meta)data strings that can be attached
to a document tree item
They are used to store things like last-used plugin settings,
gamma adjuetments, etc.
Format of known parasites:
https://gitlab.gnome.org/GNOME/gimp/blob/master/devel-docs/parasites.txt
"""
import typing
from gimpFormats.binaryIO import IO
#TODO: how to best use these for our puproses??
KNOWN_DOCUMENT_PARASITES=[
"jpeg-save-defaults",
"png-save-defaults",
"<plug-in>/_fu_data",
"exif-orientation-rotate"]
KNOWN_IMAGE_PARASITES=[
"gimp-comment",
"gimp-brush-name",
"gimp-brush-pipe-name",
"gimp-brush-pipe-parameters",
"gimp-image-grid",
"gimp-pattern-name",
"tiff-save-options",
"jpeg-save-options",
"jpeg-exif-data",
"jpeg-original-settings",
"gamma",
"chromaticity",
"rendering-intent",
"hot-spot",
"exif-data",
"gimp-metadata",
"icc-profile",
"icc-profile-name",
"decompose-data",
"print-settings",
"print-page-setup",
"dcm/XXXX-XXXX-AA"]
KNOWN_LAYER_PARASITES=[
"gimp-text-layer",
"gfig"]
class GimpParasite:
"""
Parasites are arbitrary (meta)data strings that can be attached to
a document tree item
They are used to store things like last-used plugin settings,
gamma adjuetments, etc.
Format of known parasites:
https://gitlab.gnome.org/GNOME/gimp/blob/master/devel-docs/parasites.txt
"""
def __init__(self)->None:
self.name:str=''
self.flags:int=0
self.data:typing.Optional[bytes]=None
def fromBytes(self,data,index=0):
"""
decode a byte buffer
:param data: data buffer to decode
:param index: index within the buffer to start at
"""
io=IO(data,index)
self.name=io.sz754
self.flags=io.u32
dataLength=io.u32
self.data=io.getBytes(dataLength)
return io.index
def toBytes(self):
"""
decode a byte buffer
:param data: data buffer to decode
:param index: index within the buffer to start at
"""
io=IO()
io.sz754=self.name
io.u32=self.flags
io.u32=len(self.data)
io.addBytes(self.data)
return io.data
def __repr__(self,indent=''):
"""
Get a textual representation of this object
"""
ret=[]
ret.append('Name: '+str(self.name))
ret.append('Flags: '+str(self.flags))
ret.append('Data Len: '+str(len(self.data)))
return indent+(('\n'+indent).join(ret))