@emdzej/itw-decoder 0.1.0
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/LICENSE +118 -0
- package/README.md +127 -0
- package/dist/decode0300.js +1380 -0
- package/dist/decode0400.js +323 -0
- package/dist/index.js +56 -0
- package/dist/itw.js +59 -0
- package/dist/png.js +35 -0
- package/package.json +30 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
PolyForm Noncommercial License 1.0.0
|
|
2
|
+
|
|
3
|
+
https://polyformproject.org/licenses/noncommercial/1.0.0
|
|
4
|
+
|
|
5
|
+
Acceptance
|
|
6
|
+
|
|
7
|
+
In order to get any license under these terms, you must agree to them as
|
|
8
|
+
both strict obligations and conditions to all your licenses.
|
|
9
|
+
|
|
10
|
+
Copyright License
|
|
11
|
+
|
|
12
|
+
The licensor grants you a copyright license for the software to do
|
|
13
|
+
everything you might do with the software that would otherwise infringe
|
|
14
|
+
the licensor's copyright in it for any permitted purpose. However, you
|
|
15
|
+
may only distribute the software according to Distribution License and
|
|
16
|
+
make changes or new works based on the software according to Changes and
|
|
17
|
+
New Works License.
|
|
18
|
+
|
|
19
|
+
Distribution License
|
|
20
|
+
|
|
21
|
+
The licensor grants you an additional copyright license to distribute
|
|
22
|
+
copies of the software. Your license to distribute covers distributing
|
|
23
|
+
the software with changes and new works permitted by Changes and New
|
|
24
|
+
Works License.
|
|
25
|
+
|
|
26
|
+
Notices
|
|
27
|
+
|
|
28
|
+
You must ensure that anyone who gets a copy of any part of the software
|
|
29
|
+
from you also gets a copy of these terms or the URL for them above, as
|
|
30
|
+
well as copies of any plain-text lines beginning with Required Notice:
|
|
31
|
+
that the licensor provided with the software. For example:
|
|
32
|
+
|
|
33
|
+
Required Notice: Copyright Marek Jaskolski (https://github.com/emdzej)
|
|
34
|
+
|
|
35
|
+
Changes and New Works License
|
|
36
|
+
|
|
37
|
+
The licensor grants you an additional copyright license to make changes
|
|
38
|
+
and new works based on the software for any permitted purpose.
|
|
39
|
+
|
|
40
|
+
Patent License
|
|
41
|
+
|
|
42
|
+
The licensor grants you a patent license for the software that covers
|
|
43
|
+
patent claims the licensor can license, or becomes able to license, that
|
|
44
|
+
you would infringe by using the software.
|
|
45
|
+
|
|
46
|
+
Noncommercial Purposes
|
|
47
|
+
|
|
48
|
+
Any noncommercial purpose is a permitted purpose.
|
|
49
|
+
|
|
50
|
+
Personal Uses
|
|
51
|
+
|
|
52
|
+
Personal use for research, experiment, and testing for the benefit of
|
|
53
|
+
public knowledge, personal study, private entertainment, hobby projects,
|
|
54
|
+
amateur pursuits, or religious observance, without any anticipated
|
|
55
|
+
commercial application, is use for a permitted purpose.
|
|
56
|
+
|
|
57
|
+
Noncommercial Organizations
|
|
58
|
+
|
|
59
|
+
Use by any charitable organization, educational institution, public
|
|
60
|
+
research organization, public safety or health organization,
|
|
61
|
+
environmental protection organization, or government institution is use
|
|
62
|
+
for a permitted purpose regardless of the source of funding or
|
|
63
|
+
obligations resulting from the funding.
|
|
64
|
+
|
|
65
|
+
Fair Use
|
|
66
|
+
|
|
67
|
+
You may have "fair use" rights for the software under the law. These
|
|
68
|
+
terms do not limit them.
|
|
69
|
+
|
|
70
|
+
No Other Rights
|
|
71
|
+
|
|
72
|
+
These terms do not allow you to sublicense or transfer any of your
|
|
73
|
+
licenses to anyone else, or prevent the licensor from granting licenses
|
|
74
|
+
to anyone else. These terms do not imply any other licenses.
|
|
75
|
+
|
|
76
|
+
Patent Defense
|
|
77
|
+
|
|
78
|
+
If you make any written claim that the software infringes or contributes
|
|
79
|
+
to infringement of any patent, your patent license for the software
|
|
80
|
+
granted under these terms ends immediately. If your company makes such a
|
|
81
|
+
claim, your patent license ends immediately for work on behalf of your
|
|
82
|
+
company.
|
|
83
|
+
|
|
84
|
+
Violations
|
|
85
|
+
|
|
86
|
+
The first time you are notified in writing that you have violated any of
|
|
87
|
+
these terms, or done anything with the software not covered by your
|
|
88
|
+
licenses, your licenses can nonetheless continue if you come into full
|
|
89
|
+
compliance with these terms, and take practical steps to correct past
|
|
90
|
+
violations, within 32 days of receiving notice. Otherwise, all your
|
|
91
|
+
licenses end immediately.
|
|
92
|
+
|
|
93
|
+
No Liability
|
|
94
|
+
|
|
95
|
+
As far as the law allows, the software comes as is, without any warranty
|
|
96
|
+
or condition, and the licensor will not be liable to you for any damages
|
|
97
|
+
arising out of these terms or the use or nature of the software, under
|
|
98
|
+
any kind of legal claim.
|
|
99
|
+
|
|
100
|
+
Definitions
|
|
101
|
+
|
|
102
|
+
The licensor is the individual or entity offering these terms, and the
|
|
103
|
+
software is the software the licensor makes available under these terms.
|
|
104
|
+
|
|
105
|
+
You refers to the individual or entity agreeing to these terms.
|
|
106
|
+
|
|
107
|
+
Your company is any legal entity, sole proprietorship, or other kind of
|
|
108
|
+
organization that you work for, plus all organizations that have control
|
|
109
|
+
over, are under the control of, or are under common control with that
|
|
110
|
+
organization. Control means ownership of substantially all the assets of
|
|
111
|
+
an entity, or the power to direct its management and policies by vote,
|
|
112
|
+
contract, or otherwise. Control can be direct or indirect.
|
|
113
|
+
|
|
114
|
+
Your licenses are all the licenses granted to you for the software under
|
|
115
|
+
these terms.
|
|
116
|
+
|
|
117
|
+
Use means anything you do with the software requiring one of your
|
|
118
|
+
licenses.
|
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# @emdzej/itw-decoder
|
|
2
|
+
|
|
3
|
+
TypeScript CLI decoder for BMW TIS `.ITW` proprietary image files. Converts proprietary ITW images to standard PNG format.
|
|
4
|
+
|
|
5
|
+
[](https://github.com/emdzej/itw-decoder/actions/workflows/ci.yml)
|
|
6
|
+
[](https://www.npmjs.com/package/@emdzej/itw-decoder)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
## What is ITW?
|
|
10
|
+
|
|
11
|
+
ITW is a proprietary image format used in BMW's Technical Information System (TIS) software for storing technical illustrations (wiring diagrams, exploded views, etc.). The format supports two compression codecs:
|
|
12
|
+
|
|
13
|
+
- **Subtype 0x0300** — Wavelet compression (biorthogonal wavelet transform, ~5:1–14:1 ratio)
|
|
14
|
+
- **Subtype 0x0400** — Entropy compression (Huffman + RLE interleave)
|
|
15
|
+
|
|
16
|
+
All images are 8-bit grayscale, typically 316×238 pixels.
|
|
17
|
+
|
|
18
|
+
For a full technical description of the format and decoding algorithms see [`docs/HOW_IT_WORKS.md`](docs/HOW_IT_WORKS.md).
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
### Global (recommended for CLI use)
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install -g @emdzej/itw-decoder
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Local / development
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pnpm install
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
Usage: itw-decode [options] <input>
|
|
38
|
+
|
|
39
|
+
Decode BMW TIS .ITW proprietary image files to PNG
|
|
40
|
+
|
|
41
|
+
Arguments:
|
|
42
|
+
input path to the .ITW file to decode
|
|
43
|
+
|
|
44
|
+
Options:
|
|
45
|
+
-V, --version output the current version
|
|
46
|
+
-o, --output <file> output PNG path (default: <input>.png in cwd)
|
|
47
|
+
-d, --dir <directory> output directory, keeps auto-derived filename (default: cwd)
|
|
48
|
+
-h, --help display help for command
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Examples
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Decode — output defaults to ./26.png
|
|
55
|
+
itw-decode samples/1/03/95/26.ITW
|
|
56
|
+
|
|
57
|
+
# Explicit output path
|
|
58
|
+
itw-decode samples/1/03/95/26.ITW -o out/diagram.png
|
|
59
|
+
|
|
60
|
+
# Write to a directory, keep original filename
|
|
61
|
+
itw-decode samples/1/03/95/26.ITW -d out/
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
> **Note:** `-o` and `-d` are independent; `-o` takes full precedence when both are supplied.
|
|
65
|
+
|
|
66
|
+
### Dev (without global install)
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
./node_modules/.bin/ts-node src/index.ts samples/1/03/95/26.ITW -o output.png
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Bulk testing
|
|
73
|
+
|
|
74
|
+
To test against a full GRAFIK corpus directory:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# First 100 files
|
|
78
|
+
./node_modules/.bin/ts-node bulk_test.ts /path/to/GRAFIK --limit 100
|
|
79
|
+
|
|
80
|
+
# All files
|
|
81
|
+
./node_modules/.bin/ts-node bulk_test.ts /path/to/GRAFIK
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Test results
|
|
85
|
+
|
|
86
|
+
Tested against the full 47,660-file GRAFIK corpus:
|
|
87
|
+
|
|
88
|
+
| Metric | Value |
|
|
89
|
+
|--------|-------|
|
|
90
|
+
| Success rate | **98.67%** (47,028 / 47,660) |
|
|
91
|
+
| 0x0300 wavelet decoded | 35,117 |
|
|
92
|
+
| 0x0400 entropy decoded | 11,911 |
|
|
93
|
+
| Failures | 632 — all genuinely malformed/truncated source files |
|
|
94
|
+
|
|
95
|
+
The dominant failure reason is "wavelet payload overruns file" (470 truncated files), not decoder bugs.
|
|
96
|
+
|
|
97
|
+
## Project structure
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
src/
|
|
101
|
+
itw.ts — Header parsing, shared types (ITWHeader, DecodeResult, ITWError), endian helpers
|
|
102
|
+
decode0300.ts — Wavelet codec (biorthogonal wavelet transform, ~1518 lines)
|
|
103
|
+
decode0400.ts — Entropy codec (Huffman + RLE interleave)
|
|
104
|
+
png.ts — Grayscale→RGBA conversion, PNG writer (pngjs)
|
|
105
|
+
index.ts — CLI entry point (commander.js)
|
|
106
|
+
docs/
|
|
107
|
+
HOW_IT_WORKS.md — Complete decoder specification (format to reimplement in any language)
|
|
108
|
+
findings.md — Raw reverse-engineering notes, Ghidra function table, lessons learned
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Documentation
|
|
112
|
+
|
|
113
|
+
| Document | Description |
|
|
114
|
+
|----------|-------------|
|
|
115
|
+
| [`docs/HOW_IT_WORKS.md`](docs/HOW_IT_WORKS.md) | Complete, language-agnostic decoder specification — header layout, both codecs, filter derivation, Fischer coding, polyphase convolution, all constants |
|
|
116
|
+
| [`docs/findings.md`](docs/findings.md) | Reverse-engineering notes — Ghidra function addresses, all 9 bugs found and fixed, x87 FPU pitfalls |
|
|
117
|
+
|
|
118
|
+
## Building
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
pnpm build # tsc → dist/
|
|
122
|
+
pnpm dev # run via ts-node (no build step)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
[PolyForm Noncommercial License 1.0.0](LICENSE) — free for personal, research, and noncommercial use; commercial use is not permitted.
|