PageRenderTime 14ms CodeModel.GetById 10ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/pocjs/Art.js

http://github.com/sbober/pocjs
JavaScript | 53 lines | 39 code | 12 blank | 2 comment | 4 complexity | 803e6f804862b34a951231183787400e MD5 | raw file
 1dojo.provide("pocjs.Art");
 2
 3dojo.declare("pocjs.Art", null, {
 4});
 5
 6pocjs.Art.loadBitmap = function(name, filename) {
 7    var self = this;
 8
 9    var dfd = new dojo.Deferred();
10
11    PNG.load(filename, function(png) {
12        var w = png.width;
13        var h = png.height;
14        var pixels = new Array(w * h << 0);
15        var ppix = png.decodePixels();
16
17        var result = new pocjs.gui.Bitmap(w, h);
18        for (var y = 0; y < h; y++) {
19            for (var x = 0; x < w; x++) {
20                var data = ppix[y][x];
21
22                var input = data[3] << 24
23                          | data[0] << 16
24                          | data[1] << 8
25                          | data[2];
26                var col = (input & 0xf) >> 2;
27                // if (input == (0xffff00ff << 0)) { col = -1; }
28                // silence closure compiler
29                if (input == -65281) { col = -1; }
30                result.pixels[x + y*w] = col;
31                pixels[x + y*w] = input;
32            }
33        }
34
35        self[name] = result;
36        dfd.resolve(name);
37    });
38    return dfd;
39}
40    
41
42pocjs.Art.getCol = function(c) {
43    var r = (c >> 16) & 0xff;
44    var g = (c >> 8) & 0xff;
45    var b = (c) & 0xff;
46
47    r = r * 0x55 / 0xff;
48    g = g * 0x55 / 0xff;
49    b = b * 0x55 / 0xff;
50
51    return r << 16 | g << 8 | b;
52};
53