-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PyDviPng cleanup, added diff-image and run-and-compare
- Loading branch information
1 parent
ac384d8
commit 43e82a7
Showing
7 changed files
with
208 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#! /usr/bin/env python | ||
# -*- python -*- | ||
|
||
#################################################################################################### | ||
# | ||
# PyDvi - A Python Library to Process DVI Stream | ||
# Copyright (C) 2014 Fabrice Salvaire | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
#################################################################################################### | ||
|
||
#################################################################################################### | ||
|
||
import argparse | ||
|
||
import numpy as np | ||
|
||
from PIL import Image | ||
|
||
#################################################################################################### | ||
# | ||
# Options | ||
# | ||
|
||
parser = argparse.ArgumentParser(description='Diff PNG image.') | ||
|
||
parser.add_argument('png_file1', metavar='FILE1.png', | ||
help='PNG File 1') | ||
|
||
parser.add_argument('png_file2', metavar='FILE2.png', | ||
help='PNG File 2') | ||
|
||
parser.add_argument('diff_file', metavar='DIFF.png', | ||
help='Diff PNG File') | ||
|
||
args = parser.parse_args() | ||
|
||
#################################################################################################### | ||
|
||
image1 = Image.open(args.png_file1) | ||
image2 = Image.open(args.png_file2) | ||
|
||
buffer1 = np.array(image1) | ||
buffer2 = np.array(image2) | ||
|
||
dimensions1 = buffer1.shape | ||
dimensions2 = buffer2.shape | ||
|
||
if dimensions1 != dimensions2: | ||
print "Shape mismatch {} versus {}".format(dimensions1, dimensions2) | ||
height1, width1, depth1 = dimensions1 | ||
height2, width2, depth2 = dimensions2 | ||
if depth1 != depth2: | ||
raise NameError("Depth don't match") | ||
depth = depth1 | ||
height = min(height1, height2) | ||
width = min(width1, width2) | ||
buffer1_ = buffer1 | ||
buffer2_ = buffer2 | ||
buffer1 = np.zeros((height, width, depth), dtype=np.uint8) | ||
buffer2 = np.zeros((height, width, depth), dtype=np.uint8) | ||
buffer1 = buffer1_[:height,:width] | ||
buffer2 = buffer2_[:height,:width] | ||
else: | ||
height, width, depth = dimensions1 | ||
|
||
diff_buffer = np.zeros((height, width, depth), dtype=np.uint8) | ||
diff_buffer[:,:,0] = (buffer1 - buffer2)[:,:,0] | ||
diff_buffer[:,:,1] = (buffer2 - buffer1)[:,:,1] | ||
# diff_buffer = np.abs(buffer1 - buffer2) | ||
# diff_buffer = np.xor(buffer1, buffer2) | ||
|
||
mode = 'RGB' | ||
size = width, height | ||
diff_image = Image.frombuffer(mode, size, diff_buffer, 'raw', mode, 0, 1) | ||
diff_image.save(args.diff_file) | ||
|
||
#################################################################################################### | ||
# | ||
# End | ||
# | ||
#################################################################################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#! /bin/bash | ||
|
||
#################################################################################################### | ||
# | ||
# PyDvi - A Python Library to Process DVI Stream | ||
# Copyright (C) 2014 Fabrice Salvaire | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
#################################################################################################### | ||
|
||
#################################################################################################### | ||
|
||
root_dir=`realpath $0` | ||
root_dir=`dirname ${root_dir}` | ||
root_dir=`dirname ${root_dir}` | ||
|
||
dvi_file=`realpath $1` | ||
dpi=600 | ||
|
||
tmp_dir=`mktemp -d` | ||
pushd ${tmp_dir} | ||
|
||
dvipng --truecolor -D ${dpi} -T tight ${dvi_file} -o out-ref.png | ||
${root_dir}/bin/dvi-to-png --tight --dpi=${dpi} ${dvi_file} out.png | ||
${root_dir}/bin/diff-image out-ref.png out.png diff.png | ||
|
||
geeqie diff.png | ||
|
||
rm -rf *.png | ||
popd | ||
rmdir ${tmp_dir} | ||
|
||
#################################################################################################### | ||
# | ||
# End | ||
# | ||
#################################################################################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters