Skip to content

Commit

Permalink
Merge pull request #228 from Fonger/perf/ts
Browse files Browse the repository at this point in the history
(TypeScript) Improve decode speed by avoiding re-calculating same cosine value
  • Loading branch information
Thisen authored Mar 30, 2023
2 parents 065b960 + c747c91 commit f1edb10
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions TypeScript/src/decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,10 @@ const decode = (
let b = 0;

for (let j = 0; j < numY; j++) {
const basisY = Math.cos((Math.PI * y * j) / height);
for (let i = 0; i < numX; i++) {
const basis =
Math.cos((Math.PI * x * i) / width) *
Math.cos((Math.PI * y * j) / height);
let color = colors[i + j * numX];
const basis = Math.cos((Math.PI * x * i) / width) * basisY;
const color = colors[i + j * numX];
r += color[0] * basis;
g += color[1] * basis;
b += color[2] * basis;
Expand Down

0 comments on commit f1edb10

Please sign in to comment.