MediaFile: replace APNGInspector with ExifTool.

Replace our own handwritten APNG parser with ExifTool. This makes
ExifTool a hard requirement for handling APNGs.
This commit is contained in:
evazion
2021-09-21 03:53:06 -05:00
parent 273be55de8
commit ae7d964bf1
5 changed files with 54 additions and 178 deletions

View File

@@ -1,63 +0,0 @@
require "test_helper"
class APNGInspectorTest < ActiveSupport::TestCase
def inspect(filename)
apng = APNGInspector.new("#{Rails.root}/test/files/apng/#{filename}")
apng.inspect!
apng
end
context "APNG inspector" do
should "correctly parse normal APNG file" do
apng = inspect('normal_apng.png')
assert_equal(3, apng.frames)
assert_equal(true, apng.animated?)
assert_equal(false, apng.corrupted?)
end
should "recognize 1-frame APNG as animated" do
apng = inspect('single_frame.png')
assert_equal(1, apng.frames)
assert_equal(true, apng.animated?)
assert_equal(false, apng.corrupted?)
end
should "correctly parse normal PNG file" do
apng = inspect('not_apng.png')
assert_equal(false, apng.animated?)
assert_equal(false, apng.corrupted?)
end
should "handle empty file" do
apng = inspect('empty.png')
assert_equal(false, apng.animated?)
assert_equal(true, apng.corrupted?)
end
should "handle corrupted files" do
apng = inspect('iend_missing.png')
assert_equal(false, apng.animated?)
assert_equal(true, apng.corrupted?)
apng = inspect('misaligned_chunks.png')
assert_equal(false, apng.animated?)
assert_equal(true, apng.corrupted?)
apng = inspect('broken.png')
assert_equal(false, apng.animated?)
assert_equal(true, apng.corrupted?)
end
should "handle incorrect acTL chunk" do
apng = inspect('actl_wronglen.png')
assert_equal(false, apng.animated?)
assert_equal(true, apng.corrupted?)
apng = inspect('actl_zero_frames.png')
assert_equal(false, apng.animated?)
assert_equal(true, apng.corrupted?)
end
should "handle non-png files" do
apng = inspect('jpg.png')
assert_equal(false, apng.animated?)
assert_equal(true, apng.corrupted?)
end
end
end

View File

@@ -190,6 +190,59 @@ class MediaFileTest < ActiveSupport::TestCase
end
end
context "a PNG file" do
context "that is not animated" do
should "not be detected as animated" do
file = MediaFile.open("test/files/apng/not_apng.png")
assert_equal(false, file.is_corrupt?)
assert_equal(false, file.is_animated?)
end
end
context "that is animated" do
should "be detected as animated" do
file = MediaFile.open("test/files/apng/normal_apng.png")
assert_equal(false, file.is_corrupt?)
assert_equal(true, file.is_animated?)
end
end
context "that is animated but with only one frame" do
should "not be detected as animated" do
file = MediaFile.open("test/files/apng/single_frame.png")
assert_equal(false, file.is_corrupt?)
assert_equal(false, file.is_animated?)
end
end
context "that is animated but malformed" do
should "be handled correctly" do
file = MediaFile.open("test/files/apng/iend_missing.png")
assert_equal(false, file.is_corrupt?)
assert_equal(true, file.is_animated?)
file = MediaFile.open("test/files/apng/misaligned_chunks.png")
assert_equal(true, file.is_corrupt?)
assert_equal(true, file.is_animated?)
file = MediaFile.open("test/files/apng/broken.png")
assert_equal(true, file.is_corrupt?)
assert_equal(true, file.is_animated?)
file = MediaFile.open("test/files/apng/actl_wronglen.png")
assert_equal(false, file.is_corrupt?)
assert_equal(true, file.is_animated?)
file = MediaFile.open("test/files/apng/actl_zero_frames.png")
assert_equal(false, file.is_corrupt?)
assert_equal(false, file.is_animated?)
end
end
end
context "a corrupt GIF" do
should "still read the metadata" do
@file = MediaFile.open("test/files/test-corrupt.gif")