-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrint Layer colors as RGB to error console.py
50 lines (41 loc) · 1.54 KB
/
Print Layer colors as RGB to error console.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
#!/usr/bin/env python
from gimpfu import *
def get_unique_colors(layer):
pixel_region = layer.get_pixel_rgn(0, 0, layer.width, layer.height, False, False)
unique_colors = set()
for y in range(layer.height):
for x in range(layer.width):
pixel = pixel_region[x, y]
r, g, b = ord(pixel[0]), ord(pixel[1]), ord(pixel[2])
unique_colors.add((r, g, b))
return unique_colors
def print_layer_colors(layer, indent=""):
pdb.gimp_message(indent + "Layer: " + layer.name)
if isinstance(layer, gimp.GroupLayer):
pdb.gimp_message(indent + "Group Layer - No direct colors")
pdb.gimp_message(indent + "------------------------")
for child_layer in layer.layers:
print_layer_colors(child_layer, indent + " ")
else:
unique_colors = get_unique_colors(layer)
pdb.gimp_message(indent + "Unique colors:")
for color in unique_colors:
pdb.gimp_message(indent + " RGB: {}".format(color))
pdb.gimp_message(indent + "------------------------")
def process_image(image, drawable):
for layer in image.layers:
print_layer_colors(layer)
register(
"python_fu_print_all_layer_colors",
"Print unique colors of all layers including those in groups",
"Prints unique colors of all layers in the image, including those within layer groups",
"Jordan B",
"J",
"2024",
"<Image>/Colors/Print Layer colors as RGB",
"*",
[],
[],
process_image
)
main()