Sha256: fe1e2035474c1e5563a61a20b44558e6cb0c57919cfb88929d19c83efeae0c46

Contents?: true

Size: 513 Bytes

Versions: 1

Compression:

Stored size: 513 Bytes

Contents

require 'chunky_png'

module Gitpaint
  class PNGRenderer < Array
    def initialize png_path 
      png = ChunkyPNG::Image.from_file png_path

      png.height.times do |i| 
        self.push(
	  png.row(i).to_a.map do |p|
            self.class.scale self.class.invert self.class.magnitude p
	  end
       	)
      end
    end

    def self.magnitude value 
      value / 256 ** 3
    end

    def self.invert value 
      256 - value
    end

    def self.scale value
      value / (256 / 5)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gitpaint-0.1.0 lib/gitpaint/png_renderer.rb