Bibliothèque de traitements d'images en virgule flottante. http://la.buvette.org/photos/cumul/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mkfimg.c 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <time.h>
  6. #include "../floatimg.h"
  7. int verbosity;
  8. /* --------------------------------------------------------------------- */
  9. #define T_BLACK 1
  10. #define T_DRAND48 2
  11. #define T_GRAY 3
  12. #define T_HDEG_A 4
  13. #define T_VDEG_A 5
  14. #define T_TPAT0 6
  15. typedef struct {
  16. int code;
  17. char *name;
  18. } Type;
  19. Type types[] = {
  20. { T_BLACK, "black" },
  21. { T_DRAND48, "drand48" },
  22. { T_GRAY, "gray" },
  23. { T_GRAY, "grey" },
  24. { T_HDEG_A, "hdeg" },
  25. { T_VDEG_A, "vdeg" },
  26. { T_TPAT0, "tpat0" },
  27. { 0, NULL }
  28. };
  29. static int get_type(char *name)
  30. {
  31. Type *type;
  32. #if DEBUG_LEVEL
  33. fprintf(stderr, ">>> %s ( '%s' )\n", __func__, name);
  34. #endif
  35. // #define TEST(str) ( ! strcmp(name, str) )
  36. for (type = types; type->code; type++) {
  37. if (!strcmp(name, type->name)) {
  38. return type->code;
  39. }
  40. }
  41. return -1;
  42. }
  43. /* --------------------------------------------------------------------- */
  44. static void help(int lj)
  45. {
  46. int foo;
  47. puts("Usage:\tmkfimg [options] quux.fimg width height");
  48. puts("\t-k N.N\tgive a float parameter");
  49. fputs("\t-t bla\thowto make the pic\n\t\t", stdout);
  50. for (foo=0; types[foo].code; foo++) {
  51. printf("%s ", types[foo].name);
  52. }
  53. puts("\n\t-v\tincrease verbosity");
  54. if (verbosity) {
  55. fimg_print_version(1);
  56. printf("*** compiled %s, %s\n", __DATE__, __TIME__);
  57. }
  58. exit(0);
  59. }
  60. /* --------------------------------------------------------------------- */
  61. int main(int argc, char *argv[])
  62. {
  63. int foo, opt;
  64. int width, height;
  65. char *fname;
  66. float fvalue = 1.0;
  67. int type = T_BLACK;
  68. char *tname = "wtf?";
  69. FloatImg fimg;
  70. while ((opt = getopt(argc, argv, "hk:t:v")) != -1) {
  71. switch(opt) {
  72. case 'h': help(0); break;
  73. case 'k': fvalue = atof(optarg); break;
  74. case 't': type = get_type(tname=optarg); break;
  75. case 'v': verbosity++; break;
  76. }
  77. }
  78. #if DEBUG_LEVEL
  79. fprintf(stderr, "argc %d optind %d\n", argc, optind);
  80. for (foo=0; foo<argc; foo++)
  81. fprintf(stderr, "%3d %s\n", foo, argv[foo]);
  82. #endif
  83. if (3 != argc-optind) {
  84. fprintf(stderr, "%s need filename, width & height\n", argv[0]);
  85. exit(1);
  86. }
  87. if (type < 0) {
  88. fprintf(stderr, "type '%s' is unknow\n", tname);
  89. exit(2);
  90. }
  91. fname = argv[optind];
  92. width = atoi(argv[optind+1]); height = atoi(argv[optind+2]);
  93. if (verbosity>1) fprintf(stderr, "*** mkfimg *** %s %s\n", __DATE__, __TIME__);
  94. if (verbosity) fprintf(stderr, "making '%s' %d x %d, type %d\n",
  95. fname, width, height, type);
  96. srand48(getpid() ^ time(NULL));
  97. foo = fimg_create(&fimg, width, height, 3);
  98. if (foo) {
  99. fprintf(stderr, "create floatimg -> %d\n", foo);
  100. exit(3);
  101. }
  102. switch(type) {
  103. default:
  104. case T_BLACK: fimg_clear(&fimg); break;
  105. case T_DRAND48: fimg_drand48(&fimg, fvalue); break;
  106. case T_GRAY: fimg_rgb_constant(&fimg, fvalue, fvalue, fvalue);
  107. break;
  108. case T_HDEG_A: fimg_hdeg_a(&fimg, 1.0); break;
  109. case T_VDEG_A: fimg_vdeg_a(&fimg, 1.0); break;
  110. case T_TPAT0: fimg_test_pattern(&fimg, 0, fvalue); break;
  111. case -1: exit(1);
  112. }
  113. foo = fimg_dump_to_file(&fimg, fname, 0);
  114. if (foo) {
  115. fprintf(stderr, "dump fimg -> %d\n", foo);
  116. exit(1);
  117. }
  118. return 0;
  119. }
  120. /* --------------------------------------------------------------------- */