Module: DiscreetProxy

Defined in:
lib/discreet_proxy.rb

Overview

The whole module for making and reading Flame proxy icon files

Defined Under Namespace

Classes: Proxy

Constant Summary collapse

VERSION =
"1.0.1"
MAGIC =
0xfaf0
PROXY_VERSION =
1.10003
PROXY_DEPTH =
130
VERSION_BSWAP =
"\x00\x00?\x8C\xCC\xCD"
DEFAULT_WIDTH =
126
DEFAULT_HEIGHT =
92

Class Method Summary collapse

Class Method Details

.from_file(path) ⇒ Object

Parse a .p file and return a Proxy



8
9
10
# File 'lib/discreet_proxy.rb', line 8

def self.from_file(path)
  File.open(path, "rb") {|f| from_io(f) }
end

.from_io(io) ⇒ Object

Parses out the proxy contained in the passed IO object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/discreet_proxy.rb', line 24

def self.from_io(io)
  pat = "na6nnn"
  
  magik, version_bswap, width, height, depth, _ = io.read(40).unpack(pat)
  raise "The passed data did not start with the magic bytes #{MAGIC}" if magik != MAGIC
  
  # This version check is busted for now, somehow
  ver = version_bswap.reverse.unpack("e").pop
  $stderr.puts "The passed version #{ver} is suspicious" if (ver - PROXY_VERSION).abs > 0.0001
  raise "Unknown proxy depth #{depth}" if depth != PROXY_DEPTH
  
  p = Proxy.new(width, height)
  p.fill_pixbuf(io)
  return p
end

.from_png(png) ⇒ Object

Creates a proxy object from a passed ChunkyPNG



13
14
15
16
17
18
19
20
21
# File 'lib/discreet_proxy.rb', line 13

def self.from_png(png)
  p = Proxy.new(png.width, png.height)
  (0...png.width).each do | x |
    (0...png.height).each do | y |
      p[x,y] = png[x,y]
    end
  end
  p
end