Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Aero color (https://www.delphipraxis.net/169400-aero-color.html)

WojTec 17. Jul 2012 14:54

Aero color
 
I want to get Aero color:

I wrote this:
Delphi-Quellcode:
var
  Params: TColorizationParams;
begin
  if IsAeroEnabled then
  begin
    if Assigned(DwmGetColorizationParameters) then
    begin
      ZeroMemory(@Params, SizeOf(Params));
      DwmGetColorizationParameters(Params);
      Result := RGB(GetBValue(Params.clrColor), GetGValue(Params.clrColor), GetRValue(Params.clrColor));
    end;
  end;
end;
It working, but because uses undocumented function (I got pointer, because I know offset), I tried again with documented function:

Delphi-Quellcode:
var
  pcrColorization: DWORD;
  pfOpaqueBlend: BOOL;
  A, R, G, B: Integer;
begin
  if IsAeroEnabled then
  begin
    if DwmGetColorizationColor(pcrColorization,pfOpaqueBlend) = S_OK then
    begin
      A := (pcrColorization and $FF000000) shr 24;
      R := (pcrColorization and $FF0000) shr 16;
      G := (pcrColorization and $FF00) shr 8;
      B := (pcrColorization and $FF);

      R := Min(255, Max(0, R + (255 - A - 40)));
      G := Min(255, Max(0, G + (255 - A - 40)));
      B := Min(255, Max(0, B + (255 - A - 40)));

      Result := RGB(R, G, B);
    end;
  end;
end;
Above formula I got from [DP]http://www.delphipraxis.net/147316-vista-win7-aero-farbe-auslesen.html[/DP]. It's not valid of course (color processing inside).

AARRGGBB, so I tried also:

Delphi-Quellcode:
  R := (pcrColorization shr 16) and $FF;
  G := (pcrColorization shr 8) and $FF;
  B := pcrColorization and $FF;
but color too dark. How to decode this color?

Namenloser 17. Jul 2012 18:52

AW: Aero color
 
I think the DWM uses the premultiplied alpha format internally (I found this blog post on premultiplied alpha quite enlightening). In short, premultiplied alpha basically means that each of the three components R, G and B is already multiplied by A. For example 50% opaque white, which we normally think of as ARGB(0.5, 1.0, 1.0, 1.0), would be ARGB(0.5, 0.5, 0.5, 0.5) in premultiplied alpha. 20% opaque blue would be ARGB(0.2, 0.0, 0.0, 0.2). 100% opaque black would be (1.0, 0.0, 0.0, 0.0) and so on...

Thus, if you do not take this into account, your colors will appear too dark if A<1.0.

Fortunately, converting premultiplied alpha back to “normal” colors (although, after reading the above blog post, you will understand that premultiplied alpha actually makes much more sense ;)) is as simple as dividing each component by A. The only catch is that you will naturally get an error if A=0 because the color is undetermined in that case.

Medium 17. Jul 2012 22:46

AW: Aero color
 
In addition to that: (32bit) colors are commonly stored in ABGR order, much less often in ARGB as you used it. Thus, you might just only have swapped the R and B channel.

WojTec 18. Jul 2012 11:44

Re: Aero color
 
Delphi-Quellcode:
      A := (pcrColorization shr 24) and $FF;
      R := (pcrColorization shr 16) and $FF;
      G := (pcrColorization shr 8) and $FF;
      B := pcrColorization and $FF;

      if A <> 0 then
      begin
        R := Clamp(R + (R div A), 0, 255);
        G := Clamp(G + (G div A), 0, 255);
        B := Clamp(B + (B div A), 0, 255);
      end;
Similar, but a bit too dark :(

Namenloser 18. Jul 2012 11:57

AW: Aero color
 
Why are you adding the original value?

Try this:
Delphi-Quellcode:
if A <> 0 then
begin
  R := Clamp(255*R div A, 0, 255);
  G := Clamp(255*G div A, 0, 255);
  B := Clamp(255*B div A, 0, 255);
end;
[edit]
Btw @Medium: The order used by this function is in fact ARGB: MSDN: “The color format of the value is 0xAARRGGBB”
[/edit]

Medium 18. Jul 2012 21:42

AW: Aero color
 
How odd, especially because it's used in context with D3D. I stand corrected though :)

WojTec 19. Jul 2012 10:26

Re: Aero color
 
Hm, color also is not valid.


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:33 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz