Class: ChunkyPNG::Chunk::Transparency
Overview
A transparency (tRNS) chunk defines the transparency for an image.
-
For indexed images, it contains the alpha channel for the colors defined in the Palette (PLTE) chunk.
-
For grayscale images, it contains the grayscale teint that should be considered fully transparent.
-
For truecolor images, it contains the color that should be considered fully transparent.
Images having a color mode that already includes an alpha channel, this chunk should not be included.
Instance Attribute Summary
Attributes inherited from Generic
Attributes inherited from Base
Instance Method Summary (collapse)
-
- (Integer) grayscale_entry(bit_depth)
Returns the grayscale entry to be replaced by transparent pixels.
-
- (Array<Integer>) palette_alpha_channel
Returns the alpha channel for the palette of an indexed image.
-
- (Integer) truecolor_entry(bit_depth)
Returns the truecolor entry to be replaced by transparent pixels,.
Methods inherited from Generic
Methods inherited from Base
#initialize, #write, #write_with_crc
Constructor Details
This class inherits a constructor from ChunkyPNG::Chunk::Generic
Instance Method Details
- (Integer) grayscale_entry(bit_depth)
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).
216 217 218 219 |
# File 'lib/chunky_png/chunk.rb', line 216 def grayscale_entry(bit_depth) value = ChunkyPNG::Canvas.send(:decode_png_resample_#{bit_depth}bit_value", content.unpack('n')[0]) ChunkyPNG::Color.grayscale(value) end |
- (Array<Integer>) palette_alpha_channel
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).
197 198 199 |
# File 'lib/chunky_png/chunk.rb', line 197 def palette_alpha_channel content.unpack('C*') end |
- (Integer) truecolor_entry(bit_depth)
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).
206 207 208 209 |
# File 'lib/chunky_png/chunk.rb', line 206 def truecolor_entry(bit_depth) values = content.unpack('nnn').map { |c| ChunkyPNG::Canvas.send(:decode_png_resample_#{bit_depth}bit_value", c) } ChunkyPNG::Color.rgb(*values) end |