Module ChunkyPNG::Canvas::PNGDecoding
In: lib/chunky_png/canvas/png_decoding.rb

The PNGDecoding contains methods for decoding PNG datastreams to create a Canvas object. The datastream can be provided as filename, string or IO stream.

Overview of the decoding process:

  • The optional PLTE and tRNS chunk are decoded for the color palette of the original image.
  • The contents of the IDAT chunks is combined, and uncompressed using Inflate decompression to the image pixelstream.
  • Based on the color mode, width and height of the original image, which is read from the PNG header (IHDR chunk), the amount of bytes per line is determined.
  • For every line of pixels in the encoded image, the original byte values are restored by unapplying the milter method for that line.
  • The read bytes are unfiltered given by the filter function specified by the first byte of the line.
  • The unfiltered pixelstream are is into colored pixels, using the color mode.
  • All lines combined to form the original image.

For interlaced images, the original image was split into 7 subimages. These images get decoded just like the process above (from step 3), and get combined to form the original images.

@see ChunkyPNG::Canvas::PNGEncoding @see www.w3.org/TR/PNG/ The W3C PNG format specification

Methods

decode_png_extract_1bit_value   decode_png_extract_2bit_value   decode_png_extract_4bit_value   decode_png_image_pass   decode_png_pixels_from_scanline_grayscale_16bit   decode_png_pixels_from_scanline_grayscale_1bit   decode_png_pixels_from_scanline_grayscale_2bit   decode_png_pixels_from_scanline_grayscale_4bit   decode_png_pixels_from_scanline_grayscale_8bit   decode_png_pixels_from_scanline_grayscale_alpha_16bit   decode_png_pixels_from_scanline_grayscale_alpha_8bit   decode_png_pixels_from_scanline_indexed_1bit   decode_png_pixels_from_scanline_indexed_2bit   decode_png_pixels_from_scanline_indexed_4bit   decode_png_pixels_from_scanline_indexed_8bit   decode_png_pixels_from_scanline_method   decode_png_pixels_from_scanline_truecolor_16bit   decode_png_pixels_from_scanline_truecolor_8bit   decode_png_pixels_from_scanline_truecolor_alpha_16bit   decode_png_pixels_from_scanline_truecolor_alpha_8bit   decode_png_pixelstream   decode_png_resample_16bit_value   decode_png_resample_1bit_value   decode_png_resample_2bit_value   decode_png_resample_4bit_value   decode_png_resample_8bit_value   decode_png_str_scanline   decode_png_str_scanline_average   decode_png_str_scanline_paeth   decode_png_str_scanline_sub   decode_png_str_scanline_sub_none   decode_png_str_scanline_up   decode_png_with_adam7_interlacing   decode_png_without_interlacing   from_blob   from_datastream   from_file   from_io   from_stream   from_string  

Attributes

decoding_palette  [RW]  The palette that is used to decode the image, loading from the PLTE and tRNS chunk from the PNG stream. For RGB(A) images, no palette is required. @return [ChunkyPNG::Palette]
transparent_color  [RW]  The color to be replaced with fully transparent pixels.

Public Instance methods

Decodes a canvas from a PNG encoded pixelstream, using a given width, height, color mode and interlacing mode. @param [String] stream The pixelstream to read from. @param [Integer] width The width of the image. @param [Integer] width The height of the image. @param [Integer] color_mode The color mode of the encoded pixelstream. @param [Integer] depth The bit depth of the pixel samples. @param [Integer] interlace The interlace method of the encoded pixelstream. @return [ChunkyPNG::Canvas] The decoded Canvas instance.

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 100
100:       def decode_png_pixelstream(stream, width, height, color_mode, depth, interlace)
101:         raise ChunkyPNG::ExpectationFailed, "This palette is not suitable for decoding!" if decoding_palette && !decoding_palette.can_decode?
102: 
103:         image = case interlace
104:           when ChunkyPNG::INTERLACING_NONE;  decode_png_without_interlacing(stream, width, height, color_mode, depth)
105:           when ChunkyPNG::INTERLACING_ADAM7; decode_png_with_adam7_interlacing(stream, width, height, color_mode, depth)
106:           else raise ChunkyPNG::NotSupported, "Don't know how the handle interlacing method #{interlace}!"
107:         end
108:         
109:         image.pixels.map! { |c| c == transparent_color ? ChunkyPNG::Color::TRANSPARENT : c } if transparent_color
110:         return image
111:       end

Decodes a Canvas from a PNG encoded string. @param [String] str The string to read from. @return [ChunkyPNG::Canvas] The canvas decoded from the PNG encoded string.

[Source]

    # File lib/chunky_png/canvas/png_decoding.rb, line 43
43:       def from_blob(str)
44:         from_datastream(ChunkyPNG::Datastream.from_blob(str))
45:       end

Decodes the Canvas from a PNG datastream instance. @param [ChunkyPNG::Datastream] ds The datastream to decode. @return [ChunkyPNG::Canvas] The canvas decoded from the PNG datastream.

[Source]

    # File lib/chunky_png/canvas/png_decoding.rb, line 68
68:       def from_datastream(ds)
69:         width      = ds.header_chunk.width
70:         height     = ds.header_chunk.height
71:         color_mode = ds.header_chunk.color
72:         interlace  = ds.header_chunk.interlace
73:         depth      = ds.header_chunk.depth
74: 
75:         if width == 0 || height == 0
76:           raise ExpectationFailed, "Invalid image size, width: #{width}, height: #{height}"
77:         end
78: 
79:         case color_mode
80:           when ChunkyPNG::COLOR_INDEXED
81:             self.decoding_palette = ChunkyPNG::Palette.from_chunks(ds.palette_chunk, ds.transparency_chunk)
82:           when ChunkyPNG::COLOR_TRUECOLOR
83:             self.transparent_color = ds.transparency_chunk.truecolor_entry(depth) if ds.transparency_chunk
84:           when ChunkyPNG::COLOR_GRAYSCALE
85:             self.transparent_color = ds.transparency_chunk.grayscale_entry(depth) if ds.transparency_chunk
86:         end
87:             
88:         decode_png_pixelstream(ds.imagedata, width, height, color_mode, depth, interlace)
89:       end

Decodes a Canvas from a PNG encoded file. @param [String] filename The file to read from. @return [ChunkyPNG::Canvas] The canvas decoded from the PNG file.

[Source]

    # File lib/chunky_png/canvas/png_decoding.rb, line 52
52:       def from_file(filename)
53:         from_datastream(ChunkyPNG::Datastream.from_file(filename))
54:       end

Decodes a Canvas from a PNG encoded stream. @param [IO, read] io The stream to read from. @return [ChunkyPNG::Canvas] The canvas decoded from the PNG stream.

[Source]

    # File lib/chunky_png/canvas/png_decoding.rb, line 59
59:       def from_io(io)
60:         from_datastream(ChunkyPNG::Datastream.from_io(io))
61:       end
from_stream(io)

Alias for from_io

from_string(str)

Alias for from_blob

Protected Instance methods

Extract a bit from a byte on a given index. @param [Integer] byte The byte (0..255) value to extract a bit from. @param [Integer] index The index within the byte. This should be 0..7;

       the value will be modded by 8 to enforce this.

@return [Integer] Either 1 or 0.

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 171
171:       def decode_png_extract_1bit_value(byte, index)
172:         bitshift = 7 - (index & 0x07)
173:         (byte & (0x01 << bitshift)) >> bitshift
174:       end

Extract 2 consecutive bits from a byte. @param [Integer] byte The byte (0..255) value to extract a 2 bit value from. @param [Integer] index The index within the byte. This should be either 0, 1, 2, or 3;

       the value will be modded by 4 to enforce this.

@return [Integer] The extracted 2 bit value (0..3)

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 161
161:       def decode_png_extract_2bit_value(byte, index)
162:         bitshift = 6 - ((index & 0x03) << 1)
163:         (byte & (0x03 << bitshift)) >> bitshift
164:       end

Extract 4 consecutive bits from a byte. @param [Integer] byte The byte (0..255) value to extract a 4 bit value from. @param [Integer] index The index within the byte. This should be either 0 or 2;

       the value will be modded by 2 to enforce this.

@return [Integer] The extracted 4bit value (0..15)

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 152
152:       def decode_png_extract_4bit_value(byte, index)
153:         (index & 0x01 == 0) ? ((byte & 0xf0) >> 4) : (byte & 0x0f)
154:       end

Decodes a single PNG image pass width a given width, height and color mode, to a Canvas, starting at the given position in the stream.

A non-interlaced image only consists of one pass, while an Adam7 image consists of 7 passes that must be combined after decoding.

@param stream (see ChunkyPNG::Canvas::PNGDecoding#decode_png_pixelstream) @param width (see ChunkyPNG::Canvas::PNGDecoding#decode_png_pixelstream) @param height (see ChunkyPNG::Canvas::PNGDecoding#decode_png_pixelstream) @param color_mode (see ChunkyPNG::Canvas::PNGDecoding#decode_png_pixelstream) @param [Integer] start_pos The position in the pixel stream to start reading. @return (see ChunkyPNG::Canvas::PNGDecoding#decode_png_pixelstream)

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 404
404:       def decode_png_image_pass(stream, width, height, color_mode, depth, start_pos)
405:         
406:         pixels = []
407:         if width > 0 && height > 0
408:           
409:           stream << ChunkyPNG::EXTRA_BYTE if color_mode == ChunkyPNG::COLOR_TRUECOLOR
410:           pixel_decoder = decode_png_pixels_from_scanline_method(color_mode, depth)
411:           line_length   = ChunkyPNG::Color.scanline_bytesize(color_mode, depth, width)
412:           pixel_size    = ChunkyPNG::Color.pixel_bytesize(color_mode, depth)
413:           
414:           raise ChunkyPNG::ExpectationFailed, "Invalid stream length!" unless stream.bytesize - start_pos >= ChunkyPNG::Color.pass_bytesize(color_mode, depth, width, height)
415: 
416:           pos, prev_pos = start_pos, nil
417:           for line_no in 0...height do
418:             decode_png_str_scanline(stream, pos, prev_pos, line_length, pixel_size)
419:             pixels += send(pixel_decoder, stream, pos, width)
420: 
421:             prev_pos = pos
422:             pos += line_length + 1
423:           end
424:         end
425: 
426:         new(width, height, pixels)
427:       end

Decodes a scanline of a 16-bit, grayscale image into a row of pixels. @params (see decode_png_pixels_from_scanline_indexed_1bit) @return (see decode_png_pixels_from_scanline_indexed_1bit)

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 368
368:       def decode_png_pixels_from_scanline_grayscale_16bit(stream, pos, width)
369:         values = stream.unpack("@#{pos + 1}n#{width}")
370:         values.map { |value| ChunkyPNG::Color.grayscale(decode_png_resample_16bit_value(value)) }
371:       end

Decodes a scanline of a 1-bit, grayscale image into a row of pixels. @params (see decode_png_pixels_from_scanline_indexed_1bit) @return (see decode_png_pixels_from_scanline_indexed_1bit)

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 331
331:       def decode_png_pixels_from_scanline_grayscale_1bit(stream, pos, width)
332:         (0...width).map do |index|
333:           value = decode_png_extract_1bit_value(stream.getbyte(pos + 1 + (index >> 3)), index)
334:           value == 1 ? ChunkyPNG::Color::WHITE : ChunkyPNG::Color::BLACK
335:         end
336:       end

Decodes a scanline of a 2-bit, grayscale image into a row of pixels. @params (see decode_png_pixels_from_scanline_indexed_1bit) @return (see decode_png_pixels_from_scanline_indexed_1bit)

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 341
341:       def decode_png_pixels_from_scanline_grayscale_2bit(stream, pos, width)
342:         (0...width).map do |index|
343:           value = decode_png_extract_2bit_value(stream.getbyte(pos + 1 + (index >> 2)), index)
344:           ChunkyPNG::Color.grayscale(decode_png_resample_2bit_value(value))
345:         end
346:       end

Decodes a scanline of a 4-bit, grayscale image into a row of pixels. @params (see decode_png_pixels_from_scanline_indexed_1bit) @return (see decode_png_pixels_from_scanline_indexed_1bit)

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 351
351:       def decode_png_pixels_from_scanline_grayscale_4bit(stream, pos, width)
352:         (0...width).map do |index|
353:           value = decode_png_extract_4bit_value(stream.getbyte(pos + 1 + (index >> 1)), index)
354:           ChunkyPNG::Color.grayscale(decode_png_resample_4bit_value(value))
355:         end
356:       end

Decodes a scanline of an 8-bit, grayscale image into a row of pixels. @params (see decode_png_pixels_from_scanline_indexed_1bit) @return (see decode_png_pixels_from_scanline_indexed_1bit)

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 361
361:       def decode_png_pixels_from_scanline_grayscale_8bit(stream, pos, width)
362:         (1..width).map { |i| ChunkyPNG::Color.grayscale(stream.getbyte(pos + i)) }
363:       end

Decodes a scanline of a 16-bit, grayscale image with transparency into a row of pixels. @params (see decode_png_pixels_from_scanline_indexed_1bit) @return (see decode_png_pixels_from_scanline_indexed_1bit)

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 320
320:       def decode_png_pixels_from_scanline_grayscale_alpha_16bit(stream, pos, width)
321:         pixels = []
322:         stream.unpack("@#{pos + 1}n#{width * 2}").each_slice(2) do |g, a|
323:           pixels << ChunkyPNG::Color.grayscale_alpha(decode_png_resample_16bit_value(g), decode_png_resample_16bit_value(a))
324:         end
325:         return pixels
326:       end

Decodes a scanline of an 8-bit, grayscale image with transparency into a row of pixels. @params (see decode_png_pixels_from_scanline_indexed_1bit) @return (see decode_png_pixels_from_scanline_indexed_1bit)

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 313
313:       def decode_png_pixels_from_scanline_grayscale_alpha_8bit(stream, pos, width)
314:         (0...width).map { |i| ChunkyPNG::Color.grayscale_alpha(stream.getbyte(pos + (i * 2) + 1), stream.getbyte(pos + (i * 2) + 2)) }
315:       end

Decodes a scanline of a 1-bit, indexed image into a row of pixels. @param [String] stream The stream to decode from. @param [Integer] pos The position in the stream on which the scanline starts (including the filter byte). @param [Integer] width The width in pixels of the scanline. @return [Array<Integer>] An array of decoded pixels.

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 239
239:       def decode_png_pixels_from_scanline_indexed_1bit(stream, pos, width)
240:         (0...width).map do |index|
241:           palette_pos = decode_png_extract_1bit_value(stream.getbyte(pos + 1 + (index >> 3)), index) 
242:           decoding_palette[palette_pos]
243:         end
244:       end

Decodes a scanline of a 2-bit, indexed image into a row of pixels. @params (see decode_png_pixels_from_scanline_indexed_1bit) @return (see decode_png_pixels_from_scanline_indexed_1bit)

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 249
249:       def decode_png_pixels_from_scanline_indexed_2bit(stream, pos, width)
250:         (0...width).map do |index|
251:           palette_pos = decode_png_extract_2bit_value(stream.getbyte(pos + 1 + (index >> 2)), index)
252:           decoding_palette[palette_pos]
253:         end
254:       end

Decodes a scanline of a 4-bit, indexed image into a row of pixels. @params (see decode_png_pixels_from_scanline_indexed_1bit) @return (see decode_png_pixels_from_scanline_indexed_1bit)

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 259
259:       def decode_png_pixels_from_scanline_indexed_4bit(stream, pos, width)
260:         (0...width).map do |index|
261:           palette_pos = decode_png_extract_4bit_value(stream.getbyte(pos + 1 + (index >> 1)), index)
262:           decoding_palette[palette_pos]
263:         end
264:       end

Decodes a scanline of a 8-bit, indexed image into a row of pixels. @params (see decode_png_pixels_from_scanline_indexed_1bit) @return (see decode_png_pixels_from_scanline_indexed_1bit)

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 269
269:       def decode_png_pixels_from_scanline_indexed_8bit(stream, pos, width)
270:         (1..width).map { |i| decoding_palette[stream.getbyte(pos + i)] }
271:       end

Returns the method name to use to decode scanlines into pixels. @param [Integer] color_mode The color mode of the image. @param [Integer] depth The bit depth of the image. @return [Symbol] The method name to use for decoding, to be called on the canvas class. @raise [ChunkyPNG::NotSupported] when the color_mode and/or bit depth is not supported.

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 378
378:       def decode_png_pixels_from_scanline_method(color_mode, depth)
379:         decoder_method = case color_mode
380:           when ChunkyPNG::COLOR_TRUECOLOR;       "decode_png_pixels_from_scanline_truecolor_#{depth}bit""decode_png_pixels_from_scanline_truecolor_#{depth}bit"
381:           when ChunkyPNG::COLOR_TRUECOLOR_ALPHA; "decode_png_pixels_from_scanline_truecolor_alpha_#{depth}bit""decode_png_pixels_from_scanline_truecolor_alpha_#{depth}bit"
382:           when ChunkyPNG::COLOR_INDEXED;         "decode_png_pixels_from_scanline_indexed_#{depth}bit""decode_png_pixels_from_scanline_indexed_#{depth}bit"
383:           when ChunkyPNG::COLOR_GRAYSCALE;       "decode_png_pixels_from_scanline_grayscale_#{depth}bit""decode_png_pixels_from_scanline_grayscale_#{depth}bit"
384:           when ChunkyPNG::COLOR_GRAYSCALE_ALPHA; "decode_png_pixels_from_scanline_grayscale_alpha_#{depth}bit""decode_png_pixels_from_scanline_grayscale_alpha_#{depth}bit"
385:           else nil
386:         end
387:         
388:         raise ChunkyPNG::NotSupported, "No decoder found for color mode #{color_mode} and #{depth}-bit depth!" unless respond_to?(decoder_method, true)
389:         decoder_method
390:       end

Decodes a scanline of a 16-bit, true color image into a row of pixels. @params (see decode_png_pixels_from_scanline_indexed_1bit) @return (see decode_png_pixels_from_scanline_indexed_1bit)

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 302
302:       def decode_png_pixels_from_scanline_truecolor_16bit(stream, pos, width)
303:         pixels = []
304:         stream.unpack("@#{pos + 1}n#{width * 3}").each_slice(3) do |r, g, b|
305:           pixels << ChunkyPNG::Color.rgb(decode_png_resample_16bit_value(r), decode_png_resample_16bit_value(g), decode_png_resample_16bit_value(b))
306:         end
307:         return pixels
308:       end

Decodes a scanline of an 8-bit, true color image into a row of pixels. @params (see decode_png_pixels_from_scanline_indexed_1bit) @return (see decode_png_pixels_from_scanline_indexed_1bit)

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 295
295:       def decode_png_pixels_from_scanline_truecolor_8bit(stream, pos, width)
296:         stream.unpack("@#{pos + 1}" << ('NX' * width)).map { |c| c | 0x000000ff }
297:       end

Decodes a scanline of a 16-bit, true color image with transparency into a row of pixels. @params (see decode_png_pixels_from_scanline_indexed_1bit) @return (see decode_png_pixels_from_scanline_indexed_1bit)

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 283
283:       def decode_png_pixels_from_scanline_truecolor_alpha_16bit(stream, pos, width)
284:         pixels = []
285:         stream.unpack("@#{pos + 1}n#{width * 4}").each_slice(4) do |r, g, b, a|
286:           pixels << ChunkyPNG::Color.rgba(decode_png_resample_16bit_value(r), decode_png_resample_16bit_value(g),
287:                                           decode_png_resample_16bit_value(b), decode_png_resample_16bit_value(a))
288:         end
289:         return pixels
290:       end

Decodes a scanline of an 8-bit, true color image with transparency into a row of pixels. @params (see decode_png_pixels_from_scanline_indexed_1bit) @return (see decode_png_pixels_from_scanline_indexed_1bit)

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 276
276:       def decode_png_pixels_from_scanline_truecolor_alpha_8bit(stream, pos, width)
277:         stream.unpack("@#{pos + 1}N#{width}")
278:       end

Resamples a 16 bit value to an 8 bit value. This will discard some color information. @param [Integer] value The 16 bit value to resample. @return [Integer] The 8 bit resampled value

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 179
179:       def decode_png_resample_16bit_value(value)
180:         value >> 8
181:       end

Resamples a 1 bit value to an 8 bit value. @param [Integer] value The 1 bit value to resample. @return [Integer] The 8 bit resampled value

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 229
229:       def decode_png_resample_1bit_value(value)
230:         value == 0x01 ? 0xff : 0x00
231:       end

Resamples a 2 bit value to an 8 bit value. @param [Integer] value The 2 bit value to resample. @return [Integer] The 8 bit resampled value.

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 217
217:       def decode_png_resample_2bit_value(value)
218:         case value
219:         when 0x00; 0x00
220:         when 0x01; 0x55
221:         when 0x02; 0xaa
222:         when 0x03; 0xff
223:         end
224:       end

Resamples a 4 bit value to an 8 bit value. @param [Integer] value The 4 bit value to resample. @return [Integer] The 8 bit resampled value.

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 193
193:       def decode_png_resample_4bit_value(value)
194:         case value
195:         when 0x00; 0
196:         when 0x01; 17
197:         when 0x02; 34
198:         when 0x03; 51
199:         when 0x04; 68
200:         when 0x05; 85
201:         when 0x06; 102
202:         when 0x07; 119
203:         when 0x08; 137
204:         when 0x09; 154
205:         when 0x0a; 171
206:         when 0x0b; 188
207:         when 0x0c; 205
208:         when 0x0d; 222
209:         when 0x0e; 239
210:         when 0x0f; 255
211:         end
212:       end

No-op - available for completeness sake only @param [Integer] value The 8 bit value to resample. @return [Integer] The 8 bit resampled value

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 186
186:       def decode_png_resample_8bit_value(value)
187:         value
188:       end

Decodes a scanline if it was encoded using filtering.

It will extract the filtering method from the first byte of the scanline, and uses the method to change the subsequent bytes to unfiltered values. This will modify the pixelstream.

The bytes of the scanline can then be used to construct pixels, based on the color mode..

@param [String] stream The pixelstream to undo the filtering in. @param [Integer] pos The starting position of the scanline to decode. @param [Integer, nil] prev_pos The starting position of the previously decoded scanline, or nil

    if this is the first scanline of the image.

@param [Integer] line_length The number of bytes in the scanline, discounting the filter method byte. @param [Integer] pixel_size The number of bytes used per pixel, based on the color mode. @return [void]

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 443
443:       def decode_png_str_scanline(stream, pos, prev_pos, line_length, pixel_size)
444:         case stream.getbyte(pos)
445:           when ChunkyPNG::FILTER_NONE;    # noop
446:           when ChunkyPNG::FILTER_SUB;     decode_png_str_scanline_sub(     stream, pos, prev_pos, line_length, pixel_size)
447:           when ChunkyPNG::FILTER_UP;      decode_png_str_scanline_up(      stream, pos, prev_pos, line_length, pixel_size)
448:           when ChunkyPNG::FILTER_AVERAGE; decode_png_str_scanline_average( stream, pos, prev_pos, line_length, pixel_size)
449:           when ChunkyPNG::FILTER_PAETH;   decode_png_str_scanline_paeth(   stream, pos, prev_pos, line_length, pixel_size)
450:           else raise ChunkyPNG::NotSupported, "Unknown filter type: #{stream.getbyte(pos)}!"
451:         end
452:       end

Decodes a scanline in a pixelstream that was encoded using AVERAGE filtering. This will change the pixelstream to have unfiltered values. @params (see decode_png_str_scanline) @return [void]

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 486
486:       def decode_png_str_scanline_average(stream, pos, prev_pos, line_length, pixel_size)
487:         for i in 1..line_length do
488:           a = (i > pixel_size) ? stream.getbyte(pos + i - pixel_size) : 0
489:           b = prev_pos ? stream.getbyte(prev_pos + i) : 0
490:           stream.setbyte(pos + i, (stream.getbyte(pos + i) + ((a + b) >> 1)) & 0xff)
491:         end
492:       end

Decodes a scanline in a pixelstream that was encoded using PAETH filtering. This will change the pixelstream to have unfiltered values. @params (see decode_png_str_scanline) @return [void]

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 498
498:       def decode_png_str_scanline_paeth(stream, pos, prev_pos, line_length, pixel_size)
499:         for i in 1..line_length do
500:           cur_pos = pos + i
501:           a = (i > pixel_size) ? stream.getbyte(cur_pos - pixel_size) : 0
502:           b = prev_pos ? stream.getbyte(prev_pos + i) : 0
503:           c = (prev_pos && i > pixel_size) ? stream.getbyte(prev_pos + i - pixel_size) : 0
504:           p = a + b - c
505:           pa = (p - a).abs
506:           pb = (p - b).abs
507:           pc = (p - c).abs
508:           pr = (pa <= pb) ? (pa <= pc ? a : c) : (pb <= pc ? b : c)
509:           stream.setbyte(cur_pos, (stream.getbyte(cur_pos) + pr) & 0xff)
510:         end
511:       end

Decodes a scanline in a pixelstream that was encoded using SUB filtering. This will change the pixelstream to have unfiltered values. @params (see decode_png_str_scanline) @return [void]

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 465
465:       def decode_png_str_scanline_sub(stream, pos, prev_pos, line_length, pixel_size)
466:         for i in 1..line_length do
467:           stream.setbyte(pos + i, (stream.getbyte(pos + i) + (i > pixel_size ? stream.getbyte(pos + i - pixel_size) : 0)) & 0xff)
468:         end
469:       end

Decodes a scanline that wasn‘t encoded using filtering. This is a no-op. @params (see decode_png_str_scanline) @return [void]

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 457
457:       def decode_png_str_scanline_sub_none(stream, pos, prev_pos, line_length, pixel_size)
458:         # noop - this method shouldn't get called.
459:       end

Decodes a scanline in a pixelstream that was encoded using UP filtering. This will change the pixelstream to have unfiltered values. @params (see decode_png_str_scanline) @return [void]

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 475
475:       def decode_png_str_scanline_up(stream, pos, prev_pos, line_length, pixel_size)
476:         for i in 1..line_length do
477:           up = prev_pos ? stream.getbyte(prev_pos + i) : 0
478:           stream.setbyte(pos + i, (stream.getbyte(pos + i) + up) & 0xff)
479:         end
480:       end

Decodes a canvas from a Adam 7 interlaced PNG encoded pixelstream, using a given width, height and color mode. @param stream (see ChunkyPNG::Canvas::PNGDecoding#decode_png_pixelstream) @param width (see ChunkyPNG::Canvas::PNGDecoding#decode_png_pixelstream) @param height (see ChunkyPNG::Canvas::PNGDecoding#decode_png_pixelstream) @param color_mode (see ChunkyPNG::Canvas::PNGDecoding#decode_png_pixelstream) @param depth (see ChunkyPNG::Canvas::PNGDecoding#decode_png_pixelstream) @return (see ChunkyPNG::Canvas::PNGDecoding#decode_png_pixelstream)

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 135
135:       def decode_png_with_adam7_interlacing(stream, width, height, color_mode, depth)
136:         canvas = new(width, height)
137:         start_pos = 0
138:         for pass in 0...7
139:           sm_width, sm_height = adam7_pass_size(pass, width, height)
140:           sm = decode_png_image_pass(stream, sm_width, sm_height, color_mode, depth, start_pos)
141:           adam7_merge_pass(pass, canvas, sm)
142:           start_pos += ChunkyPNG::Color.pass_bytesize(color_mode, depth, sm_width, sm_height)
143:         end
144:         canvas
145:       end

Decodes a canvas from a non-interlaced PNG encoded pixelstream, using a given width, height and color mode. @param stream (see ChunkyPNG::Canvas::PNGDecoding#decode_png_pixelstream) @param width (see ChunkyPNG::Canvas::PNGDecoding#decode_png_pixelstream) @param height (see ChunkyPNG::Canvas::PNGDecoding#decode_png_pixelstream) @param color_mode (see ChunkyPNG::Canvas::PNGDecoding#decode_png_pixelstream) @param depth (see ChunkyPNG::Canvas::PNGDecoding#decode_png_pixelstream) @return (see ChunkyPNG::Canvas::PNGDecoding#decode_png_pixelstream)

[Source]

     # File lib/chunky_png/canvas/png_decoding.rb, line 123
123:       def decode_png_without_interlacing(stream, width, height, color_mode, depth)
124:         decode_png_image_pass(stream, width, height, color_mode, depth, 0)
125:       end

[Validate]