Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
717 views
in Technique[技术] by (71.8m points)

animation - GIF Image getting distorted on interlacing

Distorted GIF

I have a few images that were converted using Imagemagick and its interlaced operation. These were the animated GIF images. The issue is that, while converting, the images have distorted and I do not have original images with me as it was the previous developer who did the wonderful thing. The GIF is no more animating and each frame has 4 copies of the same frame with decreasing sizes. I have not worked much on Imagemagick before.

Is there any way I can restore the original image from the distorted version?

The command used was:

convert <old-file.gif> -interlace plane <new-file.gif>

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

interlaced GIF images are stored as 4 separated images

  1. containing every 8th line of image (1/8 of size)
  2. containing every missing 4th line of image (1/8 of size)
  3. containing every missing even line of image (1/4 of size)
  4. containing every odd line of image (1/2 of size)

This is done so the image can be seen while loading through slow Internet connection ... increasing details with every new chunk...

So if your image looks like 4 very similar images then the result is OK you just wrongly decode it or the GIF has not set the Interlaced flag.

If your file does not contain the animation frames anymore then you are out of luck but if they are there and not rendering then check the GIF end of file is not misplaced or check the flags they could be screwed up... Have you tried different GIF viewer (some are buggy)

[Edit1] after decoding your GIF

You got GIF89a and you are missing interlaced flags in each frame. So the image is interlaced correctly but the viewer thinks it is not interlaced at all ... You need to mark interlaced flag in each frame header.

struct _img // this is image frame header
    {
    // Logical Image Descriptor
    BYTE Separator;         /* Image Descriptor identifier 0x2C */
    WORD x0;                /* X position of image on the display */
    WORD y0;                /* Y position of image on the display */
    WORD xs;                /* Width of the image in pixels */
    WORD ys;                /* Height of the image in pixels */
    BYTE Packed;            /* Image and Color Table Data Information */
    } img;

img.Packed|=64; // this will set the interlaced flag

To do that you need to decode/stream copy the GIF which is not that easy as it sounds.

see:

Here the result of frames copy + deinterlace + interlaced encode (skipping control/info/auxiliary feeds ...)

repaired image


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...