-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
671 lines (582 loc) · 24.7 KB
/
Copy pathmain.py
File metadata and controls
671 lines (582 loc) · 24.7 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
import tkinter as tk
from tkinter import *
from tkinter.ttk import Button, Checkbutton, Spinbox, LabeledScale, Progressbar
from tkinter.filedialog import askopenfilename, asksaveasfilename
from tkinter.messagebox import showerror, askyesno
from tkinter.simpledialog import askinteger
from tkinter.colorchooser import askcolor
from PIL import Image, ImageDraw, ImageTk
import numpy as np
import filters
import threading
import os
filters.set_threads(max(1, os.cpu_count() - 1))
extentions = [("All images", ("*.png", "*.jpg", "*.jpeg", "*.gif", "*.webp", "*.bmp", "*.ico")), ("PNG", "*.png"),
("JPG", ("*.jpg", "*.jpeg")), ("GIF", "*.gif"), ("WEBP", "*.webp"), ("BMP", "*.bmp"), ("ICO", "*.ico")]
im = Image.new("RGBA", (500, 500))
arr = np.asarray(im, dtype=np.uint8)
undoredo = []
curr_undoredo = -1
path = None
selection = [0, 0, im.width - 1, im.height - 1]
buttons = []
draw_mode = False
draw_color = (0, 0, 0, 0)
draw_overlay = False
draw_size = 1
draw_orig = Image.new("RGBA", (1, 1))
draw_im = Image.new("RGBA", (1, 1))
draw_last_xy = (0, 0)
progressbar_shown = False
task_running = False
shown = None
frame = 0
speed = 75
class ColorVar:
def __init__(self, value=(0, 0, 0, 0)):
self.value = value
self.traces = []
def trace_add(self, _, func):
self.traces.append(func)
def get(self):
return self.value
def set(self, value):
self.value = value
for trace in self.traces:
trace(0, 0, 0)
class Colorbutton(tk.Button):
def __init__(self, *args, **kwargs):
if "variable" in kwargs:
self.variable = kwargs["variable"]
del kwargs["variable"]
else:
self.variable = ColorVar()
self.command = None
if "command" in kwargs:
self.command = kwargs["command"]
del kwargs["command"]
# noinspection PyStringFormat
super().__init__(command=self.onclick, bg="#%02x%02x%02x" % self.variable.get()[:3], width=10, *args, **kwargs)
def onclick(self):
color = askcolor(self.variable.get()[:3])
if color[0] is not None:
# noinspection PyUnresolvedReferences
self.variable.set(color[0] + (0,))
self.config(bg=color[1])
if self.command is not None:
self.command()
class ImageVar:
def __init__(self, value):
self.value = value
self.traces = []
def trace_add(self, _, func):
self.traces.append(func)
def get(self):
return self.value
def set(self, value):
self.value = value
for trace in self.traces:
trace(0, 0, 0)
class Imagebutton(Button):
def __init__(self, *args, **kwargs):
if "variable" in kwargs:
self.variable = kwargs["variable"]
del kwargs["variable"]
else:
self.variable = ImageVar(np.asarray([[(0, 0, 0, 0)]]))
self.pathvar = StringVar(value="")
self.command = None
if "command" in kwargs:
self.command = kwargs["command"]
del kwargs["command"]
super().__init__(command=self.onclick, textvariable=self.pathvar, *args, **kwargs)
def onclick(self):
path_ = askopenfilename(title="Open - Image Editor", filetypes=extentions)
if path_:
self.pathvar.set(path_)
self.variable.set(np.asarray(Image.open(path_).convert("RGBA"), dtype=np.uint8))
if self.command is not None:
self.command()
class MatrixVar:
def __init__(self, value):
self.value = value
self.traces = []
def trace_add(self, _, func):
self.traces.append(func)
def get(self):
return self.value
def set(self, value):
self.value = value
for trace in self.traces:
trace(0, 0, 0)
class Matrixbutton(Button):
def __init__(self, *args, **kwargs):
if "variable" in kwargs:
self.variable = kwargs["variable"]
del kwargs["variable"]
else:
self.variable = MatrixVar([[0 for _ in range(5)] for _ in range(5)])
self.command = None
if "command" in kwargs:
self.command = kwargs["command"]
del kwargs["command"]
super().__init__(command=self.onclick, *args, **kwargs)
def onclick(self):
dlg = Toplevel(root)
dlg.title("Matrix - Image Editor")
newmatrix = [[DoubleVar(value=self.variable.get()[idx][jdx]) for jdx in range(5)] for idx in range(5)]
for idx in range(5):
for jdx in range(5):
Spinbox(dlg, from_=-1000, to=1000, width=5, textvariable=newmatrix[idx][jdx]).grid(
row=idx, column=jdx)
def onok():
self.variable.set([[newmatrix[idx][jdx].get() for jdx in range(5)] for idx in range(5)])
dlg.destroy()
Button(dlg, text="OK", command=onok).grid(row=5, column=0, columnspan=2)
Button(dlg, text="Reset", command=lambda: [[newmatrix[idx][jdx].set(0) for jdx in range(5)]
for idx in range(5)]).grid(row=5, column=2)
Button(dlg, text="Cancel", command=dlg.destroy).grid(row=5, column=3, columnspan=2)
dlg.bind("<Return>", lambda e: onok())
dlg.bind("<Escape>", lambda e: dlg.destroy())
dlg.transient(root)
dlg.grab_set()
dlg.focus_set()
dlg.update()
width, height = map(int, dlg.geometry().split("+")[0].split("x"))
dlg.geometry(f"{width}x{height}+{root.winfo_screenwidth() // 2 - width // 2}"
f"+{root.winfo_screenheight() // 2 - width // 2}")
dlg.wait_window(root)
if self.command is not None:
self.command()
class Filter(Frame):
def __init__(self, master=None, btnmaster=None, name="", options=None, func=None, row=0, column=0, auto_apply=False,
onclick=None, *args, **kwargs):
super().__init__(master, *args, **kwargs)
if options is None:
options = {}
self.init = False
self.func = func
self.row = row
self.column = column
self.onclick_func = onclick
self.shown = False
filtermenu.add_command(label=name, command=self.onclick)
Button(btnmaster, text=name, command=self.onclick).pack(side="top")
Label(self, text=name).pack(side="left")
self.vars = []
self.validate = []
for idx, pair in enumerate(options.items()):
labelframe = LabelFrame(self, text=pair[0])
labelframe.pack(side="left")
self.vars.append(pair[1][2](value=pair[1][3]))
if auto_apply:
self.vars[-1].trace_add("write", lambda a, b, c: self.apply())
if pair[1][4]:
pair[1][0](labelframe, variable=self.vars[-1], **pair[1][1]).pack(side="left")
else:
pair[1][0](labelframe, textvariable=self.vars[-1], **pair[1][1]).pack(side="left")
self.vars[-1].set(pair[1][3])
if len(pair[1]) > 5:
self.validate.append((idx, pair[1][5], pair[1][6]))
if not auto_apply:
buttons.append(Button(self, text="Apply", command=self.apply))
buttons[-1].pack(side="left")
self.init = True
def onclick(self):
global shown
if self.shown:
self.grid_forget()
shown = None
else:
if shown is not None:
shown.onclick()
self.grid(row=self.row, column=self.column, sticky="w")
shown = self
self.shown = not self.shown
if self.onclick_func is not None:
self.onclick_func(self)
def apply(self):
if task_running or not self.init:
return
for idx in self.validate:
try:
if not (idx[1] <= self.vars[idx[0]].get() <= idx[2]):
showerror("Value out of range", f"Value should be between {idx[1]} and {idx[2]}")
return
except Exception as e:
showerror("Wrong input type", f"Wrong input type:\n{e}")
return
self.func(*[var.get() for var in self.vars])
def change_thread_count():
answer = askinteger(
"Change thread count",
f"How many threads?\nCurrently {filters.get_threads()}\nRecommended {max(1, os.cpu_count() - 1)}")
if answer is not None:
filters.set_threads(answer)
def new_file():
global im, arr, selection, path
path = None
im = Image.new("RGBA", (500, 500))
arr = np.asarray(im, dtype=np.uint8)
selection = [0, 0, im.width - 1, im.height - 1]
add_undoredo()
update_image()
def open_file():
global im, arr, selection, path
path_ = askopenfilename(title="Open - Image Editor", filetypes=extentions)
if path_:
path = path_
im = Image.open(path).convert("RGBA")
arr = np.asarray(im, dtype=np.uint8)
selection = [0, 0, im.width - 1, im.height - 1]
add_undoredo()
update_image()
def save_file():
if path:
if askyesno("Save - Image Editor", f"Do you want to overwrite the original file \"{path}\"?"):
im.save(path)
else:
saveas_file()
def saveas_file():
global path
path_ = asksaveasfilename(title="Save As - Image Editor", filetypes=extentions, defaultextension="png")
if path_:
im.save(path_)
if not path:
path = path_
def update_image():
selection_ = selection.copy()
if selection[0] > selection[2]:
selection_[0], selection_[2] = selection[2], selection[0]
if selection[1] > selection[3]:
selection_[1], selection_[3] = selection[3], selection[1]
img = Image.fromarray(filters.selection(
arr.copy(), frame, left=selection_[0], top=selection_[1], right=selection_[2], bottom=selection_[3]))
newim = Image.fromarray(filters.transparent(np.asarray(Image.new("RGB", im.size, "white"), dtype=np.uint8), 5))
newim.paste(img, (0, 0), img)
lbl.image = ImageTk.PhotoImage(newim)
lbl.config(image=lbl.image)
def select_start(e):
global im, arr, draw_orig, draw_im, draw_last_xy
if draw_mode and not task_running:
if draw_overlay:
draw_orig = im.copy()
draw_im = Image.new("RGBA", im.size)
ImageDraw.ImageDraw(draw_im).circle((e.x, e.y), draw_size, draw_color, width=0)
im = draw_orig.copy()
im.paste(draw_im.convert("RGB"), (0, 0), draw_im)
else:
ImageDraw.ImageDraw(im).circle((e.x, e.y), draw_size, draw_color, width=0)
arr = np.asarray(im, dtype=np.uint8)
update_image()
draw_last_xy = (e.x, e.y)
return
if 0 <= e.x < im.width and 0 <= e.y < im.height:
selection[0] = selection[2] = e.x
selection[1] = selection[3] = e.y
update_image()
def select_drag(e):
global im, arr, draw_last_xy
if draw_mode and not task_running:
if draw_overlay:
draw = ImageDraw.ImageDraw(draw_im)
else:
draw = ImageDraw.ImageDraw(im)
draw.circle((e.x, e.y), draw_size, draw_color, width=0)
draw.line((draw_last_xy, (e.x, e.y)), draw_color, draw_size * 2)
if draw_overlay:
im = draw_orig.copy()
im.paste(draw_im.convert("RGB"), (0, 0), draw_im)
arr = np.asarray(im, dtype=np.uint8)
update_image()
draw_last_xy = (e.x, e.y)
return
if 0 <= e.x < im.width and 0 <= e.y < im.height:
selection[2] = e.x
selection[3] = e.y
update_image()
def select_release(e):
global selection
if draw_mode and not task_running:
add_undoredo()
return
if e.x == selection[0] and e.y == selection[1]:
selection = [0, 0, im.width - 1, im.height - 1]
update_image()
def select_reset():
global selection
selection = [0, 0, im.width - 1, im.height - 1]
update_image()
def draw_start(color, alpha, overlay, size):
global draw_mode, draw_color, draw_overlay, draw_size
if task_running:
return
draw_mode = True
draw_color = color[:3] + (alpha,)
draw_overlay = overlay
draw_size = size
def draw_stop():
global draw_mode
draw_mode = False
def add_undoredo():
global undoredo, curr_undoredo
undoredo = undoredo[:curr_undoredo + 1]
undoredo.append(im.copy())
curr_undoredo += 1
def undo():
global im, arr, selection, curr_undoredo
if curr_undoredo == 0:
return
curr_undoredo -= 1
im = undoredo[curr_undoredo].copy()
arr = np.asarray(im, dtype=np.uint8)
selection = [0, 0, im.width - 1, im.height - 1]
update_image()
def redo():
global im, arr, selection, curr_undoredo
if curr_undoredo == len(undoredo) - 1:
return
curr_undoredo += 1
im = undoredo[curr_undoredo].copy()
arr = np.asarray(im, dtype=np.uint8)
selection = [0, 0, im.width - 1, im.height - 1]
update_image()
def undoredo_reset():
global im, arr, selection, curr_undoredo
if len(undoredo) == 0:
return
curr_undoredo = 0
im = undoredo[curr_undoredo].copy()
arr = np.asarray(im, dtype=np.uint8)
selection = [0, 0, im.width - 1, im.height - 1]
update_image()
def goto_curr():
global im, arr, selection, curr_undoredo
if len(undoredo) == 0:
return
curr_undoredo = len(undoredo) - 1
im = undoredo[curr_undoredo].copy()
arr = np.asarray(im, dtype=np.uint8)
selection = [0, 0, im.width - 1, im.height - 1]
update_image()
def apply_filter(func, *args):
# noinspection PyUnboundLocalVariable
if task_running:
return
for btn in buttons:
btn.config(state="disabled")
def task():
global arr, task_running
task_running = True
selection_ = selection.copy()
if selection[0] > selection[2]:
selection_[0], selection_[2] = selection[2], selection[0]
if selection[1] > selection[3]:
selection_[1], selection_[3] = selection[3], selection[1]
if func == filters.lines:
try:
im.paste(Image.fromarray(func(np.asarray(im.crop(selection_), dtype=np.uint8, copy=True), *args)),
selection_[:2])
exception = None
except Exception as e:
exception = e
else:
try:
im.paste(Image.fromarray(func(np.asarray(im.crop(selection_), dtype=np.uint8), *args)), selection_)
exception = None
except Exception as e:
exception = e
arr = np.asarray(im, dtype=np.uint8)
def after_task():
global task_running
if exception is not None:
if "array([" in str(exception):
showerror(type(exception).__name__, str(exception)[:str(exception).index("array([")] +
"array(..." + str(exception)[str(exception).rindex("]") + 1:])
else:
showerror(type(exception).__name__, str(exception))
add_undoredo()
update_image()
for button in buttons:
button.config(state="normal")
task_running = False
root.after(0, after_task)
threading.Thread(target=task, daemon=True).start()
def apply_crop():
global im, arr, selection
selection_ = selection.copy()
if selection[0] > selection[2]:
selection_[0], selection_[2] = selection[2], selection[0]
if selection[1] > selection[3]:
selection_[1], selection_[3] = selection[3], selection[1]
im = im.crop(selection_)
arr = np.asarray(im, dtype=np.uint8)
selection = [0, 0, im.width - 1, im.height - 1]
add_undoredo()
update_image()
def apply_paste(img_arr):
global im, arr, selection
selection_ = selection.copy()
if selection[0] > selection[2]:
selection_[0], selection_[2] = selection[2], selection[0]
if selection[1] > selection[3]:
selection_[1], selection_[3] = selection[3], selection[1]
img = Image.fromarray(img_arr)
if img.size[0] > selection_[2] - selection_[0]:
img = img.crop((0, 0, selection_[2] - selection_[0], img.size[1]))
if img.size[1] > selection_[3] - selection_[1]:
img = img.crop((0, 0, img.size[0], selection_[3] - selection_[1]))
im.paste(img, (selection_[0], selection_[1]), img)
arr = np.asarray(im, dtype=np.uint8)
add_undoredo()
update_image()
def apply_resize(width, keep_aspect_ratio, height):
global im, arr, selection
if keep_aspect_ratio:
height = width * im.height // im.width
im = im.resize((width, height))
arr = np.asarray(im, dtype=np.uint8)
selection = [0, 0, im.width - 1, im.height - 1]
add_undoredo()
update_image()
def tick():
global frame, progressbar_shown
root.after(speed, tick)
prog = filters.get_progress()
if prog >= 0:
progress.set(prog)
if not progressbar_shown:
progressbar.grid(row=1, column=0, sticky="ne")
progressbar_shown = True
elif progressbar_shown:
progressbar.grid_forget()
progressbar_shown = False
update_image()
frame = (frame + 1)
root = Tk()
root.title("Image Editor")
root.geometry("+0+0")
menu = Menu()
filemenu = Menu(tearoff=0)
filemenu.add_command(label="New", command=new_file, accelerator="Ctrl+N", underline=0)
filemenu.add_command(label="Open", command=open_file, accelerator="Ctrl+O", underline=0)
filemenu.add_command(label="Save", command=save_file, accelerator="Ctrl+S", underline=0)
filemenu.add_command(label="Save as", command=saveas_file, accelerator="Ctrl+Shift+S", underline=5)
settingsmenu = Menu(tearoff=0)
settingsmenu.add_command(label="Change max thread count", command=change_thread_count, underline=11)
filemenu.add_cascade(label="Settings", menu=settingsmenu, underline=2)
menu.add_cascade(label="File", menu=filemenu, underline=0)
editmenu = Menu(tearoff=0)
editmenu.add_command(label="Undo", command=undo, accelerator="Ctrl+Z", underline=0)
editmenu.add_command(label="Redo", command=redo, accelerator=("Ctrl+Shift+Z", "Ctrl+Y"), underline=0)
editmenu.add_command(label="Reset", command=undoredo_reset, underline=1)
editmenu.add_command(label="Go to current", command=goto_curr, underline=6)
menu.add_cascade(label="Edit", menu=editmenu, underline=0)
filtermenu = Menu(tearoff=0)
menu.add_cascade(label="Filters", menu=filtermenu, underline=2)
root.config(menu=menu)
root.bind("<Control-n>", lambda e: new_file())
root.bind("<Control-o>", lambda e: open_file())
root.bind("<Control-s>", lambda e: save_file())
root.bind("<Control-Shift-S>", lambda e: saveas_file())
root.bind("<Control-z>", lambda e: undo())
root.bind("<Control-Shift-Z>", lambda e: redo())
root.bind("<Control-y>", lambda e: redo())
root.bind("<Control-a>", lambda e: select_reset())
root.bind("<Escape>", lambda e: select_reset())
lblframe = Frame()
lblframe.grid(row=1, column=1, sticky="nw", ipadx=0, ipady=0, padx=0, pady=0)
lbl = Label(lblframe)
lbl.image = ImageTk.PhotoImage(im)
lbl.config(image=lbl.image)
lbl.grid(row=0, column=0, sticky="nw", ipadx=0, ipady=0, padx=0, pady=0)
lbl.bind("<Button-1>", select_start)
lbl.bind("<B1-Motion>", select_drag)
lbl.bind("<ButtonRelease>", select_release)
progress = DoubleVar(value=0)
progressbar = Progressbar(lblframe, variable=progress)
btnframe = Frame()
btnframe.grid(row=1, column=0, sticky="n")
Filter(root, btnframe, name="Draw",
options={"color": (Colorbutton, {}, ColorVar, (0, 0, 0, 0), True),
"alpha": (LabeledScale, {"from_": 0, "to": 255}, IntVar, 255, True, 0, 255),
"overlay": (Checkbutton, {"text": "Overlay"}, BooleanVar, True, True),
"size": (Spinbox, {"from_": 1, "to": 100}, IntVar, 10, False, 1, 100)},
func=lambda *args: draw_start(*args), row=0, column=1, auto_apply=True,
onclick=lambda obj: draw_start(*[i.get() for i in obj.vars]) if obj.shown else draw_stop())
Filter(root, btnframe, name="Crop",
options={},
func=apply_crop, row=0, column=1)
Filter(root, btnframe, name="Resize",
options={"width": (Spinbox, {"from_": 0, "to": 1000}, IntVar, 500, False, 0, 1000),
"keep_aspect_ratio": (Checkbutton, {"text": "Keep aspect ratio"}, BooleanVar, True, True),
"height": (Spinbox, {"from_": 0, "to": 1000}, IntVar, 500, False, 0, 1000)},
func=apply_resize, row=0, column=1)
Filter(root, btnframe, name="Paste",
options={"im2": (Imagebutton, {}, ImageVar, np.asarray([[(0, 0, 0, 0)]]), True)},
func=apply_paste, row=0, column=1)
Filter(root, btnframe, name="Gray",
options={"use_alpha": (Checkbutton, {"text": "Use alpha"}, BooleanVar, False, True)},
func=lambda *args: apply_filter(filters.gray, *args), row=0, column=1)
Filter(root, btnframe, name="B&W",
options={"threshold": (Spinbox, {"from_": 0, "to": 255}, IntVar, 127, False, 0, 255),
"reverse": (Checkbutton, {"text": "Reverse"}, BooleanVar, False, True)},
func=lambda *args: apply_filter(filters.black_and_white, *args), row=0, column=1)
Filter(root, btnframe, name="Reverse",
options={"use_alpha": (Checkbutton, {"text": "Use alpha"}, BooleanVar, False, True)},
func=lambda *args: apply_filter(filters.reverse, *args), row=0, column=1)
Filter(root, btnframe, name="Bright noise",
options={"level": (Spinbox, {"from_": 0, "to": 1000}, IntVar, 100, False, 0, 1000),
"use_alpha": (Checkbutton, {"text": "Use alpha"}, BooleanVar, False, True)},
func=lambda *args: apply_filter(filters.brightness_noise, *args), row=0, column=1)
Filter(root, btnframe, name="Color noise",
options={"level": (Spinbox, {"from_": 0, "to": 1000}, IntVar, 100, False, 0, 1000),
"use_alpha": (Checkbutton, {"text": "Use alpha"}, BooleanVar, False, True)},
func=lambda *args: apply_filter(filters.color_noise, *args), row=0, column=1)
Filter(root, btnframe, name="Corners",
options={"top-left": (Colorbutton, {}, ColorVar, (0, 0, 0, 0), True),
"bottom-left": (Colorbutton, {}, ColorVar, (0, 0, 0, 0), True),
"top-right": (Colorbutton, {}, ColorVar, (0, 0, 0, 0), True),
"bottom-right": (Colorbutton, {}, ColorVar, (0, 0, 0, 0), True)},
func=lambda *args: apply_filter(filters.corners, args), row=0, column=1)
Filter(root, btnframe, name="Mirror",
options={},
func=lambda *args: apply_filter(filters.mirror, *args), row=0, column=1)
Filter(root, btnframe, name="Lines",
options={"width": (Spinbox, {"from_": 1, "to": 1000}, IntVar, 10, False, 1, 1000)},
func=lambda *args: apply_filter(filters.lines, *args), row=0, column=1)
Filter(root, btnframe, name="Turn",
options={"count": (Spinbox, {"from_": 2, "to": 1000}, IntVar, 5, False, 2, 1000)},
func=lambda *args: apply_filter(filters.turn, *args), row=0, column=1)
Filter(root, btnframe, name="Curtain",
options={},
func=lambda *args: apply_filter(filters.curtain, *args), row=0, column=1)
Filter(root, btnframe, name="Dots",
options={"im2": (Imagebutton, {}, ImageVar, np.asarray([[(0, 0, 0, 0)]]), True)},
func=lambda *args: apply_filter(filters.dots, *args), row=0, column=1)
Filter(root, btnframe, name="Color swap",
options={"first": (Spinbox, {"from_": 0, "to": 3}, IntVar, 0, False, 0, 3),
"second": (Spinbox, {"from_": 0, "to": 3}, IntVar, 1, False, 0, 3),
"reverse": (Checkbutton, {"text": "Reverse"}, BooleanVar, False, True)},
func=lambda *args: apply_filter(filters.channel_swap, *args), row=0, column=1)
Filter(root, btnframe, name="Matrix",
options={"matrix": (Matrixbutton, {"text": "Matrix..."}, MatrixVar, [[0 for _ in range(5)] for _ in range(5)],
True)},
func=lambda *args: apply_filter(filters.matrix, *args), row=0, column=1)
Filter(root, btnframe, name="Blur",
options={"level": (Spinbox, {"from_": 0.1, "to": 25.0}, DoubleVar, 1, False, 0.1, 25.0)},
func=lambda *args: apply_filter(filters.blur, *args), row=0, column=1)
Filter(root, btnframe, name="Sharp",
options={"level": (Spinbox, {"from_": 9, "to": 1000}, DoubleVar, 9, False, 9, 1000)},
func=lambda *args: apply_filter(filters.sharp, *args), row=0, column=1)
Filter(root, btnframe, name="Median",
options={"size": (Spinbox, {"from_": 2, "to": 1000}, IntVar, 5, False, 2, 1000)},
func=lambda *args: apply_filter(filters.median, *args), row=0, column=1)
Filter(root, btnframe, name="Bright",
options={"size": (Spinbox, {"from_": 2, "to": 1000}, IntVar, 5, False, 2, 1000)},
func=lambda *args: apply_filter(filters.bright, *args), row=0, column=1)
Filter(root, btnframe, name="Dim",
options={"size": (Spinbox, {"from_": 2, "to": 1000}, IntVar, 5, False, 2, 1000)},
func=lambda *args: apply_filter(filters.dim, *args), row=0, column=1)
root.after(speed, tick)
root.mainloop()