Results 1 to 4 of 4

Thread: function SimilarCol(col1, col2, rT, gT, bT, hT, sT, lT, xT, yT, zT: Integer): Boolean

  1. #1
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default function SimilarCol(col1, col2, rT, gT, bT, hT, sT, lT, xT, yT, zT: Integer): Boolean

    SCAR Code:
    function SimilarRGB(col1, col2, rT, gT, bT: Integer): Boolean;
    var
      r1, g1, b1, r2, g2, b2: Integer;
    begin
      ColorToRGB(col1, r1, g1, b1);
      ColorToRGB(col2, r2, g2, b2);
      Result := InRange(r2, r1 - rT, r1 + rT) and InRange(g2, g1 - gT, g1 + gT) and InRange(b2, b1 - bT, b1 + bT);
    end;

    function SimilarHSL(col1, col2, hT, sT, lT: Integer): Boolean;
    var
      h1, s1, l1, h2, s2, l2: Extended;
    begin
      ColorToHSL(col1, h1, s1, l1);
      ColorToHSL(col2, h2, s2, l2);
      Result := (h2 > (h1 - hT)) and (h2 < (h1 + hT)) and (s2 > (s1 - sT)) and (s2 < (s1 + sT)) and (l2 > (l1 - lT)) and (l2 < (l1 + lT));
    end;

    function SimilarXYZ(col1, col2, xT, yT, zT: Integer): Boolean;
    var
      x1, y1, z1, x2, y2, z2: Extended;
    begin
      ColorToXYZ(col1, x1, y1, z1);
      ColorToHSL(col2, x2, y2, z2);
      Writeln(FloatToStr(x1) + ',' + FloatToStr(y1) + ',' + FloatToStr(z1));
      Writeln(FloatToStr(x2) + ',' + FloatToStr(y2) + ',' + FloatToStr(z2));
      Result := (x2 > (x1 - xT)) and (x2 < (x1 + xT)) and (y2 > (y1 - yT)) and (y2 < (y1 + yT)) and (z2 > (z1 - zT)) and (z2 < (z1 + zT));
    end;

    function SimilarCol(col1, col2, rT, gT, bT, hT, sT, lT, xT, yT, zT: Integer): Boolean;
    begin
      Result := SimilarRGB(col1, col2, rT, gT, bT) and SimilarHSL(col1, col2, hT, sT, lT) and SimilarXYZ(col1, col2, xT, yT, zT);
    end;

    rT, gT, bT = Red Tolerance, Green Tolerance, Blue Tolerance. The rest follow the same naming pattern with it going HSL then XYZ. It converts them into their respective states then compares them against the tolerances. Haven't tested it thoroughly, but it's pretty straight forward so don't see a reason to as initial tests showed it atleast worked roughly like it should.
    Enjoy.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  2. #2
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    Kind of useless.

    SCAR Code:
    SimilarColors(XYZToColor({...}), XYZToColor({...}), GoodTol);

    Since your probably using it for autocoloring, GoodTol could be

    SCAR Code:
    GoodTol := Abs(XYZToColor({.Some selected color.}) - XYZToColor({.Other selected color.}));


    Same for any other colorspace. Same effect, also.


    EDIT: Some selected color and its counterpart would be the min and max of your array you found, variable ... and its counterpart would be the value you are comparing against and the new value you got from a findcolor or something.
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

  3. #3
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    I just added it in as I was heavily using colour comparisons amongst the three and it made it much quicker than having the fairly long code typed out multiple times. I know it could feature much more, but I just needed basic comparisons between the various values and if anyone wishes to, they can feel free to expand it to incorporate other comparative methods etc.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  4. #4
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    If you want to avoid multiple lines of code, then just make a wrapper for the above example. It'll do the same thing, tbh.
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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