AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Aero color

Ein Thema von WojTec · begonnen am 17. Jul 2012 · letzter Beitrag vom 19. Jul 2012
Antwort Antwort
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#1

Aero color

  Alt 17. Jul 2012, 15:54
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?
  Mit Zitat antworten Zitat
Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#2

AW: Aero color

  Alt 17. Jul 2012, 19:52
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.
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.686 Beiträge
 
Delphi 2007 Enterprise
 
#3

AW: Aero color

  Alt 17. Jul 2012, 23:46
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.
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)

Geändert von Medium (18. Jul 2012 um 00:40 Uhr)
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#4

Re: Aero color

  Alt 18. Jul 2012, 12:44
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
  Mit Zitat antworten Zitat
Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#5

AW: Aero color

  Alt 18. Jul 2012, 12:57
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]

Geändert von Namenloser (18. Jul 2012 um 13:09 Uhr)
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.686 Beiträge
 
Delphi 2007 Enterprise
 
#6

AW: Aero color

  Alt 18. Jul 2012, 22:42
How odd, especially because it's used in context with D3D. I stand corrected though
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#7

Re: Aero color

  Alt 19. Jul 2012, 11:26
Hm, color also is not valid.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:25 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