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

include Addition (Add) blending mode + Officially drop support for Node 8 #904

Merged
merged 4 commits into from Jun 29, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/core/src/composite/composite-modes.js
Expand Up @@ -42,6 +42,26 @@ export function multiply(src, dst, ops = 1) {
return { r, g, b, a };
}

export function add(src, dst, ops = 1) {
src.a *= ops;

const a = dst.a + src.a - dst.a * src.a;

const sra = src.r * src.a;
const sga = src.g * src.a;
const sba = src.b * src.a;

const dra = dst.r * dst.a;
const dga = dst.g * dst.a;
const dba = dst.b * dst.a;

const r = (sra + dra) / a;
const g = (sga + dga) / a;
const b = (sba + dba) / a;

return { r, g, b, a };
}

export function screen(src, dst, ops = 1) {
src.a *= ops;

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/constants.js
Expand Up @@ -14,6 +14,7 @@ export const VERTICAL_ALIGN_BOTTOM = 32;
export const BLEND_SOURCE_OVER = 'srcOver';
export const BLEND_DESTINATION_OVER = 'dstOver';
export const BLEND_MULTIPLY = 'multiply';
export const BLEND_ADD = 'add';
export const BLEND_SCREEN = 'screen';
export const BLEND_OVERLAY = 'overlay';
export const BLEND_DARKEN = 'darken';
Expand Down
1 change: 1 addition & 0 deletions packages/core/types/jimp.d.ts
Expand Up @@ -30,6 +30,7 @@ export interface JimpConstructors {
BLEND_SOURCE_OVER: string;
BLEND_DESTINATION_OVER: string;
BLEND_MULTIPLY: string;
BLEND_ADD: string;
BLEND_SCREEN: string;
BLEND_OVERLAY: string;
BLEND_DARKEN: string;
Expand Down
1 change: 1 addition & 0 deletions packages/jimp/README.md
Expand Up @@ -344,6 +344,7 @@ The following modes can be used for compositing two images together. mode defaul
Jimp.BLEND_SOURCE_OVER;
Jimp.BLEND_DESTINATION_OVER;
Jimp.BLEND_MULTIPLY;
Jimp.BLEND_ADD;
Jimp.BLEND_SCREEN;
Jimp.BLEND_OVERLAY;
Jimp.BLEND_DARKEN;
Expand Down