|
|
|
date: Mon, 26 May 2008 21:04:00 -0700,
group: microsoft.public.win32.programmer.gdi
back
TextOut to a 32-bit bitmap for AlphaBlend on Vista x64
Hello,
Problem: can't output text by TextOut (or ExtTextOut or DrawText) to a
bitmap, created with CreateDIBSection, so that bitmap can later be AlphaBlend
to a paint DC.
In pseudo code:
1. paintDC = BeginPaint()
2. compatibleDC = CreateCompatibleDC (paintDC)
3. bitmap = CreateDIBSection (32 bit, 1 plane, BI_RGB compression,
biSizeImage=0)
4. Select bitmap into the compatibleDC
5. fill the bitmap with some ARGB color
6. TextOut in any mode (SetBkMode) with any back color (SetBkColor) and any
text color (SetTextColor).
7. AlphaBlend compatibleDC into paintDC with AlphaFormat=AC_SRC_ALPHA
A string, used on step 6, is not visible when executed on Vista x64 (no
composition).
Note: steps 1-5, 7 are taken from Alpha Blending a Bitmap
(http://msdn.microsoft.com/en-us/library/ms532295(VS.85).aspx)
The real application uses a compatibleDC as an offscreen and drawing
directly to the paintDC is almost not an option.
Test systems: 32-bit XP SP2 and 64-bit Vista Business. Several other 64-bit
systems (some Intel-, some AMD-based) has the same problem, hence video
driver does not seem to contribute to a problem.
So, is it a known "limitation"? Or am I missing something obvious?
Side question: on 32-bit XP SP2, the behaviour of TextOut (step 6) is
different, depending on which brush is used during class registration. For
example, wcex.hbrBackground= (HBRUSH)GetStockObject(BLACK_BRUSH); works, but
(HBRUSH)(COLOR_WINDOW+1) causes the string to appear in a wrong color on a
wrong background.
Thank you for your time!
--
Kirill.
date: Mon, 26 May 2008 21:04:00 -0700
author: Kirill am
Re: TextOut to a 32-bit bitmap for AlphaBlend on Vista x64
Thats because GDI functions mostly only know about RGB, not ARGB. *MOST* GDI
functions will set the A channel to 0 and thus make your text transparent.
You'll find even basic functions like FillRect() and SetPixel() don't work
correctly when writing to ARGB surfaces.
So the way you need to do it is to build your bitmap on a 24bit RGB surface,
then after you are done, loop through and set the A channel to 0xff and then
AlphaBlend() and WS_EX_LAYERED will work as expected.
"Kirill" <akirill@newsgroup.nospam> wrote in message
news:96FF6DED-044B-4ED6-9452-F8B6F4558F83@microsoft.com...
>
> Hello,
>
> Problem: can't output text by TextOut (or ExtTextOut or DrawText) to a
> bitmap, created with CreateDIBSection, so that bitmap can later be
> AlphaBlend
> to a paint DC.
> In pseudo code:
> 1. paintDC = BeginPaint()
> 2. compatibleDC = CreateCompatibleDC (paintDC)
> 3. bitmap = CreateDIBSection (32 bit, 1 plane, BI_RGB compression,
> biSizeImage=0)
> 4. Select bitmap into the compatibleDC
> 5. fill the bitmap with some ARGB color
> 6. TextOut in any mode (SetBkMode) with any back color (SetBkColor) and
> any
> text color (SetTextColor).
> 7. AlphaBlend compatibleDC into paintDC with AlphaFormat=AC_SRC_ALPHA
>
> A string, used on step 6, is not visible when executed on Vista x64 (no
> composition).
>
> Note: steps 1-5, 7 are taken from Alpha Blending a Bitmap
> (http://msdn.microsoft.com/en-us/library/ms532295(VS.85).aspx)
>
> The real application uses a compatibleDC as an offscreen and drawing
> directly to the paintDC is almost not an option.
>
> Test systems: 32-bit XP SP2 and 64-bit Vista Business. Several other
> 64-bit
> systems (some Intel-, some AMD-based) has the same problem, hence video
> driver does not seem to contribute to a problem.
>
> So, is it a known "limitation"? Or am I missing something obvious?
>
> Side question: on 32-bit XP SP2, the behaviour of TextOut (step 6) is
> different, depending on which brush is used during class registration. For
> example, wcex.hbrBackground= (HBRUSH)GetStockObject(BLACK_BRUSH); works,
> but
> (HBRUSH)(COLOR_WINDOW+1) causes the string to appear in a wrong color on a
> wrong background.
>
> Thank you for your time!
>
> --
> Kirill.
date: Mon, 26 May 2008 23:08:44 -0700
author: Somebody
Re: TextOut to a 32-bit bitmap for AlphaBlend on Vista x64
> A string, used on step 6, is not visible when executed on Vista x64 (no
> composition).
Is there any reason why you cannot switch steps 6 and 7?
The AlphaBlend function requires that the pixels in the bitmap be
premultiplied by the alpha channel.
If the alpha channel contains a pixel color greater than zero and not 255,
then the rgb channels will have their color intensity changed.
Your text will have its rgb color intensity altered in those areas of the
bitmap.
If the alpha channel is 0, then those rgb channels in the bitmap will be
completely transparent. Your text will disappear, if it falls within those
areas.
"Kirill" <akirill@newsgroup.nospam> wrote in message
news:96FF6DED-044B-4ED6-9452-F8B6F4558F83@microsoft.com...
> Hello,
>
> Problem: can't output text by TextOut (or ExtTextOut or DrawText) to a
> bitmap, created with CreateDIBSection, so that bitmap can later be
> AlphaBlend
> to a paint DC.
> In pseudo code:
> 1. paintDC = BeginPaint()
> 2. compatibleDC = CreateCompatibleDC (paintDC)
> 3. bitmap = CreateDIBSection (32 bit, 1 plane, BI_RGB compression,
> biSizeImage=0)
> 4. Select bitmap into the compatibleDC
> 5. fill the bitmap with some ARGB color
> 6. TextOut in any mode (SetBkMode) with any back color (SetBkColor) and
> any
> text color (SetTextColor).
> 7. AlphaBlend compatibleDC into paintDC with AlphaFormat=AC_SRC_ALPHA
>
> A string, used on step 6, is not visible when executed on Vista x64 (no
> composition).
>
> Note: steps 1-5, 7 are taken from Alpha Blending a Bitmap
> (http://msdn.microsoft.com/en-us/library/ms532295(VS.85).aspx)
>
> The real application uses a compatibleDC as an offscreen and drawing
> directly to the paintDC is almost not an option.
>
> Test systems: 32-bit XP SP2 and 64-bit Vista Business. Several other
> 64-bit
> systems (some Intel-, some AMD-based) has the same problem, hence video
> driver does not seem to contribute to a problem.
>
> So, is it a known "limitation"? Or am I missing something obvious?
>
> Side question: on 32-bit XP SP2, the behaviour of TextOut (step 6) is
> different, depending on which brush is used during class registration. For
> example, wcex.hbrBackground= (HBRUSH)GetStockObject(BLACK_BRUSH); works,
> but
> (HBRUSH)(COLOR_WINDOW+1) causes the string to appear in a wrong color on a
> wrong background.
>
> Thank you for your time!
>
> --
> Kirill.
date: Tue, 27 May 2008 09:21:01 -0400
author: Michael Phillips, Jr. 0.c0m
Re: TextOut to a 32-bit bitmap for AlphaBlend on Vista x64
Hello,
"Somebody" wrote...
> Thats because GDI functions mostly only know about RGB, not ARGB. *MOST*
> GDI functions will set the A channel to 0 and thus make your text
> transparent. You'll find even basic functions like FillRect() and
> SetPixel() don't work correctly when writing to ARGB surfaces.
It's true and I'm aware of that, but unfortunately it does not explain why
the code works correctly under 32-bit Windows XP.
> So the way you need to do it is to build your bitmap on a 24bit RGB
> surface, then after you are done, loop through and set the A channel to
> 0xff and then AlphaBlend() and WS_EX_LAYERED will work as expected.
I thought about this as well and it indeed fixes the problem. Unfortunately,
I'm not sure how well it will work with TextOut and ClearType (seemingly,
the latter may use alpha channel).
--
Kirill.
> "Kirill" wrote ...
>> Problem: can't output text by TextOut (or ExtTextOut or DrawText) to a
>> bitmap, created with CreateDIBSection, so that bitmap can later be
>> AlphaBlend
>> to a paint DC.
>> In pseudo code:
>> 1. paintDC = BeginPaint()
>> 2. compatibleDC = CreateCompatibleDC (paintDC)
>> 3. bitmap = CreateDIBSection (32 bit, 1 plane, BI_RGB compression,
>> biSizeImage=0)
>> 4. Select bitmap into the compatibleDC
>> 5. fill the bitmap with some ARGB color
>> 6. TextOut in any mode (SetBkMode) with any back color (SetBkColor) and
>> any
>> text color (SetTextColor).
>> 7. AlphaBlend compatibleDC into paintDC with AlphaFormat=AC_SRC_ALPHA
>>
>> A string, used on step 6, is not visible when executed on Vista x64 (no
>> composition).
date: Tue, 27 May 2008 10:13:48 -0400
author: Kirill am
Re: TextOut to a 32-bit bitmap for AlphaBlend on Vista x64
Michael,
"Michael Phillips, Jr." wrote in message...
> Is there any reason why you cannot switch steps 6 and 7?
Well... in a sample application it does fix the problem. But in the real
application steps 2 (using window's DC) through 6 are not a part of WM_PAINT
event handler. And it would be difficult to bring step 6 into WM_PAINT.
> The AlphaBlend function requires that the pixels in the bitmap be
> premultiplied by the alpha channel.
>
> If the alpha channel contains a pixel color greater than zero and not 255,
> then the rgb channels will have their color intensity changed.
I've read about that, and even though it does not explain why it works under
32-bit Windows XP, your comment makes me wonder who's responsible for
pre-multiplying? If a bitmap is supposed to be pre-multiplied by the caller,
then 64-bit Windows Vista is very likely to be broken, because I verified
the pixels' values and in a simple test they're all relatively good (e.g.
0x00FFFFFF when drawing with white). If the pre-multiplication is done
inside of AlphaBlend, then looks like TextOut is broken on 64-bit version,
because it seemingly fills alpha with 0.
--
Kirill.
> "Kirill" wrote ...
>> Problem: can't output text by TextOut (or ExtTextOut or DrawText) to a
>> bitmap, created with CreateDIBSection, so that bitmap can later be
>> AlphaBlend
>> to a paint DC.
>> In pseudo code:
>> 1. paintDC = BeginPaint()
>> 2. compatibleDC = CreateCompatibleDC (paintDC)
>> 3. bitmap = CreateDIBSection (32 bit, 1 plane, BI_RGB compression,
>> biSizeImage=0)
>> 4. Select bitmap into the compatibleDC
>> 5. fill the bitmap with some ARGB color
>> 6. TextOut in any mode (SetBkMode) with any back color (SetBkColor) and
>> any
>> text color (SetTextColor).
>> 7. AlphaBlend compatibleDC into paintDC with AlphaFormat=AC_SRC_ALPHA
>>
>> A string, used on step 6, is not visible when executed on Vista x64 (no
>> composition).
date: Tue, 27 May 2008 10:21:32 -0400
author: Kirill am
|
|