summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/rltiles/bmp2png
diff options
context:
space:
mode:
Diffstat (limited to 'crawl-ref/source/rltiles/bmp2png')
-rw-r--r--crawl-ref/source/rltiles/bmp2png/README69
-rw-r--r--crawl-ref/source/rltiles/bmp2png/bmp2png.c1078
-rw-r--r--crawl-ref/source/rltiles/bmp2png/bmp2png.dsp112
-rw-r--r--crawl-ref/source/rltiles/bmp2png/bmphed.h84
-rw-r--r--crawl-ref/source/rltiles/bmp2png/common.c748
-rw-r--r--crawl-ref/source/rltiles/bmp2png/common.h196
-rw-r--r--crawl-ref/source/rltiles/bmp2png/makefile.bcc52
-rw-r--r--crawl-ref/source/rltiles/bmp2png/makefile.dj254
-rw-r--r--crawl-ref/source/rltiles/bmp2png/makefile.lin48
-rw-r--r--crawl-ref/source/rltiles/bmp2png/png2bmp.c647
-rw-r--r--crawl-ref/source/rltiles/bmp2png/png2bmp.dsp111
11 files changed, 3199 insertions, 0 deletions
diff --git a/crawl-ref/source/rltiles/bmp2png/README b/crawl-ref/source/rltiles/bmp2png/README
new file mode 100644
index 0000000000..b4ace21f2d
--- /dev/null
+++ b/crawl-ref/source/rltiles/bmp2png/README
@@ -0,0 +1,69 @@
+bmp2png / png2bmp version 1.62 - Sep 04, 2005
+---------------------------------------------
+
+bmp2png/png2bmp is a pair of simple command-line utilities that convert
+between Windows BMP format and PNG (Portable Network Graphics).
+
+This software is freeware.
+
+
+Using them
+----------
+
+The basic command line is:
+
+ bmp2png [-options] list of bmp files ...
+ png2bmp [-options] list of png files ...
+
+The input files are not modified; the output data is written to files
+which have the same names except for extension. bmp2png always uses
+".png" for the output file name's extension; png2bmp uses ".bmp".
+
+To list the options, simply type "bmp2png" or "png2bmp" with no
+arguments.
+
+
+Copyright notice, and license
+-----------------------------
+
+bmp2png --- conversion from (Windows or OS/2 style) BMP to PNG
+png2bmp --- conversion from PNG to (Windows style) BMP
+
+Copyright (C) 1999-2005 MIYASAKA Masaru <alkaid@coral.ocn.ne.jp>
+
+Permission to use, copy, modify, and distribute this software and
+its documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation. This software is provided "as is"
+without express or implied warranty.
+
+
+The latest version
+------------------
+
+To get the latest version of bmp2png/png2bmp, please visit the
+bmp2png/png2bmp home page:
+
+ http://hp.vector.co.jp/authors/VA010446/b2p-home/
+
+
+Major changes
+-------------
+
+version 1.60 [August 25, 2004]
+ bmp2png now can read all types of BMP file, including
+ 16/32 bits/pixel BMP, bitfield BMP, and RLE-encoded BMP.
+ Added -P option to bmp2png, which allows to make one particular
+ color fully transparent.
+
+version 1.61 [September 4, 2004]
+ (executable) Fixed a file-corruption bug which was introduced
+ in libpng 1.2.6.
+ (source code) Added support for emx complier (not tested).
+
+version 1.62 [September 4, 2005]
+ Added alpha channel support. (Added -A, -B and -R options.)
+
+
+[end]
diff --git a/crawl-ref/source/rltiles/bmp2png/bmp2png.c b/crawl-ref/source/rltiles/bmp2png/bmp2png.c
new file mode 100644
index 0000000000..245013e7c8
--- /dev/null
+++ b/crawl-ref/source/rltiles/bmp2png/bmp2png.c
@@ -0,0 +1,1078 @@
+/*
+** bmp2png --- conversion from (Windows or OS/2 style) BMP to PNG
+**
+** Copyright (C) 1999-2005 MIYASAKA Masaru
+**
+** For conditions of distribution and use,
+** see copyright notice in common.h.
+*/
+
+#include "common.h"
+#include "bmphed.h"
+
+#define BMP2PNG_VERSION "1.62 (Sep 4, 2005)"
+#define BMP2PNG_COPYRIGHT "Copyright (C) 1999-2005 MIYASAKA Masaru"
+
+char outnam[FILENAME_MAX];
+char outdir[FILENAME_MAX];
+int deletesrc = 0;
+int copytime = 0;
+int complevel = 6;
+int interlace = 0;
+int filters = 0;
+int alpha_bmp = 0;
+
+#define B2P_TRANSPARENT_NONE 0
+#define B2P_TRANSPARENT_RGB 1
+#define B2P_TRANSPARENT_PALETTE 2
+
+int trans_type = B2P_TRANSPARENT_NONE;
+png_color_16 trans_values;
+
+#if defined(WIN32) || defined(MSDOS)
+const char errlogfile[] = ".\\B2PERROR.LOG";
+#else
+const char errlogfile[] = "./b2perror.log";
+#endif
+
+ /* error messages */
+#ifdef JAPANESE /* ---------- */
+const char wrn_invalidtrans[] =
+ "WARNING: 透明色指定の形式が正しくありません(無視されます) - '%s'\n";
+const char wrn_notranscolor[] =
+ "WARNING: 指定された透明色に一致する色がありません - %s\n"
+ "WARNING: -> -P オプション での透明色指定は無視されます\n";
+const char wrn_transtruecolor[] =
+ "WARNING: 画像はフルカラー形式です - %s\n"
+ "WARNING: -> -P オプション での透明色指定は無視されます\n";
+const char wrn_imagehasalpha[] =
+ "WARNING: アルファチャネル付きの画像です - %s\n"
+ "WARNING: -> -P オプション での透明色指定は無視されます\n";
+const char wrn_alphaallzero[] =
+ "WARNING: 4番目のチャネルはアルファチャネルではないようです(すべて0) - %s\n"
+ "WARNING: -> 4番目のチャネル(アルファチャネル)は破棄されます\n";
+const char wrn_mkdirfail[] =
+ "WARNING: 出力先ディレクトリを作れません - %s\n"
+ "WARNING: -> -%c オプション での出力先指定は無視されます\n";
+const char err_ropenfail[] = "SKIPPED: 該当するファイルがありません - %s\n";
+const char err_wopenfail[] = "SKIPPED: 出力ファイルを作成できません - %s\n";
+const char err_outofmemory[] = "SKIPPED: 作業用メモリが確保できません - %s\n";
+ /* -- */
+const char err_readeof[] = "SKIPPED: ファイルが途中で切れています - %s\n";
+const char err_readerr[] = "SKIPPED: 読み込みエラーが発生しました - %s\n";
+const char err_not_a_bmp[] = "SKIPPED: BMP ファイルではありません - %s\n";
+const char err_invalid_hed[] =
+ "SKIPPED: BMP ファイルのヘッダサイズが無効です - %s\n";
+const char err_width_zero[] = "SKIPPED: 画像の幅が0(または負)です - %s\n";
+const char err_height_zero[] = "SKIPPED: 画像の高さが0(または負)です - %s\n";
+const char err_compression[] = "SKIPPED: 不明な圧縮タイプです - %s\n";
+const char err_invalid_bpp[] = "SKIPPED: 画像の色数が無効です - %s\n";
+const char err_no_palette[] = "SKIPPED: パレットが欠落しています - %s\n";
+#else /* ------------------- */
+const char wrn_invalidtrans[] =
+ "WARNING: Invalid transparent color specifier - '%s'. ignored.\n";
+const char wrn_notranscolor[] =
+ "WARNING: Specified transparent color is not present in palette - %s\n"
+ "WARNING: -> Transparent color specified by '-P' will be ignored.\n";
+const char wrn_transtruecolor[] =
+ "WARNING: Image is truecolor format - %s\n"
+ "WARNING: -> Transparent color specified by '-P' will be ignored.\n";
+const char wrn_imagehasalpha[] =
+ "WARNING: Image has an alpha channel - %s\n"
+ "WARNING: -> Transparent color specified by '-P' will be ignored.\n";
+const char wrn_alphaallzero[] =
+ "WARNING: The 4th channel doesn't seem to be an alpha channel (all zero) - %s\n"
+ "WARNING: -> The 4th channel (alpha channel) will be discarded.\n";
+const char wrn_mkdirfail[] =
+ "WARNING: Cannot create a directory - %s\n"
+ "WARNING: -> Output directory specified by '-%c' will be ignored.\n";
+const char err_ropenfail[] = "SKIPPED: No such file or directory - %s\n";
+const char err_wopenfail[] = "SKIPPED: Cannot create - %s\n";
+const char err_outofmemory[] = "SKIPPED: Out of memory - %s\n";
+ /* -- */
+const char err_readeof[] = "SKIPPED: Premature end of BMP file - %s\n";
+const char err_readerr[] = "SKIPPED: Read operation failed - %s\n";
+const char err_not_a_bmp[] = "SKIPPED: Not a BMP file - %s\n";
+const char err_invalid_hed[] = "SKIPPED: Invalid header size in BMP file - %s\n";
+const char err_width_zero[] = "SKIPPED: Invalid image width - %s\n";
+const char err_height_zero[] = "SKIPPED: Invalid image height - %s\n";
+const char err_compression[] = "SKIPPED: Unknown compression type - %s\n";
+const char err_invalid_bpp[] = "SKIPPED: Invalid bit depth in BMP file - %s\n";
+const char err_no_palette[] = "SKIPPED: Palette is missing - %s\n";
+#endif /* ------------------- */
+
+static int transparent_color(png_color_16p, const char *);
+static int png_filters(const char *);
+static BOOL read_bmp(char *, IMAGE *);
+static BOOL is_4th_alpha(IMAGE *);
+static const char *read_rgb_bits(IMAGE *, FILE *);
+static const char *read_bitfield_bits(IMAGE *, FILE *, DWORD *, UINT);
+static const char *decompress_rle_bits(IMAGE *, FILE *);
+static unsigned long mgetdwl(void *);
+static unsigned int mgetwl(void *);
+static BOOL write_png(char *, IMAGE *);
+static void usage_exit(char *, int);
+
+
+
+/*
+** メイン
+*/
+int main(int argc, char *argv[])
+{
+ char outf[FILENAME_MAX];
+ IMAGE image;
+ int opt;
+ char *arg;
+ char *p, c;
+ int r_stdin, w_stdout;
+ int failure = 0, success = 0;
+
+#ifdef __LCC__ /* lcc-win32 */
+ char **envp;
+ void _GetMainArgs(int *, char ***, char ***, int);
+ _GetMainArgs(&argc, &argv, &envp, 1);
+#endif
+#ifdef __EMX__
+ _wildcard(&argc, &argv);
+#endif
+ envargv(&argc, &argv, "B2P");
+
+ r_stdin = !isatty(fileno(stdin));
+ w_stdout = !isatty(fileno(stdout));
+
+ while (parsearg(&opt, &arg, argc, argv, "DdOoFfPp")) {
+ if (isdigit(opt)) { /* Zlib Compression Level (0-9) */
+ complevel = opt - '0';
+ continue;
+ }
+ switch (toupper(opt)) {
+ case 'I': interlace ^= 1; break;
+ case 'E': deletesrc ^= 1; break;
+ case 'T': copytime ^= 1; break;
+ case 'Q': quietmode ^= 1; break;
+ case 'L': errorlog ^= 1; break;
+
+ case 'X':
+ r_stdin = 0;
+ w_stdout = 0;
+ break;
+
+ case 'A':
+ alpha_bmp ^= 1;
+ break;
+
+ case 'B':
+ alpha_bmp ^= 1;
+ break;
+
+ case 'R':
+ /* '-R' option of png2bmp (ignored on bmp2png) */
+ break;
+
+ case 'F': /* filter types to be used in libpng */
+ filters = png_filters(arg);
+ break;
+
+ case 'P': /* transparent color */
+ trans_type = transparent_color(&trans_values, arg);
+ break;
+
+ case 'D': /* output directory */
+ if (*arg == '-') arg = NULL;
+ if (arg == NULL) {
+ outdir[0] = '\0';
+ } else {
+ strcpy(outdir, arg);
+ addslash(outdir);
+ if (makedir(outdir) != 0) {
+ xxprintf(wrn_mkdirfail, outdir, 'D');
+ outdir[0] = '\0';
+ }
+ }
+ break;
+
+ case 'O': /* output filename */
+ if (arg == NULL) {
+ outnam[0] = '\0';
+ } else {
+ strcpy(outnam, arg);
+ p = basname(outnam);
+ c = *p; *p = '\0';
+ if (makedir(outnam) != 0) {
+ xxprintf(wrn_mkdirfail, outnam, 'O');
+ outnam[0] = '\0';
+ } else {
+ *p = c;
+ }
+ }
+ break;
+
+ case 0x00: /* input file spec */
+ if (outnam[0] != '\0') {
+ strcpy(outf, outnam);
+ outnam[0] = '\0';
+ } else if (w_stdout) {
+ if (!read_bmp(arg, &image)) return 1;
+ if (!write_png(NULL, &image)) return 1;
+ if (deletesrc) remove(arg);
+ return 0;
+ } else {
+ if (outdir[0] != '\0') {
+ strcat(strcpy(outf, outdir), basname(arg));
+ } else {
+ strcpy(outf, arg);
+ }
+#ifdef WIN32_LFN
+ strcpy(suffix(outf), is_dos_filename(outf) ? ".PNG" : ".png");
+#else
+ strcpy(suffix(outf), ".png");
+#endif
+ }
+ /* ---------------------- */
+ if (!read_bmp(arg, &image)) {
+ failure++;
+ break;
+ }
+ renbak(outf);
+ if (!write_png(outf, &image)) {
+ failure++;
+ break;
+ }
+ /* ---------------------- */
+ if (copytime) cpyftime(arg, outf);
+ if (deletesrc) remove(arg);
+ /* ---------------------- */
+ success++;
+ break;
+
+ default:
+ ; /* Ignore unknown option */
+ }
+ }
+ if (failure == 0 && success == 0) {
+ if (!r_stdin) usage_exit(argv[0], 255);
+ if (!read_bmp(NULL, &image)) return 1;
+ if (outnam[0] != '\0') {
+ renbak(outnam);
+ return !write_png(outnam, &image);
+ } else if (w_stdout) {
+ return !write_png(NULL, &image);
+ } else {
+ strcat(strcpy(outf, outdir), "___stdin.png");
+ renbak(outf);
+ return !write_png(outf, &image);
+ }
+ }
+
+ return (failure > 255) ? 255 : failure;
+}
+
+
+#define elemsof(a) (sizeof(a) / sizeof((a)[0]))
+
+/*
+** PNG のフィルタ種別指定を読む
+*/
+static int png_filters(const char *arg)
+{
+ static const struct { char name[8]; int flag; } filter[] = {
+ { "NONE", PNG_FILTER_NONE }, { "SUB" , PNG_FILTER_SUB },
+ { "UP" , PNG_FILTER_UP }, { "AVERAGE", PNG_FILTER_AVG },
+ { "AVG" , PNG_FILTER_AVG }, { "PAETH" , PNG_FILTER_PAETH },
+ { "ALL" , PNG_ALL_FILTERS },
+ { "AUTO", 0 }, { "DEFAULT", 0 }
+ };
+ char c, buf[64];
+ int i, flags = 0;
+
+ if (arg == NULL) return 0; /* auto/default */
+
+ do {
+ i = 0;
+ while (c = *(arg++), c != ',' && c != '\0')
+ if (i < sizeof(buf) - 1) buf[i++] = toupper(c);
+ buf[i] = '\0';
+
+ for (i = 0; i < elemsof(filter); i++) {
+ if (strcmp(buf, filter[i].name) == 0) {
+ if (filter[i].flag == 0) flags = 0; /* auto/default */
+ else flags |= filter[i].flag;
+ }
+ }
+ } while (c != '\0');
+
+ return flags;
+}
+
+
+/*
+** 透明色指定を読む
+*/
+static int transparent_color(png_color_16p trans_values, const char *arg)
+{
+ char c, buf[32];
+ int i, n;
+
+ if (arg == NULL) return B2P_TRANSPARENT_NONE;
+
+ for (i = 0; (c = arg[i]) != '\0' && i < sizeof(buf)-1; i++)
+ buf[i] = toupper(c);
+ buf[i] = '\0';
+
+ if (strcmp(buf, "NONE") == 0) {
+ return B2P_TRANSPARENT_NONE;
+ }
+ if (buf[0] == '#') {
+ n = sscanf(buf, "#%2hx%2hx%2hx", &trans_values->red,
+ &trans_values->green, &trans_values->blue);
+ if (n == 3 && i >= 7) {
+ return B2P_TRANSPARENT_RGB;
+ }
+ } else {
+ n = sscanf(buf, "%hu,%hu,%hu", &trans_values->red,
+ &trans_values->green, &trans_values->blue);
+ if (n == 3 && trans_values->red <= 255 &&
+ trans_values->green <= 255 && trans_values->blue <= 255) {
+ return B2P_TRANSPARENT_RGB;
+ }
+ if (n == 1 && trans_values->red <= 255) {
+ trans_values->index = (png_byte)trans_values->red;
+ return B2P_TRANSPARENT_PALETTE;
+ }
+ }
+
+ xxprintf(wrn_invalidtrans, arg);
+
+ return B2P_TRANSPARENT_NONE;
+}
+
+
+/* -----------------------------------------------------------------------
+** BMP ファイルの読み込み
+*/
+
+#define ERROR_ABORT(s) do { errmsg = (s); goto error_abort; } while (0)
+
+/*
+** .bmp ファイルの読み込み
+*/
+static BOOL read_bmp(char *fn, IMAGE *img)
+{
+ BYTE bfh[FILEHED_SIZE + BMPV5HED_SIZE];
+ BYTE *const bih = bfh + FILEHED_SIZE;
+ BYTE rgbq[RGBQUAD_SIZE];
+ DWORD offbits, bihsize, skip;
+ DWORD compression, color_mask[4];
+ UINT palette_size, true_pixdepth;
+ BOOL alpha_check;
+ PALETTE *pal;
+ const char *errmsg;
+ FILE *fp;
+ int i;
+
+ imgbuf_init(img);
+
+ if (fn == NULL) { /* read from stdin */
+ fn = " (stdin)";
+ fp = binary_stdio(fileno(stdin));
+ } else {
+ fp = fopen(fn, "rb");
+ }
+ if (fp == NULL) ERROR_ABORT(err_ropenfail);
+
+ set_status("Reading %.80s", basname(fn));
+
+ /* ------------------------------------------------------ */
+
+ for (i = 0; ; i++) { /* skip macbinary header */
+ if (fread(bfh, (FILEHED_SIZE + BIHSIZE_SIZE), 1, fp) != 1)
+ ERROR_ABORT(ferror(fp) ? err_readerr : err_readeof);
+ if (mgetwl(bfh + BFH_WTYPE) == BMP_SIGNATURE) break;
+ if (i != 0) ERROR_ABORT(err_not_a_bmp);
+ if (fread(bfh, (128 - FILEHED_SIZE - BIHSIZE_SIZE), 1, fp) != 1)
+ ERROR_ABORT(ferror(fp) ? err_readerr : err_readeof);
+ }
+ offbits = mgetdwl(bfh + BFH_DOFFBITS);
+ bihsize = mgetdwl(bfh + BFH_DBIHSIZE);
+ skip = offbits - bihsize - FILEHED_SIZE;
+ if (bihsize < COREHED_SIZE || bihsize > BMPV5HED_SIZE ||
+ offbits < (bihsize + FILEHED_SIZE)) ERROR_ABORT(err_invalid_hed);
+
+ if (fread((bih + BIHSIZE_SIZE), (bihsize - BIHSIZE_SIZE), 1, fp) != 1)
+ ERROR_ABORT(ferror(fp) ? err_readerr : err_readeof);
+
+ if (bihsize >= INFOHED_SIZE) { /* Windows-style BMP */
+ img->width = mgetdwl(bih + BIH_LWIDTH);
+ img->height = mgetdwl(bih + BIH_LHEIGHT);
+ img->pixdepth = mgetwl(bih + BIH_WBITCOUNT);
+ img->topdown = FALSE;
+ compression = mgetdwl(bih + BIH_DCOMPRESSION);
+ palette_size = RGBQUAD_SIZE;
+ if (img->height < 0) {
+ img->height = -img->height;
+ img->topdown = TRUE; /* top-down BMP */
+ }
+ } else { /* OS/2-style BMP */
+ img->width = mgetwl(bih + BCH_WWIDTH);
+ img->height = mgetwl(bih + BCH_WHEIGHT);
+ img->pixdepth = mgetwl(bih + BCH_WBITCOUNT);
+ img->topdown = FALSE;
+ compression = BI_RGB;
+ palette_size = RGBTRIPLE_SIZE;
+ }
+ img->alpha = FALSE;
+ alpha_check = FALSE;
+ true_pixdepth = img->pixdepth;
+
+ if (img->width <= 0) ERROR_ABORT(err_width_zero);
+ if (img->height <= 0) ERROR_ABORT(err_height_zero);
+
+ switch (compression) {
+ case BI_RGB:
+ if (img->pixdepth != 1 && img->pixdepth != 4 &&
+ img->pixdepth != 8 && img->pixdepth != 16 &&
+ img->pixdepth != 24 && img->pixdepth != 32)
+ ERROR_ABORT(err_invalid_bpp);
+
+ if (img->pixdepth == 32 && alpha_bmp)
+ alpha_check = TRUE;
+
+ if (img->pixdepth == 16) {
+ color_mask[3] = 0x0000; /* alpha */
+ color_mask[2] = 0x7C00; /* red */
+ color_mask[1] = 0x03E0; /* green */
+ color_mask[0] = 0x001F; /* blue */
+ compression = BI_BITFIELDS;
+ }
+ break;
+
+ case BI_BITFIELDS:
+ if (img->pixdepth != 16 && img->pixdepth != 32)
+ ERROR_ABORT(err_invalid_bpp);
+
+ if (bihsize < INFOHED_SIZE + 12) {
+ if (skip < (INFOHED_SIZE + 12 - bihsize))
+ ERROR_ABORT(err_invalid_hed);
+ if (fread((bih + bihsize), (INFOHED_SIZE + 12 - bihsize), 1, fp)
+ != 1) ERROR_ABORT(ferror(fp) ? err_readerr : err_readeof);
+ skip -= (INFOHED_SIZE + 12 - bihsize);
+ }
+ color_mask[3] = 0x00000000; /* alpha */
+ color_mask[2] = mgetdwl(bih + B4H_DREDMASK); /* red */
+ color_mask[1] = mgetdwl(bih + B4H_DGREENMASK); /* green */
+ color_mask[0] = mgetdwl(bih + B4H_DBLUEMASK); /* blue */
+
+ if (img->pixdepth == 32 && alpha_bmp &&
+ bihsize >= INFOHED_SIZE + 16) {
+ color_mask[3] = mgetdwl(bih + B4H_DALPHAMASK); /* alpha */
+ if (color_mask[3] != 0x00000000)
+ img->alpha = TRUE;
+ }
+
+ if (img->pixdepth == 32 && color_mask[0] == 0x000000FF &&
+ color_mask[1] == 0x0000FF00 && color_mask[2] == 0x00FF0000 &&
+ (color_mask[3] == 0xFF000000 || color_mask[3] == 0x00000000)) {
+ compression = BI_RGB;
+ }
+ break;
+
+ case BI_RLE8:
+ if (img->pixdepth != 8)
+ ERROR_ABORT(err_invalid_bpp);
+ break;
+
+ case BI_RLE4:
+ if (img->pixdepth != 4)
+ ERROR_ABORT(err_invalid_bpp);
+ break;
+
+ default:
+ ERROR_ABORT(err_compression);
+ }
+
+ if (img->pixdepth == 16) img->pixdepth = 24;
+
+ if (img->pixdepth <= 8) {
+ if (skip >= palette_size << img->pixdepth) {
+ img->palnum = 1 << img->pixdepth;
+ skip -= palette_size << img->pixdepth;
+ } else {
+ img->palnum = skip / palette_size;
+ skip = skip % palette_size;
+ }
+ if (img->palnum == 0)
+ ERROR_ABORT(err_no_palette);
+ } else {
+ img->palnum = 0;
+ }
+ if (!imgbuf_alloc(img)) ERROR_ABORT(err_outofmemory);
+
+ /* ------------------------------------------------------ */
+
+ for (pal = img->palette, i = img->palnum; i > 0; pal++, i--) {
+ if (fread(rgbq, palette_size, 1, fp) != 1)
+ ERROR_ABORT(ferror(fp) ? err_readerr : err_readeof);
+ pal->red = rgbq[RGBQ_RED];
+ pal->green = rgbq[RGBQ_GREEN];
+ pal->blue = rgbq[RGBQ_BLUE];
+ }
+ for ( ; skip > 0; skip--) {
+ if (fgetc(fp) == EOF)
+ ERROR_ABORT(ferror(fp) ? err_readerr : err_readeof);
+ }
+
+ /* ------------------------------------------------------ */
+
+ img->sigbit.red = img->sigbit.green = img->sigbit.blue = 8;
+ img->sigbit.gray = img->sigbit.alpha = 8;
+
+ switch (compression) {
+ case BI_RGB:
+ errmsg = read_rgb_bits(img, fp);
+ break;
+ case BI_BITFIELDS:
+ errmsg = read_bitfield_bits(img, fp, color_mask, true_pixdepth);
+ break;
+ case BI_RLE8:
+ case BI_RLE4:
+ errmsg = decompress_rle_bits(img, fp);
+ break;
+ default:
+ errmsg = err_compression;
+ }
+ if (errmsg != NULL) ERROR_ABORT(errmsg);
+
+ if (alpha_check) {
+ img->alpha = is_4th_alpha(img);
+ if (!img->alpha)
+ xxprintf(wrn_alphaallzero, fn);
+ }
+
+ /* ------------------------------------------------------ */
+
+ set_status("Read OK %.80s", basname(fn));
+
+ if (fp != stdin) fclose(fp);
+
+ return TRUE;
+
+error_abort: /* error */
+ xxprintf(errmsg, fn);
+ if (fp != stdin && fp != NULL) fclose(fp);
+ imgbuf_free(img);
+
+ return FALSE;
+}
+
+
+/*
+** 第4のチャネルがアルファチャネルかどうか調べる
+*/
+static BOOL is_4th_alpha(IMAGE *img)
+{
+ LONG w, h;
+ BYTE *p;
+
+ if (img->pixdepth == 32) { /* failsafe */
+ for (h = img->height, p = img->bmpbits + 3; --h >= 0; )
+ for (w = img->width; --w >= 0; p += 4)
+ if (*p != 0) return TRUE;
+ }
+
+ return FALSE;
+}
+
+
+/*
+** BI_RGB (無圧縮) 形式の画像データを読む
+*/
+static const char *read_rgb_bits(IMAGE *img, FILE *fp)
+{
+#if 1
+ DWORD rd = 16*1024*1024;
+ DWORD num = img->imgbytes;
+ BYTE *ptr = img->bmpbits;
+
+ while (num > 0) {
+ if (rd > num) rd = num;
+
+ if (fread(ptr, rd, 1, fp) != 1)
+ return ferror(fp) ? err_readerr : err_readeof;
+
+ ptr += rd; num -= rd;
+ }
+#else
+ if (fread(img->bmpbits, img->imgbytes, 1, fp) != 1)
+ return ferror(fp) ? err_readerr : err_readeof;
+#endif
+ return NULL;
+}
+
+
+/*
+** BI_BITFIELDS 形式の画像データを読む
+*/
+static const char *read_bitfield_bits(IMAGE *img, FILE *fp, DWORD *color_mask,
+ UINT true_pixdepth)
+{
+ int color_shift[4];
+ int color_sigbits[4];
+ BYTE color_tbl[4][1<<7];
+ DWORD true_rowbytes;
+ BYTE *row, *p, *q;
+ LONG w, h;
+ DWORD v, u;
+ int i, j, k;
+
+ for (i = 0; i < 4; i++) {
+ v = color_mask[i];
+ if (v == 0) {
+ color_shift[i] = 0;
+ color_sigbits[i] = 8;
+ } else {
+ for (j = 0; (v & 1) == 0; v >>= 1, j++) ;
+ for (k = 0; (v) != 0; v >>= 1, k++) ;
+ color_shift[i] = j;
+ color_sigbits[i] = k;
+ }
+ if (color_sigbits[i] <= 7) {
+ k = (1 << color_sigbits[i]) - 1;
+ for (j = 0; j <= k; j++)
+ color_tbl[i][j] = (0xFF * j + k/2) / k;
+ }
+ }
+
+ if (color_sigbits[3] < 8) img->sigbit.alpha = color_sigbits[3];
+ if (color_sigbits[2] < 8) img->sigbit.red = color_sigbits[2];
+ if (color_sigbits[1] < 8) img->sigbit.green = color_sigbits[1];
+ if (color_sigbits[0] < 8) img->sigbit.blue = color_sigbits[0];
+
+ true_rowbytes = ((DWORD)img->width * (true_pixdepth/8) + 3) & (~3UL);
+
+ for (h = img->height, row = img->bmpbits; --h >= 0;
+ row += img->rowbytes) {
+ if (fread(row, true_rowbytes, 1, fp) != 1)
+ return ferror(fp) ? err_readerr : err_readeof;
+
+ switch (true_pixdepth) {
+ case 16:
+ for (w = img->width, p = row + (w-1)*2, q = row + (w-1)*3;
+ --w >= 0; p -= 2, q -= 3) {
+ v = ((UINT)p[0]) + ((UINT)p[1] << 8);
+ for (i = 0; i < 3; i++) {
+ u = (v & color_mask[i]) >> color_shift[i];
+ if (color_sigbits[i] <= 7)
+ u = color_tbl[i][u];
+ else if (color_sigbits[i] >= 9)
+ u >>= (color_sigbits[i] - 8);
+ q[i] = (BYTE) u;
+ }
+ }
+ break;
+
+ case 32:
+ for (w = img->width, p = row; --w >= 0; p += 4) {
+ v = ((DWORD)p[0] ) + ((DWORD)p[1] << 8) +
+ ((DWORD)p[2] << 16) + ((DWORD)p[3] << 24);
+ for (i = 0; i < 4; i++) {
+ u = (v & color_mask[i]) >> color_shift[i];
+ if (color_sigbits[i] <= 7)
+ u = color_tbl[i][u];
+ else if (color_sigbits[i] >= 9)
+ u >>= (color_sigbits[i] - 8);
+ p[i] = (BYTE) u;
+ }
+ }
+ break;
+ }
+ }
+
+ return NULL;
+}
+
+
+/*
+** BI_RLE8/BI_RLE4 形式の画像データを読む
+*/
+static const char *decompress_rle_bits(IMAGE *img, FILE *fp)
+{
+ BYTE buf[1024]; /* 258 or above */
+ BYTE *bfptr = buf;
+ UINT bfcnt = 0;
+ UINT rd, reclen;
+ BYTE *row = img->bmpbits;
+ LONG x = 0, y = 0;
+ BYTE *p, c;
+ int n;
+
+ memset(img->bmpbits, 0, img->imgbytes);
+
+ for (;;) {
+ while (bfcnt < (reclen = 2) ||
+ (bfptr[0] == 0 &&
+ ((bfptr[1] == 2 && bfcnt < (reclen += 2)) ||
+ (bfptr[1] >= 3 &&
+ bfcnt < (reclen += (bfptr[1] * img->pixdepth + 15) / 16 * 2)
+ )))) {
+ if (bfptr != buf && bfcnt != 0) memmove(buf, bfptr, bfcnt);
+ if ((rd = fread(buf+bfcnt, 1, sizeof(buf)-bfcnt, fp)) == 0) {
+ if (x >= img->width) { /*x = 0;*/ y += 1; }
+ if (y >= img->height) return NULL; /* missing EoB marker */
+ else return ferror(fp) ? err_readerr : err_readeof;
+ }
+ bfptr = buf;
+ bfcnt += rd;
+ }
+ if (y >= img->height) {
+ /* We simply discard the remaining records */
+ if (bfptr[0] == 0 && bfptr[1] == 1) break; /* EoB marker */
+ bfptr += reclen;
+ bfcnt -= reclen;
+ continue;
+ }
+ if (bfptr[0] != 0) { /* Encoded-mode record */
+ n = bfptr[0]; c = bfptr[1];
+ switch (img->pixdepth) {
+ case 8: /* BI_RLE8 */
+ while (n > 0 && x < img->width) {
+ row[x] = c;
+ n--; x++;
+ }
+ break;
+ case 4: /* BI_RLE4 */
+ if (x % 2 != 0 && x < img->width) {
+ c = (c >> 4) | (c << 4);
+ row[x/2] = (row[x/2] & 0xF0) | (c & 0x0F);
+ n--; x++;
+ }
+ while (n > 0 && x < img->width) {
+ row[x/2] = c;
+ n-=2; x+=2;
+ }
+ if (n < 0) x--;
+ break;
+ }
+ } else if (bfptr[1] >= 3) { /* Absolute-mode record */
+ n = bfptr[1]; p = bfptr + 2;
+ switch (img->pixdepth) {
+ case 8: /* BI_RLE8 */
+ while (n > 0 && x < img->width) {
+ row[x] = *p;
+ n--; x++; p++;
+ }
+ break;
+ case 4: /* BI_RLE4 */
+ if (x % 2 != 0) {
+ if (x < img->width) {
+ row[x/2] = (row[x/2] & 0xF0) | (*p >> 4);
+ n--; x++;
+ }
+ while (n > 0 && x < img->width) {
+ row[x/2] = (p[0] << 4) | (p[1] >> 4);
+ n-=2; x+=2; p++;
+ }
+ if (n < 0) x--;
+ } else {
+ while (n > 0 && x < img->width) {
+ row[x/2] = *p;
+ n-=2; x+=2; p++;
+ }
+ if (n < 0) x--;
+ }
+ break;
+ }
+ } else if (bfptr[1] == 2) { /* Delta record */
+ x += bfptr[2]; y += bfptr[3];
+ row += bfptr[3] * img->rowbytes;
+ } else if (bfptr[1] == 0) { /* End of line marker */
+ x = 0; y += 1;
+ row += img->rowbytes;
+ } else /*if (bfptr[1] == 1)*/ { /* End of bitmap marker */
+ break;
+ }
+ bfptr += reclen;
+ bfcnt -= reclen;
+ }
+
+ return NULL;
+}
+
+
+/*
+** メモリから little-endien 形式 4バイト無符号整数を読む
+*/
+static unsigned long mgetdwl(void *ptr)
+{
+ unsigned char *p = ptr;
+
+ return ((unsigned long)p[0] ) + ((unsigned long)p[1] << 8) +
+ ((unsigned long)p[2] << 16) + ((unsigned long)p[3] << 24);
+}
+
+
+/*
+** メモリから little-endien 形式 2バイト無符号整数を読む
+*/
+static unsigned int mgetwl(void *ptr)
+{
+ unsigned char *p = ptr;
+
+ return ((unsigned int)p[0]) + ((unsigned int)p[1] << 8);
+}
+
+
+/* -----------------------------------------------------------------------
+** PNG ファイルの書き込み
+*/
+
+/*
+** .png ファイルの書き込み
+*/
+static BOOL write_png(char *fn, IMAGE *img)
+{
+ png_structp png_ptr;
+ png_infop info_ptr;
+ int bit_depth;
+ int color_type;
+ int interlace_type;
+ png_byte trans[256];
+ unsigned i;
+ const char *errmsg;
+ FILE *fp;
+
+ if (fn == NULL) {
+ fn = " (stdout)";
+ fp = binary_stdio(fileno(stdout));
+ } else {
+ fp = fopen(fn, "wb");
+ }
+ if (fp == NULL) ERROR_ABORT(err_wopenfail);
+
+ set_status("Writing %.80s", basname(fn));
+
+ /* ------------------------------------------------------ */
+
+ png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, fn,
+ png_my_error, png_my_warning);
+ if (png_ptr == NULL) {
+ ERROR_ABORT(err_outofmemory);
+ }
+ info_ptr = png_create_info_struct(png_ptr);
+ if (info_ptr == NULL) {
+ png_destroy_write_struct(&png_ptr, NULL);
+ ERROR_ABORT(err_outofmemory);
+ }
+ if (setjmp(png_jmpbuf(png_ptr))) {
+ /* If we get here, we had a problem reading the file */
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+ ERROR_ABORT(NULL);
+ }
+ png_init_io(png_ptr, fp);
+ png_set_compression_level(png_ptr, complevel);
+ if (filters != 0)
+ png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, filters);
+
+ /* ------------------------------------------------------ */
+
+ if (img->pixdepth == 24 || img->pixdepth == 32) {
+ bit_depth = 8;
+ color_type = (img->pixdepth == 32 && img->alpha) ?
+ PNG_COLOR_TYPE_RGB_ALPHA : PNG_COLOR_TYPE_RGB;
+ png_set_compression_mem_level(png_ptr, MAX_MEM_LEVEL);
+ } else {
+ bit_depth = img->pixdepth;
+ color_type = PNG_COLOR_TYPE_PALETTE;
+ png_set_PLTE(png_ptr, info_ptr, img->palette, img->palnum);
+ }
+ interlace_type = (interlace) ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE;
+
+ png_set_IHDR(png_ptr, info_ptr, img->width, img->height, bit_depth,
+ color_type, interlace_type, PNG_COMPRESSION_TYPE_DEFAULT,
+ PNG_FILTER_TYPE_DEFAULT);
+
+ if (img->sigbit.red != 8 || img->sigbit.green != 8 || img->sigbit.blue != 8
+ || (color_type == PNG_COLOR_TYPE_RGB_ALPHA && img->sigbit.alpha != 8))
+ png_set_sBIT(png_ptr, info_ptr, &img->sigbit);
+
+ switch (trans_type) {
+ case B2P_TRANSPARENT_RGB:
+ switch (color_type) {
+ case PNG_COLOR_TYPE_PALETTE:
+ for (i = 0; i < img->palnum; i++) {
+ if (img->palette[i].red == trans_values.red &&
+ img->palette[i].green == trans_values.green &&
+ img->palette[i].blue == trans_values.blue) {
+ trans[i++] = 0x00;
+ break;
+ }
+ trans[i] = 0xFF;
+ }
+ if (trans[i-1] == 0x00) {
+ png_set_tRNS(png_ptr, info_ptr, trans, i, NULL);
+ } else {
+ xxprintf(wrn_notranscolor, fn);
+ }
+ break;
+ case PNG_COLOR_TYPE_RGB:
+ png_set_tRNS(png_ptr, info_ptr, NULL, 0, &trans_values);
+ break;
+ case PNG_COLOR_TYPE_RGB_ALPHA:
+ xxprintf(wrn_imagehasalpha, fn);
+ break;
+ }
+ break;
+ case B2P_TRANSPARENT_PALETTE:
+ switch (color_type) {
+ case PNG_COLOR_TYPE_PALETTE:
+ if (trans_values.index < img->palnum) {
+ for (i = 0; i < trans_values.index; i++) trans[i] = 0xFF;
+ trans[i++] = 0x00;
+ png_set_tRNS(png_ptr, info_ptr, trans, i, NULL);
+ } else {
+ xxprintf(wrn_notranscolor, fn);
+ }
+ break;
+ case PNG_COLOR_TYPE_RGB:
+ xxprintf(wrn_transtruecolor, fn);
+ break;
+ case PNG_COLOR_TYPE_RGB_ALPHA:
+ xxprintf(wrn_imagehasalpha, fn);
+ break;
+ }
+ break;
+ }
+
+ png_write_info(png_ptr, info_ptr);
+
+ /* ------------------------------------------------------ */
+
+ if (img->pixdepth == 32 && !img->alpha)
+ png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
+
+ if (img->pixdepth == 24 || img->pixdepth == 32)
+ png_set_bgr(png_ptr);
+
+ /* ------------------------------------------------------ */
+
+ png_set_write_status_fn(png_ptr, row_callback);
+ init_progress_meter(png_ptr, img->width, img->height);
+
+ png_write_image(png_ptr, img->rowptr);
+
+ png_write_end(png_ptr, info_ptr);
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+
+ /* ------------------------------------------------------ */
+
+ set_status("OK %.80s", basname(fn));
+ feed_line();
+
+ fflush(fp);
+ if (fp != stdout) fclose(fp);
+ imgbuf_free(img);
+
+ return TRUE;
+
+error_abort: /* error */
+ if (errmsg != NULL) xxprintf(errmsg, fn);
+ if (fp != stdout && fp != NULL) fclose(fp);
+ imgbuf_free(img);
+
+ return FALSE;
+}
+
+
+/* -----------------------------------------------------------------------
+** ヘルプスクリーンの表示
+*/
+
+/*
+** 使用法表示
+*/
+static void usage_exit(char *argv0, int status)
+{
+ static const char str_usage[] =
+#ifdef JAPANESE /* -------------------------- */
+#ifdef SJIS_ESCAPE
+#define SJ_ESC(esc,raw) esc
+#else
+#define SJ_ESC(esc,raw) raw
+#endif
+ "bmp2png, BMP -> PNG コンバータ - version " BMP2PNG_VERSION "\n"
+ " " BMP2PNG_COPYRIGHT "\n"
+ " Compiled with libpng " PNG_LIBPNG_VER_STRING " and zlib " ZLIB_VERSION ".\n"
+ "\n"
+ "使い方 : %s [-スイッチ] 入力ファイル名 ...\n"
+ " : ... | %s [-スイッチ] | ...\n"
+ "\n"
+ "入力ファイル名にはワイルドカードが使えます (* と ?)\n"
+ "出力ファイル名は入力ファイル名の拡張子を .png に変えた名前になります\n"
+ "\n"
+ "スイッチオプション (小文字でも可) :\n"
+ " -0..-9 圧縮レベル (デフォルトは -6)\n"
+ " -I インターレース形式の PNG ファイルを作成する\n"
+ " -P color 指定した色を透明色にする\n"
+ " color: #RRGGBB(html式16進) / RR,GG,BB(10進RGB) / NN(パレット番号)\n"
+ " -F type[,...] PNG の圧縮に使われるフィルタ・タイプを指定する\n"
+ " type: none,sub,up,average(avg),paeth,all,auto(default)\n"
+ " -A, -B アルファチャネルを保存する\n"
+ " -O name 出力ファイル名を指定する\n"
+ " -D dir ファイルを出力するディレクトリを指定する\n"
+ " -E 変換が成功した場合には入力ファイルを削除する\n"
+ " -T 入力ファイルのタイムスタンプを出力ファイルに設定する\n"
+ " -Q 処理中, 一切の" SJ_ESC("表\示","表示") "をしない\n"
+ " -L 処理中のエラーをログファイル(%s)に記録する\n"
+ " -X 標準入力/標準出力を介した変換を無効にする\n";
+#else /* ----------------------------------- */
+ "bmp2png, a BMP-to-PNG converter - version " BMP2PNG_VERSION "\n"
+ " " BMP2PNG_COPYRIGHT "\n"
+ " Compiled with libpng " PNG_LIBPNG_VER_STRING " and zlib " ZLIB_VERSION ".\n"
+ "\n"
+ "Usage: %s [-switches] inputfile(s) ...\n"
+ " or: ... | %s [-switches] | ...\n"
+ "\n"
+ "List of input files may use wildcards (* and ?)\n"
+ "Output filename is same as input filename, but extension .png\n"
+ "\n"
+ "Switches (case-insensitive) :\n"
+ " -0..-9 Compression level (default: -6)\n"
+ " -I Create interlaced PNG files\n"
+ " -P color Mark the specified color as transparent\n"
+ " color: #RRGGBB(html hex) / RR,GG,BB(decimal) / NN(palette index)\n"
+ " -F type[,...] Specify filter type(s) used to create PNG files\n"
+ " type: none,sub,up,average(avg),paeth,all,auto(default)\n"
+ " -A, -B Preserve alpha channel\n"
+ " -O name Specify name for output file\n"
+ " -D dir Output files into dir\n"
+ " -E Delete input files after successful conversion\n"
+ " -T Set the timestamp of input file on output file\n"
+ " -Q Quiet mode\n"
+ " -L Log errors to %s file\n"
+ " -X Disable conversion through standard input/output\n";
+#endif /* ----------------------------------- */
+#if defined(WIN32) || defined(MSDOS)
+ char exename[FILENAME_MAX];
+ char *p;
+
+ argv0 = strcpy(exename, basname(argv0));
+ for (p = argv0; *p != '\0'; p++) *p = tolower(*p);
+#endif
+ xxprintf(str_usage, argv0, argv0, errlogfile);
+
+ exit(status);
+}
+
+
+/* -----------------------------------------------------------------------
+*/
+
+#if (PNG_LIBPNG_VER >= 10007)
+/*
+** dummy - see png_reset_zstream() in png.c
+*/
+int inflateReset(z_streamp z)
+{
+ return Z_OK;
+}
+#endif
diff --git a/crawl-ref/source/rltiles/bmp2png/bmp2png.dsp b/crawl-ref/source/rltiles/bmp2png/bmp2png.dsp
new file mode 100644
index 0000000000..e38022696e
--- /dev/null
+++ b/crawl-ref/source/rltiles/bmp2png/bmp2png.dsp
@@ -0,0 +1,112 @@
+# Microsoft Developer Studio Project File - Name="bmp2png" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** 編集しないでください **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=bmp2png - Win32 Release
+!MESSAGE これは有効なメイクファイルではありません。 このプロジェクトをビルドするためには NMAKE を使用してください。
+!MESSAGE [メイクファイルのエクスポート] コマンドを使用して実行してください
+!MESSAGE
+!MESSAGE NMAKE /f "bmp2png.mak".
+!MESSAGE
+!MESSAGE NMAKE の実行時に構成を指定できます
+!MESSAGE コマンド ライン上でマクロの設定を定義します。例:
+!MESSAGE
+!MESSAGE NMAKE /f "bmp2png.mak" CFG="bmp2png - Win32 Release"
+!MESSAGE
+!MESSAGE 選択可能なビルド モード:
+!MESSAGE
+!MESSAGE "bmp2png - Win32 Release" ("Win32 (x86) Console Application" 用)
+!MESSAGE "bmp2png - Win32 Debug" ("Win32 (x86) Console Application" 用)
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "bmp2png - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "PNG_USER_CONFIG" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /O2 /I "..\libpng" /I "..\zlib" /D "NDEBUG" /D "PNG_USER_CONFIG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /GF /c
+# ADD BASE RSC /l 0x411 /d "NDEBUG"
+# ADD RSC /l 0x411 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 setargv.obj libpng.lib zlib.lib /nologo /subsystem:console /map /machine:I386 /libpath:"..\libpng\release" /libpath:"..\zlib\release" /opt:nowin98
+# SUBTRACT LINK32 /pdb:none
+
+!ELSEIF "$(CFG)" == "bmp2png - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "PNG_USER_CONFIG" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /I "..\libpng" /I "..\zlib" /D "_DEBUG" /D "PNG_USER_CONFIG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /Fr /YX /FD /GZ /c
+# ADD BASE RSC /l 0x411 /d "_DEBUG"
+# ADD RSC /l 0x411 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 setargv.obj libpng.lib zlib.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\libpng\debug" /libpath:"..\zlib\debug"
+# SUBTRACT LINK32 /map
+
+!ENDIF
+
+# Begin Target
+
+# Name "bmp2png - Win32 Release"
+# Name "bmp2png - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\bmp2png.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\common.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\bmphed.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\common.h
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/crawl-ref/source/rltiles/bmp2png/bmphed.h b/crawl-ref/source/rltiles/bmp2png/bmphed.h
new file mode 100644
index 0000000000..4799b5e4d3
--- /dev/null
+++ b/crawl-ref/source/rltiles/bmp2png/bmphed.h
@@ -0,0 +1,84 @@
+/*
+** bmphed.h - .bmp file header macros
+**
+** Public domain by MIYASAKA Masaru (July 13, 2004)
+*/
+
+#ifndef BMPHED_H
+#define BMPHED_H
+
+ /* BMP file signature */
+#define BMP_SIGNATURE 0x4D42
+#define BMP_SIG_BYTES 2
+
+ /* BITMAPFILEHEADER */
+#define BFH_WTYPE 0 /* WORD bfType; */
+#define BFH_DSIZE 2 /* DWORD bfSize; */
+#define BFH_WRESERVED1 6 /* WORD bfReserved1; */
+#define BFH_WRESERVED2 8 /* WORD bfReserved2; */
+#define BFH_DOFFBITS 10 /* DWORD bfOffBits; */
+#define BFH_DBIHSIZE 14 /* DWORD biSize; */
+#define FILEHED_SIZE 14 /* sizeof(BITMAPFILEHEADER) */
+#define BIHSIZE_SIZE 4 /* sizeof(biSize) */
+
+ /* BITMAPINFOHEADER, BITMAPV4HEADER, BITMAPV5HEADER */
+#define BIH_DSIZE 0 /* DWORD biSize; */
+#define BIH_LWIDTH 4 /* LONG biWidth; */
+#define BIH_LHEIGHT 8 /* LONG biHeight; */
+#define BIH_WPLANES 12 /* WORD biPlanes; */
+#define BIH_WBITCOUNT 14 /* WORD biBitCount; */
+#define BIH_DCOMPRESSION 16 /* DWORD biCompression; */
+#define BIH_DSIZEIMAGE 20 /* DWORD biSizeImage; */
+#define BIH_LXPELSPERMETER 24 /* LONG biXPelsPerMeter; */
+#define BIH_LYPELSPERMETER 28 /* LONG biYPelsPerMeter; */
+#define BIH_DCLRUSED 32 /* DWORD biClrUsed; */
+#define BIH_DCLRIMPORANT 36 /* DWORD biClrImportant; */
+#define B4H_DREDMASK 40 /* DWORD bV4RedMask; */
+#define B4H_DGREENMASK 44 /* DWORD bV4GreenMask; */
+#define B4H_DBLUEMASK 48 /* DWORD bV4BlueMask; */
+#define B4H_DALPHAMASK 52 /* DWORD bV4AlphaMask; */
+#define B4H_DCSTYPE 56 /* DWORD bV4CSType; */
+#define B4H_XENDPOINTS 60 /* CIEXYZTRIPLE bV4Endpoints; */
+#define B4H_DGAMMARED 96 /* DWORD bV4GammaRed; */
+#define B4H_DGAMMAGREEN 100 /* DWORD bV4GammaGreen; */
+#define B4H_DGAMMABLUE 104 /* DWORD bV4GammaBlue; */
+#define B5H_DINTENT 108 /* DWORD bV5Intent; */
+#define B5H_DPROFILEDATA 112 /* DWORD bV5ProfileData; */
+#define B5H_DPROFILESIZE 116 /* DWORD bV5ProfileSize; */
+#define B5H_DRESERVED 120 /* DWORD bV5Reserved; */
+#define INFOHED_SIZE 40 /* sizeof(BITMAPINFOHEADER) */
+#define BMPV4HED_SIZE 108 /* sizeof(BITMAPV4HEADER) */
+#define BMPV5HED_SIZE 124 /* sizeof(BITMAPV5HEADER) */
+
+ /* BITMAPCOREHEADER */
+#define BCH_DSIZE 0 /* DWORD bcSize; */
+#define BCH_WWIDTH 4 /* WORD bcWidth; */
+#define BCH_WHEIGHT 6 /* WORD bcHeight; */
+#define BCH_WPLANES 8 /* WORD bcPlanes; */
+#define BCH_WBITCOUNT 10 /* WORD bcBitCount; */
+#define COREHED_SIZE 12 /* sizeof(BITMAPCOREHEADER) */
+
+ /* RGBQUAD */
+#define RGBQ_BLUE 0 /* BYTE rgbBlue; */
+#define RGBQ_GREEN 1 /* BYTE rgbGreen; */
+#define RGBQ_RED 2 /* BYTE rgbRed; */
+#define RGBQ_RESERVED 3 /* BYTE rgbReserved; */
+#define RGBQUAD_SIZE 4 /* sizeof(RGBQUAD) */
+
+ /* RGBTRIPLE */
+#define RGBT_BLUE 0 /* BYTE rgbtBlue; */
+#define RGBT_GREEN 1 /* BYTE rgbtGreen; */
+#define RGBT_RED 2 /* BYTE rgbtRed; */
+#define RGBTRIPLE_SIZE 3 /* sizeof(RGBTRIPLE) */
+
+ /* Constants for the biCompression field */
+#ifndef BI_RGB
+#define BI_RGB 0L /* Uncompressed */
+#define BI_RLE8 1L /* RLE (8 bits/pixel) */
+#define BI_RLE4 2L /* RLE (4 bits/pixel) */
+#define BI_BITFIELDS 3L /* Bitfield */
+#define BI_JPEG 4L /* JPEG Extension */
+#define BI_PNG 5L /* PNG Extension */
+#endif
+
+#endif /* BMPHED_H */
diff --git a/crawl-ref/source/rltiles/bmp2png/common.c b/crawl-ref/source/rltiles/bmp2png/common.c
new file mode 100644
index 0000000000..2d6042ae85
--- /dev/null
+++ b/crawl-ref/source/rltiles/bmp2png/common.c
@@ -0,0 +1,748 @@
+/*
+** bmp2png --- conversion from (Windows or OS/2 style) BMP to PNG
+** png2bmp --- conversion from PNG to (Windows style) BMP
+**
+** Copyright (C) 1999-2005 MIYASAKA Masaru
+**
+** For conditions of distribution and use,
+** see copyright notice in common.h.
+*/
+
+#include "common.h"
+
+#if defined(__DJGPP__) /* DJGPP V.2 */
+#include <crt0.h>
+int _crt0_startup_flags = _CRT0_FLAG_DISALLOW_RESPONSE_FILES;
+unsigned short _djstat_flags = /* for stat() */
+ _STAT_INODE | _STAT_EXEC_EXT | _STAT_EXEC_MAGIC | _STAT_DIRSIZE |
+ _STAT_ROOT_TIME;
+#endif
+
+#if defined(__BORLANDC__) /* Borland C++ */
+#include <wildargs.h>
+typedef void _RTLENTRY (* _RTLENTRY _argv_expand_fnc)(char *, _PFN_ADDARG);
+typedef void _RTLENTRY (* _RTLENTRY _wargv_expand_fnc)(wchar_t *, _PFN_ADDARG);
+_argv_expand_fnc _argv_expand_ptr = _expand_wild; /* expand wild cards */
+_wargv_expand_fnc _wargv_expand_ptr = _wexpand_wild;
+#endif
+
+
+/* -----------------------------------------------------------------------
+** screen management
+*/
+
+#define LINE_LEN 79
+#define STATUS_LEN 22
+#define PROGBAR_MAX (LINE_LEN - STATUS_LEN - 1)
+
+static char status_msg[128];
+static int progbar_scale = 0;
+static int progbar_len = 0;
+static int progbar_pos = -1;
+
+int quietmode = 0; /* -Q option */
+int errorlog = 0; /* -L option */
+
+
+static void print_status(void)
+{
+ if (quietmode) return;
+
+ fprintf(stderr, "\r%-*.*s ", STATUS_LEN, STATUS_LEN, status_msg);
+ fflush(stderr);
+ progbar_pos = 0;
+}
+
+static void put_dots(int dotchar, int num)
+{
+ int i;
+
+ if (num > PROGBAR_MAX) num = PROGBAR_MAX;
+ if (progbar_pos == -1) print_status();
+
+ for (i = progbar_pos; i < num; i++)
+ fputc(dotchar, stderr);
+
+ if (progbar_pos < num) {
+ progbar_pos = num;
+ fflush(stderr);
+ }
+}
+
+static void print_scale(void)
+{
+ if (progbar_pos != 0) print_status();
+ put_dots('.', progbar_len);
+ print_status();
+ progbar_scale = 1;
+}
+
+static void init_progress_bar(int max)
+{
+ if (quietmode) return;
+
+ progbar_len = max;
+ print_scale();
+}
+
+static void update_progress_bar(int num)
+{
+ if (quietmode) return;
+
+ if (!progbar_scale) print_scale();
+ put_dots('o', num);
+}
+
+static void clear_line(void)
+{
+ if (quietmode) return;
+
+ fprintf(stderr, "\r%*c\r", LINE_LEN, ' ');
+ progbar_scale = 0;
+ progbar_pos = -1;
+}
+
+void xxprintf(const char *fmt, ...)
+{
+ va_list ap;
+ FILE *f;
+
+ if (quietmode) return;
+
+ va_start(ap, fmt);
+
+ clear_line();
+ vfprintf(stderr, fmt, ap);
+ fflush(stderr);
+
+ if (errorlog && (f = fopen(errlogfile, "a")) != NULL) {
+ vfprintf(f, fmt, ap);
+ fclose(f);
+ }
+
+ va_end(ap);
+}
+
+void set_status(const char *fmt, ...)
+{
+ va_list ap;
+
+ if (quietmode) return;
+
+ va_start(ap, fmt);
+ vsprintf(status_msg, fmt, ap);
+ va_end(ap);
+
+ print_status();
+}
+
+void feed_line(void)
+{
+ if (quietmode) return;
+
+ fputc('\n', stderr);
+ fflush(stderr);
+ progbar_scale = 0;
+ progbar_pos = -1;
+}
+
+
+/* -----------------------------------------------------------------------
+** libpng progress meter
+*/
+
+/*
+ * -------------------------------------------------------------
+ *
+ * PNG のインターレス形式 "Adam7" の画像パラメータ:
+ *
+ * パス 幅 高さ 開始点 面積比 進行状況
+ * pass width height origin area progress
+ * 0 1/8 1/8 (0,0) 1/64 1/64 ( 1.6%)
+ * 1 1/8 1/8 (4,0) 1/64 1/32 ( 3.1%)
+ * 2 1/4 1/8 (0,4) 1/32 1/16 ( 6.3%)
+ * 3 1/4 1/4 (2,0) 1/16 1/8 ( 12.5%)
+ * 4 1/2 1/4 (0,2) 1/8 1/4 ( 25.0%)
+ * 5 1/2 1/2 (1,0) 1/4 1/2 ( 50.0%)
+ * 6 1 1/2 (0,1) 1/2 1/1 (100.0%)
+ *
+ * Adam7 の時の進行状況算出法:
+ *
+ * (width / 8) * 1 のピクセルグループを1ブロックと考え、
+ * このブロックを通算でいくつ出力したかで進行状況を算出する。
+ * 例えば pass 0 の時は、横幅が元の画像の 1/8 なので、
+ * コールバック関数が呼ばれる(一行出力する)ごとに1ブロックを
+ * 出力したことになり、pass 4 の時は(同様に考えて)4ブロックを
+ * 出力したことになる。
+ * この計算方法によると、特定のパスが存在しなくなるような
+ * 極端に小さい画像でない限り(下の maxcount_adam7() を参照)、
+ * 画像全体の総ブロック数は (height * 8) に等しくなる。
+ *
+ * 実際にこの方式で進行状況を表示してみると、前半部分(pass0-5)
+ * よりも後半部分(pass6)が速く進行するように見える。これは、
+ * Adam7 の特徴としてピクセルが縦横双方向に間引かれて分解
+ * されており、特に横方向に間引かれている pass0-5 (前半部分)
+ * では画像の再構成に時間がかかっているものと思われる。
+ *
+ * -------------------------------------------------------------
+ */
+
+static png_uint_32 counter;
+static png_uint_32 maxcount;
+static int barlen;
+
+
+static png_uint_32
+ maxcount_adam7(png_uint_32 width, png_uint_32 height)
+{
+ png_uint_32 c = 0;
+
+ if ( 1 ) c += ((height - 0 + 7) / 8) * 1; /* Pass 0 */
+ if (width > 4) c += ((height - 0 + 7) / 8) * 1; /* Pass 1 */
+ if ( 1 ) c += ((height - 4 + 7) / 8) * 2; /* Pass 2 */
+ if (width > 2) c += ((height - 0 + 3) / 4) * 2; /* Pass 3 */
+ if ( 1 ) c += ((height - 2 + 3) / 4) * 4; /* Pass 4 */
+ if (width > 1) c += ((height - 0 + 1) / 2) * 4; /* Pass 5 */
+ if ( 1 ) c += ((height - 1 + 1) / 2) * 8; /* Pass 6 */
+
+ return c;
+}
+
+
+/*
+** initialize the progress meter
+*/
+void init_progress_meter(png_structp png_ptr, png_uint_32 width,
+ png_uint_32 height)
+{
+ enum { W = 1024, H = 768 };
+
+ if (png_set_interlace_handling(png_ptr) == 7) {
+ maxcount = maxcount_adam7(width, height); /* interlaced image */
+ } else {
+ maxcount = height; /* non-interlaced image */
+ }
+ if (height > ((png_uint_32)W * H) / width) {
+ barlen = PROGBAR_MAX;
+ } else {
+ barlen = (PROGBAR_MAX * width * height + (W * H - 1)) / (W * H);
+ }
+ counter = 0;
+ init_progress_bar(barlen);
+}
+
+
+/*
+** row callback function for progress meter
+*/
+void row_callback(png_structp png_ptr, png_uint_32 row, int pass)
+{
+/* static const png_byte step[] = { 1, 1, 2, 2, 4, 4, 8 }; */
+
+ if (row == 0) pass--;
+ /*
+ * libpng's bug ?? : In the case of interlaced image,
+ * this function is called with row=0 and pass=current_pass+1
+ * when the row should be equal to height and the pass should
+ * be equal to current_pass.
+ */
+
+ counter += (1 << (pass >> 1)); /* step[pass]; */
+ update_progress_bar(barlen * counter / maxcount);
+}
+
+
+/* -----------------------------------------------------------------------
+** libpng error handling
+*/
+
+/*
+** fatal error handling function
+*/
+void png_my_error(png_structp png_ptr, png_const_charp message)
+{
+ xxprintf("ERROR(libpng): %s - %s\n", message,
+ (char *)png_get_error_ptr(png_ptr));
+ longjmp(png_jmpbuf(png_ptr), 1);
+}
+
+
+/*
+** non-fatal error handling function
+*/
+void png_my_warning(png_structp png_ptr, png_const_charp message)
+{
+ xxprintf("WARNING(libpng): %s - %s\n", message,
+ (char *)png_get_error_ptr(png_ptr));
+}
+
+
+/* -----------------------------------------------------------------------
+** image buffer management
+*/
+
+/*
+** allocate image buffer
+*/
+BOOL imgbuf_alloc(IMAGE *img)
+{
+ BYTE *bp, **rp;
+ LONG n;
+
+ if (img->palnum > 0) {
+ img->palette = malloc((size_t)img->palnum * sizeof(PALETTE));
+ if (img->palette == NULL) { imgbuf_init(img); return FALSE; }
+ } else {
+ img->palette = NULL;
+ }
+ img->rowbytes = ((DWORD)img->width * img->pixdepth + 31) / 32 * 4;
+ img->imgbytes = img->rowbytes * img->height;
+ img->rowptr = malloc((size_t)img->height * sizeof(BYTE *));
+ img->bmpbits = malloc((size_t)img->imgbytes);
+
+ if (img->rowptr == NULL || img->bmpbits == NULL) {
+ imgbuf_free(img); imgbuf_init(img); return FALSE;
+ }
+
+ n = img->height;
+ rp = img->rowptr;
+ bp = img->bmpbits;
+
+ if (img->topdown) {
+ while (--n >= 0) {
+ *(rp++) = bp;
+ bp += img->rowbytes;
+ /* ((DWORD *)bp)[-1] = 0; */
+ }
+ } else { /* bottom-up */
+ bp += img->imgbytes;
+ while (--n >= 0) {
+ /* fill zeros to padding bytes (for write_bmp()) */
+ ((DWORD *)bp)[-1] = 0;
+ bp -= img->rowbytes;
+ *(rp++) = bp;
+ }
+ }
+
+ return TRUE;
+}
+
+
+/*
+** free image buffer allocated by imgbuf_alloc()
+*/
+void imgbuf_free(IMAGE *img)
+{
+ free(img->palette);
+ free(img->rowptr);
+ free(img->bmpbits);
+}
+
+
+/*
+** init image buffer to empty
+*/
+void imgbuf_init(IMAGE *img)
+{
+ img->palette = NULL;
+ img->rowptr = NULL;
+ img->bmpbits = NULL;
+}
+
+
+/* -----------------------------------------------------------------------
+** コマンドライン引数の処理
+*/
+
+#define isoption(p) (IsOptChar((p)[0]) && (p)[1]!='\0')
+
+/*
+** コマンドライン引数を読む
+*/
+int parsearg(int *opt, char **arg, int argc, char **argv, char *aopts)
+{
+ static int agi = 1;
+ static char *agp = NULL;
+ char *p;
+ int c, i;
+
+ if (agp != NULL && *agp == '\0') {
+ agp = NULL;
+ agi++;
+ }
+ if (agi >= argc) return 0; /* end */
+
+ if (p = argv[agi], agp == NULL && !isoption(p)) {
+ /* non-option element */
+ c = 0;
+ agi++;
+ } else {
+ if (agp == NULL) agp = p + 1;
+ if (c = (*agp & 0xFF), strchr(aopts, c) != NULL) {
+ /* option with an argument */
+ if (p = agp + 1, *p != '\0') {
+ /*NULL*/;
+ } else if (i = agi + 1, p = argv[i], i < argc && !isoption(p)) {
+ agi = i;
+ } else {
+ p = NULL;
+ }
+ agp = NULL;
+ agi++;
+ } else {
+ /* option without an argument */
+ p = NULL;
+ agp++;
+ }
+ }
+ *opt = c;
+ *arg = p;
+
+ return 1;
+}
+
+
+/*
+** 環境変数で指定されているオプションを argc, argv に併合する
+*/
+char **envargv(int *argcp, char ***argvp, const char *envn)
+{
+ int argc, nagc, envc, i;
+ char **argv, **nagv, *envs, *ep;
+
+ ep = getenv(envn);
+ if (ep == NULL || ep[0] == '\0') return NULL;
+
+ envs = malloc(strlen(ep) + 1);
+ if (envs == NULL) return NULL;
+ strcpy(envs, ep);
+
+ envc = tokenize(envs, envs);
+ if (envc == 0) { free(envs); return NULL; }
+
+ argc = *argcp;
+ argv = *argvp;
+ nagv = malloc((argc + envc + 1) * sizeof(char *));
+ if (nagv == NULL) { free(envs); return NULL; }
+
+ nagc = 1;
+ nagv[0] = argv[0];
+
+ for (i = 0; i < envc; i++) {
+ nagv[nagc++] = envs;
+ while (*(envs++) != '\0') ;
+ }
+ for (i = 1; i < argc; i++) {
+ nagv[nagc++] = argv[i];
+ }
+ nagv[nagc] = NULL;
+
+ *argcp = nagc;
+ *argvp = nagv;
+
+ return argv;
+}
+
+
+/*
+** 文字列を空白文字(スペース/水平タブ/改行)の所で区切る(クオート処理付き)
+** 区切られた部分文字列の数を返す
+*/
+int tokenize(char *buf, const char *str)
+{
+ enum { STR = 0x01, QUOTE = 0x02 };
+ int flag = 0;
+ int num = 0;
+ char c;
+ int i;
+
+ while ((c = *str++) != '\0') {
+ if (!(flag & QUOTE) &&
+ (c == ' ' || c == '\t' || c == '\n' || c == '\r')) {
+ if (flag & STR) {
+ flag &= ~STR;
+ *buf++ = '\0';
+ }
+ } else {
+ if (!(flag & STR)) {
+ flag |= STR;
+ num++;
+ }
+ switch (c) {
+ case '\\':
+ /*
+ * Escaping of `"' is the same as
+ * command-line parsing of MS-VC++.
+ *
+ * ex.) " -> quote
+ * \" -> "
+ * \\" -> \ + quote
+ * \\\" -> \ + "
+ * \\\\" -> \\ + quote
+ * \\\\\ -> \\\\\
+ */
+ for (i = 1; (c = *str) == '\\'; str++, i++) ;
+ if (c == '"') {
+ while ((i -= 2) >= 0)
+ *buf++ = '\\';
+ if (i == -1) {
+ *buf++ = '"';
+ str++;
+ }
+ } else {
+ while ((--i) >= 0)
+ *buf++ = '\\';
+ }
+ break;
+
+ case '"':
+ flag ^= QUOTE;
+ break;
+
+ default:
+ *buf++ = c;
+ }
+ }
+ }
+ if (flag & STR) *buf = '\0';
+
+ return num;
+}
+
+
+/* -----------------------------------------------------------------------
+** ファイルに関する雑用処理
+*/
+
+/*
+** 複数階層のディレクトリを一度に作成する
+*/
+int makedir(const char *path)
+{
+ char dir[FILENAME_MAX];
+ struct stat sbuf;
+ char *p, c;
+ int r;
+
+ delslash(strcpy(dir, path));
+ if (stat(dir, &sbuf) == 0) {
+ if ((sbuf.st_mode & S_IFMT) == S_IFDIR) return 0;
+ /* errno = EEXIST; */
+ return -1;
+ }
+ p = path_skiproot(dir);
+ do {
+ p = path_nextslash(p);
+ c = *p; *p = '\0';
+ r = MKDIR(dir, 0777);
+ *p++ = c;
+ } while (c != '\0');
+
+ return r;
+}
+
+
+/*
+** 既存の同名ファイルをバックアップ(リネーム)する
+*/
+int renbak(const char *path)
+{
+ char bak[FILENAME_MAX];
+ struct stat sbuf;
+ char *sfx;
+ int i;
+
+ strcpy(bak, path);
+ if (stat(bak, &sbuf) != 0) return 0;
+
+#ifdef MSDOS
+ sfx = suffix(bak);
+#else
+ sfx = bak + strlen(bak);
+#endif
+ strcpy(sfx, ".bak");
+ i = 0;
+ while (1) {
+ if (stat(bak, &sbuf) != 0 && rename(path, bak) == 0) return 0;
+ if (i >= 1000) break;
+ sprintf(sfx, ".%03d", i++);
+ }
+ return -1;
+}
+
+
+/*
+** ファイルのタイムスタンプをコピーする
+*/
+int cpyftime(const char *srcf, const char *dstf)
+{
+ struct stat sbuf;
+ struct utimbuf ubuf;
+
+ if (stat(srcf, &sbuf) != 0) return -1;
+
+ ubuf.actime = sbuf.st_atime;
+ ubuf.modtime = sbuf.st_mtime;
+
+ return utime(dstf, &ubuf);
+}
+
+
+/*
+** バイナリモードの標準入出力ストリームを取得する
+*/
+FILE *binary_stdio(int fd)
+{
+ FILE *fp;
+
+ if (fd != 0 && fd != 1) return NULL;
+
+#ifdef BINSTDIO_FDOPEN
+ fp = fdopen(fd, (fd==0)? "rb":"wb");
+#else
+#ifdef BINSTDIO_SETMODE
+ setmode(fd, O_BINARY);
+#endif
+ fp = (fd == 0) ? stdin : stdout;
+#endif
+ return fp;
+}
+
+
+/* -----------------------------------------------------------------------
+** path functions
+*/
+
+/*
+** Return a pointer that points the suffix of the PATH
+** ex.) c:\dosuty\log\test.exe -> .exe
+** ex.) c:\dosuty\log\test.tar.gz -> .gz
+*/
+char *suffix(const char *path)
+{
+ char c, *p, *q, *r;
+
+ for (r = q = p = basname(path); (c = *p) != '\0'; p++)
+ if (c == '.') q = p;
+ if (q == r) q = p; /* dotfile with no suffix */
+
+ return q;
+}
+
+
+/*
+** Return a pointer that points the basename of the PATH
+** ex.) c:\dos\format.exe -> format.exe
+*/
+char *basname(const char *path)
+{
+ const char *p, *q;
+
+ for (p = path_skiproot(path);
+ *(q = path_nextslash(p)) != '\0'; p = q + 1) ;
+
+ return (char *)p;
+}
+
+
+/*
+** Append a path-delimiter to the PATH. If the PATH is a string
+** like "c:\", "\", "c:", "", do nothing.
+** ex.) c:\dos -> c:\dos\
+*/
+char *addslash(char *path)
+{
+ char *p, *q;
+
+ for (p = path_skiproot(path);
+ *(q = path_nextslash(p)) != '\0'; p = q + 1) ;
+ /*
+ * s = path_skiproot( path );
+ * if( q==s && q==p ) - s is a mull string.
+ * if( q!=s && q==p ) - s is followed by a path delimiter.
+ * if( q!=s && q!=p ) - s is not followed by a path delimiter.
+ */
+ if (q != p) {
+ *q++ = PATHDELIM;
+ *q = '\0';
+ }
+
+ return path;
+}
+
+
+/*
+** Remove a path-delimiter at the end of the PATH. If the PATH is
+** a string like "c:\", "\", "c:", "", append a dot.
+** ex.) c:\dos\ -> c:\dos
+** c:\ -> c:\.
+*/
+char *delslash(char *path)
+{
+ char *p, *q, *s;
+
+ for (p = s = path_skiproot(path);
+ *(q = path_nextslash(p)) != '\0'; p = q + 1) ;
+ /*
+ * if( q==s && q==p ) - s is a mull string.
+ * if( q!=s && q==p ) - s is followed by a path delimiter.
+ * if( q!=s && q!=p ) - s is not followed by a path delimiter.
+ */
+ if (q == s) {
+ *q++ = '.';
+ *q = '\0';
+ } else if (q == p) {
+ *--q = '\0';
+ }
+
+ return path;
+}
+
+
+char *path_skiproot(const char *path)
+{
+#ifdef DRIVESUFFIX
+ if (isalpha((unsigned char)path[0])
+ && path[1] == DRIVESUFFIX) path += 2;
+#endif
+ if (IsPathDelim(path[0])) path++;
+ return (char *)path;
+}
+
+
+char *path_nextslash(const char *path)
+{
+ char c;
+
+ for (; (c = *path) != '\0'; path++) {
+ if (IsDBCSLead((unsigned char)c)) {
+ if (*(++path) == '\0') break;
+ continue;
+ }
+ if (IsPathDelim(c)) break;
+ }
+ return (char *)path;
+}
+
+#ifdef WIN32_LFN
+
+/*
+** return TRUE if the PATH is a dos-style filename.
+*/
+int is_dos_filename(const char *path)
+{
+ unsigned char c;
+ char *b, *p;
+
+ for (b = p = basname(path); (c = *p) != '\0' && c != '.'; p++)
+ if (islower(c)) return 0;
+ if ((p - b) == 0 || (p - b) > 8) return 0;
+ if (c == '.') {
+ for (b = ++p; (c = *p) != '\0'; p++)
+ if (islower(c) || c == '.') return 0;
+ if ((p - b) == 0 || (p - b) > 3) return 0;
+ }
+ return 1;
+}
+
+#endif /* WIN32_LFN */
diff --git a/crawl-ref/source/rltiles/bmp2png/common.h b/crawl-ref/source/rltiles/bmp2png/common.h
new file mode 100644
index 0000000000..ad5a341e92
--- /dev/null
+++ b/crawl-ref/source/rltiles/bmp2png/common.h
@@ -0,0 +1,196 @@
+/*
+** bmp2png --- conversion from (Windows or OS/2 style) BMP to PNG
+** png2bmp --- conversion from PNG to (Windows style) BMP
+**
+** Copyright (C) 1999-2005 MIYASAKA Masaru <alkaid@coral.ocn.ne.jp>
+**
+** Permission to use, copy, modify, and distribute this software and
+** its documentation for any purpose and without fee is hereby granted,
+** provided that the above copyright notice appear in all copies and
+** that both that copyright notice and this permission notice appear
+** in supporting documentation. This software is provided "as is"
+** without express or implied warranty.
+**
+** NOTE: Comments are partly written in Japanese. Sorry.
+*/
+
+#ifndef COMMON_H
+#define COMMON_H
+
+#if defined(__RSXNT__) && defined(__CRTRSXNT__)
+# include <crtrsxnt.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdarg.h>
+
+ /* for stat() */
+#include <sys/types.h>
+#include <sys/stat.h>
+
+ /* for utime() */
+#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__LCC__)
+# include <sys/utime.h>
+# if defined(__LCC__)
+ int utime(const char *, struct _utimbuf *);
+# endif
+#else
+# include <utime.h>
+#endif
+ /* for isatty() */
+#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__) || \
+ defined(__LCC__)
+# include <io.h>
+#else
+# include <unistd.h>
+#endif
+ /* for mkdir() */
+#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__) || \
+ defined(__LCC__)
+# include <direct.h>
+# if defined(__MINGW32__)
+# define MKDIR(d,m) _mkdir(d)
+# else
+# define MKDIR(d,m) mkdir(d)
+# endif
+#else
+# if defined(__GO32__) && !defined(__DJGPP__) /* DJGPP v.1 */
+# include <osfcn.h>
+# else
+# include <sys/stat.h>
+# endif
+# define MKDIR(d,m) mkdir(d,m)
+#endif
+
+#if !defined(BINSTDIO_FDOPEN) && !defined(BINSTDIO_SETMODE)
+# if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__EMX__) || \
+ defined(_MSC_VER) || defined(__BORLANDC__) || defined(__LCC__) || \
+ defined(__DJGPP__) || defined(__GO32__)
+# define BINSTDIO_SETMODE
+# endif
+# if 0 /* defined(__YOUR_COMPLIER_MACRO__) */
+# define BINSTDIO_FDOPEN
+# endif
+#endif
+ /* for setmode() */
+#ifdef BINSTDIO_SETMODE
+# include <io.h>
+# include <fcntl.h>
+#endif
+
+#include "png.h"
+
+#if (PNG_LIBPNG_VER < 10004)
+# error libpng version 1.0.4 or later is required.
+#endif
+
+#if (PNG_LIBPNG_VER == 10207) || (PNG_LIBPNG_VER == 10206) || \
+ (PNG_LIBPNG_VER == 10017) || (PNG_LIBPNG_VER == 10016)
+# error Libpng versions 1.2.7, 1.2.6, 1.0.17, and 1.0.16
+# error have a bug that will cause png2bmp to crash.
+# error Update your libpng to latest version.
+# error "http://www.libpng.org/pub/png/libpng.html"
+#endif
+
+#if !defined(PNG_READ_tRNS_SUPPORTED) || !defined(PNG_WRITE_tRNS_SUPPORTED)
+# error This software requires tRNS chunk support.
+#endif
+
+#ifndef png_jmpbuf /* pngconf.h (libpng 1.0.6 or later) */
+# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
+#endif
+
+#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
+# define WIN32
+#endif
+#if defined(__MSDOS__) && !defined(MSDOS)
+# define MSDOS
+#endif
+#if defined(__CYGWIN__)
+# undef WIN32
+# undef MSDOS
+#endif
+
+#if defined(WIN32) || defined(__DJGPP__)
+# define WIN32_LFN /* Win32-style long filename */
+#endif
+
+#if defined(WIN32) || defined(MSDOS)
+# define PATHDELIM '\\'
+# define DRIVESUFFIX ':'
+# define IsPathDelim(c) ((c)==PATHDELIM || (c)=='/')
+# define IsOptChar(c) ((c)=='-' || (c)=='/')
+# ifdef JAPANESE
+# define IsDBCSLead(c) ((0x81<=(c) && (c)<=0x9F) || (0xE0<=(c) && (c)<=0xFC))
+# else
+# define IsDBCSLead(c) (0)
+# endif
+#else /* UNIX */
+# define PATHDELIM '/'
+# define IsPathDelim(c) ((c)==PATHDELIM)
+# define IsOptChar(c) ((c)=='-')
+# define IsDBCSLead(c) (0)
+#endif
+
+typedef char CHAR;
+typedef unsigned char BYTE;
+typedef short SHORT;
+typedef unsigned short WORD;
+typedef int INT;
+typedef unsigned int UINT;
+typedef long LONG;
+typedef unsigned long DWORD;
+typedef enum { FALSE = 0, TRUE = 1 } BOOL;
+
+typedef png_color PALETTE;
+typedef struct tagIMAGE {
+ LONG width;
+ LONG height;
+ UINT pixdepth;
+ UINT palnum;
+ BOOL topdown;
+ BOOL alpha;
+ /* ----------- */
+ DWORD rowbytes;
+ DWORD imgbytes;
+ PALETTE *palette;
+ BYTE **rowptr;
+ BYTE *bmpbits;
+ /* ----------- */
+ png_color_8 sigbit;
+} IMAGE;
+
+extern int quietmode;
+extern int errorlog;
+extern const char errlogfile[];
+
+void xxprintf(const char *, ...);
+void set_status(const char *, ...);
+void feed_line(void);
+void init_progress_meter(png_structp, png_uint_32, png_uint_32);
+void row_callback(png_structp, png_uint_32, int);
+void png_my_error(png_structp, png_const_charp);
+void png_my_warning(png_structp, png_const_charp);
+BOOL imgbuf_alloc(IMAGE *);
+void imgbuf_free(IMAGE *);
+void imgbuf_init(IMAGE *);
+int parsearg(int *, char **, int, char **, char *);
+char **envargv(int *, char ***, const char *);
+int tokenize(char *, const char *);
+int makedir(const char *);
+int renbak(const char *);
+int cpyftime(const char *, const char *);
+FILE *binary_stdio(int);
+char *suffix(const char *);
+char *basname(const char *);
+char *addslash(char *);
+char *delslash(char *);
+char *path_skiproot(const char *);
+char *path_nextslash(const char *);
+#ifdef WIN32_LFN
+int is_dos_filename(const char *);
+#endif
+
+#endif /* COMMON_H */
diff --git a/crawl-ref/source/rltiles/bmp2png/makefile.bcc b/crawl-ref/source/rltiles/bmp2png/makefile.bcc
new file mode 100644
index 0000000000..b90f278fb0
--- /dev/null
+++ b/crawl-ref/source/rltiles/bmp2png/makefile.bcc
@@ -0,0 +1,52 @@
+#--------------------------------
+# bmp2png.exe & png2bmp.exe
+# makefile for Borland C++ 5.5
+#--------------------------------
+
+!ifndef srcdir
+srcdir = .
+!endif
+.path.c = $(srcdir)
+.path.h = $(srcdir)
+
+ZINC = $(srcdir)/../zlib
+PINC = $(srcdir)/../libpng
+ZLIB = $(srcdir)/../zlib
+PLIB = $(srcdir)/../libpng
+
+CC = bcc32
+LD = bcc32
+CFLAGS = $(MODEL) -q -d -O2 -OS -Oi -Oc -DPNG_USER_CONFIG -I$(PINC) \
+ -I$(ZINC) $(COPT)
+LDFLAGS = $(MODEL) -q -WC -L$(PLIB) -L$(ZLIB) $(LOPT)
+
+LIBS = libpng.lib zlib.lib noeh32.lib
+B2POBJ = bmp2png.obj common.obj
+P2BOBJ = png2bmp.obj common.obj
+
+
+all : bmp2png.exe png2bmp.exe
+
+bmp2png.exe : $(B2POBJ)
+ $(LD) $(LDFLAGS) -e$@ $(B2POBJ) $(LIBS)
+
+png2bmp.exe : $(P2BOBJ)
+ $(LD) $(LDFLAGS) -e$@ $(P2BOBJ) $(LIBS)
+
+.c.obj :
+ $(CC) $(CFLAGS) -c $*.c
+
+.c.asm :
+ $(CC) $(CFLAGS) -S $*.c
+
+clean : mostlyclean
+ if exist *.exe del *.exe
+
+mostlyclean :
+ if exist *.obj del *.obj
+ if exist *.tds del *.tds
+
+bmp2png.obj : bmp2png.c common.h bmphed.h
+png2bmp.obj : png2bmp.c common.h bmphed.h
+common.obj : common.c common.h
+
diff --git a/crawl-ref/source/rltiles/bmp2png/makefile.dj2 b/crawl-ref/source/rltiles/bmp2png/makefile.dj2
new file mode 100644
index 0000000000..c8f6b8aabf
--- /dev/null
+++ b/crawl-ref/source/rltiles/bmp2png/makefile.dj2
@@ -0,0 +1,54 @@
+#-----------------------------
+# bmp2png.exe & png2bmp.exe
+# makefile for DJGPP V.2
+#-----------------------------
+
+srcdir = .
+VPATH = $(srcdir)
+
+ZINC = $(srcdir)/../zlib
+PINC = $(srcdir)/../libpng
+ZLIB = $(srcdir)/../zlib
+PLIB = $(srcdir)/../libpng
+
+CC = gcc
+LD = gcc
+CFLAGS = -O2 -Wall -mcpu=pentium -march=i386 -DPNG_USER_CONFIG \
+ -I$(PINC) -I$(ZINC) $(COPT)
+LDFLAGS = -s -L$(PLIB) -L$(ZLIB) $(LOPT)
+
+LIBS = -lpng -lz -lm
+B2POBJ = bmp2png.o common.o
+P2BOBJ = png2bmp.o common.o
+B2PMAP = -Wl,-Map,bmp2png.map
+P2BMAP = -Wl,-Map,png2bmp.map
+
+
+all : bmp2png.exe png2bmp.exe
+
+bmp2png.exe : $(B2POBJ)
+ $(LD) $(LDFLAGS) $(B2PMAP) -o $@ $(B2POBJ) $(LIBS)
+
+png2bmp.exe : $(P2BOBJ)
+ $(LD) $(LDFLAGS) $(P2BMAP) -o $@ $(P2BOBJ) $(LIBS)
+
+%.o : %.c
+ $(CC) $(CFLAGS) -c $<
+
+%.s : %.c
+ $(CC) $(CFLAGS) -S -fverbose-asm $<
+
+%.lst : %.s
+ $(CC) -Wa,-a=$@ -c -o NUL $<
+
+clean : mostlyclean
+ if exist *.exe del *.exe
+ if exist *.map del *.map
+
+mostlyclean :
+ if exist *.o del *.o
+
+bmp2png.o : bmp2png.c common.h bmphed.h
+png2bmp.o : png2bmp.c common.h bmphed.h
+common.o : common.c common.h
+
diff --git a/crawl-ref/source/rltiles/bmp2png/makefile.lin b/crawl-ref/source/rltiles/bmp2png/makefile.lin
new file mode 100644
index 0000000000..85136685f4
--- /dev/null
+++ b/crawl-ref/source/rltiles/bmp2png/makefile.lin
@@ -0,0 +1,48 @@
+#-------------------------------------
+# bmp2png & png2bmp
+# makefile for gcc/gmake
+# Thanks to Gary Aviv for this file.
+#-------------------------------------
+
+ifndef BINDIR
+BINDIR = /usr/local/bin
+endif
+
+CC = gcc
+LD = gcc
+ifndef INSTALL
+INSTALL = install -s -m 755
+endif
+ifndef CFLAGS
+CFLAGS = -O2 -g -Wall
+endif
+
+LIBS = -lpng -lz -lm
+B2POBJ = bmp2png.o common.o
+P2BOBJ = png2bmp.o common.o
+
+
+all : bmp2png png2bmp
+
+bmp2png : $(B2POBJ)
+ $(LD) $(LDFLAGS) -o bmp2png $(B2POBJ) $(LIBS)
+
+png2bmp : $(P2BOBJ)
+ $(LD) $(LDFLAGS) -o png2bmp $(P2BOBJ) $(LIBS)
+
+%.o : %.c
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+install :
+ $(INSTALL) bmp2png png2bmp $(BINDIR)
+
+uninstall :
+ rm -f $(BINDIR)/bmp2png $(BINDIR)/png2bmp
+
+clean :
+ rm -f $(B2POBJ) $(P2BOBJ) bmp2png png2bmp
+
+bmp2png.o : bmp2png.c common.h bmphed.h
+png2bmp.o : png2bmp.c common.h bmphed.h
+common.o : common.c common.h
+
diff --git a/crawl-ref/source/rltiles/bmp2png/png2bmp.c b/crawl-ref/source/rltiles/bmp2png/png2bmp.c
new file mode 100644
index 0000000000..d08da6df23
--- /dev/null
+++ b/crawl-ref/source/rltiles/bmp2png/png2bmp.c
@@ -0,0 +1,647 @@
+/*
+** png2bmp --- conversion from PNG to (Windows style) BMP
+**
+** Copyright (C) 1999-2005 MIYASAKA Masaru
+**
+** For conditions of distribution and use,
+** see copyright notice in common.h.
+*/
+
+#include "common.h"
+#include "bmphed.h"
+
+#define PNG2BMP_VERSION "1.62 (Sep 4, 2005)"
+#define PNG2BMP_COPYRIGHT "Copyright (C) 1999-2005 MIYASAKA Masaru"
+
+char outnam[FILENAME_MAX];
+char outdir[FILENAME_MAX];
+int deletesrc = 0;
+int copytime = 0;
+
+#define P2B_ALPHABMP_NONE 0
+#define P2B_ALPHABMP_ARGB 1 /* -a option; 32bit ARGB(RGB) BMP */
+#define P2B_ALPHABMP_BITFIELD 2 /* -b option; 32bit Bitfield BMP */
+
+int alpha_format = P2B_ALPHABMP_NONE;
+int expand_trans = 0;
+
+#if defined(WIN32) || defined(MSDOS)
+const char errlogfile[] = ".\\P2BERROR.LOG";
+#else
+const char errlogfile[] = "./p2berror.log";
+#endif
+
+ /* error messages */
+#ifdef JAPANESE /* ---------- */
+const char wrn_mkdirfail[] =
+ "WARNING: 出力先ディレクトリを作れません - %s\n"
+ "WARNING: -> -%c オプション での出力先指定は無視されます\n";
+const char err_ropenfail[] = "SKIPPED: 該当するファイルがありません - %s\n";
+const char err_wopenfail[] = "SKIPPED: 出力ファイルを作成できません - %s\n";
+const char err_outofmemory[] = "SKIPPED: 作業用メモリが確保できません - %s\n";
+ /* -- */
+const char err_writeerr[] = "SKIPPED: 書き込みエラーが発生しました - %s\n";
+const char err_not_a_png[] = "SKIPPED: PNG ファイルではありません - %s\n";
+#else /* ------------------- */
+const char wrn_mkdirfail[] =
+ "WARNING: Cannot create a directory - %s\n"
+ "WARNING: -> Output directory specified by '-%c' will be ignored.\n";
+const char err_ropenfail[] = "SKIPPED: No such file or directory - %s\n";
+const char err_wopenfail[] = "SKIPPED: Cannot create - %s\n";
+const char err_outofmemory[] = "SKIPPED: Out of memory - %s\n";
+ /* -- */
+const char err_writeerr[] = "SKIPPED: Write operation failed - %s\n";
+const char err_not_a_png[] = "SKIPPED: Not a PNG file - %s\n";
+#endif /* ------------------- */
+
+static BOOL read_png(char *, IMAGE *);
+static int skip_macbinary(png_structp);
+static void to4bpp(png_structp, png_row_infop, png_bytep);
+static BOOL write_bmp(char *, IMAGE *);
+static const char *write_rgb_bits(IMAGE *, FILE *);
+static void mputdwl(void *, unsigned long);
+static void mputwl(void *, unsigned int);
+static void usage_exit(char *, int);
+
+
+
+/*
+** メイン
+*/
+int main(int argc, char *argv[])
+{
+ char outf[FILENAME_MAX];
+ IMAGE image;
+ int opt;
+ char *arg;
+ char *p, c;
+ int r_stdin, w_stdout;
+ int failure = 0, success = 0;
+
+#ifdef __LCC__ /* lcc-win32 */
+ char **envp;
+ void _GetMainArgs(int *, char ***, char ***, int);
+ _GetMainArgs(&argc, &argv, &envp, 1);
+#endif
+#ifdef __EMX__
+ _wildcard(&argc, &argv);
+#endif
+ envargv(&argc, &argv, "B2P");
+
+ r_stdin = !isatty(fileno(stdin));
+ w_stdout = !isatty(fileno(stdout));
+
+ while (parsearg(&opt, &arg, argc, argv, "DdOoFfPp")) {
+ switch (toupper(opt)) {
+ case 'E': deletesrc ^= 1; break;
+ case 'T': copytime ^= 1; break;
+ case 'Q': quietmode ^= 1; break;
+ case 'L': errorlog ^= 1; break;
+
+ case 'X':
+ r_stdin = 0;
+ w_stdout = 0;
+ break;
+
+ case 'A':
+ alpha_format = (alpha_format == P2B_ALPHABMP_ARGB) ?
+ P2B_ALPHABMP_NONE : P2B_ALPHABMP_ARGB;
+ break;
+
+ case 'B':
+ alpha_format = (alpha_format == P2B_ALPHABMP_BITFIELD) ?
+ P2B_ALPHABMP_NONE : P2B_ALPHABMP_BITFIELD;
+ break;
+
+ case 'R':
+ expand_trans ^= 1;
+ break;
+
+ case 'F':
+ /* '-F' option of bmp2png (ignored on png2bmp) */
+ break;
+
+ case 'P':
+ /* '-P' option of bmp2png (ignored on png2bmp) */
+ break;
+
+ case 'D': /* output directory */
+ if (*arg == '-') arg = NULL;
+ if (arg == NULL) {
+ outdir[0] = '\0';
+ } else {
+ strcpy(outdir, arg);
+ addslash(outdir);
+ if (makedir(outdir) != 0) {
+ xxprintf(wrn_mkdirfail, outdir, 'D');
+ outdir[0] = '\0';
+ }
+ }
+ break;
+
+ case 'O': /* output filename */
+ if (arg == NULL) {
+ outnam[0] = '\0';
+ } else {
+ strcpy(outnam, arg);
+ p = basname(outnam);
+ c = *p; *p = '\0';
+ if (makedir(outnam) != 0) {
+ xxprintf(wrn_mkdirfail, outnam, 'O');
+ outnam[0] = '\0';
+ } else {
+ *p = c;
+ }
+ }
+ break;
+
+ case 0x00: /* input file spec */
+ if (outnam[0] != '\0') {
+ strcpy(outf, outnam);
+ outnam[0] = '\0';
+ } else if (w_stdout) {
+ if (!read_png(arg, &image)) return 1;
+ if (!write_bmp(NULL, &image)) return 1;
+ if (deletesrc) remove(arg);
+ return 0;
+ } else {
+ if (outdir[0] != '\0') {
+ strcat(strcpy(outf, outdir), basname(arg));
+ } else {
+ strcpy(outf, arg);
+ }
+#ifdef WIN32_LFN
+ strcpy(suffix(outf), is_dos_filename(outf) ? ".BMP" : ".bmp");
+#else
+ strcpy(suffix(outf), ".bmp");
+#endif
+ }
+ /* ---------------------- */
+ if (!read_png(arg, &image)) {
+ failure++;
+ break;
+ }
+ renbak(outf);
+ if (!write_bmp(outf, &image)) {
+ failure++;
+ break;
+ }
+ /* ---------------------- */
+ if (copytime) cpyftime(arg, outf);
+ if (deletesrc) remove(arg);
+ /* ---------------------- */
+ success++;
+ break;
+
+ default:
+ ; /* Ignore unknown option */
+ }
+ }
+ if (failure == 0 && success == 0) {
+ if (!r_stdin) usage_exit(argv[0], 255);
+ if (!read_png(NULL, &image)) return 1;
+ if (outnam[0] != '\0') {
+ renbak(outnam);
+ return !write_bmp(outnam, &image);
+ } else if (w_stdout) {
+ return !write_bmp(NULL, &image);
+ } else {
+ strcat(strcpy(outf, outdir), "___stdin.bmp");
+ renbak(outf);
+ return !write_bmp(outf, &image);
+ }
+ }
+
+ return (failure > 255) ? 255 : failure;
+}
+
+
+/* -----------------------------------------------------------------------
+** PNG ファイルの読み込み
+*/
+
+#define ERROR_ABORT(s) do { errmsg = (s); goto error_abort; } while (0)
+
+/*
+** .pngファイルからの読み込み
+*/
+static BOOL read_png(char *fn, IMAGE *img)
+{
+ png_structp png_ptr;
+ png_infop info_ptr, end_info;
+ png_uint_32 width, height;
+ int bit_depth, color_type;
+ int xbit_depth, xcolor_type, xchannels;
+ const char *errmsg;
+ FILE *fp;
+
+ imgbuf_init(img);
+
+ if (fn == NULL) {
+ fn = " (stdin)";
+ fp = binary_stdio(fileno(stdin));
+ } else {
+ fp = fopen(fn, "rb");
+ }
+ if (fp == NULL) ERROR_ABORT(err_ropenfail);
+
+ set_status("Reading %.80s", basname(fn));
+
+ /* ------------------------------------------------------ */
+
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, fn,
+ png_my_error, png_my_warning);
+ if (png_ptr == NULL) {
+ ERROR_ABORT(err_outofmemory);
+ }
+ info_ptr = png_create_info_struct(png_ptr);
+ end_info = png_create_info_struct(png_ptr);
+ if (info_ptr == NULL || end_info == NULL) {
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+ ERROR_ABORT(err_outofmemory);
+ }
+ if (setjmp(png_jmpbuf(png_ptr))) {
+ /* If we get here, we had a problem writing the file */
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+ ERROR_ABORT(NULL);
+ }
+ png_init_io(png_ptr, fp);
+ png_set_sig_bytes(png_ptr, skip_macbinary(png_ptr));
+
+ /* ------------------------------------------------------ */
+
+ png_read_info(png_ptr, info_ptr);
+
+ png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
+ &color_type, NULL, NULL, NULL);
+
+ /* ------------------------------------------------------ */
+
+ if (color_type & PNG_COLOR_MASK_ALPHA) {
+ if (alpha_format == P2B_ALPHABMP_NONE) {
+ png_set_strip_alpha(png_ptr);
+ color_type &= ~PNG_COLOR_MASK_ALPHA;
+ }
+ } else if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
+ if (alpha_format != P2B_ALPHABMP_NONE && expand_trans) {
+ png_set_tRNS_to_alpha(png_ptr);
+ color_type |= PNG_COLOR_MASK_ALPHA;
+ color_type &= ~PNG_COLOR_MASK_PALETTE;
+ }
+ }
+ if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
+ png_set_gray_to_rgb(png_ptr);
+ }
+ if (color_type == PNG_COLOR_TYPE_RGB ||
+ color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
+ png_set_bgr(png_ptr);
+ }
+ if (!(color_type & PNG_COLOR_MASK_ALPHA) && bit_depth == 2) {
+ png_set_user_transform_info(png_ptr, NULL, 4, 1);
+ png_set_read_user_transform_fn(png_ptr, to4bpp);
+ }
+ if (bit_depth == 16)
+ png_set_strip_16(png_ptr);
+
+ png_read_update_info(png_ptr, info_ptr);
+
+ /* ------------------------------------------------------ */
+
+ png_get_IHDR(png_ptr, info_ptr, &width, &height, &xbit_depth,
+ &xcolor_type, NULL, NULL, NULL);
+ xchannels = png_get_channels(png_ptr, info_ptr);
+
+ img->width = (LONG)width;
+ img->height = (LONG)height;
+ img->pixdepth = (UINT)xbit_depth * xchannels;
+ img->palnum = (img->pixdepth <= 8) ? (1 << img->pixdepth) : 0;
+ img->topdown = FALSE;
+ img->alpha = (xcolor_type & PNG_COLOR_MASK_ALPHA) ? TRUE : FALSE;
+
+ if (!imgbuf_alloc(img)) {
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+ ERROR_ABORT(err_outofmemory);
+ }
+
+ if (img->palnum > 0) {
+ if (xcolor_type == PNG_COLOR_TYPE_PALETTE) {
+ png_colorp palette;
+ int num_palette;
+ png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
+ if (num_palette > (int)img->palnum) num_palette = img->palnum;
+ memset(img->palette, 0, img->palnum * sizeof(png_color));
+ memcpy(img->palette, palette, num_palette * sizeof(png_color));
+ } else {
+ int depth = (bit_depth == 16) ? 8 : bit_depth;
+ memset(img->palette, 0, img->palnum * sizeof(png_color));
+ png_build_grayscale_palette(depth, img->palette);
+ }
+ }
+
+ /* ------------------------------------------------------ */
+
+ png_set_read_status_fn(png_ptr, row_callback);
+ init_progress_meter(png_ptr, img->width, img->height);
+
+ png_read_image(png_ptr, img->rowptr);
+
+ png_read_end(png_ptr, end_info);
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+
+ /* ------------------------------------------------------ */
+
+ set_status("Read OK %.80s", basname(fn));
+
+ if (fp != stdin) fclose(fp);
+
+ return TRUE;
+
+error_abort: /* error */
+ if (errmsg != NULL) xxprintf(errmsg, fn);
+ if (fp != stdin && fp != NULL) fclose(fp);
+ imgbuf_free(img);
+
+ return FALSE;
+}
+
+
+/*
+** ファイル先頭にあるマックバイナリを読み跳ばす
+*/
+static int skip_macbinary(png_structp png_ptr)
+{
+#if 0
+ void png_read_data(png_structp, png_bytep, png_size_t);
+ enum { PNG_BYTES_TO_CHECK = 8, MACBIN_SIZE = 128 }; /* ^ in pngrio.c */
+ png_byte buf[MACBIN_SIZE];
+ png_bytep sig;
+
+ png_read_data(png_ptr, buf, PNG_BYTES_TO_CHECK);
+ if (png_sig_cmp(buf, 0, PNG_BYTES_TO_CHECK) == 0)
+ return PNG_BYTES_TO_CHECK;
+
+ png_read_data(png_ptr, buf, MACBIN_SIZE);
+ sig = buf + MACBIN_SIZE - PNG_BYTES_TO_CHECK;
+ if (png_sig_cmp(sig, 0, PNG_BYTES_TO_CHECK) == 0)
+ return PNG_BYTES_TO_CHECK;
+
+ xxprintf(err_not_a_png, (char *)png_get_error_ptr(png_ptr));
+ longjmp(png_jmpbuf(png_ptr), 1);
+
+#endif
+ return 0; /* to quiet compiler warnings */
+}
+
+
+/*
+** 4色形式 -> 16色形式への変換
+*/
+static void to4bpp(png_structp png_ptr, png_row_infop row_info, png_bytep data)
+{
+ static const png_byte pix[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x10, 0x11, 0x12, 0x13,
+ 0x20, 0x21, 0x22, 0x23, 0x30, 0x31, 0x32, 0x33,
+ };
+ png_uint_32 rowb;
+ png_bytep p, q;
+ png_byte c;
+
+ rowb = (row_info->width + 1) / 2;
+ q = data + rowb;
+ p = data + rowb / 2;
+
+ if (rowb % 2 == 1) {
+ c = *p;
+ *(--q) = pix[c >> 4];
+ }
+ while (p > data) {
+ c = *(--p);
+ *(--q) = pix[c & 0x0F];
+ *(--q) = pix[c >> 4];
+ }
+ row_info->bit_depth = 4;
+ row_info->pixel_depth = 4;
+ row_info->rowbytes = rowb;
+}
+
+
+/* -----------------------------------------------------------------------
+** BMP ファイルの書き込み
+*/
+
+/*
+** .bmp ファイルの書き込み
+*/
+static BOOL write_bmp(char *fn, IMAGE *img)
+{
+ BYTE bfh[FILEHED_SIZE + BMPV4HED_SIZE];
+ BYTE *const bih = bfh + FILEHED_SIZE;
+ BYTE rgbq[RGBQUAD_SIZE];
+ BOOL alpha_bitfield;
+ DWORD bihsize, offbits, filesize;
+ PALETTE *pal;
+ const char *errmsg;
+ FILE *fp;
+ UINT i;
+
+ if (fn == NULL) {
+ fn = " (stdout)";
+ fp = binary_stdio(fileno(stdout));
+ } else {
+ fp = fopen(fn, "wb");
+ }
+ if (fp == NULL) ERROR_ABORT(err_wopenfail);
+
+ set_status("Writing %.80s", basname(fn));
+
+ /* ------------------------------------------------------ */
+
+ alpha_bitfield = (img->alpha && alpha_format == P2B_ALPHABMP_BITFIELD);
+ bihsize = (alpha_bitfield) ? BMPV4HED_SIZE : INFOHED_SIZE;
+ offbits = FILEHED_SIZE + bihsize + RGBQUAD_SIZE * img->palnum;
+ filesize = offbits + img->imgbytes;
+
+ memset(bfh, 0, sizeof(bfh));
+
+ mputwl( bfh + BFH_WTYPE , BMP_SIGNATURE);
+ mputdwl(bfh + BFH_DSIZE , filesize);
+ mputdwl(bfh + BFH_DOFFBITS, offbits);
+
+ mputdwl(bih + BIH_DSIZE , bihsize);
+ mputdwl(bih + BIH_LWIDTH , (DWORD)img->width);
+ mputdwl(bih + BIH_LHEIGHT , (DWORD)img->height);
+ mputwl( bih + BIH_WPLANES , 1);
+ mputwl( bih + BIH_WBITCOUNT , img->pixdepth);
+ mputdwl(bih + BIH_DSIZEIMAGE, img->imgbytes);
+
+ if (alpha_bitfield) {
+ mputdwl(bih + BIH_DCOMPRESSION, BI_BITFIELDS);
+ mputdwl(bih + B4H_DALPHAMASK, 0xFF000000);
+ mputdwl(bih + B4H_DREDMASK , 0x00FF0000);
+ mputdwl(bih + B4H_DGREENMASK, 0x0000FF00);
+ mputdwl(bih + B4H_DBLUEMASK , 0x000000FF);
+ }
+
+ if (fwrite(bfh, (FILEHED_SIZE + bihsize), 1, fp) != 1)
+ ERROR_ABORT(err_writeerr);
+
+ /* ------------------------------------------------------ */
+
+ memset(rgbq, 0, sizeof(rgbq));
+
+ for (pal = img->palette, i = img->palnum; i > 0; i--, pal++) {
+ rgbq[RGBQ_RED] = pal->red;
+ rgbq[RGBQ_GREEN] = pal->green;
+ rgbq[RGBQ_BLUE] = pal->blue;
+ if (fwrite(rgbq, RGBQUAD_SIZE, 1, fp) != 1)
+ ERROR_ABORT(err_writeerr);
+ }
+
+ /* ------------------------------------------------------ */
+
+ if ((errmsg = write_rgb_bits(img, fp)) != NULL) ERROR_ABORT(errmsg);
+
+ /* ------------------------------------------------------ */
+
+ set_status("OK %.80s", basname(fn));
+ feed_line();
+
+ fflush(fp);
+ if (fp != stdout) fclose(fp);
+ imgbuf_free(img);
+
+ return TRUE;
+
+error_abort: /* error */
+ xxprintf(errmsg, fn);
+ if (fp != stdout && fp != NULL) fclose(fp);
+ imgbuf_free(img);
+
+ return FALSE;
+}
+
+
+/*
+** BI_RGB (無圧縮) 形式の画像データを書く
+*/
+static const char *write_rgb_bits(IMAGE *img, FILE *fp)
+{
+#if 1
+ DWORD wr = 16*1024*1024;
+ DWORD num = img->imgbytes;
+ BYTE *ptr = img->bmpbits;
+
+ while (num > 0) {
+ if (wr > num) wr = num;
+
+ if (fwrite(ptr, wr, 1, fp) != 1)
+ return err_writeerr;
+
+ ptr += wr; num -= wr;
+ }
+#else
+ if (fwrite(img->bmpbits, img->imgbytes, 1, fp) != 1)
+ return err_writeerr;
+#endif
+ return NULL;
+}
+
+
+/*
+** メモリへ little-endien 形式 4バイト無符号整数を書く
+*/
+static void mputdwl(void *ptr, unsigned long val)
+{
+ unsigned char *p = ptr;
+
+ p[0] = (unsigned char)(val & 0xFF);
+ p[1] = (unsigned char)(val >> 8 & 0xFF);
+ p[2] = (unsigned char)(val >> 16 & 0xFF);
+ p[3] = (unsigned char)(val >> 24 & 0xFF);
+}
+
+
+/*
+** メモリへ little-endien 形式 2バイト無符号整数を書く
+*/
+static void mputwl(void *ptr, unsigned int val)
+{
+ unsigned char *p = ptr;
+
+ p[0] = (unsigned char)(val & 0xFF);
+ p[1] = (unsigned char)(val >> 8 & 0xFF);
+}
+
+
+/* -----------------------------------------------------------------------
+** ヘルプスクリーンの表示
+*/
+
+/*
+** 使用法表示
+*/
+static void usage_exit(char *argv0, int status)
+{
+ static const char str_usage[] =
+#ifdef JAPANESE /* -------------------------- */
+#ifdef SJIS_ESCAPE
+#define SJ_ESC(esc,raw) esc
+#else
+#define SJ_ESC(esc,raw) raw
+#endif
+ "png2bmp, PNG -> BMP コンバータ - version " PNG2BMP_VERSION "\n"
+ " " PNG2BMP_COPYRIGHT "\n"
+ " Compiled with libpng " PNG_LIBPNG_VER_STRING " and zlib " ZLIB_VERSION ".\n"
+ "\n"
+ "使い方 : %s [-スイッチ] 入力ファイル名 ...\n"
+ " : ... | %s [-スイッチ] | ...\n"
+ "\n"
+ "入力ファイル名にはワイルドカードが使えます (* と ?)\n"
+ "出力ファイル名は入力ファイル名の拡張子を .bmp に変えた名前になります\n"
+ "\n"
+ "スイッチオプション (小文字でも可) :\n"
+ " -A アルファチャネルを保存する (32bit ARGB BMP 形式で)\n"
+ " -B アルファチャネルを保存する (32bit Bitfield BMP 形式で)\n"
+ " -R 透明色をアルファチャネルに変換する (-A か -B と共に使う)\n"
+ " -O name 出力ファイル名を指定する\n"
+ " -D dir ファイルを出力するディレクトリを指定する\n"
+ " -E 変換が成功した場合には入力ファイルを削除する\n"
+ " -T 入力ファイルのタイムスタンプを出力ファイルに設定する\n"
+ " -Q 処理中, 一切の" SJ_ESC("表\示","表示") "をしない\n"
+ " -L 処理中のエラーをログファイル(%s)に記録する\n"
+ " -X 標準入力/標準出力を介した変換を無効にする\n";
+#else /* ----------------------------------- */
+ "png2bmp, a PNG-to-BMP converter - version " PNG2BMP_VERSION "\n"
+ " " PNG2BMP_COPYRIGHT "\n"
+ " Compiled with libpng " PNG_LIBPNG_VER_STRING " and zlib " ZLIB_VERSION ".\n"
+ "\n"
+ "Usage: %s [-switches] inputfile(s) ...\n"
+ " or: ... | %s [-switches] | ...\n"
+ "\n"
+ "List of input files may use wildcards (* and ?)\n"
+ "Output filename is same as input filename, but extension .bmp\n"
+ "\n"
+ "Switches (case-insensitive) :\n"
+ " -A Preserve alpha channel (save in 32bit ARGB BMP format)\n"
+ " -B Preserve alpha channel (save in 32bit Bitfield BMP format)\n"
+ " -R Convert transparent color to alpha channel (use with -A or -B)\n"
+ " -O name Specify name for output file\n"
+ " -D dir Output files into dir\n"
+ " -E Delete input files after successful conversion\n"
+ " -T Set the timestamp of input file on output file\n"
+ " -Q Quiet mode\n"
+ " -L Log errors to %s file\n"
+ " -X Disable conversion through standard input/output\n";
+#endif /* ----------------------------------- */
+#if defined(WIN32) || defined(MSDOS)
+ char exename[FILENAME_MAX];
+ char *p;
+
+ argv0 = strcpy(exename, basname(argv0));
+ for (p = argv0; *p != '\0'; p++) *p = tolower(*p);
+#endif
+ fprintf(stdout, str_usage, argv0, argv0, errlogfile);
+
+ exit(status);
+}
+
diff --git a/crawl-ref/source/rltiles/bmp2png/png2bmp.dsp b/crawl-ref/source/rltiles/bmp2png/png2bmp.dsp
new file mode 100644
index 0000000000..9012f86579
--- /dev/null
+++ b/crawl-ref/source/rltiles/bmp2png/png2bmp.dsp
@@ -0,0 +1,111 @@
+# Microsoft Developer Studio Project File - Name="png2bmp" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** 編集しないでください **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=png2bmp - Win32 Debug
+!MESSAGE これは有効なメイクファイルではありません。 このプロジェクトをビルドするためには NMAKE を使用してください。
+!MESSAGE [メイクファイルのエクスポート] コマンドを使用して実行してください
+!MESSAGE
+!MESSAGE NMAKE /f "png2bmp.mak".
+!MESSAGE
+!MESSAGE NMAKE の実行時に構成を指定できます
+!MESSAGE コマンド ライン上でマクロの設定を定義します。例:
+!MESSAGE
+!MESSAGE NMAKE /f "png2bmp.mak" CFG="png2bmp - Win32 Debug"
+!MESSAGE
+!MESSAGE 選択可能なビルド モード:
+!MESSAGE
+!MESSAGE "png2bmp - Win32 Release" ("Win32 (x86) Console Application" 用)
+!MESSAGE "png2bmp - Win32 Debug" ("Win32 (x86) Console Application" 用)
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "png2bmp - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "PNG_USER_CONFIG" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /O2 /I "..\libpng" /I "..\zlib" /D "NDEBUG" /D "PNG_USER_CONFIG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /GF /c
+# ADD BASE RSC /l 0x411 /d "NDEBUG"
+# ADD RSC /l 0x411 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 setargv.obj libpng.lib zlib.lib /nologo /subsystem:console /map /machine:I386 /libpath:"..\libpng\release" /libpath:"..\zlib\release" /opt:nowin98
+# SUBTRACT LINK32 /pdb:none
+
+!ELSEIF "$(CFG)" == "png2bmp - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "PNG_USER_CONFIG" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /I "..\libpng" /I "..\zlib" /D "_DEBUG" /D "PNG_USER_CONFIG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /Fr /YX /FD /GZ /c
+# ADD BASE RSC /l 0x411 /d "_DEBUG"
+# ADD RSC /l 0x411 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 setargv.obj libpng.lib zlib.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\libpng\debug" /libpath:"..\zlib\debug"
+
+!ENDIF
+
+# Begin Target
+
+# Name "png2bmp - Win32 Release"
+# Name "png2bmp - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\common.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\png2bmp.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\bmphed.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\common.h
+# End Source File
+# End Group
+# End Target
+# End Project