Class: PNG::Image
- Inherits:
-
Object
- Object
- PNG::Image
- Defined in:
- lib/spittle/png/image.rb
Constant Summary collapse
- RGB =
color types
2
- RGBA =
6
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .default_filter_type ⇒ Object
- .image_data(file_name, options = {}) ⇒ Object
- .open(file_name) ⇒ Object
- .write(file_name, data, options = {}) ⇒ Object
Instance Method Summary collapse
- #color_type ⇒ Object
- #depth ⇒ Object
- #filter_encoded_rows(filter_type) ⇒ Object
- #height ⇒ Object
-
#initialize(ihdr, idat, name, options = {}) ⇒ Image
constructor
A new instance of Image.
- #inspect ⇒ Object
-
#pixel_width ⇒ Object
check for RGB or RGBA.
- #to_image ⇒ Object
- #to_s ⇒ Object
- #uncompressed ⇒ Object
- #width ⇒ Object
- #write(file_name, options = {}) ⇒ Object
Constructor Details
#initialize(ihdr, idat, name, options = {}) ⇒ Image
Returns a new instance of Image.
48 49 50 51 52 53 |
# File 'lib/spittle/png/image.rb', line 48 def initialize( ihdr, idat, name, = {} ) @ihdr = ihdr @idat = idat @name = name @rows = [:rows] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
55 56 57 |
# File 'lib/spittle/png/image.rb', line 55 def name @name end |
Class Method Details
.default_filter_type ⇒ Object
32 33 34 |
# File 'lib/spittle/png/image.rb', line 32 def default_filter_type 4 # paeth end |
.image_data(file_name, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/spittle/png/image.rb', line 8 def image_data( file_name, ={} ) = {:rgba => true}.merge( ) png = open(file_name) return png.to_image unless [:rgba] png.to_image.to_rgba end |
Instance Method Details
#color_type ⇒ Object
59 |
# File 'lib/spittle/png/image.rb', line 59 def color_type; @ihdr.color_type end |
#depth ⇒ Object
58 |
# File 'lib/spittle/png/image.rb', line 58 def depth; @ihdr.depth end |
#filter_encoded_rows(filter_type) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/spittle/png/image.rb', line 74 def filter_encoded_rows(filter_type) out = Array.new(height) rows.each_with_index do |row, scanline| last_row = rows.last_scanline(scanline) out[scanline] = encode_row( row, last_row, filter_type, pixel_width) end out end |
#height ⇒ Object
57 |
# File 'lib/spittle/png/image.rb', line 57 def height; @ihdr.height end |
#inspect ⇒ Object
105 106 107 |
# File 'lib/spittle/png/image.rb', line 105 def inspect "#{@name} (#{height} x #{width}) [color type: #{color_type}, depth: #{depth}]" end |
#pixel_width ⇒ Object
check for RGB or RGBA
70 71 72 |
# File 'lib/spittle/png/image.rb', line 70 def pixel_width ( color_type == RGB ? 3 : 4) end |
#to_image ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/spittle/png/image.rb', line 83 def to_image uncompressed = @idat.uncompressed #scanline_width - 1 because we're stripping the filter bit n_out = Spittle::ImageData.new(:scanline_width => scanline_width - 1, :pixel_width => pixel_width, :name => self.name, :data => Array.new(height)) offset = 0 height.times do |scanline| end_row = scanline_width + offset row = uncompressed.slice(offset, scanline_width) n_out[scanline] = decode(scanline, row, n_out, pixel_width) offset = end_row end n_out end |
#to_s ⇒ Object
101 102 103 |
# File 'lib/spittle/png/image.rb', line 101 def to_s inspect end |
#uncompressed ⇒ Object
60 |
# File 'lib/spittle/png/image.rb', line 60 def uncompressed; @idat.uncompressed end |
#width ⇒ Object
56 |
# File 'lib/spittle/png/image.rb', line 56 def width; @ihdr.width end |
#write(file_name, options = {}) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/spittle/png/image.rb', line 62 def write(file_name, ={}) filter_type = [:filter_type] || Image.default_filter_type File.open(file_name, 'w') do |f| f.write(generate_png( filter_type )) end end |