Path: blob/master/node_modules/@jimp/utils/src/index.js
1126 views
export function isNodePattern(cb) {1if (typeof cb === 'undefined') {2return false;3}45if (typeof cb !== 'function') {6throw new TypeError('Callback must be a function');7}89return true;10}1112export function throwError(error, cb) {13if (typeof error === 'string') {14error = new Error(error);15}1617if (typeof cb === 'function') {18return cb.call(this, error);19}2021throw error;22}2324export function scan(image, x, y, w, h, f) {25// round input26x = Math.round(x);27y = Math.round(y);28w = Math.round(w);29h = Math.round(h);3031for (let _y = y; _y < y + h; _y++) {32for (let _x = x; _x < x + w; _x++) {33const idx = (image.bitmap.width * _y + _x) << 2;34f.call(image, _x, _y, idx);35}36}3738return image;39}4041export function* scanIterator(image, x, y, w, h) {42// round input43x = Math.round(x);44y = Math.round(y);45w = Math.round(w);46h = Math.round(h);4748for (let _y = y; _y < y + h; _y++) {49for (let _x = x; _x < x + w; _x++) {50const idx = (image.bitmap.width * _y + _x) << 2;51yield { x: _x, y: _y, idx, image };52}53}54}555657