Skip to content

Commit 71453b8

Browse files
committed
testing encoded image
1 parent db76adc commit 71453b8

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/GAME.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,22 +223,10 @@ const updateDemoLogo = (pngPath: string) => {
223223
}
224224
}
225225

226-
const decompressed = Buffer.alloc((width * height) / 2, 0);
227-
228-
let index = 0;
229-
for (let y = 0; y < height; y++) {
230-
for (let x = 0; x < width; x += 2) {
231-
const lowByte = imgData[index++];
232-
const highByte = imgData[index++];
233-
const byte = ((highByte << 4) | lowByte) & 0xff;
234-
decompressed[outOfs++] = byte;
235-
}
236-
}
237-
238-
// Write the
226+
// Write the texture to png to confirm it's working'
239227
const png = new PNG({ width, height });
240228

241-
index = 0;
229+
let index = 0;
242230
let dst = 0;
243231
for (let y = 0; y < height; y++) {
244232
for (var x = 0; x < width; x++) {
@@ -255,6 +243,21 @@ const updateDemoLogo = (pngPath: string) => {
255243
const dat = PNG.sync.write(png);
256244
writeFileSync(`out/smol.png`, dat);
257245

246+
// Convert the image data back to a 4bit encoded buffer
247+
const decompressed = Buffer.alloc((width * height) / 2, 0);
248+
249+
index = 0;
250+
outOfs = 0;
251+
for (let y = 0; y < height; y++) {
252+
for (let x = 0; x < width; x += 2) {
253+
const lowByte = imgData[index++];
254+
const highByte = imgData[index++];
255+
const byte = ((highByte << 4) | lowByte) & 0xff;
256+
decompressed[outOfs] = byte;
257+
outOfs++;
258+
}
259+
}
260+
258261
// And then we compress and put it back in
259262
const [bodyBitField, compressedBody] = compressData(decompressed);
260263
const len = bodyBitField.length + compressedBody.length;

0 commit comments

Comments
 (0)