@jimp/utils
Advanced tools
Comparing version
@@ -11,3 +11,10 @@ "use strict"; | ||
exports.scan = scan; | ||
exports.scanIterator = scanIterator; | ||
require("regenerator-runtime/runtime"); | ||
var _marked = | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(scanIterator); | ||
function isNodePattern(cb) { | ||
@@ -53,2 +60,57 @@ if (typeof cb === 'undefined') { | ||
} | ||
function scanIterator(image, x, y, w, h) { | ||
var _y, _x, idx; | ||
return regeneratorRuntime.wrap(function scanIterator$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
// round input | ||
x = Math.round(x); | ||
y = Math.round(y); | ||
w = Math.round(w); | ||
h = Math.round(h); | ||
_y = y; | ||
case 5: | ||
if (!(_y < y + h)) { | ||
_context.next = 17; | ||
break; | ||
} | ||
_x = x; | ||
case 7: | ||
if (!(_x < x + w)) { | ||
_context.next = 14; | ||
break; | ||
} | ||
idx = image.bitmap.width * _y + _x << 2; | ||
_context.next = 11; | ||
return { | ||
x: _x, | ||
y: _y, | ||
idx: idx, | ||
image: image | ||
}; | ||
case 11: | ||
_x++; | ||
_context.next = 7; | ||
break; | ||
case 14: | ||
_y++; | ||
_context.next = 5; | ||
break; | ||
case 17: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _marked, this); | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,5 @@ | ||
var _marked = | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(scanIterator); | ||
export function isNodePattern(cb) { | ||
@@ -39,2 +43,56 @@ if (typeof cb === 'undefined') { | ||
} | ||
export function scanIterator(image, x, y, w, h) { | ||
var _y, _x, idx; | ||
return regeneratorRuntime.wrap(function scanIterator$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
// round input | ||
x = Math.round(x); | ||
y = Math.round(y); | ||
w = Math.round(w); | ||
h = Math.round(h); | ||
_y = y; | ||
case 5: | ||
if (!(_y < y + h)) { | ||
_context.next = 17; | ||
break; | ||
} | ||
_x = x; | ||
case 7: | ||
if (!(_x < x + w)) { | ||
_context.next = 14; | ||
break; | ||
} | ||
idx = image.bitmap.width * _y + _x << 2; | ||
_context.next = 11; | ||
return { | ||
x: _x, | ||
y: _y, | ||
idx: idx, | ||
image: image | ||
}; | ||
case 11: | ||
_x++; | ||
_context.next = 7; | ||
break; | ||
case 14: | ||
_y++; | ||
_context.next = 5; | ||
break; | ||
case 17: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _marked, this); | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@jimp/utils", | ||
"version": "0.6.8", | ||
"version": "0.7.0", | ||
"description": "Utils for jimp extensions.", | ||
@@ -24,3 +24,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "aa937725a7db4f33c68cbab36ab5cf942f4b90ff" | ||
"gitHead": "cd5ff6a525c0e547fb0b8172a864d98c4ed7d5fd" | ||
} |
@@ -53,1 +53,11 @@ <div align="center"> | ||
``` | ||
### scanIterator | ||
It's possible to make an iterator scan with a `for ... of`, if you want to `break` the scan before it reaches the end, but note, that this iterator has a huge performance implication: | ||
```js | ||
for (const { x, y, idx, image } of scanIterator(image, 0, 0, image.bitmap.width, image.bitmap.height)) { | ||
} | ||
``` |
@@ -41,1 +41,16 @@ export function isNodePattern(cb) { | ||
} | ||
export function* scanIterator(image, x, y, w, h) { | ||
// round input | ||
x = Math.round(x); | ||
y = Math.round(y); | ||
w = Math.round(w); | ||
h = Math.round(h); | ||
for (let _y = y; _y < y + h; _y++) { | ||
for (let _x = x; _x < x + w; _x++) { | ||
const idx = (image.bitmap.width * _y + _x) << 2; | ||
yield { x: _x, y: _y, idx, image }; | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
15627
54.91%217
108.65%63
18.87%