Class: Exerb::Win32::IconFile
- Inherits:
-
Object
- Object
- Exerb::Win32::IconFile
- Defined in:
- lib/exerb/win32/icon_file.rb
Overview
#
Defined Under Namespace
Classes: Entry
Instance Attribute Summary collapse
-
#entries ⇒ Object
Returns the value of attribute entries.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ IconFile
constructor
A new instance of IconFile.
- #read(io) ⇒ Object
Constructor Details
#initialize ⇒ IconFile
Returns a new instance of IconFile.
21 22 23 |
# File 'lib/exerb/win32/icon_file.rb', line 21 def initialize @entries = [] end |
Instance Attribute Details
#entries ⇒ Object
Returns the value of attribute entries.
25 26 27 |
# File 'lib/exerb/win32/icon_file.rb', line 25 def entries @entries end |
Class Method Details
.read(input) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/exerb/win32/icon_file.rb', line 27 def self.read(input) case input when IO then return self.new.read(input) when String then return File.open(input, 'rb') { |file| self.read(file) } else raise(ArgumentError, "input must be IO or String object") end end |
Instance Method Details
#read(io) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/exerb/win32/icon_file.rb', line 35 def read(io) base = io.pos icon_header = Exerb::Win32::Struct::IconHeader.read(io) @entries = (1..icon_header.count).collect { Exerb::Win32::Struct::IconDirEntry.read(io) }.collect { |icon_dir_entry| io.seek(base + icon_dir_entry.image_offset) entry = Exerb::Win32::IconFile::Entry.new entry.width = icon_dir_entry.width == 0 ? 256 : icon_dir_entry.width entry.height = icon_dir_entry.height == 0 ? 256 : icon_dir_entry.height entry.bit_count = icon_dir_entry.bit_count entry.bit_count = 4 if entry.bit_count == 0 && icon_dir_entry.color_count == 16 entry.bit_count = 8 if entry.bit_count == 0 && icon_dir_entry.bytes_in_res == 2216 entry.bit_count = 8 if entry.bit_count == 0 && icon_dir_entry.bytes_in_res == 1384 entry.value = io.read(icon_dir_entry.bytes_in_res) entry } return self end |