lib/chunky_png/image.rb in chunky_png-0.0.1 vs lib/chunky_png/image.rb in chunky_png-0.0.2

- old
+ new

@@ -1,11 +1,11 @@ module ChunkyPNG class Image attr_reader :pixels - def initialize(width, height, background_color = ChunkyPNG::Color::WHITE) + def initialize(width, height, background_color = ChunkyPNG::Pixel::TRANSPARENT) @pixels = ChunkyPNG::PixelMatrix.new(width, height, background_color) end def width pixels.width @@ -13,25 +13,11 @@ def height pixels.height end - def write(io) - datastream = ChunkyPNG::Datastream.new - - palette = pixels.palette - if palette.indexable? - datastream.header_chunk = ChunkyPNG::Chunk::Header.new(:width => width, :height => height, :color => ChunkyPNG::Chunk::Header::COLOR_INDEXED) - datastream.palette_chunk = palette.to_plte_chunk - datastream.data_chunks = datastream.idat_chunks(pixels.to_indexed_pixelstream(palette)) - datastream.end_chunk = ChunkyPNG::Chunk::End.new - else - raise 'd' - datastream.header_chunk = ChunkyPNG::Chunk::Header.new(:width => width, :height => height) - datastream.data_chunks = datastream.idat_chunks(pixels.to_rgb_pixelstream) - datastream.end_chunk = ChunkyPNG::Chunk::End.new - end - + def write(io, constraints = {}) + datastream = pixels.to_datastream(constraints) datastream.write(io) end end end \ No newline at end of file