@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 +7 -1
- package/README.md +1 -1
- package/package.json +10 -10
- package/read.js +12 -13
- package/write.js +13 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
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
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
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.
|
|
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://
|
|
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.
|
|
40
|
-
"@thi.ng/errors": "^2.5.
|
|
41
|
-
"@thi.ng/pixel": "^6.1.
|
|
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.
|
|
45
|
-
"esbuild": "^0.
|
|
46
|
-
"typedoc": "^0.25.
|
|
47
|
-
"typescript": "^5.
|
|
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": "
|
|
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
|
|
8
|
-
const
|
|
9
|
-
const
|
|
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
|
|
21
|
+
const __readComments = (src, acc, i) => {
|
|
22
22
|
while (src[i] === 35) {
|
|
23
|
-
const [comment, j] =
|
|
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 =
|
|
37
|
-
[type, i] =
|
|
38
|
-
i =
|
|
39
|
-
[sw, i] =
|
|
40
|
-
[sh, i] =
|
|
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] =
|
|
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
|
|
3
|
-
const
|
|
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 =
|
|
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 } =
|
|
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 (
|
|
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 } =
|
|
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] =
|
|
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 } =
|
|
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 } =
|
|
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,
|