Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify and fix flip #879

Merged
merged 2 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions packages/plugin-flip/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ function flipFn(horizontal, vertical, cb) {
cb
);

if (horizontal && vertical) {
// shortcut
return this.rotate(180, true, cb);
}

const bitmap = Buffer.alloc(this.bitmap.data.length);
this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function(
x,
Expand Down
99 changes: 99 additions & 0 deletions packages/plugin-flip/test/flipping.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { Jimp, mkJGD } from '@jimp/test-utils';

import configure from '@jimp/custom';

import flip from '../src';

const jimp = configure({ plugins: [flip] }, Jimp);

describe('Flipping plugin', () => {
it('can flip horizontally', async () => {
const src = await jimp.read(
mkJGD(
'AAAABBBB',
'AAABAAAB',
'ABABABAB',
'CCCCCCCC',
'CCCCCCCC',
'CCCCCCCC',
'AACCCCAA'
)
);

const result = src.flip(true, false);

result
.getJGDSync()
.should.be.sameJGD(
mkJGD(
'BBBBAAAA',
'BAAABAAA',
'BABABABA',
'CCCCCCCC',
'CCCCCCCC',
'CCCCCCCC',
'AACCCCAA'
)
);
});

it('can flip vertically', async () => {
const src = await jimp.read(
mkJGD(
'AAAABBBB',
'AAABAAAB',
'ABABABAB',
'CCCCCCCC',
'CCCCCCCC',
'CCCCCCCC',
'AACCCCAA'
)
);

const result = src.flip(false, true);

result
.getJGDSync()
.should.be.sameJGD(
mkJGD(
'AACCCCAA',
'CCCCCCCC',
'CCCCCCCC',
'CCCCCCCC',
'ABABABAB',
'AAABAAAB',
'AAAABBBB'
)
);
});

it('can flip both horizontally and vertically at once', async () => {
const src = await jimp.read(
mkJGD(
'AAAABBBB',
'AAABAAAB',
'ABABABAB',
'CCCCCCCC',
'CCCCCCCC',
'CCCCCCCC',
'AACCCCAA'
)
);

const result = src.flip(true, true);

result
.getJGDSync()
.should.be.sameJGD(
mkJGD(
'AACCCCAA',
'CCCCCCCC',
'CCCCCCCC',
'CCCCCCCC',
'BABABABA',
'BAAABAAA',
'BBBBAAAA'
)
);
});
});