From dcfd6abeabb4658dcda7e37f839b3dac2753dd15 Mon Sep 17 00:00:00 2001 From: Andrew Lisowski Date: Sun, 1 Sep 2024 21:09:16 -0700 Subject: [PATCH 1/2] Make brightness function behave like other implementations --- ...box-blur-matrix-using-convolute-1-snap.png | Bin 0 -> 6551 bytes .../src/__snapshots__/index.test.ts.snap | 56 ++++++++++++++++++ .../plugin-color/src/birghtness.node.test.ts | 18 ++++++ plugins/plugin-color/src/index.test.ts | 24 ++++++++ plugins/plugin-color/src/index.ts | 20 ++----- 5 files changed, 102 insertions(+), 16 deletions(-) create mode 100644 plugins/plugin-color/src/__image_snapshots__/birghtness-node-test-ts-src-birghtness-node-test-ts-brightness-3-x-3-box-blur-matrix-using-convolute-1-snap.png create mode 100644 plugins/plugin-color/src/birghtness.node.test.ts diff --git a/plugins/plugin-color/src/__image_snapshots__/birghtness-node-test-ts-src-birghtness-node-test-ts-brightness-3-x-3-box-blur-matrix-using-convolute-1-snap.png b/plugins/plugin-color/src/__image_snapshots__/birghtness-node-test-ts-src-birghtness-node-test-ts-brightness-3-x-3-box-blur-matrix-using-convolute-1-snap.png new file mode 100644 index 0000000000000000000000000000000000000000..01defca2e3c306a58ec5877c6e78b2c0e17b0a9e GIT binary patch literal 6551 zcmW-mdpuMBAICHIS!{E^GnR#zYq`%h*ODnp7k9Fda?hO%bD1GANo@1YDup6aOeL30 zO(}O>6p~!$e*3N8=kYk_{Pp>K&gbzs@7L?~e4i}bNxOqUIpBc<2M#*eV^49PsDGD` z0Qdgja@fRy1G1hDSZmkoJfv45l#2mA$Zs)Bg_D^+7YE@48L*2U81-BNjC(GfdLD(t z0!QqQOdMvO!UkV)%`UOqJpAKV)0ZFR6IX&;-Lz<@a%IrDy>f$5=Sl)(GJ5=vnV6Vt zu8k_|?~X6yd-mJZx^#7PrVx576AR7w)ga~O#hy#-SC?EF5J*0VKVf<9sLAqzmG)@P z_imWTuCxz^b{R#H=1W-D4cA++6B;DCKEovyGZz%Wj2|u|{luilJjoHk^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Cri|N4`a()~_1iR5p)$_yuR$*1RP96}xa>)T zmr~hwA}05AlB)-mUUrJIz8RnJ;dYYj3D3k2Vy#PVSKa8H<}@m69&T8#z>6_5 z_K3(caQ2)`I`QpfO_y!RYxP5VIepDP?P9h&hLdY@gd;)xOdVC(clsPXQcmr5isTT{ zcq%_1TmaV2!mBF8 zfTZnTPZ7yZBWM_`7YX~NOVcF1z=z_xW`*&e7zD T< should be able to brighten 1`] = ` +Visualization: + +6666666666 +6666666666 +6666666666 +6666666666 +6666666666 +6666666666 +6666666666 +6666666666 +6666666666 +6666666666 + +Data: + +FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ +FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ +FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ +FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ +FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ +FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ +FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ +FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ +FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ +FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ FF-00-00⁸⁸ +`; + +exports[`brightness > should be able to darken 1`] = ` +Visualization: + +CCCCCCCCCC +CCCCCCCCCC +CCCCCCCCCC +CCCCCCCCCC +CCCCCCCCCC +CCCCCCCCCC +CCCCCCCCCC +CCCCCCCCCC +CCCCCCCCCC +CCCCCCCCCC + +Data: + +22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ +22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ +22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ +22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ +22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ +22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ +22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ +22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ +22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ +22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ 22-00-00⁸⁸ +`; + exports[`canvas color transformation > brighten 1`] = ` Visualization: diff --git a/plugins/plugin-color/src/birghtness.node.test.ts b/plugins/plugin-color/src/birghtness.node.test.ts new file mode 100644 index 00000000..08c0d7a3 --- /dev/null +++ b/plugins/plugin-color/src/birghtness.node.test.ts @@ -0,0 +1,18 @@ +import { expect, test, describe } from "vitest"; +import png from "@jimp/js-png"; +import jpeg from "@jimp/js-jpeg"; +import { createJimp } from "@jimp/core"; +import "@jimp/test-utils/image-snapshot"; + +import { methods } from "./index.js"; + +const jimp = createJimp({ formats: [png, jpeg], plugins: [methods] }); + +describe("Brightness", function () { + test("3x3 box blur matrix using convolute", async () => { + const image = await jimp.read(__dirname + "/images/tiles.jpg"); + const output = await image.brightness(2).getBuffer("image/png"); + + expect(output).toMatchImageSnapshot(); + }); +}); diff --git a/plugins/plugin-color/src/index.test.ts b/plugins/plugin-color/src/index.test.ts index 70ea200c..2552beae 100644 --- a/plugins/plugin-color/src/index.test.ts +++ b/plugins/plugin-color/src/index.test.ts @@ -37,3 +37,27 @@ describe("canvas color transformation", () => { expect(image.color([{ apply: "hue", params: [150] }])).toMatchSnapshot(); }); }); + +describe("brightness", () => { + test("brightness of 1 should be the same as no change", () => { + const jgd = makeDonutTestImage(0xff000088, 0xff000088, 0xff000088); + const image = jimp.fromBitmap(jgd); + const image2 = jimp.fromBitmap(jgd); + + expect(image.brightness(1).bitmap).toStrictEqual(image2.bitmap); + }); + + test("should be able to brighten", () => { + const jgd = makeDonutTestImage(0xaa000088, 0xaa000088, 0xaa000088); + const image = jimp.fromBitmap(jgd); + + expect(image.brightness(2).bitmap).toMatchSnapshot(); + }); + + test("should be able to darken", () => { + const jgd = makeDonutTestImage(0xaa000088, 0xaa000088, 0xaa000088); + const image = jimp.fromBitmap(jgd); + + expect(image.brightness(0.2).bitmap).toMatchSnapshot(); + }); +}); diff --git a/plugins/plugin-color/src/index.ts b/plugins/plugin-color/src/index.ts index 6ba8ef45..eba72ace 100644 --- a/plugins/plugin-color/src/index.ts +++ b/plugins/plugin-color/src/index.ts @@ -336,7 +336,7 @@ export const methods = { /** * Adjusts the brightness of the image - * @param val the amount to adjust the brightness, a number between -1 and +1 + * @param val the amount to adjust the brightness. * @example * ```ts * import { Jimp } from "jimp"; @@ -351,22 +351,10 @@ export const methods = { throw new Error("val must be numbers"); } - if (val < -1 || val > +1) { - throw new Error("val must be a number between -1 and +1"); - } - image.scan((_, __, idx) => { - if (val < 0.0) { - image.bitmap.data[idx]! *= 1 + val; - image.bitmap.data[idx + 1]! *= 1 + val; - image.bitmap.data[idx + 2]! *= 1 + val; - } else { - image.bitmap.data[idx]! += (255 - image.bitmap.data[idx]!) * val; - image.bitmap.data[idx + 1]! += - (255 - image.bitmap.data[idx + 1]!) * val; - image.bitmap.data[idx + 2]! += - (255 - image.bitmap.data[idx + 2]!) * val; - } + image.bitmap.data[idx]! = limit255(image.bitmap.data[idx]! * val); + image.bitmap.data[idx + 1]! = limit255(image.bitmap.data[idx + 1]! * val); + image.bitmap.data[idx + 2]! = limit255(image.bitmap.data[idx + 2]! * val); }); return image; From 558f7cb2b4c17dd9d1dfe0f2c70312f48f1a6052 Mon Sep 17 00:00:00 2001 From: Andrew Lisowski Date: Sun, 1 Sep 2024 22:15:22 -0700 Subject: [PATCH 2/2] fix test --- .../jimp/src/__snapshots__/callbacks.test.ts.snap | 12 ++++++------ packages/jimp/src/callbacks.test.ts | 2 +- turbo.json | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/jimp/src/__snapshots__/callbacks.test.ts.snap b/packages/jimp/src/__snapshots__/callbacks.test.ts.snap index 5d5df786..4d49dc97 100644 --- a/packages/jimp/src/__snapshots__/callbacks.test.ts.snap +++ b/packages/jimp/src/__snapshots__/callbacks.test.ts.snap @@ -31,15 +31,15 @@ AA-94-3Fᶠ¹ 7E-7E-7Eᶠ¹ 54-69-BFᶠ¹ exports[`Callbacks > with brightness 1`] = ` Visualization: -▫▾4 -2 A -D▦◆ +▴▸▾ +◆▪▰ +▵▹▿ Data: -FF-7F-7Fᶠᶠ 7F-FF-7Fᶠᶠ 7F-7F-FFᶠᶠ -FF-FF-7Fᶠᶠ 7F-FF-FFᶠᶠ FF-7F-FFᶠᶠ -FF-7F-7F⁷ᶠ 7F-FF-7F⁷ᶠ 7F-7F-FF⁷ᶠ +FF-00-00ᶠᶠ 00-FF-00ᶠᶠ 00-00-FFᶠᶠ +FF-FF-00ᶠᶠ 00-FF-FFᶠᶠ FF-00-FFᶠᶠ +FF-00-00⁷ᶠ 00-FF-00⁷ᶠ 00-00-FF⁷ᶠ `; exports[`Callbacks > with composite 1`] = ` diff --git a/packages/jimp/src/callbacks.test.ts b/packages/jimp/src/callbacks.test.ts index 0f4f5c8b..3fb18887 100644 --- a/packages/jimp/src/callbacks.test.ts +++ b/packages/jimp/src/callbacks.test.ts @@ -27,7 +27,7 @@ describe("Callbacks", () => { opacity: { args: [0.5] }, resize: { args: [{ w: 2, h: 2 } as ResizeOptions] }, scale: { args: [0.5] }, - brightness: { args: [0.5] }, + brightness: { args: [1.5] }, contrast: { args: [0.75] }, posterize: { args: [5] }, dither: { args: [] }, diff --git a/turbo.json b/turbo.json index 40137713..7f78cdfe 100644 --- a/turbo.json +++ b/turbo.json @@ -13,10 +13,10 @@ "dependsOn": ["^lint"] }, "test": { - "dependsOn": ["^test"] + "dependsOn": ["^build", "^test"] }, "test:browser": { - "dependsOn": ["^test:browser"] + "dependsOn": ["^build", "^test:browser"] }, "dev": { "cache": false,