summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/rltiles/tool/tile_convert.cc
blob: 0134b67654b68109f69700878faf5d110d29c4b3 (plain) (blame)
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
#include <stdio.h>
#include <string.h>

// This is a standalone utility to convert old-style palettized BMPs 
// to transparent PNGs.

#include "tile.h"
#include <SDL_main.h>

int main(int argc, char **argv)
{
    if (argc < 2)
    {
        printf("Usage: %s (filename.bmp)\n", argv[0]);
        return -1;
    }

    char dest[1024];
    strcpy(dest, argv[1]);

    size_t len = strlen(dest);
    if (!strcmp(&dest[len-4], ".bmp"))
    {
        dest[len-3] = 'p';
        dest[len-2] = 'n';
        dest[len-1] = 'g';
    }
    else if (!strcmp(&dest[len-4], ".png"))
    {
        // ok as-is.
    }
    else
    {
        printf("File '%s' does not end in bmp or png.\n", argv[1]);
        return -2;
    }

    tile conv;
    if (!conv.load(argv[1]))
    {
        printf("Failed to load '%s'.\n", argv[1]);
        return -3;
    }

    conv.replace_colour(tile_colour::background, tile_colour::transparent);

    if (!write_png(dest, &conv.get_pixel(0,0), conv.width(), conv.height()))
    {
        printf("Failed to write dest '%s'.\n", dest);
        return -4;
    }

    printf("Converted '%s'.\n", argv[1]);

    return 0;
}