Skip to content

Commit

Permalink
Added test for partial frame rendering. Test fails prior to pull #18.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtlapp committed Jul 21, 2019
1 parent 506f927 commit 9da7a84
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
Binary file added test/fixtures/rnaples-bad.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/fixtures/rnaples-check.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/fixtures/rnaples-frame-10.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 32 additions & 3 deletions test/lib/tools.js
Expand Up @@ -2,14 +2,19 @@

const assert = require('chai').assert;
const Path = require('path');
const Jimp = require('jimp');
const Bitmaps = require('./bitmaps');
const { BitmapImage } = require('../../src/index');
const { GifFrame } = require('../../src/gifframe');

exports.checkBitmap = function (bitmap, width, height, rgbaOrBuf) {
assert.strictEqual(bitmap.width, width);
assert.strictEqual(bitmap.height, height);
assert.strictEqual(bitmap.width, width, "width");
assert.strictEqual(bitmap.height, height, "height");
if (Buffer.isBuffer(rgbaOrBuf)) {
assert.strictEqual(bitmap.data, rgbaOrBuf);
assert.strictEqual(bitmap.data.length, rgbaOrBuf.length, "length");
for (let i = 0; i < rgbaOrBuf.length; ++i ) {
assert.strictEqual(rgbaOrBuf[i], bitmap.data[i], "at buffer index "+ i);
}
}
else if (typeof rgbaOrBuf === 'number') {
const rgba = rgbaOrBuf
Expand Down Expand Up @@ -91,6 +96,10 @@ exports.getGifPath = function (filenameMinusExtension) {
return exports.getFixturePath(filenameMinusExtension + '.gif');
};

exports.getImagePath = function (filename) {
return exports.getFixturePath(filename);
};

exports.getSeries = function (seriesName, transparentRGB) {
const series = Bitmaps.PREMADE[seriesName];
if (series === undefined) {
Expand All @@ -103,6 +112,26 @@ exports.getSeries = function (seriesName, transparentRGB) {
(_stringsToBitmap(stringPic, transparentRGB)));
};

exports.loadBitmapImage = function (imagePath) {
return new Promise((resolve, reject) => {
new Jimp(imagePath, (err, jimp) => {
if (err) return reject(err);
resolve(new BitmapImage(jimp.bitmap));
});
});
};

exports.saveBitmapImage = function (bitmapImage, path) {
let jimp = new Jimp(1, 1, 0);
jimp.bitmap = bitmapImage.bitmap;
return new Promise((resolve, reject) => {
jimp.write(path, (err) => {
if (err) return reject(err);
resolve();
});
});
};

exports.verifyFrameInfo = function (actual, expected, frameIndex=0, note='') {
expected = Object.assign({}, expected); // don't munge caller
if (expected.xOffset !== undefined) {
Expand Down
23 changes: 23 additions & 0 deletions test/test_decoding.js
Expand Up @@ -200,6 +200,29 @@ describe("multiframe decoding", () => {
});
});

describe("partial frame decoding", () => {

it("renders partial frames properly onto full frames", () => {
return GifUtil.read(Tools.getGifPath('rnaples-offsets-public'))
.then(actualGif => {
const actualBitmapImage = actualGif.frames[10];
return Tools.saveBitmapImage(actualBitmapImage, Tools.getImagePath('rnaples-check.png'))
.then(() => {
return Tools.loadBitmapImage(Tools.getImagePath('rnaples-frame-10.png'));
})
.then(expectedBitmapImage => {
const expectedBitmap = expectedBitmapImage.bitmap;
Tools.checkBitmap(
actualBitmapImage.bitmap,
expectedBitmap.width,
expectedBitmap.height,
expectedBitmap.data
);
});
});
});
});

function _compareGifToSeries(actualGif, expectedSeries, options) {

assert.strictEqual(actualGif.width, expectedSeries[0].width);
Expand Down

0 comments on commit 9da7a84

Please sign in to comment.