2019-03-04 02:22:55 +11:00
|
|
|
#include <stdio.h>
|
2019-09-11 15:06:59 +11:00
|
|
|
#include <string.h>
|
2019-03-04 02:22:55 +11:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2019-09-11 22:45:18 +11:00
|
|
|
#include <time.h>
|
2019-03-04 02:22:55 +11:00
|
|
|
|
|
|
|
#include "../floatimg.h"
|
|
|
|
|
2019-07-16 09:19:59 +11:00
|
|
|
int verbosity;
|
|
|
|
|
2019-03-04 02:22:55 +11:00
|
|
|
/* --------------------------------------------------------------------- */
|
2019-09-11 15:06:59 +11:00
|
|
|
#define T_BLACK 0
|
|
|
|
#define T_DRAND48 1
|
|
|
|
#define T_RGB_0 2
|
|
|
|
static int get_type(char *name)
|
2019-07-16 09:19:59 +11:00
|
|
|
{
|
2019-09-11 15:06:59 +11:00
|
|
|
|
2019-09-11 22:45:18 +11:00
|
|
|
#if DEBUG_LEVEL
|
2019-09-11 15:06:59 +11:00
|
|
|
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, name);
|
2019-09-11 22:45:18 +11:00
|
|
|
#endif
|
2019-09-11 15:06:59 +11:00
|
|
|
|
|
|
|
#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)
|
|
|
|
{
|
|
|
|
|
2019-09-27 21:25:09 +11:00
|
|
|
puts("Usage:\tmkfimg [options] quux.fimg width height");
|
|
|
|
|
|
|
|
puts("\t-k N.N\tgive a float parameter");
|
|
|
|
puts("\t-t bla\t\howto make the pic");
|
|
|
|
puts("\t\t\tblack, drand48...");
|
|
|
|
puts("\t-v\tincrease verbosity");
|
2019-09-11 15:06:59 +11:00
|
|
|
|
|
|
|
if (verbosity) fimg_print_version(1);
|
2019-03-04 02:22:55 +11:00
|
|
|
|
2019-07-16 09:19:59 +11:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
2019-03-04 02:22:55 +11:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2019-07-16 09:19:59 +11:00
|
|
|
int foo, opt;
|
2019-03-04 02:22:55 +11:00
|
|
|
int width, height;
|
|
|
|
char *fname;
|
2019-09-11 22:45:18 +11:00
|
|
|
float fvalue = 0.00001;
|
2019-09-11 15:06:59 +11:00
|
|
|
int type = 0;
|
2019-08-24 22:24:01 +11:00
|
|
|
|
2019-03-04 02:22:55 +11:00
|
|
|
FloatImg fimg;
|
|
|
|
|
2019-09-11 22:45:18 +11:00
|
|
|
while ((opt = getopt(argc, argv, "hk:t:v")) != -1) {
|
2019-07-16 09:19:59 +11:00
|
|
|
switch(opt) {
|
|
|
|
case 'h': help(0); break;
|
2019-09-11 22:45:18 +11:00
|
|
|
case 'k': fvalue = atof(optarg); break;
|
2019-09-11 15:06:59 +11:00
|
|
|
case 't': type = get_type(optarg); break;
|
2019-07-16 09:19:59 +11:00
|
|
|
case 'v': verbosity++; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-11 15:06:59 +11:00
|
|
|
#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]);
|
2019-03-04 02:22:55 +11:00
|
|
|
exit(1);
|
|
|
|
}
|
2019-07-16 09:19:59 +11:00
|
|
|
|
|
|
|
fname = argv[optind];
|
|
|
|
width = atoi(argv[optind+1]); height = atoi(argv[optind+2]);
|
2019-09-11 15:06:59 +11:00
|
|
|
|
|
|
|
if (verbosity) fprintf(stderr, "making '%s' %d x %d\n", fname, width, height);
|
2019-03-04 02:22:55 +11:00
|
|
|
|
2019-09-11 22:45:18 +11:00
|
|
|
srand48(getpid() ^ time(NULL));
|
|
|
|
|
2019-03-04 02:22:55 +11:00
|
|
|
foo = fimg_create(&fimg, width, height, 3);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "create floatimg -> %d\n", foo);
|
|
|
|
exit(1);
|
|
|
|
}
|
2019-09-11 15:06:59 +11:00
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
default:
|
|
|
|
case T_BLACK: fimg_clear(&fimg); break;
|
|
|
|
case T_DRAND48: fimg_drand48(&fimg, 1.0); break;
|
|
|
|
}
|
2019-03-04 02:22:55 +11:00
|
|
|
|
|
|
|
foo = fimg_dump_to_file(&fimg, fname, 0);
|
|
|
|
if (foo) {
|
2019-07-16 09:19:59 +11:00
|
|
|
fprintf(stderr, "dump fimg -> %d\n", foo);
|
2019-03-04 02:22:55 +11:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|