Initial commit

This commit is contained in:
robert committed 2025-05-30 18:13:30 +08:00
commit e49726988c
5445 files changed
+1089914

No files matched your search

+72
View File
@@ -0,0 +1,72 @@
import { JimpClass } from "@jimp/types";
import { z } from "zod";
declare const DisplaceOptionsSchema: z.ZodObject<{
/** the source Jimp instance */
map: 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 maximum displacement value */
offset: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
map: {
bitmap: {
data: Buffer | Uint8Array;
width: number;
height: number;
};
};
offset: number;
}, {
map: {
bitmap: {
data: Buffer | Uint8Array;
width: number;
height: number;
};
};
offset: number;
}>;
export type DisplaceOptions = z.infer<typeof DisplaceOptionsSchema>;
export declare const methods: {
/**
* Displaces the image based on the provided displacement map
* @param map the source Jimp instance
* @param offset
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
* const map = await Jimp.read("test/map.png");
*
* image.displace(map, 10);
* ```
*/
displace<I extends JimpClass>(image: I, options: DisplaceOptions): I;
};
export {};
//# sourceMappingURL=index.d.ts.map
+1
View File
@@ -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;AAExB,QAAA,MAAM,qBAAqB;IACzB,+BAA+B;;;wCAwBwB,MAAM,gBACnD,MAAO;;;;kBAIyB,MAEzC;;;;kBACwB,MAAO;;;;;;kBAEG,MAAO;;;;;;kBAMC,MAAO;;;;;IAtClD,qCAAqC;;;;;kBAgCF,MAAO;;;;;;;;;kBAMC,MAAO;;;;;;EApClD,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;;;;OAaG;aACM,CAAC,SAAS,SAAS,SAAS,CAAC,WAAW,eAAe;CAgBjE,CAAC"}
+42
View File
@@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.methods = void 0;
const types_1 = require("@jimp/types");
const utils_1 = require("@jimp/utils");
const zod_1 = require("zod");
const DisplaceOptionsSchema = zod_1.z.object({
/** the source Jimp instance */
map: types_1.JimpClassSchema,
/** the maximum displacement value */
offset: zod_1.z.number(),
});
exports.methods = {
/**
* Displaces the image based on the provided displacement map
* @param map the source Jimp instance
* @param offset
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
* const map = await Jimp.read("test/map.png");
*
* image.displace(map, 10);
* ```
*/
displace(image, options) {
const { map, offset } = DisplaceOptionsSchema.parse(options);
const source = (0, utils_1.clone)(image);
image.scan((x, y, idx) => {
let displacement = (map.bitmap.data[idx] / 256) * offset;
displacement = Math.round(displacement);
const ids = image.getPixelIndex(x + displacement, y);
image.bitmap.data[ids] = source.bitmap.data[idx];
image.bitmap.data[ids + 1] = source.bitmap.data[idx + 1];
image.bitmap.data[ids + 2] = source.bitmap.data[idx + 2];
});
return image;
},
};
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,uCAAyD;AACzD,uCAAoC;AACpC,6BAAwB;AAExB,MAAM,qBAAqB,GAAG,OAAC,CAAC,MAAM,CAAC;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+1,72 @@
import { JimpClass } from "@jimp/types";
import { z } from "zod";
declare const DisplaceOptionsSchema: z.ZodObject<{
/** the source Jimp instance */
map: 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 maximum displacement value */
offset: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
map: {
bitmap: {
data: Buffer | Uint8Array;
width: number;
height: number;
};
};
offset: number;
}, {
map: {
bitmap: {
data: Buffer | Uint8Array;
width: number;
height: number;
};
};
offset: number;
}>;
export type DisplaceOptions = z.infer<typeof DisplaceOptionsSchema>;
export declare const methods: {
/**
* Displaces the image based on the provided displacement map
* @param map the source Jimp instance
* @param offset
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
* const map = await Jimp.read("test/map.png");
*
* image.displace(map, 10);
* ```
*/
displace<I extends JimpClass>(image: I, options: DisplaceOptions): I;
};
export {};
//# sourceMappingURL=index.d.ts.map
+1
View File
@@ -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;AAExB,QAAA,MAAM,qBAAqB;IACzB,+BAA+B;;;wCAwBwB,MAAM,gBACnD,MAAO;;;;kBAIyB,MAEzC;;;;kBACwB,MAAO;;;;;;kBAEG,MAAO;;;;;;kBAMC,MAAO;;;;;IAtClD,qCAAqC;;;;;kBAgCF,MAAO;;;;;;;;;kBAMC,MAAO;;;;;;EApClD,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE,eAAO,MAAM,OAAO;IAClB;;;;;;;;;;;;;OAaG;aACM,CAAC,SAAS,SAAS,SAAS,CAAC,WAAW,eAAe;CAgBjE,CAAC"}
+39
View File
@@ -0,0 +1,39 @@
import { JimpClassSchema } from "@jimp/types";
import { clone } from "@jimp/utils";
import { z } from "zod";
const DisplaceOptionsSchema = z.object({
/** the source Jimp instance */
map: JimpClassSchema,
/** the maximum displacement value */
offset: z.number(),
});
export const methods = {
/**
* Displaces the image based on the provided displacement map
* @param map the source Jimp instance
* @param offset
* @example
* ```ts
* import { Jimp } from "jimp";
*
* const image = await Jimp.read("test/image.png");
* const map = await Jimp.read("test/map.png");
*
* image.displace(map, 10);
* ```
*/
displace(image, options) {
const { map, offset } = DisplaceOptionsSchema.parse(options);
const source = clone(image);
image.scan((x, y, idx) => {
let displacement = (map.bitmap.data[idx] / 256) * offset;
displacement = Math.round(displacement);
const ids = image.getPixelIndex(x + displacement, y);
image.bitmap.data[ids] = source.bitmap.data[idx];
image.bitmap.data[ids + 1] = source.bitmap.data[idx + 1];
image.bitmap.data[ids + 2] = source.bitmap.data[idx + 2];
});
return image;
},
};
//# sourceMappingURL=index.js.map
+1
View File
@@ -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,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,+BAA+B;IAC/B,GAAG,EAAE,eAAe;IACpB,qCAAqC;IACrC,MAAM,EAAE,CA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