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