class ChunkyPNG::Chunk::Transparency

A transparency (tRNS) chunk defines the transparency for an image.

Images having a color mode that already includes an alpha channel, this chunk should not be included.

@see www.w3.org/TR/PNG/#11tRNS @see ChunkyPNG::Chunk::Palette @see ChunkyPNG::Palette

Public Instance Methods

grayscale_entry(bit_depth) click to toggle source

Returns the grayscale entry to be replaced by transparent pixels.

This method should only be used for images having color mode ChunkyPNG::COLOR_GRAYSCALE (0).

@return [Integer] The (grayscale) color to replace with fully

transparent pixels.
    # File lib/chunky_png/chunk.rb
254 def grayscale_entry(bit_depth)
255   value = ChunkyPNG::Canvas.send(:"decode_png_resample_#{bit_depth}bit_value", content.unpack("n")[0])
256   ChunkyPNG::Color.grayscale(value)
257 end
palette_alpha_channel() click to toggle source

Returns the alpha channel for the palette of an indexed image.

This method should only be used for images having color mode ChunkyPNG::COLOR_INDEXED (3).

@return [Array<Integer>] Returns an array of alpha channel values

[0-255].
    # File lib/chunky_png/chunk.rb
231 def palette_alpha_channel
232   content.unpack("C*")
233 end
truecolor_entry(bit_depth) click to toggle source

Returns the truecolor entry to be replaced by transparent pixels,

This method should only be used for images having color mode ChunkyPNG::COLOR_TRUECOLOR (2).

@return [Integer] The color to replace with fully transparent pixels.

    # File lib/chunky_png/chunk.rb
241 def truecolor_entry(bit_depth)
242   decode_method_name = :"decode_png_resample_#{bit_depth}bit_value"
243   values = content.unpack("nnn").map { |c| ChunkyPNG::Canvas.send(decode_method_name, c) }
244   ChunkyPNG::Color.rgb(*values)
245 end