* 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)
| 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 | }; |
nothing calls this directly
no test coverage detected
searching dependent graphs…