Skip to content

Commit

Permalink
Protect flips before compressing (#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenaio authored Dec 7, 2022
1 parent 735fc7e commit 202b798
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
11 changes: 8 additions & 3 deletions renderer/screens/flips/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,18 +717,23 @@ export function FlipProtectStep({

const regenerateImage = async () => {
onProtecting()

const protectedImageSrc = await protectFlipImage(
images[originalOrder[currentIndex]]
)

const compressedImage = await new Promise(resolve =>
resolve(
Jimp.read(images[originalOrder[currentIndex]]).then(raw =>
Jimp.read(protectedImageSrc).then(raw =>
raw
.resize(240, 180)
.quality(60) // jpeg quality
.getBase64Async('image/jpeg')
)
)
)
const protectedImageSrc = await protectFlipImage(compressedImage)
onProtectImage(protectedImageSrc, originalOrder[currentIndex])

onProtectImage(compressedImage, originalOrder[currentIndex])
}

return (
Expand Down
23 changes: 12 additions & 11 deletions renderer/screens/flips/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,18 @@ export async function protectFlipImage(imgSrc) {

export async function protectFlip({images}) {
const protectedFlips = []

for (let i = 0; i < images.length; i++) {
if (images[i]) {
const protectedImageSrc = await protectFlipImage(images[i])
protectedFlips[i] = protectedImageSrc
} else {
protectedFlips[i] = images[i]
}
}

const compressedImages = await Promise.all(
images.map(image =>
protectedFlips.map(image =>
image
? Jimp.read(image).then(raw =>
raw
Expand All @@ -865,16 +875,7 @@ export async function protectFlip({images}) {
)
)

// eslint-disable-next-line no-plusplus
for (let i = 0; i < images.length; i++) {
if (compressedImages[i]) {
const protectedImageSrc = await protectFlipImage(compressedImages[i])
protectedFlips[i] = protectedImageSrc
} else {
protectedFlips[i] = compressedImages[i]
}
}
return {protectedImages: protectedFlips}
return {protectedImages: compressedImages}
}

export const checkIfFlipNoiseEnabled = epochNumber =>
Expand Down

0 comments on commit 202b798

Please sign in to comment.