MCPcopy Create free account
hub / github.com/melonjs/melonJS / buildDDS_DXT1

Function buildDDS_DXT1

packages/melonjs/tests/imageFallback.node-test.js:135–151  ·  view source on GitHub ↗

Build a minimal valid DDS DXT1 buffer

(width = 8, height = 8)

Source from the content-addressed store, hash-verified

133
134/** Build a minimal valid DDS DXT1 buffer */
135function buildDDS_DXT1(width = 8, height = 8) {
136 const blockSize = 8;
137 const dataSize =
138 Math.max(1, (width + 3) >> 2) * Math.max(1, (height + 3) >> 2) * blockSize;
139 const buffer = new ArrayBuffer(128 + dataSize);
140 const view = new DataView(buffer);
141 view.setUint32(0, 0x20534444, true); // magic
142 // header at offset 4 (124 bytes)
143 view.setUint32(4, 124, true); // dwSize
144 view.setUint32(8, 0x000a1007, true); // dwFlags
145 view.setUint32(12, height, true); // dwHeight
146 view.setUint32(16, width, true); // dwWidth
147 view.setUint32(28, 1, true); // dwMipMapCount
148 view.setUint32(80, 32, true); // ddspf.dwSize
149 view.setUint32(84, 0x31545844, true); // ddspf.dwFourCC = "DXT1"
150 return buffer;
151}
152
153/** Build a minimal valid PKM ETC1 buffer */
154function buildPKM_ETC1(width = 8, height = 8) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected