correct RGB irder for png

This commit is contained in:
Andrey Sidorov 2012-02-28 17:52:03 +11:00
parent 16a464fc26
commit 19c3505c40
2 changed files with 77 additions and 21 deletions

View file

@ -784,12 +784,21 @@ var FlateStream = (function() {
data[i++] = v;
data[i++] = pixel[1] || 255;
} else {
if (pixel.length == 4 && pixel[3] != 0)
console.log(pixel);
for (_k = 0, _len3 = pixel.length; _k < _len3; _k++) {
byte = pixel[_k];
data[i++] = byte;
}
//console.log(pixel.length);
//if (pixel.length == 4 && pixel[3] != 0)
//console.log(pixel);
//for (_k = 0, _len3 = pixel.length; _k < _len3; _k++) {
//for (_k = 0; _k < 4; _k++) {
// byte = pixel[_k];
// data[i++] = byte;
//}
var a = (256 - pixel[3])/256.;
var aa = (1.-a)*255.;
data[i++] = parseInt(pixel[2]*a + aa);
data[i++] = parseInt(pixel[1]*a + aa);
data[i++] = parseInt(pixel[0]*a + aa);
data[i++] = pixel[3];
if (!alpha) {
data[i++] = 255;
}

View file

@ -8,9 +8,15 @@ var ButtonPress = x11.eventMask.ButtonPress;
var ButtonRelease = x11.eventMask.ButtonRelease;
var PointerMotion = x11.eventMask.PointerMotion;
var interv = 0;
var total_frames = 0;
var last_frames = 0;
x11.createClient(function(display)
{
var X = display.client;
X.InternAtom(false, 'test', function() {
});
X.require('big-requests', function(BigReq)
{
X.require('render', function(Render) {
@ -24,17 +30,29 @@ x11.createClient(function(display)
var win, picWin, piclogoi, logo;
function showpic(path)
{
console.log(path);
logo = require('./node-png').readPng(path);
//console.log(logo);
/*
var d = logo.data; var l = logo.data.length;
for (var p=0; p < l; p+=4)
{
b = d[p];
d[p] = d[p+2];
d[p+2] = b;
}
*/
win = X.AllocID();
X.CreateWindow(
win, root,
0, 0, logo.width, logo.height,
1, 1, 0,
1, 0, 1, 0,
{
backgroundPixel: white, eventMask: Exposure|KeyPress|ButtonPress|PointerMotion
}
@ -44,30 +62,54 @@ x11.createClient(function(display)
var gc = X.AllocID();
X.CreateGC(gc, win);
var pixmaplogo = X.AllocID();
X.CreatePixmap(pixmaplogo, win, 24, logo.width, logo.height);
X.PolyFillRectangle(pixmaplogo, gc, [0, 0, 1000, 1000]);
X.PutImage(2, pixmaplogo, gc, logo.width, logo.height, 0, 0, 0, 24, logo.data);
//var pixmaplogo = X.AllocID();
//X.CreatePixmap(pixmaplogo, win, 32, logo.width, logo.height);
//X.PolyFillRectangle(pixmaplogo, gc, [0, 0, 1000, 1000]);
//X.PutImage(2, pixmaplogo, gc, logo.width, logo.height, 0, 0, 0, 24, logo.data);
piclogo = X.AllocID();
Render.CreatePicture(piclogo, pixmaplogo, Render.rgb24);
var lastdelta = 0;
picWin = X.AllocID();
Render.CreatePicture(picWin, win, Render.rgb24);
if (interv) clearInterval(interv);
interv = setInterval(function() {
//console.log('sending!');
if (lastdelta > 100)
{
lastdelta -= 10;
} else {
var n = +new Date();
console.log(logo.data.length/(logo.width*logo.height));
console.log("here");
X.PutImage(2, win, gc, logo.width, logo.height, 0, 0, 0, 24, logo.data);
total_frames++;
X.GetAtomName(1, function(name) {
lastdelta = +new Date() - n;
//console.log(lastdelta);
});
}
}, 200);
//piclogo = X.AllocID();
//Render.CreatePicture(piclogo, pixmaplogo, Render.rgb24);
//picWin = X.AllocID();
//Render.CreatePicture(picWin, win, Render.rgb24);
}
var idx = 10000;
//showpic('/Applications/iTunes.app/Contents/Resources/FolderAnimationLinenIPadLandscape.png');
//showpic('./node-logo.png');
showpic('/Applications/iPhoto.app/Contents/Resources/Themes/Assets/Mistletoe/Mistletoe-Outside-200dpi.png');
var files = require('fs').readFileSync('./qqq').toString().split('\n');
var idx = 10070;
showpic('./node-logo.png');
//showpic('./pnggrad8rgb.png');
//var files = require('fs').readFileSync('./qqq').toString().split('\n');
X.on('event', function(ev) {
if (ev.type == 12) // expose
{
Render.Composite(3, piclogo, 0, picWin, 0, 0, 0, 0, 0, 0, logo.width, logo.height);
//X.PutImage(2, win, gc, logo.width, logo.height, 0, 0, 0, 24, logo.data);
//Render.Composite(3, piclogo, 0, picWin, 0, 0, 0, 0, 0, 0, logo.width, logo.height);
}
if (ev.type == 2)
{
@ -96,3 +138,8 @@ X.on('error', function(err) {
});
});
});
//setInterval(function() {
// console.log(total_frames - last_frames);
// last_frames = total_frames;
//}, 1000);