mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-19 14:29:29 +02:00
Added a new global variable, DisabledDrawEffectStyle, that controls how TRawImage.PerformEffect(gdeDisabled) works to improve the appearance on colored backgrounds and in dark mode apps.
There are three possible values: - ddesGrayscale This is the default and matches the existing behavior of just converting the pixels to gray. - ddesDarken Convert the image to fully black pixels with alpha transparency. This roughly matches ddesGrayscale on traditional gray backgrounds but lets colored backgrounds through. - ddesLighten Convert the image to fully white pixels with alpha transparency. This is the dark mode equivalent of ddesDarken. Existing alpha transparency is factored into the conversion. The constants used for the visibility calculation roughly match what other macOS apps use.
This commit is contained in:
parent
bd1bc6ebb5
commit
1ec73247e5
@ -268,6 +268,10 @@ function RawImageQueryFlagsToString(AFlags: TRawImageQueryFlags): string;
|
||||
|
||||
var
|
||||
MissingBits: array[0..15] of array[0..7] of word;
|
||||
// Control whether gdeDisabled is a grayscale image (classic), or uses
|
||||
// alpha-transparent black or alpha-transparent white, improving appearance
|
||||
// on non-grey light and dark backgrounds
|
||||
DisabledDrawEffectStyle: (ddesGrayscale, ddesDarken, ddesLighten) = ddesGrayscale;
|
||||
|
||||
implementation
|
||||
|
||||
@ -1651,6 +1655,7 @@ var
|
||||
AData: PRGBAQuad;
|
||||
P: Pointer;
|
||||
i, j: integer;
|
||||
Gray: Byte;
|
||||
begin
|
||||
// check here for Description. Only RGBA data can be processed here.
|
||||
if not CheckDescription then
|
||||
@ -1676,9 +1681,25 @@ begin
|
||||
begin
|
||||
with AData^ do
|
||||
begin
|
||||
Red := (Red + Green + Blue) div 3;
|
||||
Green := Red;
|
||||
Blue := Red;
|
||||
Gray := (Red + Green + Blue) div 3;
|
||||
if DisabledDrawEffectStyle = ddesLighten then
|
||||
begin
|
||||
// Apply existing alpha and reduce visibility by a further 66%
|
||||
Alpha := Byte((Integer(Gray) * Alpha) div 768);
|
||||
Gray := $FF;
|
||||
end
|
||||
else begin
|
||||
Gray := Byte(Integer(Gray) + Integer((DimPercent * (DimColor - Gray)) div 100));
|
||||
if DisabledDrawEffectStyle = ddesDarken then
|
||||
begin
|
||||
// Apply existing alpha and Reduce visibility by a further 25%
|
||||
Alpha := Byte((Integer($FF - Gray) * Alpha) div 384);
|
||||
Gray := $00;
|
||||
end;
|
||||
end;
|
||||
Red := Gray;
|
||||
Green := Gray;
|
||||
Blue := Gray;
|
||||
end;
|
||||
inc(AData);
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user