gputex 0.4.0 → 0.6.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/dist/testing.d.ts CHANGED
@@ -75,6 +75,16 @@ declare function encodeBC7Mode6Block(pixels: BC7Pixels): BC7Block;
75
75
  * Throws if the block doesn't start with the mode 6 field.
76
76
  */
77
77
  declare function decodeBC7Mode6Block(block: BC7Block): Float32Array;
78
+ /**
79
+ * Decode a BC7 mode 1 block to 16 normalized [0, 1] RGBA pixels (64 floats).
80
+ * Throws if the block doesn't start with the mode 1 field.
81
+ */
82
+ declare function decodeBC7Mode1Block(block: BC7Block): Float32Array;
83
+ /**
84
+ * Decode a BC7 mode 4 block to 16 normalized [0, 1] RGBA pixels (64 floats).
85
+ * Throws if the block doesn't start with the mode 4 field.
86
+ */
87
+ declare function decodeBC7Mode4Block(block: BC7Block): Float32Array;
78
88
  /**
79
89
  * Encode a BC7 block. Currently this always produces a mode 6 block —
80
90
  * see the file header for why other modes are deliberately out of scope.
@@ -82,9 +92,10 @@ declare function decodeBC7Mode6Block(block: BC7Block): Float32Array;
82
92
  declare function encodeBC7Block(pixels: BC7Pixels): BC7Block;
83
93
  /**
84
94
  * 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.
95
+ * supports modes 1, 4 and 6 — the modes the GPU encoder emits (or has
96
+ * emitted); other modes throw. Encoders outside this project (AMD
97
+ * Compressonator, bc7enc, ...) routinely pick other modes, so this
98
+ * decoder is mainly for round-tripping our own output.
88
99
  */
89
100
  declare function decodeBC7Block(block: BC7Block): Float32Array;
90
101
 
@@ -94,27 +105,53 @@ type ASTC4x4Pixels = Readonly<ArrayLike<number>>;
94
105
  type ASTC4x4Block = Uint8Array;
95
106
  /**
96
107
  * 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.
108
+ * block using the narrow subset described at the top of this file. The
109
+ * block class (CEM 0 / 8 / 12) is picked from the 8-bit content: exact
110
+ * grayscale + opaque → luminance, opaque → RGB, otherwise RGBA.
98
111
  *
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.
112
+ * Algorithm per class:
113
+ * 1. Quantise input to 8-bit; classify.
114
+ * 2. Farthest-pair over the class's channels → initial (e0, e1).
115
+ * 3. Assign per-texel indices by nearest palette entry.
103
116
  * 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.
117
+ * 5. CEM 8/12: flip endpoints (and reflect weights) if
118
+ * sum(e0.rgb) > sum(e1.rgb) so the decoder skips blue contraction.
106
119
  * 6. Pack block mode, CEM, endpoints, weights into 128 bits.
107
120
  */
108
121
  declare function encodeASTC4x4Block(pixels: ASTC4x4Pixels): ASTC4x4Block;
109
122
  /**
110
123
  * 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.
124
+ * encoder that respects our narrow subset: block modes 0x042/0x053/0x253,
125
+ * single partition, CEM 0/8/12 with 8-bit endpoints). Handles the
126
+ * blue-contraction branch even though our encoder doesn't produce it, so
127
+ * externally-supplied blocks round-trip predictably.
128
+ *
129
+ * The CEM is validated against the block mode's expected pairing (we only
130
+ * ever emit the three fixed combinations above).
115
131
  *
116
132
  * Output: 16 RGBA pixels as 64 floats in [0, 1].
117
133
  */
118
134
  declare function decodeASTC4x4Block(block: ASTC4x4Block): Float32Array;
119
135
 
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 };
136
+ /** 48-value input: 16 RGB triplets, channel-interleaved, row-major, each in [0, 1]. */
137
+ type ETC2Pixels = Readonly<ArrayLike<number>>;
138
+ /** Exactly 8 bytes of ETC2 RGB8 block data. */
139
+ type ETC2Block = Uint8Array;
140
+ type ETC2Quality = 'fast' | 'high';
141
+ type ETC2Mode = 'individual' | 'differential' | 'T' | 'H' | 'planar';
142
+ /**
143
+ * Encode a 4×4 RGB block (48 floats in [0, 1], row-major) into an 8-byte
144
+ * ETC2 RGB8 block. Emits individual, differential or planar mode.
145
+ */
146
+ declare function encodeETC2Block(pixels: ETC2Pixels, { quality }?: {
147
+ quality?: ETC2Quality;
148
+ }): ETC2Block;
149
+ /** Which of the five ETC2 RGB8 modes a packed block uses. */
150
+ declare function readETC2Mode(block: ETC2Block): ETC2Mode;
151
+ /**
152
+ * Decode an 8-byte ETC2 RGB8 block to 48 normalised [0, 1] values (16 RGB
153
+ * triplets, row-major). Handles all five modes.
154
+ */
155
+ declare function decodeETC2Block(block: ETC2Block): Float32Array;
156
+
157
+ export { type ASTC4x4Block, type ASTC4x4Pixels, type BC1Block, type BC1Pixels, type BC1Quality, type BC4Block, type BC4Values, type BC5Block, type BC5Decoded, type BC7Block, type BC7Pixels, type ETC2Block, type ETC2Mode, type ETC2Pixels, type ETC2Quality, decodeASTC4x4Block, decodeBC1Block, decodeBC4Block, decodeBC5Block, decodeBC7Block, decodeBC7Mode1Block, decodeBC7Mode4Block, decodeBC7Mode6Block, decodeETC2Block, encodeASTC4x4Block, encodeBC1Block, encodeBC4Block, encodeBC5Block, encodeBC7Block, encodeBC7Mode6Block, encodeETC2Block, readBC7Mode, readETC2Mode };