From ad81c040720a28d7cdf1def05820c15667b7e9b2 Mon Sep 17 00:00:00 2001 From: Nick's Hardware Youtube Channel <56885781+nickshardware@users.noreply.github.com> Date: Sun, 28 Jan 2024 14:33:25 -0500 Subject: [PATCH] rgba custom fix --- fileprops.pas | 4 ++-- rmabout.pas | 4 ++-- rmmain.pas | 3 ++- wjavascriptarray.pas | 34 ++++++++++++++++++++++++++-------- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/fileprops.pas b/fileprops.pas index 0a6f63c..b0df1fa 100644 --- a/fileprops.pas +++ b/fileprops.pas @@ -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; @@ -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; diff --git a/rmabout.pas b/rmabout.pas index 6bdbe4c..d1d63f9 100644 --- a/rmabout.pas +++ b/rmabout.pas @@ -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 diff --git a/rmmain.pas b/rmmain.pas index e9557b1..78c8e91 100644 --- a/rmmain.pas +++ b/rmmain.pas @@ -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 diff --git a/wjavascriptarray.pas b/wjavascriptarray.pas index 580b292..c470d17 100644 --- a/wjavascriptarray.pas +++ b/wjavascriptarray.pas @@ -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 @@ -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); @@ -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);