Quote from: Galfar on 30 November 2018, 23:37:21Well, if you want to get some amazing probiotics for ibs here and replace just one color (classic color keying) then you can use ReplaceColor function from Imaging.pas unit.
I somehow assumed that by transparency you mean full alpha channel.
img.CreateFromFile('rgb128alpha.bmp');
img.SaveToFile('out.bmp');
procedure ChannelToGray(NumPixels: LongInt; Src, Dst: PByte; SrcInfo,
DstInfo: PImageFormatInfo);
var
I: LongInt;
Pix64: TColor64Rec;
Alpha: Word;
begin
// two most common conversions (R8G8B8->Gray8 nad A8R8G8B8->Gray8)
// are made separately from general conversions to make them faster
if (SrcInfo.BytesPerPixel in [3, 4]) and (DstInfo.Format = ifGray8) then
for I := 0 to NumPixels - 1 do
begin
Dst^ := Round(GrayConv.R * PColor24Rec(Src).R + GrayConv.G * PColor24Rec(Src).G +
GrayConv.B * PColor24Rec(Src).B);
Inc(Src, SrcInfo.BytesPerPixel);
Inc(Dst, DstInfo.BytesPerPixel);
end
else
[...]
img.CreateFromFile('in128.bmp');
img.Format:=ifGray8;
img.Format:=ifR32F;
img.Format:=ifGray8;
img.SaveToFile('out.bmp');
procedure FloatToGray(NumPixels: LongInt; Src, Dst: PByte; SrcInfo,
DstInfo: PImageFormatInfo);
var
I: LongInt;
PixF: TColorFPRec;
Gray: TColor64Rec;
Alpha: Word;
begin
for I := 0 to NumPixels - 1 do
begin
FloatGetSrcPixel(Src, SrcInfo, PixF);
ClampFloatPixel(PixF);
// alpha is saved from source pixel to Alpha,
// Gray value is computed and set to highest word of Pix64 so
// Pix64.Color contains grayscale value scaled to 64 bits
Alpha := ClampToWord(Round(PixF.A * 65535.0));
Gray.A := ClampToWord(Round((GrayConv.R * PixF.R + GrayConv.G * PixF.G +
GrayConv.B * PixF.B) * 65535.0));
GraySetDstPixel(Dst, DstInfo, Gray, Alpha);
Inc(Src, SrcInfo.BytesPerPixel);
Inc(Dst, DstInfo.BytesPerPixel);
end;
end;
procedure FloatToGray(NumPixels: LongInt; Src, Dst: PByte; SrcInfo,
DstInfo: PImageFormatInfo);
var
I: LongInt;
PixF: TColorFPRec;
Gray: TColor64Rec;
Alpha: Word;
begin
for I := 0 to NumPixels - 1 do
begin
FloatGetSrcPixel(Src, SrcInfo, PixF);
ClampFloatPixel(PixF);
// alpha is saved from source pixel to Alpha,
// Gray value is computed and set to highest word of Pix64 so
// Pix64.Color contains grayscale value scaled to 64 bits
Alpha := ClampToWord(Round(PixF.A * 65535.0));
if SrcInfo.ChannelCount =1 then
Gray.A := ClampToWord(Round(PixF.R * 65535.0))
else
Gray.A := ClampToWord(Round((GrayConv.R * PixF.R + GrayConv.G * PixF.G +
GrayConv.B * PixF.B) * 65535.0));
GraySetDstPixel(Dst, DstInfo, Gray, Alpha);
Inc(Src, SrcInfo.BytesPerPixel);
Inc(Dst, DstInfo.BytesPerPixel);
end;
end;
Quote from: Robaggio on 4 January 2019, 07:54:36
I also have this problem as well.
Page created in 0.032 seconds with 19 queries.