Skip to content

Commit

Permalink
rgba custom fix
Browse files Browse the repository at this point in the history
  • Loading branch information
RetroNick2020 committed Jan 28, 2024
1 parent 775c4a1 commit ad81c04
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
4 changes: 2 additions & 2 deletions fileprops.pas
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TFileProperties = class(TForm)

public
procedure UpdateValues;
procedure SetProps(props : PngRGBASettingsRec);
procedure SetProps(var props : PngRGBASettingsRec);
procedure GetProps(var props : PngRGBASettingsRec);

end;
Expand Down Expand Up @@ -110,7 +110,7 @@ procedure TFileProperties.UpdateValues;
ColorIndexValue.Text:=IntToStr(PngRGBA.ColorIndex);
end;

procedure TFileProperties.SetProps(props : PngRGBASettingsRec);
procedure TFileProperties.SetProps(var props : PngRGBASettingsRec);
begin
PngRGBA:=props;
end;
Expand Down
4 changes: 2 additions & 2 deletions rmabout.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ interface
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,lclintf;

Const
ProgramName ='Raster Master v3.5 R102';
ProgramLicense = 'Released January 25 - 2024 under MIT License';
ProgramName ='Raster Master v3.6 R103';
ProgramLicense = 'Released January 28 - 2024 under MIT License';

type

Expand Down
3 changes: 2 additions & 1 deletion rmmain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2908,7 +2908,8 @@ procedure TRMMainForm.PropertiesFileDialogClick(Sender: TObject);
FilePropertiesDialog.GetProps(PngRGBA); //get values before change
if FilePropertiesDialog.ShowModal = mrOK then
begin
rmconfigbase.SetProps(PngRGBA); //set these values to config object
FilePropertiesDialog.GetProps(PngRGBA); //get the new updated props
rmconfigbase.SetProps(PngRGBA); //set new values to config object
end
else
begin
Expand Down
34 changes: 26 additions & 8 deletions wjavascriptarray.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Unit wjavascriptarray;
Interface
uses SysUtils,LazFileUtils,rmcore,bits;
uses SysUtils,LazFileUtils,rmcore,bits,rwpng,rmconfig;

Function WriteJavaScriptArray(x,y,x2,y2 : word;filename:string; transparent : boolean):word;
Implementation
Expand Down Expand Up @@ -86,8 +86,10 @@ function GetArraySize(width,height : integer) : longint;
ImageName : string;
asize : longint;
r,g,b,a : byte;
ColorIndex : integer;
PixelIndex : integer;
PngRGBA : PngRGBASettingsRec;
begin
rmconfigbase.GetProps(PngRGBA);
width:=x2-x+1;
height:=y2-y+1;
asize:=GetArraySize(width,height);
Expand All @@ -107,16 +109,32 @@ function GetArraySize(width,height : integer) : longint;
begin
for i:=x to x2 do
begin
colorIndex:=RMCoreBase.GetPixel(i,j);
PixelIndex:=RMCoreBase.GetPixel(i,j);

r:=RMCoreBase.palette.GetRed(ColorIndex);
g:=RMCoreBase.palette.GetGreen(ColorIndex);
b:=RMCoreBase.palette.GetBlue(ColorIndex);
r:=RMCoreBase.palette.GetRed(PixelIndex);
g:=RMCoreBase.palette.GetGreen(PixelIndex);
b:=RMCoreBase.palette.GetBlue(PixelIndex);
a:=255;
if transparent then
begin
if ColorIndex = 0 then a:=0;
if (r=255) and (g=0) and (b=255) then a:=0;
//if ColorIndex = 0 then a:=0;
//if (r=255) and (g=0) and (b=255) then a:=0;

if (PngRGBA.UseColorIndex) and (PngRGBA.ColorIndex=PixelIndex) then
begin
a:=0; // Alpha 0 = transparent
end;

if (PngRGBA.UseFuschia) and (r = 255) and (g=0) and (b=255) then //use fuschia
begin
a:=0; // Alpha 0 = transparent
end;

if (PngRGBA.UseCustom) and (r = PngRGBA.R) and (b=PngRGBA.B) and (g=PngRGBA.G) then //if custom RGB
begin
a:=PngRGBA.A; // set custom Alpha value
end;

end;
ArrayWriter(r,data,1);
ArrayWriter(g,data,1);
Expand Down

0 comments on commit ad81c04

Please sign in to comment.