uploads: add support for uploading .avif files.

Features of AVIF include:

* Lossless and lossy compression.
* High dynamic range (HDR) images
* Wide color gamut images (i.e. 10- and 12-bit color depths)
* Transparency (through alpha planes).
* Animations (with an optional cover image).
* Auxiliary image sequences, where the file contains a single primary
  image and a short secondary video, like Apple's Live Photos.
* Metadata rotation, mirroring, and cropping.

The AVIF format is still relatively new and some of these features aren't well
supported by browsers or other software:

* Animated AVIFs aren't supported by Firefox or by libvips.
* HDR images aren't supported by Firefox.
* Rotated, mirrored, and cropped AVIFs aren't supported by Firefox or Chrome.
* Image grids, where the file contains multiple images that are tiled
  together into one big image, aren't supported by Firefox.
* AVIF as a whole has only been supported for a year or two by Chrome
  and Firefox, and less than a year by Safari.

For these reasons, only basic AVIFs that don't use animation, rotation,
cropping, or image grids can be uploaded.
This commit is contained in:
evazion
2022-10-24 19:10:57 -05:00
parent 420ff2f2f5
commit c96d60a840
26 changed files with 197 additions and 15 deletions

View File

@@ -195,6 +195,33 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
end
end
context "for an unsupported AVIF file" do
should "fail for a grid image" do
create_upload!("test/files/avif/Image grid example.avif", user: @user)
assert_match("File type is not supported", Upload.last.error)
end
should "fail for a cropped image" do
create_upload!("test/files/avif/kimono.crop.avif", user: @user)
assert_match("File type is not supported", Upload.last.error)
end
should "fail for a rotated image" do
create_upload!("test/files/avif/kimono.rotate90.avif", user: @user)
assert_match("File type is not supported", Upload.last.error)
end
should "fail for an image sequence" do
create_upload!("test/files/avif/sequence-with-pitm.avif", user: @user)
assert_match("File type is not supported", Upload.last.error)
end
should "fail for a still image with an auxiliary image sequence" do
create_upload!("test/files/avif/sequence-with-pitm-avif-major.avif", user: @user)
assert_match("File type is not supported", Upload.last.error)
end
end
context "for a video longer than the video length limit" do
should "fail for a regular user" do
create_upload!("https://cdn.donmai.us/original/63/cb/63cb09f2526ef3ac14f11c011516ad9b.webm", user: @user)
@@ -267,6 +294,12 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
should_upload_successfully("test/files/test-512x512.webm")
should_upload_successfully("test/files/test-audio.m4v")
# should_upload_successfully("test/files/compressed.swf")
should_upload_successfully("test/files/avif/fox.profile0.8bpc.yuv420.monochrome.avif")
should_upload_successfully("test/files/avif/hdr_cosmos01000_cicp9-16-9_yuv420_limited_qp40.avif")
should_upload_successfully("test/files/avif/hdr_cosmos01000_cicp9-16-9_yuv444_full_qp40.avif")
should_upload_successfully("test/files/avif/paris_icc_exif_xmp.avif")
should_upload_successfully("test/files/avif/tiger_3layer_1res.avif")
end
context "uploading multiple files from your computer" do