Skip to content

Commit

Permalink
Luminance inversion workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
PC-SUMMO\Michele Summo committed Aug 25, 2022
1 parent 98027ce commit 2849aff
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 32 deletions.
2 changes: 1 addition & 1 deletion apophysis7x/Apophysis7X.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ProjectGuid>{AC01F3AB-4101-4C09-A648-1CC8E2C412D5}</ProjectGuid>
<MainSource>Apophysis7X.dpr</MainSource>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
<Config Condition="'$(Config)'==''">Release</Config>
<TargetedPlatforms>3</TargetedPlatforms>
<AppType>Application</AppType>
<FrameworkType>VCL</FrameworkType>
Expand Down
71 changes: 40 additions & 31 deletions apophysis7x/Rendering/ImageMaker.pas
Original file line number Diff line number Diff line change
Expand Up @@ -367,28 +367,28 @@ procedure TImageMaker.SetCP(CP: TControlPoint);
Fcp := CP;
end;

procedure InvertLuminance(var red: integer; var green: integer; var blue: integer);
procedure InvertLuminance(var rgb: TRGB);
var
max, min, c: integer;
max, min, c: byte;
begin
max := red;
min := red;
max := rgb.red;
min := rgb.red;

if max < green then
max := green;
if min > green then
min := green;
if max < rgb.green then
max := rgb.green;
if min > rgb.green then
min := rgb.green;

if max < blue then
max := blue;
if min > blue then
min := blue;
if max < rgb.blue then
max := rgb.blue;
if min > rgb.blue then
min := rgb.blue;

c := 255 - max - min;

red := red + c;
green := green + c;
blue := blue + c;
rgb.red := rgb.red + c;
rgb.green := rgb.green + c;
rgb.blue := rgb.blue + c;
end;

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -408,7 +408,7 @@ procedure TImageMaker.CreateImage(YOffset: integer);
Row: PRGBArray;
AlphaRow: PbyteArray;
vib, notvib: Integer;
bgi: array[0..2] of Integer;
bgi: TRGB;
// bucketpos: Integer;
filterValue: double;
// filterpos: Integer;
Expand Down Expand Up @@ -449,12 +449,15 @@ procedure TImageMaker.CreateImage(YOffset: integer);
funcval := power(fcp.gamma_threshold, gamma - 1) { / fcp.gamma_threshold; }
else funcval := 0;

bgi[0] := round(fcp.background[0]);
bgi[1] := round(fcp.background[1]);
bgi[2] := round(fcp.background[2]);
bgtot.red := bgi[0];
bgtot.green := bgi[1];
bgtot.blue := bgi[2];
//MS
bgi.red := round(fcp.background[0]);
bgi.green := round(fcp.background[1]);
bgi.blue := round(fcp.background[2]);
if fcp.invert_luminance then
InvertLuminance(bgi);
bgtot.red := bgi.red;
bgtot.green := bgi.green;
bgtot.blue := bgi.blue;
zero_BG.red := 0;
zero_BG.green := 0;
zero_BG.blue := 0;
Expand Down Expand Up @@ -670,12 +673,14 @@ procedure TImageMaker.CreateImage(YOffset: integer);
if (bi < 0) then bi := 0
else if (bi > 255) then bi := 255;

//MS MUTATION
if fcp.invert_luminance then
InvertLuminance(ri, gi, bi);
Row[j].red := ri;
Row[j].green := gi;
Row[j].blue := bi;

//MS MUTATION
if fcp.invert_luminance then
InvertLuminance(Row[j]);

AlphaRow[j] := ai;
end
else begin // ------------------------------------------- No transparency
Expand All @@ -698,6 +703,8 @@ procedure TImageMaker.CreateImage(YOffset: integer);
// no intensity so simply set the BG;
//MS XXX
Row[j] := bgtot;
if fcp.invert_luminance then
InvertLuminance(Row[j]);
continue;
end;

Expand All @@ -716,24 +723,26 @@ procedure TImageMaker.CreateImage(YOffset: integer);
if (gi >= 0) and (gi <= 256) and (curvesSet) then gi := Round(csa[2][Round(csa[0][gi])]);
if (bi >= 0) and (bi <= 256) and (curvesSet) then bi := Round(csa[3][Round(csa[0][bi])]);

ri := ri + (ia * bgi[0]) shr 8;
ri := ri + (ia * bgi.red) shr 8;
if (ri < 0) then ri := 0
else if (ri > 255) then ri := 255;

gi := gi + (ia * bgi[1]) shr 8;
gi := gi + (ia * bgi.green) shr 8;
if (gi < 0) then gi := 0
else if (gi > 255) then gi := 255;

bi := bi + (ia * bgi[2]) shr 8;
bi := bi + (ia * bgi.blue) shr 8;
if (bi < 0) then bi := 0
else if (bi > 255) then bi := 255;

//MS MUTATION
if fcp.invert_luminance then
InvertLuminance(ri, gi, bi);
Row[j].red := ri;
Row[j].green := gi;
Row[j].blue := bi;

//MS MUTATION
if fcp.invert_luminance then
InvertLuminance(Row[j]);

AlphaRow[j] := ai;//?
end
end;
Expand Down

0 comments on commit 2849aff

Please sign in to comment.