You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
596 B
24 lines
596 B
'use strict'
|
|
|
|
module.exports = function clip (pixels, shape, rect) {
|
|
var stride = shape[2] || 4
|
|
var row = shape[0],
|
|
col = shape[1] || Math.floor(pixels.length / stride / row)
|
|
var x = rect[0],
|
|
y = rect[1] || 0,
|
|
w = rect[2] || row - x,
|
|
h = rect[3] || col - y
|
|
|
|
var result = Array(w * stride * h)
|
|
|
|
var off = y * row * stride + x * stride
|
|
for (var j = 0; j < h; j++) {
|
|
for (var i = 0; i < w; i++) {
|
|
for (var k = 0; k < stride; k++) {
|
|
result[j * w * stride + i * stride + k] = pixels[off + j * row * stride + i * stride + k]
|
|
}
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|
|
|