@thi.ng/pixel-io-netpbm 2.1.129 → 2.1.131

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**: 2024-04-23T07:02:18Z
3
+ - **Last updated**: 2024-06-21T19:34:38Z
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.
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ### [2.1.131](https://github.com/thi-ng/umbrella/tree/@thi.ng/pixel-io-netpbm@2.1.131) (2024-06-21)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
17
+
12
18
  ### [2.1.127](https://github.com/thi-ng/umbrella/tree/@thi.ng/pixel-io-netpbm@2.1.127) (2024-04-20)
13
19
 
14
20
  #### ♻️ Refactoring
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 193 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/pixel-io-netpbm",
3
- "version": "2.1.129",
3
+ "version": "2.1.131",
4
4
  "description": "Multi-format NetPBM reader & writer support for @thi.ng/pixel",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/thi-ng/umbrella.git"
12
12
  },
13
- "homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/pixel-io-netpbm#readme",
13
+ "homepage": "https://thi.ng/pixel-io-netpbm",
14
14
  "funding": [
15
15
  {
16
16
  "type": "github",
@@ -36,15 +36,15 @@
36
36
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@thi.ng/api": "^8.11.1",
40
- "@thi.ng/errors": "^2.5.6",
41
- "@thi.ng/pixel": "^6.1.31"
39
+ "@thi.ng/api": "^8.11.3",
40
+ "@thi.ng/errors": "^2.5.8",
41
+ "@thi.ng/pixel": "^6.1.33"
42
42
  },
43
43
  "devDependencies": {
44
- "@microsoft/api-extractor": "^7.43.0",
45
- "esbuild": "^0.20.2",
46
- "typedoc": "^0.25.12",
47
- "typescript": "^5.4.3"
44
+ "@microsoft/api-extractor": "^7.47.0",
45
+ "esbuild": "^0.21.5",
46
+ "typedoc": "^0.25.13",
47
+ "typescript": "^5.5.2"
48
48
  },
49
49
  "keywords": [
50
50
  "1bit",
@@ -87,5 +87,5 @@
87
87
  "parent": "@thi.ng/pixel",
88
88
  "year": 2021
89
89
  },
90
- "gitHead": "aed3421c21044c005fbcb7cc37965ccf85a870d2\n"
90
+ "gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
91
91
  }
package/read.js CHANGED
@@ -4,9 +4,9 @@ import { GRAY16 } from "@thi.ng/pixel/format/gray16";
4
4
  import { GRAY8 } from "@thi.ng/pixel/format/gray8";
5
5
  import { RGB888 } from "@thi.ng/pixel/format/rgb888";
6
6
  import { intBuffer } from "@thi.ng/pixel/int";
7
- const isLinebreak = (c) => c === 10;
8
- const isWS = (c) => c === 32 || c >= 9 && c <= 13;
9
- const readUntil = (src, i, end = isLinebreak) => {
7
+ const __isLinebreak = (c) => c === 10;
8
+ const __isWS = (c) => c === 32 || c >= 9 && c <= 13;
9
+ const __readUntil = (src, i, end = __isLinebreak) => {
10
10
  let res = "";
11
11
  for (; i < src.length; i++) {
12
12
  let c = src[i];
@@ -18,9 +18,9 @@ const readUntil = (src, i, end = isLinebreak) => {
18
18
  }
19
19
  return [res, i];
20
20
  };
21
- const readComments = (src, acc, i) => {
21
+ const __readComments = (src, acc, i) => {
22
22
  while (src[i] === 35) {
23
- const [comment, j] = readUntil(src, i);
23
+ const [comment, j] = __readUntil(src, i);
24
24
  assert(j !== i, `EOF reached`);
25
25
  acc.push(comment.substring(1).trim());
26
26
  i = j;
@@ -33,16 +33,16 @@ const parseHeader = (src) => {
33
33
  let norm;
34
34
  let max;
35
35
  const comments = [];
36
- let i = readComments(src, comments, 0);
37
- [type, i] = readUntil(src, i);
38
- i = readComments(src, comments, i);
39
- [sw, i] = readUntil(src, i, isWS);
40
- [sh, i] = readUntil(src, i, isWS);
36
+ let i = __readComments(src, comments, 0);
37
+ [type, i] = __readUntil(src, i);
38
+ i = __readComments(src, comments, i);
39
+ [sw, i] = __readUntil(src, i, __isWS);
40
+ [sh, i] = __readUntil(src, i, __isWS);
41
41
  const width = parseInt(sw);
42
42
  const height = parseInt(sh);
43
43
  assert(width > 0 && height > 0, `invalid NetPBM header`);
44
44
  if (type === "P5" || type === "P6") {
45
- [norm, i] = readUntil(src, i);
45
+ [norm, i] = __readUntil(src, i);
46
46
  max = parseInt(norm);
47
47
  }
48
48
  return {
@@ -74,8 +74,7 @@ const readPBM = (src, i, width, height) => {
74
74
  for (let y = 0, j = 0; y < height; y++) {
75
75
  for (let x = 0; x < width; x++, j++) {
76
76
  data[j] = src[i] & 1 << (~x & 7) ? 0 : 255;
77
- if ((x & 7) === 7 || x === w1)
78
- i++;
77
+ if ((x & 7) === 7 || x === w1) i++;
79
78
  }
80
79
  }
81
80
  return buf;
package/write.js CHANGED
@@ -1,22 +1,21 @@
1
1
  import { GRAY16 } from "@thi.ng/pixel/format/gray16";
2
- const formatComments = (comments = ["generated by @thi.ng/pixel-io-netpbm"]) => comments.map((x) => `# ${x}`).join("\n");
3
- const initHeader = (magic, limits, size, buf, comments) => {
2
+ const __formatComments = (comments = ["generated by @thi.ng/pixel-io-netpbm"]) => comments.map((x) => `# ${x}`).join("\n");
3
+ const __luminance = (c) => ((c >>> 16 & 255) * 29 + (c >>> 8 & 255) * 150 + (c & 255) * 76) / 255;
4
+ const __initHeader = (magic, limits, size, buf, comments) => {
4
5
  const { width, height } = buf;
5
6
  let header = magic + "\n";
6
- const comm = formatComments(comments);
7
- if (comm.length)
8
- header += comm + "\n";
7
+ const comm = __formatComments(comments);
8
+ if (comm.length) header += comm + "\n";
9
9
  header += `${width} ${height}
10
10
  `;
11
- if (limits > 0)
12
- header += limits + "\n";
11
+ if (limits > 0) header += limits + "\n";
13
12
  const dest = new Uint8Array(size + header.length);
14
13
  dest.set([...header].map((x) => x.charCodeAt(0)));
15
14
  return { dest, start: header.length, abgr: buf.format.toABGR };
16
15
  };
17
16
  const asPBM = (buf, comments) => {
18
17
  const { data, width, height } = buf;
19
- const { dest, start, abgr } = initHeader(
18
+ const { dest, start, abgr } = __initHeader(
20
19
  "P4",
21
20
  0,
22
21
  Math.ceil(width / 8) * height,
@@ -27,7 +26,7 @@ const asPBM = (buf, comments) => {
27
26
  for (let y = 0, i = start, j = 0; y < height; y++) {
28
27
  for (let x = 0, b = 0; x <= w1; x++, j++) {
29
28
  const xx = ~x & 7;
30
- if (luminance(abgr(data[j])) < 128) {
29
+ if (__luminance(abgr(data[j])) < 128) {
31
30
  b |= 1 << xx;
32
31
  }
33
32
  if (xx === 0 || x === w1) {
@@ -40,7 +39,7 @@ const asPBM = (buf, comments) => {
40
39
  };
41
40
  const asPGM = (buf, comments) => {
42
41
  const { data, width, height } = buf;
43
- const { dest, start, abgr } = initHeader(
42
+ const { dest, start, abgr } = __initHeader(
44
43
  "P5",
45
44
  255,
46
45
  width * height,
@@ -48,15 +47,14 @@ const asPGM = (buf, comments) => {
48
47
  comments
49
48
  );
50
49
  for (let i = start, j = 0; j < data.length; i++, j++) {
51
- dest[i] = luminance(abgr(data[j]));
50
+ dest[i] = __luminance(abgr(data[j]));
52
51
  }
53
52
  return dest;
54
53
  };
55
54
  const asPGM16 = (buf, comments) => {
56
- if (buf.format !== GRAY16)
57
- buf = buf.as(GRAY16);
55
+ if (buf.format !== GRAY16) buf = buf.as(GRAY16);
58
56
  const { data, width, height } = buf;
59
- const { dest, start } = initHeader(
57
+ const { dest, start } = __initHeader(
60
58
  "P5",
61
59
  65535,
62
60
  width * height * 2,
@@ -71,7 +69,7 @@ const asPGM16 = (buf, comments) => {
71
69
  };
72
70
  const asPPM = (buf, comments) => {
73
71
  const { data, width, height } = buf;
74
- const { dest, start, abgr } = initHeader(
72
+ const { dest, start, abgr } = __initHeader(
75
73
  "P6",
76
74
  255,
77
75
  width * 3 * height,
@@ -86,7 +84,6 @@ const asPPM = (buf, comments) => {
86
84
  }
87
85
  return dest;
88
86
  };
89
- const luminance = (c) => ((c >>> 16 & 255) * 29 + (c >>> 8 & 255) * 150 + (c & 255) * 76) / 255;
90
87
  export {
91
88
  asPBM,
92
89
  asPGM,