Skip to content

Commit

Permalink
include Addition (Add) blending mode + Officially drop support for No…
Browse files Browse the repository at this point in the history
…de 8 (#904)

* add Addition blending mode (oliver-moran#724)

* Bump version (0.14.0)

* Update README for jimp (addition of Addition blending mode)

* Revert @jimp/core's package.json
  • Loading branch information
GlitchyPSIX committed Jun 29, 2020
1 parent a29b668 commit 37cc5c6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
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

0 comments on commit 37cc5c6

Please sign in to comment.