Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

picha

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

picha - npm Package Compare versions

Comparing version 0.4.4 to 0.4.5

.jshintrc

75

index.js

@@ -0,1 +1,2 @@

"use strict";

@@ -16,7 +17,7 @@ var image = require('./lib/image');

});
}
};
var resizeSync = exports.resizeSync = function(img, opt) {
return new Image(picha.resizeSync(img, opt));
}
};

@@ -29,7 +30,7 @@ //--

});
}
};
var colorConvertSync = exports.colorConvertSync = function(img, opt) {
return new Image(picha.colorConvertSync(img, opt));
}
};

@@ -43,20 +44,20 @@ //--

var decodePng = exports.decodePng = function(buf, opt, cb) {
if (typeof opt === 'function') cb = opt, opt = {};
if (typeof opt === 'function') { cb = opt; opt = {}; }
picha.decodePng(buf, opt, function(err, img) {
cb(err, img && new Image(img));
})
}
});
};
var decodePngSync = exports.decodePngSync = function(buf, opt) {
return new Image(picha.decodePngSync(buf, opt || {}));
}
};
var encodePng = exports.encodePng = function(img, opt, cb) {
if (typeof opt === 'function') cb = opt, opt = {};
if (typeof opt === 'function') { cb = opt; opt = {}; }
picha.encodePng(img, opt, cb);
}
};
var encodePngSync = exports.encodePngSync = function(img, opt) {
return picha.encodePngSync(img, opt || {});
}
};
}

@@ -71,20 +72,20 @@

var decodeJpeg = exports.decodeJpeg = function(buf, opt, cb) {
if (typeof opt === 'function') cb = opt, opt = {};
if (typeof opt === 'function') { cb = opt; opt = {}; }
picha.decodeJpeg(buf, opt, function(err, img) {
cb(err, img && new Image(img));
})
}
});
};
var decodeJpegSync = exports.decodeJpegSync = function(buf, opt) {
return new Image(picha.decodeJpegSync(buf, opt || {}));
}
};
var encodeJpeg = exports.encodeJpeg = function(img, opt, cb) {
if (typeof opt === 'function') cb = opt, opt = {};
if (typeof opt === 'function') { cb = opt; opt = {}; }
picha.encodeJpeg(img, opt, cb);
}
};
var encodeJpegSync = exports.encodeJpegSync = function(img, opt) {
return picha.encodeJpegSync(img, opt || {});
}
};
}

@@ -99,20 +100,20 @@

var decodeTiff = exports.decodeTiff = function(buf, opt, cb) {
if (typeof opt === 'function') cb = opt, opt = {};
if (typeof opt === 'function') { cb = opt; opt = {}; }
picha.decodeTiff(buf, opt, function(err, img) {
cb(err, img && new Image(img));
})
}
});
};
var decodeTiffSync = exports.decodeTiffSync = function(buf, opt) {
return new Image(picha.decodeTiffSync(buf, opt || {}));
}
};
var encodeTiff = exports.encodeTiff = function(img, opt, cb) {
if (typeof opt === 'function') cb = opt, opt = {};
if (typeof opt === 'function') { cb = opt; opt = {}; }
picha.encodeTiff(img, opt, cb);
}
};
var encodeTiffSync = exports.encodeTiffSync = function(img, opt) {
return picha.encodeTiffSync(img, opt || {});
}
};
}

@@ -127,20 +128,20 @@

var decodeWebP = exports.decodeWebP = function(buf, opt, cb) {
if (typeof opt === 'function') cb = opt, opt = {};
if (typeof opt === 'function') { cb = opt; opt = {}; }
picha.decodeWebP(buf, opt, function(err, img) {
cb(err, img && new Image(img));
})
}
});
};
var decodeWebPSync = exports.decodeWebPSync = function(buf, opt) {
return new Image(picha.decodeWebPSync(buf, opt || {}));
}
};
var encodeWebP = exports.encodeWebP = function(img, opt, cb) {
if (typeof opt === 'function') cb = opt, opt = {};
if (typeof opt === 'function') { cb = opt; opt = {}; }
picha.encodeWebP(img, opt, cb);
}
};
var encodeWebPSync = exports.encodeWebPSync = function(img, opt) {
return picha.encodeWebPSync(img, opt || {});
}
};
}

@@ -158,6 +159,6 @@

}
}
};
var decode = exports.decode = function(buf, opt, cb) {
if (typeof opt === 'function') cb = opt, opt = {};
if (typeof opt === 'function') { cb = opt; opt = {}; }
tryNext(0);

@@ -172,3 +173,3 @@

}
}
};

@@ -184,3 +185,3 @@ var decodeSync = exports.decodeSync = function(buf, opt) {

}
throw new Error("unsupported image file")
}
throw new Error("unsupported image file");
};

@@ -0,6 +1,5 @@

"use strict";
var buffertools = require('buffertools');
var Image = exports.Image = function(opt) {
if (opt == null) opt = {};
if (!opt) opt = {};
this.data = opt.data;

@@ -12,3 +11,3 @@ this.width = opt.width || 0;

this.stride = opt.stride || ((this.width * psize + 3) & ~3);
if (psize == 0)
if (psize === 0)
throw new Error("invalid pixel format " + this.pixel);

@@ -19,9 +18,9 @@ if (this.stide < this.width * psize)

throw new Error("invalid dimensions");
if (this.stride * this.height != 0 && this.data == null)
if (this.stride * this.height !== 0 && !this.data)
this.data = new Buffer(this.stride * this.height);
if (this.data && this.data.length < this.stride * (this.height - 1) + this.width * psize)
throw new Error("image data too small");
}
};
const pixelSizes = {
var pixelSizes = {
'rgb': 3,

@@ -31,16 +30,27 @@ 'rgba': 4,

'greya': 2,
}
};
Image.pixelSize = function(pixel) {
return pixelSizes[pixel] || 0;
}
};
Image.prototype.pixelSize = function() {
return pixelSizes[this.pixel] || 0;
}
};
Image.prototype.row = function(y) {
return this.data.slice(y * this.stride, y * this.stride + this.width * this.pixelSize());
};
function slowBufferCompare(a, b) {
for (var i = 0; ; i += 1) {
if (i == a.length) return i == b.length ? 0 : -1;
if (i == b.length) return 1;
if (a[i] < b[i]) return -1;
if (a[i] > b[i]) return 1;
}
}
Image.bufferCompare = Buffer.compare || slowBufferCompare;
Image.prototype.equalPixels = function(o) {

@@ -50,6 +60,6 @@ if (this.width !== o.width || this.height != o.height || this.pixel != o.pixel)

for (var y = 0; y < this.height; ++y)
if (buffertools.compare(this.row(y), o.row(y)) != 0)
if (Image.bufferCompare(this.row(y), o.row(y)) !== 0)
return false;
return true;
}
};

@@ -64,3 +74,3 @@ Image.prototype.avgChannelDiff = function(o) {

return s / (this.height * rw);
}
};

@@ -78,3 +88,3 @@ Image.prototype.subView = function(x, y, w, h) {

});
}
};

@@ -86,3 +96,4 @@ Image.prototype.copy = function(targetImage) {

var h = Math.min(this.height, targetImage.height);
for (var y = 0; y < h; ++y) this.data.copy(targetImage.data, y * targetImage.stride, y * this.stride, y * this.stride + rw);
}
for (var y = 0; y < h; ++y)
this.data.copy(targetImage.data, y * targetImage.stride, y * this.stride, y * this.stride + rw);
};
{
"name": "picha",
"version": "0.4.4",
"version": "0.4.5",
"description": "image format codec and simple image processing",

@@ -23,3 +23,3 @@ "main": "index.js",

"dependencies": {
"buffertools": "~2.0.0"
"nan": "^1.5.1"
},

@@ -26,0 +26,0 @@ "devDependencies": {

@@ -0,1 +1,3 @@

/*global describe, before, after, it */
"use strict";

@@ -65,3 +67,3 @@ var fs = require('fs');

}
})
})
});
});

@@ -0,1 +1,3 @@

/*global describe, before, after, it */
"use strict";

@@ -32,5 +34,5 @@ var fs = require('fs');

done();
})
})
})
})
});
});
});
});

@@ -0,1 +1,3 @@

/*global describe, before, after, it */
"use strict";

@@ -20,3 +22,3 @@ var fs = require('fs');

assert(image.subView(0, 0, 30, 30).equalPixels(c));
})
})
});
});

@@ -0,1 +1,3 @@

/*global describe, before, after, it */
"use strict";

@@ -5,3 +7,2 @@ var fs = require('fs');

var assert = require('assert');
var buffertools = require('buffertools');
var picha = require('../index.js');

@@ -43,4 +44,4 @@

assert(syncImage.equalPixels(asyncImage));
})
})
});
});
describe("encode " + name, function() {

@@ -51,11 +52,11 @@ it("should async encode", function(done) {

done(err);
})
});
});
it("should sync encode", function() {
syncJpeg = picha.encodeJpegSync(syncImage, { quality: 100 });
})
});
it("should be the same sync or async", function() {
assert(buffertools.compare(asyncJpeg, syncJpeg) == 0);
})
})
assert(picha.Image.bufferCompare(asyncJpeg, syncJpeg) === 0);
});
});
describe("round trip " + name, function() {

@@ -67,8 +68,8 @@ it("async should nearly match original", function(done) {

});
})
});
it("sync should nearly match original", function() {
image = picha.decodeJpegSync(syncJpeg);
var image = picha.decodeJpegSync(syncJpeg);
assert(image.avgChannelDiff(syncImage) < 8);
})
})
});
});
}

@@ -85,10 +86,10 @@

assert(img.pixel === "rgba");
})
});
it("should jpeg encode rgba", function() {
var jpeg = picha.encodeJpegSync(img, { quality: 100 });
})
});
it("should jpeg encode greya", function() {
var jpeg = picha.encodeJpegSync(picha.colorConvertSync(img, { pixel: 'greya' }), { quality: 100 });
})
})
})
});
});
});

@@ -0,1 +1,3 @@

/*global describe, before, after, it */
"use strict";

@@ -5,3 +7,2 @@ var fs = require('fs');

var assert = require('assert');
var buffertools = require('buffertools');
var picha = require('../index.js');

@@ -42,4 +43,4 @@

assert(syncImage.equalPixels(asyncImage));
})
})
});
});
describe("encode", function() {

@@ -50,11 +51,11 @@ it("should async encode", function(done) {

done(err);
})
});
});
it("should sync encode", function() {
syncPng = picha.encodePngSync(syncImage);
})
});
it("should be the same sync or async", function() {
assert(buffertools.compare(asyncPng, syncPng) == 0);
})
})
assert(picha.Image.bufferCompare(asyncPng, syncPng) === 0);
});
});
describe("round trip", function() {

@@ -66,8 +67,8 @@ it("async match original", function(done) {

});
})
});
it("sync match original", function() {
image = picha.decodePngSync(syncPng);
var image = picha.decodePngSync(syncPng);
assert(image.equalPixels(syncImage));
})
})
})
});
});
});

@@ -0,1 +1,3 @@

/*global describe, before, after, it */
"use strict";

@@ -24,3 +26,3 @@ var fs = require('fs');

});
})
});
it("should sync resize", function() {

@@ -30,3 +32,3 @@ var syncSmall = picha.resizeSync(image, opts);

assert(syncSmall.equalPixels(asyncSmall));
})
})
});
});

@@ -0,1 +1,3 @@

/*global describe, before, after, it */
"use strict";

@@ -5,3 +7,2 @@ var fs = require('fs');

var assert = require('assert');
var buffertools = require('buffertools');
var picha = require('../index.js');

@@ -42,4 +43,4 @@

assert(syncImage.equalPixels(asyncImage));
})
})
});
});
describe("encode", function() {

@@ -50,12 +51,12 @@ it("should async encode", function(done) {

done(err);
})
});
});
it("should sync encode", function() {
syncTiff = picha.encodeTiffSync(syncImage);
})
});
// It seems lib tiff will write some uninitialized memory into the output file!
// it("should be the same sync or async", function() {
// assert(buffertools.compare(asyncTiff, syncTiff) == 0);
// assert(picha.Image.bufferCompare(asyncTiff, syncTiff) == 0);
// })
})
});
describe("round trip", function() {

@@ -67,8 +68,8 @@ it("async match original", function(done) {

});
})
});
it("sync match original", function() {
var image = picha.decodeTiffSync(syncTiff);
assert(image.equalPixels(syncImage));
})
})
});
});
describe("none compression round trips", function() {

@@ -78,4 +79,4 @@ it("sync match original", function() {

assert(image.equalPixels(asyncImage));
})
})
});
});
describe("deflate compression round trips", function() {

@@ -85,4 +86,4 @@ it("sync match original", function() {

assert(image.equalPixels(asyncImage));
})
})
})
});
});
});

@@ -0,1 +1,3 @@

/*global describe, before, after, it */
"use strict";

@@ -5,3 +7,2 @@ var fs = require('fs');

var assert = require('assert');
var buffertools = require('buffertools');
var picha = require('../index.js');

@@ -42,4 +43,4 @@

assert(syncImage.equalPixels(asyncImage));
})
})
});
});
describe("lossless encode", function() {

@@ -50,10 +51,10 @@ it("should async encode", function(done) {

done(err);
})
});
});
it("should sync encode", function() {
syncWebP = picha.encodeWebPSync(syncImage, { preset: 'lossless' });
})
});
it("should be the same sync or async", function() {
assert(buffertools.compare(asyncWebP, syncWebP) == 0);
})
assert(picha.Image.bufferCompare(asyncWebP, syncWebP) === 0);
});
it("async should match original", function(done) {

@@ -64,8 +65,8 @@ picha.decodeWebP(asyncWebP, function(err, image) {

});
})
});
it("sync should match original", function() {
image = picha.decodeWebPSync(syncWebP);
var image = picha.decodeWebPSync(syncWebP);
assert(image.equalPixels(syncImage));
})
})
});
});
describe("lossey encode", function() {

@@ -76,10 +77,10 @@ it("should async encode", function(done) {

done(err);
})
});
});
it("should sync encode", function() {
syncWebP = picha.encodeWebPSync(syncImage, { quality: 70 });
})
});
it("should be the same sync or async", function() {
assert(buffertools.compare(asyncWebP, syncWebP) == 0);
})
assert(picha.Image.bufferCompare(asyncWebP, syncWebP) === 0);
});
it("async should nearly match original", function(done) {

@@ -90,8 +91,8 @@ picha.decodeWebP(asyncWebP, function(err, image) {

});
})
});
it("sync should nearly match original", function() {
image = picha.decodeWebPSync(syncWebP);
var image = picha.decodeWebPSync(syncWebP);
assert(image.avgChannelDiff(syncImage) < 8);
})
})
})
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc