[diffoscope] 01/01: Compare GIF images using gifbuild. (Closes: #857610)
Chris Lamb
chris at chris-lamb.co.uk
Tue Mar 14 09:24:06 UTC 2017
This is an automated email from the git hooks/post-receive script.
lamby pushed a commit to branch experimental
in repository diffoscope.
commit f6f2f29f3f0271d6aefe215b389fe429972eb06f
Author: Chris Lamb <lamby at debian.org>
Date: Tue Mar 14 08:53:30 2017 +0100
Compare GIF images using gifbuild. (Closes: #857610)
Signed-off-by: Chris Lamb <lamby at debian.org>
---
debian/control | 1 +
diffoscope/comparators/__init__.py | 1 +
diffoscope/comparators/gif.py | 54 +++++++++++
diffoscope/external_tools.py | 3 +
tests/comparators/test_gif.py | 50 ++++++++++
tests/data/gif_expected_diff | 181 +++++++++++++++++++++++++++++++++++++
tests/data/test1.gif | Bin 0 -> 1791 bytes
tests/data/test2.gif | Bin 0 -> 793 bytes
8 files changed, 290 insertions(+)
diff --git a/debian/control b/debian/control
index 31d3e0b..0722b25 100644
--- a/debian/control
+++ b/debian/control
@@ -23,6 +23,7 @@ Build-Depends:
fp-utils <!nocheck>,
ghc <!nocheck>,
ghostscript <!nocheck>,
+ giflib-tools <!nocheck>,
imagemagick <!nocheck>,
libjs-jquery <!nocheck>,
libjs-jquery-hotkeys <!nocheck>,
diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index 572e895..baa078f 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -77,6 +77,7 @@ class ComparatorManager(object):
('cbfs.CbfsFile',),
('git.GitIndexFile',),
('openssh.PublicKeyFile',),
+ ('gif.GifFile',),
)
_singleton = {}
diff --git a/diffoscope/comparators/gif.py b/diffoscope/comparators/gif.py
new file mode 100644
index 0000000..eb9467b
--- /dev/null
+++ b/diffoscope/comparators/gif.py
@@ -0,0 +1,54 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2017 Chris Lamb <lamby at debian.org>
+#
+# diffoscope 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.
+#
+# diffoscope 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 diffoscope. If not, see <https://www.gnu.org/licenses/>.
+
+import re
+
+from diffoscope.tools import tool_required
+from diffoscope.difference import Difference
+
+from .utils.file import File
+from .utils.command import Command
+
+
+class Gifbuild(Command):
+ RE_FILTERS = (
+ re.compile(r'^# GIF information from'),
+ re.compile(r'^# End of .* dump'),
+ )
+
+ @tool_required('gifbuild')
+ def cmdline(self):
+ return ['gifbuild', '-d', self.path]
+
+ def filter(self, line):
+ if any(x.match(line.decode('utf-8')) for x in self.RE_FILTERS):
+ return b""
+ return line
+
+
+class GifFile(File):
+ RE_FILE_TYPE = re.compile(r'^GIF image data\b')
+
+ def compare_details(self, other, source=None):
+ return [Difference.from_command(
+ Gifbuild,
+ self.path,
+ other.path,
+ source='gifbuild')m
+ ]
diff --git a/diffoscope/external_tools.py b/diffoscope/external_tools.py
index b05a0d8..f379162 100644
--- a/diffoscope/external_tools.py
+++ b/diffoscope/external_tools.py
@@ -60,6 +60,9 @@ EXTERNAL_TOOLS = {
'debian': 'acl',
'arch': 'acl',
},
+ 'gifbuild': {
+ 'debian': 'giflib-tools',
+ },
'ghc': {
'debian': 'ghc',
'arch': 'ghc',
diff --git a/tests/comparators/test_gif.py b/tests/comparators/test_gif.py
new file mode 100644
index 0000000..bd1915e
--- /dev/null
+++ b/tests/comparators/test_gif.py
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2017 Chris Lamb <lamby at debian.org>
+#
+# diffoscope 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.
+#
+# diffoscope 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 diffoscope. If not, see <https://www.gnu.org/licenses/>.
+
+import pytest
+
+from diffoscope.comparators.gif import GifFile
+
+from utils.data import load_fixture, get_data
+from utils.tools import skip_unless_tools_exist
+from utils.nonexisting import assert_non_existing
+
+gif1 = load_fixture('test1.gif')
+gif2 = load_fixture('test2.gif')
+
+
+def test_identification(gif1):
+ assert isinstance(gif1, GifFile)
+
+def test_no_differences(gif1):
+ difference = gif1.compare(gif1)
+ assert difference is None
+
+ at pytest.fixture
+def differences(gif1, gif2):
+ return gif1.compare(gif2).details
+
+ at skip_unless_tools_exist('gifbuild')
+def test_diff(differences):
+ expected_diff = get_data('gif_expected_diff')
+ assert differences[0].unified_diff == expected_diff
+
+ at skip_unless_tools_exist('gifbuild')
+def test_compare_non_existing(monkeypatch, gif1):
+ assert_non_existing(monkeypatch, gif1, has_null_source=False)
diff --git a/tests/data/gif_expected_diff b/tests/data/gif_expected_diff
new file mode 100644
index 0000000..99b5fe4
--- /dev/null
+++ b/tests/data/gif_expected_diff
@@ -0,0 +1,181 @@
+@@ -1,117 +1,80 @@
+ #
+-screen width 122
+-screen height 80
++screen width 89
++screen height 36
+ screen colors 128
+-screen background 2
++screen background 14
+ pixel aspect byte 0
+
+ screen map
+ sort flag off
+- rgb 254 254 254 is 0
+- rgb 003 003 004 is 1
+- rgb 146 168 206 is 2
+- rgb 091 117 158 is 3
+- rgb 107 139 190 is 4
+- rgb 128 153 195 is 5
+- rgb 183 195 219 is 6
+- rgb 054 101 172 is 7
+- rgb 013 071 157 is 8
+- rgb 150 169 202 is 9
+- rgb 162 178 203 is a
+- rgb 053 061 075 is b
+- rgb 154 170 199 is c
+- rgb 213 221 237 is d
+- rgb 147 168 205 is e
+- rgb 144 167 207 is f
++ rgb 064 131 181 is 0
++ rgb 016 100 162 is 1
++ rgb 239 245 249 is 2
++ rgb 223 234 243 is 3
++ rgb 191 214 230 is 4
++ rgb 032 111 168 is 5
++ rgb 048 121 175 is 6
++ rgb 159 193 218 is 7
++ rgb 207 224 236 is 8
++ rgb 128 173 206 is 9
++ rgb 103 156 195 is a
++ rgb 175 203 224 is b
++ rgb 143 183 212 is c
++ rgb 080 142 187 is d
++ rgb 255 255 255 is e
++ rgb 255 255 255 is f
++end
++
++graphics control
++ disposal mode 0
++ user input flag off
++ delay 0
++ transparent index 15
+ end
+
+ image # 1
+ image left 0
+ image top 0
+-image bits 122 by 80
+-22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
+-22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
+-22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
+-22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
+-22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
+-22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
+-22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
+-22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
+-22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
+-22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
+-22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
+-e2e2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222b1b1b22222
+-eeee222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222223b1bbbb2222
+-e2e222222222224444445222222222225444444222222222222222225444444444444444444444444222222222222222222222222242222151513b2222
+-eeee2e2222222288888872222222222278888885222222222222222278888888888888888888888882222222222253bb352222222212222b21b12b2222
+-eeee2ee22222227888888f222222222248888883222222222222222288888888888888888888888882222222222b111111b522222314222b41513b2222
+-eeee2e2222222248888884222222222228888887222222222222222588888888888888888888888882222222251111111111522221132225b353b52222
+-eeeeeee2222222588888872222222222278888885222222222222223888888888888888888888888722222225111111111111522311b222253b3522222
+-eeeeeee2e2222227888888222222222224888888422222222222222788888888888888888888888852222222b111111111111122111b22222222222222
+-eeeeeeee2222222388888842222222222f88888872222222222222f88888888888888888888888872222222311111111111111b3111122222222222222
+-eeeeee22e2222225888888722222222222788888822222222222224888888744444444438888888f222222211111111111111111111b22222222222222
+-eeeee2e222222222888888822222222222388888842222222222227888888f222222222888888842222222311111113424b11111111522222222222222
+-eeeee222222222227888888522222222225888888722222222222288888872222222223888888722222222b11111b2222225b11111b222222222222222
+-eeeee222222222224888888322222222222788888822222222222488888832222222258888888422222225111113222222222b11115222222222222222
+-eeeee2222222222228888887222222222228888888522222222227888888522222222788888872222222231111b22222222222b11b2222222222222222
+-eeeee2222222222227888888f222222222488888883222222222288888882222222248888888f22222222b111b22222222222251152222222222222222
+-e2222222222222222488888842222222227888888872222222225888888722222222788888832222222221111322222222222223b22222222222222222
+-ee222222222222222f8888887222222222888888888522222222388888842222222388888872222222222111b222222222222222222222222222222222
+-222222222222222222788888822222222588888888842222222278888882222222f8888888422222222241113222222222222222222222222222222222
+-222222222222222222388888842222222388888888872222222f8888887222222278888887222222222231112222222222222222222222222222222222
+-2222222222222222225888888722222227888888888822222224888888422222248888888f2222222222311b2222222222222222222222222222222222
+-2222222222222222222788888822222258888888888842222227888888f222222788888832222222222231132222222222222222222222222222222222
+-22222222222222222227888888522222488888888888722222288888872222224888888874222222222231152222222222222222222222222222222222
+-222222222222222222258888883222227888887888888222224888888322222f8888888888752222222231122222222222222222222222222222222222
+-22222222222222222222888888722222888888488888852222788888852222238888888888883222222231b22222222222222222222222222222222222
+-222222222222222222227888888f2224888888278888832222888888822222238888888888888722222241b22222222222222222222222222222222222
+-22222222222222222222488888842227888887248888872225888888722222238888888888888842222221b22222222222222222222222222222222222
+-22222222222222222222f88888872228888884228888885223888888422222247777888888888885222221b22222222222222222222222222222222222
+-2222222222222222222227888888225888888f22788888422788888822222222222225788888888722222bb22222222222222222222222222222222222
+-222222222222222222222488888842788888722248888872f8888887222222222222222588888888522223b22222222222222222222222222222222222
+-2222222222222222222225888888727888883222f888888248888884222222222222222258888888722222b22222222222222222222222222222222222
+-2222222222222222222222788888858888885222278888847888888f222222222222222223888888822222b22222222222222222222222222222222222
+-2222222222222222222222388888878888872222238888878888887222222222222222222f888888852222522222222222222222222222222222222222
+-22222222222222222222225888888888888722222588888888888832222222222222222222788888842222222222222222222222222222222222222222
+-22222222222222222222222888888888888522222288888888888852222222222222222222388888832222222222222222222222222222222222222222
+-22222222222222222222222788888888888222222278888888888822222222222222222222488888832222222222222222222222222222222222222222
+-22222222222222222222222488888888887222222258888888888722222222222222222222488888872222222222222222222222222222222222222222
+-22222222222222222222222288888888884222222228888888888422222222222222222222488888872222222222222222222222222222222222222222
+-22222222222222222222222278888888882222222227888888888222222222222222222222488888873222222222222222222222222522222222222222
+-22222222222222222222222248888888872222222224888888887222222222222222222222388888873322222222222222222222223322222222222222
+-222222222222222222222222f888888884222222222f888888884222222225222222222222788888835152222222222222222222251b22222222222222
+-2222222222222222222222222788888885222222222278888888f222225788222222222222888888842bb22222222222222222222b1b22222222222222
+-22222222222222222222222223888888722222222222488888872222478888322222222224888888852313222222222222222222311122222222222222
+-222222222222222222222222258888883222222222225888888322223888888522222222288888887222b14222222222222222231111222222222222ff
+-2222222222222222222222222288888852222222222227888885222258888887f222222238888888322231132222222222222231111b2222222222ffff
+-22222222222222222222222222788888222222222222238888822222278888888422222388888888f2222b113222222222222b11111322222222ffffff
+-22222222222222222222222222588887222222222222258888722222258888888873338888888883222225111b3222222223111111b222222222ffffff
+-2222222222222222222222222228888422222222222222888842222222388888888888888888887222222231111133333b1111111122222222ffffffff
+-2222222222222222222222222227888222222222222222788822222222278888888888888888885222222223111111111111111115222222ffffffffff
+-22222222222222222222222222248872222222222222224887222222222f788888888888888885222222222231111111111111115222222fffffffffff
+-222222222222222222222222222f88422222222222222228842222222222278888888888888852222222222223111111111111b5222222ffffffffffff
+-222222222222222222222222222278f222222222222222278f2222222222224888888888887f222222222222225b11111111132222222fffffffffffff
+-2222222222222222222222222222472222222222222222247222222222222222477888873522222222222222222253bbbb34222222222fffffffffffff
+-222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222ffffffffffffff
+-222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222ffffffffffffff
+-222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222ffffffffffffff
+-22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222fffffffffffffff
+-22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222fffffffffffffff
+-22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222ffffffffffff222
+-222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222fffffff2222222
+-222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222fffff222222222
+-222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222ff222222222222
+-2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222e222222222222222222
+-222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222e22ee222222222222222222
+-2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222e2eeeeee22222222222222222
+-222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222ee22eeeeeeeeeee22222222222222222
+-e2222222222222222222222222222222222222222222222222222222222222222222222222222222222222eeeeeeeeeeeeeee999922222222222222222
+-e222222222222222222222222222222222222222222222222222222222222222222222222222222222e2eeeeeeeeeeeeee999999922222222222222222
+-eeee2222222222222222222222222222222222222222222222222222222222222222222222222eeeeeeeeeeeeeeee9999999999cc22222222222222222
+-eeeeee2222222222222222222222222222222222222222222222222222222222222222222eeeeeeeeeeeeeeee99999999999ccccc22222222222222222
++image bits 89 by 36
++600006fffffffff600006fffffffffffff100000000000000000005fffffffffffffffffff5fffff15fffffff
++9eeeee1ffffffffbeeee3fffffffffffffceeeeeeeeeeeeeeeeeee9fffffff1a447affffff45ff08794cfffff
++5eeeeeaffffffffdeeeee6ffffffffffff3eeeeeeeeeeeeeeeeeee9ffffffa2eeeee30fffaedf68a447ffffff
++f8eeeebfffffffff2eeeecfffffffffff6eeeeeeeeeeeeeeeeeeee6fffffaeeeeeeeeeaf13e9f7098020fffff
++faeeeee1ffffffff7eeee3fffffffffffceeeeeeeeeeeeeeeeeee9fffffdeeeeeeeeeee69ee4f41933bffffff
++f5eeeeeaffffffffdeeeee6ffffffffff3eeee800000009eeeee8fffff13eeeeeeeeeee3eee7fa994026fffff
++ff8eeeebfffffffff2eeeecfffffffff6eeeeedffffff13eeee26fffff9eeee3a1f1a3eeee25ff7705af6ffff
++ffaeeeee5ffffffff7eeee3fffffffffceeee2fffffffceeeeeaffffff3eee71fffff17eee9ffff099a1fffff
++ff1eeeeeaffffffffbeeeee0ffffffff2eeee7ffffffdeeeee4ffffff0eeebfffffffff7e8fffffffffffffff
++fffbeeee8fffffff1eeeeee7fffffffdeeeee6fffff12eeee25ffffff9ee31ffffffffff80fffffffffffffff
++fffaeeeee5ffffffaeeeeee2fffffff7eeee3ffffffbeeeeeafffffff4eeafffffffffff1ffffffffffffffff
++fff1eeeeeaffffff8eeeeeeedffffff2eeeecfffffdeeeee4ffffffff8e3fffffffffffffffffffffffffffff
++ffffbeeee8fffff5eeeeeeee7fffffdeeeee6ffff12eeee25ffffffffeecfffffffffffffffffffffffffffff
++ffffaeeeee5ffffaeeeeeeee2fffff7eeee3fffffbeeeeecfffffffffee0fffffffffffffffffffffffffffff
++fffff2eeeeaffff8eeee3eeeedffff2eeee9ffffdeeeeeee8afffffffeeffffffffffffffffffffffffffffff
++fffff7eeee3fff5eeee3aeeee7fffdeeeee5ffff2eeeeeeeee41fffff38ffffffffffffffffffffffffffffff
++fffffdeeeee6ffaeeeec1eeeee1ffbeeee8fffffeeeeeeeeeee25ffff44ffffffffffffffffffffffffffffff
++ffffff2eeeecff3eeee6fbeeeeaf1eeeeeafffff99948eeeeeee8ffff94ffffffffffffffffffffffffffffff
++ffffff7eeee3f6eeee3ffaeeeebfaeeeee5ffffffffff57eeeeee9fff64ffffffffffffffffffffffffffffff
++ffffffdeeeee6ceeee9fff2eeee1beeee8fffffffffffffaeeeee21fff4ffffffffffffffffffffffffffffff
++fffffff3eeeec3eeee5fff7eeeeaeeeeeaffffffffffffffbeeeeeafffdffffffffffffffffffffffffffffff
++fffffffceeee2eeee8ffffdeeee2eeeee1ffffffffffffff0eeeee7ffffffffffffffffffffffffffffffffff
++fffffff6eeeeeeeeeafffff2eeeeeeeebffffffffffffffffeeeee4ffffffffffffffffffffffffffffffffff
++ffffffff3eeeeeeee5fffff7eeeeeeeeaffffffffffffffff8eeee4ffffffffffffffffffffffffffffffffff
++ffffffffceeeeeee4ffffff0eeeeeeee1ffffffffffffffff4eeee41fffffffffffffffffffffffffffffffff
++ffffffff6eeeeeeeafffffff3eeeeeebfffffffffffffffff2eeee4c1fffffffffffffffff10fffffffffffff
++fffffffff3eeeeee1fffffffceeeeeeaffffff6fffffffff5eeeee46bfffffffffffffffffbcfffffffffffff
++fffffffffaeeeeebffffffff6eeeee21fffd72e5ffffffff9eeeee9f4afffffffffffffffae8fffffffffffff
++fffffffff5eeeeeafffffffff3eeee7fffaeeee81ffffff12eeeee6f0eafffffffffffffaeeefffffffffffff
++ffffffffff8eee21fffffffff9eeeedfff5eeeee41ffff18eeeee4fffbe9fffffffffffceee4fffffffffffff
++ffffffffffaeee7ffffffffff5eee2fffff9eeeee2900a3eeeeee0fff13e40fffffff08eee25fffffffffffff
++ffffffffff5eeedfffffffffff8ee7ffffff8eeeeeeeeeeeeeeecfffff62ee89d0ac3eeee26ffffffffffffff
++fffffffffff8e2ffffffffffffaeedffffff18eeeeeeeeeeeee7fffffff62eeeeeeeeeee26fffffffffffffff
++fffffffffffae7ffffffffffff5e3ffffffff17eeeeeeeeeee9fffffffff54eeeeeeeee45ffffffffffffffff
++fffffffffff1e0fffffffffffff4cffffffffff0beeeeee275ffffffffffff0beeeeebaffffffffffffffffff
++ffffffffffff6ffffffffffffff51fffffffffffff00006ffffffffffffffffff105fffffffffffffffffffff
+
+ # The following sets edit modes for GNU EMACS
+ # Local Variables:
+ # mode:picture
+ # truncate-lines:t
+ # End:
diff --git a/tests/data/test1.gif b/tests/data/test1.gif
new file mode 100644
index 0000000..890bc97
Binary files /dev/null and b/tests/data/test1.gif differ
diff --git a/tests/data/test2.gif b/tests/data/test2.gif
new file mode 100644
index 0000000..3b3c6fd
Binary files /dev/null and b/tests/data/test2.gif differ
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the Reproducible-commits
mailing list