check_mode.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include <stdbool.h>
  2. #include "greatest.h"
  3. #include "libdng.h"
  4. #define R 0
  5. #define G 1
  6. #define B 2
  7. static enum greatest_test_res
  8. check_mode(const char *name, int depth, int cfa1, int cfa2, int cfa3, int cfa4, bool needs_repack)
  9. {
  10. libdng_info info = {0};
  11. libdng_new(&info);
  12. libdng_set_mode_from_name(&info, name);
  13. ASSERT_EQ_FMTm("Bit depth", depth, info.bit_depth, "%d");
  14. ASSERT_EQ_FMTm("CFA1", cfa1, info.cfapattern[0], "%d");
  15. ASSERT_EQ_FMTm("CFA2", cfa2, info.cfapattern[1], "%d");
  16. ASSERT_EQ_FMTm("CFA3", cfa3, info.cfapattern[2], "%d");
  17. ASSERT_EQ_FMTm("CFA4", cfa4, info.cfapattern[3], "%d");
  18. ASSERT_EQ_FMTm("Repack", needs_repack, info.needs_repack, "%d");
  19. PASS();
  20. }
  21. TEST mode_from_name_8bit(void)
  22. {
  23. CHECK_CALL(check_mode("RGGB", 8, R, G, G, B, false));
  24. CHECK_CALL(check_mode("BGGR", 8, B, G, G, R, false));
  25. CHECK_CALL(check_mode("GRBG", 8, G, R, B, G, false));
  26. CHECK_CALL(check_mode("GBRG", 8, G, B, R, G, false));
  27. PASS();
  28. }
  29. TEST mode_from_name_10bit(void)
  30. {
  31. CHECK_CALL(check_mode("SRGGB10", 10, R, G, G, B, false));
  32. CHECK_CALL(check_mode("SBGGR10", 10, B, G, G, R, false));
  33. CHECK_CALL(check_mode("SGRBG10", 10, G, R, B, G, false));
  34. CHECK_CALL(check_mode("SGBRG10", 10, G, B, R, G, false));
  35. PASS();
  36. }
  37. TEST mode_from_name_10bit_packed(void)
  38. {
  39. CHECK_CALL(check_mode("SRGGB10P", 10, R, G, G, B, true));
  40. CHECK_CALL(check_mode("SBGGR10P", 10, B, G, G, R, true));
  41. CHECK_CALL(check_mode("SGRBG10P", 10, G, R, B, G, true));
  42. CHECK_CALL(check_mode("SGBRG10P", 10, G, B, R, G, true));
  43. PASS();
  44. }
  45. SUITE (test_suite)
  46. {
  47. RUN_TEST(mode_from_name_8bit);
  48. RUN_TEST(mode_from_name_10bit);
  49. RUN_TEST(mode_from_name_10bit_packed);
  50. }
  51. GREATEST_MAIN_DEFS();
  52. int
  53. main(int argc, char **argv)
  54. {
  55. GREATEST_MAIN_BEGIN();
  56. libdng_init();
  57. RUN_SUITE(test_suite);
  58. GREATEST_MAIN_END();
  59. }