better parsing of type, and add on "gray" type
This commit is contained in:
parent
bacf6ecd94
commit
adc08ce777
@ -9,19 +9,37 @@
|
|||||||
int verbosity;
|
int verbosity;
|
||||||
|
|
||||||
/* --------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------- */
|
||||||
#define T_BLACK 0
|
#define T_BLACK 1
|
||||||
#define T_DRAND48 1
|
#define T_DRAND48 2
|
||||||
#define T_RGB_0 2
|
#define T_GRAY 3
|
||||||
|
typedef struct {
|
||||||
|
int code;
|
||||||
|
char *name;
|
||||||
|
} Type;
|
||||||
|
|
||||||
|
Type types[] = {
|
||||||
|
{ T_BLACK, "black" },
|
||||||
|
{ T_DRAND48, "drand48" },
|
||||||
|
{ T_GRAY, "gray" },
|
||||||
|
{ T_GRAY, "grey" }
|
||||||
|
};
|
||||||
|
|
||||||
static int get_type(char *name)
|
static int get_type(char *name)
|
||||||
{
|
{
|
||||||
|
Type *type;
|
||||||
|
|
||||||
#if DEBUG_LEVEL
|
#if DEBUG_LEVEL
|
||||||
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, name);
|
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TEST(str) ( ! strcmp(name, str) )
|
// #define TEST(str) ( ! strcmp(name, str) )
|
||||||
if TEST("black") return T_BLACK;
|
|
||||||
if TEST("drand48") return T_DRAND48;
|
for (type = types; type->code; type++) {
|
||||||
|
// printf("\t%-15s %d\n", type->name, type->code);
|
||||||
|
if (!strcmp(name, type->name)) {
|
||||||
|
return type->code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -32,7 +50,7 @@ static void help(int lj)
|
|||||||
puts("Usage:\tmkfimg [options] quux.fimg width height");
|
puts("Usage:\tmkfimg [options] quux.fimg width height");
|
||||||
|
|
||||||
puts("\t-k N.N\tgive a float parameter");
|
puts("\t-k N.N\tgive a float parameter");
|
||||||
puts("\t-t bla\t\howto make the pic");
|
puts("\t-t bla\t\thowto make the pic");
|
||||||
puts("\t\t\tblack, drand48...");
|
puts("\t\t\tblack, drand48...");
|
||||||
puts("\t-v\tincrease verbosity");
|
puts("\t-v\tincrease verbosity");
|
||||||
|
|
||||||
@ -46,8 +64,9 @@ int main(int argc, char *argv[])
|
|||||||
int foo, opt;
|
int foo, opt;
|
||||||
int width, height;
|
int width, height;
|
||||||
char *fname;
|
char *fname;
|
||||||
float fvalue = 0.00001;
|
float fvalue = 0.01;
|
||||||
int type = 0;
|
int type = T_BLACK;
|
||||||
|
char *tname = "wtf?";
|
||||||
|
|
||||||
FloatImg fimg;
|
FloatImg fimg;
|
||||||
|
|
||||||
@ -55,7 +74,7 @@ while ((opt = getopt(argc, argv, "hk:t:v")) != -1) {
|
|||||||
switch(opt) {
|
switch(opt) {
|
||||||
case 'h': help(0); break;
|
case 'h': help(0); break;
|
||||||
case 'k': fvalue = atof(optarg); break;
|
case 'k': fvalue = atof(optarg); break;
|
||||||
case 't': type = get_type(optarg); break;
|
case 't': type = get_type(tname=optarg); break;
|
||||||
case 'v': verbosity++; break;
|
case 'v': verbosity++; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,6 +90,11 @@ if (3 != argc-optind) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type < 0) {
|
||||||
|
fprintf(stderr, "type '%s' is unknow\n", tname);
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
fname = argv[optind];
|
fname = argv[optind];
|
||||||
width = atoi(argv[optind+1]); height = atoi(argv[optind+2]);
|
width = atoi(argv[optind+1]); height = atoi(argv[optind+2]);
|
||||||
|
|
||||||
@ -81,13 +105,15 @@ srand48(getpid() ^ time(NULL));
|
|||||||
foo = fimg_create(&fimg, width, height, 3);
|
foo = fimg_create(&fimg, width, height, 3);
|
||||||
if (foo) {
|
if (foo) {
|
||||||
fprintf(stderr, "create floatimg -> %d\n", foo);
|
fprintf(stderr, "create floatimg -> %d\n", foo);
|
||||||
exit(1);
|
exit(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(type) {
|
switch(type) {
|
||||||
default:
|
default:
|
||||||
case T_BLACK: fimg_clear(&fimg); break;
|
case T_BLACK: fimg_clear(&fimg); break;
|
||||||
case T_DRAND48: fimg_drand48(&fimg, 1.0); break;
|
case T_DRAND48: fimg_drand48(&fimg, fvalue); break;
|
||||||
|
case T_GRAY: fimg_rgb_constant(&fimg, fvalue, fvalue, fvalue);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
foo = fimg_dump_to_file(&fimg, fname, 0);
|
foo = fimg_dump_to_file(&fimg, fname, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user