-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: blend pixels using alpha in all draw functions (#478)
Closes: #477
- Loading branch information
1 parent
ec04a57
commit 692b155
Showing
12 changed files
with
129 additions
and
42 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
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
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
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
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,49 @@ | ||
import { setBlendedVisiblePixel } from '../setBlendedVisiblePixel'; | ||
|
||
test('GREYA image, default options', () => { | ||
const image = testUtils.createGreyaImage([ | ||
[50, 255], | ||
[20, 30], | ||
]); | ||
setBlendedVisiblePixel(image, 0, 1); | ||
expect(image).toMatchImageData([ | ||
[50, 255], | ||
[0, 255], | ||
]); | ||
}); | ||
|
||
test('GREYA image: set pixel out of bounds', () => { | ||
const data = [ | ||
[50, 255, 1, 2, 3, 4], | ||
[20, 30, 5, 6, 7, 8], | ||
[1, 2, 3, 4, 5, 6], | ||
]; | ||
const image = testUtils.createGreyaImage(data); | ||
setBlendedVisiblePixel(image, 0, 5, [40, 40]); | ||
expect(image).toMatchImageData(data); | ||
}); | ||
|
||
test('RGBA image: set pixel out of bounds', () => { | ||
const data = [ | ||
[50, 255, 1, 200, 2, 3, 4, 200], | ||
[20, 30, 5, 200, 6, 7, 8, 200], | ||
[1, 2, 3, 200, 4, 5, 6, 200], | ||
]; | ||
const image = testUtils.createGreyaImage(data); | ||
setBlendedVisiblePixel(image, 0, 5, [40, 40, 40, 40]); | ||
expect(image).toMatchImageData(data); | ||
}); | ||
|
||
test('asymetrical test', () => { | ||
const image = testUtils.createGreyaImage([ | ||
[50, 255, 1, 2, 3, 4], | ||
[20, 30, 5, 6, 7, 8], | ||
[1, 2, 3, 4, 5, 6], | ||
]); | ||
setBlendedVisiblePixel(image, 2, 0, [0, 125]); | ||
expect(image).toMatchImageData([ | ||
[50, 255, 1, 2, 0, 127], | ||
[20, 30, 5, 6, 7, 8], | ||
[1, 2, 3, 4, 5, 6], | ||
]); | ||
}); |
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,22 @@ | ||
import { Image } from '../Image'; | ||
import { Mask } from '../Mask'; | ||
|
||
import { setBlendedPixel } from './setBlendedPixel'; | ||
|
||
/** | ||
* Blend the given pixel with the pixel at the specified location in the image if the pixel is in image's bounds. | ||
* @param image - The image with which to blend. | ||
* @param column - Column of the target pixel. | ||
* @param row - Row of the target pixel. | ||
* @param color - Color with which to blend the image pixel. @default `'Opaque black'`. | ||
*/ | ||
export function setBlendedVisiblePixel( | ||
image: Image | Mask, | ||
column: number, | ||
row: number, | ||
color?: number[], | ||
) { | ||
if (column >= 0 && column < image.width && row >= 0 && row < image.height) { | ||
setBlendedPixel(image, column, row, color); | ||
} | ||
} |