選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

123 行
3.0 KiB

  1. #include "config.h"
  2. #if !defined HAVE_GETOPT_LONG
  3. # include "mygetopt.h"
  4. #elif defined HAVE_GETOPT_H
  5. # include <getopt.h>
  6. #endif
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <pipi.h>
  11. #if defined HAVE_GETOPT_LONG
  12. # define mygetopt getopt_long
  13. # define myoptind optind
  14. # define myoptarg optarg
  15. # define myoption option
  16. #endif
  17. #define DEFAULT_WIDTH 120
  18. #define DEFAULT_HEIGHT 90
  19. #define MOREINFO "Try `%s --help' for more information.\n"
  20. static void usage(void);
  21. int main(int argc, char *argv[])
  22. {
  23. char *srcname = NULL, *dstname = NULL;
  24. pipi_image_t *src, *dst;
  25. int i, w = DEFAULT_WIDTH, h = DEFAULT_HEIGHT, bpp = 24;
  26. for(;;)
  27. {
  28. int option_index = 0;
  29. static struct myoption long_options[] =
  30. {
  31. { "bpp", 1, NULL, 'b' },
  32. { "geometry", 1, NULL, 'g' },
  33. { "help", 0, NULL, 'h' },
  34. { NULL, 0, NULL, 0 },
  35. };
  36. int c = mygetopt(argc, argv, "b:g:h", long_options, &option_index);
  37. if(c == -1)
  38. break;
  39. switch(c)
  40. {
  41. case 'b':
  42. bpp = atoi(myoptarg);
  43. if(bpp != 32 && bpp != 24 && bpp != 16)
  44. {
  45. fprintf(stderr, "%s: invalid bpp -- %s\n", argv[0], myoptarg);
  46. return EXIT_FAILURE;
  47. }
  48. break;
  49. case 'g':
  50. w = atoi(myoptarg);
  51. if(strchr(myoptarg, 'x'))
  52. h = atoi(strchr(myoptarg, 'x') + 1);
  53. break;
  54. case 'h':
  55. usage();
  56. return EXIT_SUCCESS;
  57. default:
  58. fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
  59. printf(MOREINFO, argv[0]);
  60. return EXIT_FAILURE;
  61. }
  62. }
  63. for(i = myoptind; i < argc; i++)
  64. {
  65. if(!srcname)
  66. srcname = argv[i];
  67. else
  68. dstname = argv[i];
  69. }
  70. if(!srcname || !dstname)
  71. {
  72. fprintf(stderr, "%s: too few arguments\n", argv[0]);
  73. printf(MOREINFO, argv[0]);
  74. return EXIT_FAILURE;
  75. }
  76. src = pipi_load(srcname);
  77. if(!src)
  78. {
  79. fprintf(stderr, "%s: could not load `%s'\n", argv[0], srcname);
  80. return EXIT_FAILURE;
  81. }
  82. dst = pipi_resize_bicubic(src, w, h);
  83. if(bpp == 16)
  84. pipi_dither_24to16(dst);
  85. pipi_save(dst, dstname);
  86. pipi_free(src);
  87. pipi_free(dst);
  88. return 0;
  89. }
  90. static void usage(void)
  91. {
  92. printf("Usage: genethumb [-b bpp] [-g geometry] SOURCE DESTINATION\n");
  93. printf(" genethumb -h | --help\n");
  94. printf("Create an image thumbnail.\n");
  95. printf("\n");
  96. printf("Mandatory arguments to long options are mandatory for short options too.\n");
  97. printf(" -b, --bpp <bits> bits per pixel (32 or 16)\n");
  98. printf(" -g, --geometry <geometry> target geometry (default %ix%i)\n",
  99. DEFAULT_WIDTH, DEFAULT_HEIGHT);
  100. printf(" -h, --help display this help and exit\n");
  101. printf("\n");
  102. printf("Written by Sam Hocevar. Report bugs to <sam@zoy.org>.\n");
  103. }