Skip to content

Commit

Permalink
Refactoring: Move function definition
Browse files Browse the repository at this point in the history
  • Loading branch information
zk-phi committed Jul 4, 2024
1 parent 3ae35ba commit 5eb39b2
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/utils/emoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,6 @@ function renderFrameUncut(
}
}

function initializeEncoder(
height: number,
width: number,
delay: number,
transparent: boolean,
) {
const encoder = new Worker("./gifworker.js");
encoder.postMessage({
initialize: { height, width, delay, transparent },
});
return encoder;
}

/**
* ASYNC:
* returns a 2d-array of (possibly animated) images of specified size (tragetSize).
Expand Down Expand Up @@ -161,10 +148,22 @@ function renderAllCellsFixedSize(
/* instantiate GIF encoders for each cells */
const delayPerFrame = 1000 / framerate;
const encoders = [];
const initializeEncoder = () => {
const encoder = new Worker("./gifworker.js");
encoder.postMessage({
initialize: {
height: croppedHeight,
width: croppedWidth,
delay: delayPerFrame,
transparent,
},
});
return encoder;
};
for (let y = 0; y < vCells; y += 1) {
const row = [];
for (let x = 0; x < hCells; x += 1) {
row.push(initializeEncoder(croppedHeight, croppedWidth, delayPerFrame, transparent));
row.push(initializeEncoder());
}
encoders.push(row);
}
Expand Down

0 comments on commit 5eb39b2

Please sign in to comment.