Skip to content

Commit

Permalink
[Added] New 2color mode
Browse files Browse the repository at this point in the history
- Needed for people that have problems to distinguish between red/green/black
- Bumped version to 2.5.3
  • Loading branch information
set-soft committed Jan 10, 2024
1 parent f3014f5 commit 2c178c1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
@@ -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 <salvador@inti.gob.ar> 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 <salvador@inti.gob.ar> Thu, 04 Jan 2024 10:41:43 -0300
-- Salvador Eduardo Tropea <salvador@inti.gob.ar> Thu, 09 Jan 2024 10:41:43 -0300

kidiff (2.5.1-1) stable; urgency=medium

Expand Down
2 changes: 1 addition & 1 deletion kicad-diff-init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
Expand Down
56 changes: 50 additions & 6 deletions kicad-diff.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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/'
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand All @@ -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]')
Expand Down
2 changes: 1 addition & 1 deletion kicad-git-diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
Expand Down

0 comments on commit 2c178c1

Please sign in to comment.