lib/chunky_png/canvas/png_encoding.rb
# Encodes the canvas according to the PNG format specification with a given color
# mode, possibly with interlacing.
# @param [Integer] color_mode The color mode to use for encoding.
# @param [Integer] bit_depth The bit depth of the image.
# @param [Integer] interlace The interlacing method to use.
# @return [String] The PNG encoded canvas as string.
Encodes the canvas according to the PNG format specification with a given color
mode, possibly with interlacing.
Encodes the canvas according to the PNG format specification with a given color mode possibly with interlacing .
def encode_png_pixelstream(color_mode = ChunkyPNG::COLOR_TRUECOLOR, bit_depth = 8, interlace = ChunkyPNG::INTERLACING_NONE, filtering = ChunkyPNG::FILTER_NONE)
        if color_mode == ChunkyPNG::COLOR_INDEXED
          raise ChunkyPNG::ExpectationFailed, "This palette is not suitable for encoding!" if encoding_palette.nil? || !encoding_palette.can_encode?
          raise ChunkyPNG::ExpectationFailed, "This palette has too many colors!" if encoding_palette.size > (1 << bit_depth)
        end
        case interlace
          when ChunkyPNG::INTERLACING_NONE  then encode_png_image_without_interlacing(color_mode, bit_depth, filtering)
          when ChunkyPNG::INTERLACING_ADAM7 then encode_png_image_with_interlacing(color_mode, bit_depth, filtering)
          else raise ChunkyPNG::NotSupported, "Unknown interlacing method: #{interlace}!"
        end
      end
def encode_png_pixelstream ( color_mode = ChunkyPNG :: COLOR_TRUECOLOR , bit_depth = 8 , interlace = ChunkyPNG :: INTERLACING_NONE , filtering = ChunkyPNG :: FILTER_NONE ) if color_mode == ChunkyPNG :: COLOR_INDEXED raise ChunkyPNG :: ExpectationFailed , "This palette is not suitable for encoding!" if encoding_palette . nil? || ! encoding_palette . can_encode? raise ChunkyPNG :: ExpectationFailed , "This palette has too many colors!" if encoding_palette . size > ( 1 << bit_depth ) end case interlace when ChunkyPNG :: INTERLACING_NONE then encode_png_image_without_interlacing ( color_mode , bit_depth , filtering ) when ChunkyPNG :: INTERLACING_ADAM7 then encode_png_image_with_interlacing ( color_mode , bit_depth , filtering ) else raise ChunkyPNG :: NotSupported , "Unknown interlacing method: #{interlace}!" end end
Encodes the canvas according to the PNG format specification with a given color
mode, possibly with interlacing.
Encodes the canvas according to the PNG format specification with a given color mode possibly with interlacing .
The PNG encoded canvas as string.
The PNG encoded canvas as string .
String
color_mode
<not_specific>
bit_depth
<not_specific>
interlace
<not_specific>
filtering
<not_specific>
<not_specific>
interlace The interlacing method to use.
interlace The interlacing method to use .