Class: Gifenc::Extension::Application
- Inherits:
-
Gifenc::Extension
- Object
- Gifenc::Extension
- Gifenc::Extension::Application
- Defined in:
- lib/extensions.rb
Overview
This generic extension was added to the GIF specification to allow software
developers to inject their own features into the format. Only one became truly
standard, the Netscape extension, which introduced GIF looping.
An Application Extension is a container in itself, and the specific contents are to
be defined in the data
method, which must be implemented by any subclass.
The structure of this extension block, as per the GIF specification, is
the following:
- Application Identifier (8 bytes): Sequence of ASCII characters used to identify the application owning this extension.
- Application Authentication Code (3 bytes): Used to authenticate the Application Identifier. An Application program may use an algorithm to compute a binary code that uniquely identifies it as the application owning the Application Extension.
- Application Data: The actual contents of the extension block, specific to each type of application extension.
Direct Known Subclasses
Constant Summary collapse
- LABEL =
Label identifying an Application Extension block.
"\xFF".freeze
Constants inherited from Gifenc::Extension
Instance Attribute Summary collapse
-
#code ⇒ String
Application authentication code.
-
#id ⇒ String
Application identifier.
Instance Method Summary collapse
-
#body ⇒ String
Encode the extension block as a binary string (id + code + data), as it will appear in the actual GIF file.
-
#initialize(id, code) ⇒ Application
constructor
Create a new generic Application Extension block.
Methods inherited from Gifenc::Extension
Constructor Details
#initialize(id, code) ⇒ Application
Create a new generic Application Extension block.
217 218 219 220 221 |
# File 'lib/extensions.rb', line 217 def initialize(id, code) super(LABEL) @id = id # Application Identifier @code = code # Application Authentication Code end |
Instance Attribute Details
#code ⇒ String
Application authentication code. Must be an arbitrary 3-byte binary string. It was originally intended as a way for applications to validate the extension, but is in practice just a suffix of the identifier.
206 207 208 |
# File 'lib/extensions.rb', line 206 def code @code end |
#id ⇒ String
Application identifier. Must be an 8 character ASCII string.
200 201 202 |
# File 'lib/extensions.rb', line 200 def id @id end |
Instance Method Details
#body ⇒ String
Encode the extension block as a binary string (id + code + data), as it will appear in the actual GIF file.
226 227 228 229 230 231 232 233 |
# File 'lib/extensions.rb', line 226 def body # Sanitize fields id = @id.force_encoding('US-ASCII').scrub[0...8].ljust(8, "\x00") code = @code[0...3].ljust(3, "\x00") # Build string "\x0B" + id + code + Util.blockify(data) end |