class HexaPDF::ImageLoader::PNG
def alpha_mask_for_indexed_image(offset, decode_parms, trns)
Creates the alpha mask source data for an indexed PNG with alpha values.
def alpha_mask_for_indexed_image(offset, decode_parms, trns) width = decode_parms[:Columns] bpc = decode_parms[:BitsPerComponent] bytes_per_row = (width * bpc + 7) / 8 + 1 flate_decode = @document.config.constantize('filter.map', :FlateDecode) source = flate_decode.decoder(Fiber.new(&image_data_proc(offset))) mask_data = ''.b stream = HexaPDF::Utils::BitStreamReader.new while source.alive? && (data = source.resume) stream.append_data(data) while stream.remaining_bits / 8 >= bytes_per_row stream.read(8) # read filter byte i = 0 while i < width index = stream.read(bpc) mask_data << (trns[index] || 255) i += 1 end stream.read(8 - ((width * bpc) % 8)) if bpc != 8 # read remaining fill bits end end mask_data end