-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added fx to the MagickImageCollection.
- Loading branch information
Showing
2 changed files
with
120 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm. | ||
Licensed under the Apache License, Version 2.0. | ||
*/ | ||
|
||
import { Channels } from '@src/enums/channels'; | ||
import { MagickColor } from '@src/magick-color'; | ||
import { MagickImage } from '@src/magick-image'; | ||
import { bogusAsyncMethod } from '@test/bogus-async'; | ||
import { TestImages } from '@test/test-images'; | ||
|
||
describe('MagickImageCollection#fx', () => { | ||
it('should throw exception when collection is empty', () => { | ||
TestImages.emptyCollection.use((images) => { | ||
expect(() => { | ||
images.fx('test', () => { /* never reached */ }); | ||
}).toThrowError('operation requires at least one image'); | ||
}); | ||
}); | ||
|
||
it('apply a mathematical expression', () => { | ||
TestImages.emptyCollection.use((images) => { | ||
images.push(MagickImage.create(new MagickColor('#ff0040'), 1, 1)); | ||
images.push(MagickImage.create(new MagickColor('#00ff40'), 1, 1)); | ||
images.fx('(u+v)/2', (image) => { | ||
expect(image).toHavePixelWithColor(0, 0, new MagickColor('#808040ff')); | ||
}); | ||
}); | ||
}); | ||
|
||
it('apply a mathematical expression async', async () => { | ||
await TestImages.emptyCollection.use(async (images) => { | ||
images.push(MagickImage.create(new MagickColor('#ff0040'), 1, 1)); | ||
images.push(MagickImage.create(new MagickColor('#00ff40'), 1, 1)); | ||
await images.fx('(u+v)/2', async (image) => { | ||
expect(image).toHavePixelWithColor(0, 0, new MagickColor('#808040ff')); | ||
|
||
await bogusAsyncMethod(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('apply a mathematical expression to the specified channels', () => { | ||
TestImages.emptyCollection.use((images) => { | ||
images.push(MagickImage.create(new MagickColor('#ff0040'), 1, 1)); | ||
images.push(MagickImage.create(new MagickColor('#00ff40'), 1, 1)); | ||
images.fx('(u+v)/2', Channels.Red | Channels.Blue, (image) => { | ||
expect(image).toHavePixelWithColor(0, 0, new MagickColor('#800040ff')); | ||
}); | ||
}); | ||
}); | ||
|
||
it('apply a mathematical expression to the specified channels async', async () => { | ||
await TestImages.emptyCollection.use(async (images) => { | ||
images.push(MagickImage.create(new MagickColor('#aa00bb'), 1, 1)); | ||
images.push(MagickImage.create(new MagickColor('#00ff40'), 1, 1)); | ||
await images.fx('(u+v)/2', Channels.Green, async (image) => { | ||
expect(image).toHavePixelWithColor(0, 0, new MagickColor('#aa80bbff')); | ||
|
||
await bogusAsyncMethod(); | ||
}); | ||
}); | ||
}); | ||
}); |