summaryrefslogtreecommitdiff
path: root/python-fu
diff options
context:
space:
mode:
Diffstat (limited to 'python-fu')
-rwxr-xr-xpython-fu/2.10/przem-waved-cubism/przem-waved-cubism.py276
-rwxr-xr-xpython-fu/3.0.0RC2/przem-waved-cubism/przem-waved-cubism.py244
2 files changed, 520 insertions, 0 deletions
diff --git a/python-fu/2.10/przem-waved-cubism/przem-waved-cubism.py b/python-fu/2.10/przem-waved-cubism/przem-waved-cubism.py
new file mode 100755
index 0000000..7e3a0dc
--- /dev/null
+++ b/python-fu/2.10/przem-waved-cubism/przem-waved-cubism.py
@@ -0,0 +1,276 @@
+#!/usr/bin/env python
+import sys, os, math
+#gi.require_version("Gtk", "3.0")
+#from gi.repository import Gtk, Gdk, GdkPixbuf
+#from gi.repository.GdkPixbuf import Pixbuf
+#import cairo
+
+from gimpfu import *
+
+
+def get_pixel_color(layer, x, y):
+
+ #width = layer.get_width()
+ #height = layer.get_height()
+ width, height = layer.width, layer.height
+
+ if x > width or y > height:
+ return None
+ elif x < 0 or y < 0:
+ return None
+
+ if layer.type == RGB_IMAGE:
+ n_channels = 3
+ elif layer.type == RGBA_IMAGE:
+ n_channels = 4
+ elif layer.type == GRAY_IMAGE:
+ n_channels = 1
+ elif layer.type == GRAYA_IMAGE:
+ n_channels = 2
+ else:
+ raise ValueError("Unsupportet channels")
+
+ #pixels = layer.get_pixel(x, y)
+ #pixels = pixbuf.get_pixels()
+ #rowstride = pixbuf.get_rowstride()
+ pixel_region = layer.get_pixel_rgn(0, 0, layer.width, layer.height, False, False)
+
+
+
+
+
+
+ #pixChars=pixel_region[:,:]
+ #bpp=pixel_region.bpp
+ #return np.frombuffer(pixChars,dtype=np.uint8).reshape(1,1,bpp)
+
+ # Get the rowstride from the pixel region
+ #rowstride = pixel_region.rowstride
+ #n_channels = pixbuf.get_n_channels()
+
+ #offset = y * pixel_region.rowstride + x * n_channels
+ #pixel_data = pixel_region[offset:offset + n_channels]
+
+ pixel_data = pixel_region[0:width, 0:height]
+
+ width, height = layer.width, layer.height
+ rowstride = width * n_channels
+ #for y in range(height):
+ row_start = y * rowstride
+ row_end = row_start + width * n_channels
+ row_data = pixel_data[row_start:row_end]
+ #for x in range(width):
+ r = row_data[x * n_channels]
+ g = row_data[x * n_channels + 1]
+ b = row_data[x * n_channels + 2]
+ #a = row_data[x * n_channels + 3]
+
+ #if layer.type == RGB_IMAGE or layer.type == RGBA_IMAGE:
+ # # Dla RGB/RGBA (R, G, B) lub (R, G, B, A)
+ # return tuple(byte for byte in pixel_data)
+ #elif layer.type == GRAY_IMAGE or layer.type == GRAYA_IMAGE:
+ # Dla Grayscale
+ # return tuple(byte for byte in pixel_data)
+ #else:
+ # raise ValueError("Unsupported type layer")
+
+ #red = pixels[offset]
+ #green = pixels[offset + 1]
+ #blue = pixels[offset + 2]
+ #alpha = pixels[offset + 3] if n_channels == 4 else 255
+
+ #return (red, green, blue, alpha)
+ #return (red, green, blue)
+
+ #if r.isdigit() and g.isdigit() and b.isdigit():
+ # if r != 0 and g != 0 and b != 0:
+ # return (r, g, b)
+ #return (0, 0, 0)
+
+ #return float(''.join(map(str, (r, g, b))))
+ #if r.isdigit() and g.isdigit() and b.isdigit():
+ #if r != 0 and g != 0 and b != 0:
+ #res=""
+ #for i in (r, g, b):
+ # res+=str(i) #str
+ # #return int(res)
+ #return res
+ return (r, g, b)
+
+
+def sincos_func( data, sincos):
+
+ h = True
+ angle1 = 0.1
+ angle2 = 0.1
+ width = len(data[0])
+ height = len(data)
+ m = int(width / 6.666666667)+1
+ print("MNOZNIK: " +str(m))
+ for y in range(0, height):
+
+ for x in range(0, width):
+ mod1 = x % 30
+ if mod1 == 0:
+ angle1 *= -1
+ mod2 = x % 30
+ if mod2 == 0:
+ if h == True:
+ angle1 = 0.1
+ h = False
+ else:
+ angle1 = -0.1
+ h = True
+
+ if h == True:
+ angle1 += -0.1
+ else:
+ angle1 += 0.1
+
+
+
+
+ lineX = int(10*math.sin(angle1) + x)
+ lineY = int(10*math.sin(angle1) + y)
+ #lineY = int(25*math.sin(angle1) + y*math.cos(angle1))
+ #lineX = int(25*math.sin(angle1) + x*math.cos(angle1))
+ #print ("lineX: " + str(lineX) + " lineY: " + str(lineY))
+ if lineX >= width:
+ continue
+ if lineY >= height:
+ continue
+ if lineX < 0:
+ continue
+ if lineY < 0:
+ continue
+
+ #if x >= width:
+ # continue
+ #if y >= height:
+ # continue
+ ##else:
+ # print ("ZA: "+ str(x) + " " + str(y))
+ #sincos[lineY][lineX] = (data[y][x][0], data[y][x][1], data[y][x][2])
+ sincos[y][x] = (data[lineY][lineX][0], data[lineY][lineX][1], data[lineY][lineX][2])
+
+def create_pixbuf_from_rgb_tuples(drawable, colors, width, height):
+
+ #pixels = bytearray()
+ x = 0
+ y = 0
+ pixels = bytearray()
+ for row in colors:
+ for color in row:
+ r, g, b = color # Rozpakuj krotke (R, G, B)
+ #pixels.extend([r, g, b])
+
+
+ # Ustawienie koloru pierwszego planu (np. czerwony)
+ if r == u"\xef" or g == u"\xef" or b == u"\xef":
+ continue
+ pdb.gimp_context_set_foreground(float(r), float(g), float(b))
+
+ # Wybor pedzla (np. "Circle (11)")
+ pdb.gimp_context_set_brush("Circle (01)")
+
+ # Rysowanie linii od punktu (50, 50) do punktu (450, 450)
+ points = [x, y, x, y]
+ pdb.gimp_paintbrush_default(drawable, len(points), points)
+ x += 1
+ print("LINIA: " + str(y))
+ x = 0
+ y += 1
+
+ """
+ # Pobieranie regionu do edycji
+ region = drawable.get_pixel_rgn(0, 0, width, height, True, True)
+
+ for row in colors:
+ for color in row:
+ #index = y * width + x
+ #if index < len(color):
+ #r, g, b = rgb_list[index]
+ r, g, b = color # Rozpakuj krotke (R, G, B)
+ #pixels.extend([r, g, b])
+
+ region[x, y] = chr(r) + chr(g) + chr(b)
+ #else:
+ #region[x, y] = chr(0) + chr(0) + chr(0)
+ x += 1
+ x = 0
+ y += 1
+ drawable.flush()
+ drawable.update(0, 0, width, height)
+ """
+
+ #return pixbuf
+
+def plugin_func(image, drawable, args):
+
+ width = image.width
+ height = image.height
+ duplicate_image = pdb.gimp_image_duplicate(image)
+ #duplicate_drawable = pdb.gimp-image-get-active-drawable(duplicate_image)
+ duplicate_drawable = duplicate_image.active_layer
+
+ # Dodaj skopiowany obraz do listy obrazow w GIMPie
+ #gimp.Display(duplicate_image)
+ #pdb.gimp-selection-none(duplicate_image)
+ #pdb.gimp-context-push()
+ #pdb.gimp-context-set-defaults()
+ grid = []
+ for y in range (0, height):
+ pix_width = []
+ for x in range (0, width):
+ pix_width.append(get_pixel_color(duplicate_drawable, x, y))
+ #pix_width.append(drawable.get_pixel(x, y))
+ grid.append(pix_width)
+ print(grid)
+ print("GET: " +str(y))
+
+ sincos = []
+ for y in range (0, height):
+ pix_width = []
+ for x in range (0, width):
+ pix_width.append((255, 255, 255))
+ sincos.append(pix_width)
+
+ sincos_func(grid, sincos)
+
+ #new_image = gimp.Image(width, height, RGB)
+ #layer = gimp.Layer(new_image, "New Layer", width, height, RGB_IMAGE, 100, NORMAL_MODE)
+ #new_image.add_layer(layer, 0)
+
+
+ create_pixbuf_from_rgb_tuples(duplicate_drawable, sincos, width, height)
+ #pdb.gimp-context-pop()
+
+ #pdb.gimp_displays_flush()
+ duplicate_drawable.flush()
+ duplicate_drawable.update(0, 0, width, height)
+ display = gimp.Display(duplicate_image)
+ pdb.gimp_displays_flush()
+
+whoiam='\n'+os.path.abspath(sys.argv[0])
+
+register(
+ "przem-waved-cubism",
+ N_("Make waved cubism on image")+whoiam,
+ "Tworzy kubistyczne falowanie na obrazie",
+ "Przemyslaw R. Pietraszczyk",
+ "Public Domain",
+ "2025-03-04",
+ N_("Waved Cubism"),
+ "RGB*,GRAY*",
+ [
+ (PF_IMAGE, "image", "Input image", None), # type, name, description, default
+ (PF_DRAWABLE, "drawable", "Input drawable", None),
+ (PF_STRING, "arg", "The argument", "default-value"),
+ ],
+ [],
+ plugin_func,
+ menu="<Image>/Filters/PIETRASZCZYK/",
+ #domain=("gimp30-python", gimp.locale_directory)
+)
+
+main()
diff --git a/python-fu/3.0.0RC2/przem-waved-cubism/przem-waved-cubism.py b/python-fu/3.0.0RC2/przem-waved-cubism/przem-waved-cubism.py
new file mode 100755
index 0000000..4a3070f
--- /dev/null
+++ b/python-fu/3.0.0RC2/przem-waved-cubism/przem-waved-cubism.py
@@ -0,0 +1,244 @@
+#!/usr/bin/env python3
+# przem-waved-cubism - filtr dodający efekt falowania obrazu
+# 2025-03-04 © Przemysław R. Pietraszczyk
+# licencja: Public Domain
+# edytor: Geany
+# ver. 2.250306-0~beta
+
+import gi
+gi.require_version('Gimp', '3.0')
+from gi.repository import Gimp
+gi.require_version('GimpUi', '3.0')
+from gi.repository import GimpUi
+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 time
+import sys
+import math
+
+def N_(message): return message
+def _(message): return GLib.dgettext(None, message)
+
+def sincos_func( data, sincos):
+
+ h = True
+ angle1 = 0.1
+ angle2 = 0.1
+ width = len(data[0])
+ height = len(data)
+ for y in range(0, height):
+
+ for x in range(0, width):
+ mod1 = x % 25
+ if mod1 == 0:
+ angle1 *= -1
+ mod2 = x % 25
+ if mod2 == 0:
+ if h == True:
+ angle1 = 0.1
+ h = False
+ else:
+ angle1 = -0.1
+ h = True
+
+ if h == True:
+ angle1 += -0.1
+ else:
+ angle1 += 0.1
+
+
+
+
+ lineX = int(10*math.sin(angle1) + x)
+ lineY = int(10*math.sin(angle1) + y)
+
+ print ("lineX: " + str(lineX) + " lineY: " + str(lineY))
+ if lineX >= width:
+ continue
+ if lineY >= height:
+ continue
+ if lineX < 0:
+ continue
+ if lineY < 0:
+ continue
+
+ #if x >= width:
+ # continue
+ #if y >= height:
+ # continue
+ ##else:
+ # print ("ZA: "+ str(x) + " " + str(y))
+ #sincos[lineY][lineX] = (data[y][x][0], data[y][x][1], data[y][x][2])
+ sincos[y][x] = (data[lineY][lineX][0], data[lineY][lineX][1], data[lineY][lineX][2])
+"""
+def get_pixel_color(pixbuf, x, y):
+ # Pobierz szerokość i wysokość obrazu
+ width = pixbuf.get_width()
+ height = pixbuf.get_height()
+
+ # Sprawdź, czy współrzędne są w granicach obrazu
+ if x < 0 or x >= width or y < 0 or y >= height:
+ raise ValueError("Współrzędne poza zakresem obrazu")
+
+ # Pobierz dane pikseli
+ pixels = pixbuf.get_pixels()
+ rowstride = pixbuf.get_rowstride()
+ n_channels = pixbuf.get_n_channels()
+
+ # Oblicz pozycję piksela w danych
+ offset = y * rowstride + x * n_channels
+
+
+ # Pobierz wartości kanałów koloru (R, G, B, A)
+ red = pixels[offset]
+ green = pixels[offset + 1]
+ blue = pixels[offset + 2]
+ alpha = pixels[offset + 3] if n_channels == 4 else 255
+
+ #return (red, green, blue, alpha)
+ return (red, green, blue)
+"""
+
+def create_pixbuf_from_rgb_tuples(drawable, colors, width, height):
+ # Sprawdź, czy liczba kolorów odpowiada wymiarom obrazu
+ #if len(colors) != width * height:
+ # raise ValueError("Liczba kolorów musi być równa width * height")
+
+ # Przekształć krotki RGB na dane pikseli
+ pixels = bytearray()
+ x = 0
+ y = 0
+ for row in colors:
+ for color in row:
+ r, g, b = color # Rozpakuj krotkę (R, G, B)
+ pixels.extend([r, g, b])
+
+
+ # Ustawienie koloru pierwszego planu (np. czerwony)
+ #pdb.gimp_context_set_foreground((r, g, b))
+ Gimp.context_set_foreground((r, g, b))
+
+ # Wybór pędzla (np. "Circle (11)")
+ #pdb.gimp_context_set_brush("Circle (01)")
+ Gimp.context_set_brush("Circle (01)")
+
+ # Rysowanie linii od punktu (50, 50) do punktu (450, 450)
+ #pdb.gimp_paintbrush_default(drawable, 2, [x, y, x, y])
+ Gimp.paintbrush_default(drawable, 2, [x, y, x, y])
+
+ x += 1
+ x = 0
+ y += 1
+
+
+
+
+
+ #return pixbuf
+
+def plugin_func(procedure, run_mode, image, drawable, config, data):
+
+ width = image.width
+ height = image.height
+ #duplicate_image = pdb.gimp_image_duplicate(image)
+ #duplicate_drawable = pdb.gimp-image-get-active-drawable(duplicate_image)
+
+ if run_mode == Gimp.RunMode.INTERACTIVE:
+ GimpUi.init('przem-waved-cubism')
+
+ dialog = GimpUi.ProcedureDialog(procedure=procedure, config=config)
+ dialog.fill(None)
+ if not dialog.run():
+ dialog.destroy()
+ return procedure.new_return_values(Gimp.PDBStatusType.CANCEL, GLib.Error())
+ else:
+ dialog.destroy()
+
+ color = config.get_property('color')
+
+
+
+ # Dodaj skopiowany obraz do listy obrazów w GIMPie
+ #gimp.Display(duplicate_image)
+
+ Gimp.context_push()
+ image.undo_group_start()
+
+ #pdb.gimp-selection-none(duplicate_image)
+ #pdb.gimp-context-push()
+ #pdb.gimp-context-set-defaults()
+ grid = []
+ for y in range (0, height):
+ pix_width = []
+ for x in range (0, width):
+ #pix_width.append(get_pixel_color(duplicate_drawable, x, y))
+ pix_width.append(drawable.get_pixel(x, y))
+ grid.append(pix_width)
+
+ sincos = []
+ for y in range (0, height):
+ pix_width = []
+ for x in range (0, width):
+ pix_width.append((0, 0, 0))
+ sincos.append(pix_width)
+
+ sincos_func(grid, sincos)
+ create_pixbuf_from_rgb_tuples(drawable, sincos, width, height)
+
+ Gimp.displays_flush()
+
+ image.undo_group_end()
+ Gimp.context_pop()
+
+
+ return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())
+
+
+
+class WavedCubism (Gimp.PlugIn):
+ ## GimpPlugIn virtual methods ##
+ def do_set_i18n(self, procname):
+ return True, 'gimp30-python', None
+
+ def do_query_procedures(self):
+ return ['przem-waved-cubism']
+
+ def do_create_procedure(self, name):
+ Gegl.init(None)
+
+ _color = Gegl.Color.new("black")
+ _color.set_rgba(0.94, 0.71, 0.27, 1.0)
+
+ procedure = Gimp.Procedure.new(self, name,
+ Gimp.PDBProcType.PLUGIN,
+ plugin_func, None)
+
+ if procedure is not None:
+
+ procedure.set_image_types("RGB*, GRAY*")
+
+
+ procedure.set_menu_label(_("Make waved cubism on image"))
+ procedure.set_documentation ('Make waved cubism on image',
+ 'Make waved cubism on image',
+ name)
+
+ procedure.set_attribution("Przemysław R. Pietraszczyk",
+ "Public Domain", "2025-03-04")
+
+
+ #procedure.add_string_argument ("name", _("Layer _name"), _("Layer name"),
+ # _("Clouds"), GObject.ParamFlags.READWRITE)
+
+ procedure.add_color_argument ("color", _("_BG color"), _("BG color"),
+ True, _color, GObject.ParamFlags.READWRITE)
+
+ procedure.add_menu_path ("<Image>/Filters/PIETRASZCZYK")
+
+ return procedure
+
+Gimp.main(WavedCubism.__gtype__, sys.argv)
+