Einzelnen Beitrag anzeigen

Peter666

Registriert seit: 11. Aug 2007
357 Beiträge
 
#3

AW: Additives Alphablending

  Alt 27. Jan 2015, 11:21
Naja ich brauch die auch für ARM

Meine aktuelle Lösung schaut so aus:

Delphi-Quellcode:
function Scale32(scale, p: cardinal): cardinal;
var
  ag, rb: cardinal;
  sag, srb: cardinal;
begin
  ag := (p and $FF00FF00) shr 8;
  rb := p and $00FF00FF;

  sag := scale * ag;
  srb := scale * rb;

  sag := sag and $FF00FF00;
  srb := srb shr 8 and $00FF00FF;

  result := sag or srb;
end;

function blend_avg(source, target: cardinal): cardinal;
begin
  result := ((source and $FCFCFCFC) + (target and $FCFCFCFC)) shr 1;
end;

function blend_mul(source, target: cardinal): cardinal;
var
  sourcea, sourcer, sourceg, sourceb, targeta, targetr, targetg,
    targetb: integer;
begin
  sourcer := (source shr 0) and $FF;
  sourceg := (source shr 8) and $FF;
  sourceb := (source shr 16) and $FF;
  sourcea := (source shr 24) and $FF;

  targetr := (target shr 0) and $FF;
  targetg := (target shr 8) and $FF;
  targetb := (target shr 16) and $FF;
  targeta := (target shr 24) and $FF;

  targetr := (sourcer * targetr) shr 8;
  targetg := (sourceg * targetg) shr 8;
  targetb := (sourceb * targetb) shr 8;
  targeta := (sourcea * targeta) shr 8;

  result := (targetr shl 0) or (targetg shl 8) or (targetb shl 16) or
    (targeta shl 24);
end;

function blend_add(source, target: cardinal): cardinal;
const
  signmask = $80808080;
var
  t0, t1: cardinal;
begin
  t0 := (source xor target) and signmask;
  t1 := (source and target) and signmask;

  source := source and (not signmask);
  target := target and (not signmask);
  source := source + target;

  t1 := t1 or (t0 and source);
  t1 := (t1 shl 1) - (t1 shr 7);
  result := (source xor t0) or t1;
end;

function blend_alpha(src, tgt: cardinal): cardinal;
var
  alpha, invalpha: integer;
begin
  alpha := (tgt shr 24) and $FF;
  invalpha := $FF - alpha;

  result := Scale32(alpha, tgt) + Scale32(invalpha, src);
end;
Das klappt auch mit Alpha recht gut, aber addaptiv schaut nicht so aus wie es sollte.
  Mit Zitat antworten Zitat