# File lib/native_file_types/c64/C64GeoPaintPic.rb, line 79
def to_picture
  require 'PatchedPNG'
  (bitmap_lines,colours)=unpacked_picture_bytes
  canvas = PNG::Canvas.new picture_width,picture_height, C64::COLOR_LTGRAY
  bitmap_lines.length.times do |line|
        line_bytes= bitmap_lines[line]
        next if line_bytes.nil?
#       raise "bad line #{line} in #{filename} (should be VLIR $#{"%02x" % (1+(line/2))})" if line_bytes.nil?

        line_bytes.length.times do |i|
                pattern_byte=line_bytes[i]
                colour_byte=colours[line][i/8]
                foreground_colour=C64::COLOR_MAP[colour_byte/0x10]
                background_colour=C64::COLOR_MAP[colour_byte%0x10]
                y=line*8+(i % 8)
                card_col=(i/8)
                bitmask=0b10000000
                8.times do |bit|
                        x=(card_col*8)+bit                         
                        canvas[x,y]=(((pattern_byte & bitmask)==0) ? background_colour : foreground_colour )
                        bitmask=bitmask/2
                end
        end
        canvas
  end
  png = PNG.new canvas
  result=png.raw_bytes
  result
end