Skip to content

Commit

Permalink
transparent png
Browse files Browse the repository at this point in the history
  • Loading branch information
RetroNick2020 committed May 9, 2022
1 parent 5994767 commit d66dcb4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rmabout.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,lclintf;

Const
ProgramName ='Raster Master v1.0 R44';
ProgramName ='Raster Master v1.0 R45';
ProgramLicense = 'Released under MIT License';

type
Expand Down
43 changes: 42 additions & 1 deletion rwpng.pas
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ function ReadPNG(x,y,x2,y2 : integer;filename : string; LoadPalette : Boolean) :
EasyPNG.Free;
ReadPNG:=0;
end;

(* no transparent support
procedure TEasyPNG.CopyCoreToImage(x,y,x2,y2 : integer);
var
Expand All @@ -408,6 +408,7 @@ procedure TEasyPNG.CopyCoreToImage(x,y,x2,y2 : integer);
picture1.Bitmap.Width:=width;
Picture1.Bitmap.height:=height;
picture1.Bitmap.PixelFormat:=pf32bit;
for j:=0 to height-1 do
begin
for i:=0 to width-1 do
Expand All @@ -419,6 +420,46 @@ procedure TEasyPNG.CopyCoreToImage(x,y,x2,y2 : integer);
end;
end;
end;
*)

procedure TEasyPNG.CopyCoreToImage(x,y,x2,y2 : integer);
var
width,height : integer;
i,j : integer;
ci : integer;
cr : TRMColorRec;
pixeldata : PByte;
pixelpos : longint;
begin
width:=x2-x+1;
height:=y2-y+1;

picture1.Bitmap.Width:=width;
Picture1.Bitmap.height:=height;
picture1.Bitmap.PixelFormat:=pf32bit; //change format to 32 bit/RGBA
pixeldata:=picture1.Bitmap.RawImage.Data;
pixelpos:=0;
for j:=0 to height-1 do
begin
for i:=0 to width-1 do
begin
ci:=RMCoreBase.GetPixel(x+i,y+j);
RMCoreBase.Palette.GetColor(ci,cr);
pixeldata[pixelpos]:=cr.b; // Blue
pixeldata[pixelpos+1]:=cr.g; // Green
pixeldata[pixelpos+2]:=cr.r; // Red
if (cr.r = 255) and (cr.b=255) and (cr.g=0) then //if fuschia
begin
pixeldata[pixelpos+3]:=0; // Alpha 0 = transparent
end
else
begin
pixeldata[pixelpos+3]:=255; // Alpha 255 = solid
end;
inc(pixelpos,4);
end;
end;
end;


Procedure TEasyPNG.SaveToFile(filename : string);
Expand Down

0 comments on commit d66dcb4

Please sign in to comment.