-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbsz-pixelbuster.py
executable file
·114 lines (91 loc) · 2.98 KB
/
bsz-pixelbuster.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
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Gegl Operation references:
http://www.gegl.org/operations/
https://gitlab.gnome.org/GNOME/gegl/-/tree/master/operations
If on Linux:
$ gegl --list-all
$ gegl --info "operation-name"
Also build the .gir files using g-ir-doc-tool for additional insight.
If the docs don't have a description on something like class methods,
run python's help() on it to view it in the terminal.
"""
# Uncomment as needed.
# I don't actually know if it's faster to not import some of the gi repo stuff
# since it probably gets imported later anyway ...right?
import gi
gi.require_version('Gimp', '3.0')
from gi.repository import Gimp
gi.require_version('Gegl', '0.4')
from gi.repository import Gegl
# from gi.repository import GObject
# from gi.repository import GLib
# from gi.repository import Gio
import sys
import os.path
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + '/../')
from bsz_gimp_lib import PlugIn, ParamCombo, ParamString
import ctypes
from sys import platform
LIBRARY = {"win32": "pixelbuster.dll", "linux": "libpixelbuster.so"}
import os.path
pb_lib = ctypes.CDLL(
os.path.dirname(os.path.realpath(__file__)) + "/../" +
LIBRARY.get(platform))
pb_lib.pb_help_ffi.restype = ctypes.c_char_p
HELP = pb_lib.pb_help_ffi().decode('UTF-8')
pb_lib.pixelbuster_ffi.argtypes = [
ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_uint,
ctypes.c_uint
]
# Main function.
def pixelbuster(image, drawable, code):
# {{{
# Fairly certain mask_intersect() is the current selection mask
intersect, x, y, width, height = drawable.mask_intersect()
if intersect:
# start Gegl
Gegl.init(None)
# fetch main buffer
buff = drawable.get_buffer()
# fetch shadow aka "temp" buffer
shadow = drawable.get_shadow_buffer()
# create working rectangle area using mask intersect.
rect = Gegl.Rectangle.new(x, y, width, height)
pixels = buff.get(rect, 1.0, "RGBA float", Gegl.AbyssPolicy.CLAMP)
pb_lib.pixelbuster_ffi(
code.encode('UTF-8'),
"lrgba".encode('UTF-8'),
pixels,
len(pixels),
width,
)
shadow.set(rect, "RGBA float", bytes(pixels))
# Flush shadow buffer and combine it with main drawable
shadow.flush()
drawable.merge_shadow(True)
# Update everything.
drawable.update(x, y, width, height)
Gimp.displays_flush()
# }}}
# create the plugin from bsz_gimp_lib
plugin = PlugIn(
"Pixelbuster", # name
pixelbuster, # function
ParamString("Operations",
"""# simple filmic-chroma
LCH
v1 = L
v1 / 100
v1 invert 1
C * v1""",
"See description for documentation",
ui_multiline=True,
ui_min_width=300,
ui_min_height=300),
description=HELP,
images="*",
)
# register the plugin's Procedure class with gimp
Gimp.main(plugin.Procedure.__gtype__, sys.argv)