def HGR.buffer_to_png(buffer,pallete_mode=:amber)
canvas = PNG::Canvas.new HGR_COLS*SCALE, HGR_ROWS*SCALE, PNG::Color::Black
0.upto(HGR_ROWS-1) do |y|
last_bit_set=false
0.upto(39) do |x_byte|
offset=@@scanline_offsets[y]+x_byte
current_byte=buffer[offset]
current_byte=0 if current_byte.nil?
0.upto(6) do |x_bit|
x=x_byte*7+x_bit
bit_set=((current_byte & (2**x_bit))>0)
if (bit_set) then
if pallete_mode==:colour then
if (last_bit_set) then
set_pixel(canvas,x-1,y,HGR_WHITE)
set_pixel(canvas,x,y,HGR_WHITE)
else
if current_byte>=0x80 then
pallete=[HGR_BLUE,HGR_ORANGE]
else
pallete=[HGR_VIOLET,HGR_GREEN]
end
this_pixel_colour=pallete[x%2]
set_pixel(canvas,x,y,this_pixel_colour)
set_pixel(canvas,x+1,y,this_pixel_colour)
end
else
this_pixel_colour=PALLETE[pallete_mode]
this_pixel_colour=PALLETE.values[0] if this_pixel_colour.nil?
set_pixel(canvas,x,y,this_pixel_colour)
end
end
last_bit_set=bit_set
end
end
end
png = PNG.new canvas
png.raw_bytes
end