我需要一个提示,如何使用 SSE2 程序集(32 位)实现这个 Delphi 函数。也欢迎其他优化。也许有人可以告诉我,可以使用什么样的指令,所以我有一个进一步阅读的起点。
实际的:
const Precision = 10000;
// This function adds all Pixels into one. The pixels are weighted before adding.
// A weight can range from 0 to "Precision". "Size" is typically 10 to 50.
function TFilter.Combine(Pixels: PByte; Weights: PCardinal; const Size: Cardinal): Cardinal;
var
i, R, G, B, A: Cardinal;
begin
B := Pixels^ * Weights^; Inc(Pixels);
G := Pixels^ * Weights^; Inc(Pixels);
R := Pixels^ * Weights^; Inc(Pixels);
A := Pixels^ * Weights^; Inc(Pixels);
Inc(Weights); // goto next weight
for i := 1 to Size - 1 do
begin
Inc(B, Pixels^ * Weights^); Inc(Pixels);
Inc(G, Pixels^ * Weights^); Inc(Pixels);
Inc(R, Pixels^ * Weights^); Inc(Pixels);
Inc(A, Pixels^ * Weights^); Inc(Pixels);
Inc(Weights); // goto next weight
end;
B := B div Precision;
G := G div Precision;
R := R div Precision;
A := A div Precision;
Result := A shl 24 or R shl 16 or G shl 8 or B;
end;
预期的:
function TFilter.Combine(Pixels: PByte; Weights: PCardinal; const Size: Cardinal): Cardinal;
asm
// Insert fast SSE2-Code here ;-)
end;