Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

124 Zeilen
3.0 KiB

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