The Wayback Machine - https://web.archive.org/web/20201127050001/https://github.com/litehtml/litehtml/issues/140
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

Invalid el_image colours #140

Open
crazydef opened this issue Sep 22, 2020 · 7 comments
Open

Invalid el_image colours #140

crazydef opened this issue Sep 22, 2020 · 7 comments

Comments

@crazydef
Copy link

@crazydef crazydef commented Sep 22, 2020

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).

@tordex
Copy link
Member

@tordex tordex commented Oct 12, 2020

Please can you provide example html/css to show problem?

@crazydef
Copy link
Author

@crazydef crazydef commented Oct 12, 2020

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.

@tordex
Copy link
Member

@tordex tordex commented Oct 12, 2020

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.

@crazydef
Copy link
Author

@crazydef crazydef commented Oct 12, 2020

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.

@tordex
Copy link
Member

@tordex tordex commented Oct 12, 2020

I guess you tell about your implementation of document draw. As I see this process, and you can see it litebrowser:

  1. Before painting rendered document you should create buffer or get HDC
  2. You fill buffer with initial values (window background or something like this)
  3. call document::draw
  4. litehtml calls draw_background for backgrounds and images.
  5. you should draw colors/images in buffer over existing pixels using blending. Blending with transparent image/color doesn't change buffer

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.

@crazydef
Copy link
Author

@crazydef crazydef commented Oct 13, 2020

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.

@tordex
Copy link
Member

@tordex tordex commented Oct 13, 2020

But my original point was that every call to draw_background from el_image has a colour with zero opacity.

Yes, but background_paint struct has two fields: image and color. You should process both. First fill with color (or ignore if it is transparent) and then draw the image. Yes, every call to draw_background has color with zero opacity, but non-zero image.

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.