lib/chunky_png/canvas/png_encoding.rb
# Encodes the canvas to a stream, in a given color mode.
# @param [String] stream The stream to write to.
# @param [Integer] color_mode The color mode to use for encoding.
# @param [Integer] bit_depth The bit depth of the image.
# @param [Integer] filtering The filtering method to use.
Encodes the canvas to a stream, in a given color mode.
Encodes the canvas to a stream in a given color mode .
def encode_png_image_pass_to_stream(stream, color_mode, bit_depth, filtering)
        start_pos  = stream.bytesize
        pixel_size = Color.pixel_bytesize(color_mode)
        line_width = Color.scanline_bytesize(color_mode, bit_depth, width)
        encode_method = encode_png_pixels_to_scanline_method(color_mode, bit_depth)
        filter_method = case filtering
          when ChunkyPNG::FILTER_NONE    then nil
          when ChunkyPNG::FILTER_SUB     then :encode_png_str_scanline_sub
          when ChunkyPNG::FILTER_UP      then :encode_png_str_scanline_up
          when ChunkyPNG::FILTER_AVERAGE then :encode_png_str_scanline_average
          when ChunkyPNG::FILTER_PAETH   then :encode_png_str_scanline_paeth
          else raise ArgumentError, "Filtering method #{filtering} is not supported"
        end
        0.upto(height - 1) do |y|
          stream << send(encode_method, row(y))
        end
        if filter_method
          (height - 1).downto(0) do |y|
            pos = start_pos + y * (line_width + 1)
            prev_pos = y == 0 ? nil : pos - (line_width + 1)
            send(filter_method, stream, pos, prev_pos, line_width, pixel_size)
          end
        end
      end
def encode_png_image_pass_to_stream ( stream , color_mode , bit_depth , filtering ) start_pos = stream . bytesize pixel_size = Color . pixel_bytesize ( color_mode ) line_width = Color . scanline_bytesize ( color_mode , bit_depth , width ) encode_method = encode_png_pixels_to_scanline_method ( color_mode , bit_depth ) filter_method = case filtering when ChunkyPNG :: FILTER_NONE then nil when ChunkyPNG :: FILTER_SUB then :encode_png_str_scanline_sub when ChunkyPNG :: FILTER_UP then :encode_png_str_scanline_up when ChunkyPNG :: FILTER_AVERAGE then :encode_png_str_scanline_average when ChunkyPNG :: FILTER_PAETH then :encode_png_str_scanline_paeth else raise ArgumentError , "Filtering method #{filtering} is not supported" end 0 . upto ( height - 1 ) do | y | stream << send ( encode_method , row ( y ) ) end if filter_method ( height - 1 ) . downto ( 0 ) do | y | pos = start_pos + y * ( line_width + 1 ) prev_pos = y == 0 ? nil : pos - ( line_width + 1 ) send ( filter_method , stream , pos , prev_pos , line_width , pixel_size ) end end end
Encodes the canvas to a stream, in a given color mode.
Encodes the canvas to a stream in a given color mode .
# Determine the filter method # Now, apply filtering if any
stream
<not_specific>
color_mode
<not_specific>
bit_depth
<not_specific>
filtering
<not_specific>
<not_specific>
filtering The filtering method to use.
filtering The filtering method to use .