Sha256: af7be08e22b888953b247cfb27fc62b36dacb75e785fb778b81786310a913cce

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

require File.expand_path('../spec_helper.rb', File.dirname(__FILE__))

describe ChunkyPNG::PixelMatrix do
  
  describe '.decode' do
    
    [:indexed, :grayscale, :grayscale_alpha, :truecolor, :truecolor_alpha].each do |color_mode|
      it "should decode an image with color mode #{color_mode} correctly" do
        reference = ChunkyPNG::PixelMatrix.new(10, 10, ChunkyPNG::Pixel.rgb(100, 100, 100))
        ds = ChunkyPNG.load(resource_file("gray_10x10_#{color_mode}.png"))
        ds.pixel_matrix.should == reference
      end
    end
    
    it "should decode a transparent image correctly" do
      reference = ChunkyPNG::PixelMatrix.new(10, 10, ChunkyPNG::Pixel.rgba(100, 100, 100, 128))
      ds = ChunkyPNG.load(resource_file("transparent_gray_10x10.png"))
        ds.pixel_matrix.should == reference
    end
    
    it "should decode an interlaced image correctly" do
      ds_i  = ChunkyPNG.load(resource_file("16x16_interlaced.png"))
      ds_ni = ChunkyPNG.load(resource_file("16x16_non_interlaced.png"))
      ds_i.pixel_matrix.should == ds_ni.pixel_matrix
    end
  end
  
  describe '.encode' do
    before(:each) do
      @reference = ChunkyPNG::PixelMatrix.new(10, 10, ChunkyPNG::Pixel.rgb(100, 100, 100))
    end
    
    [:indexed, :grayscale, :grayscale_alpha, :truecolor, :truecolor_alpha].each do |color_mode|
      it "should encode an image with color mode #{color_mode} correctly" do

        filename = resource_file("_tmp_#{color_mode}.png")
        File.open(filename, 'w') { |f| @reference.to_datastream.write(f) }
        
        ChunkyPNG.load(filename).pixel_matrix.should == @reference
        
        File.unlink(filename)
      end
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
chunky_png-0.0.3 spec/unit/pixel_matrix_spec.rb