summaryrefslogtreecommitdiff
path: root/trunk/palette2c.c
blob: bbe272c9c9753238abee62bd3c1bd2b8e4f62054 (plain)
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
/*
 * This file is part of librosprite.
 * Licensed under the MIT License,
 *                http://www.opensource.org/licenses/mit-license.php
 * Copyright 2008 James Shaw <js102@zepler.net>
 */

#include <stdio.h>
#include <stdlib.h>

#include "librosprite.h"
 
int main(int argc, char *argv[])
{
	if (argc < 2) {
		printf("Usage: palette2c palettefile\n");
		exit(EXIT_FAILURE);
	}

	char* filename = argv[1];

	FILE* f = fopen(filename, "rb");
	if (f == NULL) {
		printf("Can't load palettefile %s\n", filename);
		exit(EXIT_FAILURE);
	}

	struct rosprite_file_context* ctx;
	if (rosprite_create_file_context(f, &ctx) != ROSPRITE_OK) {
		exit(EXIT_FAILURE);
	}
	
	struct rosprite_palette* palette;
	if (rosprite_load_palette(rosprite_file_reader, ctx, &palette) != ROSPRITE_OK) {
		exit(EXIT_FAILURE);
	}

	for (uint32_t i = 0; i < palette->size; i++) {
		printf("0x%x, ", palette->palette[i]);
	}

	fclose(f);

	rosprite_destroy_file_context(ctx);
	rosprite_destroy_palette(palette);

	return EXIT_SUCCESS;
}