{$mode objfpc}{$h+}
program Prog_au32totimage;
uses classes, sysutils,
FPImage, FPWriteJPEG;
var
au32 : array of uint32;
w,h: integer;
i: integer;
//
function au32ToImage(au32:array of uint32; w,h:integer) : TFPMemoryImage;
var
i,j : integer;
pix : uint32;
col : TFPColor; // rgba in 0..$ffff range -> (0..$ff) << 8
begin
au32ToImage := TFPMemoryImage.Create(w,h);
for i:=0 to w-1 do
for j:=0 to h-1 do begin
pix:=au32[i*w + j];
with col do begin
red:=(pix and $FF) shl 8;
green:=((pix shr 8) and $FF) shl 8;
blue:=((pix shr 16) and $FF) shl 8;
alpha:=((pix shr 24) and $FF) shl 8;
end;
au32ToImage.Colors[i, j] := col;
end;
end;
//
procedure au32ToJPEG(au32:array of uint32; w,h:integer; fileName:string);
var
writer: TFPCustomImageWriter;
image : TFPMemoryImage;
begin
image:=au32ToImage(au32, w,h);
writer:=TFPWriterJPEG.Create;
image.SaveToFile(fileName, writer);
image.free;
writer.free;
end;
/////
begin
w:=1024; h:=w;
SetLength(au32, w*h);
randomize;
for i:=0 to w*h-1 do
au32[i]:=random($ff000000);
au32ToJPEG(au32, w,h, 'au32.jpg');
end.