MCPcopy
hub / github.com/jimp-dev/jimp / colorDiff

Function colorDiff

packages/utils/src/index.ts:220–236  ·  view source on GitHub ↗
(
  rgba1: RGBAColor | RGBColor,
  rgba2: RGBAColor | RGBColor
)

Source from the content-addressed store, hash-verified

218 * ```
219 */
220export function colorDiff(
221 rgba1: RGBAColor | RGBColor,
222 rgba2: RGBAColor | RGBColor
223) {
224 const sq = (n: number) => Math.pow(n, 2);
225 const { max } = Math;
226 const maxVal = 255 * 255 * 3;
227 const rgba1A = "a" in rgba1 ? rgba1.a : 255;
228 const rgba2A = "a" in rgba2 ? rgba2.a : 255;
229
230 return (
231 (max(sq(rgba1.r - rgba2.r), sq(rgba1.r - rgba2.r - rgba1A + rgba2A)) +
232 max(sq(rgba1.g - rgba2.g), sq(rgba1.g - rgba2.g - rgba1A + rgba2A)) +
233 max(sq(rgba1.b - rgba2.b), sq(rgba1.b - rgba2.b - rgba1A + rgba2A))) /
234 maxVal
235 );
236}
237
238/**
239 * Limits a number to between 0 or 255

Callers 2

autocropFunction · 0.90
index.test.tsFile · 0.85

Calls 1

sqFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…