From 2c178c1afe7f81f089255fdd3cb79ffb1ea6d2bb Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Wed, 10 Jan 2024 10:17:05 -0300 Subject: [PATCH] [Added] New 2color mode - Needed for people that have problems to distinguish between red/green/black - Bumped version to 2.5.3 --- CHANGELOG.md | 4 ++++ debian/changelog | 8 ++++++- kicad-diff-init.py | 2 +- kicad-diff.py | 56 +++++++++++++++++++++++++++++++++++++++++----- kicad-git-diff.py | 2 +- 5 files changed, 63 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f2c591..937c5e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.5.3] - 2024-01-10 +### Added +* New mode "2color" where you can control the added/removed colors + ## [2.5.2] - 2024-01-09 ### Added * Smarter cache: changing KiCad or --zones option invalidates the cache diff --git a/debian/changelog b/debian/changelog index 98b7326..a419e3c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,10 +1,16 @@ +kidiff (2.5.3-1) stable; urgency=medium + + * Added new mode "2color" where you can control the added/removed colors + + -- Salvador Eduardo Tropea Wed, 10 Jan 2024 09:54:13 -0300 + kidiff (2.5.2-1) stable; urgency=medium * Added Smarter cache: changing KiCad or --zones option invalidates the cache * Fixed KiRi mode for KiCad 5: Plotting the worksheet makes KiCad crash, disabled - -- Salvador Eduardo Tropea Thu, 04 Jan 2024 10:41:43 -0300 + -- Salvador Eduardo Tropea Thu, 09 Jan 2024 10:41:43 -0300 kidiff (2.5.1-1) stable; urgency=medium diff --git a/kicad-diff-init.py b/kicad-diff-init.py index de97441..5c2e593 100755 --- a/kicad-diff-init.py +++ b/kicad-diff-init.py @@ -12,7 +12,7 @@ __copyright__ = 'Copyright 2020, INTI' __credits__ = ['Salvador E. Tropea'] __license__ = 'GPL 2.0' -__version__ = '2.5.2' +__version__ = '2.5.3' __email__ = 'stopea@inti.gob.ar' __status__ = 'beta' __url__ = 'https://github.com/INTI-CMNB/KiDiff/' diff --git a/kicad-diff.py b/kicad-diff.py index 798a249..eb5eebf 100755 --- a/kicad-diff.py +++ b/kicad-diff.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 -# Copyright (c) 2020-2023 Salvador E. Tropea -# Copyright (c) 2020-2023 Instituto Nacional de Tecnologïa Industrial +# Copyright (c) 2020-2024 Salvador E. Tropea +# Copyright (c) 2020-2024 Instituto Nacional de Tecnología Industrial # License: GPL-2.0 # Project: KiCad Diff # Adapted from: https://github.com/obra/kicad-tools @@ -25,10 +25,10 @@ """ __author__ = 'Salvador E. Tropea' -__copyright__ = 'Copyright 2020-2023, INTI/'+__author__ +__copyright__ = 'Copyright 2020-2024, INTI/'+__author__ __credits__ = ['Salvador E. Tropea', 'Jesse Vincent'] __license__ = 'GPL 2.0' -__version__ = '2.5.2' +__version__ = '2.5.3' __email__ = 'salvador@inti.gob.ar' __status__ = 'beta' __url__ = 'https://github.com/INTI-CMNB/KiDiff/' @@ -51,7 +51,7 @@ from struct import unpack from subprocess import call, PIPE, run, STDOUT, CalledProcessError from sys import exit -from tempfile import mkdtemp +from tempfile import mkdtemp, NamedTemporaryFile import time # Exit error codes @@ -451,6 +451,45 @@ def create_diff_stereo(old_name, new_name, diff_name, font_size, layer, resoluti return include +def create_diff_stereo_colored(old_name, new_name, diff_name, font_size, layer, resolution, name_layer, only_different): + """ A more complex version of create_diff_stereo where we can control the colors """ + wn, hn = png_size(new_name) + wo, ho = png_size(old_name) + if wn != wo or hn != ho: + extent = ' -extent {}x{}'.format(max(wn, wo), max(hn, ho)) + extra_name = ' [diff page size]' + else: + extra_name = extent = '' + with NamedTemporaryFile(mode='w', prefix='removed', suffix='.png', delete=False) as f: + removed = f.name + with NamedTemporaryFile(mode='w', prefix='added', suffix='.png', delete=False) as f: + added = f.name + command = ['bash', '-c', + '( convert -threshold 50% "'+new_name+'"'+extent+' miff:- ;' + + ' convert -threshold 50% -negate "'+old_name+'"'+extent+' miff:- ) | ' + + r'convert - -compose darken -composite -negate -fill "'+args.removed_2color+'" ' + + ' -opaque black -transparent white "'+removed+'"'] + run_command(command) + command = ['bash', '-c', + '( convert -threshold 50% -negate "'+new_name+'"'+extent+' miff:- ;' + + ' convert -threshold 50% "'+old_name+'"'+extent+' miff:- ) | ' + + r'convert - -compose darken -composite -negate -fill "'+args.added_2color+'" ' + + ' -opaque black -transparent white "'+added+'"'] + run_command(command) + run_command(['convert', old_name, added, '-composite', removed, '-composite', + '-font', 'helvetica', '-pointsize', font_size, '-draw', + "text 10,"+font_size+" '"+adapt_name(name_layer)+extra_name+"'", + diff_name]) + include = True + if only_different: + res1 = run_command(['identify', '-format', '%k', added]) + res2 = run_command(['identify', '-format', '%k', removed]) + include = res1 == '2' and res2 == '2' + remove(added) + remove(removed) + return include + + def create_diff_stat(old_name, new_name, diff_name, font_size, layer, resolution, name_layer, only_different): wn, hn = png_size(new_name) wo, ho = png_size(old_name) @@ -527,6 +566,9 @@ def DiffImages(old_file_hash, new_file_hash, layers_old, layers_new, only_differ if args.diff_mode == 'red_green': inc = create_diff_stereo(old_name, new_name, diff_name, font_size, layer, resolution, name_layer, only_different) + elif args.diff_mode == '2color': + inc = create_diff_stereo_colored(old_name, new_name, diff_name, font_size, layer, resolution, + name_layer, only_different) else: inc = create_diff_stat(old_name, new_name, diff_name, font_size, layer, resolution, name_layer, only_different) @@ -718,10 +760,11 @@ def get_layer(line): parser.add_argument('old_file', help='Original file (PCB/SCH)') parser.add_argument('new_file', help='New file (PCB/SCH)') + parser.add_argument('--added_2color', help='Color used for added stuff in 2color mode', type=str, default='green') parser.add_argument('--all_pages', help='Compare all the schematic pages', action='store_true') parser.add_argument('--cache_dir', help='Directory to cache images', type=str) parser.add_argument('--diff_mode', help='How to compute the image difference [red_green]', - choices=['red_green', 'stats'], default='red_green') + choices=['red_green', 'stats', '2color'], default='red_green') group = parser.add_mutually_exclusive_group() group.add_argument('--exclude', help='Exclude layers in file (one layer per line)', type=str) parser.add_argument('--force_gs', help='Use Ghostscript even when Poppler is available', action='store_true') @@ -740,6 +783,7 @@ def get_layer(line): parser.add_argument('--only_different', help='Only include the pages with differences', action='store_true') parser.add_argument('--output_dir', help='Directory for the output file', type=str) parser.add_argument('--output_name', help='Name of the output diff', type=str, default='diff.pdf') + parser.add_argument('--removed_2color', help='Color used for removed stuff in 2color mode', type=str, default='red') parser.add_argument('--resolution', help='Image resolution in DPIs [%(default)s]', type=int, default=150) parser.add_argument('--threshold', help='Error threshold for diff stats mode, 0 is no error [%(default)s]', type=thre_type, default=0, metavar='[0-1000000]') diff --git a/kicad-git-diff.py b/kicad-git-diff.py index d3e686e..637e1e6 100755 --- a/kicad-git-diff.py +++ b/kicad-git-diff.py @@ -14,7 +14,7 @@ __copyright__ = 'Copyright 2020, INTI' __credits__ = ['Salvador E. Tropea', 'Jesse Vincent'] __license__ = 'GPL 2.0' -__version__ = '2.5.2' +__version__ = '2.5.3' __email__ = 'salvador@inti.gob.ar' __status__ = 'beta' __url__ = 'https://github.com/INTI-CMNB/KiDiff/'