gputex 0.2.0 → 0.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.
- package/README.md +90 -12
- package/dist/index.d.ts +25 -8
- package/dist/index.js +416 -91
- package/dist/testing.d.ts +120 -0
- package/dist/testing.js +945 -0
- package/dist/three.js +416 -91
- package/package.json +5 -1
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/** 48-value input: 16 RGB triplets, channel-interleaved, each in [0, 1]. */
|
|
2
|
+
type BC1Pixels = Readonly<ArrayLike<number>>;
|
|
3
|
+
/** Exactly 8 bytes of BC1 block data. */
|
|
4
|
+
type BC1Block = Uint8Array;
|
|
5
|
+
type BC1Quality = 'fast' | 'high';
|
|
6
|
+
/**
|
|
7
|
+
* Encode a 4×4 RGB block (48 floats in [0, 1]) into an 8-byte BC1 block.
|
|
8
|
+
* Always emits 4-colour (opaque) mode.
|
|
9
|
+
*/
|
|
10
|
+
declare function encodeBC1Block(pixels: BC1Pixels, { quality }?: {
|
|
11
|
+
quality?: BC1Quality;
|
|
12
|
+
}): BC1Block;
|
|
13
|
+
/**
|
|
14
|
+
* Decode an 8-byte BC1 block to 48 normalised [0, 1] values (16 RGB triplets).
|
|
15
|
+
* Handles both 4-colour and 3-colour modes; the 3-colour transparent index
|
|
16
|
+
* decodes to black (this library samples BC1 as opaque RGB).
|
|
17
|
+
*/
|
|
18
|
+
declare function decodeBC1Block(block: BC1Block): Float32Array;
|
|
19
|
+
|
|
20
|
+
/** 16-value input: accepts both real arrays and typed arrays. */
|
|
21
|
+
type BC4Values = Readonly<ArrayLike<number>>;
|
|
22
|
+
/** Exactly 8 bytes, indexed numerically. */
|
|
23
|
+
type BC4Block = Uint8Array;
|
|
24
|
+
/**
|
|
25
|
+
* Encode 16 single-channel values in [0, 1] into an 8-byte BC4 block.
|
|
26
|
+
*
|
|
27
|
+
* Always produces a 6-interpolation-mode block (red0 > red1). This is
|
|
28
|
+
* the right choice for the BC5 normal-map use case; see file comment.
|
|
29
|
+
*/
|
|
30
|
+
declare function encodeBC4Block(values: BC4Values): BC4Block;
|
|
31
|
+
/**
|
|
32
|
+
* Decode an 8-byte BC4 block to 16 normalized [0, 1] values.
|
|
33
|
+
*
|
|
34
|
+
* Handles both 6-interpolation and 4-interpolation modes so we can
|
|
35
|
+
* round-trip blocks produced externally (hardware, other encoders).
|
|
36
|
+
*/
|
|
37
|
+
declare function decodeBC4Block(block: BC4Block): Float32Array;
|
|
38
|
+
|
|
39
|
+
/** Exactly 16 bytes of BC5 block data. */
|
|
40
|
+
type BC5Block = Uint8Array;
|
|
41
|
+
interface BC5Decoded {
|
|
42
|
+
r: Float32Array;
|
|
43
|
+
g: Float32Array;
|
|
44
|
+
}
|
|
45
|
+
declare function encodeBC5Block(r: BC4Values, g: BC4Values): BC5Block;
|
|
46
|
+
declare function decodeBC5Block(block: BC5Block): BC5Decoded;
|
|
47
|
+
|
|
48
|
+
/** 16 pixels × 4 channels = 64 normalized floats, interleaved RGBA. */
|
|
49
|
+
type BC7Pixels = Readonly<ArrayLike<number>>;
|
|
50
|
+
/** 16 bytes of BC7 block data. */
|
|
51
|
+
type BC7Block = Uint8Array;
|
|
52
|
+
/** Read the variable-width unary-coded mode field. Returns the mode number. */
|
|
53
|
+
declare function readBC7Mode(block: BC7Block): number;
|
|
54
|
+
/**
|
|
55
|
+
* Encode 16 RGBA pixels (64 floats in [0,1]) as a BC7 mode 6 block.
|
|
56
|
+
*
|
|
57
|
+
* Algorithm:
|
|
58
|
+
* 1. Convert to 8-bit per channel.
|
|
59
|
+
* 2. Farthest-pair in 4D → initial 8-bit endpoints. (See farthestPair
|
|
60
|
+
* for why bbox corners aren't safe when channels vary in different
|
|
61
|
+
* directions along the data line.)
|
|
62
|
+
* 3. For each p-bit combo {(0,0),(0,1),(1,0),(1,1)}:
|
|
63
|
+
* quantize each endpoint to 7-bit under its chosen p-bit,
|
|
64
|
+
* rebuild palette, reassign indices, measure total error.
|
|
65
|
+
* 4. Keep the best p-bit combo.
|
|
66
|
+
* 5. One-pass least-squares refinement on the surviving indices,
|
|
67
|
+
* re-quantize with p-bit search, accept if error decreases.
|
|
68
|
+
* 6. Anchor fix: if pixel 0's index has MSB=1, swap endpoints and
|
|
69
|
+
* invert all indices.
|
|
70
|
+
* 7. Pack.
|
|
71
|
+
*/
|
|
72
|
+
declare function encodeBC7Mode6Block(pixels: BC7Pixels): BC7Block;
|
|
73
|
+
/**
|
|
74
|
+
* Decode a BC7 mode 6 block to 16 normalized [0, 1] RGBA pixels (64 floats).
|
|
75
|
+
* Throws if the block doesn't start with the mode 6 field.
|
|
76
|
+
*/
|
|
77
|
+
declare function decodeBC7Mode6Block(block: BC7Block): Float32Array;
|
|
78
|
+
/**
|
|
79
|
+
* Encode a BC7 block. Currently this always produces a mode 6 block —
|
|
80
|
+
* see the file header for why other modes are deliberately out of scope.
|
|
81
|
+
*/
|
|
82
|
+
declare function encodeBC7Block(pixels: BC7Pixels): BC7Block;
|
|
83
|
+
/**
|
|
84
|
+
* Decode a BC7 block, dispatching on the mode field. This reference
|
|
85
|
+
* supports mode 6 only; other modes throw. Encoders outside this
|
|
86
|
+
* project (AMD Compressonator, bc7enc, ...) routinely pick other modes,
|
|
87
|
+
* so this decoder is mainly for round-tripping our own output.
|
|
88
|
+
*/
|
|
89
|
+
declare function decodeBC7Block(block: BC7Block): Float32Array;
|
|
90
|
+
|
|
91
|
+
/** 16 pixels × 4 channels = 64 normalised floats, interleaved RGBA. */
|
|
92
|
+
type ASTC4x4Pixels = Readonly<ArrayLike<number>>;
|
|
93
|
+
/** 16 bytes of ASTC 4×4 block data. */
|
|
94
|
+
type ASTC4x4Block = Uint8Array;
|
|
95
|
+
/**
|
|
96
|
+
* Encode 16 RGBA pixels (64 floats in [0, 1]) as a single ASTC 4×4 LDR
|
|
97
|
+
* block using the narrow subset described at the top of this file.
|
|
98
|
+
*
|
|
99
|
+
* Algorithm:
|
|
100
|
+
* 1. Quantise input to 8-bit.
|
|
101
|
+
* 2. Farthest-pair in 4D → initial (e0, e1).
|
|
102
|
+
* 3. Assign per-texel 2-bit indices by nearest palette entry.
|
|
103
|
+
* 4. One LSQ refit pass; accept only if total error strictly decreases.
|
|
104
|
+
* 5. Flip endpoints (and invert indices) if sum(e0.rgb) > sum(e1.rgb)
|
|
105
|
+
* so the decoder doesn't apply blue contraction.
|
|
106
|
+
* 6. Pack block mode, CEM, endpoints, weights into 128 bits.
|
|
107
|
+
*/
|
|
108
|
+
declare function encodeASTC4x4Block(pixels: ASTC4x4Pixels): ASTC4x4Block;
|
|
109
|
+
/**
|
|
110
|
+
* Decode an ASTC 4×4 block produced by this encoder (or by any other
|
|
111
|
+
* encoder that respects our narrow subset: block mode 0x042, single
|
|
112
|
+
* partition, CEM 12). Handles the blue-contraction branch even though
|
|
113
|
+
* our encoder doesn't produce it, so externally-supplied blocks round-
|
|
114
|
+
* trip predictably.
|
|
115
|
+
*
|
|
116
|
+
* Output: 16 RGBA pixels as 64 floats in [0, 1].
|
|
117
|
+
*/
|
|
118
|
+
declare function decodeASTC4x4Block(block: ASTC4x4Block): Float32Array;
|
|
119
|
+
|
|
120
|
+
export { type ASTC4x4Block, type ASTC4x4Pixels, type BC1Block, type BC1Pixels, type BC1Quality, type BC4Block, type BC4Values, type BC5Block, type BC5Decoded, type BC7Block, type BC7Pixels, decodeASTC4x4Block, decodeBC1Block, decodeBC4Block, decodeBC5Block, decodeBC7Block, decodeBC7Mode6Block, encodeASTC4x4Block, encodeBC1Block, encodeBC4Block, encodeBC5Block, encodeBC7Block, encodeBC7Mode6Block, readBC7Mode };
|