# Changeset 2207Tweet

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

color: simplify CIEDE2000 distance code.

Location:
trunk
Files:
2 edited

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

 r2206 float Cp_ = 0.5f * (Cp1 + Cp2); float hp1 = fmod(atan2(lab1.z, ap1) + 2.f * pi, 2.f * pi); float hp2 = fmod(atan2(lab2.z, ap2) + 2.f * pi, 2.f * pi); float dhp; /* -pi .. pi */ if (abs(hp1 - hp2) <= pi) dhp = hp2 - hp1; else if (hp2 <= hp1) dhp = hp2 - hp1 + 2.f * pi; else dhp = hp2 - hp1 - 2.f * pi; float dHp = 2.f * sqrt(Cp1 * Cp2) * sin(dhp / 2.f); float Hp_; /* half-angle 0 .. 360 */ if (!(Cp1 * Cp2)) Hp_ = hp1 + hp2; else if (abs(hp1 - hp2) > pi && hp1 + hp2 < 2.f * pi) Hp_ = 0.5f * (hp1 + hp2) + pi; else if (abs(hp1 - hp2) > pi) Hp_ = 0.5f * (hp1 + hp2) - pi; else Hp_ = 0.5f * (hp1 + hp2); float hp1 = atan2(lab1.z, ap1); float hp2 = atan2(lab2.z, ap2); float dhp = fmod(hp2 - hp1 + 3.f * pi, 2.f * pi) - pi; /* -pi .. pi */ float dHp = 2.f * sqrt(Cp1 * Cp2) * sin(0.5f * dhp); float Hp_ = Cp1 * Cp2 ? fmod(hp1 + 0.5f * dhp + 2.f * pi, 2.f * pi) : hp1 + hp2; /* 0 .. 2pi */ float T = 1.f - 0.17f * cos(Hp_ - pi / 6.f)
• ## trunk/test/unit/color.cpp

 r2206 50.0000f,  -1.0000f,   2.0000f, 50.0000f,   0.0000f,   0.0000f,  2.3669f, 50.0000f,   2.4900f,  -0.0010f, 50.0000f,  -2.4900f,   0.0009f,  7.1792f, 50.0000f,   2.4900f,  -0.0010f, 50.0000f,  -2.4900f,   0.0010f,  7.1792f, //50.0000f,   2.4900f,  -0.0010f, 50.0000f,  -2.4900f,   0.0011f,  7.2195f, //50.0000f,   2.4900f,  -0.0010f, 50.0000f,  -2.4900f,   0.0012f,  7.2195f, //50.0000f,   2.4900f,  -0.0010f, 50.0000f,  -2.4900f,   0.0010f,  7.1792f, 50.0000f,   2.4900f,  -0.0010f, 50.0000f,  -2.4900f,   0.0011f,  7.2195f, 50.0000f,   2.4900f,  -0.0010f, 50.0000f,  -2.4900f,   0.0012f,  7.2195f, 50.0000f,  -0.0010f,   2.4900f, 50.0000f,   0.0009f,  -2.4900f,  4.8045f, //50.0000f,  -0.0010f,   2.4900f, 50.0000f,   0.0010f,  -2.4900f,  4.8045f, float d2 = Color::DistanceCIEDE2000(a, b); float d3 = Color::DistanceCIEDE2000(b, a); /* Check that our function works, and check that * it is symmetrical. */ LOLUNIT_SET_CONTEXT(n / 7); LOLUNIT_ASSERT_DOUBLES_EQUAL(d1, d2, 0.0001); LOLUNIT_ASSERT_DOUBLES_EQUAL(d2, d3, 0.0001); } }
Note: See TracChangeset for help on using the changeset viewer.