mirror of
https://github.com/danbulant/pngjs
synced 2026-06-20 23:11:19 +00:00
add ability to write gamma chunks
This commit is contained in:
parent
bf5ae3c54e
commit
ff9d322a36
4 changed files with 14 additions and 5 deletions
|
|
@ -43,12 +43,16 @@ var Packer = module.exports = function(options) {
|
|||
util.inherits(Packer, Stream);
|
||||
|
||||
|
||||
Packer.prototype.pack = function(data, width, height) {
|
||||
Packer.prototype.pack = function(data, width, height, gamma) {
|
||||
|
||||
// Signature
|
||||
this.emit('data', new Buffer(constants.PNG_SIGNATURE));
|
||||
this.emit('data', this._packIHDR(width, height));
|
||||
|
||||
if (gamma) {
|
||||
this.emit('data', this._packGAMA(gamma));
|
||||
}
|
||||
|
||||
// filter pixel data
|
||||
//TODO {}
|
||||
var filter = new Filter(width, height, 4, 8, false, this._options, {});
|
||||
|
|
@ -88,6 +92,12 @@ Packer.prototype._packChunk = function(type, data) {
|
|||
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) {
|
||||
|
||||
var buf = new Buffer(13);
|
||||
|
|
|
|||
|
|
@ -270,7 +270,7 @@ Parser.prototype._handleGAMA = function(length) {
|
|||
Parser.prototype._parseGAMA = function(data) {
|
||||
|
||||
this._crc.write(data);
|
||||
this.gamma(data.readUInt32BE(0) / 100000);
|
||||
this.gamma(data.readUInt32BE(0) / 100000); //TODO constant
|
||||
|
||||
this._handleChunkEnd();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ PNG.sync = PNGSync;
|
|||
PNG.prototype.pack = 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));
|
||||
|
||||
return this;
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ module.exports = function(done) {
|
|||
} else {
|
||||
|
||||
var outpng = new PNG();
|
||||
//PNG.adjustGamma(png);
|
||||
outpng.gamma = png.gamma;
|
||||
outpng.data = png.data;
|
||||
outpng.width = png.width;
|
||||
outpng.height = png.height;
|
||||
|
|
@ -76,7 +76,6 @@ module.exports = function(done) {
|
|||
if (expectedError) {
|
||||
console.log("Async: Error expected, parsed fine ..", file);
|
||||
}
|
||||
//this.adjustGamma();
|
||||
|
||||
this.pack()
|
||||
.pipe(
|
||||
|
|
|
|||
Loading…
Reference in a new issue