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

Function scan

packages/utils/src/index.ts:29–81  ·  view source on GitHub ↗
(
  image: I,
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  xArg: number | ((x: number, y: number, idx: number) => any),
  yArg?: number,
  wArg?: number,
  hArg?: number,
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  cbArg?: (x: number, y: number, idx: number) => any
)

Source from the content-addressed store, hash-verified

27 cb: (x: number, y: number, idx: number) => any
28): I;
29export function scan<I extends { bitmap: Bitmap }>(
30 image: I,
31 // eslint-disable-next-line @typescript-eslint/no-explicit-any
32 xArg: number | ((x: number, y: number, idx: number) => any),
33 yArg?: number,
34 wArg?: number,
35 hArg?: number,
36 // eslint-disable-next-line @typescript-eslint/no-explicit-any
37 cbArg?: (x: number, y: number, idx: number) => any
38): I {
39 let x: number;
40 let y: number;
41 let w: number;
42 let h: number;
43 // eslint-disable-next-line @typescript-eslint/no-explicit-any
44 let cb: (x: number, y: number, idx: number) => any;
45
46 if (typeof xArg === "function") {
47 cb = xArg;
48 x = 0;
49 y = 0;
50 w = image.bitmap.width;
51 h = image.bitmap.height;
52 } else {
53 x = xArg;
54 if (typeof yArg !== "number") throw new Error("y must be a number");
55 y = yArg;
56 if (typeof wArg !== "number") throw new Error("w must be a number");
57 w = wArg;
58 if (typeof hArg !== "number") throw new Error("h must be a number");
59 h = hArg;
60 if (typeof cbArg !== "function") throw new Error("cb must be a function");
61 cb = cbArg;
62 }
63
64 // round input
65 x = Math.round(x);
66 y = Math.round(y);
67 w = Math.round(w);
68 h = Math.round(h);
69
70 const bound = cb.bind(image);
71
72 for (let _y = y; _y < y + h; _y++) {
73 for (let _x = x; _x < x + w; _x++) {
74 const idx = (image.bitmap.width * _y + _x) << 2;
75 // Bind the images so this.bitmap works
76 bound(_x, _y, idx);
77 }
78 }
79
80 return image;
81}
82
83export function* scanIterator<I extends JimpClass>(
84 image: I,

Callers 8

scanMethod · 0.90
cropFunction · 0.90
blitFunction · 0.90
pixelateFunction · 0.90
convoluteFunction · 0.90
encodeFunction · 0.90
decodeFunction · 0.90
index.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…