This repository was archived by the owner on Nov 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpxpat_main.c
61 lines (52 loc) · 1.83 KB
/
pxpat_main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "./pxpat.h"
#include "./pxpat_util.h"
const char *arg0;
static struct pat_context ctx;
static char *env_seed, *env_tile, *env_getpx;
static void cleanup(void) {
pat_ctx_free(&ctx);
free(env_seed);
free(env_tile);
free(env_getpx);
}
int main(int argc, const char *argv[]) {
unsigned int i;
arg0 = argv[0];
if (atexit(cleanup) != 0)
return 1;
if (argc < 5) {
fprintf(stderr,
"Usage: %s width height pixel_size 0xRRGGBB... > output.tga\n"
"Example: pxpat 320 180 4 0x963068 0xa2a9b0 0x100a0e > myfile.tga\n"
"Environment variables:\n"
" PXPAT_SEED : unsigned int (passed to srand, default: time(NULL))\n"
" PXPAT_TILE : boolean (true if set)\n"
" PXPAT_GETPX : one of these:\n ", arg0);
for (i = 0; pat_getpx_funcs[i].getpx; ++i)
if (pat_getpx_funcs[i+1].getpx)
fprintf(stderr, "\"%s\", ", pat_getpx_funcs[i].name);
else
fprintf(stderr, "\"%s\"\n", pat_getpx_funcs[i].name);
return 1;
}
env_seed = getenv_alloc("PXPAT_SEED");
env_tile = getenv_alloc("PXPAT_TILE");
env_getpx = getenv_alloc("PXPAT_GETPX");
ctx = pat_ctx_new(atoi(argv[1]),
atoi(argv[2]),
atoi(argv[3]),
argv + 4,
argc - 4,
env_seed ? strtoul(env_seed, NULL, 10) : (unsigned int)time(NULL),
env_getpx,
env_tile ? PXPAT_F_TILE : PXPAT_F_NONE);
if (ctx.err)
die("%s: %s", arg0, pat_strerror(&ctx));
pat_ctx_write(&ctx, stdout, PXPAT_FFMT_TGA);
if (ctx.err)
die("%s: %s", arg0, pat_strerror(&ctx));
return 0;
}