Initial commit
This commit is contained in:
commit
e49726988c
5445 files changed
+1089914
No files matched your search
+8
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "../src",
|
||||
"module": "nodenext",
|
||||
"moduleResolution": "nodenext"
|
||||
}
|
||||
}
|
||||
+17
@@ -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
@@ -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
@@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
> @jimp/plugin-quantize@1.5.0 build /Users/andrewlisowski/Documents/jimp/plugins/plugin-quantize
|
||||
> tshy
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
> @jimp/plugin-quantize@1.1.2 lint /Users/andrewlisowski/Documents/jimp/plugins/plugin-quantize
|
||||
> eslint .
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
|
||||
|
||||
> @jimp/plugin-quantize@1.1.2 test /Users/andrewlisowski/Documents/jimp/plugins/plugin-quantize
|
||||
> vitest "--watch=false"
|
||||
|
||||
|
||||
[7m[1m[36m RUN [39m[22m[27m [36mv2.0.5[39m [90m/Users/andrewlisowski/Documents/jimp/plugins/plugin-quantize[39m
|
||||
|
||||
[?25l [90m·[39m [2msrc/[22mindex[2m.node.test.ts[22m[2m (1)[22m
|
||||
[90m·[39m Quantize[2m (1)[22m
|
||||
[90m·[39m defines default threshold for lighter backgrounds
|
||||
[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[2K[1A[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.node.test.ts[22m[2m (1)[22m[33m 5585[2mms[22m[39m
|
||||
[32m✓[39m Quantize[2m (1)[22m[33m 5585[2mms[22m[39m
|
||||
[32m✓[39m defines default threshold for lighter backgrounds[33m 5584[2mms[22m[39m
|
||||
[?25l[?25l[2K[1A[2K[1A[2K[1A[2K[G [32m✓[39m [2msrc/[22mindex[2m.node.test.ts[22m[2m (1)[22m[33m 5585[2mms[22m[39m
|
||||
[32m✓[39m Quantize[2m (1)[22m[33m 5585[2mms[22m[39m
|
||||
[32m✓[39m defines default threshold for lighter backgrounds[33m 5584[2mms[22m[39m
|
||||
|
||||
[2m Test Files [22m [1m[32m1 passed[39m[22m[90m (1)[39m
|
||||
[2m Tests [22m [1m[32m1 passed[39m[22m[90m (1)[39m
|
||||
[2m Start at [22m 01:34:00
|
||||
[2m Duration [22m 8.74s[2m (transform 630ms, setup 0ms, collect 1.47s, tests 5.58s, environment 0ms, prepare 461ms)[22m
|
||||
|
||||
[?25h[?25h
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
# v1.4.0 (Sat Sep 07 2024)
|
||||
|
||||
#### ⚠️ Pushed to `main`
|
||||
|
||||
- fix docs build ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
#### Authors: 1
|
||||
|
||||
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
---
|
||||
|
||||
# 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)
|
||||
|
||||
#### 🚀 Enhancement
|
||||
|
||||
- Add quantize plugin [#1307](https://github.com/jimp-dev/jimp/pull/1307) ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
|
||||
#### Authors: 1
|
||||
|
||||
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
||||
+21
@@ -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.
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<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-quantize</h1>
|
||||
<p>Reduces the number of colors in an image.</p>
|
||||
</div>
|
||||
|
||||
- [quantize](http://jimp-dev.github.io/jimp/api/jimp/classes/jimp#quantize)
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import { JimpClass } from "@jimp/types";
|
||||
import z from "zod";
|
||||
declare const QuantizeOptionsSchema: z.ZodObject<{
|
||||
colors: z.ZodOptional<z.ZodNumber>;
|
||||
colorDistanceFormula: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"cie94-textiles">, z.ZodLiteral<"cie94-graphic-arts">, z.ZodLiteral<"ciede2000">, z.ZodLiteral<"color-metric">, z.ZodLiteral<"euclidean">, z.ZodLiteral<"euclidean-bt709-noalpha">, z.ZodLiteral<"euclidean-bt709">, z.ZodLiteral<"manhattan">, z.ZodLiteral<"manhattan-bt709">, z.ZodLiteral<"manhattan-nommyde">, z.ZodLiteral<"pngquant">]>>;
|
||||
paletteQuantization: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"neuquant">, z.ZodLiteral<"neuquant-float">, z.ZodLiteral<"rgbquant">, z.ZodLiteral<"wuquant">]>>;
|
||||
imageQuantization: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"nearest">, z.ZodLiteral<"riemersma">, z.ZodLiteral<"floyd-steinberg">, z.ZodLiteral<"false-floyd-steinberg">, z.ZodLiteral<"stucki">, z.ZodLiteral<"atkinson">, z.ZodLiteral<"jarvis">, z.ZodLiteral<"burkes">, z.ZodLiteral<"sierra">, z.ZodLiteral<"two-sierra">, z.ZodLiteral<"sierra-lite">]>>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
colors?: number | undefined;
|
||||
colorDistanceFormula?: "cie94-textiles" | "cie94-graphic-arts" | "ciede2000" | "color-metric" | "euclidean" | "euclidean-bt709-noalpha" | "euclidean-bt709" | "manhattan" | "manhattan-bt709" | "manhattan-nommyde" | "pngquant" | undefined;
|
||||
paletteQuantization?: "neuquant" | "neuquant-float" | "rgbquant" | "wuquant" | undefined;
|
||||
imageQuantization?: "nearest" | "riemersma" | "floyd-steinberg" | "false-floyd-steinberg" | "stucki" | "atkinson" | "jarvis" | "burkes" | "sierra" | "two-sierra" | "sierra-lite" | undefined;
|
||||
}, {
|
||||
colors?: number | undefined;
|
||||
colorDistanceFormula?: "cie94-textiles" | "cie94-graphic-arts" | "ciede2000" | "color-metric" | "euclidean" | "euclidean-bt709-noalpha" | "euclidean-bt709" | "manhattan" | "manhattan-bt709" | "manhattan-nommyde" | "pngquant" | undefined;
|
||||
paletteQuantization?: "neuquant" | "neuquant-float" | "rgbquant" | "wuquant" | undefined;
|
||||
imageQuantization?: "nearest" | "riemersma" | "floyd-steinberg" | "false-floyd-steinberg" | "stucki" | "atkinson" | "jarvis" | "burkes" | "sierra" | "two-sierra" | "sierra-lite" | undefined;
|
||||
}>;
|
||||
export type QuantizeOptions = z.infer<typeof QuantizeOptionsSchema>;
|
||||
export declare const methods: {
|
||||
/**
|
||||
* Image color number reduction.
|
||||
*/
|
||||
quantize<I extends JimpClass>(image: I, options: QuantizeOptions): 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,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,QAAA,MAAM,qBAAqB;;;;;;;;;;;;;;;EAwCzB,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE,eAAO,MAAM,OAAO;IAClB;;OAEG;aACM,CAAC,SAAS,SAAS,SAAS,CAAC,WAAW,eAAe;CA4BjE,CAAC"}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.methods = void 0;
|
||||
const image_q_1 = require("image-q");
|
||||
const zod_1 = __importDefault(require("zod"));
|
||||
const QuantizeOptionsSchema = zod_1.default.object({
|
||||
colors: zod_1.default.number().optional(),
|
||||
colorDistanceFormula: zod_1.default
|
||||
.union([
|
||||
zod_1.default.literal("cie94-textiles"),
|
||||
zod_1.default.literal("cie94-graphic-arts"),
|
||||
zod_1.default.literal("ciede2000"),
|
||||
zod_1.default.literal("color-metric"),
|
||||
zod_1.default.literal("euclidean"),
|
||||
zod_1.default.literal("euclidean-bt709-noalpha"),
|
||||
zod_1.default.literal("euclidean-bt709"),
|
||||
zod_1.default.literal("manhattan"),
|
||||
zod_1.default.literal("manhattan-bt709"),
|
||||
zod_1.default.literal("manhattan-nommyde"),
|
||||
zod_1.default.literal("pngquant"),
|
||||
])
|
||||
.optional(),
|
||||
paletteQuantization: zod_1.default
|
||||
.union([
|
||||
zod_1.default.literal("neuquant"),
|
||||
zod_1.default.literal("neuquant-float"),
|
||||
zod_1.default.literal("rgbquant"),
|
||||
zod_1.default.literal("wuquant"),
|
||||
])
|
||||
.optional(),
|
||||
imageQuantization: zod_1.default
|
||||
.union([
|
||||
zod_1.default.literal("nearest"),
|
||||
zod_1.default.literal("riemersma"),
|
||||
zod_1.default.literal("floyd-steinberg"),
|
||||
zod_1.default.literal("false-floyd-steinberg"),
|
||||
zod_1.default.literal("stucki"),
|
||||
zod_1.default.literal("atkinson"),
|
||||
zod_1.default.literal("jarvis"),
|
||||
zod_1.default.literal("burkes"),
|
||||
zod_1.default.literal("sierra"),
|
||||
zod_1.default.literal("two-sierra"),
|
||||
zod_1.default.literal("sierra-lite"),
|
||||
])
|
||||
.optional(),
|
||||
});
|
||||
exports.methods = {
|
||||
/**
|
||||
* Image color number reduction.
|
||||
*/
|
||||
quantize(image, options) {
|
||||
const { colors, colorDistanceFormula, paletteQuantization, imageQuantization, } = QuantizeOptionsSchema.parse(options);
|
||||
const inPointContainer = image_q_1.utils.PointContainer.fromUint8Array(image.bitmap.data, image.bitmap.width, image.bitmap.height);
|
||||
const palette = (0, image_q_1.buildPaletteSync)([inPointContainer], {
|
||||
colors,
|
||||
colorDistanceFormula,
|
||||
paletteQuantization,
|
||||
});
|
||||
const outPointContainer = (0, image_q_1.applyPaletteSync)(inPointContainer, palette, {
|
||||
colorDistanceFormula,
|
||||
imageQuantization,
|
||||
});
|
||||
image.bitmap.data = Buffer.from(outPointContainer.toUint8Array());
|
||||
return image;
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AACA,qCAAoE;AACpE,8CAAoB;AAEpB,MAAM,qBAAqB,GAAG,aAAC,CAAC,MAAM,CAAC;IACrC,MAAM,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,oBAAoB,EAAE,aAAC;SACpB,KAAK,CAAC;QACL,aAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC;QAC3B,aAAC,CAAC,OAAO,CAAC,oBAAoB,CAAC;QAC/B,aAAC,CAAC,OAAO,CAAC,WAAW,CAAC;QACtB,aAAC,CAAC,OAAO,CAAC,cAAc,CAAC;QACzB,aAAC,CAAC,OAAO,CAAC,WAAW,CAAC;QACtB,aAAC,CAAC,OAAO,CAAC,yBAAyB,CAAC;QACpC,aAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC;QAC5B,aAAC,CAAC,OAAO,CAAC,WAAW,CAAC;QACtB,aAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC;QAC5B,aAAC,CAAC,OAAO,CAAC,mBAAmB,CAAC;QAC9B,aAAC,CAAC,OAAO,CAAC,UAAU,CAAC;KACtB,CAAC;SACD,QAA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gB,EAAC,CAAC,gBAAgB,CAAC,EAAE;YACnD,MAAM;YACN,oBAAoB;YACpB,mBAAmB;SACpB,CAAC,CAAC;QACH,MAAM,iBAAiB,GAAG,IAAA,0BAAgB,EAAC,gBAAgB,EAAE,OAAO,EAAE;YACpE,oBAAoB;YACpB,iBAAiB;SAClB,CAAC,CAAC;QAEH,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,YAAY,EAAE,CAAC,CAAC;QAElE,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC"}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "commonjs"
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import { JimpClass } from "@jimp/types";
|
||||
import z from "zod";
|
||||
declare const QuantizeOptionsSchema: z.ZodObject<{
|
||||
colors: z.ZodOptional<z.ZodNumber>;
|
||||
colorDistanceFormula: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"cie94-textiles">, z.ZodLiteral<"cie94-graphic-arts">, z.ZodLiteral<"ciede2000">, z.ZodLiteral<"color-metric">, z.ZodLiteral<"euclidean">, z.ZodLiteral<"euclidean-bt709-noalpha">, z.ZodLiteral<"euclidean-bt709">, z.ZodLiteral<"manhattan">, z.ZodLiteral<"manhattan-bt709">, z.ZodLiteral<"manhattan-nommyde">, z.ZodLiteral<"pngquant">]>>;
|
||||
paletteQuantization: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"neuquant">, z.ZodLiteral<"neuquant-float">, z.ZodLiteral<"rgbquant">, z.ZodLiteral<"wuquant">]>>;
|
||||
imageQuantization: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"nearest">, z.ZodLiteral<"riemersma">, z.ZodLiteral<"floyd-steinberg">, z.ZodLiteral<"false-floyd-steinberg">, z.ZodLiteral<"stucki">, z.ZodLiteral<"atkinson">, z.ZodLiteral<"jarvis">, z.ZodLiteral<"burkes">, z.ZodLiteral<"sierra">, z.ZodLiteral<"two-sierra">, z.ZodLiteral<"sierra-lite">]>>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
colors?: number | undefined;
|
||||
colorDistanceFormula?: "cie94-textiles" | "cie94-graphic-arts" | "ciede2000" | "color-metric" | "euclidean" | "euclidean-bt709-noalpha" | "euclidean-bt709" | "manhattan" | "manhattan-bt709" | "manhattan-nommyde" | "pngquant" | undefined;
|
||||
paletteQuantization?: "neuquant" | "neuquant-float" | "rgbquant" | "wuquant" | undefined;
|
||||
imageQuantization?: "nearest" | "riemersma" | "floyd-steinberg" | "false-floyd-steinberg" | "stucki" | "atkinson" | "jarvis" | "burkes" | "sierra" | "two-sierra" | "sierra-lite" | undefined;
|
||||
}, {
|
||||
colors?: number | undefined;
|
||||
colorDistanceFormula?: "cie94-textiles" | "cie94-graphic-arts" | "ciede2000" | "color-metric" | "euclidean" | "euclidean-bt709-noalpha" | "euclidean-bt709" | "manhattan" | "manhattan-bt709" | "manhattan-nommyde" | "pngquant" | undefined;
|
||||
paletteQuantization?: "neuquant" | "neuquant-float" | "rgbquant" | "wuquant" | undefined;
|
||||
imageQuantization?: "nearest" | "riemersma" | "floyd-steinberg" | "false-floyd-steinberg" | "stucki" | "atkinson" | "jarvis" | "burkes" | "sierra" | "two-sierra" | "sierra-lite" | undefined;
|
||||
}>;
|
||||
export type QuantizeOptions = z.infer<typeof QuantizeOptionsSchema>;
|
||||
export declare const methods: {
|
||||
/**
|
||||
* Image color number reduction.
|
||||
*/
|
||||
quantize<I extends JimpClass>(image: I, options: QuantizeOptions): 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,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,QAAA,MAAM,qBAAqB;;;;;;;;;;;;;;;EAwCzB,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE,eAAO,MAAM,OAAO;IAClB;;OAEG;aACM,CAAC,SAAS,SAAS,SAAS,CAAC,WAAW,eAAe;CA4BjE,CAAC"}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
import { applyPaletteSync, buildPaletteSync, utils } from "image-q";
|
||||
import z from "zod";
|
||||
const QuantizeOptionsSchema = z.object({
|
||||
colors: z.number().optional(),
|
||||
colorDistanceFormula: z
|
||||
.union([
|
||||
z.literal("cie94-textiles"),
|
||||
z.literal("cie94-graphic-arts"),
|
||||
z.literal("ciede2000"),
|
||||
z.literal("color-metric"),
|
||||
z.literal("euclidean"),
|
||||
z.literal("euclidean-bt709-noalpha"),
|
||||
z.literal("euclidean-bt709"),
|
||||
z.literal("manhattan"),
|
||||
z.literal("manhattan-bt709"),
|
||||
z.literal("manhattan-nommyde"),
|
||||
z.literal("pngquant"),
|
||||
])
|
||||
.optional(),
|
||||
paletteQuantization: z
|
||||
.union([
|
||||
z.literal("neuquant"),
|
||||
z.literal("neuquant-float"),
|
||||
z.literal("rgbquant"),
|
||||
z.literal("wuquant"),
|
||||
])
|
||||
.optional(),
|
||||
imageQuantization: z
|
||||
.union([
|
||||
z.literal("nearest"),
|
||||
z.literal("riemersma"),
|
||||
z.literal("floyd-steinberg"),
|
||||
z.literal("false-floyd-steinberg"),
|
||||
z.literal("stucki"),
|
||||
z.literal("atkinson"),
|
||||
z.literal("jarvis"),
|
||||
z.literal("burkes"),
|
||||
z.literal("sierra"),
|
||||
z.literal("two-sierra"),
|
||||
z.literal("sierra-lite"),
|
||||
])
|
||||
.optional(),
|
||||
});
|
||||
export const methods = {
|
||||
/**
|
||||
* Image color number reduction.
|
||||
*/
|
||||
quantize(image, options) {
|
||||
const { colors, colorDistanceFormula, paletteQuantization, imageQuantization, } = QuantizeOptionsSchema.parse(options);
|
||||
const inPointContainer = utils.PointContainer.fromUint8Array(image.bitmap.data, image.bitmap.width, image.bitmap.height);
|
||||
const palette = buildPaletteSync([inPointContainer], {
|
||||
colors,
|
||||
colorDistanceFormula,
|
||||
paletteQuantization,
|
||||
});
|
||||
const outPointContainer = applyPaletteSync(inPointContainer, palette, {
|
||||
colorDistanceFormula,
|
||||
imageQuantization,
|
||||
});
|
||||
image.bitmap.data = Buffer.from(outPointContainer.toUint8Array());
|
||||
return image;
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACpE,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,oBAAoB,EAAE,CAAC;SACpB,KAAK,CAAC;QACL,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC;QAC3B,CAAC,CAAC,OAAO,CAAC,oBAAoB,CAAC;QAC/B,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC;QACtB,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC;QACzB,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC;QACtB,CAAC,CAAC,OAAO,CAAC,yBAAyB,CAAC;QACpC,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC;QAC5B,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC;QACtB,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC;QAC5B,CAAC,CAAC,OAAO,CAAC,mBAAmB,CAAC;QAC9B,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;KACtB,CAAC;SACD,QAAQ,EAAE;IACb,mBAAmB,EAAE,C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CAAC,EAAE;YACnD,MAAM;YACN,oBAAoB;YACpB,mBAAmB;SACpB,CAAC,CAAC;QACH,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,gBAAgB,EAAE,OAAO,EAAE;YACpE,oBAAoB;YACpB,iBAAiB;SAClB,CAAC,CAAC;QAEH,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,YAAY,EAAE,CAAC,CAAC;QAElE,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC"}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "module"
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import shared from "@jimp/config-eslint/base.js";
|
||||
export default [...shared];
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"name": "@jimp/plugin-quantize",
|
||||
"version": "1.6.0",
|
||||
"repository": "jimp-dev/jimp",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"test": "vitest",
|
||||
"build": "tshy",
|
||||
"dev": "tshy --watch",
|
||||
"clean": "rm -rf node_modules .tshy .tshy-build dist .turbo"
|
||||
},
|
||||
"author": "Andrew Lisowski <lisowski54@gmail.com>",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@jimp/config-eslint": "1.6.0",
|
||||
"@jimp/config-typescript": "1.6.0",
|
||||
"@jimp/core": "1.6.0",
|
||||
"@jimp/js-jpeg": "1.6.0",
|
||||
"@jimp/js-png": "1.6.0",
|
||||
"@jimp/test-utils": "1.6.0",
|
||||
"@jimp/types": "1.6.0",
|
||||
"eslint": "^9.9.1",
|
||||
"tshy": "^3.0.2",
|
||||
"typescript": "^5.5.4",
|
||||
"vite-plugin-node-polyfills": "^0.22.0",
|
||||
"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,
|
||||
"dependencies": {
|
||||
"image-q": "^4.0.0",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"module": "./dist/esm/index.js",
|
||||
"gitHead": "c88abe6046dccbdb6e4f5f00c3dd403c81d83515"
|
||||
}
|
||||
Generated
Vendored
BIN
Binary file not shown.
|
After Width: | Height: | Size: 63 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 69 KiB |
+23
@@ -0,0 +1,23 @@
|
||||
import { expect, test, describe } from "vitest";
|
||||
import "@jimp/test-utils";
|
||||
import "@jimp/test-utils/image-snapshot";
|
||||
|
||||
import png from "@jimp/js-png";
|
||||
import { createJimp } from "@jimp/core";
|
||||
|
||||
import { methods as quantize } from "./index.js";
|
||||
|
||||
const jimp = createJimp({ formats: [png], plugins: [quantize] });
|
||||
|
||||
describe("Quantize", () => {
|
||||
test("defines default threshold for lighter backgrounds", async () => {
|
||||
const testImage = await jimp.read(__dirname + "/images/colorful.png");
|
||||
const output = await testImage
|
||||
.quantize({
|
||||
colors: 8,
|
||||
})
|
||||
.getBuffer("image/png");
|
||||
|
||||
expect(output).toMatchImageSnapshot();
|
||||
});
|
||||
});
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
import { JimpClass } from "@jimp/types";
|
||||
import { applyPaletteSync, buildPaletteSync, utils } from "image-q";
|
||||
import z from "zod";
|
||||
|
||||
const QuantizeOptionsSchema = z.object({
|
||||
colors: z.number().optional(),
|
||||
colorDistanceFormula: z
|
||||
.union([
|
||||
z.literal("cie94-textiles"),
|
||||
z.literal("cie94-graphic-arts"),
|
||||
z.literal("ciede2000"),
|
||||
z.literal("color-metric"),
|
||||
z.literal("euclidean"),
|
||||
z.literal("euclidean-bt709-noalpha"),
|
||||
z.literal("euclidean-bt709"),
|
||||
z.literal("manhattan"),
|
||||
z.literal("manhattan-bt709"),
|
||||
z.literal("manhattan-nommyde"),
|
||||
z.literal("pngquant"),
|
||||
])
|
||||
.optional(),
|
||||
paletteQuantization: z
|
||||
.union([
|
||||
z.literal("neuquant"),
|
||||
z.literal("neuquant-float"),
|
||||
z.literal("rgbquant"),
|
||||
z.literal("wuquant"),
|
||||
])
|
||||
.optional(),
|
||||
imageQuantization: z
|
||||
.union([
|
||||
z.literal("nearest"),
|
||||
z.literal("riemersma"),
|
||||
z.literal("floyd-steinberg"),
|
||||
z.literal("false-floyd-steinberg"),
|
||||
z.literal("stucki"),
|
||||
z.literal("atkinson"),
|
||||
z.literal("jarvis"),
|
||||
z.literal("burkes"),
|
||||
z.literal("sierra"),
|
||||
z.literal("two-sierra"),
|
||||
z.literal("sierra-lite"),
|
||||
])
|
||||
.optional(),
|
||||
});
|
||||
|
||||
export type QuantizeOptions = z.infer<typeof QuantizeOptionsSchema>;
|
||||
|
||||
export const methods = {
|
||||
/**
|
||||
* Image color number reduction.
|
||||
*/
|
||||
quantize<I extends JimpClass>(image: I, options: QuantizeOptions) {
|
||||
const {
|
||||
colors,
|
||||
colorDistanceFormula,
|
||||
paletteQuantization,
|
||||
imageQuantization,
|
||||
} = QuantizeOptionsSchema.parse(options);
|
||||
|
||||
const inPointContainer = utils.PointContainer.fromUint8Array(
|
||||
image.bitmap.data,
|
||||
image.bitmap.width,
|
||||
image.bitmap.height
|
||||
);
|
||||
|
||||
const palette = buildPaletteSync([inPointContainer], {
|
||||
colors,
|
||||
colorDistanceFormula,
|
||||
paletteQuantization,
|
||||
});
|
||||
const outPointContainer = applyPaletteSync(inPointContainer, palette, {
|
||||
colorDistanceFormula,
|
||||
imageQuantization,
|
||||
});
|
||||
|
||||
image.bitmap.data = Buffer.from(outPointContainer.toUint8Array());
|
||||
|
||||
return image;
|
||||
},
|
||||
};
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "@jimp/config-typescript/base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user