single.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <stdio.h>
  2. #include <errno.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include "postprocess.h"
  6. void
  7. print_usage(char *name)
  8. {
  9. fprintf(stderr, "usage: %s [-v] [-q quality] INPUT OUTPUT\n", name);
  10. fprintf(stderr, "Post-process a single .dng bayer raw file to a jpeg file.\n\n");
  11. fprintf(stderr, "Mandatory arguments\n");
  12. fprintf(stderr, "INPUT Input filename, should be a .dng file\n");
  13. fprintf(stderr, "OUTPUT Output filename, should be a .jpg file\n\n");
  14. fprintf(stderr, "Optional arguments\n");
  15. fprintf(stderr, " -v Show verbose debugging output\n");
  16. fprintf(stderr, " -q 90 Set the output jpeg quality [0-100]\n\n");
  17. }
  18. int
  19. main(int argc, char *argv[])
  20. {
  21. int opt;
  22. int verbose = 0;
  23. long temp;
  24. int quality = 90;
  25. char *endptr;
  26. char *input_path;
  27. char *output_path;
  28. while ((opt = getopt(argc, argv, "vq:h")) != -1) {
  29. switch (opt) {
  30. case 'v':
  31. verbose = 1;
  32. break;
  33. case 'q':
  34. temp = strtol(optarg, &endptr, 0);
  35. if (errno == ERANGE || *endptr != '\0' || optarg == endptr) {
  36. fprintf(stderr, "Invalid value for -q\n");
  37. print_usage(argv[0]);
  38. return 1;
  39. }
  40. if (temp < 0 || temp > 100) {
  41. fprintf(stderr, "Quality out of range, valid values are 0-100\n");
  42. print_usage(argv[0]);
  43. return 1;
  44. }
  45. quality = (int) temp;
  46. break;
  47. case 'h':
  48. print_usage(argv[0]);
  49. return 0;
  50. case '?':
  51. print_usage(argv[0]);
  52. return 1;
  53. }
  54. }
  55. if (argc < optind + 2) {
  56. fprintf(stderr, "Missing image parameters\n");
  57. print_usage(argv[0]);
  58. return 1;
  59. }
  60. input_path = argv[optind];
  61. output_path = argv[optind + 1];
  62. postprocess_setup();
  63. postprocess_single(input_path, output_path, quality, verbose);
  64. return 0;
  65. }