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
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bc1 = bc1;
4
+ exports.bc2 = bc2;
5
+ exports.bc3 = bc3;
6
+ var color_1 = require("./color");
7
+ function bc1(data, width, height) {
8
+ var rgba = new Uint8Array(4 * width * height);
9
+ var colorPalette = new Uint8Array(16);
10
+ var offset = 0;
11
+ for (var y = 0; y < height; y += 4) {
12
+ for (var x = 0; x < width; x += 4) {
13
+ var color0 = (0, color_1.readUInt16LE)(data, offset);
14
+ var color1 = (0, color_1.readUInt16LE)(data, offset + 2);
15
+ var colorBits = (0, color_1.readUInt32LE)(data, offset + 4);
16
+ offset += 8;
17
+ var _a = (0, color_1.decode565)(color0), c0r = _a[0], c0g = _a[1], c0b = _a[2];
18
+ var _b = (0, color_1.decode565)(color1), c1r = _b[0], c1g = _b[1], c1b = _b[2];
19
+ colorPalette[0] = c0r;
20
+ colorPalette[1] = c0g;
21
+ colorPalette[2] = c0b;
22
+ colorPalette[4] = c1r;
23
+ colorPalette[5] = c1g;
24
+ colorPalette[6] = c1b;
25
+ if (color0 > color1) {
26
+ colorPalette[8] = (2 * c0r + c1r) / 3;
27
+ colorPalette[9] = (2 * c0g + c1g) / 3;
28
+ colorPalette[10] = (2 * c0b + c1b) / 3;
29
+ colorPalette[12] = (c0r + 2 * c1r) / 3;
30
+ colorPalette[13] = (c0g + 2 * c1g) / 3;
31
+ colorPalette[14] = (c0b + 2 * c1b) / 3;
32
+ }
33
+ else {
34
+ colorPalette[8] = (c0r + c1r) >> 1;
35
+ colorPalette[9] = (c0g + c1g) >> 1;
36
+ colorPalette[10] = (c0b + c1b) >> 1;
37
+ colorPalette[12] = 0;
38
+ colorPalette[13] = 0;
39
+ colorPalette[14] = 0;
40
+ }
41
+ var baseIndex = (y * width + x) * 4;
42
+ for (var k = 0; k < 16; k++) {
43
+ var colorIdx = colorBits & 0x3;
44
+ colorBits >>>= 2;
45
+ var j = k >> 2, i = k & 3;
46
+ var idx = baseIndex + ((j * width + i) << 2);
47
+ rgba[idx] = colorPalette[colorIdx * 4];
48
+ rgba[idx + 1] = colorPalette[colorIdx * 4 + 1];
49
+ rgba[idx + 2] = colorPalette[colorIdx * 4 + 2];
50
+ rgba[idx + 3] = color0 <= color1 && colorIdx === 3 ? 0 : 255;
51
+ }
52
+ }
53
+ }
54
+ return rgba;
55
+ }
56
+ function bc2(data, width, height, premultiplied) {
57
+ var rgba = new Uint8Array(4 * width * height);
58
+ var colorPalette = new Uint8Array(16);
59
+ var alphaTable = new Uint8Array(16);
60
+ for (var i = 0; i < 16; i++)
61
+ alphaTable[i] = ((i * 255 + 7.5) / 15) | 0;
62
+ var offset = 0;
63
+ for (var y = 0; y < height; y += 4) {
64
+ for (var x = 0; x < width; x += 4) {
65
+ var alpha0 = (0, color_1.readUInt32LE)(data, offset);
66
+ var alpha1 = (0, color_1.readUInt32LE)(data, offset + 4);
67
+ offset += 8;
68
+ var color0 = (0, color_1.readUInt16LE)(data, offset);
69
+ var color1 = (0, color_1.readUInt16LE)(data, offset + 2);
70
+ var colorBits = (0, color_1.readUInt32LE)(data, offset + 4);
71
+ offset += 8;
72
+ var _a = (0, color_1.decode565)(color0), c0r = _a[0], c0g = _a[1], c0b = _a[2];
73
+ var _b = (0, color_1.decode565)(color1), c1r = _b[0], c1g = _b[1], c1b = _b[2];
74
+ colorPalette[0] = c0r;
75
+ colorPalette[1] = c0g;
76
+ colorPalette[2] = c0b;
77
+ colorPalette[4] = c1r;
78
+ colorPalette[5] = c1g;
79
+ colorPalette[6] = c1b;
80
+ if (color0 > color1) {
81
+ colorPalette[8] = (2 * c0r + c1r) / 3;
82
+ colorPalette[9] = (2 * c0g + c1g) / 3;
83
+ colorPalette[10] = (2 * c0b + c1b) / 3;
84
+ colorPalette[12] = (c0r + 2 * c1r) / 3;
85
+ colorPalette[13] = (c0g + 2 * c1g) / 3;
86
+ colorPalette[14] = (c0b + 2 * c1b) / 3;
87
+ }
88
+ else {
89
+ colorPalette[8] = (c0r + c1r) >> 1;
90
+ colorPalette[9] = (c0g + c1g) >> 1;
91
+ colorPalette[10] = (c0b + c1b) >> 1;
92
+ colorPalette[12] = 0;
93
+ colorPalette[13] = 0;
94
+ colorPalette[14] = 0;
95
+ }
96
+ var baseIndex = (y * width + x) << 2;
97
+ for (var k = 0; k < 16; k++) {
98
+ var j = k >> 2, i = k & 3;
99
+ var idx = baseIndex + ((j * width + i) << 2);
100
+ var colorIdx = colorBits & 0x3;
101
+ colorBits >>>= 2;
102
+ var bitPos = (j << 2) + i;
103
+ var byteIndex = bitPos >> 3;
104
+ var shift = (bitPos & 7) << 2;
105
+ var alpha4 = ((byteIndex === 0 ? alpha0 : alpha1) >>> shift) & 0xf;
106
+ var alpha = alphaTable[alpha4];
107
+ rgba[idx] = colorPalette[colorIdx * 4];
108
+ rgba[idx + 1] = colorPalette[colorIdx * 4 + 1];
109
+ rgba[idx + 2] = colorPalette[colorIdx * 4 + 2];
110
+ rgba[idx + 3] = alpha;
111
+ if (premultiplied && alpha > 0 && alpha < 255) {
112
+ var factor = 255 / alpha;
113
+ rgba[idx] = Math.min(255, Math.round(rgba[idx] * factor));
114
+ rgba[idx + 1] = Math.min(255, Math.round(rgba[idx + 1] * factor));
115
+ rgba[idx + 2] = Math.min(255, Math.round(rgba[idx + 2] * factor));
116
+ }
117
+ }
118
+ }
119
+ }
120
+ return rgba;
121
+ }
122
+ function bc3(data, width, height, premultiplied) {
123
+ var rgba = new Uint8Array(4 * width * height);
124
+ var alphaPalette = new Uint8Array(8);
125
+ var colorPalette = new Uint8Array(16);
126
+ var alphaIndices = new Uint8Array(16);
127
+ var offset = 0;
128
+ for (var y = 0; y < height; y += 4) {
129
+ for (var x = 0; x < width; x += 4) {
130
+ var alpha0 = data[offset++];
131
+ var alpha1 = data[offset++];
132
+ var alphaBits = data.subarray(offset, offset + 6);
133
+ offset += 6;
134
+ var color0 = (0, color_1.readUInt16LE)(data, offset);
135
+ var color1 = (0, color_1.readUInt16LE)(data, offset + 2);
136
+ var colorBits = (0, color_1.readUInt32LE)(data, offset + 4);
137
+ offset += 8;
138
+ var _a = (0, color_1.decode565)(color0), c0r = _a[0], c0g = _a[1], c0b = _a[2];
139
+ var _b = (0, color_1.decode565)(color1), c1r = _b[0], c1g = _b[1], c1b = _b[2];
140
+ colorPalette[0] = c0r;
141
+ colorPalette[1] = c0g;
142
+ colorPalette[2] = c0b;
143
+ colorPalette[4] = c1r;
144
+ colorPalette[5] = c1g;
145
+ colorPalette[6] = c1b;
146
+ if (color0 > color1) {
147
+ colorPalette[8] = (2 * c0r + c1r) / 3;
148
+ colorPalette[9] = (2 * c0g + c1g) / 3;
149
+ colorPalette[10] = (2 * c0b + c1b) / 3;
150
+ colorPalette[12] = (c0r + 2 * c1r) / 3;
151
+ colorPalette[13] = (c0g + 2 * c1g) / 3;
152
+ colorPalette[14] = (c0b + 2 * c1b) / 3;
153
+ }
154
+ else {
155
+ colorPalette[8] = (c0r + c1r) >> 1;
156
+ colorPalette[9] = (c0g + c1g) >> 1;
157
+ colorPalette[10] = (c0b + c1b) >> 1;
158
+ colorPalette[12] = 0;
159
+ colorPalette[13] = 0;
160
+ colorPalette[14] = 0;
161
+ }
162
+ if (alpha0 > alpha1) {
163
+ alphaPalette[0] = alpha0;
164
+ alphaPalette[1] = alpha1;
165
+ alphaPalette[2] = (alpha0 * 6 + alpha1 + 3) / 7;
166
+ alphaPalette[3] = (alpha0 * 5 + alpha1 * 2 + 3) / 7;
167
+ alphaPalette[4] = (alpha0 * 4 + alpha1 * 3 + 3) / 7;
168
+ alphaPalette[5] = (alpha0 * 3 + alpha1 * 4 + 3) / 7;
169
+ alphaPalette[6] = (alpha0 * 2 + alpha1 * 5 + 3) / 7;
170
+ alphaPalette[7] = (alpha0 + alpha1 * 6 + 3) / 7;
171
+ }
172
+ else {
173
+ alphaPalette[0] = alpha0;
174
+ alphaPalette[1] = alpha1;
175
+ alphaPalette[2] = (alpha0 * 4 + alpha1 + 2) / 5;
176
+ alphaPalette[3] = (alpha0 * 3 + alpha1 * 2 + 2) / 5;
177
+ alphaPalette[4] = (alpha0 * 2 + alpha1 * 3 + 2) / 5;
178
+ alphaPalette[5] = (alpha0 + alpha1 * 4 + 2) / 5;
179
+ alphaPalette[6] = 0;
180
+ alphaPalette[7] = 255;
181
+ }
182
+ for (var k = 0; k < 16; k++) {
183
+ var bitOffset = k * 3;
184
+ var byteOffset = bitOffset >> 3;
185
+ var shift = bitOffset & 7;
186
+ alphaIndices[k] =
187
+ shift <= 5
188
+ ? (alphaBits[byteOffset] >> shift) & 0x7
189
+ : ((alphaBits[byteOffset] >> shift) | (alphaBits[byteOffset + 1] << (8 - shift))) & 0x7;
190
+ }
191
+ var baseIndex = (y * width + x) << 2;
192
+ for (var k = 0; k < 16; k++) {
193
+ var j = k >> 2, i = k & 3;
194
+ var idx = baseIndex + ((j * width + i) << 2);
195
+ var colorIdx = colorBits & 0x3;
196
+ colorBits >>>= 2;
197
+ var alpha = alphaPalette[alphaIndices[k] & 0x7];
198
+ rgba[idx] = colorPalette[colorIdx * 4];
199
+ rgba[idx + 1] = colorPalette[colorIdx * 4 + 1];
200
+ rgba[idx + 2] = colorPalette[colorIdx * 4 + 2];
201
+ rgba[idx + 3] = alpha;
202
+ if (premultiplied && alpha > 0 && alpha < 255) {
203
+ var factor = 255 / alpha;
204
+ rgba[idx] = Math.min(255, Math.round(rgba[idx] * factor));
205
+ rgba[idx + 1] = Math.min(255, Math.round(rgba[idx + 1] * factor));
206
+ rgba[idx + 2] = Math.min(255, Math.round(rgba[idx + 2] * factor));
207
+ }
208
+ }
209
+ }
210
+ }
211
+ return rgba;
212
+ }
@@ -0,0 +1,25 @@
1
+ export declare enum RasterFormat {
2
+ RASTER_1555 = 256,
3
+ RASTER_565 = 512,
4
+ RASTER_4444 = 768,
5
+ RASTER_LUM = 1024,
6
+ RASTER_8888 = 1280,
7
+ RASTER_888 = 1536,
8
+ RASTER_555 = 2560
9
+ }
10
+ export declare enum D3DFormat {
11
+ D3DFMT_A8L8 = "3",
12
+ D3D_DXT1 = "DXT1",
13
+ D3D_DXT2 = "DXT2",
14
+ D3D_DXT3 = "DXT3",
15
+ D3D_DXT4 = "DXT4",
16
+ D3D_DXT5 = "DXT5"
17
+ }
18
+ export declare enum PaletteType {
19
+ PALETTE_NONE = 0,
20
+ PALETTE_8 = 1
21
+ }
22
+ export declare enum PlatformType {
23
+ D3D8 = 8,
24
+ D3D9 = 9
25
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlatformType = exports.PaletteType = exports.D3DFormat = exports.RasterFormat = void 0;
4
+ var RasterFormat;
5
+ (function (RasterFormat) {
6
+ RasterFormat[RasterFormat["RASTER_1555"] = 256] = "RASTER_1555";
7
+ RasterFormat[RasterFormat["RASTER_565"] = 512] = "RASTER_565";
8
+ RasterFormat[RasterFormat["RASTER_4444"] = 768] = "RASTER_4444";
9
+ RasterFormat[RasterFormat["RASTER_LUM"] = 1024] = "RASTER_LUM";
10
+ RasterFormat[RasterFormat["RASTER_8888"] = 1280] = "RASTER_8888";
11
+ RasterFormat[RasterFormat["RASTER_888"] = 1536] = "RASTER_888";
12
+ RasterFormat[RasterFormat["RASTER_555"] = 2560] = "RASTER_555";
13
+ })(RasterFormat || (exports.RasterFormat = RasterFormat = {}));
14
+ var D3DFormat;
15
+ (function (D3DFormat) {
16
+ D3DFormat["D3DFMT_A8L8"] = "3";
17
+ D3DFormat["D3D_DXT1"] = "DXT1";
18
+ D3DFormat["D3D_DXT2"] = "DXT2";
19
+ D3DFormat["D3D_DXT3"] = "DXT3";
20
+ D3DFormat["D3D_DXT4"] = "DXT4";
21
+ D3DFormat["D3D_DXT5"] = "DXT5";
22
+ })(D3DFormat || (exports.D3DFormat = D3DFormat = {}));
23
+ var PaletteType;
24
+ (function (PaletteType) {
25
+ PaletteType[PaletteType["PALETTE_NONE"] = 0] = "PALETTE_NONE";
26
+ PaletteType[PaletteType["PALETTE_8"] = 1] = "PALETTE_8";
27
+ })(PaletteType || (exports.PaletteType = PaletteType = {}));
28
+ var PlatformType;
29
+ (function (PlatformType) {
30
+ PlatformType[PlatformType["D3D8"] = 8] = "D3D8";
31
+ PlatformType[PlatformType["D3D9"] = 9] = "D3D9";
32
+ })(PlatformType || (exports.PlatformType = PlatformType = {}));
@@ -0,0 +1,5 @@
1
+ export * from "./bitmap";
2
+ export * from "./color";
3
+ export * from "./dxt";
4
+ export * from "./formats";
5
+ export * from "./palette";
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./bitmap"), exports);
18
+ __exportStar(require("./color"), exports);
19
+ __exportStar(require("./dxt"), exports);
20
+ __exportStar(require("./formats"), exports);
21
+ __exportStar(require("./palette"), exports);
@@ -0,0 +1,6 @@
1
+ export declare function lum8(data: Uint8Array, width: number, height: number): Uint8Array;
2
+ export declare function lum8a8(data: Uint8Array, width: number, height: number): Uint8Array;
3
+ export declare function pal4(data: Uint8Array, palette: Uint8Array, width: number, height: number): Uint8Array;
4
+ export declare function pal4NoAlpha(data: Uint8Array, palette: Uint8Array, width: number, height: number): Uint8Array;
5
+ export declare function pal8(data: Uint8Array, palette: Uint8Array, width: number, height: number): Uint8Array;
6
+ export declare function pal8NoAlpha(data: Uint8Array, palette: Uint8Array, width: number, height: number): Uint8Array;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lum8 = lum8;
4
+ exports.lum8a8 = lum8a8;
5
+ exports.pal4 = pal4;
6
+ exports.pal4NoAlpha = pal4NoAlpha;
7
+ exports.pal8 = pal8;
8
+ exports.pal8NoAlpha = pal8NoAlpha;
9
+ function lum8(data, width, height) {
10
+ var rgba = new Uint8Array(4 * width * height);
11
+ for (var i = 0; i < data.length; i++) {
12
+ var offset = i * 4;
13
+ var lum = data[i];
14
+ rgba[offset] = lum;
15
+ rgba[offset + 1] = lum;
16
+ rgba[offset + 2] = lum;
17
+ rgba[offset + 3] = 0xff;
18
+ }
19
+ return rgba;
20
+ }
21
+ function lum8a8(data, width, height) {
22
+ var rgba = new Uint8Array(4 * width * height);
23
+ var offset = 0;
24
+ for (var i = 0; i < data.length; i += 2) {
25
+ var lum = data[i], alpha = data[i + 1];
26
+ rgba[offset++] = lum;
27
+ rgba[offset++] = lum;
28
+ rgba[offset++] = lum;
29
+ rgba[offset++] = alpha;
30
+ }
31
+ return rgba;
32
+ }
33
+ function pal4(data, palette, width, height) {
34
+ var rgba = new Uint8Array(4 * width * height);
35
+ var offset = 0;
36
+ for (var i = 0; i < data.length; i++) {
37
+ var idx1 = (data[i] >> 4) & 0xf, idx2 = data[i] & 0xf;
38
+ rgba[offset++] = palette[idx1 * 4];
39
+ rgba[offset++] = palette[idx1 * 4 + 1];
40
+ rgba[offset++] = palette[idx1 * 4 + 2];
41
+ rgba[offset++] = palette[idx1 * 4 + 3];
42
+ rgba[offset++] = palette[idx2 * 4];
43
+ rgba[offset++] = palette[idx2 * 4 + 1];
44
+ rgba[offset++] = palette[idx2 * 4 + 2];
45
+ rgba[offset++] = palette[idx2 * 4 + 3];
46
+ }
47
+ return rgba;
48
+ }
49
+ function pal4NoAlpha(data, palette, width, height) {
50
+ var rgba = new Uint8Array(4 * width * height);
51
+ var offset = 0;
52
+ for (var i = 0; i < data.length; i++) {
53
+ var idx1 = (data[i] >> 4) & 0xf, idx2 = data[i] & 0xf;
54
+ rgba[offset++] = palette[idx1 * 4];
55
+ rgba[offset++] = palette[idx1 * 4 + 1];
56
+ rgba[offset++] = palette[idx1 * 4 + 2];
57
+ rgba[offset++] = 0xff;
58
+ rgba[offset++] = palette[idx2 * 4];
59
+ rgba[offset++] = palette[idx2 * 4 + 1];
60
+ rgba[offset++] = palette[idx2 * 4 + 2];
61
+ rgba[offset++] = 0xff;
62
+ }
63
+ return rgba;
64
+ }
65
+ function pal8(data, palette, width, height) {
66
+ var rgba = new Uint8Array(4 * width * height);
67
+ for (var i = 0; i < data.length; i++) {
68
+ var idx = data[i];
69
+ rgba[i * 4] = palette[idx * 4];
70
+ rgba[i * 4 + 1] = palette[idx * 4 + 1];
71
+ rgba[i * 4 + 2] = palette[idx * 4 + 2];
72
+ rgba[i * 4 + 3] = palette[idx * 4 + 3];
73
+ }
74
+ return rgba;
75
+ }
76
+ function pal8NoAlpha(data, palette, width, height) {
77
+ var rgba = new Uint8Array(4 * width * height);
78
+ for (var i = 0; i < data.length; i++) {
79
+ var idx = data[i];
80
+ rgba[i * 4] = palette[idx * 4];
81
+ rgba[i * 4 + 1] = palette[idx * 4 + 1];
82
+ rgba[i * 4 + 2] = palette[idx * 4 + 2];
83
+ rgba[i * 4 + 3] = 0xff;
84
+ }
85
+ return rgba;
86
+ }
@@ -0,0 +1,50 @@
1
+ export interface RwVector2 {
2
+ x: number;
3
+ y: number;
4
+ }
5
+ export interface RwVector3 {
6
+ x: number;
7
+ y: number;
8
+ z: number;
9
+ }
10
+ export interface RwVector4 {
11
+ x: number;
12
+ y: number;
13
+ z: number;
14
+ t: number;
15
+ }
16
+ export interface RwQuaternion {
17
+ x: number;
18
+ y: number;
19
+ z: number;
20
+ w: number;
21
+ }
22
+ export interface RwMatrix3 {
23
+ right: RwVector3;
24
+ up: RwVector3;
25
+ at: RwVector3;
26
+ }
27
+ export interface RwMatrix4 {
28
+ right: RwVector4;
29
+ up: RwVector4;
30
+ at: RwVector4;
31
+ transform: RwVector4;
32
+ }
33
+ export interface RwColor {
34
+ r: number;
35
+ g: number;
36
+ b: number;
37
+ a: number;
38
+ }
39
+ export interface RwTextureCoordinate {
40
+ u: number;
41
+ v: number;
42
+ }
43
+ export interface RwTriangle {
44
+ vector: RwVector3;
45
+ materialId: number;
46
+ }
47
+ export interface RwSphere {
48
+ vector: RwVector3;
49
+ radius: number;
50
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,20 @@
1
+ export declare class ByteStream {
2
+ private _cursor;
3
+ private _stream;
4
+ constructor(stream: Buffer);
5
+ readUint8(): number;
6
+ readUint16(): number;
7
+ readUint32(): number;
8
+ readInt16(): number;
9
+ readInt8(): number;
10
+ readInt32(): number;
11
+ readFloat(): number;
12
+ readString(size: number): string;
13
+ readBytes(size: number): Uint8Array;
14
+ read(size: number): Uint8Array;
15
+ getSize(): number;
16
+ getPosition(): number;
17
+ setPosition(position: number): void;
18
+ skip(size: number): void;
19
+ dispose(): void;
20
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ByteStream = void 0;
4
+ var ByteStream = /** @class */ (function () {
5
+ function ByteStream(stream) {
6
+ this._cursor = 0;
7
+ this._stream = stream;
8
+ }
9
+ ByteStream.prototype.readUint8 = function () {
10
+ return this._stream.readUInt8(this._cursor++);
11
+ };
12
+ ByteStream.prototype.readUint16 = function () {
13
+ var val = this._stream.readUInt16LE(this._cursor);
14
+ this._cursor += 2;
15
+ return val;
16
+ };
17
+ ByteStream.prototype.readUint32 = function () {
18
+ var val = this._stream.readUInt32LE(this._cursor);
19
+ this._cursor += 4;
20
+ return val;
21
+ };
22
+ ByteStream.prototype.readInt16 = function () {
23
+ var val = this._stream.readInt16LE(this._cursor);
24
+ this._cursor += 2;
25
+ return val;
26
+ };
27
+ ByteStream.prototype.readInt8 = function () {
28
+ return this._stream.readInt8(this._cursor++);
29
+ };
30
+ ByteStream.prototype.readInt32 = function () {
31
+ var val = this._stream.readInt32LE(this._cursor);
32
+ this._cursor += 4;
33
+ return val;
34
+ };
35
+ ByteStream.prototype.readFloat = function () {
36
+ var val = this._stream.readFloatLE(this._cursor);
37
+ this._cursor += 4;
38
+ return val;
39
+ };
40
+ ByteStream.prototype.readString = function (size) {
41
+ var str = this._stream.toString("ascii", this._cursor, this._cursor + size);
42
+ this._cursor += size;
43
+ return str.split(/\0/g).shift() || "";
44
+ };
45
+ ByteStream.prototype.readBytes = function (size) {
46
+ var data = this._stream.subarray(this._cursor, this._cursor + size);
47
+ this._cursor += size;
48
+ return new Uint8Array(data);
49
+ };
50
+ ByteStream.prototype.read = function (size) {
51
+ return this.readBytes(size);
52
+ };
53
+ ByteStream.prototype.getSize = function () {
54
+ return this._stream.byteLength;
55
+ };
56
+ ByteStream.prototype.getPosition = function () {
57
+ return this._cursor;
58
+ };
59
+ ByteStream.prototype.setPosition = function (position) {
60
+ this._cursor = position;
61
+ };
62
+ ByteStream.prototype.skip = function (size) {
63
+ this._cursor += size;
64
+ };
65
+ ByteStream.prototype.dispose = function () {
66
+ this._stream = Buffer.alloc(0);
67
+ this._cursor = 0;
68
+ };
69
+ return ByteStream;
70
+ }());
71
+ exports.ByteStream = ByteStream;
@@ -0,0 +1,5 @@
1
+ export declare class RwParseError extends Error {
2
+ }
3
+ export declare class RwParseStructureNotFoundError extends RwParseError {
4
+ constructor(structureName: string);
5
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.RwParseStructureNotFoundError = exports.RwParseError = void 0;
19
+ var RwParseError = /** @class */ (function (_super) {
20
+ __extends(RwParseError, _super);
21
+ function RwParseError() {
22
+ return _super !== null && _super.apply(this, arguments) || this;
23
+ }
24
+ return RwParseError;
25
+ }(Error));
26
+ exports.RwParseError = RwParseError;
27
+ var RwParseStructureNotFoundError = /** @class */ (function (_super) {
28
+ __extends(RwParseStructureNotFoundError, _super);
29
+ function RwParseStructureNotFoundError(structureName) {
30
+ return _super.call(this, "Structure ".concat(structureName, " not found.")) || this;
31
+ }
32
+ return RwParseStructureNotFoundError;
33
+ }(RwParseError));
34
+ exports.RwParseStructureNotFoundError = RwParseStructureNotFoundError;
@@ -0,0 +1,5 @@
1
+ export * from "./byte-stream";
2
+ export * from "./errors";
3
+ export * from "./rw-file";
4
+ export * from "./rw-sections";
5
+ export * from "./rw-version";
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./byte-stream"), exports);
18
+ __exportStar(require("./errors"), exports);
19
+ __exportStar(require("./rw-file"), exports);
20
+ __exportStar(require("./rw-sections"), exports);
21
+ __exportStar(require("./rw-version"), exports);
@@ -0,0 +1,9 @@
1
+ import { ByteStream } from "./byte-stream";
2
+ export interface RwSectionHeader {
3
+ sectionType: number;
4
+ sectionSize: number;
5
+ versionNumber: number;
6
+ }
7
+ export declare class RwFile extends ByteStream {
8
+ readSectionHeader(): RwSectionHeader;
9
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.RwFile = void 0;
19
+ var byte_stream_1 = require("./byte-stream");
20
+ var RwFile = /** @class */ (function (_super) {
21
+ __extends(RwFile, _super);
22
+ function RwFile() {
23
+ return _super !== null && _super.apply(this, arguments) || this;
24
+ }
25
+ RwFile.prototype.readSectionHeader = function () {
26
+ if (this.getPosition() + 12 > this.getSize()) {
27
+ throw new Error("Cannot read section header at offset ".concat(this.getPosition().toString(16), ": need 12 bytes but only ").concat(this.getSize() - this.getPosition(), " bytes remaining"));
28
+ }
29
+ var sectionType = this.readUint32();
30
+ var sectionSize = this.readUint32();
31
+ var versionNumber = this.readUint32();
32
+ return { sectionType: sectionType, sectionSize: sectionSize, versionNumber: versionNumber };
33
+ };
34
+ return RwFile;
35
+ }(byte_stream_1.ByteStream));
36
+ exports.RwFile = RwFile;