Results 1 to 9 of 9

Thread: How to desaturate image?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    Code:
    Function Gray(vColor:TByte4):TByte4;
    Var
      vAverage:TFlt;
    begin
      vAverage:=vColor.R*0.3+vColor.G*0.59+vColor.B*0.11;
      result.R:=Round(vAverage);
      result.G:=Round(vAverage);
      result.B:=Round(vAverage);
      result.A:=vColor.A;
    end;

  2. #2
    Quote Originally Posted by Carver413 View Post
    Code:
    Function Gray(vColor:TByte4):TByte4;
    Var
      vAverage:TFlt;
    begin
      vAverage:=vColor.R*0.3+vColor.G*0.59+vColor.B*0.11;
      result.R:=Round(vAverage);
      result.G:=Round(vAverage);
      result.B:=Round(vAverage);
      result.A:=vColor.A;
    end;
    Round() would be bottlenecking that
    Code:
    Function Gray(vColor:TByte4):TByte4;
    Var
      vAverage: byte;
    begin
      vAverage:=round(vColor.R*0.3+vColor.G*0.59+vColor.B*0.11);
      result.R:=vAverage;
      result.G:=vAverage;
      result.B:=vAverage;
      result.A:=vColor.A;
    end;
    The function should work, if you are getting black you are not using it with right parameters and result value. It's not directly compatible with TColor if that is the type.
    Last edited by User137; 16-07-2014 at 05:25 PM.

  3. #3
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    Quote Originally Posted by User137 View Post
    Round() would be bottlenecking that
    Code:
    Function Gray(vColor:TByte4):TByte4; Var   vAverage: byte; begin   vAverage:=round(vColor.R*0.3+vColor.G*0.59+vColor.B*0.11);   result.R:=vAverage;   result.G:=vAverage;   result.B:=vAverage;   result.A:=vColor.A; end;
    The function should work, if you are getting black you are not using it with right parameters and result value. It's not directly compatible with TColor if that is the type.
    Thanks, I guess I overlooked that.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •