Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
yi = y % this.bitmap.height;
}
}
let i = (this.bitmap.width * yi + xi) << 2;
// if out of bounds index is -1
if (xi < 0 || xi >= this.bitmap.width) {
i = -1;
}
if (yi < 0 || yi >= this.bitmap.height) {
i = -1;
}
if (isNodePattern(cb)) {
cb.call(this, null, i);
}
return i;
}
const alignH = hbits >> 1; // 0, 1, 2
const alignV = vbits >> 1; // 0, 1, 2
const f =
w / h > this.bitmap.width / this.bitmap.height
? w / this.bitmap.width
: h / this.bitmap.height;
this.scale(f, mode);
this.crop(
((this.bitmap.width - w) / 2) * alignH,
((this.bitmap.height - h) / 2) * alignV,
w,
h
);
if (isNodePattern(cb)) {
cb.call(this, null, this);
}
return this;
}
});
const bitmap = Buffer.allocUnsafe(w * h * 4);
let offset = 0;
this.scanQuiet(x, y, w, h, function(x, y, idx) {
const data = this.bitmap.data.readUInt32BE(idx, true);
bitmap.writeUInt32BE(data, offset, true);
offset += 4;
});
this.bitmap.data = bitmap;
}
this.bitmap.width = w;
this.bitmap.height = h;
if (isNodePattern(cb)) {
// @ts-ignore because cb can be undefined and isNodePattern doesn't narrow
cb.call(this, null, this);
}
return this;
});
}
if (gSum > 255) {
gSum = 255;
}
if (bSum > 255) {
bSum = 255;
}
newData[idx + 0] = rSum;
newData[idx + 1] = gSum;
newData[idx + 2] = bSum;
});
this.bitmap.data = newData;
if (isNodePattern(cb)) {
cb.call(this, null, this);
}
return this;
},
}
p1 = x + vmin[y];
p2 = x + vmax[y];
rsum += red[p1] - red[p2];
gsum += green[p1] - green[p2];
bsum += blue[p1] - blue[p2];
asum += alpha[p1] - alpha[p2];
yi += this.bitmap.width << 2;
}
}
}
if (isNodePattern(cb)) {
cb.call(this, null, this);
}
return this;
}
});
invert(cb) {
this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function(
x,
y,
idx
) {
this.bitmap.data[idx] = 255 - this.bitmap.data[idx];
this.bitmap.data[idx + 1] = 255 - this.bitmap.data[idx + 1];
this.bitmap.data[idx + 2] = 255 - this.bitmap.data[idx + 2];
});
if (isNodePattern(cb)) {
cb.call(this, null, this);
}
return this;
}
});
jimpEvMethod('clone', 'clone', function(cb) {
const clone = new Jimp(this);
if (isNodePattern(cb)) {
cb.call(clone, null, clone);
}
return clone;
});
blue += this.bitmap.data[idx + 2] * weight;
alpha += this.bitmap.data[idx + 3] * weight;
wsum += weight;
}
const idx = (y * this.bitmap.width + x) << 2;
this.bitmap.data[idx] = Math.round(red / wsum);
this.bitmap.data[idx + 1] = Math.round(green / wsum);
this.bitmap.data[idx + 2] = Math.round(blue / wsum);
this.bitmap.data[idx + 3] = Math.round(alpha / wsum);
}
}
}
if (isNodePattern(cb)) {
cb.call(this, null, this);
}
return this;
}
});
this.scanQuiet(0, 0, this.bitmap.width, this.bitmap.height, function(
x,
y,
idx
) {
const _x = horizontal ? this.bitmap.width - 1 - x : x;
const _y = vertical ? this.bitmap.height - 1 - y : y;
const _idx = (this.bitmap.width * _y + _x) << 2;
const data = this.bitmap.data.readUInt32BE(idx);
bitmap.writeUInt32BE(data, _idx);
});
this.bitmap.data = Buffer.from(bitmap);
if (isNodePattern(cb)) {
cb.call(this, null, this);
}
return this;
}
sy,
idx
) {
const destX = x + sx;
const destY = y + sy;
if (destX >= 0 && destY >= 0 && destX < w && destY < h) {
const dstIdx = baseImage.getPixelIndex(destX, destY);
const { data } = this.bitmap;
const avg = (data[idx + 0] + data[idx + 1] + data[idx + 2]) / 3;
baseImage.bitmap.data[dstIdx + 3] *= avg / 255;
}
});
if (isNodePattern(cb)) {
cb.call(this, null, this);
}
return this;
}
});