gif-info 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +33 -0
- data/LICENSE.txt +20 -0
- data/README.md +52 -0
- data/Rakefile +37 -0
- data/VERSION +1 -0
- data/ajax-loader-0.gif +0 -0
- data/ajax-loader.gif +0 -0
- data/bin/gif-dump +41 -0
- data/bin/gif-info +44 -0
- data/gif-info.gemspec +86 -0
- data/lib/gif-info.rb +407 -0
- data/lib/gif-info/block.rb +84 -0
- data/lib/gif-info/blocks/application-extension.rb +38 -0
- data/lib/gif-info/blocks/comment-extension.rb +35 -0
- data/lib/gif-info/blocks/global-color-table.rb +25 -0
- data/lib/gif-info/blocks/graphics-control-extension.rb +43 -0
- data/lib/gif-info/blocks/header-block.rb +35 -0
- data/lib/gif-info/blocks/image-data.rb +35 -0
- data/lib/gif-info/blocks/image-descriptor.rb +45 -0
- data/lib/gif-info/blocks/local-color-table.rb +25 -0
- data/lib/gif-info/blocks/logical-screen-descriptor.rb +43 -0
- data/lib/gif-info/blocks/plain-text-extension.rb +77 -0
- data/lib/gif-info/blocks/trailer.rb +32 -0
- data/lib/gif-info/body.rb +105 -0
- data/lib/gif-info/color-table.rb +32 -0
- data/lib/gif-info/data-block.rb +56 -0
- data/lib/gif-info/dynamic-block.rb +66 -0
- data/lib/gif-info/fixed-block.rb +82 -0
- data/lib/gif-info/raw-block.rb +78 -0
- data/test +112 -0
- metadata +157 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
|
+
|
4
|
+
require "abstract"
|
5
|
+
|
6
|
+
##
|
7
|
+
# Primary GifInfo module.
|
8
|
+
#
|
9
|
+
|
10
|
+
class GifInfo
|
11
|
+
|
12
|
+
##
|
13
|
+
# General block.
|
14
|
+
# @abstract
|
15
|
+
#
|
16
|
+
|
17
|
+
class Block
|
18
|
+
|
19
|
+
##
|
20
|
+
# Holds IO object.
|
21
|
+
#
|
22
|
+
|
23
|
+
@io
|
24
|
+
|
25
|
+
##
|
26
|
+
# Holds block position in stream.
|
27
|
+
#
|
28
|
+
|
29
|
+
@position
|
30
|
+
|
31
|
+
##
|
32
|
+
# Returns header.
|
33
|
+
#
|
34
|
+
|
35
|
+
def header
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# Returns body.
|
41
|
+
#
|
42
|
+
|
43
|
+
def body
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# Constructor.
|
49
|
+
# @param [IO] io some IO object at appropriate offset
|
50
|
+
#
|
51
|
+
|
52
|
+
def initialize(io)
|
53
|
+
@io = io
|
54
|
+
@position = io.pos
|
55
|
+
self.skip!
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# Skips block in stream.
|
60
|
+
# @abstract
|
61
|
+
#
|
62
|
+
|
63
|
+
def skip!
|
64
|
+
not_implemented
|
65
|
+
end
|
66
|
+
|
67
|
+
##
|
68
|
+
# Prepares to reading position.
|
69
|
+
#
|
70
|
+
|
71
|
+
def prepare!
|
72
|
+
@io.seek(@position)
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Returns size of block in bytes.
|
77
|
+
# @abstract
|
78
|
+
#
|
79
|
+
|
80
|
+
def bytesize
|
81
|
+
not_implemented
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
|
+
|
4
|
+
require "gif-info/dynamic-block"
|
5
|
+
require "frozen-objects"
|
6
|
+
|
7
|
+
##
|
8
|
+
# Primary GifInfo module.
|
9
|
+
#
|
10
|
+
|
11
|
+
class GifInfo
|
12
|
+
|
13
|
+
##
|
14
|
+
# General blocks module.
|
15
|
+
#
|
16
|
+
|
17
|
+
module Blocks
|
18
|
+
|
19
|
+
##
|
20
|
+
# Application specific information to embedded in the GIF file itself.
|
21
|
+
#
|
22
|
+
|
23
|
+
class ApplicationExtension < DynamicBlock
|
24
|
+
|
25
|
+
##
|
26
|
+
# Byte structure.
|
27
|
+
#
|
28
|
+
|
29
|
+
STRUCTURE = Frozen << Proc::new do
|
30
|
+
skip {1}
|
31
|
+
uint8 :extension_type
|
32
|
+
uint8 :block_size
|
33
|
+
string (:application_identifier) {8}
|
34
|
+
string (:application_authentication_code) {3}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
|
+
|
4
|
+
require "gif-info/dynamic-block"
|
5
|
+
require "frozen-objects"
|
6
|
+
|
7
|
+
##
|
8
|
+
# Primary GifInfo module.
|
9
|
+
#
|
10
|
+
|
11
|
+
class GifInfo
|
12
|
+
|
13
|
+
##
|
14
|
+
# General blocks module.
|
15
|
+
#
|
16
|
+
|
17
|
+
module Blocks
|
18
|
+
|
19
|
+
##
|
20
|
+
# Contents textual comment data.
|
21
|
+
#
|
22
|
+
|
23
|
+
class CommentExtension < DynamicBlock
|
24
|
+
|
25
|
+
##
|
26
|
+
# Byte structure.
|
27
|
+
#
|
28
|
+
|
29
|
+
STRUCTURE = Frozen << Proc::new do
|
30
|
+
skip {1}
|
31
|
+
uint8 :extension_type
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
|
+
|
4
|
+
require "gif-info/color-table"
|
5
|
+
|
6
|
+
##
|
7
|
+
# Primary GifInfo module.
|
8
|
+
#
|
9
|
+
|
10
|
+
class GifInfo
|
11
|
+
|
12
|
+
##
|
13
|
+
# General blocks module.
|
14
|
+
#
|
15
|
+
|
16
|
+
module Blocks
|
17
|
+
|
18
|
+
##
|
19
|
+
# List of all the colors that can be in the image.
|
20
|
+
#
|
21
|
+
|
22
|
+
class GlobalColorTable < ColorTable
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
|
+
|
4
|
+
require "gif-info/fixed-block"
|
5
|
+
require "frozen-objects"
|
6
|
+
|
7
|
+
##
|
8
|
+
# Primary GifInfo module.
|
9
|
+
#
|
10
|
+
|
11
|
+
class GifInfo
|
12
|
+
|
13
|
+
##
|
14
|
+
# General blocks module.
|
15
|
+
#
|
16
|
+
|
17
|
+
module Blocks
|
18
|
+
|
19
|
+
##
|
20
|
+
# Used to specify transparency settings and control animations.
|
21
|
+
#
|
22
|
+
|
23
|
+
class GraphicsControlExtension < FixedBlock
|
24
|
+
|
25
|
+
##
|
26
|
+
# Byte structure.
|
27
|
+
#
|
28
|
+
|
29
|
+
STRUCTURE = Frozen << Proc::new do
|
30
|
+
skip {3}
|
31
|
+
byte (:packed) do
|
32
|
+
number (:reserved) {3}
|
33
|
+
number (:disposal_method) {3}
|
34
|
+
boolean :user_input
|
35
|
+
boolean :transparent_color
|
36
|
+
end
|
37
|
+
uint16 :delay_time
|
38
|
+
uint8 :transparent_color_index
|
39
|
+
skip {1}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
|
+
|
4
|
+
require "gif-info/fixed-block"
|
5
|
+
require "frozen-objects"
|
6
|
+
|
7
|
+
##
|
8
|
+
# Primary GifInfo module.
|
9
|
+
#
|
10
|
+
|
11
|
+
class GifInfo
|
12
|
+
|
13
|
+
##
|
14
|
+
# General blocks module.
|
15
|
+
#
|
16
|
+
|
17
|
+
module Blocks
|
18
|
+
|
19
|
+
##
|
20
|
+
# Signature and version.
|
21
|
+
#
|
22
|
+
|
23
|
+
class HeaderBlock < FixedBlock
|
24
|
+
|
25
|
+
##
|
26
|
+
# Byte structure.
|
27
|
+
#
|
28
|
+
|
29
|
+
STRUCTURE = Frozen << Proc::new do
|
30
|
+
string (:signature) {3}
|
31
|
+
string (:version) {3}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
|
+
|
4
|
+
require "gif-info/dynamic-block"
|
5
|
+
require "frozen-objects"
|
6
|
+
|
7
|
+
##
|
8
|
+
# Primary GifInfo module.
|
9
|
+
#
|
10
|
+
|
11
|
+
class GifInfo
|
12
|
+
|
13
|
+
##
|
14
|
+
# General blocks module.
|
15
|
+
#
|
16
|
+
|
17
|
+
module Blocks
|
18
|
+
|
19
|
+
##
|
20
|
+
# series of output codes which tell the decoder which colors to
|
21
|
+
# spit out to the canvas.
|
22
|
+
#
|
23
|
+
|
24
|
+
class ImageData < DynamicBlock
|
25
|
+
|
26
|
+
##
|
27
|
+
# Byte structure.
|
28
|
+
#
|
29
|
+
|
30
|
+
STRUCTURE = Frozen << Proc::new do
|
31
|
+
uint8 :lzw_minimum_code_size
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
|
+
|
4
|
+
require "gif-info/fixed-block"
|
5
|
+
require "frozen-objects"
|
6
|
+
|
7
|
+
##
|
8
|
+
# Primary GifInfo module.
|
9
|
+
#
|
10
|
+
|
11
|
+
class GifInfo
|
12
|
+
|
13
|
+
##
|
14
|
+
# General blocks module.
|
15
|
+
#
|
16
|
+
|
17
|
+
module Blocks
|
18
|
+
|
19
|
+
##
|
20
|
+
# Block for describing single image in GIF.
|
21
|
+
#
|
22
|
+
|
23
|
+
class ImageDescriptor < FixedBlock
|
24
|
+
|
25
|
+
##
|
26
|
+
# Byte structure.
|
27
|
+
#
|
28
|
+
|
29
|
+
STRUCTURE = Frozen << Proc::new do
|
30
|
+
skip {1}
|
31
|
+
uint16 :image_left
|
32
|
+
uint16 :image_top
|
33
|
+
uint16 :image_width
|
34
|
+
uint16 :image_height
|
35
|
+
byte (:packed) do
|
36
|
+
boolean :local_color_table
|
37
|
+
boolean :interlace
|
38
|
+
boolean :local_color_table_sort
|
39
|
+
number (:reserved) {2}
|
40
|
+
number (:local_color_table_size) {3}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
|
+
|
4
|
+
require "gif-info/color-table"
|
5
|
+
|
6
|
+
##
|
7
|
+
# Primary GifInfo module.
|
8
|
+
#
|
9
|
+
|
10
|
+
class GifInfo
|
11
|
+
|
12
|
+
##
|
13
|
+
# General blocks module.
|
14
|
+
#
|
15
|
+
|
16
|
+
module Blocks
|
17
|
+
|
18
|
+
##
|
19
|
+
# List of all the colors that can be in the image.
|
20
|
+
#
|
21
|
+
|
22
|
+
class LocalColorTable < ColorTable
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
|
+
|
4
|
+
require "gif-info/fixed-block"
|
5
|
+
require "frozen-objects"
|
6
|
+
|
7
|
+
##
|
8
|
+
# Primary GifInfo module.
|
9
|
+
#
|
10
|
+
|
11
|
+
class GifInfo
|
12
|
+
|
13
|
+
##
|
14
|
+
# General blocks module.
|
15
|
+
#
|
16
|
+
|
17
|
+
module Blocks
|
18
|
+
|
19
|
+
##
|
20
|
+
# Tells the decoder how much room this image will take up.
|
21
|
+
#
|
22
|
+
|
23
|
+
class LogicalScreenDescriptor < FixedBlock
|
24
|
+
|
25
|
+
##
|
26
|
+
# Byte structure.
|
27
|
+
#
|
28
|
+
|
29
|
+
STRUCTURE = Frozen << Proc::new do
|
30
|
+
uint16 :canvas_width
|
31
|
+
uint16 :canvas_height
|
32
|
+
byte (:packed) do
|
33
|
+
boolean :global_color_table
|
34
|
+
number (:global_color_table_resolution) {3}
|
35
|
+
boolean :global_color_table_sort
|
36
|
+
number (:global_color_table_size) {3}
|
37
|
+
end
|
38
|
+
uint8 :background_color_index
|
39
|
+
uint8 :pixel_aspect_ratio
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
|
+
|
4
|
+
require "gif-info/dynamic-block"
|
5
|
+
require "gif-info/body"
|
6
|
+
require "frozen-objects"
|
7
|
+
|
8
|
+
##
|
9
|
+
# Primary GifInfo module.
|
10
|
+
#
|
11
|
+
|
12
|
+
class GifInfo
|
13
|
+
|
14
|
+
##
|
15
|
+
# General blocks module.
|
16
|
+
#
|
17
|
+
|
18
|
+
module Blocks
|
19
|
+
|
20
|
+
##
|
21
|
+
# Specifies text which user wish to have rendered on the image.
|
22
|
+
# Support of this feature is very rare.
|
23
|
+
#
|
24
|
+
|
25
|
+
class PlainTextExtension < DynamicBlock
|
26
|
+
|
27
|
+
##
|
28
|
+
# Byte structure.
|
29
|
+
#
|
30
|
+
|
31
|
+
STRUCTURE = Frozen << Proc::new do
|
32
|
+
skip {1}
|
33
|
+
uint8 :extension_type
|
34
|
+
uint8 :block_size
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# Returns data body.
|
39
|
+
#
|
40
|
+
# @param [Integer] skip number of bytes to skip before data
|
41
|
+
# @return [Body] data body
|
42
|
+
#
|
43
|
+
|
44
|
+
def body
|
45
|
+
super(__additional)
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# Skips block in stream.
|
50
|
+
#
|
51
|
+
|
52
|
+
def skip!
|
53
|
+
super(__additional)
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# Returns block size.
|
58
|
+
# @return [Integer] block size in bytes
|
59
|
+
#
|
60
|
+
|
61
|
+
def bytesize
|
62
|
+
super + __additional
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
##
|
69
|
+
# Returns additional length.
|
70
|
+
#
|
71
|
+
|
72
|
+
def __additional
|
73
|
+
self.header.data.block_size
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|