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

gif-encoder

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gif-encoder - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

test/expected-files/moving-dot.gif

2

CHANGELOG.md
# gif-encoder changelog
0.6.0 - Repaired transparency support via @scinos in #7
0.5.0 - Dropped Node.js@0.8.0 support and updated Travis CI versions

@@ -3,0 +5,0 @@

40

lib/GIFEncoder.js

@@ -280,37 +280,15 @@ /*

// get closest match to transparent color if specified
// find index for transparent color
if (this.transparent !== null) {
this.transIndex = this.findClosest(this.transparent);
this.transIndex = imgq.lookupRGB(
(this.transparent & 0xFF0000) >> 16,
(this.transparent & 0x00FF00) >> 8,
(this.transparent & 0x0000FF)
);
} else {
this.transIndex = 0;
}
};
/*
Returns index of palette color closest to c
*/
GIFEncoder.prototype.findClosest = function(c) {
if (this.colorTab === null) return -1;
var r = (c & 0xFF0000) >> 16;
var g = (c & 0x00FF00) >> 8;
var b = (c & 0x0000FF);
var minpos = 0;
var dmin = 256 * 256 * 256;
var len = this.colorTab.length;
for (var i = 0; i < len;) {
var dr = r - (this.colorTab[i++] & 0xff);
var dg = g - (this.colorTab[i++] & 0xff);
var db = b - (this.colorTab[i] & 0xff);
var d = dr * dr + dg * dg + db * db;
var index = i / 3;
if (this.usedEntry[index] && (d < dmin)) {
dmin = d;
minpos = index;
}
i++;
}
return minpos;
};
/*

@@ -361,3 +339,3 @@ Extracts image pixels into byte array pixels

if (this.dispose >= 0) {
disp = dispose & 7; // user override
disp = this.dispose & 7; // user override
}

@@ -364,0 +342,0 @@ disp <<= 2;

{
"name": "gif-encoder",
"description": "Streaming GIF encoder",
"version": "0.5.0",
"version": "0.6.0",
"homepage": "https://github.com/twolfson/gif-encoder",

@@ -45,3 +45,5 @@ "author": {

"grunt-contrib-watch": "~0.4.0",
"mocha": "~1.11.0"
"mocha": "~1.11.0",
"ndarray-fill": "~1.0.1",
"zeros": "~1.0.0"
},

@@ -48,0 +50,0 @@ "keywords": [

@@ -5,2 +5,4 @@ var assert = require('assert');

var async = require('async');
var ndarrayFill = require('ndarray-fill');
var zeros = require('zeros');

@@ -94,1 +96,59 @@ var GifEncoder = require('../lib/GIFEncoder.js');

});
describe('GifEncoder encoding a multi-framed image with a transparent background', function () {
createGif(15, 15);
before(function () {
this.gif.writeHeader();
this.gif.setDelay(500);
this.gif.setTransparent(0xFF00FF);
this.gif.setRepeat(0);
var i = 0;
for (; i < 3; i++) {
// DEV: We are drawing a diagonally moving dot
// +------+ +------+ +------+
// |xx | | | | |
// |xx | | | | |
// | | -> | xx | -> | |
// | | -> | xx | -> | |
// | | | | | xx|
// | | | | | xx|
// +------+ +------+ +------+
// Generate our frame
var frameNdarray = zeros([15, 15, 4]);
ndarrayFill(frameNdarray, function fillFrame (x, y, rgbaIndex) {
// If this is the alpha channel, always return it as full
if (rgbaIndex === 3) {
return 0xFF;
}
// Otherwise, if we are on our black dot, then draw it
if (i * 5 <= x && x < (i + 1) * 5 &&
i * 5 <= y && y < (i + 1) * 5) {
// Generate black dot (00 00 00)
return 0x00;
// Otherwise, draw our transparent color
} else {
return rgbaIndex === 1 ? 0x00 : 0xFF;
}
});
// Draw our frame
this.gif.addFrame(frameNdarray.data);
}
this.gif.finish();
});
before(function (done) {
this.gif.once('readable', done);
});
it('generates the expected bytes', function () {
var expectedBytes = fs.readFileSync(__dirname + '/expected-files/moving-dot.gif');
var actualBytes = this.gif.read();
if (process.env.DEBUG_TEST) {
try { fs.mkdirSync(__dirname + '/actual-files'); } catch (e) {}
fs.writeFileSync(__dirname + '/actual-files/moving-dot.gif', actualBytes);
}
assert.deepEqual(expectedBytes, actualBytes);
});
});
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