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

Function normalize

plugins/plugin-color/src/index.ts:281–315  ·  view source on GitHub ↗

* Normalizes the image. * @example * ```ts * import { Jimp } from "jimp"; * * const image = await Jimp.read("test/image.png"); * * image.normalize(); * ```

(image: I)

Source from the content-addressed store, hash-verified

279 * ```
280 */
281 normalize<I extends JimpClass>(image: I) {
282 const h = histogram(image);
283
284 // store bounds (minimum and maximum values)
285 const bounds = {
286 r: getBounds(h.r),
287 g: getBounds(h.g),
288 b: getBounds(h.b),
289 };
290
291 // apply value transformations
292 image.scan((_, __, idx) => {
293 const r = image.bitmap.data[idx + 0]!;
294 const g = image.bitmap.data[idx + 1]!;
295 const b = image.bitmap.data[idx + 2]!;
296
297 image.bitmap.data[idx + 0] = normalizeValue(
298 r,
299 bounds.r[0]!,
300 bounds.r[1]!,
301 );
302 image.bitmap.data[idx + 1] = normalizeValue(
303 g,
304 bounds.g[0]!,
305 bounds.g[1]!,
306 );
307 image.bitmap.data[idx + 2] = normalizeValue(
308 b,
309 bounds.b[0]!,
310 bounds.b[1]!,
311 );
312 });
313
314 return image;
315 },
316
317 /**
318 * Inverts the colors in the image.

Callers

nothing calls this directly

Calls 4

histogramFunction · 0.85
getBoundsFunction · 0.85
normalizeValueFunction · 0.85
scanMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…