X
X
xdenser2011-05-07 14:06:11
HTML
xdenser, 2011-05-07 14:06:11

How to restore alpha channel?

You need to draw HTML in Direct3D. HTML is drawn by the IE engine on a DC received from a Direct3D Surface or in an in-memory Bitmap without problems. From all this, a texture is obtained that is drawn anywhere.
There are also no problems when the background color is set for the HTML (in itself) - i.e. when there are no transparent areas - everything is OK. But there is also a task to display HTML with transparency. The simplest option is just some formatted text on an arbitrary background in a Direct3D scene. It is impossible to get bitmap with alpha channel from IE. It's possible to grab a portion of an image from a Direct3D buffer and slip it into IE to draw the HTML on top of it, then take it and put it back in Direct3D, but that's horribly inefficient since the HTML is usually static and the scene underneath is constantly changing. I want to get a texture with an alpha channel that only updates when the HTML is updated. So far, I came up with this approach - to draw HTML several times on a black and white background, then, based on two images, calculate the third one with an alpha channel. In theory, everything is fine. In practice, there is a problem - IE smooths fonts and character outlines look wrong. It is clear that the colors on the anti-aliased contours on a black and white background are different, so for the final image it is necessary to calculate a certain color and alpha, so that when applied to an arbitrary color, the contour also looks anti-aliased.
Perhaps I am incorrectly calculating the alpha channel and the colors of the dots in the final image. But I have a doubt - is it possible in principle?
Maybe it makes sense to dig in the direction of disabling font smoothing in IE and smoothing the picture already at the last stage in Direct3D. But something tells me that the result will be worse.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xanep, 2011-05-07
@xanep

Of course you can. I will count the color of the pixels from 0 (black) to 1 (white) everywhere.
Let's say you have a pixel color C that blends with the background by a factor of λ. Then on a black background you will have the color B=λC, and on a white background the color W=λC+(1-λ).
Then W=B+(1-λ), whence λ = B-W+1 and the initial color C = B/λ.
However, I am sure that rendering HTML 2 times on a black and white background will be the best solution for your task. Maybe you don't really need an alpha channel? You didn't really describe what you are doing.

X
xanep, 2011-05-08
@xanep

Try htmllayout . It is written that it renders to a 32 bit texture. Style the document
html
{
background-color: transparent;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question