lib/chunky_png/canvas/png_encoding.rb
# Encodes a line of pixels using 1-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 1-bit indexed mode.
Encodes a line of pixels using 1 - bit indexed mode .
def encode_png_pixels_to_scanline_indexed_1bit(pixels)
        chars = []
        pixels.each_slice(8) do |p1, p2, p3, p4, p5, p6, p7, p8|
          chars << (
            (encoding_palette.index(p1) << 7) |
            (encoding_palette.index(p2) << 6) |
            (encoding_palette.index(p3) << 5) |
            (encoding_palette.index(p4) << 4) |
            (encoding_palette.index(p5) << 3) |
            (encoding_palette.index(p6) << 2) |
            (encoding_palette.index(p7) << 1) |
            encoding_palette.index(p8)
          )
        end
        chars.pack("xC*")
      end
def encode_png_pixels_to_scanline_indexed_1bit ( pixels ) chars = [ ] pixels . each_slice ( 8 ) do | p1 , p2 , p3 , p4 , p5 , p6 , p7 , p8 | chars << ( ( encoding_palette . index ( p1 ) << 7 ) | ( encoding_palette . index ( p2 ) << 6 ) | ( encoding_palette . index ( p3 ) << 5 ) | ( encoding_palette . index ( p4 ) << 4 ) | ( encoding_palette . index ( p5 ) << 3 ) | ( encoding_palette . index ( p6 ) << 2 ) | ( encoding_palette . index ( p7 ) << 1 ) | encoding_palette . index ( p8 ) ) end chars . pack ( "xC*" ) end
Encodes a line of pixels using 1-bit indexed mode.
Encodes a line of pixels using 1 - 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 .