Class: Branding::PNG::Imagedata
- Inherits:
-
Object
- Object
- Branding::PNG::Imagedata
- Includes:
- Enumerable
- Defined in:
- lib/branding/png.rb
Overview
Private class for holding and deflating image data
Instance Method Summary collapse
-
#each ⇒ Object
yields byte.
- #each_pixel ⇒ Object
- #each_scanline ⇒ Object
-
#initialize(data: nil, scanline_width: 0, color_channels: 3) ⇒ Imagedata
constructor
A new instance of Imagedata.
Constructor Details
#initialize(data: nil, scanline_width: 0, color_channels: 3) ⇒ Imagedata
Returns a new instance of Imagedata.
17 18 19 20 21 22 23 24 25 |
# File 'lib/branding/png.rb', line 17 def initialize(data: nil, scanline_width: 0, color_channels: 3) @scanline_width = scanline_width @color_channels = color_channels zstream = Zlib::Inflate.new zstream << data @inflated = zstream.finish zstream.close end |
Instance Method Details
#each ⇒ Object
yields byte
29 30 31 32 33 |
# File 'lib/branding/png.rb', line 29 def each @inflated.each_byte do |byte| yield byte end end |
#each_pixel ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/branding/png.rb', line 51 def each_pixel each_scanline do |scanline| scanline.each_slice(@color_channels) do |*rgba| yield Pixel.new(*rgba) end end end |
#each_scanline ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/branding/png.rb', line 35 def each_scanline # the number of bytes is + 1 because of the filter byte bytes_in_scanline = @scanline_width * @color_channels + 1 previous_scanline = nil each_slice(bytes_in_scanline) do |scanline| filter_bit, *rest = *scanline filter = Filter.new(filter_bit, rest, previous_scanline, @color_channels) recon = filter.reconstructed_scanline yield recon previous_scanline = recon end end |