diff options
| author | Vincent Deffontaines | 2025-03-18 22:11:27 +0100 |
|---|---|---|
| committer | jvoisin | 2025-03-18 22:20:17 +0100 |
| commit | 2b58eece509c22a692f4de2512ec41c00e1d2728 (patch) | |
| tree | c74baaf6570b8721eff0ef8e8ccbf7d07fc9e05b | |
| parent | 29f404bce34706f1902659a8aa713d9c2570cc60 (diff) | |
Add webp support
Diffstat (limited to '')
| -rw-r--r-- | libmat2/images.py | 12 | ||||
| -rw-r--r-- | tests/data/dirty.webp | bin | 0 -> 38502 bytes | |||
| -rw-r--r-- | tests/test_climat2.py | 5 | ||||
| -rw-r--r-- | tests/test_libmat2.py | 10 | ||||
| -rw-r--r-- | tests/test_lightweight_cleaning.py | 5 |
5 files changed, 32 insertions, 0 deletions
diff --git a/libmat2/images.py b/libmat2/images.py index bca1e74..317a9e3 100644 --- a/libmat2/images.py +++ b/libmat2/images.py | |||
| @@ -196,3 +196,15 @@ class HEICParser(exiftool.ExiftoolParser): | |||
| 196 | 196 | ||
| 197 | def remove_all(self) -> bool: | 197 | def remove_all(self) -> bool: |
| 198 | return self._lightweight_cleanup() | 198 | return self._lightweight_cleanup() |
| 199 | |||
| 200 | class WEBPParser(GdkPixbufAbstractParser): | ||
| 201 | mimetypes = {'image/webp'} | ||
| 202 | meta_allowlist = {'SourceFile', 'ExifToolVersion', 'FileName', | ||
| 203 | 'Directory', 'FileSize', 'FileModifyDate', | ||
| 204 | 'FileAccessDate', "FileInodeChangeDate", | ||
| 205 | 'FilePermissions', 'FileType', 'FileTypeExtension', | ||
| 206 | 'MIMEType', 'ImageWidth', 'ImageSize', 'BitsPerSample', | ||
| 207 | 'ColorComponents', 'EncodingProcess', 'JFIFVersion', | ||
| 208 | 'ResolutionUnit', 'XResolution', 'YCbCrSubSampling', | ||
| 209 | 'YResolution', 'Megapixels', 'ImageHeight', 'Orientation', | ||
| 210 | 'HorizontalScale', 'VerticalScale', 'VP8Version'} | ||
diff --git a/tests/data/dirty.webp b/tests/data/dirty.webp new file mode 100644 index 0000000..0d0e42c --- /dev/null +++ b/tests/data/dirty.webp | |||
| Binary files differ | |||
diff --git a/tests/test_climat2.py b/tests/test_climat2.py index 9238253..edc8e88 100644 --- a/tests/test_climat2.py +++ b/tests/test_climat2.py | |||
| @@ -236,6 +236,11 @@ class TestGetMeta(unittest.TestCase): | |||
| 236 | self.assertIn(b'i am a : various comment', stdout) | 236 | self.assertIn(b'i am a : various comment', stdout) |
| 237 | self.assertIn(b'artist: jvoisin', stdout) | 237 | self.assertIn(b'artist: jvoisin', stdout) |
| 238 | 238 | ||
| 239 | def test_webp(self): | ||
| 240 | proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/dirty.webp'], | ||
| 241 | stdout=subprocess.PIPE) | ||
| 242 | stdout, _ = proc.communicate() | ||
| 243 | self.assertIn(b'Warning: [minor] Improper EXIF header', stdout) | ||
| 239 | 244 | ||
| 240 | class TestControlCharInjection(unittest.TestCase): | 245 | class TestControlCharInjection(unittest.TestCase): |
| 241 | def test_jpg(self): | 246 | def test_jpg(self): |
diff --git a/tests/test_libmat2.py b/tests/test_libmat2.py index 1925201..332a5a3 100644 --- a/tests/test_libmat2.py +++ b/tests/test_libmat2.py | |||
| @@ -113,6 +113,11 @@ class TestGetMeta(unittest.TestCase): | |||
| 113 | meta = p.get_meta() | 113 | meta = p.get_meta() |
| 114 | self.assertEqual(meta['Comment'], 'Created with GIMP') | 114 | self.assertEqual(meta['Comment'], 'Created with GIMP') |
| 115 | 115 | ||
| 116 | def test_webp(self): | ||
| 117 | p = images.WEBPParser('./tests/data/dirty.webp') | ||
| 118 | meta = p.get_meta() | ||
| 119 | self.assertEqual(meta['Warning'], '[minor] Improper EXIF header') | ||
| 120 | |||
| 116 | def test_ppm(self): | 121 | def test_ppm(self): |
| 117 | p = images.PPMParser('./tests/data/dirty.ppm') | 122 | p = images.PPMParser('./tests/data/dirty.ppm') |
| 118 | meta = p.get_meta() | 123 | meta = p.get_meta() |
| @@ -334,6 +339,11 @@ class TestCleaning(unittest.TestCase): | |||
| 334 | 'meta': {'Comment': 'Created with GIMP'}, | 339 | 'meta': {'Comment': 'Created with GIMP'}, |
| 335 | 'expected_meta': {}, | 340 | 'expected_meta': {}, |
| 336 | }, { | 341 | }, { |
| 342 | 'name': 'webp', | ||
| 343 | 'parser': images.WEBPParser, | ||
| 344 | 'meta': {'Warning': '[minor] Improper EXIF header'}, | ||
| 345 | 'expected_meta': {}, | ||
| 346 | }, { | ||
| 337 | 'name': 'wav', | 347 | 'name': 'wav', |
| 338 | 'parser': audio.WAVParser, | 348 | 'parser': audio.WAVParser, |
| 339 | 'meta': {'Comment': 'Zomg, a comment!'}, | 349 | 'meta': {'Comment': 'Zomg, a comment!'}, |
diff --git a/tests/test_lightweight_cleaning.py b/tests/test_lightweight_cleaning.py index ce7e48c..9b33df4 100644 --- a/tests/test_lightweight_cleaning.py +++ b/tests/test_lightweight_cleaning.py | |||
| @@ -24,6 +24,11 @@ class TestLightWeightCleaning(unittest.TestCase): | |||
| 24 | 'meta': {'Comment': 'Created with GIMP'}, | 24 | 'meta': {'Comment': 'Created with GIMP'}, |
| 25 | 'expected_meta': {}, | 25 | 'expected_meta': {}, |
| 26 | }, { | 26 | }, { |
| 27 | 'name': 'webp', | ||
| 28 | 'parser': images.WEBPParser, | ||
| 29 | 'meta': {'Warning': '[minor] Improper EXIF header'}, | ||
| 30 | 'expected_meta': {}, | ||
| 31 | }, { | ||
| 27 | 'name': 'torrent', | 32 | 'name': 'torrent', |
| 28 | 'parser': torrent.TorrentParser, | 33 | 'parser': torrent.TorrentParser, |
| 29 | 'meta': {'created by': b'mktorrent 1.0'}, | 34 | 'meta': {'created by': b'mktorrent 1.0'}, |
