Repository navigation
Expand file tree
/
Copy pathimage_analyzer.py
More file actions
1242 lines (1069 loc) · 54.8 KB
/
Copy pathimage_analyzer.py
File metadata and controls
1242 lines (1069 loc) · 54.8 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
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
"""
╔══════════════════════════════════════════════════════════╗
║ INGEN SYSTEMS — IMAGE FORENSICS WORKSTATION v2.0 ║
║ Classified Analysis Tool — Authorized Personnel Only ║
╚══════════════════════════════════════════════════════════╝
"""
import tkinter as tk
from tkinter import ttk, filedialog, messagebox, scrolledtext
import os
import json
import math
import struct
import hashlib
import colorsys
import io
import traceback
import threading
import time
from datetime import datetime
from collections import Counter
from PIL import Image, ImageTk, ImageFilter, ImageEnhance, ImageOps, ImageDraw
import numpy as np
# ── Palette phosphore ──────────────────────────────────────
C_BG = "#050a05"
C_BG2 = "#0a0f0a"
C_BG3 = "#0f150f"
C_PANEL = "#0d1a0d"
C_BORDER = "#1a3a1a"
C_GREEN = "#00ff41"
C_GREEN2 = "#00cc33"
C_GREEN3 = "#008822"
C_AMBER = "#ffb000"
C_RED = "#ff2222"
C_CYAN = "#00e5ff"
C_WHITE = "#e8ffe8"
C_DIM = "#3a5a3a"
FONT_MONO = ("Courier New", 10)
FONT_MONO_S = ("Courier New", 9)
FONT_MONO_L = ("Courier New", 12, "bold")
FONT_TITLE = ("Courier New", 14, "bold")
EFFECTS_FILE = os.path.join(os.path.dirname(__file__), "effects.json")
# ══════════════════════════════════════════════════════════════
# UTILITIES
# ══════════════════════════════════════════════════════════════
def load_effects():
with open(EFFECTS_FILE, "r", encoding="utf-8") as f:
data = json.load(f)
return data["effects"]
def apply_effect(img: Image.Image, effect: dict) -> Image.Image:
params = effect.get("params", {})
code = effect.get("code", "return img.copy()")
local_ns = {"img": img, "params": params}
# Wrap code in a function to support `return`
wrapped = "def _effect(img, params):\n"
for line in code.splitlines():
wrapped += " " + line + "\n"
exec(wrapped, local_ns)
result = local_ns["_effect"](img, params)
return result
def file_hash(path, algo="md5"):
h = hashlib.new(algo)
with open(path, "rb") as f:
for chunk in iter(lambda: f.read(65536), b""):
h.update(chunk)
return h.hexdigest()
def parse_exif(img: Image.Image) -> dict:
try:
from PIL.ExifTags import TAGS, GPSTAGS
exif_raw = img._getexif()
if not exif_raw:
return {}
decoded = {}
for tag_id, value in exif_raw.items():
tag = TAGS.get(tag_id, str(tag_id))
if tag == "GPSInfo":
gps = {}
for gps_id, gps_val in value.items():
gps_tag = GPSTAGS.get(gps_id, str(gps_id))
gps[gps_tag] = gps_val
decoded["GPS_RAW"] = gps
else:
try:
if isinstance(value, bytes):
value = value.decode("utf-8", errors="replace")
decoded[tag] = str(value)[:200]
except Exception:
pass
return decoded
except Exception:
return {}
def gps_to_decimal(gps_raw: dict):
try:
lat_ref = gps_raw.get("GPSLatitudeRef", "N")
lon_ref = gps_raw.get("GPSLongitudeRef", "E")
lat_vals = gps_raw.get("GPSLatitude", None)
lon_vals = gps_raw.get("GPSLongitude", None)
if not lat_vals or not lon_vals:
return None, None
def to_deg(vals):
d, m, s = vals
# Handle IFDRational or tuples
def to_float(v):
if hasattr(v, 'numerator'):
return v.numerator / v.denominator if v.denominator else 0
if isinstance(v, tuple):
return v[0] / v[1] if v[1] else 0
return float(v)
return to_float(d) + to_float(m) / 60 + to_float(s) / 3600
lat = to_deg(lat_vals)
lon = to_deg(lon_vals)
if lat_ref == "S":
lat = -lat
if lon_ref == "W":
lon = -lon
return lat, lon
except Exception:
return None, None
def dominant_colors(img: Image.Image, n=8):
small = img.convert("RGB").resize((100, 100), Image.LANCZOS)
pixels = list(small.getdata())
quantized = small.quantize(colors=n, method=Image.Quantize.MEDIANCUT)
palette = quantized.getpalette()[:n*3]
colors = []
for i in range(n):
r, g, b = palette[i*3], palette[i*3+1], palette[i*3+2]
colors.append((r, g, b))
return colors
def analyze_image_full(path: str, img: Image.Image) -> dict:
result = {}
# ── File properties ──
stat = os.stat(path)
result["file"] = {
"path": path,
"filename": os.path.basename(path),
"size_bytes": stat.st_size,
"size_human": f"{stat.st_size / 1024:.2f} KB" if stat.st_size < 1_048_576 else f"{stat.st_size / 1_048_576:.2f} MB",
"created": datetime.fromtimestamp(stat.st_ctime).strftime("%Y-%m-%d %H:%M:%S"),
"modified": datetime.fromtimestamp(stat.st_mtime).strftime("%Y-%m-%d %H:%M:%S"),
"md5": file_hash(path, "md5"),
"sha256": file_hash(path, "sha256"),
"format": img.format or "N/A",
"mime": f"image/{(img.format or 'unknown').lower()}",
}
# ── Image properties ──
rgb = img.convert("RGB")
arr = np.array(rgb, dtype=np.float32)
w, h = img.size
result["image"] = {
"width": w,
"height": h,
"megapixels": f"{(w * h) / 1_000_000:.2f} MP",
"aspect_ratio": f"{w/math.gcd(w,h)}:{h/math.gcd(w,h)}",
"mode": img.mode,
"channels": len(img.getbands()),
"has_alpha": "A" in img.getbands(),
"bit_depth": 8 * len(img.getbands()),
"dpi": str(img.info.get("dpi", "N/A")),
"compression": img.info.get("compression", "N/A"),
}
# ── Color analysis ──
r_ch = arr[:,:,0].flatten()
g_ch = arr[:,:,1].flatten()
b_ch = arr[:,:,2].flatten()
mean_r, mean_g, mean_b = r_ch.mean(), g_ch.mean(), b_ch.mean()
gray = arr.mean(axis=2).flatten()
result["colors"] = {
"mean_rgb": f"({mean_r:.1f}, {mean_g:.1f}, {mean_b:.1f})",
"mean_brightness": f"{gray.mean():.1f}/255",
"brightness_pct": f"{gray.mean()/255*100:.1f}%",
"std_dev": f"{gray.std():.2f}",
"contrast_rms": f"{np.sqrt(np.mean((gray - gray.mean())**2)):.2f}",
"dominant_channel": ["Rouge", "Vert", "Bleu"][np.argmax([mean_r, mean_g, mean_b])],
"is_grayscale": bool(np.allclose(r_ch, g_ch, atol=5) and np.allclose(g_ch, b_ch, atol=5)),
"entropy": f"{-np.sum(np.unique(gray.astype(int), return_counts=True)[1]/len(gray) * np.log2(np.unique(gray.astype(int), return_counts=True)[1]/len(gray) + 1e-10)):.3f} bits",
}
dom = dominant_colors(img, 8)
result["colors"]["dominant_palette"] = [f"#{r:02x}{g:02x}{b:02x}" for r, g, b in dom]
# ── EXIF / Metadata ──
exif = parse_exif(img)
gps_raw = exif.pop("GPS_RAW", {})
result["exif"] = exif
result["gps"] = {}
if gps_raw:
lat, lon = gps_to_decimal(gps_raw)
result["gps"]["raw"] = {k: str(v)[:100] for k, v in gps_raw.items()}
if lat is not None:
result["gps"]["latitude"] = f"{lat:.6f}°"
result["gps"]["longitude"] = f"{lon:.6f}°"
result["gps"]["maps_url"] = f"https://www.google.com/maps?q={lat},{lon}"
# ── PNG chunks ──
result["png_chunks"] = {}
if img.format == "PNG":
for key, val in img.info.items():
try:
result["png_chunks"][key] = str(val)[:200]
except Exception:
pass
return result
# ══════════════════════════════════════════════════════════════
# EFFECT EDITOR DIALOG
# ══════════════════════════════════════════════════════════════
class EffectEditorDialog(tk.Toplevel):
def __init__(self, parent, effect=None, on_save=None):
super().__init__(parent)
self.on_save = on_save
self.edit_mode = effect is not None
self.configure(bg=C_BG)
self.title("◈ ÉDITEUR D'EFFET CUSTOM")
self.geometry("720x600")
self.resizable(True, True)
title = "MODIFIER EFFET" if self.edit_mode else "NOUVEL EFFET CUSTOM"
tk.Label(self, text=f"╔ {title} ╗", font=FONT_TITLE,
bg=C_BG, fg=C_GREEN).pack(pady=(16, 8))
frm = tk.Frame(self, bg=C_BG)
frm.pack(fill=tk.BOTH, expand=True, padx=16, pady=8)
def lbl(text, row, col=0):
tk.Label(frm, text=text, font=FONT_MONO_S, bg=C_BG, fg=C_GREEN2,
anchor="w").grid(row=row, column=col, sticky="w", padx=4, pady=2)
lbl("ID (unique, snake_case):", 0)
self.id_var = tk.StringVar(value=effect.get("id", "") if effect else "")
tk.Entry(frm, textvariable=self.id_var, font=FONT_MONO, bg=C_BG3,
fg=C_GREEN, insertbackground=C_GREEN, relief="flat",
highlightthickness=1, highlightcolor=C_GREEN3).grid(
row=0, column=1, sticky="ew", padx=4, pady=2)
lbl("Nom affiché:", 1)
self.name_var = tk.StringVar(value=effect.get("name", "") if effect else "")
tk.Entry(frm, textvariable=self.name_var, font=FONT_MONO, bg=C_BG3,
fg=C_GREEN, insertbackground=C_GREEN, relief="flat",
highlightthickness=1, highlightcolor=C_GREEN3).grid(
row=1, column=1, sticky="ew", padx=4, pady=2)
lbl("Description:", 2)
self.desc_var = tk.StringVar(value=effect.get("description", "") if effect else "")
tk.Entry(frm, textvariable=self.desc_var, font=FONT_MONO, bg=C_BG3,
fg=C_GREEN, insertbackground=C_GREEN, relief="flat",
highlightthickness=1, highlightcolor=C_GREEN3).grid(
row=2, column=1, sticky="ew", padx=4, pady=2)
lbl("Paramètres JSON:", 3)
self.params_var = tk.StringVar(value=json.dumps(effect.get("params", {})) if effect else "{}")
tk.Entry(frm, textvariable=self.params_var, font=FONT_MONO, bg=C_BG3,
fg=C_AMBER, insertbackground=C_AMBER, relief="flat",
highlightthickness=1, highlightcolor=C_GREEN3).grid(
row=3, column=1, sticky="ew", padx=4, pady=2)
frm.columnconfigure(1, weight=1)
tk.Label(frm, text="Code Python (variable 'img': PIL.Image, 'params': dict → return PIL.Image):",
font=FONT_MONO_S, bg=C_BG, fg=C_GREEN2, anchor="w").grid(
row=4, column=0, columnspan=2, sticky="w", padx=4, pady=(8,2))
default_code = effect.get("code", "# Exemple:\n# from PIL import ImageOps\n# return ImageOps.grayscale(img).convert('RGB')") if effect else \
"# Votre effet ici\n# 'img' = PIL.Image.Image\n# 'params' = dict des paramètres\n# Retournez un PIL.Image.Image\nresult = img.copy()\nreturn result"
self.code_text = scrolledtext.ScrolledText(frm, font=("Courier New", 10),
bg="#000a00", fg=C_GREEN,
insertbackground=C_GREEN,
selectbackground=C_GREEN3,
relief="flat", height=14,
wrap=tk.NONE)
self.code_text.grid(row=5, column=0, columnspan=2, sticky="nsew", padx=4, pady=4)
self.code_text.insert("1.0", default_code)
frm.rowconfigure(5, weight=1)
btn_frm = tk.Frame(self, bg=C_BG)
btn_frm.pack(pady=12)
tk.Button(btn_frm, text="[ TESTER ]", font=FONT_MONO, bg=C_BG3,
fg=C_AMBER, activebackground=C_GREEN3, relief="flat",
padx=12, command=self.test_effect).pack(side=tk.LEFT, padx=8)
tk.Button(btn_frm, text="[ SAUVEGARDER ]", font=FONT_MONO, bg=C_BG3,
fg=C_GREEN, activebackground=C_GREEN3, relief="flat",
padx=12, command=self.save_effect).pack(side=tk.LEFT, padx=8)
tk.Button(btn_frm, text="[ ANNULER ]", font=FONT_MONO, bg=C_BG3,
fg=C_RED, activebackground=C_GREEN3, relief="flat",
padx=12, command=self.destroy).pack(side=tk.LEFT, padx=8)
def test_effect(self):
code = self.code_text.get("1.0", tk.END).strip()
try:
test_img = Image.new("RGB", (64, 64), (128, 64, 200))
params = json.loads(self.params_var.get() or "{}")
effect = {"code": code, "params": params}
result = apply_effect(test_img, effect)
messagebox.showinfo("TEST OK",
f"✓ Effet compilé avec succès.\nType retourné: {type(result).__name__}\nTaille: {result.size}")
except Exception as e:
messagebox.showerror("ERREUR", f"Erreur dans le code:\n\n{traceback.format_exc()}")
def save_effect(self):
eid = self.id_var.get().strip()
name = self.name_var.get().strip()
code = self.code_text.get("1.0", tk.END).strip()
if not eid or not name or not code:
messagebox.showerror("ERREUR", "ID, Nom et Code sont obligatoires.")
return
try:
params = json.loads(self.params_var.get() or "{}")
except json.JSONDecodeError:
messagebox.showerror("ERREUR", "Paramètres JSON invalides.")
return
effect = {
"id": eid,
"name": f"[CUSTOM] {name}",
"category": "custom",
"description": self.desc_var.get().strip(),
"params": params,
"code": code,
}
# Save to JSON
with open(EFFECTS_FILE, "r", encoding="utf-8") as f:
data = json.load(f)
existing_ids = [e["id"] for e in data["effects"]]
if eid in existing_ids:
idx = existing_ids.index(eid)
data["effects"][idx] = effect
else:
data["effects"].append(effect)
with open(EFFECTS_FILE, "w", encoding="utf-8") as f:
json.dump(data, f, indent=2, ensure_ascii=False)
if self.on_save:
self.on_save()
messagebox.showinfo("SAUVEGARDÉ", f"Effet '{name}' sauvegardé dans effects.json")
self.destroy()
# ══════════════════════════════════════════════════════════════
# HISTOGRAM CANVAS
# ══════════════════════════════════════════════════════════════
class HistogramCanvas(tk.Canvas):
def __init__(self, parent, **kwargs):
super().__init__(parent, bg=C_BG, highlightthickness=0, **kwargs)
def draw(self, img: Image.Image):
self.delete("all")
w = self.winfo_width() or 280
h = self.winfo_height() or 100
if w < 10 or h < 10:
return
arr = np.array(img.convert("RGB"))
colors_map = [("red", 0, C_RED), ("green", 1, C_GREEN), ("blue", 2, "#4488ff")]
for color_name, ch_idx, color_hex in colors_map:
channel = arr[:, :, ch_idx].flatten()
hist, _ = np.histogram(channel, bins=64, range=(0, 255))
hist = hist / (hist.max() + 1e-6)
points = []
for i, val in enumerate(hist):
x = int(i * w / 64)
y = int(h - val * (h - 4))
points.extend([x, y])
points.extend([w, h, 0, h])
if len(points) >= 4:
self.create_polygon(points, fill="", outline=color_hex, width=1)
# Grid
for i in range(0, w, w//8):
self.create_line(i, 0, i, h, fill=C_BORDER, width=1)
# ══════════════════════════════════════════════════════════════
# MAIN APPLICATION
# ══════════════════════════════════════════════════════════════
class ImageAnalyzerApp(tk.Tk):
def __init__(self):
super().__init__()
self.title("INGEN SYSTEMS — IMAGE FORENSICS WORKSTATION v2.0")
self.configure(bg=C_BG)
self.geometry("1440x900")
self.minsize(1100, 700)
self.img_path: str = None
self.img_original: Image.Image = None
self.img_display: Image.Image = None
self.img_photo: ImageTk.PhotoImage = None
self.analysis_data: dict = {}
self.effects_list: list = []
self.current_effect_id = "none"
self._scan_job = None
self._clock_job = None
self._build_style()
self._build_ui()
self._reload_effects()
self._start_clock()
self._animate_scanline()
# ── Style ──────────────────────────────────────────────────
def _build_style(self):
style = ttk.Style(self)
style.theme_use("clam")
style.configure("TNotebook", background=C_BG, borderwidth=0)
style.configure("TNotebook.Tab", background=C_BG2, foreground=C_DIM,
font=FONT_MONO_S, padding=[12, 4], borderwidth=0)
style.map("TNotebook.Tab",
background=[("selected", C_BG3)],
foreground=[("selected", C_GREEN)])
style.configure("TScrollbar", background=C_BG2, troughcolor=C_BG,
borderwidth=0, arrowcolor=C_GREEN3)
style.configure("Treeview", background=C_BG2, fieldbackground=C_BG2,
foreground=C_GREEN2, rowheight=20, font=FONT_MONO_S)
style.configure("Treeview.Heading", background=C_BG3,
foreground=C_GREEN, font=FONT_MONO_S)
style.map("Treeview", background=[("selected", C_GREEN3)],
foreground=[("selected", C_WHITE)])
# ── UI Layout ──────────────────────────────────────────────
def _build_ui(self):
# ─── Header ───
header = tk.Frame(self, bg=C_BG, height=48)
header.pack(fill=tk.X, side=tk.TOP)
header.pack_propagate(False)
tk.Label(header, text="◈ INGEN SYSTEMS", font=("Courier New", 16, "bold"),
bg=C_BG, fg=C_GREEN).pack(side=tk.LEFT, padx=16, pady=8)
tk.Label(header, text="IMAGE FORENSICS WORKSTATION", font=("Courier New", 11),
bg=C_BG, fg=C_GREEN3).pack(side=tk.LEFT, padx=4, pady=8)
self.clock_var = tk.StringVar(value="")
tk.Label(header, textvariable=self.clock_var, font=FONT_MONO_S,
bg=C_BG, fg=C_DIM).pack(side=tk.RIGHT, padx=16)
self.status_var = tk.StringVar(value="SYSTÈME PRÊT — Chargez une image pour commencer")
tk.Label(header, textvariable=self.status_var, font=FONT_MONO_S,
bg=C_BG, fg=C_AMBER).pack(side=tk.RIGHT, padx=16)
tk.Frame(self, bg=C_BORDER, height=1).pack(fill=tk.X)
# ─── Main paned ───
paned = tk.PanedWindow(self, orient=tk.HORIZONTAL, bg=C_BG,
sashwidth=4, sashrelief="flat", sashpad=0)
paned.pack(fill=tk.BOTH, expand=True)
# ─ Left panel ─
left = tk.Frame(paned, bg=C_PANEL, width=290)
left.pack_propagate(False)
paned.add(left, minsize=240)
self._build_left_panel(left)
# ─ Center panel ─
center = tk.Frame(paned, bg=C_BG)
paned.add(center, minsize=500)
self._build_center_panel(center)
# ─ Right panel ─
right = tk.Frame(paned, bg=C_PANEL, width=360)
right.pack_propagate(False)
paned.add(right, minsize=300)
self._build_right_panel(right)
# ─── Status bar ───
tk.Frame(self, bg=C_BORDER, height=1).pack(fill=tk.X)
sbar = tk.Frame(self, bg=C_BG, height=22)
sbar.pack(fill=tk.X, side=tk.BOTTOM)
sbar.pack_propagate(False)
self.pixel_var = tk.StringVar(value="")
tk.Label(sbar, textvariable=self.pixel_var, font=("Courier New", 8),
bg=C_BG, fg=C_DIM).pack(side=tk.LEFT, padx=8)
# ── Left Panel ────────────────────────────────────────────
def _build_left_panel(self, parent):
tk.Label(parent, text="╔ CONTRÔLES ╗", font=FONT_MONO_S,
bg=C_PANEL, fg=C_GREEN).pack(pady=(12, 4), padx=8, anchor="w")
# Load / Save buttons
btn_cfg = dict(font=FONT_MONO_S, bg=C_BG, fg=C_GREEN,
activebackground=C_GREEN3, activeforeground=C_WHITE,
relief="flat", bd=0, padx=8, pady=4, cursor="hand2")
tk.Button(parent, text="▶ CHARGER IMAGE", command=self._load_image,
**btn_cfg).pack(fill=tk.X, padx=12, pady=3)
tk.Button(parent, text="▼ EXPORTER IMAGE TRAITÉE", command=self._export_image,
**btn_cfg).pack(fill=tk.X, padx=12, pady=3)
tk.Button(parent, text="▼ EXPORTER RAPPORT", command=self._export_report,
**btn_cfg).pack(fill=tk.X, padx=12, pady=3)
tk.Frame(parent, bg=C_BORDER, height=1).pack(fill=tk.X, padx=8, pady=8)
# ─ Effects ─
tk.Label(parent, text="╔ EFFETS IMAGE ╗", font=FONT_MONO_S,
bg=C_PANEL, fg=C_GREEN).pack(pady=(0, 4), padx=8, anchor="w")
self.effect_var = tk.StringVar()
self.effect_combo = ttk.Combobox(parent, textvariable=self.effect_var,
font=FONT_MONO_S, state="readonly")
self.effect_combo.pack(fill=tk.X, padx=12, pady=2)
self.effect_combo.bind("<<ComboboxSelected>>", self._on_effect_change)
self.effect_desc = tk.Label(parent, text="", font=("Courier New", 8),
bg=C_PANEL, fg=C_DIM, wraplength=240,
justify="left", anchor="nw")
self.effect_desc.pack(fill=tk.X, padx=12, pady=(0, 4))
btn_cfg2 = dict(**btn_cfg)
btn_cfg2["fg"] = C_AMBER
tk.Button(parent, text="✎ AJOUTER EFFET CUSTOM",
command=self._add_custom_effect, **btn_cfg2).pack(fill=tk.X, padx=12, pady=2)
tk.Button(parent, text="✎ MODIFIER EFFET SÉLECTIONNÉ",
command=self._edit_selected_effect, **btn_cfg2).pack(fill=tk.X, padx=12, pady=2)
tk.Frame(parent, bg=C_BORDER, height=1).pack(fill=tk.X, padx=8, pady=8)
# ─ Adjustments ─
tk.Label(parent, text="╔ AJUSTEMENTS ╗", font=FONT_MONO_S,
bg=C_PANEL, fg=C_GREEN).pack(pady=(0, 4), padx=8, anchor="w")
sliders_cfg = [
("Luminosité", "brightness", 0.1, 3.0, 1.0),
("Contraste", "contrast", 0.1, 3.0, 1.0),
("Saturation", "saturation", 0.0, 3.0, 1.0),
("Netteté", "sharpness", 0.0, 3.0, 1.0),
]
self.adj_vars = {}
for label, key, lo, hi, default in sliders_cfg:
frm = tk.Frame(parent, bg=C_PANEL)
frm.pack(fill=tk.X, padx=12, pady=1)
tk.Label(frm, text=f"{label}:", font=("Courier New", 8),
bg=C_PANEL, fg=C_DIM, width=10, anchor="w").pack(side=tk.LEFT)
var = tk.DoubleVar(value=default)
self.adj_vars[key] = var
val_lbl = tk.Label(frm, text=f"{default:.1f}", font=("Courier New", 8),
bg=C_PANEL, fg=C_GREEN2, width=4)
val_lbl.pack(side=tk.RIGHT)
sl = tk.Scale(frm, variable=var, from_=lo, to=hi, resolution=0.05,
orient=tk.HORIZONTAL, bg=C_PANEL, fg=C_GREEN2,
troughcolor=C_BG, highlightthickness=0, showvalue=False,
command=lambda v, lbl=val_lbl, k=key: self._on_adj(v, lbl, k))
sl.pack(side=tk.LEFT, fill=tk.X, expand=True)
tk.Button(parent, text="↺ RESET AJUSTEMENTS",
command=self._reset_adjustments, **btn_cfg).pack(fill=tk.X, padx=12, pady=6)
# ─ Histogram ─
tk.Frame(parent, bg=C_BORDER, height=1).pack(fill=tk.X, padx=8, pady=4)
tk.Label(parent, text="╔ HISTOGRAMME ╗", font=FONT_MONO_S,
bg=C_PANEL, fg=C_GREEN).pack(pady=(0, 2), padx=8, anchor="w")
self.hist_canvas = HistogramCanvas(parent, height=90)
self.hist_canvas.pack(fill=tk.X, padx=12, pady=4)
self.hist_canvas.bind("<Configure>", lambda e: self._update_histogram())
# ─ Dominant palette ─
tk.Label(parent, text="PALETTE DOMINANTE:", font=("Courier New", 8),
bg=C_PANEL, fg=C_DIM).pack(anchor="w", padx=12, pady=(4, 0))
self.palette_canvas = tk.Canvas(parent, height=28, bg=C_BG, highlightthickness=0)
self.palette_canvas.pack(fill=tk.X, padx=12, pady=4)
# ── Center Panel ──────────────────────────────────────────
def _build_center_panel(self, parent):
tk.Label(parent, text="╔ VISUALISATION ╗", font=FONT_MONO_S,
bg=C_BG, fg=C_GREEN).pack(anchor="w", padx=12, pady=(8, 0))
# Toolbar
toolbar = tk.Frame(parent, bg=C_BG)
toolbar.pack(fill=tk.X, padx=12, pady=4)
tb_cfg = dict(font=("Courier New", 8), bg=C_BG2, fg=C_GREEN2,
activebackground=C_GREEN3, relief="flat", padx=6, pady=2, cursor="hand2")
self.zoom_var = tk.DoubleVar(value=1.0)
tk.Button(toolbar, text="[-]", command=self._zoom_out, **tb_cfg).pack(side=tk.LEFT, padx=2)
self.zoom_lbl = tk.Label(toolbar, text="100%", font=("Courier New", 8),
bg=C_BG, fg=C_DIM, width=5)
self.zoom_lbl.pack(side=tk.LEFT, padx=2)
tk.Button(toolbar, text="[+]", command=self._zoom_in, **tb_cfg).pack(side=tk.LEFT, padx=2)
tk.Button(toolbar, text="[FIT]", command=self._zoom_fit, **tb_cfg).pack(side=tk.LEFT, padx=2)
tk.Button(toolbar, text="[1:1]", command=self._zoom_100, **tb_cfg).pack(side=tk.LEFT, padx=2)
self.show_grid_var = tk.BooleanVar(value=False)
tk.Checkbutton(toolbar, text="Grille", variable=self.show_grid_var,
bg=C_BG, fg=C_DIM, selectcolor=C_BG2, activebackground=C_BG,
font=("Courier New", 8), command=self._refresh_display).pack(side=tk.LEFT, padx=8)
self.compare_var = tk.BooleanVar(value=False)
tk.Checkbutton(toolbar, text="Comparer (avant/après)", variable=self.compare_var,
bg=C_BG, fg=C_DIM, selectcolor=C_BG2, activebackground=C_BG,
font=("Courier New", 8), command=self._refresh_display).pack(side=tk.LEFT, padx=4)
# Image canvas with scrollbars
canvas_frame = tk.Frame(parent, bg=C_BG)
canvas_frame.pack(fill=tk.BOTH, expand=True, padx=8, pady=4)
self.h_scroll = tk.Scrollbar(canvas_frame, orient=tk.HORIZONTAL, bg=C_BG2)
self.v_scroll = tk.Scrollbar(canvas_frame, orient=tk.VERTICAL, bg=C_BG2)
self.img_canvas = tk.Canvas(canvas_frame, bg="#000500", cursor="crosshair",
highlightthickness=1, highlightbackground=C_BORDER,
xscrollcommand=self.h_scroll.set,
yscrollcommand=self.v_scroll.set)
self.h_scroll.config(command=self.img_canvas.xview)
self.v_scroll.config(command=self.img_canvas.yview)
self.h_scroll.pack(side=tk.BOTTOM, fill=tk.X)
self.v_scroll.pack(side=tk.RIGHT, fill=tk.Y)
self.img_canvas.pack(fill=tk.BOTH, expand=True)
self.img_canvas.bind("<Motion>", self._on_canvas_mouse)
self.img_canvas.bind("<MouseWheel>", self._on_mousewheel)
self.img_canvas.bind("<Configure>", lambda e: self._refresh_display())
# Scanline overlay
self._scanline_y = 0
# Placeholder
self._draw_placeholder()
# ── Right Panel (Tabs) ────────────────────────────────────
def _build_right_panel(self, parent):
tk.Label(parent, text="╔ ANALYSE ╗", font=FONT_MONO_S,
bg=C_PANEL, fg=C_GREEN).pack(pady=(12, 0), padx=8, anchor="w")
notebook = ttk.Notebook(parent)
notebook.pack(fill=tk.BOTH, expand=True, padx=4, pady=4)
def make_tab(label):
frm = tk.Frame(notebook, bg=C_BG2)
notebook.add(frm, text=f" {label} ")
return frm
# Tab: Fichier
tab_file = make_tab("FICHIER")
self.tv_file = self._make_treeview(tab_file)
# Tab: Image
tab_img = make_tab("IMAGE")
self.tv_image = self._make_treeview(tab_img)
# Tab: Couleurs
tab_col = make_tab("COULEURS")
self.tv_colors = self._make_treeview(tab_col)
# Tab: EXIF
tab_exif = make_tab("EXIF")
self.tv_exif = self._make_treeview(tab_exif)
# Tab: GPS
tab_gps = make_tab("GPS")
self._build_gps_tab(tab_gps)
# Tab: PNG
tab_png = make_tab("CHUNKS")
self.tv_png = self._make_treeview(tab_png)
# Tab: Pixel Inspector
tab_px = make_tab("PIXEL")
self._build_pixel_tab(tab_px)
# Tab: Forensique
tab_forensic = make_tab("FORENSIQUE")
self._build_forensic_tab(tab_forensic)
def _make_treeview(self, parent):
frm = tk.Frame(parent, bg=C_BG2)
frm.pack(fill=tk.BOTH, expand=True, padx=4, pady=4)
sb = ttk.Scrollbar(frm)
sb.pack(side=tk.RIGHT, fill=tk.Y)
tv = ttk.Treeview(frm, columns=("val",), show="tree headings",
yscrollcommand=sb.set)
tv.heading("#0", text="Propriété", anchor="w")
tv.heading("val", text="Valeur", anchor="w")
tv.column("#0", width=140, minwidth=100)
tv.column("val", width=180, minwidth=100)
sb.config(command=tv.yview)
tv.pack(fill=tk.BOTH, expand=True)
return tv
def _build_gps_tab(self, parent):
self.tv_gps = self._make_treeview(parent)
self.gps_map_btn = tk.Button(parent, text="▶ OUVRIR DANS GOOGLE MAPS",
font=FONT_MONO_S, bg=C_BG, fg=C_CYAN,
activebackground=C_GREEN3, relief="flat",
command=self._open_maps, state="disabled")
self.gps_map_btn.pack(fill=tk.X, padx=8, pady=4)
def _build_pixel_tab(self, parent):
frm = tk.Frame(parent, bg=C_BG2)
frm.pack(fill=tk.BOTH, expand=True, padx=8, pady=8)
self.px_info = tk.StringVar(value="Survolez l'image pour inspecter les pixels")
tk.Label(frm, textvariable=self.px_info, font=FONT_MONO_S,
bg=C_BG2, fg=C_GREEN2, justify="left", wraplength=300,
anchor="nw").pack(fill=tk.X, pady=4)
self.px_color_canvas = tk.Canvas(frm, height=60, bg=C_BG, highlightthickness=0)
self.px_color_canvas.pack(fill=tk.X, pady=4)
tk.Label(frm, text="Loupe (5×5 pixels):", font=("Courier New", 8),
bg=C_BG2, fg=C_DIM).pack(anchor="w", pady=(8, 2))
self.loupe_canvas = tk.Canvas(frm, width=150, height=150,
bg=C_BG, highlightthickness=1,
highlightbackground=C_GREEN3)
self.loupe_canvas.pack()
def _build_forensic_tab(self, parent):
frm = tk.Frame(parent, bg=C_BG2)
frm.pack(fill=tk.BOTH, expand=True, padx=8, pady=8)
tk.Label(frm, text="ANALYSE FORENSIQUE AUTOMATIQUE", font=FONT_MONO_S,
bg=C_BG2, fg=C_GREEN).pack(anchor="w", pady=(0, 8))
self.forensic_text = scrolledtext.ScrolledText(frm, font=("Courier New", 9),
bg="#000500", fg=C_GREEN2,
insertbackground=C_GREEN,
relief="flat", wrap=tk.WORD)
self.forensic_text.pack(fill=tk.BOTH, expand=True)
tk.Button(frm, text="▶ LANCER ANALYSE FORENSIQUE",
font=FONT_MONO_S, bg=C_BG, fg=C_AMBER,
activebackground=C_GREEN3, relief="flat",
command=self._run_forensic_analysis).pack(fill=tk.X, pady=(6, 0))
# ──────────────────────────────────────────────────────────
# LOGIC
# ──────────────────────────────────────────────────────────
def _start_clock(self):
def tick():
self.clock_var.set(datetime.now().strftime(" [%Y-%m-%d %H:%M:%S]"))
self._clock_job = self.after(1000, tick)
tick()
def _animate_scanline(self):
"""Subtle scanline animation on image canvas"""
if self.img_canvas.winfo_exists():
h = self.img_canvas.winfo_height()
self.img_canvas.delete("scanline")
if h > 0:
y = self._scanline_y % (h + 20)
self.img_canvas.create_line(0, y, 9999, y, fill="#0a1f0a",
width=2, tags="scanline")
self._scanline_y += 3
self.after(60, self._animate_scanline)
def _draw_placeholder(self):
self.img_canvas.delete("all")
w = self.img_canvas.winfo_width() or 600
h = self.img_canvas.winfo_height() or 400
cx, cy = w // 2, h // 2
self.img_canvas.create_text(cx, cy - 20, text="◈ AUCUNE IMAGE CHARGÉE ◈",
font=FONT_TITLE, fill=C_GREEN3)
self.img_canvas.create_text(cx, cy + 20,
text="Cliquez sur ▶ CHARGER IMAGE",
font=FONT_MONO_S, fill=C_DIM)
def _load_image(self):
path = filedialog.askopenfilename(
title="Charger une image",
filetypes=[("Images", "*.jpg *.jpeg *.png *.bmp *.gif *.tiff *.tif *.webp *.ico"),
("Tous fichiers", "*.*")])
if not path:
return
try:
self.img_path = path
self.img_original = Image.open(path)
self.img_original.load()
self.status_var.set(f"CHARGÉ: {os.path.basename(path)}")
self._reset_adjustments()
self._run_analysis()
except Exception as e:
messagebox.showerror("Erreur", f"Impossible d'ouvrir l'image:\n{e}")
def _run_analysis(self):
if not self.img_original:
return
self.status_var.set("ANALYSE EN COURS...")
self.update_idletasks()
try:
self.analysis_data = analyze_image_full(self.img_path, self.img_original)
self._populate_tabs()
self._apply_effect_and_adjustments()
self.status_var.set(f"ANALYSE COMPLÈTE — {os.path.basename(self.img_path)}")
except Exception as e:
self.status_var.set(f"ERREUR: {e}")
messagebox.showerror("Erreur analyse", traceback.format_exc())
def _populate_tabs(self):
d = self.analysis_data
def fill_tv(tv, data: dict, prefix=""):
tv.delete(*tv.get_children())
for k, v in data.items():
if isinstance(v, list):
v = ", ".join(str(x) for x in v)
tv.insert("", tk.END, text=str(k), values=(str(v),))
fill_tv(self.tv_file, d.get("file", {}))
fill_tv(self.tv_image, d.get("image", {}))
colors = d.get("colors", {})
col_display = {k: v for k, v in colors.items() if k != "dominant_palette"}
fill_tv(self.tv_colors, col_display)
fill_tv(self.tv_exif, d.get("exif", {}))
gps = d.get("gps", {})
self.tv_gps.delete(*self.tv_gps.get_children())
gps_flat = {}
for k, v in gps.items():
if isinstance(v, dict):
for kk, vv in v.items():
gps_flat[kk] = str(vv)
else:
gps_flat[k] = str(v)
for k, v in gps_flat.items():
self.tv_gps.insert("", tk.END, text=k, values=(v,))
has_gps = "maps_url" in gps
self.gps_map_btn.config(state="normal" if has_gps else "disabled")
fill_tv(self.tv_png, d.get("png_chunks", {}))
# Dominant palette
self._draw_palette(colors.get("dominant_palette", []))
self._update_histogram()
def _draw_palette(self, colors):
self.palette_canvas.delete("all")
if not colors:
return
w = self.palette_canvas.winfo_width() or 260
bw = max(1, w // len(colors))
for i, hex_color in enumerate(colors):
x0 = i * bw
x1 = x0 + bw
self.palette_canvas.create_rectangle(x0, 0, x1, 28, fill=hex_color, outline="")
self.palette_canvas.create_text(x0 + bw//2, 14, text=hex_color,
font=("Courier New", 6), fill="#000000")
def _update_histogram(self):
img = self.img_display or self.img_original
if img:
self.hist_canvas.draw(img)
def _apply_effect_and_adjustments(self):
if not self.img_original:
return
try:
# Apply selected effect
effect = next((e for e in self.effects_list
if e["id"] == self.current_effect_id), None)
if effect and effect["id"] != "none":
img = apply_effect(self.img_original.convert("RGB"), effect)
else:
img = self.img_original.convert("RGB")
# Apply adjustments
img = ImageEnhance.Brightness(img).enhance(self.adj_vars["brightness"].get())
img = ImageEnhance.Contrast(img).enhance(self.adj_vars["contrast"].get())
img = ImageEnhance.Color(img).enhance(self.adj_vars["saturation"].get())
img = ImageEnhance.Sharpness(img).enhance(self.adj_vars["sharpness"].get())
self.img_display = img
self._refresh_display()
self._update_histogram()
except Exception as e:
self.status_var.set(f"ERREUR EFFET: {e}")
def _refresh_display(self):
self.img_canvas.delete("all")
if not self.img_display:
self._draw_placeholder()
return
cw = self.img_canvas.winfo_width() or 600
ch = self.img_canvas.winfo_height() or 400
zoom = self.zoom_var.get()
if self.compare_var.get() and self.img_original:
# Side by side
half = cw // 2
left_img = self._resize_for_display(self.img_original.convert("RGB"),
half - 2, ch, zoom)
right_img = self._resize_for_display(self.img_display, half - 2, ch, zoom)
combined = Image.new("RGB", (cw, ch), (0, 0, 0))
combined.paste(left_img, (0, (ch - left_img.height) // 2))
combined.paste(right_img, (half + 2, (ch - right_img.height) // 2))
draw = ImageDraw.Draw(combined)
draw.line([(half, 0), (half, ch)], fill=(0, 100, 0), width=2)
self.img_photo = ImageTk.PhotoImage(combined)
self.img_canvas.create_image(0, 0, anchor="nw", image=self.img_photo)
self.img_canvas.create_text(half // 2, 12, text="ORIGINAL",
font=("Courier New", 8), fill=C_DIM)
self.img_canvas.create_text(half + half // 2, 12, text="TRAITÉ",
font=("Courier New", 8), fill=C_GREEN2)
else:
display = self._resize_for_display(self.img_display, cw, ch, zoom)
x = (cw - display.width) // 2
y = (ch - display.height) // 2
self.img_photo = ImageTk.PhotoImage(display)
self.img_canvas.create_image(x, y, anchor="nw", image=self.img_photo)
self._img_offset = (x, y)
self._img_scale = display.width / self.img_display.width
if self.show_grid_var.get():
for x in range(0, cw, 50):
self.img_canvas.create_line(x, 0, x, ch, fill=C_BORDER, width=1)
for y in range(0, ch, 50):
self.img_canvas.create_line(0, y, cw, y, fill=C_BORDER, width=1)
def _resize_for_display(self, img, max_w, max_h, zoom):
w, h = img.size
scale = min(max_w / max(w, 1), max_h / max(h, 1)) * zoom
nw, nh = max(1, int(w * scale)), max(1, int(h * scale))
return img.resize((nw, nh), Image.LANCZOS if scale < 1 else Image.NEAREST)
# ── Zoom ──────────────────────────────────────────────────
def _zoom_in(self):
self.zoom_var.set(min(8.0, self.zoom_var.get() * 1.25))
self.zoom_lbl.config(text=f"{int(self.zoom_var.get()*100)}%")
self._refresh_display()
def _zoom_out(self):
self.zoom_var.set(max(0.05, self.zoom_var.get() / 1.25))
self.zoom_lbl.config(text=f"{int(self.zoom_var.get()*100)}%")
self._refresh_display()
def _zoom_fit(self):
self.zoom_var.set(1.0)
self.zoom_lbl.config(text="FIT")
self._refresh_display()
def _zoom_100(self):
if self.img_display:
cw = self.img_canvas.winfo_width() or 600
ch = self.img_canvas.winfo_height() or 400
w, h = self.img_display.size
scale = min(cw / w, ch / h)
self.zoom_var.set(1.0 / scale)
self.zoom_lbl.config(text="1:1")
self._refresh_display()
def _on_mousewheel(self, event):
if event.delta > 0:
self._zoom_in()
else:
self._zoom_out()
# ── Mouse / Pixel Inspector ────────────────────────────────
def _on_canvas_mouse(self, event):
if not self.img_display:
return
try:
ox, oy = getattr(self, "_img_offset", (0, 0))
scale = getattr(self, "_img_scale", 1.0)
px = int((event.x - ox) / scale)
py = int((event.y - oy) / scale)
w, h = self.img_display.size
if 0 <= px < w and 0 <= py < h:
r, g, b = self.img_display.getpixel((px, py))[:3]
hex_col = f"#{r:02x}{g:02x}{b:02x}"
hue, sat, val = colorsys.rgb_to_hsv(r/255, g/255, b/255)
self.px_info.set(
f"X:{px} Y:{py}\n"
f"RGB: ({r}, {g}, {b})\n"
f"HEX: {hex_col.upper()}\n"
f"HSV: ({int(hue*360)}°, {int(sat*100)}%, {int(val*100)}%)\n"
f"L: {int(0.299*r+0.587*g+0.114*b)}"
)
self.px_color_canvas.delete("all")
self.px_color_canvas.create_rectangle(0, 0, 200, 60, fill=hex_col, outline=C_GREEN3)
lum = 0.299*r+0.587*g+0.114*b