Class: C64GeoPaintPic

Inherits:
C64GeosFile show all
Defined in:
lib/native_file_types/c64/C64GeoPaintPic.rb

Instance Attribute Summary

Attributes inherited from NativeFileType

#aux_code, #contents, #file_system_image, #file_type, #filename

Instance Method Summary collapse

Methods inherited from C64GeosFile

#contents, #header_filename, #icon_background, #icon_bitmap, #icon_foreground, #icon_format, #icon_height, #icon_tag, #icon_width, #info_block, #load_address, #parent_application, #record_nos, #to_hex_dump, #to_icon, #type_description

Methods inherited from CbmFile

file_system_file_types, #type_description

Methods inherited from NativeFileType

#<=>, #==, all_native_file_types, best_fit, code_for_tests, compatability_score, #data_without_header, file_type_matches?, #full_filename, #header_length, #initialize, is_valid_file_if, #load_address, load_address, matching_score, native_file_types_possible_on_file_system, non_matching_score, #to_hex_dump, #to_info_dump, #type_description

Methods included from SubclassTracking

extended

Constructor Details

This class inherits a constructor from NativeFileType

Instance Method Details

#meta_dataObject



114
115
116
117
118
# File 'lib/native_file_types/c64/C64GeoPaintPic.rb', line 114

def 
	return super unless @contents.kind_of?(Array) && !info_block.nil?
#	@meta_data["geos_font_lengths"]=(lengths.collect{|x| '$%04x' % x}).join(",")	
	super
end

#picture_formatObject



22
23
24
# File 'lib/native_file_types/c64/C64GeoPaintPic.rb', line 22

def picture_format
  :png
end

#picture_heightObject



19
20
21
# File 'lib/native_file_types/c64/C64GeoPaintPic.rb', line 19

def picture_height
	record_nos.max*8*2
end

#picture_widthObject



16
17
18
# File 'lib/native_file_types/c64/C64GeoPaintPic.rb', line 16

def picture_width
	320*2 #geoPain pics are 2 screens wide
end

#to_pictureObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/native_file_types/c64/C64GeoPaintPic.rb', line 84

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

#unpacked_picture_bytesObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/native_file_types/c64/C64GeoPaintPic.rb', line 27

def unpacked_picture_bytes
	bitmap_lines=[]
	colour_map=[]
	(record_nos-[0]).each do |record_no|
#		puts "record #{record_no}"
		record=@contents[record_no]
		line=""
		p=0
		while p<record.length do
			b=record[p]
#			puts "byte %02x code %02x" % [p,b]
			p+=1
			case b
			when (0..0x3F) then
#				puts "copy $#{"%02x" % b} bytes"
				b.times do 
					c=record[p]
					c=0 if c.nil?
					line<<c.chr
					p+=1
				end
			when (0x40..0x7F) then
				pattern=record[p,8]
				rep_count=b % 0x40
#				puts "pattern rep count $#{"%02x" % rep_count}"
				p+=8 
				line<<pattern*rep_count
			when (0x80..0xff) then
				rep_count=b - 0x80
#				puts "copy $#{"%02x" % rep_count} bytes"
				b=record[p]
				b = 0 if b.nil?
				rep_count.times do 
					line<<b.chr
				end
				p+=1
			else
				raise "invalid code byte #{b}"
			end
		end
		
		#if we don't have enough data, pad with 0s
		(line<<"\000"*(1448-line.length)) unless line.length>=1448
		raise "malformed line (length was #{line.length}) at record ##{record_no}" unless line.length>=1448

#		puts "line length was #{line.length}) at record ##{record_no}"

		bitmap_lines[(record_no-1)*2]=line[0,640]
		bitmap_lines[1+(record_no-1)*2]=line[640,640]

		colour_map[(record_no-1)*2]=line[1288,80]
		colour_map[(record_no-1)*2+1]=line[1368,80]

	end
	[bitmap_lines,colour_map]
end