Skip to content

Commit 758f914

Browse files
committed
XYZ constants made softdouble
1 parent 121fa04 commit 758f914

File tree

1 file changed

+50
-26
lines changed

1 file changed

+50
-26
lines changed

modules/imgproc/test/test_color.cpp

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -899,24 +899,42 @@ void CV_ColorHLSTest::convert_row_abc2bgr_32f_c3( const float* src_row, float* d
899899
}
900900
}
901901

902-
903-
static const double RGB2XYZ[] =
904-
{
905-
0.412453, 0.357580, 0.180423,
906-
0.212671, 0.715160, 0.072169,
907-
0.019334, 0.119193, 0.950227
902+
// 0.412453, 0.357580, 0.180423,
903+
// 0.212671, 0.715160, 0.072169,
904+
// 0.019334, 0.119193, 0.950227
905+
static const softdouble RGB2XYZ[] =
906+
{
907+
softdouble::fromRaw(0x3fda65a14488c60d),
908+
softdouble::fromRaw(0x3fd6e297396d0918),
909+
softdouble::fromRaw(0x3fc71819d2391d58),
910+
softdouble::fromRaw(0x3fcb38cda6e75ff6),
911+
softdouble::fromRaw(0x3fe6e297396d0918),
912+
softdouble::fromRaw(0x3fb279aae6c8f755),
913+
softdouble::fromRaw(0x3f93cc4ac6cdaf4b),
914+
softdouble::fromRaw(0x3fbe836eb4e98138),
915+
softdouble::fromRaw(0x3fee68427418d691)
908916
};
909917

910-
911-
static const double XYZ2RGB[] =
912-
{
913-
3.240479, -1.53715, -0.498535,
914-
-0.969256, 1.875991, 0.041556,
915-
0.055648, -0.204043, 1.057311
918+
// 3.240479, -1.53715, -0.498535,
919+
// -0.969256, 1.875991, 0.041556,
920+
// 0.055648, -0.204043, 1.057311
921+
static const softdouble XYZ2RGB[] =
922+
{
923+
softdouble::fromRaw(0x4009ec804102ff8f),
924+
softdouble::fromRaw(0xbff8982a9930be0e),
925+
softdouble::fromRaw(0xbfdfe7ff583a53b9),
926+
softdouble::fromRaw(0xbfef042528ae74f3),
927+
softdouble::fromRaw(0x3ffe040f23897204),
928+
softdouble::fromRaw(0x3fa546d3f9e7b80b),
929+
softdouble::fromRaw(0x3fac7de5082cf52c),
930+
softdouble::fromRaw(0xbfca1e14bdfd2631),
931+
softdouble::fromRaw(0x3ff0eabef06b3786)
916932
};
917933

918-
static const float Xn = 0.950456f;
919-
static const float Zn = 1.088754f;
934+
//0.950456
935+
static const softdouble Xn = softdouble::fromRaw(0x3fee6a22b3892ee8);
936+
//1.088754
937+
static const softdouble Zn = softdouble::fromRaw(0x3ff16b8950763a19);
920938

921939

922940
//// rgb <=> xyz
@@ -959,12 +977,13 @@ double CV_ColorXYZTest::get_success_error_level( int /*test_case_idx*/, int i, i
959977
void CV_ColorXYZTest::convert_row_bgr2abc_32f_c3( const float* src_row, float* dst_row, int n )
960978
{
961979
int depth = test_mat[INPUT][0].depth();
962-
double scale = depth == CV_8U ? 255 : depth == CV_16U ? 65535 : 1;
980+
softdouble scale(depth == CV_8U ? 255 :
981+
depth == CV_16U ? 65535 : 1);
963982

964983
double M[9];
965984
int j;
966985
for( j = 0; j < 9; j++ )
967-
M[j] = RGB2XYZ[j]*scale;
986+
M[j] = (double)(RGB2XYZ[j]*scale);
968987

969988
for( j = 0; j < n*3; j += 3 )
970989
{
@@ -984,12 +1003,13 @@ void CV_ColorXYZTest::convert_row_bgr2abc_32f_c3( const float* src_row, float* d
9841003
void CV_ColorXYZTest::convert_row_abc2bgr_32f_c3( const float* src_row, float* dst_row, int n )
9851004
{
9861005
int depth = test_mat[INPUT][0].depth();
987-
double scale = depth == CV_8U ? 1./255 : depth == CV_16U ? 1./65535 : 1;
1006+
softdouble scale(depth == CV_8U ? 1./255 :
1007+
depth == CV_16U ? 1./65535 : 1);
9881008

9891009
double M[9];
9901010
int j;
9911011
for( j = 0; j < 9; j++ )
992-
M[j] = XYZ2RGB[j]*scale;
1012+
M[j] = (double)(XYZ2RGB[j]*scale);
9931013

9941014
for( j = 0; j < n*3; j += 3 )
9951015
{
@@ -1082,6 +1102,7 @@ void CV_ColorLabTest::convert_row_bgr2abc_32f_c3(const float* src_row, float* ds
10821102
for (int j = 0; j < 9; j++ )
10831103
M[j] = (float)RGB2XYZ[j];
10841104

1105+
float xn = (float)Xn, zn = (float)Zn;
10851106
for (int x = 0; x < n*3; x += 3)
10861107
{
10871108
float R = src_row[x + 2];
@@ -1098,9 +1119,9 @@ void CV_ColorLabTest::convert_row_bgr2abc_32f_c3(const float* src_row, float* ds
10981119
B = applyGamma(B);
10991120
}
11001121

1101-
float X = (R * M[0] + G * M[1] + B * M[2]) / Xn;
1122+
float X = (R * M[0] + G * M[1] + B * M[2]) / xn;
11021123
float Y = R * M[3] + G * M[4] + B * M[5];
1103-
float Z = (R * M[6] + G * M[7] + B * M[8]) / Zn;
1124+
float Z = (R * M[6] + G * M[7] + B * M[8]) / zn;
11041125

11051126
float fX = X > lthresh ? cubeRoot(X) : (lowScale * X + f16of116);
11061127
float fY = Y > lthresh ? cubeRoot(Y) : (lowScale * Y + f16of116);
@@ -1136,6 +1157,7 @@ void CV_ColorLabTest::convert_row_abc2bgr_32f_c3( const float* src_row, float* d
11361157
// 903.3 = (29/3)^3
11371158
static const float yscale = 29.f*29.f*29.f/27.f;
11381159

1160+
float xn = (float)Xn, zn = (float)Zn;
11391161
for (int x = 0, end = n * 3; x < end; x += 3)
11401162
{
11411163
float L = src_row[x] * Lscale;
@@ -1165,8 +1187,8 @@ void CV_ColorLabTest::convert_row_abc2bgr_32f_c3( const float* src_row, float* d
11651187
else
11661188
FXZ[k] = FXZ[k] * FXZ[k] * FXZ[k];
11671189
}
1168-
float X = FXZ[0] * Xn;
1169-
float Z = FXZ[1] * Zn;
1190+
float X = FXZ[0] * xn;
1191+
float Z = FXZ[1] * zn;
11701192

11711193
float R = M[0] * X + M[1] * Y + M[2] * Z;
11721194
float G = M[3] * X + M[4] * Y + M[5] * Z;
@@ -1246,8 +1268,9 @@ void CV_ColorLuvTest::convert_row_bgr2abc_32f_c3( const float* src_row, float* d
12461268

12471269
float M[9];
12481270
// Yn == 1
1249-
float dd = Xn + 15.f*1.f + 3.f*Zn;
1250-
float un = 4.f*13.f*Xn/dd;
1271+
float xn = (float)Xn, zn = (float)Zn;
1272+
float dd = xn + 15.f*1.f + 3.f*zn;
1273+
float un = 4.f*13.f*xn/dd;
12511274
float vn = 9.f*13.f/dd;
12521275

12531276
float u_scale = 1.f, u_bias = 0.f;
@@ -1322,8 +1345,9 @@ void CV_ColorLuvTest::convert_row_abc2bgr_32f_c3( const float* src_row, float* d
13221345
int j;
13231346
float M[9];
13241347
// Yn == 1
1325-
float dd = Xn + 15.f*1.f + 3.f*Zn;
1326-
float un = 4*13.f*Xn/dd;
1348+
float xn = (float)Xn, zn = (float)Zn;
1349+
float dd = xn + 15.f*1.f + 3.f*zn;
1350+
float un = 4*13.f*xn/dd;
13271351
float vn = 9*13.f*1.f/dd;
13281352

13291353
float u_scale = 1.f, u_bias = 0.f;

0 commit comments

Comments
 (0)