mirror of
https://github.com/sdsykes/fastimage.git
synced 2025-10-04 00:00:35 -04:00
Merge pull request #135 from stefanoverna/avif-format
Add support for AVIF format
This commit is contained in:
commit
abd8059bd9
@ -544,12 +544,9 @@ class FastImage
|
||||
case @stream.peek(3).bytes.to_a.last
|
||||
when 0
|
||||
# http://www.ftyps.com/what.html
|
||||
# HEIC is composed of nested "boxes". Each box has a header composed of
|
||||
# - Size (32 bit integer)
|
||||
# - Box type (4 chars)
|
||||
# - Extended size: only if size === 1, the type field is followed by 64 bit integer of extended size
|
||||
# - Payload: Type-dependent
|
||||
case @stream.peek(12)[4..-1]
|
||||
when "ftypavif"
|
||||
:avif
|
||||
when "ftypheic"
|
||||
:heic
|
||||
when "ftypmif1"
|
||||
@ -584,7 +581,14 @@ class FastImage
|
||||
end
|
||||
alias_method :parse_size_for_cur, :parse_size_for_ico
|
||||
|
||||
class Heic # :nodoc:
|
||||
# HEIC/AVIF are a special case of the general ISO_BMFF format, in which all data is encapsulated in typed boxes,
|
||||
# with a mandatory ftyp box that is used to indicate particular file types. Is composed of nested "boxes". Each
|
||||
# box has a header composed of
|
||||
# - Size (32 bit integer)
|
||||
# - Box type (4 chars)
|
||||
# - Extended size: only if size === 1, the type field is followed by 64 bit integer of extended size
|
||||
# - Payload: Type-dependent
|
||||
class IsoBmff # :nodoc:
|
||||
def initialize(stream)
|
||||
@stream = stream
|
||||
end
|
||||
@ -735,14 +739,19 @@ class FastImage
|
||||
end
|
||||
end
|
||||
|
||||
def parse_size_for_avif
|
||||
bmff = IsoBmff.new(@stream)
|
||||
bmff.width_and_height
|
||||
end
|
||||
|
||||
def parse_size_for_heic
|
||||
heic = Heic.new(@stream)
|
||||
heic.width_and_height
|
||||
bmff = IsoBmff.new(@stream)
|
||||
bmff.width_and_height
|
||||
end
|
||||
|
||||
def parse_size_for_heif
|
||||
heic = Heic.new(@stream)
|
||||
heic.width_and_height
|
||||
bmff = IsoBmff.new(@stream)
|
||||
bmff.width_and_height
|
||||
end
|
||||
|
||||
class Gif # :nodoc:
|
||||
|
BIN
test/fixtures/avif/fox.avif
vendored
Normal file
BIN
test/fixtures/avif/fox.avif
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 77 KiB |
BIN
test/fixtures/avif/hato.avif
vendored
Normal file
BIN
test/fixtures/avif/hato.avif
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 253 KiB |
BIN
test/fixtures/avif/kimono.avif
vendored
Normal file
BIN
test/fixtures/avif/kimono.avif
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 83 KiB |
BIN
test/fixtures/avif/star.avifs
vendored
Normal file
BIN
test/fixtures/avif/star.avifs
vendored
Normal file
Binary file not shown.
@ -49,7 +49,10 @@ GoodFixtures = {
|
||||
"heic/heic-single.heic"=>[:heif,[1440,960]],
|
||||
"heic/heic-collection.heic"=>[:heif,[1440,960]],
|
||||
"heic/inverted.heic"=>[:heic,[3024, 4032]],
|
||||
"test6.svg" => [:svg, [450, 450]]
|
||||
"test6.svg" => [:svg, [450, 450]],
|
||||
"avif/hato.avif" => [:avif, [3082, 2048]],
|
||||
"avif/fox.avif" => [:avif, [1204, 799]],
|
||||
"avif/kimono.avif" => [:avif, [722, 1024]],
|
||||
}
|
||||
|
||||
BadFixtures = [
|
||||
@ -59,6 +62,7 @@ BadFixtures = [
|
||||
"test2.xml",
|
||||
"a.CR2",
|
||||
"a.CRW",
|
||||
"avif/star.avifs",
|
||||
]
|
||||
# man.ico courtesy of http://www.iconseeker.com/search-icon/artists-valley-sample/business-man-blue.html
|
||||
# test_rgb.ct courtesy of http://fileformats.archiveteam.org/wiki/Scitex_CT
|
||||
|
Loading…
x
Reference in New Issue
Block a user