Class: NEXXT::Parser::PngExporter
- Inherits:
-
Object
- Object
- NEXXT::Parser::PngExporter
- Defined in:
- lib/nexxt/parser/png_exporter.rb
Constant Summary collapse
- NES_PALETTE =
2C02 NES RGB palette (FCEUX-style), one RGB triple per palette index (0x00-0x3F).
[ [0x7C, 0x7C, 0x7C], [0x00, 0x00, 0xFC], [0x00, 0x00, 0xBC], [0x44, 0x28, 0xBC], [0x94, 0x00, 0x84], [0xA8, 0x00, 0x20], [0xA8, 0x10, 0x00], [0x88, 0x14, 0x00], [0x50, 0x30, 0x00], [0x00, 0x78, 0x00], [0x00, 0x68, 0x00], [0x00, 0x58, 0x00], [0x00, 0x40, 0x58], [0x00, 0x00, 0x00], [0x00, 0x00, 0x00], [0x00, 0x00, 0x00], [0xBC, 0xBC, 0xBC], [0x00, 0x78, 0xF8], [0x00, 0x58, 0xF8], [0x68, 0x44, 0xFC], [0xD8, 0x00, 0xCC], [0xE4, 0x00, 0x58], [0xF8, 0x38, 0x00], [0xE4, 0x5C, 0x10], [0xAC, 0x7C, 0x00], [0x00, 0xB8, 0x00], [0x00, 0xA8, 0x00], [0x00, 0xA8, 0x44], [0x00, 0x88, 0x88], [0x00, 0x00, 0x00], [0x00, 0x00, 0x00], [0x00, 0x00, 0x00], [0xF8, 0xF8, 0xF8], [0x3C, 0xBC, 0xFC], [0x68, 0x88, 0xFC], [0x98, 0x78, 0xF8], [0xF8, 0x78, 0xF8], [0xF8, 0x58, 0x98], [0xF8, 0x78, 0x58], [0xFC, 0xA0, 0x44], [0xF8, 0xB8, 0x00], [0xB8, 0xF8, 0x18], [0x58, 0xD8, 0x54], [0x58, 0xF8, 0x98], [0x00, 0xE8, 0xD8], [0x78, 0x78, 0x78], [0x00, 0x00, 0x00], [0x00, 0x00, 0x00], [0xFC, 0xFC, 0xFC], [0xA4, 0xE4, 0xFC], [0xB8, 0xB8, 0xF8], [0xD8, 0xB8, 0xF8], [0xF8, 0xB8, 0xF8], [0xF8, 0xA4, 0xC0], [0xF0, 0xD0, 0xB0], [0xFC, 0xE0, 0xA8], [0xF8, 0xD8, 0x78], [0xD8, 0xF8, 0x78], [0xB8, 0xF8, 0xB8], [0xB8, 0xF8, 0xD8], [0x00, 0xFC, 0xFC], [0xF8, 0xD8, 0xF8], [0x00, 0x00, 0x00], [0x00, 0x00, 0x00] ].freeze
- TILE_SIZE =
8- BYTES_PER_TILE =
16- CHR_BANK_SIZE =
4096- PALETTE_BANK_SIZE =
16- PNG_MAGIC =
"\x89PNG\r\n\x1A\n".b.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(session, chr_bank: nil, palette_bank: nil, nes_palette: NES_PALETTE) ⇒ PngExporter
constructor
A new instance of PngExporter.
- #pixels ⇒ Object
- #to_png ⇒ Object
- #write(path) ⇒ Object
Constructor Details
#initialize(session, chr_bank: nil, palette_bank: nil, nes_palette: NES_PALETTE) ⇒ PngExporter
Returns a new instance of PngExporter.
39 40 41 42 43 44 45 46 |
# File 'lib/nexxt/parser/png_exporter.rb', line 39 def initialize(session, chr_bank: nil, palette_bank: nil, nes_palette: NES_PALETTE) @session = session @map = session.map or raise Error, 'Session has no nametable data' @chr_bank = chr_bank || session.flat_table['VarBankActive'].to_i @palette_bank = palette_bank || session.flat_table['VarPalBank'].to_i @nes_palette = nes_palette @palette = session.palette end |
Class Method Details
.export(session, path) ⇒ Object
35 36 37 |
# File 'lib/nexxt/parser/png_exporter.rb', line 35 def self.export(session, path, **) new(session, **).write(path) end |
Instance Method Details
#pixels ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/nexxt/parser/png_exporter.rb', line 56 def pixels height_px = @map.height * TILE_SIZE width_px = @map.width * TILE_SIZE matrix = Array.new(height_px) { Array.new(width_px) } (0...@map.height).each do |tile_row| (0...@map.width).each { |tile_col| render_tile(matrix, tile_row, tile_col) } end matrix end |
#to_png ⇒ Object
52 53 54 |
# File 'lib/nexxt/parser/png_exporter.rb', line 52 def to_png encode_png(pixels) end |
#write(path) ⇒ Object
48 49 50 |
# File 'lib/nexxt/parser/png_exporter.rb', line 48 def write(path) File.binwrite(path, to_png) end |