check_dcp.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include <stdbool.h>
  2. #include <tiffio.h>
  3. #include "greatest.h"
  4. #include "libdng.h"
  5. TEST load_pinephone_dcp(void)
  6. {
  7. libdng_info info = {0};
  8. libdng_new(&info);
  9. if (!libdng_load_calibration_file(&info, "fixture/pinephone.dcp")) {
  10. FAILm("Could not load calibration file");
  11. }
  12. float colormatrix1[] = {
  13. 1.8464f, -0.9617f, 0.096f,
  14. -0.4260f, 1.3753f, 0.3348f,
  15. -0.1147f, 0.4933f, 1.6042f,
  16. };
  17. char name[20] = {0};
  18. for (int i = 0; i < 9; i++) {
  19. snprintf(name, 20, "COLORMATRIX1[%d]", i);
  20. ASSERT_EQ_FMTm(strdup(name), colormatrix1[i], info.color_matrix_1[i], "%f");
  21. }
  22. float forwardmatrix1[] = {
  23. 0.7063f, 0.1361f, 0.1219f,
  24. 0.2691f, 0.6969f, 0.0340f,
  25. 0.0003f, 0.0855f, 0.7393f,
  26. };
  27. for (int i = 0; i < 9; i++) {
  28. snprintf(name, 20, "FORWARDMATRIX1[%d]", i);
  29. ASSERT_EQ_FMTm(strdup(name), forwardmatrix1[i], info.forward_matrix_1[i], "%f");
  30. }
  31. ASSERT_EQ_FMTm("ILLUMINANT1", LIBDNG_ILLUMINANT_STANDARD_A, info.illuminant_1, "%d");
  32. ASSERT_EQ_FMTm("ILLUMINANT2", LIBDNG_ILLUMINANT_D65, info.illuminant_2, "%d");
  33. ASSERT_EQ_FMTm("TONE_CURVE_LEN", (size_t) 4, info.tone_curve_length, "%zu");
  34. double tonecurve[] = {0.0, 0.0, 1.0, 1.0};
  35. for (size_t i = 0; i < info.tone_curve_length; i++) {
  36. snprintf(name, 20, "TONECURVE[%zu]", i);
  37. ASSERT_EQ_FMTm(strdup(name), tonecurve[i], info.tone_curve[i], "%f");
  38. }
  39. // HueSat map is 90x30x1 in this DCP (ProfileHueSatMapDims: Hues = 90, Sats = 30, Vals = 1)
  40. ASSERT_EQ_FMTm("HUE_SAT_MAP_DIMS[0]", 90, info.hue_sat_map_dims[0], "%d");
  41. ASSERT_EQ_FMTm("HUE_SAT_MAP_DIMS[1]", 30, info.hue_sat_map_dims[1], "%d");
  42. ASSERT_EQ_FMTm("HUE_SAT_MAP_DIMS[2]", 1, info.hue_sat_map_dims[2], "%d");
  43. size_t entries = info.hue_sat_map_dims[0] * info.hue_sat_map_dims[1] * info.hue_sat_map_dims[2];
  44. for (size_t i = 0; i < entries; i = i + 3) {
  45. if (info.hue_sat_map_data_1[i] < -360.0f || info.hue_sat_map_data_1[i] > 360.0f) {
  46. snprintf(name, 20, "HUESATMAP1[%zu]", i);
  47. FAILm(strdup(name));
  48. }
  49. if (info.hue_sat_map_data_2[i] < -360.0f || info.hue_sat_map_data_2[i] > 360.0f) {
  50. snprintf(name, 20, "HUESATMAP2[%zu]", i);
  51. FAILm(strdup(name));
  52. }
  53. }
  54. PASS();
  55. }
  56. SUITE (test_suite)
  57. {
  58. RUN_TEST(load_pinephone_dcp);
  59. }
  60. GREATEST_MAIN_DEFS();
  61. int
  62. main(int argc, char **argv)
  63. {
  64. GREATEST_MAIN_BEGIN();
  65. libdng_init();
  66. RUN_SUITE(test_suite);
  67. GREATEST_MAIN_END();
  68. }