lib/chunky_png/palette.rb in chunky_png-1.3.11 vs lib/chunky_png/palette.rb in chunky_png-1.3.12

- old
+ new

@@ -38,16 +38,12 @@ return nil if palette_chunk.nil? decoding_map = [] index = 0 - palatte_bytes = palette_chunk.content.unpack('C*') - if transparency_chunk - alpha_channel = transparency_chunk.content.unpack('C*') - else - alpha_channel = [] - end + palatte_bytes = palette_chunk.content.unpack("C*") + alpha_channel = transparency_chunk ? transparency_chunk.content.unpack("C*") : [] index = 0 palatte_bytes.each_slice(3) do |bytes| bytes << alpha_channel.fetch(index, ChunkyPNG::Color::MAX) decoding_map << ChunkyPNG::Color.rgba(*bytes) @@ -163,11 +159,11 @@ # Note that this chunk can be left out of every color in the palette is # opaque, and the image is encoded using indexed colors. # # @return [ChunkyPNG::Chunk::Transparency] The tRNS chunk. def to_trns_chunk - ChunkyPNG::Chunk::Transparency.new('tRNS', map { |c| ChunkyPNG::Color.a(c) }.pack('C*')) + ChunkyPNG::Chunk::Transparency.new("tRNS", map { |c| ChunkyPNG::Color.a(c) }.pack("C*")) end # Creates a PLTE chunk that corresponds with this palette to store the r, # g, and b channels of all colors. # @@ -184,11 +180,11 @@ each_with_index do |color, index| @encoding_map[color] = index colors += ChunkyPNG::Color.to_truecolor_bytes(color) end - ChunkyPNG::Chunk::Palette.new('PLTE', colors.pack('C*')) + ChunkyPNG::Chunk::Palette.new("PLTE", colors.pack("C*")) end # Determines the most suitable colormode for this palette. # @return [Integer] The colormode which would create the smallest possible # file for images that use this exact palette. @@ -217,10 +213,9 @@ case size when 1..2 then 1 when 3..4 then 2 when 5..16 then 4 when 17..256 then 8 - else nil end end end end