dngmerge.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <getopt.h>
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <errno.h>
  7. #include "libdng.h"
  8. void
  9. usage(char *name)
  10. {
  11. fprintf(stderr, "Usage: %s src-file dcp-file dst-file\n", name);
  12. fprintf(stderr, "Merge color metadata from one TIFF file into the image data of another TIFF\n\n");
  13. }
  14. int
  15. main(int argc, char *argv[])
  16. {
  17. libdng_init();
  18. libdng_info info = {0};
  19. libdng_new(&info);
  20. if (argc < 3) {
  21. fprintf(stderr, "Missing required argument\n");
  22. usage(argv[0]);
  23. return 1;
  24. }
  25. uint32_t width, height, thumb_width, thumb_height;
  26. uint8_t *thumb;
  27. uint8_t *image;
  28. size_t thumb_length;
  29. size_t image_length;
  30. if (!libdng_read(&info, argv[1])) {
  31. fprintf(stderr, "Could not load the metadata from the original file\n");
  32. exit(1);
  33. }
  34. if (!libdng_read_image(&info, argv[1], 0, &thumb, &thumb_length, &thumb_width, &thumb_height)) {
  35. fprintf(stderr, "Could not load thumbnail from the original file\n");
  36. exit(1);
  37. }
  38. printf("Got %dx%d thumbnail of %zu bytes\n", thumb_width, thumb_height, thumb_length);
  39. if (!libdng_read_image(&info, argv[1], 1, &image, &image_length, &width, &height)) {
  40. fprintf(stderr, "Could not load image data from the original file\n");
  41. exit(1);
  42. }
  43. printf("Got %dx%d image of %zu bytes\n", width, height, image_length);
  44. if (!libdng_load_calibration_file(&info, argv[2])) {
  45. fprintf(stderr, "Could not load calibration files: %s\n", argv[2]);
  46. exit(1);
  47. }
  48. libdng_write_with_thumbnail(&info, argv[3], width, height, image, image_length, thumb_width, thumb_height, thumb,
  49. thumb_length);
  50. free(thumb);
  51. free(image);
  52. libdng_free(&info);
  53. return 0;
  54. }