some cleanup before heading into main render code

This commit is contained in:
Howland Owl 2013-10-07 16:14:30 +03:00
parent a6c928396e
commit f01c5717f4
2 changed files with 1311 additions and 1301 deletions

View file

@ -10,7 +10,7 @@ class @ImageTextModeSAUCE
parse: ( content ) -> parse: ( content ) ->
sauceMarker = content.length - 128; sauceMarker = content.length - 128;
return false if content.substr( sauceMarker, 5 ) is not 'SAUCE' return false if content.substr( sauceMarker, 5 ) isnt 'SAUCE'
@id = 'SAUCE' @id = 'SAUCE'
@version = content.substr( sauceMarker + 5, 2 ) @version = content.substr( sauceMarker + 5, 2 )
@title = content.substr( sauceMarker + 7, 35 ) @title = content.substr( sauceMarker + 7, 35 )
@ -66,7 +66,8 @@ class @ImageTextModePalette
class @ImageTextModePaletteVGA extends @ImageTextModePalette class @ImageTextModePaletteVGA extends @ImageTextModePalette
constructor: ( options ) -> constructor: ( options ) ->
super @colors = [ super
@colors = [
[ 0x00, 0x00, 0x00 ], [ 0x00, 0x00, 0x00 ],
[ 0x00, 0x00, 0xaa ], [ 0x00, 0x00, 0xaa ],
[ 0x00, 0xaa, 0x00 ], [ 0x00, 0xaa, 0x00 ],
@ -918,12 +919,12 @@ class @ImageTextMode
constructor: ( options ) -> constructor: ( options ) ->
@screen = [] @screen = []
@palette = new ImageTextModePaletteVGA @palette = new ImageTextModePaletteVGA()
@font = new ImageTextModeFont8x16 @font = new ImageTextModeFont8x16()
this[k] = v for own k, v of options @[k] = v for own k, v of options
parseUrl: ( url ) -> parseUrl: ( url ) ->
req = new XMLHttpRequest req = new XMLHttpRequest()
req.open 'GET', url, false req.open 'GET', url, false
req.overrideMimeType 'text/plain; charset=x-user-defined' req.overrideMimeType 'text/plain; charset=x-user-defined'
req.send null req.send null
@ -945,6 +946,8 @@ class @ImageTextMode
getByteAt: ( data, offset ) -> getByteAt: ( data, offset ) ->
return data.charCodeAt( offset ) & 0xFF return data.charCodeAt( offset ) & 0xFF
# could we replace this with math.max ?
getWidth: -> getWidth: ->
max = 0 max = 0
for y in [ 0 .. @screen.length - 1 ] for y in [ 0 .. @screen.length - 1 ]
@ -965,7 +968,7 @@ class @ImageTextMode
b = b << 2 | b >> 4 b = b << 2 | b >> 4
colors.push [ r, g, b ] colors.push [ r, g, b ]
@palette = new ImageTextModePalette( { colors: colors } ) @palette = new ImageTextModePalette( colors: colors )
parseFontData: ( data, height = 16 ) -> parseFontData: ( data, height = 16 ) ->
chars = [] chars = []
@ -976,6 +979,8 @@ class @ImageTextMode
chars.push chr chars.push chr
@font = new ImageTextModeFont( { chars: chars, height: height } ) @font = new ImageTextModeFont( { chars: chars, height: height } )
# the majority of time is spent in this routine
renderCanvas: ( canvasElem ) -> renderCanvas: ( canvasElem ) ->
w = @getWidth() * @font.width w = @getWidth() * @font.width
h = @getHeight() * @font.height h = @getHeight() * @font.height
@ -985,9 +990,9 @@ class @ImageTextMode
canvas.setAttribute 'height', h canvas.setAttribute 'height', h
ctx = canvas.getContext '2d' ctx = canvas.getContext '2d'
for cy in [ 0 .. @screen.length - 1 ] for cy in [ 0 ... @screen.length ]
continue if !@screen[ cy ]? continue if !@screen[ cy ]?
for cx in [ 0 .. @screen[ cy ].length - 1 ] for cx in [ 0 ... @screen[ cy ].length ]
pixel = @screen[ cy ][ cx ] pixel = @screen[ cy ][ cx ]
continue if !pixel? continue if !pixel?
if pixel.attr? if pixel.attr?
@ -1005,9 +1010,9 @@ class @ImageTextMode
ctx.fillStyle = @palette.toRgbaString( @palette.colors[ fg ] ) ctx.fillStyle = @palette.toRgbaString( @palette.colors[ fg ] )
chr = @font.chars[ pixel.ch.charCodeAt( 0 ) & 0xff ] chr = @font.chars[ pixel.ch.charCodeAt( 0 ) & 0xff ]
for i in [ 0 .. @font.height - 1 ] for i in [ 0 ... @font.height ]
line = chr[ i ] line = chr[ i ]
for j in [ 0 .. @font.width - 1 ] for j in [ 0 ... @font.width ]
if line & ( 1 << @font.width - 1 - j ) if line & ( 1 << @font.width - 1 - j )
ctx.fillRect px + j, py + i, 1, 1 ctx.fillRect px + j, py + i, 1, 1
@ -1056,7 +1061,7 @@ class @ImageTextModeXBin extends @ImageTextMode
parse: ( content ) -> parse: ( content ) ->
@screen = [] @screen = []
headerData = content.substr( 0, 11 ) headerData = content.substr( 0, 11 )
if headerData.length is not 11 || !headerData.match( '^XBIN\x1a' ) if headerData.length isnt 11 || !headerData.match( '^XBIN\x1a' )
throw new Error( 'File is not an XBin' ) throw new Error( 'File is not an XBin' )
@header.width = @unpackShort( headerData.substr( 5, 2 ) ) @header.width = @unpackShort( headerData.substr( 5, 2 ) )
@ -1353,7 +1358,7 @@ class @ImageTextModeIDF extends @ImageTextMode
parse: ( content ) -> parse: ( content ) ->
headerData = content.substr( 0, 12 ) headerData = content.substr( 0, 12 )
if headerData.length is not 12 || !headerData.match( '^\x041.4' ) if headerData.length isnt 12 || !headerData.match( '^\x041.4' )
throw new Error( 'File is not an IDF' ) throw new Error( 'File is not an IDF' )
@header.x0 = @unpackShort( headerData.substr( 4, 2 ) ) @header.x0 = @unpackShort( headerData.substr( 4, 2 ) )
@ -1558,7 +1563,7 @@ class @ImageTextModePCBoard extends @ImageTextMode
else if ch + content[ 0..2 ].join( '' ) is 'POS:' else if ch + content[ 0..2 ].join( '' ) is 'POS:'
content.shift() for [ 1 .. 3 ] content.shift() for [ 1 .. 3 ]
@x = content.shift() @x = content.shift()
@x += content.shift() if content[ 0 ] is not '@' @x += content.shift() if content[ 0 ] isnt '@'
@x-- @x--
content.shift() content.shift()
@ -1648,3 +1653,5 @@ class @ImageTextModeAVATAR extends @ImageTextMode
if ++@x >= @linewrap if ++@x >= @linewrap
@x = 0 @x = 0
@y++ @y++

View file

@ -1,13 +1,14 @@
// Generated by CoffeeScript 1.6.3 // Generated by CoffeeScript 1.6.3
var __hasProp = {}.hasOwnProperty, (function() {
var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
this.ImageTextModeSAUCE = (function() { this.ImageTextModeSAUCE = (function() {
function ImageTextModeSAUCE() {} function ImageTextModeSAUCE() {}
ImageTextModeSAUCE.prototype.parseUrl = function(url) { ImageTextModeSAUCE.prototype.parseUrl = function(url) {
var content, req; var content, req;
req = new XMLHttpRequest; req = new XMLHttpRequest();
req.open('GET', url, false); req.open('GET', url, false);
req.overrideMimeType('text/plain; charset=x-user-defined'); req.overrideMimeType('text/plain; charset=x-user-defined');
req.send(null); req.send(null);
@ -18,7 +19,7 @@ this.ImageTextModeSAUCE = (function() {
ImageTextModeSAUCE.prototype.parse = function(content) { ImageTextModeSAUCE.prototype.parse = function(content) {
var commentMarker, i, sauceMarker; var commentMarker, i, sauceMarker;
sauceMarker = content.length - 128; sauceMarker = content.length - 128;
if (content.substr(sauceMarker, 5) === !'SAUCE') { if (content.substr(sauceMarker, 5) !== 'SAUCE') {
return false; return false;
} }
this.id = 'SAUCE'; this.id = 'SAUCE';
@ -74,9 +75,9 @@ this.ImageTextModeSAUCE = (function() {
return ImageTextModeSAUCE; return ImageTextModeSAUCE;
})(); })();
this.ImageTextModePalette = (function() { this.ImageTextModePalette = (function() {
function ImageTextModePalette(options) { function ImageTextModePalette(options) {
var k, v; var k, v;
this.colors = []; this.colors = [];
@ -93,9 +94,9 @@ this.ImageTextModePalette = (function() {
return ImageTextModePalette; return ImageTextModePalette;
})(); })();
this.ImageTextModePaletteVGA = (function(_super) { this.ImageTextModePaletteVGA = (function(_super) {
__extends(ImageTextModePaletteVGA, _super); __extends(ImageTextModePaletteVGA, _super);
function ImageTextModePaletteVGA(options) { function ImageTextModePaletteVGA(options) {
@ -111,9 +112,9 @@ this.ImageTextModePaletteVGA = (function(_super) {
return ImageTextModePaletteVGA; return ImageTextModePaletteVGA;
})(this.ImageTextModePalette); })(this.ImageTextModePalette);
this.ImageTextModePaletteANSI = (function(_super) { this.ImageTextModePaletteANSI = (function(_super) {
__extends(ImageTextModePaletteANSI, _super); __extends(ImageTextModePaletteANSI, _super);
function ImageTextModePaletteANSI(options) { function ImageTextModePaletteANSI(options) {
@ -129,9 +130,9 @@ this.ImageTextModePaletteANSI = (function(_super) {
return ImageTextModePaletteANSI; return ImageTextModePaletteANSI;
})(this.ImageTextModePalette); })(this.ImageTextModePalette);
this.ImageTextModeFont = (function() { this.ImageTextModeFont = (function() {
function ImageTextModeFont(options) { function ImageTextModeFont(options) {
var k, v; var k, v;
this.chars = []; this.chars = [];
@ -145,9 +146,9 @@ this.ImageTextModeFont = (function() {
return ImageTextModeFont; return ImageTextModeFont;
})(); })();
this.ImageTextModeFont8x16 = (function(_super) { this.ImageTextModeFont8x16 = (function(_super) {
__extends(ImageTextModeFont8x16, _super); __extends(ImageTextModeFont8x16, _super);
function ImageTextModeFont8x16(options) { function ImageTextModeFont8x16(options) {
@ -164,9 +165,9 @@ this.ImageTextModeFont8x16 = (function(_super) {
return ImageTextModeFont8x16; return ImageTextModeFont8x16;
})(this.ImageTextModeFont); })(this.ImageTextModeFont);
this.ImageTextModeFont8x8 = (function(_super) { this.ImageTextModeFont8x8 = (function(_super) {
__extends(ImageTextModeFont8x8, _super); __extends(ImageTextModeFont8x8, _super);
function ImageTextModeFont8x8(options) { function ImageTextModeFont8x8(options) {
@ -183,9 +184,9 @@ this.ImageTextModeFont8x8 = (function(_super) {
return ImageTextModeFont8x8; return ImageTextModeFont8x8;
})(this.ImageTextModeFont); })(this.ImageTextModeFont);
this.ImageTextModeFontAmiga = (function(_super) { this.ImageTextModeFontAmiga = (function(_super) {
__extends(ImageTextModeFontAmiga, _super); __extends(ImageTextModeFontAmiga, _super);
function ImageTextModeFontAmiga(options) { function ImageTextModeFontAmiga(options) {
@ -202,16 +203,16 @@ this.ImageTextModeFontAmiga = (function(_super) {
return ImageTextModeFontAmiga; return ImageTextModeFontAmiga;
})(this.ImageTextModeFont); })(this.ImageTextModeFont);
this.ImageTextMode = (function() { this.ImageTextMode = (function() {
ImageTextMode.VERSION = '0.01'; ImageTextMode.VERSION = '0.01';
function ImageTextMode(options) { function ImageTextMode(options) {
var k, v; var k, v;
this.screen = []; this.screen = [];
this.palette = new ImageTextModePaletteVGA; this.palette = new ImageTextModePaletteVGA();
this.font = new ImageTextModeFont8x16; this.font = new ImageTextModeFont8x16();
for (k in options) { for (k in options) {
if (!__hasProp.call(options, k)) continue; if (!__hasProp.call(options, k)) continue;
v = options[k]; v = options[k];
@ -221,7 +222,7 @@ this.ImageTextMode = (function() {
ImageTextMode.prototype.parseUrl = function(url) { ImageTextMode.prototype.parseUrl = function(url) {
var content, req; var content, req;
req = new XMLHttpRequest; req = new XMLHttpRequest();
req.open('GET', url, false); req.open('GET', url, false);
req.overrideMimeType('text/plain; charset=x-user-defined'); req.overrideMimeType('text/plain; charset=x-user-defined');
req.send(null); req.send(null);
@ -310,11 +311,11 @@ this.ImageTextMode = (function() {
canvas.setAttribute('width', w); canvas.setAttribute('width', w);
canvas.setAttribute('height', h); canvas.setAttribute('height', h);
ctx = canvas.getContext('2d'); ctx = canvas.getContext('2d');
for (cy = _i = 0, _ref = this.screen.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; cy = 0 <= _ref ? ++_i : --_i) { for (cy = _i = 0, _ref = this.screen.length; 0 <= _ref ? _i < _ref : _i > _ref; cy = 0 <= _ref ? ++_i : --_i) {
if (this.screen[cy] == null) { if (this.screen[cy] == null) {
continue; continue;
} }
for (cx = _j = 0, _ref1 = this.screen[cy].length - 1; 0 <= _ref1 ? _j <= _ref1 : _j >= _ref1; cx = 0 <= _ref1 ? ++_j : --_j) { for (cx = _j = 0, _ref1 = this.screen[cy].length; 0 <= _ref1 ? _j < _ref1 : _j > _ref1; cx = 0 <= _ref1 ? ++_j : --_j) {
pixel = this.screen[cy][cx]; pixel = this.screen[cy][cx];
if (pixel == null) { if (pixel == null) {
continue; continue;
@ -332,9 +333,9 @@ this.ImageTextMode = (function() {
ctx.fillRect(px, py, this.font.width, this.font.height); ctx.fillRect(px, py, this.font.width, this.font.height);
ctx.fillStyle = this.palette.toRgbaString(this.palette.colors[fg]); ctx.fillStyle = this.palette.toRgbaString(this.palette.colors[fg]);
chr = this.font.chars[pixel.ch.charCodeAt(0) & 0xff]; chr = this.font.chars[pixel.ch.charCodeAt(0) & 0xff];
for (i = _k = 0, _ref2 = this.font.height - 1; 0 <= _ref2 ? _k <= _ref2 : _k >= _ref2; i = 0 <= _ref2 ? ++_k : --_k) { for (i = _k = 0, _ref2 = this.font.height; 0 <= _ref2 ? _k < _ref2 : _k > _ref2; i = 0 <= _ref2 ? ++_k : --_k) {
line = chr[i]; line = chr[i];
for (j = _l = 0, _ref3 = this.font.width - 1; 0 <= _ref3 ? _l <= _ref3 : _l >= _ref3; j = 0 <= _ref3 ? ++_l : --_l) { for (j = _l = 0, _ref3 = this.font.width; 0 <= _ref3 ? _l < _ref3 : _l > _ref3; j = 0 <= _ref3 ? ++_l : --_l) {
if (line & (1 << this.font.width - 1 - j)) { if (line & (1 << this.font.width - 1 - j)) {
ctx.fillRect(px + j, py + i, 1, 1); ctx.fillRect(px + j, py + i, 1, 1);
} }
@ -363,9 +364,9 @@ this.ImageTextMode = (function() {
return ImageTextMode; return ImageTextMode;
})(); })();
this.ImageTextModeXBin = (function(_super) { this.ImageTextModeXBin = (function(_super) {
var ATTRIBUTE_COMPRESSION, CHARACTER_COMPRESSION, COMPRESSED, COMPRESSION_COUNTER, COMPRESSION_TYPE, FIVETWELVE_CHARS, FONT, FULL_COMPRESSION, NON_BLINK, NO_COMPRESSION, PALETTE; var ATTRIBUTE_COMPRESSION, CHARACTER_COMPRESSION, COMPRESSED, COMPRESSION_COUNTER, COMPRESSION_TYPE, FIVETWELVE_CHARS, FONT, FULL_COMPRESSION, NON_BLINK, NO_COMPRESSION, PALETTE;
__extends(ImageTextModeXBin, _super); __extends(ImageTextModeXBin, _super);
@ -412,7 +413,7 @@ this.ImageTextModeXBin = (function(_super) {
var fontlength, headerData, offset; var fontlength, headerData, offset;
this.screen = []; this.screen = [];
headerData = content.substr(0, 11); headerData = content.substr(0, 11);
if (headerData.length === !11 || !headerData.match('^XBIN\x1a')) { if (headerData.length !== 11 || !headerData.match('^XBIN\x1a')) {
throw new Error('File is not an XBin'); throw new Error('File is not an XBin');
} }
this.header.width = this.unpackShort(headerData.substr(5, 2)); this.header.width = this.unpackShort(headerData.substr(5, 2));
@ -557,9 +558,9 @@ this.ImageTextModeXBin = (function(_super) {
return ImageTextModeXBin; return ImageTextModeXBin;
})(this.ImageTextMode); })(this.ImageTextMode);
this.ImageTextModeANSI = (function(_super) { this.ImageTextModeANSI = (function(_super) {
var ANSI_BG, ANSI_BG_INTENSE, ANSI_CSI, ANSI_CUR_DOWN, ANSI_ESC, ANSI_FG, ANSI_FG_INTENSE, ANSI_RESET, ANSI_RETURN, ANSI_SEP, ANSI_TEXT_PROP; var ANSI_BG, ANSI_BG_INTENSE, ANSI_CSI, ANSI_CUR_DOWN, ANSI_ESC, ANSI_FG, ANSI_FG_INTENSE, ANSI_RESET, ANSI_RETURN, ANSI_SEP, ANSI_TEXT_PROP;
__extends(ImageTextModeANSI, _super); __extends(ImageTextModeANSI, _super);
@ -841,9 +842,9 @@ this.ImageTextModeANSI = (function(_super) {
return ImageTextModeANSI; return ImageTextModeANSI;
})(this.ImageTextMode); })(this.ImageTextMode);
this.ImageTextModeBin = (function(_super) { this.ImageTextModeBin = (function(_super) {
__extends(ImageTextModeBin, _super); __extends(ImageTextModeBin, _super);
function ImageTextModeBin(options) { function ImageTextModeBin(options) {
@ -886,9 +887,9 @@ this.ImageTextModeBin = (function(_super) {
return ImageTextModeBin; return ImageTextModeBin;
})(this.ImageTextMode); })(this.ImageTextMode);
this.ImageTextModeIDF = (function(_super) { this.ImageTextModeIDF = (function(_super) {
__extends(ImageTextModeIDF, _super); __extends(ImageTextModeIDF, _super);
function ImageTextModeIDF(options) { function ImageTextModeIDF(options) {
@ -910,7 +911,7 @@ this.ImageTextModeIDF = (function(_super) {
ImageTextModeIDF.prototype.parse = function(content) { ImageTextModeIDF.prototype.parse = function(content) {
var attr, buffer, ch, eodata, headerData, i, info, len, offset, x, y, _i; var attr, buffer, ch, eodata, headerData, i, info, len, offset, x, y, _i;
headerData = content.substr(0, 12); headerData = content.substr(0, 12);
if (headerData.length === !12 || !headerData.match('^\x041.4')) { if (headerData.length !== 12 || !headerData.match('^\x041.4')) {
throw new Error('File is not an IDF'); throw new Error('File is not an IDF');
} }
this.header.x0 = this.unpackShort(headerData.substr(4, 2)); this.header.x0 = this.unpackShort(headerData.substr(4, 2));
@ -960,9 +961,9 @@ this.ImageTextModeIDF = (function(_super) {
return ImageTextModeIDF; return ImageTextModeIDF;
})(this.ImageTextMode); })(this.ImageTextMode);
this.ImageTextModeADF = (function(_super) { this.ImageTextModeADF = (function(_super) {
var COLOR_INDEX; var COLOR_INDEX;
__extends(ImageTextModeADF, _super); __extends(ImageTextModeADF, _super);
@ -1033,9 +1034,9 @@ this.ImageTextModeADF = (function(_super) {
return ImageTextModeADF; return ImageTextModeADF;
})(this.ImageTextMode); })(this.ImageTextMode);
this.ImageTextModeTundra = (function(_super) { this.ImageTextModeTundra = (function(_super) {
__extends(ImageTextModeTundra, _super); __extends(ImageTextModeTundra, _super);
function ImageTextModeTundra(options) { function ImageTextModeTundra(options) {
@ -1116,9 +1117,9 @@ this.ImageTextModeTundra = (function(_super) {
return ImageTextModeTundra; return ImageTextModeTundra;
})(this.ImageTextMode); })(this.ImageTextMode);
this.ImageTextModePCBoard = (function(_super) { this.ImageTextModePCBoard = (function(_super) {
__extends(ImageTextModePCBoard, _super); __extends(ImageTextModePCBoard, _super);
function ImageTextModePCBoard(options) { function ImageTextModePCBoard(options) {
@ -1194,7 +1195,7 @@ this.ImageTextModePCBoard = (function(_super) {
content.shift(); content.shift();
} }
this.x = content.shift(); this.x = content.shift();
if (content[0] === !'@') { if (content[0] !== '@') {
this.x += content.shift(); this.x += content.shift();
} }
this.x--; this.x--;
@ -1229,9 +1230,9 @@ this.ImageTextModePCBoard = (function(_super) {
return ImageTextModePCBoard; return ImageTextModePCBoard;
})(this.ImageTextMode); })(this.ImageTextMode);
this.ImageTextModeAVATAR = (function(_super) { this.ImageTextModeAVATAR = (function(_super) {
__extends(ImageTextModeAVATAR, _super); __extends(ImageTextModeAVATAR, _super);
function ImageTextModeAVATAR(options) { function ImageTextModeAVATAR(options) {
@ -1366,4 +1367,6 @@ this.ImageTextModeAVATAR = (function(_super) {
return ImageTextModeAVATAR; return ImageTextModeAVATAR;
})(this.ImageTextMode); })(this.ImageTextMode);
}).call(this);