Einzelnen Beitrag anzeigen

Medium

Registriert seit: 23. Jan 2008
3.679 Beiträge
 
Delphi 2007 Enterprise
 
#6

AW: Black and white - advanced

  Alt 4. Dez 2010, 14:23
Too few infos. What type is "Luminosity" of, and how is IntToByte() implemented?

Also, it usually is a good idea to re-order your calculation, and go with floats as long as possible to avoid nasty early rounding errors:


Delphi-Quellcode:
var
  L: Byte;
  temp: Single;
  C, M, Y: Single;
  i: array[0..5] of Single; // the percentages
begin
  C := (Bits.G+Bits.B)/2;
  Y := (Bits.R+Bits.G)/2;
  M := (Bits.R+Bits.B)/2;
  temp := (Bits.R*i[0] + Bits.G*i[1] + Bits.B*i[2] + C*i[3] + M*i[4] + Y*i[5])/300; // division by 300 is your Input() method mangled in, and put as last step for the whole thingy
  L := Byte(Round(Max(0, Min(255, temp))));
end;
Clipping and rounding and divisions are usually placed best after additions and multiplications (>=1) took place, to minimize rounding and precision errors. The brain grease spent on reordering the formulas is well spent in these places, and in this case is really simple math.
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat