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/js-tiff@1.5.0 build /Users/andrewlisowski/Documents/jimp/plugins/js-tiff
> tshy
+5
View File
@@ -0,0 +1,5 @@

> @jimp/js-tiff@1.1.2 lint /Users/andrewlisowski/Documents/jimp/plugins/js-tiff
> eslint .
+2
View File
@@ -0,0 +1,2 @@

+23
View File
@@ -0,0 +1,23 @@

> @jimp/js-tiff@1.1.2 test /Users/andrewlisowski/Documents/jimp/plugins/js-tiff
> vitest "--watch=false"
 RUN  v2.0.5 /Users/andrewlisowski/Documents/jimp/plugins/js-tiff
[?25l · src/index.test.ts (2)
· TIFF (2)
· load TIFF
· export TIFF
[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l[?25l ✓ src/index.test.ts (2)
✓ TIFF (2)
✓ load TIFF
✓ export TIFF
 Test Files  1 passed (1)
 Tests  2 passed (2)
 Start at  01:33:35
 Duration  2.59s (transform 416ms, setup 0ms, collect 612ms, tests 187ms, environment 0ms, prepare 254ms)
[?25h[?25h
+51
View File
@@ -0,0 +1,51 @@
# 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))
#### 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.
+6
View File
@@ -0,0 +1,6 @@
<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/tiff</h1>
<p>Default Jimp tiff encoder/decoder.</p>
</div>
+7
View File
@@ -0,0 +1,7 @@
import { Bitmap } from "@jimp/types";
export default function tiff(): {
mime: "image/tiff";
encode: (bitmap: Bitmap) => Buffer;
decode: (data: Buffer) => Bitmap;
};
//# sourceMappingURL=index.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAU,MAAM,aAAa,CAAC;AAkB7C,MAAM,CAAC,OAAO,UAAU,IAAI;;;8BAiCjB,MAAM;EAGhB"}
+51
View File
@@ -0,0 +1,51 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = tiff;
const utif2_1 = __importDefault(require("utif2"));
function getDimensionValue(dimension) {
if (typeof dimension === "number") {
return dimension;
}
if (dimension instanceof Uint8Array) {
return dimension[0];
}
if (typeof dimension[0] === "string") {
return parseInt(dimension[0]);
}
return dimension[0];
}
function tiff() {
return {
mime: "image/tiff",
encode: (bitmap) => {
const tiff = utif2_1.default.encodeImage(bitmap.data, bitmap.width, bitmap.height);
return Buffer.from(tiff);
},
decode: (data) => {
const ifds = utif2_1.default.decode(data);
const page = ifds[0];
if (!page) {
throw new Error("No page found in TIFF");
}
if (!page.t256) {
throw new Error("No image width found in TIFF");
}
if (!page.t257) {
throw new Error("No image height found in TIFF");
}
ifds.forEach((ifd) => {
utif2_1.default.decodeImage(data, ifd);
});
const rgba = utif2_1.default.toRGBA8(page);
return {
data: Buffer.from(rgba),
width: getDimensionValue(page.t256),
height: getDimensionValue(page.t257),
};
},
};
}
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;AAmBA,uBAoCC;AAvDD,kDAAsC;AAGtC,SAAS,iBAAiB,CAAC,SAAwC;IACjE,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QAClC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,SAAS,YAAY,UAAU,EAAE,CAAC;QACpC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC;IACtB,CAAC;IAED,IAAI,OAAO,SAAS,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC;AACtB,CAAC;AAED,SAAwB,IAAI;IAC1B,OAAO;QACL,IAAI,EAAE,YAAY;QAClB,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;YACjB,MAAM,IAAI,GAAG,eAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;YACxE,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC;QACD,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YACf,MAAM,IAAI,GAAG,eAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YAErB,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAC3C,CAAC;YAED,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;gBACf,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;YAClD,CAAC;YAED,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;gBACf,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;YACnD,CAAC;YAED,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;gBACnB,eAAI,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;YAC9B,CAAC,CAAC,CAAC;YAEH,MAAM,IAAI,GAAG,eAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAEhC,OAAO;gBACL,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;gBACvB,KAAK,EAAE,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC;gBACnC,MAAM,EAAE,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC;aAC3B,CAAC;QACd,CAAC;KAC6B,CAAC;AACnC,CAAC"}
+3
View File
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
+7
View File
@@ -0,0 +1,7 @@
import { Bitmap } from "@jimp/types";
export default function tiff(): {
mime: "image/tiff";
encode: (bitmap: Bitmap) => Buffer;
decode: (data: Buffer) => Bitmap;
};
//# sourceMappingURL=index.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAU,MAAM,aAAa,CAAC;AAkB7C,MAAM,CAAC,OAAO,UAAU,IAAI;;;8BAiCjB,MAAM;EAGhB"}
+45
View File
@@ -0,0 +1,45 @@
import utif from "utif2";
function getDimensionValue(dimension) {
if (typeof dimension === "number") {
return dimension;
}
if (dimension instanceof Uint8Array) {
return dimension[0];
}
if (typeof dimension[0] === "string") {
return parseInt(dimension[0]);
}
return dimension[0];
}
export default function tiff() {
return {
mime: "image/tiff",
encode: (bitmap) => {
const tiff = utif.encodeImage(bitmap.data, bitmap.width, bitmap.height);
return Buffer.from(tiff);
},
decode: (data) => {
const ifds = utif.decode(data);
const page = ifds[0];
if (!page) {
throw new Error("No page found in TIFF");
}
if (!page.t256) {
throw new Error("No image width found in TIFF");
}
if (!page.t257) {
throw new Error("No image height found in TIFF");
}
ifds.forEach((ifd) => {
utif.decodeImage(data, ifd);
});
const rgba = utif.toRGBA8(page);
return {
data: Buffer.from(rgba),
width: getDimensionValue(page.t256),
height: getDimensionValue(page.t257),
};
},
};
}
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAiB,MAAM,OAAO,CAAC;AAGtC,SAAS,iBAAiB,CAAC,SAAwC;IACjE,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QAClC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,SAAS,YAAY,UAAU,EAAE,CAAC;QACpC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC;IACtB,CAAC;IAED,IAAI,OAAO,SAAS,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC;AACtB,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,IAAI;IAC1B,OAAO;QACL,IAAI,EAAE,YAAY;QAClB,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;YACjB,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;YACxE,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC;QACD,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YACf,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YAErB,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAC3C,CAAC;YAED,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;gBACf,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;YAClD,CAAC;YAED,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;gBACf,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;YACnD,CAAC;YAED,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;gBACnB,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;YAC9B,CAAC,CAAC,CAAC;YAEH,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAEhC,OAAO;gBACL,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;gBACvB,KAAK,EAAE,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC;gBACnC,MAAM,EAAE,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC;aAC3B,CAAC;QACd,CAAC;KAC6B,CAAC;AACnC,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];
+67
View File
@@ -0,0 +1,67 @@
{
"name": "@jimp/js-tiff",
"version": "1.6.0",
"repository": "jimp-dev/jimp",
"engines": {
"node": ">=18"
},
"scripts": {
"lint": "eslint .",
"test": "vitest",
"test:browser": "vitest --config vitest.config.browser.mjs",
"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/config-vitest": "1.6.0",
"@jimp/test-utils": "1.6.0",
"@types/node": "^18.19.48",
"@vitest/browser": "^2.0.5",
"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",
"dependencies": {
"@jimp/core": "1.6.0",
"@jimp/types": "1.6.0",
"utif2": "^4.1.0"
},
"publishConfig": {
"access": "public"
},
"sideEffects": false,
"module": "./dist/esm/index.js",
"gitHead": "c88abe6046dccbdb6e4f5f00c3dd403c81d83515"
}
+32
View File
@@ -0,0 +1,32 @@
import { expect, test, describe } from "vitest";
import { createJimp } from "@jimp/core";
import { getTestImagePath } from "@jimp/test-utils";
import tiff from "./index.js";
const jimp = createJimp({ formats: [tiff] });
describe("TIFF", () => {
test("load TIFF", async () => {
const image = await jimp.read(getTestImagePath("rgb.tiff"));
expect(image.getPixelColor(10, 10)).toBe(0xa4988bff);
expect(image.getPixelColor(220, 190)).toBe(0xe0d7ddff);
expect(image.getPixelColor(350, 130)).toBe(0x565433ff);
});
test("export TIFF", async () => {
const image = jimp.fromBitmap({
width: 3,
height: 3,
data: [
0xff0000ff, 0xff0080ff, 0xff00ffff, 0xff0080ff, 0xff00ffff, 0x8000ffff,
0xff00ffff, 0x8000ffff, 0x0000ffff,
],
});
const buffer = await image.getBuffer("image/tiff");
// eslint-disable-next-line no-control-regex
expect(buffer.toString()).toMatch(/^MM\u0000*\u0000/);
});
});
+56
View File
@@ -0,0 +1,56 @@
import utif, { TiffTag } from "utif2";
import { Bitmap, Format } from "@jimp/types";
function getDimensionValue(dimension: number | Uint8Array | TiffTag) {
if (typeof dimension === "number") {
return dimension;
}
if (dimension instanceof Uint8Array) {
return dimension[0];
}
if (typeof dimension[0] === "string") {
return parseInt(dimension[0]);
}
return dimension[0];
}
export default function tiff() {
return {
mime: "image/tiff",
encode: (bitmap) => {
const tiff = utif.encodeImage(bitmap.data, bitmap.width, bitmap.height);
return Buffer.from(tiff);
},
decode: (data) => {
const ifds = utif.decode(data);
const page = ifds[0];
if (!page) {
throw new Error("No page found in TIFF");
}
if (!page.t256) {
throw new Error("No image width found in TIFF");
}
if (!page.t257) {
throw new Error("No image height found in TIFF");
}
ifds.forEach((ifd) => {
utif.decodeImage(data, ifd);
});
const rgba = utif.toRGBA8(page);
return {
data: Buffer.from(rgba),
width: getDimensionValue(page.t256),
height: getDimensionValue(page.t257),
} as Bitmap;
},
} satisfies Format<"image/tiff">;
}
+6
View File
@@ -0,0 +1,6 @@
{
"extends": "@jimp/config-typescript/base.json",
"compilerOptions": {
"outDir": "dist"
}
}
+3
View File
@@ -0,0 +1,3 @@
import config from "@jimp/config-vitest/browser";
export default config;