-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathiff2raw.c
More file actions
98 lines (80 loc) · 2.32 KB
/
iff2raw.c
File metadata and controls
98 lines (80 loc) · 2.32 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdbool.h>
#include <getopt.h>
#include "iff2raw.h"
#include "byte_order.h"
#include "iff_loader.h"
#include "iff_image.h"
#include "raw_writer.h"
_options opts;
void print_usage()
{
fprintf(stderr, "Usage: iff2raw [flags]\n\n");
fprintf(stderr, "Flags:\n");
fprintf(stderr, " -i <filename> Input filename\n");
fprintf(stderr, " -o <filename> Output filename without extension\n");
fprintf(stderr, " -c <mode> Color mode. 4=4 bits per channel (default), 8=8 bits per channel\n");
fprintf(stderr, " -p <mode> Palette output mode. 0=binary (default), 1=asm-source\n");
fprintf(stderr, " -r <mode> Row output mode. 0=normal (default), 1=interleaved\n");
fprintf(stderr, " -v Verbose mode");
fprintf(stderr, "\n");
fprintf(stderr, " -h Print this message and exit\n");
fprintf(stderr, "\n");
}
static bool collect_arguments(int argc, char **argv)
{
int ch;
if (argc < 2)
{
fprintf(stderr, "** Wrong number of arguments!\n\n");
return false;
}
while ((ch = getopt(argc, argv, "c:h:i:o:p:r:v")) != -1)
{
switch (ch) {
case 'i':
opts.input_filename = strdup(optarg);
break;
case 'o':
opts.output_filename = strdup(optarg);
break;
case 'c':
opts.color_mode = atoi(optarg);
break;
case 'p':
opts.palette_mode = atoi(optarg);
break;
case 'r':
opts.row_mode = atoi(optarg);
break;
case 'v':
opts.verbose_mode = true;
break;
case 'h':
default:
return false;
}
}
return true;
}
int main(int argc, char** argv)
{
fprintf(stderr, "iff2raw 0.1 Copyright (c) Michael Nattfalk 2019\n\n");
if(!collect_arguments(argc, argv)) {
print_usage();
exit(1);
}
iff_image_data image;
if(iff_loadimage(&opts, &image))
{
raw_writeimage(&opts, &image);
}
if (image.data)
free(image.data);
if (image.palette)
free(image.palette);
return 0;
}