Skip to content

Commit

Permalink
testing encoded image
Browse files Browse the repository at this point in the history
  • Loading branch information
kion-dgl committed Sep 24, 2024
1 parent db76adc commit 71453b8
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/GAME.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,22 +223,10 @@ const updateDemoLogo = (pngPath: string) => {
}
}

const decompressed = Buffer.alloc((width * height) / 2, 0);

let index = 0;
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x += 2) {
const lowByte = imgData[index++];
const highByte = imgData[index++];
const byte = ((highByte << 4) | lowByte) & 0xff;
decompressed[outOfs++] = byte;
}
}

// Write the
// Write the texture to png to confirm it's working'
const png = new PNG({ width, height });

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

// Convert the image data back to a 4bit encoded buffer
const decompressed = Buffer.alloc((width * height) / 2, 0);

index = 0;
outOfs = 0;
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x += 2) {
const lowByte = imgData[index++];
const highByte = imgData[index++];
const byte = ((highByte << 4) | lowByte) & 0xff;
decompressed[outOfs] = byte;
outOfs++;
}
}

// And then we compress and put it back in
const [bodyBitField, compressedBody] = compressData(decompressed);
const len = bodyBitField.length + compressedBody.length;
Expand Down

0 comments on commit 71453b8

Please sign in to comment.