Initial commit
This commit is contained in:
commit
e49726988c
5445 files changed
+1089914
No files matched your search
+118
@@ -0,0 +1,118 @@
|
||||
import { JimpClass } from "@jimp/types";
|
||||
import { z } from "zod";
|
||||
declare const BlitOptionsSchema: z.ZodUnion<[z.ZodObject<{
|
||||
bitmap: z.ZodObject<{
|
||||
data: z.ZodUnion<[z.ZodType<Buffer, z.ZodTypeDef, Buffer>, z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>]>;
|
||||
width: z.ZodNumber;
|
||||
height: z.ZodNumber;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
data: Buffer | Uint8Array;
|
||||
width: number;
|
||||
height: number;
|
||||
}, {
|
||||
data: Buffer | Uint8Array;
|
||||
width: number;
|
||||
height: number;
|
||||
}>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
bitmap: {
|
||||
data: Buffer | Uint8Array;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
}, {
|
||||
bitmap: {
|
||||
data: Buffer | Uint8Array;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
}>, z.ZodObject<{
|
||||
src: z.ZodObject<{
|
||||
bitmap: z.ZodObject<{
|
||||
data: z.ZodUnion<[z.ZodType<Buffer, z.ZodTypeDef, Buffer>, z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>]>;
|
||||
width: z.ZodNumber;
|
||||
height: z.ZodNumber;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
data: Buffer | Uint8Array;
|
||||
width: number;
|
||||
height: number;
|
||||
}, {
|
||||
data: Buffer | Uint8Array;
|
||||
width: number;
|
||||
height: number;
|
||||
}>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
bitmap: {
|
||||
data: Buffer | Uint8Array;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
}, {
|
||||
bitmap: {
|
||||
data: Buffer | Uint8Array;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
}>;
|
||||
/** the x position to blit the image */
|
||||
x: z.ZodOptional<z.ZodNumber>;
|
||||
/** the y position to blit the image */
|
||||
y: z.ZodOptional<z.ZodNumber>;
|
||||
/** the x position from which to crop the source image */
|
||||
srcX: z.ZodOptional<z.ZodNumber>;
|
||||
/** the y position from which to crop the source image */
|
||||
srcY: z.ZodOptional<z.ZodNumber>;
|
||||
/** the width to which to crop the source image */
|
||||
srcW: z.ZodOptional<z.ZodNumber>;
|
||||
/** the height to which to crop the source image */
|
||||
srcH: z.ZodOptional<z.ZodNumber>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
src: {
|
||||
bitmap: {
|
||||
data: Buffer | Uint8Array;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
};
|
||||
x?: number | undefined;
|
||||
y?: number | undefined;
|
||||
srcX?: number | undefined;
|
||||
srcY?: number | undefined;
|
||||
srcW?: number | undefined;
|
||||
srcH?: number | undefined;
|
||||
}, {
|
||||
src: {
|
||||
bitmap: {
|
||||
data: Buffer | Uint8Array;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
};
|
||||
x?: number | undefined;
|
||||
y?: number | undefined;
|
||||
srcX?: number | undefined;
|
||||
srcY?: number | undefined;
|
||||
srcW?: number | undefined;
|
||||
srcH?: number | undefined;
|
||||
}>]>;
|
||||
export type BlitOptions = z.infer<typeof BlitOptionsSchema>;
|
||||
export declare const methods: {
|
||||
/**
|
||||
* Short for "bit-block transfer".
|
||||
* It involves the transfer of a block of pixel data from one area of a computer's memory to another area, typically for the purpose of rendering images on the screen or manipulating them in various ways.
|
||||
* It's a fundamental operation in computer graphics utilized in various applications, from operating systems to video games.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Jimp } from "jimp";
|
||||
*
|
||||
* const image = await Jimp.read("test/image.png");
|
||||
* const parrot = await Jimp.read("test/party-parrot.png");
|
||||
*
|
||||
* image.blit({ src: parrot, x: 10, y: 10 });
|
||||
* ```
|
||||
*/
|
||||
blit<I extends JimpClass>(image: I, options: BlitOptions): I;
|
||||
};
|
||||
export {};
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAmB,MAAM,aAAa,CAAC;AAEzD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAoBxB,QAAA,MAAM,iBAAiB;;oCAEV,MAAM,gBAAe,MAAO;;;;cAK0B,MAAO;;;;cAAoF,MAAO;;;;;;cAClF,MAAO;;;;;;cAKvF,MACF;;;;;;;wCAZY,MAAM,gBAAe,MAAO;;;;kBAK0B,MAAO;;;;kBAAoF,MAAO;;;;;;kBAClF,MAAO;;;;;;kBAKvF,MACF;;;;;IA9BC,uCAAuC;;IAEvC,uCAAuC;;IAEvC,yDAAyD;;IAEzD,yDAAyD;;IAEzD,kDAAkD;;IAElD,mDAAmD;;;;;kBAc8B,MAAO;;;;;;;;;;;;;;kBAKvF,MACF;;;;;;;;;;;IAd6E,CAAC;AAE/E,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;;;;;OAcG;SACE,CAAC,SAAS,SAAS,SAAS,CAAC,WAAW,WAAW;CAuEzD,CAAC"}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
import { JimpClassSchema } from "@jimp/types";
|
||||
import { limit255, scan } from "@jimp/utils";
|
||||
import { z } from "zod";
|
||||
const BlitOptionsSchemaComplex = z.object({
|
||||
src: JimpClassSchema,
|
||||
/** the x position to blit the image */
|
||||
x: z.number().optional(),
|
||||
/** the y position to blit the image */
|
||||
y: z.number().optional(),
|
||||
/** the x position from which to crop the source image */
|
||||
srcX: z.number().optional(),
|
||||
/** the y position from which to crop the source image */
|
||||
srcY: z.number().optional(),
|
||||
/** the width to which to crop the source image */
|
||||
srcW: z.number().optional(),
|
||||
/** the height to which to crop the source image */
|
||||
srcH: z.number().optional(),
|
||||
});
|
||||
const BlitOptionsSchema = z.union([JimpClassSchema, BlitOptionsSchemaComplex]);
|
||||
export const methods = {
|
||||
/**
|
||||
* Short for "bit-block transfer".
|
||||
* It involves the transfer of a block of pixel data from one area of a computer's memory to another area, typically for the purpose of rendering images on the screen or manipulating them in various ways.
|
||||
* It's a fundamental operation in computer graphics utilized in various applications, from operating systems to video games.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { Jimp } from "jimp";
|
||||
*
|
||||
* const image = await Jimp.read("test/image.png");
|
||||
* const parrot = await Jimp.read("test/party-parrot.png");
|
||||
*
|
||||
* image.blit({ src: parrot, x: 10, y: 10 });
|
||||
* ```
|
||||
*/
|
||||
blit(image, options) {
|
||||
const parsed = BlitOptionsSchema.parse(options);
|
||||
let {
|
||||
// eslint-disable-next-line prefer-const
|
||||
src, x = 0, y = 0, srcX = 0, srcY = 0, srcW = src.bitmap.width, srcH = src.bitmap.height, } = "bitmap" in parsed ? { src: parsed } : parsed;
|
||||
if (!("bitmap" in src)) {
|
||||
throw new Error("The source must be a Jimp image");
|
||||
}
|
||||
if (typeof x !== "number" || typeof y !== "number") {
|
||||
throw new Error("x and y must be numbers");
|
||||
}
|
||||
// round input
|
||||
x = Math.round(x);
|
||||
y = Math.round(y);
|
||||
// round input
|
||||
srcX = Math.round(srcX);
|
||||
srcY = Math.round(srcY);
|
||||
srcW = Math.round(srcW);
|
||||
srcH = Math.round(srcH);
|
||||
const maxWidth = image.bitmap.width;
|
||||
const maxHeight = image.bitmap.height;
|
||||
scan(src, srcX, srcY, srcW, srcH, function (sx, sy, idx) {
|
||||
const xOffset = x + sx - srcX;
|
||||
const yOffset = y + sy - srcY;
|
||||
if (xOffset >= 0 &&
|
||||
yOffset >= 0 &&
|
||||
maxWidth - xOffset > 0 &&
|
||||
maxHeight - yOffset > 0) {
|
||||
const dstIdx = image.getPixelIndex(xOffset, yOffset);
|
||||
const srcColor = {
|
||||
r: src.bitmap.data[idx] || 0,
|
||||
g: src.bitmap.data[idx + 1] || 0,
|
||||
b: src.bitmap.data[idx + 2] || 0,
|
||||
a: src.bitmap.data[idx + 3] || 0,
|
||||
};
|
||||
const dst = {
|
||||
r: image.bitmap.data[dstIdx] || 0,
|
||||
g: image.bitmap.data[dstIdx + 1] || 0,
|
||||
b: image.bitmap.data[dstIdx + 2] || 0,
|
||||
a: image.bitmap.data[dstIdx + 3] || 0,
|
||||
};
|
||||
image.bitmap.data[dstIdx] =
|
||||
((srcColor.a * (srcColor.r - dst.r) - dst.r + 255) >> 8) + dst.r;
|
||||
image.bitmap.data[dstIdx + 1] =
|
||||
((srcColor.a * (srcColor.g - dst.g) - dst.g + 255) >> 8) + dst.g;
|
||||
image.bitmap.data[dstIdx + 2] =
|
||||
((srcColor.a * (srcColor.b - dst.b) - dst.b + 255) >> 8) + dst.b;
|
||||
image.bitmap.data[dstIdx + 3] = limit255(dst.a + srcColor.a);
|
||||
}
|
||||
});
|
||||
return image;
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,eAAe,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,GAAG,EAAE,eAAe;IACpB,uCAAuC;IACvC,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACxB,uCAAuC;IACvC,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACxB,yDAAyD;IACzD,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,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