Skip to content

Commit

Permalink
fix: decode of disposal 0
Browse files Browse the repository at this point in the history
  • Loading branch information
qq15725 committed Aug 21, 2023
1 parent 03696db commit e844d90
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/decode-frames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,22 @@ export function decodeFrames(source: BufferSource, options?: DecodeFramesOptions
colorIndexs = deinterlace(colorIndexs, width)
}

if (previousFrame?.disposal !== 1) {
const { left = 0, top = 0, width = globalWidth, height = globalHeight } = previousFrame ?? {}
const previousDisposal = previousFrame?.disposal
if (previousDisposal === 0 || previousDisposal === 2) {
const { left, top, width, height } = previousFrame!
const bottom = top + height
for (let y = top; y < bottom; y++) {
const globalOffset = y * globalWidth + left
const localOffset = (y - top) * width
for (let x = 0; x < width; x++) {
const index = (globalOffset + x) * 4
pixels[index] = pixels[index + 1] = pixels[index + 2] = pixels[index + 3] = 0
const colorIndex = colorIndexs[localOffset + x]
if (
disposal === 2
|| (colorIndex !== transparentIndex)
) {
const index = (globalOffset + x) * 4
pixels[index] = pixels[index + 1] = pixels[index + 2] = pixels[index + 3] = 0
}
}
}
}
Expand Down

1 comment on commit e844d90

@vercel
Copy link

@vercel vercel bot commented on e844d90 Aug 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

modern-gif – ./

modern-gif-git-main-qq15725.vercel.app
modern-gif-qq15725.vercel.app
modern-gif.vercel.app

Please sign in to comment.