Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GIF parses out redundant images #38

Closed
jianjunxia opened this issue Feb 14, 2022 · 31 comments
Closed

GIF parses out redundant images #38

jianjunxia opened this issue Feb 14, 2022 · 31 comments

Comments

@jianjunxia
Copy link

in release/v7, use this GIF,Caused extra images to be parsed, please help to see what caused the problem?
In addition, is there a useful tool for parsing GIF data?
zoomies_test

@jianjunxia
Copy link
Author

image

@kisvegabor
Copy link
Member

Is it the same with v8 where gif is already part of lvgl?

@jianjunxia
Copy link
Author

Is it the same with v8 where gif is already part of lvgl?

yes, my lvgl version is v7, latest v7 version of my lv_lib_gif

@kisvegabor
Copy link
Member

I mean can ou try out in a simulator with v8 too?

@jianjunxia
Copy link
Author

I mean can ou try out in a simulator with v8 too?

yes, you can try it!

@jianjunxia
Copy link
Author

I mean can ou try out in a simulator with v8 too?

how about?

@jianjunxia
Copy link
Author

I mean can ou try out in a simulator with v8 too?
hi,do you try it? how about it?

@kisvegabor
Copy link
Member

I meant you can try it out if the issue still persists. Anyway I've just checked it an v8 it looked fine.

Can you try it out on your end too with v8?

@jianjunxia
Copy link
Author

I meant you can try it out if the issue still persists. Anyway I've just checked it an v8 it looked fine.

Can you try it out on your end too with v8?

i found this gif background=0xff, when i add this code in gif_open function in release/v7, this gif is shows normal
if (gif->bgindex == 0xff) gif->bgindex = 0;

@jianjunxia
Copy link
Author

so, i think when gif->bgindex = 0xff, it may cause the gif to display abnormally, do you think so? I need some advice from you

@jianjunxia
Copy link
Author

Also, I'm developing with lgvl v7 now

@kisvegabor
Copy link
Member

I think it's just working accidentally.
I tried a lot optimization things and if I recall correctly the final solution is only included in v8.

I suggest backporting the gif decoder from v8 to v7.

@jianjunxia
Copy link
Author

I have compared the difference between v8 and release/v7 versions of gif parsers and they are no different in my opinion

@jianjunxia
Copy link
Author

I think it's just working accidentally. I tried a lot optimization things and if I recall correctly the final solution is only included in v8.

I suggest backporting the gif decoder from v8 to v7.

but,i can try it

@jianjunxia
Copy link
Author

I think it's just working accidentally. I tried a lot optimization things and if I recall correctly the final solution is only included in v8.

I suggest backporting the gif decoder from v8 to v7.

In addition, why does it cause this problem when gif->bgindex = 0xff?

@kisvegabor
Copy link
Member

It seems the problem is related to the transparent background. Wikipedia says:

Each frame can designate one index as a "transparent background color": any pixel assigned this index takes on the color of the pixel in the same position from the background, which may have been determined by a previous frame of animation.

I remember that tested this but there might be some issues.

I suspect that the offending line is this: https://github.com/lvgl/lvgl/blob/master/src/extra/libs/gif/gifdec.c#L486

@jianjunxia
Copy link
Author

jianjunxia commented Feb 16, 2022

It seems the problem is related to the transparent background. Wikipedia says:

Each frame can designate one index as a "transparent background color": any pixel assigned this index takes on the color of the pixel in the same position from the background, which may have been determined by a previous frame of animation.

I remember that tested this but there might be some issues.

I suspect that the offending line is this: https://github.com/lvgl/lvgl/blob/master/src/extra/libs/gif/gifdec.c#L486
My current solution is: if (gif->bgindex == 0xff) gif->bgindex = 0,Do you think this solution is reasonable?I need your help, thanks

@kisvegabor
Copy link
Member

My current solution is: if (gif->bgindex == 0xff) gif->bgindex = 0`,Do you think this solution is reasonable?I need your help, thanks

gif->gce.tindex is the index of the transparent color. So if it's incorrect then it should be tracked why is not set correctly.

By definition, gif->bgindex = 0 doesn't have any special meaning.

@jianjunxia
Copy link
Author

By definition, gif->bgindex = 0 doesn't have any special meaning

yes,i know gif->gce.tindex is the index of the transparent color, it is included in every frame of the picture, but i use cmd gifsicle -I this.gif, i found every frame index of the transparent is 255=0xff, it doesn't look like any difference

@jianjunxia
Copy link
Author

i'm tested in v7 lvgl and in v7 lv_lib_gif do you help me to test it?please

@jianjunxia
Copy link
Author

image

@jianjunxia
Copy link
Author

hi,I know what is causing the above problem,The above gif image is very special, and it has several characteristics that cause the above problems。
When I use gifsicle --cinfo this.gif, I find transparent 255 is #000000 of the global colormap and local colormap of this image, and this.gif gif->gce.disposal is always 3,It will cause the following problems:
Step1:in gif_open function , it won't go into the following case:

lv_lib_gif/gifdec.c

Lines 138 to 155 in 27a7450

if (bgcolor[0] || bgcolor[1] || bgcolor [2])
for (i = 0; i < gif->width * gif->height; i++) {
#if LV_COLOR_DEPTH == 32
gif->canvas[i*4 + 0] = *(bgcolor + 2);
gif->canvas[i*4 + 1] = *(bgcolor + 1);
gif->canvas[i*4 + 2] = *(bgcolor + 0);
gif->canvas[i*4 + 3] = 0xff;
#elif LV_COLOR_DEPTH == 16
lv_color_t c = lv_color_make(*(bgcolor + 0), *(bgcolor + 1), *(bgcolor + 2));
gif->canvas[i*3 + 0] = c.full & 0xff;
gif->canvas[i*3 + 1] = (c.full >> 8) & 0xff;
gif->canvas[i*3 + 2] = 0xff;
#elif LV_COLOR_DEPTH == 8
lv_color_t c = lv_color_make(*(bgcolor + 0), *(bgcolor + 1), *(bgcolor + 2));
gif->canvas[i*2 + 0] = c.full;
gif->canvas[i*2 + 1] = 0xff;
#endif
}

Step2:because gif->gce.disposal = 3,it's restore to previous, don't update canvas

Step3:because every frame Local Color Table gif->gce.tindex= 255, and this data is #000000

So I think the above situation leads to why the background color has an extra white line.

Also, I think white background color is not supported in release/v7,I think the code should be changed like this:
delete this line code: if (bgcolor[0] || bgcolor[1] || bgcolor [2])

@jianjunxia
Copy link
Author

in this issues,#15 his problem is similar to mine, But I don't think your explanation is accurate:#15 (comment)
in his gif #15 (comment) and #15 (comment)

I found a similar question,use cmd: gifsicle --cinfo xx.gif,this global color table[63] = #000000, and this background = 63,so when parsing these two gifs, the code of step1 above cannot be entered.
But luckily,this two gif gif->gce.disposal = 2,so, it can restore to background color,so,this why a white line flashes on the background.
I think there are two problems in release/v7 lv_lib_gif,
1:when background data = #000000, it's caused some problem.
2:in v7 lvgl it's not set white background

@kisvegabor
Copy link
Member

I think I mostly understand 🙂
But isn't #000000 black?

@jianjunxia
Copy link
Author

I think I mostly understand 🙂 But isn't #000000 black?

yes, in RGB #0000000 is black,but, the actual running scenario does
and when i delete this code if (bgcolor[0] || bgcolor[1] || bgcolor [2]) every gif run is back to normal

this code if (bgcolor[0] || bgcolor[1] || bgcolor [2]) llooks useless

@kisvegabor
Copy link
Member

To be honest I also don't know what is the point of if (bgcolor[0] || bgcolor[1] || bgcolor [2]).

So can you confirm that removing it all works well?

@jianjunxia
Copy link
Author

jianjunxia commented Feb 17, 2022 via email

@jianjunxia
Copy link
Author

jianjunxia commented Feb 17, 2022 via email

@kisvegabor
Copy link
Member

Great!

I fixed it in lvgl/master here lvgl/lvgl@b1e2c06

@jianjunxia
Copy link
Author

Great!

I fixed it in lvgl/master here lvgl/lvgl@b1e2c06

Thanks,i will colse this issue

@kisvegabor
Copy link
Member

Thanks for the debugging and finding the root of this issue! 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants