2021-03-09 21:55:48 +11:00
|
|
|
/*
|
|
|
|
* making a floatimg with some random datas
|
|
|
|
* an ugly software from tTh - february 2021
|
|
|
|
*/
|
|
|
|
|
2019-03-04 02:22:55 +11:00
|
|
|
#include <stdio.h>
|
2019-09-11 15:06:59 +11:00
|
|
|
#include <string.h>
|
2021-05-20 18:31:28 +11:00
|
|
|
#include <stdint.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-29 09:11:18 +11:00
|
|
|
#define T_BLACK 1
|
|
|
|
#define T_DRAND48 2
|
|
|
|
#define T_GRAY 3
|
2020-01-04 04:21:43 +11:00
|
|
|
#define T_HDEG_A 4
|
|
|
|
#define T_VDEG_A 5
|
2020-03-01 07:34:29 +11:00
|
|
|
#define T_TPAT0 6
|
2021-05-12 21:04:55 +11:00
|
|
|
#define T_MIRCOL1 7
|
2021-05-13 01:45:30 +11:00
|
|
|
#define T_BLOUP 8
|
2019-09-29 09:11:18 +11:00
|
|
|
typedef struct {
|
|
|
|
int code;
|
|
|
|
char *name;
|
|
|
|
} Type;
|
|
|
|
|
|
|
|
Type types[] = {
|
|
|
|
{ T_BLACK, "black" },
|
|
|
|
{ T_DRAND48, "drand48" },
|
|
|
|
{ T_GRAY, "gray" },
|
2020-01-04 04:21:43 +11:00
|
|
|
{ T_GRAY, "grey" },
|
|
|
|
{ T_HDEG_A, "hdeg" },
|
|
|
|
{ T_VDEG_A, "vdeg" },
|
2020-03-01 07:34:29 +11:00
|
|
|
{ T_TPAT0, "tpat0" },
|
2021-05-12 21:04:55 +11:00
|
|
|
{ T_MIRCOL1, "mircol1" },
|
2021-05-13 01:45:30 +11:00
|
|
|
{ T_BLOUP, "bloup" },
|
2020-01-04 04:21:43 +11:00
|
|
|
{ 0, NULL }
|
2019-09-29 09:11:18 +11:00
|
|
|
};
|
|
|
|
|
2021-05-13 01:45:30 +11:00
|
|
|
static int get_type_by_name(char *name)
|
2019-07-16 09:19:59 +11:00
|
|
|
{
|
2019-09-29 09:11:18 +11:00
|
|
|
Type *type;
|
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
|
|
|
|
2019-09-29 09:11:18 +11:00
|
|
|
for (type = types; type->code; type++) {
|
|
|
|
if (!strcmp(name, type->name)) {
|
|
|
|
return type->code;
|
|
|
|
}
|
|
|
|
}
|
2019-09-11 15:06:59 +11:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
2021-05-29 18:33:38 +11:00
|
|
|
static void list_types(void)
|
|
|
|
{
|
|
|
|
Type *type;
|
|
|
|
|
|
|
|
for (type = types; type->code; type++) {
|
|
|
|
puts(type->name);
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
2019-09-11 15:06:59 +11:00
|
|
|
static void help(int lj)
|
|
|
|
{
|
2021-05-12 21:04:55 +11:00
|
|
|
int foo, cc;
|
2019-09-11 15:06:59 +11:00
|
|
|
|
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");
|
2021-05-29 22:01:32 +11:00
|
|
|
puts("\t-L\tlist howto make a pic");
|
2021-05-13 01:45:30 +11:00
|
|
|
fputs("\t-t bla\thowto make the pic :\n\t\t| ", stdout);
|
|
|
|
|
|
|
|
for (foo=cc=0; types[foo].code; foo++) {
|
|
|
|
cc += printf("%s ", types[foo].name);
|
|
|
|
if (cc>42) { cc=0; printf("\n\t\t| "); }
|
2020-01-04 04:21:43 +11:00
|
|
|
}
|
2021-05-13 01:45:30 +11:00
|
|
|
|
2020-01-04 04:21:43 +11:00
|
|
|
puts("\n\t-v\tincrease verbosity");
|
2019-09-11 15:06:59 +11:00
|
|
|
|
2020-01-09 11:34:07 +11:00
|
|
|
if (verbosity) {
|
|
|
|
fimg_print_version(1);
|
|
|
|
printf("*** compiled %s, %s\n", __DATE__, __TIME__);
|
|
|
|
}
|
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[])
|
|
|
|
{
|
2021-05-04 19:29:02 +11:00
|
|
|
int foo, opt, nbargs;
|
2019-03-04 02:22:55 +11:00
|
|
|
int width, height;
|
|
|
|
char *fname;
|
2020-02-13 21:29:28 +11:00
|
|
|
float fvalue = 1.0;
|
2019-09-29 09:11:18 +11:00
|
|
|
int type = T_BLACK;
|
|
|
|
char *tname = "wtf?";
|
2019-08-24 22:24:01 +11:00
|
|
|
|
2019-03-04 02:22:55 +11:00
|
|
|
FloatImg fimg;
|
|
|
|
|
2021-05-29 18:33:38 +11:00
|
|
|
while ((opt = getopt(argc, argv, "hk:Lt: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;
|
2021-05-13 01:45:30 +11:00
|
|
|
case 't': type = get_type_by_name(tname=optarg);
|
|
|
|
break;
|
2021-05-29 18:33:38 +11:00
|
|
|
case 'L': list_types(); 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
|
|
|
|
|
2019-09-29 09:11:18 +11:00
|
|
|
if (type < 0) {
|
|
|
|
fprintf(stderr, "type '%s' is unknow\n", tname);
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
2021-05-04 19:29:02 +11:00
|
|
|
nbargs = argc-optind;
|
|
|
|
switch (nbargs) {
|
|
|
|
case 2:
|
|
|
|
if (2!=parse_WxH(argv[optind+1], &width, &height)) {
|
|
|
|
fprintf(stderr, "%s: parse error on '%s'\n",
|
|
|
|
argv[0], argv[optind+1]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
width = atoi(argv[optind+1]);
|
|
|
|
height = atoi(argv[optind+2]);
|
|
|
|
break;
|
|
|
|
default:
|
2021-05-12 21:04:55 +11:00
|
|
|
fprintf(stderr, "%s need filename, width & height\n",
|
|
|
|
argv[0]);
|
2021-05-04 19:29:02 +11:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2019-07-16 09:19:59 +11:00
|
|
|
fname = argv[optind];
|
2019-09-11 15:06:59 +11:00
|
|
|
|
2021-05-12 21:04:55 +11:00
|
|
|
if (verbosity>1) fprintf(stderr, "*** mkfimg *** %s %s\n",
|
|
|
|
__DATE__, __TIME__);
|
2021-05-04 19:29:02 +11:00
|
|
|
if (verbosity) fprintf(stderr, "making '%s' %dx%d, type %d\n",
|
2020-06-24 21:37:02 +11:00
|
|
|
fname, width, height, type);
|
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);
|
2019-09-29 09:11:18 +11:00
|
|
|
exit(3);
|
2019-03-04 02:22:55 +11:00
|
|
|
}
|
2019-09-11 15:06:59 +11:00
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
default:
|
|
|
|
case T_BLACK: fimg_clear(&fimg); break;
|
2019-09-29 09:11:18 +11:00
|
|
|
case T_DRAND48: fimg_drand48(&fimg, fvalue); break;
|
|
|
|
case T_GRAY: fimg_rgb_constant(&fimg, fvalue, fvalue, fvalue);
|
|
|
|
break;
|
2020-01-04 04:21:43 +11:00
|
|
|
case T_HDEG_A: fimg_hdeg_a(&fimg, 1.0); break;
|
|
|
|
case T_VDEG_A: fimg_vdeg_a(&fimg, 1.0); break;
|
2020-03-01 07:34:29 +11:00
|
|
|
case T_TPAT0: fimg_test_pattern(&fimg, 0, fvalue); break;
|
2021-05-12 21:04:55 +11:00
|
|
|
case T_MIRCOL1: fimg_mircol_1(&fimg, fvalue); break;
|
2021-05-13 01:45:30 +11:00
|
|
|
case T_BLOUP: fimg_draw_something(&fimg); break;
|
2020-05-29 22:32:15 +11:00
|
|
|
case -1: exit(1);
|
2019-09-11 15:06:59 +11:00
|
|
|
}
|
2019-03-04 02:22:55 +11:00
|
|
|
|
|
|
|
foo = fimg_dump_to_file(&fimg, fname, 0);
|
|
|
|
if (foo) {
|
2021-03-09 21:55:48 +11:00
|
|
|
fprintf(stderr, "dump fimg to %s -> %d\n", fname, foo);
|
2019-03-04 02:22:55 +11:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2020-08-24 08:55:36 +11:00
|
|
|
fimg_destroy(&fimg);
|
|
|
|
|
2019-03-04 02:22:55 +11:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|