@thi.ng/pixel-analysis 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2025-07-14T10:38:44Z
3
+ - **Last updated**: 2025-07-15T09:30:47Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -11,6 +11,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
11
11
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
12
12
  and/or version bumps of transitive dependencies.
13
13
 
14
+ ### [0.4.1](https://github.com/thi-ng/umbrella/tree/@thi.ng/pixel-analysis@0.4.1) (2025-07-15)
15
+
16
+ #### ♻️ Refactoring
17
+
18
+ - extract `derivedColorsResults()` ([c8fb4ed](https://github.com/thi-ng/umbrella/commit/c8fb4ed))
19
+
14
20
  ## [0.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/pixel-analysis@0.4.0) (2025-07-14)
15
21
 
16
22
  #### 🚀 Features
@@ -8,4 +8,11 @@ import type { AnalysisOpts, AnalyzedImage } from "./api.js";
8
8
  * @param opts
9
9
  */
10
10
  export declare const analyzeColors: (img: FloatBuffer | IntBuffer, opts?: Partial<AnalysisOpts>) => AnalyzedImage;
11
+ /**
12
+ * Computes a number of metrics (partial {@link AnalyzedImage}) derived from
13
+ * given raw SRGB colors. Helper function for {@link analyzeColors}.
14
+ *
15
+ * @param colors
16
+ */
17
+ export declare const derivedColorsResults: (colors: number[][]) => Pick<AnalyzedImage, "css" | "srgb" | "hsv" | "oklch" | "hueRange" | "satRange" | "chromaRange" | "lumaRange" | "contrast" | "colorContrast">;
11
18
  //# sourceMappingURL=analyze-colors.d.ts.map
package/analyze-colors.js CHANGED
@@ -1,4 +1,4 @@
1
- import { contrast } from "@thi.ng/color/contrast";
1
+ import { contrast as contrastWCAG } from "@thi.ng/color/contrast";
2
2
  import { css } from "@thi.ng/color/css/css";
3
3
  import { hsv } from "@thi.ng/color/hsv/hsv";
4
4
  import { luminanceSrgb } from "@thi.ng/color/luminance-rgb";
@@ -41,28 +41,45 @@ const analyzeColors = (img, opts) => {
41
41
  return x;
42
42
  });
43
43
  const colorAreas = colors.map((x) => x.area);
44
- const dominantLuma = colors.map((x) => luminanceSrgb(x.color));
45
- const dominantSrgb = colors.map((x) => srgb(x.color));
46
- const dominantHsv = dominantSrgb.map((x) => hsv(x));
47
- const dominantOklch = dominantSrgb.map((x) => oklch(x));
48
- const dominantCss = dominantSrgb.map((x) => css(x));
49
- const hueRange = transduce(pluck(0), minMax(), dominantHsv);
50
- const satRange = transduce(pluck(1), minMax(), dominantHsv);
51
- const chromaRange = transduce(pluck(1), minMax(), dominantOklch);
52
- const lumaRange = reduce(minMax(), dominantLuma);
44
+ const derived = derivedColorsResults(colors.map((x) => x.color));
53
45
  const lumaRangeImg = reduce(minMax(), imgGray.data);
54
- const weightedLuma = dot(dominantLuma, colorAreas);
46
+ const weightedLuma = dot(derived.lumaRange, colorAreas);
55
47
  const weightedChroma = dot(
56
- dominantOklch.map((x) => x[1]),
48
+ derived.oklch.map((x) => x[1]),
57
49
  colorAreas
58
50
  );
59
51
  const weightedSat = dot(
60
- dominantHsv.map((x) => x[1]),
52
+ derived.hsv.map((x) => x[1]),
61
53
  colorAreas
62
54
  );
55
+ return {
56
+ img: $img,
57
+ imgGray,
58
+ imgHsv,
59
+ ...derived,
60
+ area: colorAreas,
61
+ warmth: warmIntensityHsv(imgHsv, opts?.minSat),
62
+ contrastImg: lumaRangeImg[1] - lumaRangeImg[0],
63
+ lumaRangeImg,
64
+ weightedSat,
65
+ weightedLuma,
66
+ weightedChroma
67
+ };
68
+ };
69
+ const derivedColorsResults = (colors) => {
70
+ const dominantLuma = colors.map((x) => luminanceSrgb(x));
71
+ const dominantSrgb = colors.map((x) => srgb(x));
72
+ const dominantHsv = dominantSrgb.map((x) => hsv(x));
73
+ const dominantOklch = dominantSrgb.map((x) => oklch(x));
74
+ const dominantCss = dominantSrgb.map((x) => css(x));
75
+ const hueRange = transduce(pluck(0), minMax(), dominantHsv);
76
+ const satRange = transduce(pluck(1), minMax(), dominantHsv);
77
+ const chromaRange = transduce(pluck(1), minMax(), dominantOklch);
78
+ const lumaRange = reduce(minMax(), dominantLuma);
79
+ const contrast = lumaRange[1] - lumaRange[0];
63
80
  const colorContrast = fit(
64
81
  transduce(
65
- map((pair) => contrast(...pair)),
82
+ map((pair) => contrastWCAG(...pair)),
66
83
  max(),
67
84
  permutations(dominantSrgb, dominantSrgb)
68
85
  ),
@@ -72,28 +89,19 @@ const analyzeColors = (img, opts) => {
72
89
  1
73
90
  );
74
91
  return {
75
- img: $img,
76
- imgGray,
77
- imgHsv,
78
92
  css: dominantCss,
79
93
  srgb: dominantSrgb,
80
94
  hsv: dominantHsv,
81
95
  oklch: dominantOklch,
82
- area: colorAreas,
83
96
  hueRange,
84
97
  satRange,
85
98
  chromaRange,
86
99
  lumaRange,
87
- lumaRangeImg,
88
- warmth: warmIntensityHsv(imgHsv, opts?.minSat),
89
- contrast: lumaRange[1] - lumaRange[0],
90
- contrastImg: lumaRangeImg[1] - lumaRangeImg[0],
91
- colorContrast,
92
- weightedSat,
93
- weightedLuma,
94
- weightedChroma
100
+ contrast,
101
+ colorContrast
95
102
  };
96
103
  };
97
104
  export {
98
- analyzeColors
105
+ analyzeColors,
106
+ derivedColorsResults
99
107
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/pixel-analysis",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Image color & feature analysis utilities",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -40,13 +40,13 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@thi.ng/api": "^8.11.30",
43
- "@thi.ng/color": "^5.7.46",
43
+ "@thi.ng/color": "^5.7.47",
44
44
  "@thi.ng/compare": "^2.4.22",
45
45
  "@thi.ng/math": "^5.11.30",
46
46
  "@thi.ng/pixel": "^7.5.2",
47
47
  "@thi.ng/pixel-convolve": "^1.1.2",
48
48
  "@thi.ng/pixel-dominant-colors": "^2.0.2",
49
- "@thi.ng/transducers": "^9.6.0",
49
+ "@thi.ng/transducers": "^9.6.1",
50
50
  "@thi.ng/vectors": "^8.3.3"
51
51
  },
52
52
  "devDependencies": {
@@ -107,5 +107,5 @@
107
107
  "status": "beta",
108
108
  "year": 2024
109
109
  },
110
- "gitHead": "89a9dc2519be2461de39381de3c13e2771178c39\n"
110
+ "gitHead": "9ec4a5584ed6e59f2b74f4ca9726daef7e766974\n"
111
111
  }