@jimp/utils
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -0,1 +1,17 @@ | ||
# v1.4.0 (Sat Sep 07 2024) | ||
#### 🐛 Bug Fix | ||
- Bind callback to image instance [#1335](https://github.com/jimp-dev/jimp/pull/1335) ([@hipstersmoothie](https://github.com/hipstersmoothie)) | ||
#### ⚠️ 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) | ||
@@ -2,0 +18,0 @@ |
@@ -62,6 +62,8 @@ "use strict"; | ||
h = Math.round(h); | ||
const bound = cb.bind(image); | ||
for (let _y = y; _y < y + h; _y++) { | ||
for (let _x = x; _x < x + w; _x++) { | ||
const idx = (image.bitmap.width * _y + _x) << 2; | ||
cb(_x, _y, idx); | ||
// Bind the images so this.bitmap works | ||
bound(_x, _y, idx); | ||
} | ||
@@ -68,0 +70,0 @@ } |
@@ -49,6 +49,8 @@ import tinyColor from "tinycolor2"; | ||
h = Math.round(h); | ||
const bound = cb.bind(image); | ||
for (let _y = y; _y < y + h; _y++) { | ||
for (let _x = x; _x < x + w; _x++) { | ||
const idx = (image.bitmap.width * _y + _x) << 2; | ||
cb(_x, _y, idx); | ||
// Bind the images so this.bitmap works | ||
bound(_x, _y, idx); | ||
} | ||
@@ -55,0 +57,0 @@ } |
{ | ||
"name": "@jimp/utils", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"repository": "jimp-dev/jimp", | ||
@@ -18,8 +18,8 @@ "engines": { | ||
"dependencies": { | ||
"@jimp/types": "1.3.0", | ||
"@jimp/types": "1.4.0", | ||
"tinycolor2": "^1.6.0" | ||
}, | ||
"devDependencies": { | ||
"@jimp/config-eslint": "1.3.0", | ||
"@jimp/config-typescript": "1.3.0", | ||
"@jimp/config-eslint": "1.4.0", | ||
"@jimp/config-typescript": "1.4.0", | ||
"@types/node": "^18.19.48", | ||
@@ -30,2 +30,3 @@ "@types/tinycolor2": "^1.4.6", | ||
"typescript": "^5.5.4", | ||
"vite-plugin-node-polyfills": "^0.22.0", | ||
"vitest": "^2.0.5" | ||
@@ -63,3 +64,3 @@ }, | ||
"module": "./dist/esm/index.js", | ||
"gitHead": "fb52a357ac774d6314a319fe43f8d0d022ac214c" | ||
"gitHead": "c1b91e9007f17d0702894bd9bfab8215cff764f9" | ||
} |
import { expect, test, describe } from "vitest"; | ||
import { colorDiff } from "./index.js"; | ||
import { colorDiff, scan } from "./index.js"; | ||
import { JimpClass } from "@jimp/types"; | ||
@@ -11,19 +12,19 @@ // Convert [0..1] float to a percent value with only one decimal. | ||
expect(colorDiff({ r: 255, g: 0, b: 0 }, { r: 255, g: 0, b: 0 })).toEqual( | ||
0, | ||
0 | ||
); | ||
expect( | ||
pct(colorDiff({ r: 255, g: 0, b: 0 }, { r: 0, g: 0, b: 0 })), | ||
pct(colorDiff({ r: 255, g: 0, b: 0 }, { r: 0, g: 0, b: 0 })) | ||
).toEqual(33.3); | ||
expect( | ||
pct(colorDiff({ r: 255, g: 0, b: 0 }, { r: 0, g: 255, b: 0 })), | ||
pct(colorDiff({ r: 255, g: 0, b: 0 }, { r: 0, g: 255, b: 0 })) | ||
).toEqual(66.6); | ||
expect(colorDiff({ r: 255, g: 0, b: 0 }, { r: 0, g: 255, b: 255 })).toEqual( | ||
1, | ||
1 | ||
); | ||
expect(colorDiff({ r: 0, g: 0, b: 0 }, { r: 255, g: 255, b: 255 })).toEqual( | ||
1, | ||
1 | ||
); | ||
@@ -34,7 +35,7 @@ }); | ||
expect( | ||
colorDiff({ r: 255, g: 0, b: 0, a: 0 }, { r: 255, g: 0, b: 0, a: 0 }), | ||
colorDiff({ r: 255, g: 0, b: 0, a: 0 }, { r: 255, g: 0, b: 0, a: 0 }) | ||
).toEqual(0); | ||
expect( | ||
colorDiff({ r: 0, g: 0, b: 0, a: 0 }, { r: 255, g: 255, b: 255, a: 0 }), | ||
colorDiff({ r: 0, g: 0, b: 0, a: 0 }, { r: 255, g: 255, b: 255, a: 0 }) | ||
).toEqual(1); | ||
@@ -48,11 +49,37 @@ }); | ||
{ r: 255, g: 0, b: 0, a: 100 }, | ||
{ r: 255, g: 0, b: 0, a: 150 }, | ||
), | ||
), | ||
{ r: 255, g: 0, b: 0, a: 150 } | ||
) | ||
) | ||
).toEqual(3.8); | ||
expect( | ||
colorDiff({ r: 0, g: 0, b: 0, a: 0 }, { r: 255, g: 255, b: 255, a: 255 }), | ||
colorDiff({ r: 0, g: 0, b: 0, a: 0 }, { r: 255, g: 255, b: 255, a: 255 }) | ||
).toEqual(1); | ||
}); | ||
}); | ||
describe("scan", () => { | ||
class TestImage { | ||
public bitmap = { | ||
height: 3, | ||
width: 3, | ||
data: Buffer.from([ | ||
0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, | ||
0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, | ||
]), | ||
}; | ||
} | ||
const img = new TestImage() as JimpClass; | ||
test("scan", () => { | ||
let count = 0; | ||
scan(img, function (_, __, idx) { | ||
count++; | ||
expect(img.bitmap.data[idx]).toBe(this.bitmap.data[idx]); | ||
}); | ||
expect(count).toBe(img.bitmap.width * img.bitmap.height); | ||
}); | ||
}); |
@@ -18,3 +18,3 @@ import { RGBAColor, JimpClass, Bitmap, RGBColor } from "@jimp/types"; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
f: (this: I, x: number, y: number, idx: number) => any, | ||
f: (this: I, x: number, y: number, idx: number) => any | ||
): I; | ||
@@ -28,3 +28,3 @@ export function scan<I extends { bitmap: Bitmap }>( | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
cb: (x: number, y: number, idx: number) => any, | ||
cb: (x: number, y: number, idx: number) => any | ||
): I; | ||
@@ -39,3 +39,3 @@ export function scan<I extends { bitmap: Bitmap }>( | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
cbArg?: (x: number, y: number, idx: number) => any, | ||
cbArg?: (x: number, y: number, idx: number) => any | ||
): I { | ||
@@ -73,6 +73,9 @@ let x: number; | ||
const bound = cb.bind(image); | ||
for (let _y = y; _y < y + h; _y++) { | ||
for (let _x = x; _x < x + w; _x++) { | ||
const idx = (image.bitmap.width * _y + _x) << 2; | ||
cb(_x, _y, idx); | ||
// Bind the images so this.bitmap works | ||
bound(_x, _y, idx); | ||
} | ||
@@ -89,3 +92,3 @@ } | ||
w: number, | ||
h: number, | ||
h: number | ||
) { | ||
@@ -133,3 +136,3 @@ // round input | ||
(i - rgba.r * Math.pow(256, 3) - rgba.g * Math.pow(256, 2)) / | ||
Math.pow(256, 1), | ||
Math.pow(256, 1) | ||
); | ||
@@ -141,3 +144,3 @@ rgba.a = Math.floor( | ||
rgba.b * Math.pow(256, 1)) / | ||
Math.pow(256, 0), | ||
Math.pow(256, 0) | ||
); | ||
@@ -226,3 +229,3 @@ | ||
rgba1: RGBAColor | RGBColor, | ||
rgba2: RGBAColor | RGBColor, | ||
rgba2: RGBAColor | RGBColor | ||
) { | ||
@@ -229,0 +232,0 @@ const sq = (n: number) => Math.pow(n, 2); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48079
960
9
+ Added@jimp/types@1.4.0(transitive)
- Removed@jimp/types@1.3.0(transitive)
Updated@jimp/types@1.4.0