module DiscreetProxy
The whole module for making and reading Flame proxy icon files
Constants
- DEFAULT_HEIGHT
- DEFAULT_WIDTH
- MAGIC
- PROXY_DEPTH
- PROXY_VERSION
- VERSION
- VERSION_BSWAP
Public Class Methods
from_file(path)
click to toggle source
Parse a .p file and return a Proxy
# File lib/discreet_proxy.rb, line 8 def self.from_file(path) File.open(path, "rb") {|f| from_io(f) } end
from_io(io)
click to toggle source
Parses out the proxy contained in the passed IO object
# 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)
click to toggle source
Creates a proxy object from a passed ChunkyPNG
# 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