1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #include <stdbool.h>
- #include <tiffio.h>
- #include "greatest.h"
- #include "libdng.h"
- static enum greatest_test_res
- check_str_tag(TIFF *im, uint32_t tag, const char *name, const char *expected)
- {
- char *temp;
- if (TIFFGetField(im, tag, &temp) != 1) {
- FAILm(name);
- }
- ASSERT_STR_EQm(name, expected, temp);
- PASS();
- }
- static enum greatest_test_res
- check_int_tag(TIFF *im, uint32_t tag, const char *name, int expected)
- {
- uint32_t temp;
- if (TIFFGetField(im, tag, &temp) != 1) {
- FAILm(name);
- }
- ASSERT_EQ_FMTm(name, expected, temp, "%d");
- PASS();
- }
- TEST generate_simple_dng(void)
- {
- libdng_info info = {0};
- libdng_new(&info);
- ASSERT_EQm("Set mode", 1, libdng_set_mode_from_name(&info, "RGGB"));
- ASSERT_EQm("Set make", 1, libdng_set_make_model(&info, "Make", "Model"));
- ASSERT_EQm("Set software", 1, libdng_set_software(&info, "Software"));
- ASSERT_EQm("Set orientation", 1, libdng_set_orientation(&info, 4));
- uint8_t *data = malloc(1280 * 720);
- ASSERT_EQm("Write DNG", 1, libdng_write(&info, "test.dng", 1280, 720, data, 1280 * 720));
- free(data);
- libdng_free(&info);
- // Use LibTIFF directly to verify results
- TIFF *im = TIFFOpen("test.dng", "r");
- if (im == NULL) {
- FAILm("Could not open result");
- }
- // Check IFD0 with most metadata and the thumbnail image
- CHECK_CALL(check_int_tag(im, TIFFTAG_ORIENTATION, "ORIENTATION", 4));
- CHECK_CALL(check_int_tag(im, TIFFTAG_BITSPERSAMPLE, "THUMB_BPS", 8));
- CHECK_CALL(check_int_tag(im, TIFFTAG_SAMPLESPERPIXEL, "THUMB_CHANNELS", 3));
- CHECK_CALL(check_int_tag(im, TIFFTAG_PHOTOMETRIC, "THUMB_PHOTOMETRIC", PHOTOMETRIC_RGB));
- CHECK_CALL(check_str_tag(im, TIFFTAG_MAKE, "MAKE", "Make"));
- CHECK_CALL(check_str_tag(im, TIFFTAG_MODEL, "MODEL", "Model"));
- CHECK_CALL(check_str_tag(im, TIFFTAG_UNIQUECAMERAMODEL, "UCM", "Make Model"));
- CHECK_CALL(check_str_tag(im, TIFFTAG_SOFTWARE, "SOFTWARE", "Software"));
- CHECK_CALL(check_int_tag(im, TIFFTAG_ORIENTATION, "ORIENTATION", 4));
- // Switch to IFD1 which has the raw data
- int subifd_count = 0;
- void *ptr;
- toff_t subifd_offsets[2];
- TIFFGetField(im, TIFFTAG_SUBIFD, &subifd_count, &ptr);
- memcpy(subifd_offsets, ptr, subifd_count * sizeof(subifd_offsets[0]));
- TIFFSetSubDirectory(im, subifd_offsets[0]);
- // Check IFD1 metadata
- CHECK_CALL(check_int_tag(im, TIFFTAG_IMAGEWIDTH, "RAW_WIDTH", 1280));
- CHECK_CALL(check_int_tag(im, TIFFTAG_IMAGELENGTH, "RAW_HEIGHT", 720));
- CHECK_CALL(check_int_tag(im, TIFFTAG_BITSPERSAMPLE, "RAW_BPS", 8));
- CHECK_CALL(check_int_tag(im, TIFFTAG_SAMPLESPERPIXEL, "RAW_CHANNELS", 1));
- CHECK_CALL(check_int_tag(im, TIFFTAG_PHOTOMETRIC, "RAW_PHOTOMETRIC", PHOTOMETRIC_CFA));
- PASS();
- }
- SUITE (test_suite)
- {
- RUN_TEST(generate_simple_dng);
- }
- GREATEST_MAIN_DEFS();
- int
- main(int argc, char **argv)
- {
- GREATEST_MAIN_BEGIN();
- libdng_init();
- RUN_SUITE(test_suite);
- GREATEST_MAIN_END();
- }
|