rw-parser-ng 2.1.1 → 2.3.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.
Files changed (141) hide show
  1. package/README.md +252 -52
  2. package/lib/codecs/bitmap.d.ts +6 -0
  3. package/lib/codecs/bitmap.js +77 -0
  4. package/lib/codecs/color.d.ts +6 -0
  5. package/lib/codecs/color.js +43 -0
  6. package/lib/codecs/dxt.d.ts +3 -0
  7. package/lib/codecs/dxt.js +212 -0
  8. package/lib/codecs/formats.d.ts +25 -0
  9. package/lib/codecs/formats.js +32 -0
  10. package/lib/codecs/index.d.ts +5 -0
  11. package/lib/codecs/index.js +21 -0
  12. package/lib/codecs/palette.d.ts +6 -0
  13. package/lib/codecs/palette.js +86 -0
  14. package/lib/common/types.d.ts +50 -0
  15. package/lib/common/types.js +2 -0
  16. package/lib/core/byte-stream.d.ts +20 -0
  17. package/lib/core/byte-stream.js +71 -0
  18. package/lib/core/errors.d.ts +5 -0
  19. package/lib/core/errors.js +34 -0
  20. package/lib/core/index.d.ts +5 -0
  21. package/lib/core/index.js +21 -0
  22. package/lib/core/rw-file.d.ts +9 -0
  23. package/lib/core/rw-file.js +36 -0
  24. package/lib/core/rw-sections.d.ts +24 -0
  25. package/lib/core/rw-sections.js +28 -0
  26. package/lib/core/rw-version.d.ts +3 -0
  27. package/lib/core/rw-version.js +27 -0
  28. package/lib/dff/dff-model-type.d.ts +5 -0
  29. package/lib/dff/dff-model-type.js +9 -0
  30. package/lib/dff/index.d.ts +4 -0
  31. package/lib/dff/index.js +20 -0
  32. package/lib/dff/parser.d.ts +5 -0
  33. package/lib/dff/parser.js +154 -0
  34. package/lib/dff/readers/2d-effect.d.ts +3 -0
  35. package/lib/dff/readers/2d-effect.js +211 -0
  36. package/lib/dff/readers/geometry.d.ts +4 -0
  37. package/lib/dff/readers/geometry.js +229 -0
  38. package/lib/dff/readers/index.d.ts +5 -0
  39. package/lib/dff/readers/index.js +21 -0
  40. package/lib/dff/readers/material.d.ts +5 -0
  41. package/lib/dff/readers/material.js +72 -0
  42. package/lib/dff/readers/mesh.d.ts +5 -0
  43. package/lib/dff/readers/mesh.js +84 -0
  44. package/lib/dff/readers/structure.d.ts +6 -0
  45. package/lib/dff/readers/structure.js +67 -0
  46. package/lib/dff/types.d.ts +237 -0
  47. package/lib/dff/types.js +44 -0
  48. package/lib/fxp/index.d.ts +2 -0
  49. package/lib/fxp/index.js +18 -0
  50. package/lib/fxp/info-parser.d.ts +2 -0
  51. package/lib/fxp/info-parser.js +169 -0
  52. package/lib/fxp/parser.d.ts +3 -0
  53. package/lib/fxp/parser.js +285 -0
  54. package/lib/fxp/types/common.d.ts +36 -0
  55. package/lib/fxp/types/common.js +2 -0
  56. package/lib/fxp/types/index.d.ts +3 -0
  57. package/lib/fxp/types/index.js +19 -0
  58. package/lib/fxp/types/info.d.ts +186 -0
  59. package/lib/fxp/types/info.js +2 -0
  60. package/lib/fxp/types/system.d.ts +27 -0
  61. package/lib/fxp/types/system.js +2 -0
  62. package/lib/ifp/index.d.ts +4 -0
  63. package/lib/ifp/index.js +20 -0
  64. package/lib/ifp/parser.d.ts +5 -0
  65. package/lib/ifp/parser.js +38 -0
  66. package/lib/ifp/readers/anp3.d.ts +3 -0
  67. package/lib/ifp/readers/anp3.js +56 -0
  68. package/lib/ifp/readers/anpk.d.ts +3 -0
  69. package/lib/ifp/readers/anpk.js +86 -0
  70. package/lib/ifp/types.d.ts +28 -0
  71. package/lib/ifp/types.js +9 -0
  72. package/lib/index.d.ts +6 -9
  73. package/lib/index.js +6 -13
  74. package/lib/renderware/fxp/FxpData.d.ts +246 -0
  75. package/lib/renderware/fxp/FxpData.js +2 -0
  76. package/lib/renderware/fxp/FxpParser.d.ts +3 -0
  77. package/lib/renderware/fxp/FxpParser.js +512 -0
  78. package/lib/renderware/fxp/index.d.ts +2 -0
  79. package/lib/renderware/fxp/index.js +18 -0
  80. package/lib/txd/bitmap-decoder.d.ts +3 -0
  81. package/lib/txd/bitmap-decoder.js +57 -0
  82. package/lib/txd/index.d.ts +3 -0
  83. package/lib/txd/index.js +19 -0
  84. package/lib/txd/parser.d.ts +8 -0
  85. package/lib/txd/parser.js +122 -0
  86. package/lib/txd/types.d.ts +27 -0
  87. package/lib/txd/types.js +2 -0
  88. package/package.json +16 -9
  89. package/src/codecs/bitmap.ts +75 -0
  90. package/src/codecs/color.ts +40 -0
  91. package/src/codecs/dxt.ts +243 -0
  92. package/src/codecs/formats.ts +28 -0
  93. package/src/codecs/index.ts +5 -0
  94. package/src/codecs/palette.ts +106 -0
  95. package/src/common/types.ts +59 -0
  96. package/src/core/byte-stream.ts +87 -0
  97. package/src/core/errors.ts +7 -0
  98. package/src/core/index.ts +5 -0
  99. package/src/core/rw-file.ts +23 -0
  100. package/src/core/rw-sections.ts +24 -0
  101. package/src/core/rw-version.ts +24 -0
  102. package/src/dff/dff-model-type.ts +5 -0
  103. package/src/dff/index.ts +4 -0
  104. package/src/dff/parser.ts +142 -0
  105. package/src/dff/readers/2d-effect.ts +265 -0
  106. package/src/dff/readers/geometry.ts +264 -0
  107. package/src/dff/readers/index.ts +5 -0
  108. package/src/dff/readers/material.ts +89 -0
  109. package/src/dff/readers/mesh.ts +93 -0
  110. package/src/dff/readers/structure.ts +79 -0
  111. package/src/dff/types.ts +278 -0
  112. package/src/fxp/index.ts +2 -0
  113. package/src/fxp/info-parser.ts +166 -0
  114. package/src/fxp/parser.ts +323 -0
  115. package/src/fxp/types/common.ts +23 -0
  116. package/src/fxp/types/index.ts +3 -0
  117. package/src/fxp/types/info.ts +251 -0
  118. package/src/fxp/types/system.ts +30 -0
  119. package/src/ifp/index.ts +4 -0
  120. package/src/ifp/parser.ts +16 -0
  121. package/src/ifp/readers/anp3.ts +75 -0
  122. package/src/ifp/readers/anpk.ts +110 -0
  123. package/src/ifp/types.ts +33 -0
  124. package/src/index.ts +6 -12
  125. package/src/txd/bitmap-decoder.ts +73 -0
  126. package/src/txd/index.ts +3 -0
  127. package/src/txd/parser.ts +148 -0
  128. package/src/txd/types.ts +29 -0
  129. package/src/renderware/RwFile.ts +0 -26
  130. package/src/renderware/RwSections.ts +0 -27
  131. package/src/renderware/common/types.ts +0 -59
  132. package/src/renderware/dff/DffModelType.ts +0 -5
  133. package/src/renderware/dff/DffParser.ts +0 -611
  134. package/src/renderware/errors/RwParseError.ts +0 -11
  135. package/src/renderware/ifp/IfpData.ts +0 -33
  136. package/src/renderware/ifp/IfpParser.ts +0 -203
  137. package/src/renderware/txd/TxdParser.ts +0 -235
  138. package/src/renderware/utils/ImageDecoder.ts +0 -571
  139. package/src/renderware/utils/ImageFormatEnums.ts +0 -28
  140. package/src/renderware/utils/RwVersion.ts +0 -28
  141. package/src/utils/ByteStream.ts +0 -80
package/README.md CHANGED
@@ -1,88 +1,288 @@
1
1
  # RenderWare Binary Stream Parser NG
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/rw-parser-ng.svg)](https://www.npmjs.com/package/rw-parser-ng)
4
- [![NPM](https://img.shields.io/npm/l/rw-parser-ng.svg)](https://github.com/DepsCian/rw-parser-ng/blob/master/LICENSE)
4
+ [![CI](https://github.com/DepsCian/rw-parser-ng/actions/workflows/test.yml/badge.svg)](https://github.com/DepsCian/rw-parser-ng/actions/workflows/test.yml)
5
+ [![License: GPL-3.0](https://img.shields.io/npm/l/rw-parser-ng.svg)](https://github.com/DepsCian/rw-parser-ng/blob/master/LICENSE)
5
6
 
6
- Parses RenderWare files (`.dff`, `.txd`, `.ifp`) into a usable format.
7
+ A TypeScript library for parsing RenderWare binary stream files used in GTA III, Vice City, and San Andreas.
7
8
 
8
- This is a fork of the original [rw-parser](https://github.com/Timic3/rw-parser) by Timic3, which is no longer active maintained. This version aims to continue development, fix bugs, and add new features.
9
+ This is a maintained fork of [rw-parser](https://github.com/Timic3/rw-parser) by Timic3.
9
10
 
10
- ## Features
11
+ ## Supported Formats
11
12
 
12
- * **DFF (Model) Parsing:** Extracts geometry, materials, frames, and skinning data.
13
- * **TXD (Texture Dictionary) Parsing:** Extracts texture information, including name, resolution and pixel data.
14
- * **IFP (Animation) Parsing:** Extracts animation data, including bone names, keyframes, and timings.
15
- * **Cross-Platform:** Works in both Node.js and modern web browsers.
16
- * **TypeScript Support:** Fully typed for a better development experience.
13
+ | Format | Extension | Description |
14
+ |--------|-----------|-------------|
15
+ | DFF | `.dff` | 3D model geometry, materials, frames, skinning data |
16
+ | TXD | `.txd` | Texture dictionaries with compressed/paletted textures |
17
+ | IFP | `.ifp` | Skeletal animations (ANP3, ANPK formats) |
18
+ | FXP | `.fxp` | Particle effect systems (GTA SA) |
19
+
20
+ ## Supported RenderWare Versions
21
+
22
+ | Version | Build | Game |
23
+ |---------|-------|------|
24
+ | 3.1.0.0 | 200704 | GTA III (PS2) |
25
+ | 3.2.0.0 | 204800 | GTA III (PC) |
26
+ | 3.3.0.2 | 208898 | GTA III (PC), Vice City (PS2) |
27
+ | 3.4.0.3 | 212995 | Vice City (PC) |
28
+ | 3.4.0.5 | 212997 | GTA III (PS2), Vice City (Android/PC) |
29
+ | 3.5.0.0 | 217088 | GTA III/VC (Xbox) |
30
+ | 3.6.0.3 | 221187 | San Andreas |
17
31
 
18
32
  ## Installation
19
33
 
20
- Install `rw-parser-ng` using pnpm:
34
+ ```sh
35
+ bun add rw-parser-ng
36
+ ```
21
37
 
22
- ```bash
23
- pnpm install --save rw-parser-ng
38
+ ```sh
39
+ npm install rw-parser-ng
24
40
  ```
25
41
 
26
42
  ## Usage
27
43
 
28
- ### ES6 Module
29
-
30
- ```javascript
31
- import { DffParser, TxdParser, IfpParser } from 'rw-parser-ng';
32
- import { readFileSync } from 'fs';
33
-
34
- // DFF
35
- const dffBuffer = readFileSync('path/to/your/model.dff');
36
- const dffParser = new DffParser(dffBuffer);
37
- const dffData = dffParser.parse();
38
- console.log(dffData);
39
-
40
- // TXD
41
- const txdBuffer = readFileSync('path/to/your/textures.txd');
42
- const txdParser = new TxdParser(txdBuffer);
43
- const txdData = txdParser.parse();
44
- console.log(txdData);
45
-
46
- // IFP
47
- const ifpBuffer = readFileSync('path/to/your/animation.ifp');
48
- const ifpParser = new IfpParser(ifpBuffer);
49
- const ifpData = ifpParser.parse();
50
- console.log(ifpData);
44
+ ### DFF (3D Models)
45
+
46
+ ```typescript
47
+ import { DffParser } from 'rw-parser-ng';
48
+ import { readFileSync } from 'node:fs';
49
+
50
+ const buffer = readFileSync('model.dff');
51
+ const parser = new DffParser(buffer);
52
+ const dff = parser.parse();
53
+
54
+ // Access parsed data
55
+ console.log(dff.version); // "RenderWare 3.6.0.3 (SA)"
56
+ console.log(dff.modelType); // DffModelType.SKIN | VEHICLE | GENERIC
57
+ console.log(dff.geometryList.geometries.length); // Number of geometries
58
+ console.log(dff.frameList.frames.length); // Number of frames
59
+ console.log(dff.dummies); // Node names
60
+ console.log(dff.animNodes); // Animation hierarchy
61
+ ```
62
+
63
+ ### TXD (Textures)
64
+
65
+ ```typescript
66
+ import { TxdParser } from 'rw-parser-ng';
67
+ import { readFileSync } from 'node:fs';
68
+
69
+ const buffer = readFileSync('textures.txd');
70
+ const parser = new TxdParser(buffer);
71
+ const txd = parser.parse();
72
+
73
+ for (const texture of txd.textureDictionary.textureNatives) {
74
+ console.log(texture.textureName); // Texture name
75
+ console.log(texture.width, texture.height);
76
+ console.log(texture.d3dFormat); // DXT1, DXT3, DXT5, etc.
77
+ console.log(texture.mipmaps[0]); // Decoded BGRA pixel data
78
+ }
79
+ ```
80
+
81
+ ### IFP (Animations)
82
+
83
+ ```typescript
84
+ import { IfpParser } from 'rw-parser-ng';
85
+ import { readFileSync } from 'node:fs';
86
+
87
+ const buffer = readFileSync('animation.ifp');
88
+ const parser = new IfpParser(buffer);
89
+ const ifp = parser.parse();
90
+
91
+ console.log(ifp.name); // Animation pack name
92
+ console.log(ifp.version); // IfpVersion.ANP3 | ANPK
93
+
94
+ for (const anim of ifp.animations) {
95
+ console.log(anim.name); // Animation name
96
+ for (const bone of anim.bones) {
97
+ console.log(bone.name, bone.keyframes.length);
98
+ }
99
+ }
100
+ ```
101
+
102
+ ### FXP (Particle Effects)
103
+
104
+ ```typescript
105
+ import { parseFxpFile, parseFxpContent } from 'rw-parser-ng';
106
+
107
+ // From file path
108
+ const project = parseFxpFile('effects.fxp');
109
+
110
+ // From string content
111
+ const content = readFileSync('effects.fxp', 'utf-8');
112
+ const project = parseFxpContent(content);
113
+
114
+ for (const [name, system] of project.systems) {
115
+ console.log(name, system.length); // System name and duration
116
+ for (const emitter of system.prims) {
117
+ console.log(emitter.name, emitter.textures);
118
+ }
119
+ }
51
120
  ```
52
121
 
53
122
  ### Browser Usage
54
123
 
55
- This library can also be used in the browser. You will need a bundler like Webpack or Rollup to handle the Node.js `Buffer` dependency.
124
+ The library works in browsers with a Buffer polyfill (provided by bundlers like Webpack, Vite, or esbuild):
56
125
 
57
- ```javascript
126
+ ```typescript
58
127
  import { DffParser } from 'rw-parser-ng';
59
128
 
60
- async function parseDffFromUrl(url) {
61
- const response = await fetch(url);
62
- const arrayBuffer = await response.arrayBuffer();
63
- const buffer = Buffer.from(arrayBuffer); // Requires Buffer polyfill
129
+ const response = await fetch('model.dff');
130
+ const arrayBuffer = await response.arrayBuffer();
131
+ const buffer = Buffer.from(arrayBuffer);
132
+
133
+ const parser = new DffParser(buffer);
134
+ const dff = parser.parse();
135
+ ```
136
+
137
+ ## API Reference
138
+
139
+ ### DFF Parser
140
+
141
+ The `DffParser` class parses RenderWare Clump structures:
142
+
143
+ ```typescript
144
+ interface RwDff {
145
+ modelType: DffModelType; // GENERIC, SKIN, or VEHICLE
146
+ version: string; // Human-readable version
147
+ versionNumber: number; // Numeric version
148
+ geometryList: RwGeometryList; // Meshes with vertices, normals, UVs
149
+ frameList: RwFrameList; // Bone/node hierarchy
150
+ atomics: number[]; // Geometry-to-frame mapping
151
+ dummies: string[]; // Node names
152
+ animNodes: RwAnimNode[]; // Animation node data
153
+ }
154
+ ```
155
+
156
+ Geometry data includes:
157
+ - Vertex positions and normals
158
+ - Texture coordinates (multiple UV sets)
159
+ - Vertex colors
160
+ - Triangle indices
161
+ - Materials with textures
162
+ - BinMesh data for rendering
163
+ - Skin weights and bone matrices
164
+
165
+ ### TXD Parser
166
+
167
+ The `TxdParser` class parses texture dictionaries:
64
168
 
65
- const dffParser = new DffParser(buffer);
66
- const dffData = dffParser.parse();
67
- console.log(dffData);
169
+ ```typescript
170
+ interface RwTextureNative {
171
+ platformId: number; // D3D8 (0x8) or D3D9 (0x9)
172
+ textureName: string;
173
+ maskName: string;
174
+ width: number;
175
+ height: number;
176
+ depth: number; // Bits per pixel
177
+ d3dFormat: string; // DXT1, DXT3, DXT5, etc.
178
+ mipmaps: number[][]; // Decoded BGRA data
179
+ alpha: boolean;
180
+ compressed: boolean;
68
181
  }
182
+ ```
183
+
184
+ Supported texture formats:
185
+ - DXT1, DXT2, DXT3, DXT4, DXT5 (S3TC compression)
186
+ - Paletted 4-bit and 8-bit
187
+ - BGRA 8888, 888, 565, 555, 1555, 4444
188
+ - Luminance 8-bit, A8L8
189
+
190
+ ### IFP Parser
191
+
192
+ The `IfpParser` class parses animation files:
69
193
 
70
- parseDffFromUrl('path/to/your/model.dff');
194
+ ```typescript
195
+ interface RwIfp {
196
+ version: IfpVersion; // ANP3 or ANPK
197
+ name: string;
198
+ animations: RwIfpAnimation[];
199
+ }
200
+
201
+ interface RwIfpKeyframe {
202
+ time: number;
203
+ position: RwVector3;
204
+ rotation: RwQuaternion;
205
+ scale: RwVector3;
206
+ }
207
+ ```
208
+
209
+ ### FXP Parser
210
+
211
+ The FXP parser handles GTA San Andreas particle effect definitions:
212
+
213
+ ```typescript
214
+ interface FxProject {
215
+ systems: Map<string, FxSystemBP>;
216
+ }
217
+
218
+ interface FxSystemBP {
219
+ name: string;
220
+ length: number;
221
+ playMode: number;
222
+ cullDist: number;
223
+ boundingSphere: FxBoundingSphere;
224
+ prims: FxEmitterBP[];
225
+ }
226
+ ```
227
+
228
+ Supported effect info types: emrate, emsize, emspeed, emdir, emangle, emlife, empos, emweather, emrotation, noise, force, friction, attractpt, attractline, groundcollide, wind, jitter, rotspeed, float, underwater, colour, size, spriterect, heathaze, trail, flat, dir, animtex, colourrange, selflit, colourbright, smoke.
229
+
230
+ ## Project Structure
231
+
232
+ ```
233
+ src/
234
+ ├── core/ # Base classes: ByteStream, RwFile, section definitions
235
+ ├── common/ # Shared types: vectors, matrices, colors, quaternions
236
+ ├── codecs/ # Texture decoders: DXT, palette, raster formats
237
+ ├── dff/ # DFF parser and geometry readers
238
+ ├── txd/ # TXD parser and bitmap decoder
239
+ ├── ifp/ # IFP parser (ANP3, ANPK readers)
240
+ └── fxp/ # FXP parser and info type handlers
71
241
  ```
72
242
 
73
243
  ## Development
74
244
 
75
- 1. Clone the repository: `git clone https://github.com/DepsCian/rw-parser-ng.git`
76
- 2. Install dependencies: `pnpm install`
77
- 3. Build the project: `pnpm run build`
78
- 4. Run tests: `pnpm test`
245
+ Requirements: [Bun](https://bun.sh/) runtime
246
+
247
+ ```sh
248
+ # Install dependencies
249
+ bun install
79
250
 
80
- To watch for changes during development, use `pnpm run dev`.
251
+ # Build
252
+ bun run build
253
+
254
+ # Watch mode
255
+ bun run dev
256
+
257
+ # Run tests
258
+ bun test
259
+
260
+ # Lint
261
+ bun run lint
262
+
263
+ # Format
264
+ bun run format
265
+ ```
81
266
 
82
267
  ## Contributing
83
268
 
84
- Contributions are welcome! Please feel free to open an issue or submit a pull request.
269
+ Contributions are welcome. Please open an issue or submit a pull request.
270
+
271
+ When contributing:
272
+ 1. Fork the repository
273
+ 2. Create a feature branch
274
+ 3. Ensure tests pass with `bun test`
275
+ 4. Ensure code passes lint with `bun run lint`
276
+ 5. Submit a pull request
277
+
278
+ ## Credits
279
+
280
+ - [Timic3](https://github.com/Timic3) - Original rw-parser author
281
+ - [MegadreamsBE](https://github.com/MegadreamsBE) - Contributor
282
+ - [AlterSDB](https://github.com/AlterSDB) - Contributor
283
+ - [librw](https://github.com/aap/librw) - RenderWare reference implementation
284
+ - [gta-reversed](https://github.com/gta-reversed/gta-reversed-modern) - GTA SA reverse engineering
85
285
 
86
286
  ## License
87
287
 
88
- This project is licensed under the GPL-3.0 License. See the [LICENSE](LICENSE) file for details.
288
+ GPL-3.0 - See [LICENSE](LICENSE) for details.
@@ -0,0 +1,6 @@
1
+ export declare function bgra1555(data: Uint8Array, width: number, height: number): Uint8Array;
2
+ export declare function bgra4444(data: Uint8Array, width: number, height: number): Uint8Array;
3
+ export declare function bgra555(data: Uint8Array, width: number, height: number): Uint8Array;
4
+ export declare function bgra565(data: Uint8Array, width: number, height: number): Uint8Array;
5
+ export declare function bgra888(data: Uint8Array, width: number, height: number): Uint8Array;
6
+ export declare function bgra8888(data: Uint8Array, width: number, height: number): Uint8Array;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bgra1555 = bgra1555;
4
+ exports.bgra4444 = bgra4444;
5
+ exports.bgra555 = bgra555;
6
+ exports.bgra565 = bgra565;
7
+ exports.bgra888 = bgra888;
8
+ exports.bgra8888 = bgra8888;
9
+ var color_1 = require("./color");
10
+ function bgra1555(data, width, height) {
11
+ var rgba = new Uint8Array(4 * width * height);
12
+ var offset = 0;
13
+ for (var i = 0; i < data.length; i += 2) {
14
+ var _a = (0, color_1.decode1555)((0, color_1.readUInt16LE)(data, i)), a = _a[0], r = _a[1], g = _a[2], b = _a[3];
15
+ rgba[offset++] = r;
16
+ rgba[offset++] = g;
17
+ rgba[offset++] = b;
18
+ rgba[offset++] = a;
19
+ }
20
+ return rgba;
21
+ }
22
+ function bgra4444(data, width, height) {
23
+ var rgba = new Uint8Array(4 * width * height);
24
+ var offset = 0;
25
+ for (var i = 0; i < data.length; i += 2) {
26
+ var _a = (0, color_1.decode4444)((0, color_1.readUInt16LE)(data, i)), a = _a[0], r = _a[1], g = _a[2], b = _a[3];
27
+ rgba[offset++] = r;
28
+ rgba[offset++] = g;
29
+ rgba[offset++] = b;
30
+ rgba[offset++] = a;
31
+ }
32
+ return rgba;
33
+ }
34
+ function bgra555(data, width, height) {
35
+ var rgba = new Uint8Array(4 * width * height);
36
+ var offset = 0;
37
+ for (var i = 0; i < data.length; i += 2) {
38
+ var _a = (0, color_1.decode555)((0, color_1.readUInt16LE)(data, i)), r = _a[0], g = _a[1], b = _a[2];
39
+ rgba[offset++] = r;
40
+ rgba[offset++] = g;
41
+ rgba[offset++] = b;
42
+ rgba[offset++] = 0xff;
43
+ }
44
+ return rgba;
45
+ }
46
+ function bgra565(data, width, height) {
47
+ var rgba = new Uint8Array(4 * width * height);
48
+ var offset = 0;
49
+ for (var i = 0; i < data.length; i += 2) {
50
+ var _a = (0, color_1.decode565)((0, color_1.readUInt16LE)(data, i)), r = _a[0], g = _a[1], b = _a[2];
51
+ rgba[offset++] = r;
52
+ rgba[offset++] = g;
53
+ rgba[offset++] = b;
54
+ rgba[offset++] = 0xff;
55
+ }
56
+ return rgba;
57
+ }
58
+ function bgra888(data, width, height) {
59
+ var rgba = new Uint8Array(4 * width * height);
60
+ for (var i = 0; i < data.length; i += 4) {
61
+ rgba[i] = data[i + 2];
62
+ rgba[i + 1] = data[i + 1];
63
+ rgba[i + 2] = data[i];
64
+ rgba[i + 3] = 0xff;
65
+ }
66
+ return rgba;
67
+ }
68
+ function bgra8888(data, width, height) {
69
+ var rgba = new Uint8Array(4 * width * height);
70
+ for (var i = 0; i < data.length; i += 4) {
71
+ rgba[i] = data[i + 2];
72
+ rgba[i + 1] = data[i + 1];
73
+ rgba[i + 2] = data[i];
74
+ rgba[i + 3] = data[i + 3];
75
+ }
76
+ return rgba;
77
+ }
@@ -0,0 +1,6 @@
1
+ export declare function readUInt16LE(buf: Uint8Array, offset: number): number;
2
+ export declare function readUInt32LE(buf: Uint8Array, offset: number): number;
3
+ export declare function decode565(bits: number): [number, number, number];
4
+ export declare function decode555(bits: number): [number, number, number];
5
+ export declare function decode1555(bits: number): [number, number, number, number];
6
+ export declare function decode4444(bits: number): [number, number, number, number];
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readUInt16LE = readUInt16LE;
4
+ exports.readUInt32LE = readUInt32LE;
5
+ exports.decode565 = decode565;
6
+ exports.decode555 = decode555;
7
+ exports.decode1555 = decode1555;
8
+ exports.decode4444 = decode4444;
9
+ function readUInt16LE(buf, offset) {
10
+ return buf[offset] | (buf[offset + 1] << 8);
11
+ }
12
+ function readUInt32LE(buf, offset) {
13
+ return buf[offset] | (buf[offset + 1] << 8) | (buf[offset + 2] << 16) | (buf[offset + 3] << 24);
14
+ }
15
+ function decode565(bits) {
16
+ var r = (bits >> 11) & 31;
17
+ var g = (bits >> 5) & 63;
18
+ var b = bits & 31;
19
+ return [(r << 3) | (r >> 2), (g << 2) | (g >> 4), (b << 3) | (b >> 2)];
20
+ }
21
+ function decode555(bits) {
22
+ return [
23
+ Math.round((((bits >> 10) & 31) * 255) / 31),
24
+ Math.round((((bits >> 5) & 31) * 255) / 31),
25
+ Math.round(((bits & 31) * 255) / 31),
26
+ ];
27
+ }
28
+ function decode1555(bits) {
29
+ return [
30
+ Math.round(((bits >> 15) & 1) * 255),
31
+ Math.round((((bits >> 10) & 31) * 255) / 31),
32
+ Math.round((((bits >> 5) & 31) * 255) / 31),
33
+ Math.round(((bits & 31) * 255) / 31),
34
+ ];
35
+ }
36
+ function decode4444(bits) {
37
+ return [
38
+ Math.round((((bits >> 12) & 15) * 255) / 15),
39
+ Math.round((((bits >> 8) & 15) * 255) / 15),
40
+ Math.round((((bits >> 4) & 15) * 255) / 15),
41
+ Math.round(((bits & 15) * 255) / 15),
42
+ ];
43
+ }
@@ -0,0 +1,3 @@
1
+ export declare function bc1(data: Uint8Array, width: number, height: number): Uint8Array;
2
+ export declare function bc2(data: Uint8Array, width: number, height: number, premultiplied: boolean): Uint8Array;
3
+ export declare function bc3(data: Uint8Array, width: number, height: number, premultiplied: boolean): Uint8Array;