( 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 )
| 27 | cb: (x: number, y: number, idx: number) => any |
| 28 | ): I; |
| 29 | export 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 | |
| 83 | export function* scanIterator<I extends JimpClass>( |
| 84 | image: I, |
no outgoing calls
no test coverage detected
searching dependent graphs…