Skip to content

Commit

Permalink
Fixed off by one error in image generation and decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
agg23 committed Sep 21, 2023
1 parent 9c904a6 commit 122948e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules/
node_modules/
*.png
*.bin
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ const create = async () => {
byte = 0;
}

// Brightness byte
image[i / 2] = byte;
// Reserved byte
image[i / 2 + 1] = 0;
}

Expand All @@ -39,7 +41,7 @@ const create = async () => {
const prevColumn = i % width;
const prevRow = Math.floor(i / width);

const row = width - prevColumn;
const row = width - 1 - prevColumn;
const column = prevRow;

rotatedImage[(row * height + column) * 2] = byte1;
Expand Down
2 changes: 1 addition & 1 deletion src/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ for (let i = 0; i < rgba.length / 4; i++) {
const prevRow = Math.floor(i / width);

const row = prevColumn;
const column = height - prevRow;
const column = height - 1 - prevRow;

const outputPos = (row * height + column) * 4;
rotatedImage[outputPos] = byte1;
Expand Down

0 comments on commit 122948e

Please sign in to comment.