FloatImg4PythonBinding/tools/mkfimg.c
2019-09-11 13:45:18 +02:00

97 lines
2.0 KiB
C

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include "../floatimg.h"
int verbosity;
/* --------------------------------------------------------------------- */
#define T_BLACK 0
#define T_DRAND48 1
#define T_RGB_0 2
static int get_type(char *name)
{
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, name);
#endif
#define TEST(str) ( ! strcmp(name, str) )
if TEST("black") return T_BLACK;
if TEST("drand48") return T_DRAND48;
return -1;
}
/* --------------------------------------------------------------------- */
static void help(int lj)
{
puts("Usage:\n\tmkfimg [options] quux.fimg width height\n");
if (verbosity) fimg_print_version(1);
exit(0);
}
/* --------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo, opt;
int width, height;
char *fname;
float fvalue = 0.00001;
int type = 0;
FloatImg fimg;
while ((opt = getopt(argc, argv, "hk:t:v")) != -1) {
switch(opt) {
case 'h': help(0); break;
case 'k': fvalue = atof(optarg); break;
case 't': type = get_type(optarg); break;
case 'v': verbosity++; break;
}
}
#if DEBUG_LEVEL
fprintf(stderr, "argc %d optind %d\n", argc, optind);
for (foo=0; foo<argc; foo++)
fprintf(stderr, "%3d %s\n", foo, argv[foo]);
#endif
if (3 != argc-optind) {
fprintf(stderr, "%s need filename, width & height\n", argv[0]);
exit(1);
}
fname = argv[optind];
width = atoi(argv[optind+1]); height = atoi(argv[optind+2]);
if (verbosity) fprintf(stderr, "making '%s' %d x %d\n", fname, width, height);
srand48(getpid() ^ time(NULL));
foo = fimg_create(&fimg, width, height, 3);
if (foo) {
fprintf(stderr, "create floatimg -> %d\n", foo);
exit(1);
}
switch(type) {
default:
case T_BLACK: fimg_clear(&fimg); break;
case T_DRAND48: fimg_drand48(&fimg, 1.0); break;
}
foo = fimg_dump_to_file(&fimg, fname, 0);
if (foo) {
fprintf(stderr, "dump fimg -> %d\n", foo);
exit(1);
}
return 0;
}
/* --------------------------------------------------------------------- */