[go: up one dir, main page]

Menu

[r81]: / engine / utils / png2cel.c  Maximize  Restore  History

Download this file

107 lines (82 with data), 2.4 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
 99
100
101
102
103
104
105
106
/* $Id: png2cel.c,v 1.1 2004/09/11 16:17:55 mlefebvr Exp $
*
* Tool for the IRE engine.
*
* Convert a paletted PNG file to a CEL one.
*
* Restrictions on the PNG image:
* - must be a paletted image
* - height and width can't excess a two bytes-seized unsigned integer
* in order to store them in the CEL file header ;)
* - Transparency [indexes] will be lost.
* Check the source file "cel-png.c"
*
* Link against libpng library: "-lpng"
*/
#ifdef __GNUC__
#define _GNU_SOURCE /* To allow the use of the strcasestr() function
* (case independent)
*/
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include "cel-png.h" /* CEL <-> PNG conversion functions */
static char progname[] = "png2cel";
static int usage(const char *progname);
int main(int argc, char **argv)
{
int rc = 0; /* return code */
int remaining_args;
char *cel_file;
char *png_file;
char *filename_tmp = NULL;
remaining_args = argc - 1;
if ((remaining_args == 0) || (remaining_args > 2)) /* No or too many args */ {
usage(progname);
exit(1); /* Bad args */
} else if (remaining_args == 1) /* Only the PNG file specified */ {
char *ptr;
png_file = argv[1];
/*
* Build the cel file name
* (cel_file = png_file) =~ s/.png$/.cel/i;
*/
filename_tmp = strdup(png_file);
if (filename_tmp == NULL) {
perror("strdup");
exit(2);
}
#ifdef _GNU_SOURCE
ptr = strcasestr(filename_tmp, ".png"); /* case independent */
#else
ptr = strstr (filename_tmp, ".png");
#endif
if (ptr == NULL) {
fprintf(stderr, "%s \"%s\": PNG files must end by \".png\"\n",
progname, filename_tmp);
free(filename_tmp);
exit(1);
}
strcpy(ptr, ".cel");
cel_file = filename_tmp;
} else /* CEL file and PNG file specified */ {
png_file = argv[1];
cel_file = argv[2];
}
rc = png2cel(png_file, cel_file);
if (filename_tmp != NULL) { free(filename_tmp); }
exit(rc);
}
static int usage(const char *progname)
{
printf("Usage: %s pngfile.png [celfile.cel]\n\n", progname);
puts("Convert a paletted PNG file to the CEL format used by IRE");
puts("If celfile.cel is not specified, it is named after pngfile.png\n");
puts("Restrictions on the PNG image:");
puts("- must be a paletted image");
puts("- Transparency [indexes] will be lost\n");
return 0;
}