Class: FormatParser::GIFParser
- Inherits:
-
Object
- Object
- FormatParser::GIFParser
show all
- Includes:
- IOUtils
- Defined in:
- lib/parsers/gif_parser.rb
Constant Summary
collapse
['GIF87a', 'GIF89a'].map(&:b)
- NETSCAPE_AND_AUTHENTICATION_CODE =
'NETSCAPE2.0'
- GIF_MIME_TYPE =
'image/gif'
Constants included
from IOUtils
IOUtils::INTEGER_DIRECTIVES
Instance Method Summary
collapse
Methods included from IOUtils
#read_bytes, #read_fixed_point, #read_int, #safe_read, #safe_skip, #skip_bytes
Instance Method Details
#call(io) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/parsers/gif_parser.rb', line 12
def call(io)
io = FormatParser::IOConstraint.new(io)
= safe_read(io, 6)
return unless HEADERS.include?()
w, h = safe_read(io, 4).unpack('vv')
gct_byte, _bgcolor_index, _pixel_aspect_ratio = safe_read(io, 5).unpack('Cvv')
has_gct = gct_byte[0] == 1
bytes_per_color = gct_byte >> 6
unpacked_radix = gct_byte & 0b00000111
num_colors = 2**(unpacked_radix + 1)
gct_table_size = num_colors * bytes_per_color
safe_read(io, gct_table_size) if has_gct
= safe_read(io, 64)
is_animated = .include?(NETSCAPE_AND_AUTHENTICATION_CODE)
FormatParser::Image.new(
format: :gif,
width_px: w,
height_px: h,
has_multiple_frames: is_animated,
color_mode: :indexed,
content_type: GIF_MIME_TYPE
)
end
|
#likely_match?(filename) ⇒ Boolean
8
9
10
|
# File 'lib/parsers/gif_parser.rb', line 8
def likely_match?(filename)
filename =~ /\.gif$/i
end
|