deanm / omggif

JavaScript implementation of a GIF 89a encoder and decoder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Disposal method 2 not supported

another-pjohnson opened this issue · comments

When disposal method 2 is set, canvas needs to be cleared to the background color before doing the blit operation when using the decodeAndBlitFrame* functions.

example gif / JS attached.
gif_test.zip

I have a workaround basically by checking the previous frameInfo disposal value and if it's 2 clear the pixel buffer, however i really should be clearing to the indexed background color palette value rather than just assuming it's 0x00000000. I didn't really see an easy way to get to that with the code.

    var dispose_last_frame = true;
    for(var i = 0; i < gr.numFrames(); ++i) {
        if(dispose_last_frame) {
            pixel_data.fill(0, 'hex');
            console.log('clearing before frame: ' + i)
        }
        dispose_last_frame = (gr.frameInfo(i).disposal == 2)
        gr.decodeAndBlitFrameRGBA(i, pixel_data);
        frame_data.push(Buffer.from(pixel_data));
    }

Sorry, maybe it's not clear but decodeAndBlitFrame is not meant to handle the disposal, for example see:

https://github.com/deanm/omggif/blob/master/plask_viewer.js#L30

I should mention, there is sometimes big differences between what the spec said, and what browsers / others did with GIFs over the years. So really there is sort of an unspoken spec of the reality of GIF, I don't remember all the details now but I know there were a lot of things around disposal where basically nobody follows the spec. It could make sense to add a helper method to omggif to get the background RGBA for example, taking care to handle transparent index, etc, there is a little bit of work to do there and deal with the cascade of the local/global palette etc.