mirror of
https://github.com/danbulant/pngjs
synced 2026-07-07 12:10:59 +00:00
Merge branch 'master' of github.com:lukeapage/node-pngjs2
This commit is contained in:
commit
f84416a523
5 changed files with 15 additions and 6 deletions
|
|
@ -23,12 +23,16 @@ var Packer = module.exports = function(options) {
|
||||||
util.inherits(Packer, Stream);
|
util.inherits(Packer, Stream);
|
||||||
|
|
||||||
|
|
||||||
Packer.prototype.pack = function(data, width, height) {
|
Packer.prototype.pack = function(data, width, height, gamma) {
|
||||||
|
|
||||||
// Signature
|
// Signature
|
||||||
this.emit('data', new Buffer(constants.PNG_SIGNATURE));
|
this.emit('data', new Buffer(constants.PNG_SIGNATURE));
|
||||||
this.emit('data', this._packIHDR(width, height));
|
this.emit('data', this._packIHDR(width, height));
|
||||||
|
|
||||||
|
if (gamma) {
|
||||||
|
this.emit('data', this._packGAMA(gamma));
|
||||||
|
}
|
||||||
|
|
||||||
// filter pixel data
|
// filter pixel data
|
||||||
//TODO {}
|
//TODO {}
|
||||||
var filter = new Filter(width, height, 4, 8, false, this._options, {});
|
var filter = new Filter(width, height, 4, 8, false, this._options, {});
|
||||||
|
|
@ -70,6 +74,12 @@ Packer.prototype._packChunk = function(type, data) {
|
||||||
return buf;
|
return buf;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Packer.prototype._packGAMA = function(gamma) {
|
||||||
|
var buf = new Buffer(4);
|
||||||
|
buf.writeUInt32BE(Math.floor(gamma * 100000), 0); // TODO constant
|
||||||
|
return this._packChunk(constants.TYPE_gAMA, buf);
|
||||||
|
};
|
||||||
|
|
||||||
Packer.prototype._packIHDR = function(width, height) {
|
Packer.prototype._packIHDR = function(width, height) {
|
||||||
|
|
||||||
var buf = new Buffer(13);
|
var buf = new Buffer(13);
|
||||||
|
|
|
||||||
|
|
@ -249,7 +249,7 @@ Parser.prototype._handleGAMA = function(length) {
|
||||||
Parser.prototype._parseGAMA = function(data) {
|
Parser.prototype._parseGAMA = function(data) {
|
||||||
|
|
||||||
this._crc.write(data);
|
this._crc.write(data);
|
||||||
this.gamma(data.readUInt32BE(0) / 100000);
|
this.gamma(data.readUInt32BE(0) / 100000); //TODO constant
|
||||||
|
|
||||||
this._handleChunkEnd();
|
this._handleChunkEnd();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ PNG.prototype.pack = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
process.nextTick(function() {
|
process.nextTick(function() {
|
||||||
this._packer.pack(this.data, this.width, this.height);
|
this._packer.pack(this.data, this.width, this.height, this.gamma);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "pngjs2",
|
"name": "pngjs2",
|
||||||
"version": "0.0.3",
|
"version": "0.0.3",
|
||||||
"description": "Pure JS PNG encoder/decoder",
|
"description": "PNG encoder/decoder in pure JS, supporting any bit size & interlace, async & sync with full test suite.",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"Alexandre Paré",
|
"Alexandre Paré",
|
||||||
"Gaurav Mali",
|
"Gaurav Mali",
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ module.exports = function(done) {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
var outpng = new PNG();
|
var outpng = new PNG();
|
||||||
//PNG.adjustGamma(png);
|
outpng.gamma = png.gamma;
|
||||||
outpng.data = png.data;
|
outpng.data = png.data;
|
||||||
outpng.width = png.width;
|
outpng.width = png.width;
|
||||||
outpng.height = png.height;
|
outpng.height = png.height;
|
||||||
|
|
@ -82,7 +82,6 @@ module.exports = function(done) {
|
||||||
if (expectedError) {
|
if (expectedError) {
|
||||||
console.log("Async: Error expected, parsed fine ..", file);
|
console.log("Async: Error expected, parsed fine ..", file);
|
||||||
}
|
}
|
||||||
//this.adjustGamma();
|
|
||||||
|
|
||||||
this.pack()
|
this.pack()
|
||||||
.pipe(
|
.pipe(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue