MCPcopy Create free account
hub / github.com/Kitware/VTK / TestColorConvert

Function TestColorConvert

Common/Core/Testing/Cxx/TestMath.cxx:741–831  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

739}
740
741static int TestColorConvert(
742 const Triple& rgb, const Triple& hsv, const Triple& xyz, const Triple& lab, const Triple& prolab)
743{
744 std::cout << "Ensuring the following colors are consistent: " << std::endl;
745 std::cout << " RGB: " << rgb << std::endl;
746 std::cout << " HSV: " << hsv << std::endl;
747 std::cout << " CIE XYZ: " << xyz << std::endl;
748 std::cout << " CIE-L*ab: " << lab << std::endl;
749 std::cout << " ProLAB: " << prolab << std::endl;
750
751 Triple result1;
752
753#define COMPARE(testname, target, dest) \
754 do \
755 { \
756 if ((target) != (dest)) \
757 { \
758 vtkGenericWarningMacro(<< "Incorrect " #testname " conversion. Got " << (dest) \
759 << " expected " << (target)); \
760 return 0; \
761 } \
762 } while (false)
763
764 // Test conversion between RGB and HSV.
765 vtkMath::RGBToHSV(rgb(), result1());
766 COMPARE(RGBToHSV, hsv, result1);
767 vtkMath::HSVToRGB(hsv(), result1());
768 COMPARE(HSVToRGB, rgb, result1);
769
770 vtkMath::RGBToHSV(rgb[0], rgb[1], rgb[2], &result1[0], &result1[1], &result1[2]);
771 COMPARE(RGBToHSV, hsv, result1);
772 vtkMath::HSVToRGB(hsv[0], hsv[1], hsv[2], &result1[0], &result1[1], &result1[2]);
773 COMPARE(HSVToRGB, rgb, result1);
774
775 // Test conversion between RGB and XYZ.
776 vtkMath::RGBToXYZ(rgb(), result1());
777 COMPARE(RGBToXYZ, xyz, result1);
778 vtkMath::XYZToRGB(xyz(), result1());
779 COMPARE(XYZToRGB, rgb, result1);
780
781 vtkMath::RGBToXYZ(rgb[0], rgb[1], rgb[2], &result1[0], &result1[1], &result1[2]);
782 COMPARE(RGBToXYZ, xyz, result1);
783 vtkMath::XYZToRGB(xyz[0], xyz[1], xyz[2], &result1[0], &result1[1], &result1[2]);
784 COMPARE(XYZToRGB, rgb, result1);
785
786 // Test conversion between Lab and XYZ.
787 vtkMath::LabToXYZ(lab(), result1());
788 COMPARE(LabToXYZ, xyz, result1);
789 vtkMath::XYZToLab(xyz(), result1());
790 COMPARE(XYZToLab, lab, result1);
791
792 vtkMath::LabToXYZ(lab[0], lab[1], lab[2], &result1[0], &result1[1], &result1[2]);
793 COMPARE(LabToXYZ, xyz, result1);
794 vtkMath::XYZToLab(xyz[0], xyz[1], xyz[2], &result1[0], &result1[1], &result1[2]);
795 COMPARE(XYZToLab, lab, result1);
796
797 // Test conversion between Lab and RGB.
798 vtkMath::LabToRGB(lab(), result1());

Callers 1

TestMathFunction · 0.85

Calls 13

rgbClass · 0.85
HSVToRGBFunction · 0.85
RGBToXYZFunction · 0.85
XYZToRGBFunction · 0.85
LabToXYZFunction · 0.85
XYZToLabFunction · 0.85
LabToRGBFunction · 0.85
RGBToLabFunction · 0.85
ProLabToXYZFunction · 0.85
XYZToProLabFunction · 0.85
ProLabToRGBFunction · 0.85
RGBToProLabFunction · 0.85

Tested by

no test coverage detected