Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Invalid el_image colours #140
Comments
Please can you provide example html/css to show problem? |
I don't think there's actually valid html/css to highlight this problem, but I'll try and explain what I found out: litehtml::el_image::draw calls get_document()->container()->draw_background() twice. Once for the real background, and once again for the image. The first call (for the real background) has the colour setup correctly from parsing the css (or applying the default, which is, I believe, 0,0,0,255). The background_paint structure is filled out from these parsed values, and passed to draw_background. This is fine. The correct colour and/or image will be drawn and blended accordingly. The second call, however, fills out a local instance of background_paint (line 228 in el_image.cpp) before passing it to draw_background. This code that fills out the structure does not set up the colour to be used. Which would be fine if the constructor for background_paint didn't explicitly set the colour to 0,0,0,0. (The web_color constructor would normally set the colour to the default value of 0,0,0255.) The problem being the user implementation of draw_background has no way of knowing that it should ignore the colour in the background_paint structure the second time around, and in fact has no way of knowing it is a second call for the same object. Basically it has to use what it has been given and assume everything is correct, which it isn't. Without setting the colour correctly the draw_background function will blend the image with the colour which has zero opacity and effectively draw nothing. (At least that's what our implementation was doing.) A workaround for us was to set a 255,255,255,255 colour in the background_paint structure before the second call to draw_background. |
The 4th number in color is alpha channel. As you say it means "zero opacity" or 100% transparency. You can just ignore colors with zero opacity. Draw process is similar to "layers", litehtml draws the first background and then draw image considering it will be drawn over background with image transparency applied. |
But saying just ignore colours with zero opacity is wrong. Consider an animation sequence that fades an image out. As soon as the alpha value reached zero the image would be rendered fully opaque again. |
I guess you tell about your implementation of document draw. As I see this process, and you can see it litebrowser:
So when you have fade animation, your image becomes transparent and buffer will show the default or parent background. You don't require additional colors to draw transparent image in buffer. |
You're missing my point. You said: "You can just ignore colors with zero opacity." By which you presumably mean if a colour has zero opacity, my draw_background function should just do nothing and return, right? But my original point was that every call to draw_background from el_image has a colour with zero opacity. |
Yes, but |
el_image::draw does not set the background colours before calling draw_background, so the draw_background function either has to have a special path for dealing with images (which prevents images from being coloured via css) or use a default colour when the background colour is 0,0,0,0 (which will potentially cause problems later on).