Class: Gifenc::Extension::Netscape

Inherits:
Application show all
Defined in:
lib/extensions.rb

Overview

This is the only Application Extension block that is widely supported, so much so that it became a defacto standard. It controls whether the GIF should loop or not, and if so, how many times. It need only appear once in the GIF file, and for maximum compatibility, it should be the very first extension block in the GIF file (i.e., it should appear right after the Global Color Table). Structure:

  • Sub-block ID (1 byte): Identifies the sub-block (always 1).
  • Loop count (2 bytes): Number of iterations (0-65535) the GIF should be looped. A count of 0 means loop indefinitely.

Constant Summary

Constants inherited from Application

Application::LABEL

Constants inherited from Gifenc::Extension

EXTENSION_INTRODUCER

Instance Attribute Summary collapse

Attributes inherited from Application

#code, #id

Instance Method Summary collapse

Methods inherited from Application

#body

Methods inherited from Gifenc::Extension

#encode

Constructor Details

#initialize(loops = 0) ⇒ Netscape

Create a new Netscape Extension block.

Parameters:

  • loops (Integer) (defaults to: 0)

    Times (0-65535) to loop the GIF (0 = infinite).



255
256
257
258
# File 'lib/extensions.rb', line 255

def initialize(loops = 0)
  super('NETSCAPE', '2.0')
  @loops = loops.clamp(0, 2 ** 16 - 1)
end

Instance Attribute Details

#loopsInteger

The amount of times to loop the GIF. Must be between 0 and 65535, where 0 indicates to loop indefinitely.

Returns:

  • (Integer)

    Loop count.



250
251
252
# File 'lib/extensions.rb', line 250

def loops
  @loops
end

Instance Method Details

#dataString

Data of the actual extension as a 3-byte binary string.

Returns:

  • (String)

    The raw application data.



262
263
264
265
266
# File 'lib/extensions.rb', line 262

def data
  # Note: We do not add the block size or null terminator here, since it will
  # be blockified later.
  "\x01" + [@loops & 0xFFFF].pack('S<')
end

#dupNetscape

Create a duplicate copy of this Netscape extension.

Returns:

  • (Netscape)

    The new extension object.



270
271
272
# File 'lib/extensions.rb', line 270

def dup
  Netscape.new(@loops)
end