lib/chunky_png/canvas/png_encoding.rb
# Encodes a line of pixels using 2-bit indexed mode.
# @param [Array<Integer>] pixels A row of pixels of the original image.
# @return [String] The encoded scanline as binary string
Encodes a line of pixels using 2-bit indexed mode.
Encodes a line of pixels using 2 - bit indexed mode .
def encode_png_pixels_to_scanline_indexed_2bit(pixels)
        chars = []
        pixels.each_slice(4) do |p1, p2, p3, p4|
          chars << (
            (encoding_palette.index(p1) << 6) |
            (encoding_palette.index(p2) << 4) |
            (encoding_palette.index(p3) << 2) |
            encoding_palette.index(p4)
          )
        end
        chars.pack("xC*")
      end
def encode_png_pixels_to_scanline_indexed_2bit ( pixels ) chars = [ ] pixels . each_slice ( 4 ) do | p1 , p2 , p3 , p4 | chars << ( ( encoding_palette . index ( p1 ) << 6 ) | ( encoding_palette . index ( p2 ) << 4 ) | ( encoding_palette . index ( p3 ) << 2 ) | encoding_palette . index ( p4 ) ) end chars . pack ( "xC*" ) end
Encodes a line of pixels using 2-bit indexed mode.
Encodes a line of pixels using 2 - bit indexed mode .
The encoded scanline as binary string
The encoded scanline as binary string
String
pixels
<not_specific>
<not_specific>
pixels A row of pixels of the original image.
pixels A row of pixels of the original image .