Changeset 2207


Ignore:
Timestamp:
Jan 7, 2013, 1:42:03 PM (7 years ago)
Author:
sam
Message:

color: simplify CIEDE2000 distance code.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/image/color/cie1931.cpp

    r2206 r2207  
    4747    float Cp_ = 0.5f * (Cp1 + Cp2);
    4848
    49     float hp1 = fmod(atan2(lab1.z, ap1) + 2.f * pi, 2.f * pi);
    50     float hp2 = fmod(atan2(lab2.z, ap2) + 2.f * pi, 2.f * pi);
    51     float dhp; /* -pi .. pi */
    52     if (abs(hp1 - hp2) <= pi)
    53         dhp = hp2 - hp1;
    54     else if (hp2 <= hp1)
    55         dhp = hp2 - hp1 + 2.f * pi;
    56     else
    57         dhp = hp2 - hp1 - 2.f * pi;
    58     float dHp = 2.f * sqrt(Cp1 * Cp2) * sin(dhp / 2.f);
    59     float Hp_; /* half-angle 0 .. 360 */
    60     if (!(Cp1 * Cp2))
    61         Hp_ = hp1 + hp2;
    62     else if (abs(hp1 - hp2) > pi && hp1 + hp2 < 2.f * pi)
    63         Hp_ = 0.5f * (hp1 + hp2) + pi;
    64     else if (abs(hp1 - hp2) > pi)
    65         Hp_ = 0.5f * (hp1 + hp2) - pi;
    66     else
    67         Hp_ = 0.5f * (hp1 + hp2);
     49    float hp1 = atan2(lab1.z, ap1);
     50    float hp2 = atan2(lab2.z, ap2);
     51    float dhp = fmod(hp2 - hp1 + 3.f * pi, 2.f * pi) - pi; /* -pi .. pi */
     52    float dHp = 2.f * sqrt(Cp1 * Cp2) * sin(0.5f * dhp);
     53    float Hp_ = Cp1 * Cp2 ? fmod(hp1 + 0.5f * dhp + 2.f * pi, 2.f * pi) : hp1 + hp2; /* 0 .. 2pi */
    6854
    6955    float T = 1.f - 0.17f * cos(Hp_ - pi / 6.f)
  • trunk/test/unit/color.cpp

    r2206 r2207  
    3434    50.0000f,  -1.0000f,   2.0000f, 50.0000f,   0.0000f,   0.0000f,  2.3669f,
    3535    50.0000f,   2.4900f,  -0.0010f, 50.0000f,  -2.4900f,   0.0009f,  7.1792f,
    36     50.0000f,   2.4900f,  -0.0010f, 50.0000f,  -2.4900f,   0.0010f,  7.1792f,
    37     //50.0000f,   2.4900f,  -0.0010f, 50.0000f,  -2.4900f,   0.0011f,  7.2195f,
    38     //50.0000f,   2.4900f,  -0.0010f, 50.0000f,  -2.4900f,   0.0012f,  7.2195f,
     36    //50.0000f,   2.4900f,  -0.0010f, 50.0000f,  -2.4900f,   0.0010f,  7.1792f,
     37    50.0000f,   2.4900f,  -0.0010f, 50.0000f,  -2.4900f,   0.0011f,  7.2195f,
     38    50.0000f,   2.4900f,  -0.0010f, 50.0000f,  -2.4900f,   0.0012f,  7.2195f,
    3939    50.0000f,  -0.0010f,   2.4900f, 50.0000f,   0.0009f,  -2.4900f,  4.8045f,
    4040    //50.0000f,  -0.0010f,   2.4900f, 50.0000f,   0.0010f,  -2.4900f,  4.8045f,
     
    7878
    7979            float d2 = Color::DistanceCIEDE2000(a, b);
     80            float d3 = Color::DistanceCIEDE2000(b, a);
    8081
     82            /* Check that our function works, and check that
     83             * it is symmetrical. */
     84            LOLUNIT_SET_CONTEXT(n / 7);
    8185            LOLUNIT_ASSERT_DOUBLES_EQUAL(d1, d2, 0.0001);
     86            LOLUNIT_ASSERT_DOUBLES_EQUAL(d2, d3, 0.0001);
    8287        }
    8388    }
Note: See TracChangeset for help on using the changeset viewer.