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

+8
View File
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "../src",
"module": "nodenext",
"moduleResolution": "nodenext"
}
}
+17
View File
@@ -0,0 +1,17 @@
{
"extends": "./build.json",
"include": [
"../src/**/*.ts",
"../src/**/*.cts",
"../src/**/*.tsx",
"../src/**/*.json"
],
"exclude": [
"../**/*.test.ts",
"../src/**/*.mts",
"../src/package.json"
],
"compilerOptions": {
"outDir": "../.tshy-build/commonjs"
}
}
+16
View File
@@ -0,0 +1,16 @@
{
"extends": "./build.json",
"include": [
"../src/**/*.ts",
"../src/**/*.mts",
"../src/**/*.tsx",
"../src/**/*.json"
],
"exclude": [
"../**/*.test.ts",
"../src/package.json"
],
"compilerOptions": {
"outDir": "../.tshy-build/esm"
}
}
+5
View File
@@ -0,0 +1,5 @@

> @jimp/plugin-displace@1.5.0 build /Users/andrewlisowski/Documents/jimp/plugins/plugin-displace
> tshy
+5
View File
@@ -0,0 +1,5 @@

> @jimp/plugin-displace@1.1.2 lint /Users/andrewlisowski/Documents/jimp/plugins/plugin-displace
> eslint .
+52
View File
@@ -0,0 +1,52 @@
# v1.1.3 (Mon Sep 02 2024)
#### 🐛 Bug Fix
- Update deps [#1319](https://github.com/jimp-dev/jimp/pull/1319) ([@hipstersmoothie](https://github.com/hipstersmoothie))
#### Authors: 1
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
---
# v1.1.0 (Sun Sep 01 2024)
#### ⚠️ Pushed to `main`
- upgrade tshy ([@hipstersmoothie](https://github.com/hipstersmoothie))
- update more docs ([@hipstersmoothie](https://github.com/hipstersmoothie))
#### Authors: 1
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
---
# v1.0.3 (Sat Aug 31 2024)
#### 🐛 Bug Fix
- Fix build [#1303](https://github.com/jimp-dev/jimp/pull/1303) ([@hipstersmoothie](https://github.com/hipstersmoothie))
#### ⚠️ Pushed to `main`
- add clean script ([@hipstersmoothie](https://github.com/hipstersmoothie))
#### Authors: 1
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
---
# v1.0.2 (Sat Aug 31 2024)
#### ⚠️ Pushed to `main`
- set side effects ([@hipstersmoothie](https://github.com/hipstersmoothie))
- fix versions ([@hipstersmoothie](https://github.com/hipstersmoothie))
- add publish config ([@hipstersmoothie](https://github.com/hipstersmoothie))
#### Authors: 1
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Oliver Moran
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+10
View File
@@ -0,0 +1,10 @@
<div align="center">
<img width="200" height="200"
src="https://s3.amazonaws.com/pix.iemoji.com/images/emoji/apple/ios-11/256/crayon.png">
<h1>@jimp/plugin-displace</h1>
<p>Displace an image.</p>
</div>
Displaces the image based on the provided displacement map
- [displace](http://jimp-dev.github.io/jimp/api/jimp/classes/jimp#displace)
+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;IACrC,+BAA+B;IAC/B,GAAG,EAAE,uBAAe;IACpB,qCAAqC;IACrC,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;CACnB,CAAC,CAAC;AAIU,QAAA,OAAO,GAAG;IACrB;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAsB,KAAQ,EAAE,OAAwB;QAC9D,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,qBAAqB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC7D,MAAM,MAAM,GAAG,IAAA,aAAK,EAAC,KAAK,CAAC,CAAC;QAE5B,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE;YACvB,IAAI,YAAY,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAE,GAAG,GAAG,CAAC,GAAG,MAAM,CAAC;YAC1D,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YAExC,MAAM,GAAG,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,GAAG,YAAY,EAAE,CAAC,CAAC,CAAC;YACrD,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAE,CAAC;YAClD,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAE,CAAC;YAC1D,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAE,CAAC;QAC5D,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC"}
+3
View File
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
+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"}
+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,CAAC,CAAC,MAAM,EAAE;CACnB,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAsB,KAAQ,EAAE,OAAwB;QAC9D,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,qBAAqB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC7D,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QAE5B,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE;YACvB,IAAI,YAAY,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAE,GAAG,GAAG,CAAC,GAAG,MAAM,CAAC;YAC1D,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YAExC,MAAM,GAAG,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,GAAG,YAAY,EAAE,CAAC,CAAC,CAAC;YACrD,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAE,CAAC;YAClD,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAE,CAAC;YAC1D,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAE,CAAC;QAC5D,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC"}
+3
View File
@@ -0,0 +1,3 @@
{
"type": "module"
}
+2
View File
@@ -0,0 +1,2 @@
import shared from "@jimp/config-eslint/base.js";
export default [...shared];
+60
View File
@@ -0,0 +1,60 @@
{
"name": "@jimp/plugin-displace",
"version": "1.6.0",
"repository": "jimp-dev/jimp",
"engines": {
"node": ">=18"
},
"scripts": {
"lint": "eslint .",
"build": "tshy",
"dev": "tshy --watch",
"clean": "rm -rf node_modules .tshy .tshy-build dist .turbo"
},
"author": "Andrew Lisowski <lisowski54@gmail.com>",
"license": "MIT",
"dependencies": {
"@jimp/types": "1.6.0",
"@jimp/utils": "1.6.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@jimp/config-eslint": "1.6.0",
"@jimp/config-typescript": "1.6.0",
"eslint": "^9.9.1",
"tshy": "^3.0.2",
"typescript": "^5.5.4",
"vitest": "^2.0.5"
},
"tshy": {
"exclude": [
"**/*.test.ts"
],
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts"
}
},
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/commonjs/index.d.ts",
"default": "./dist/commonjs/index.js"
}
}
},
"main": "./dist/commonjs/index.js",
"types": "./dist/commonjs/index.d.ts",
"type": "module",
"publishConfig": {
"access": "public"
},
"sideEffects": false,
"module": "./dist/esm/index.js",
"gitHead": "c88abe6046dccbdb6e4f5f00c3dd403c81d83515"
}
+45
View File
@@ -0,0 +1,45 @@
import { JimpClass, 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 type DisplaceOptions = z.infer<typeof DisplaceOptionsSchema>;
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<I extends JimpClass>(image: I, options: DisplaceOptions) {
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;
},
};
+6
View File
@@ -0,0 +1,6 @@
{
"extends": "@jimp/config-typescript/base.json",
"compilerOptions": {
"outDir": "dist"
}
}