Class: TiArtistPattern

Inherits:
Ti99File show all
Defined in:
lib/native_file_types/ti99/TiArtistPattern.rb

Constant Summary collapse

TMS9918_PALLETE =
[
  PNG::Color.new(0,0,0,0xFF), #color=$00 Transparent

  PNG::Color.new(0,0,0,0xFF), #color=$01 black

  PNG::Color.new(38,229,0,0xFF),  #color=$02 medium green

  PNG::Color.new(100,240,49,0xFF),  #color=$03 light green

  PNG::Color.new(93,57,255,0xFF), #color=$04 dark blue

  PNG::Color.new(132,94,255,0xFF),  #color=$05 light blue

  PNG::Color.new(214,104,20,0xFF),  #color=$06 dark red

  PNG::Color.new(64,228,255,0xFF),  #color=$07 cyan

  PNG::Color.new(253,111,15,0xFF),  #color=$08 medium red

  PNG::Color.new(255,245,49,0xFF),  #color=$09 light red

  PNG::Color.new(216,230,0,0xFF), #color=$0A dark yellow

  PNG::Color.new(232,233,14,0xFF),  #color=$0B light yellow

  PNG::Color.new(40,202,0,0xFF),  #color=$0C dark green

  PNG::Color.new(205,86,255,0xFF),  #color=$0D magenta

  PNG::Color.new(208,208,208,0xFF), #color=$0E grey

  PNG::Color.new(255,255,255,0xFF), #color=$0F white

]

Instance Attribute Summary

Attributes inherited from NativeFileType

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

Instance Method Summary collapse

Methods inherited from Ti99File

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

#picture_formatObject



80
81
82
# File 'lib/native_file_types/ti99/TiArtistPattern.rb', line 80

def picture_format
  :png
end

#picture_heightObject



77
78
79
# File 'lib/native_file_types/ti99/TiArtistPattern.rb', line 77

def picture_height
  192
end

#picture_widthObject



74
75
76
# File 'lib/native_file_types/ti99/TiArtistPattern.rb', line 74

def picture_width
  256
end

#to_pictureObject



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
# File 'lib/native_file_types/ti99/TiArtistPattern.rb', line 38

def to_picture
  canvas = PNG::Canvas.new picture_width, picture_height, TMS9918_PALLETE[0]
  colour_attributes_filename=filename.sub(/_P$/,'_C')
  colour_attributes_file=file_system_image.files[colour_attributes_filename]
  if colour_attributes_file.nil? || colour_attributes_file.contents.length<6144 then    
    #colour_attributes=(0x4E.chr)*6144

    colour_attributes=(0x0F.chr)*6144
  else
    colour_attributes=colour_attributes_file.contents
  end

  picture_width.times do |x|
    picture_height.times do |y|  
      byte_offset=y<<5
      byte_offset|=y
      byte_offset&=0xFF07
      bit_offset=x % 0x08
      byte_offset+=x
      byte_offset-=bit_offset      
      bitmask=1<<(7-bit_offset)
      bitmap_byte=contents[byte_offset]
      colour_byte=colour_attributes[byte_offset]
      foreground_colour=TMS9918_PALLETE[colour_byte>>4]
      background_colour=TMS9918_PALLETE[colour_byte%16]
      if ((bitmap_byte & bitmask)==bitmask) then
        canvas[x, y]= foreground_colour
      else
        canvas[x, y]= background_colour
      end
    end
  end
  png = PNG.new canvas
  result=png.raw_bytes
  result
end