lib/chunky_png/canvas/png_encoding.rb
# Encodes a line of pixels using 2-bit grayscale 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 grayscale mode.
Encodes a line of pixels using 2 - bit grayscale mode .
def encode_png_pixels_to_scanline_grayscale_4bit(pixels)
        chars = []
        pixels.each_slice(2) do |p1, p2|
          chars << ((p1.nil? ? 0 : ((p1 & 0x0000ffff) >> 12) << 4) | (p2.nil? ? 0 : ((p2 & 0x0000ffff) >> 12)))
        end
        chars.pack("xC*")
      end
def encode_png_pixels_to_scanline_grayscale_4bit ( pixels ) chars = [ ] pixels . each_slice ( 2 ) do | p1 , p2 | chars << ( ( p1 . nil? ? 0 : ( ( p1 & 0x0000ffff ) >> 12 ) << 4 ) | ( p2 . nil? ? 0 : ( ( p2 & 0x0000ffff ) >> 12 ) ) ) end chars . pack ( "xC*" ) end
Encodes a line of pixels using 2-bit grayscale mode.
Encodes a line of pixels using 2 - bit grayscale 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 .