@@ -257,6 +257,55 @@ OCIO_ADD_TEST(DynamicPropertyImpl, equal_grading_rgb_curve)
257
257
OCIO_CHECK_ASSERT (!(*dp0 == *dpImplDouble));
258
258
}
259
259
260
+ OCIO_ADD_TEST (DynamicPropertyImpl, setter_validation)
261
+ {
262
+ // Make an identity dynamic transform.
263
+ OCIO::GradingHueCurveTransformRcPtr gct = OCIO::GradingHueCurveTransform::Create (OCIO::GRADING_LOG);
264
+ gct->makeDynamic ();
265
+
266
+ // Apply it on CPU.
267
+ OCIO::ConfigRcPtr config = OCIO::Config::Create ();
268
+ OCIO::ConstProcessorRcPtr processor = config->getProcessor (gct);
269
+ OCIO::ConstCPUProcessorRcPtr cpuProcessor = processor->getDefaultCPUProcessor ();
270
+
271
+ float pixel[3 ] = { 0 .4f , 0 .3f , 0 .2f };
272
+ cpuProcessor->applyRGB (pixel);
273
+
274
+ const float error = 1e-5f ;
275
+ OCIO_CHECK_CLOSE (pixel[0 ], pixel[0 ], error);
276
+ OCIO_CHECK_CLOSE (pixel[1 ], pixel[1 ], error);
277
+ OCIO_CHECK_CLOSE (pixel[2 ], pixel[2 ], error);
278
+
279
+ // Get a handle to the dynamic property.
280
+ OCIO::DynamicPropertyRcPtr dp;
281
+ OCIO_CHECK_NO_THROW (dp = cpuProcessor->getDynamicProperty (OCIO::DYNAMIC_PROPERTY_GRADING_HUECURVE));
282
+ auto dpVal = OCIO::DynamicPropertyValue::AsGradingHueCurve (dp);
283
+ OCIO_REQUIRE_ASSERT (dpVal);
284
+
285
+ // Set a non-identity value.
286
+ OCIO::GradingHueCurveRcPtr hueCurve = dpVal->getValue ()->createEditableCopy ();
287
+ OCIO::GradingBSplineCurveRcPtr huehue = hueCurve->getCurve (OCIO::HUE_HUE);
288
+ huehue->setNumControlPoints (3 );
289
+ huehue->getControlPoint (0 ) = OCIO::GradingControlPoint (0 .f , -0 .1f );
290
+ huehue->getControlPoint (1 ) = OCIO::GradingControlPoint (0 .5f , 0 .5f );
291
+ huehue->getControlPoint (2 ) = OCIO::GradingControlPoint (0 .8f , 0 .8f );
292
+ dpVal->setValue (hueCurve);
293
+ cpuProcessor->applyRGB (pixel);
294
+
295
+ OCIO_CHECK_CLOSE (pixel[0 ], 0 .4385873675f , error);
296
+ OCIO_CHECK_CLOSE (pixel[1 ], 0 .2829087377f , error);
297
+ OCIO_CHECK_CLOSE (pixel[2 ], 0 .2556785941f , error);
298
+
299
+ // Ensure that validation of control points is happening as expected. Set the last point
300
+ // so that it is no longer monotonic with respect to the first point. Because it is periodic,
301
+ // the last point Y value becomes -0.05 when wrapped around to an X value of -0.2.
302
+ huehue->getControlPoint (2 ) = OCIO::GradingControlPoint (0 .8f , 0 .95f );
303
+ OCIO_CHECK_THROW_WHAT (dpVal->setValue (hueCurve),
304
+ OCIO::Exception,
305
+ " GradingHueCurve validation failed for 'hue_hue' curve with: Control point at index 0 "
306
+ " has a y coordinate '-0.1' that is less than previous control point y coordinate '-0.05'." );
307
+ }
308
+
260
309
OCIO_ADD_TEST (DynamicPropertyImpl, grading_rgb_curve_knots_coefs)
261
310
{
262
311
auto curve11 = OCIO::GradingBSplineCurve::Create ({ { 0 .f , 10 .f },{ 2 .f , 10 .f },{ 3 .f , 10 .f },
@@ -431,8 +480,8 @@ void checkKnotsAndCoefs(
431
480
432
481
OCIO_ADD_TEST (DynamicPropertyImpl, grading_hue_curve_knots_coefs)
433
482
{
434
- auto hh = OCIO::GradingBSplineCurve::Create (
435
- { {- 0 .1f , - 0 . 15f }, {0 .2f , 0 .3f }, {0 .5f , 0 .25f }, {0 .8f , 0 .7f }, {0 .85f , 0 .8f }, {1 .05f , 0 .9f } },
483
+ auto hh = OCIO::GradingBSplineCurve::Create (
484
+ { {0 .1f , 0 . 05f }, {0 .2f , 0 .3f }, {0 .5f , 0 .4f }, {0 .8f , 0 .7f }, {0 .9f , 0 .75f }, {1 .0f , 0 .9f } },
436
485
OCIO::HUE_HUE);
437
486
auto hs = OCIO::GradingBSplineCurve::Create (
438
487
{ {-0 .15f , 1 .25f }, {0 .f , 0 .8f }, {0 .2f , 0 .9f }, {0 .4f , 1 .8f }, {0 .6f , 1 .4f }, {0 .8f , 1 .3f }, {0 .9f , 1 .1f }, {1 .1f , 0 .7f } },
@@ -505,20 +554,20 @@ OCIO_ADD_TEST(DynamicPropertyImpl, grading_hue_curve_knots_coefs)
505
554
506
555
{
507
556
// Hue-Hue
557
+ const float true_knots[15 ] = {-0 .1f , -0 .06928571f , 0 .0f , 0 .05642857f , 0 .1f , 0 .17549634f , 0 .2f , 0 .33714286f ,
558
+ 0 .5f , 0 .62499860f , 0 .8f , 0 .85261905f , 0 .9f , 0 .93071429f , 1 .f };
508
559
509
- const float true_knots[15 ] = {-0 .1f , -0 .01816964f , 0 .05f , 0 .125f , 0 .2f , 0 .35f , 0 .5f , 0 .57558291f , 0 .8f , 0 .82731918f ,
510
- 0 .85f , 0 .87808036f , 0 .9f , 0 .98183036f , 1 .05f };
511
560
// Quadratic coefs.
512
- const float true_coefsA[14 ] = { - 2 .29385141e+ 00f , 3 .43265663e+ 00f , 2 .95979024e+ 01f , - 3 .34850652e+ 01f , - 2 .11943922e- 02f ,
513
- 2 .11186821e- 02f , 9 .58311056e+ 00f , 3 .05897301e- 01f , 1 .69849435e+ 01f , -2 .62364216e+ 01f ,
514
- -5 .36565978e+ 00f , - 1 .21350984e+ 01f , - 2 .29385141e+ 00f , 3 .43265663e+ 00f };
561
+ const float true_coefsA[14 ] = { 15 . 95930233f , - 1 . 66237113f , - 1 . 44778481f , 6 . 17827869f , 10 . 39930009f ,
562
+ - 58 . 70626575f , - 1 . 54375789f , 1 . 03834397f , 3 . 7077401f , -2 .12344738f ,
563
+ -3 . 54260935f , 4 . 81365159f , 15 . 95930233f ,- 1 . 66237113f };
515
564
// Linear coefs.
516
- const float true_coefsB[14 ] = { 5 .00000000e- 01f , 1 .24586640e- 01f , 5 .92592593e- 01f , 5 .03227795e+ 00f , 9 .51817043e- 03f ,
517
- 3 .15985276e- 03f , 9 .49545739e- 03f , 1 .45813415e+ 00f , 1 .59543132e+ 00f , 2 .52346065e+ 00f ,
518
- 1 .33333333e+ 00f , 1 .03199405e+ 00f , 5 .00000000e- 01f , 1 .24586640e- 01f };
565
+ const float true_coefsB[14 ] = { 0 . 75f , 1 . 73035714f , 1 .5f , 1 . 33660714f , 1 . 875f , 3 . 44521825f , 0 . 56818182f ,
566
+ 0 . 14475108f , 0 . 48295455f , 1 .40987919f , 0 . 66666667f , 0 . 29384921f , 0 . 75f , 1 . 73035714f };
567
+
519
568
// Constant coefs.
520
- const float true_coefsC[14 ] = { -0 .15f , -0 .12444493f , -0 .1f , 0 . 11093265f , 0 .3f , 0 .30095085f , 0 .3019f , 0 . 35736386f ,
521
- 0 .7f , 0 .75626237f , 0 .8f , 0 .83320962f , 0 .85f , 0 .87555507f };
569
+ const float true_coefsC[14 ] = { -0 .25f , -0 .2119088f , -0 .1f , - 0 . 01996716f , 0 .05f , 0 .25082851f , 0 .3f ,
570
+ 0 .34888683f , 0 .4f , 0 .51830078f , 0 .7f , 0 .72527072f , 0 .75f , 0 . 7880912f };
522
571
523
572
checkKnotsAndCoefs (dp, 0 , true_knots, true_coefsA, true_coefsB, true_coefsC, __LINE__);
524
573
}
0 commit comments