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

Function displace

plugins/plugin-displace/src/index.ts:29–44  ·  view source on GitHub ↗

* Displaces the image based on the provided displacement map * @param map the source Jimp instance * @param offset * @example * ```ts * import { Jimp } from "jimp"; * * const image = await Jimp.read("test/image.png"); * const map = await Jimp.read("test/map.png"); * * i

(image: I, options: DisplaceOptions)

Source from the content-addressed store, hash-verified

27 * ```
28 */
29 displace<I extends JimpClass>(image: I, options: DisplaceOptions) {
30 const { map, offset } = DisplaceOptionsSchema.parse(options);
31 const source = clone(image);
32
33 image.scan((x, y, idx) => {
34 let displacement = (map.bitmap.data[idx]! / 256) * offset;
35 displacement = Math.round(displacement);
36
37 const ids = image.getPixelIndex(x + displacement, y);
38 image.bitmap.data[ids] = source.bitmap.data[idx]!;
39 image.bitmap.data[ids + 1] = source.bitmap.data[idx + 1]!;
40 image.bitmap.data[ids + 2] = source.bitmap.data[idx + 2]!;
41 });
42
43 return image;
44 },
45};

Callers

nothing calls this directly

Calls 3

cloneFunction · 0.90
getPixelIndexMethod · 0.80
scanMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…