From 17790a34df08b9954b01a4d75c845d2b56bec757 Mon Sep 17 00:00:00 2001 From: castano Date: Tue, 3 Feb 2009 09:08:39 +0000 Subject: [PATCH] Add support for PNG in nvdecompress. Patch by Frank Richter. Fixes issue 80. --- src/nvtt/tools/decompress.cpp | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/nvtt/tools/decompress.cpp b/src/nvtt/tools/decompress.cpp index 8589e23..ec3ac7e 100644 --- a/src/nvtt/tools/decompress.cpp +++ b/src/nvtt/tools/decompress.cpp @@ -41,6 +41,7 @@ int main(int argc, char *argv[]) bool forcenormal = false; bool mipmaps = false; bool faces = false; + bool savePNG = false; nv::Path input; nv::Path output; @@ -60,6 +61,19 @@ int main(int argc, char *argv[]) { faces = true; } + else if (strcmp("-format", argv[i]) == 0) + { + if (i+1 == argc) break; + i++; + + if (strcmp("png", argv[i]) == 0) savePNG = true; + else if (strcmp("tga", argv[i]) == 0) savePNG = false; + else + { + fprintf(stderr, "Unsupported output format '%s', defaulting to 'tga'.\n", argv[i]); + savePNG = false; + } + } else if (argv[i][0] != '-') { input = argv[i]; @@ -71,8 +85,6 @@ int main(int argc, char *argv[]) else { output.copy(input.str()); - output.stripExtension(); - output.append(".tga"); } break; @@ -85,16 +97,17 @@ int main(int argc, char *argv[]) { printf("usage: nvdecompress [options] infile [outfile]\n\n"); - printf("Note: the .tga extension is forced on outfile\n\n"); + printf("Note: the .tga or .png extension is forced on outfile\n\n"); printf("Input options:\n"); - printf(" -forcenormal \tThe input image is a normal map.\n"); - printf(" -mipmaps \tDecompress all mipmaps.\n"); - printf(" -faces \tDecompress all faces.\n"); + printf(" -forcenormal \tThe input image is a normal map.\n"); + printf(" -mipmaps \tDecompress all mipmaps.\n"); + printf(" -faces \tDecompress all faces.\n"); + printf(" -format \tOutput format ('tga' or 'png').\n"); return 1; } - + // Load surface. nv::DirectDrawSurface dds(input); if (!dds.isValid()) @@ -155,7 +168,7 @@ int main(int argc, char *argv[]) name.copy(output); if (faces) name.appendFormat("_face%d", f); if (mipmaps) name.appendFormat("_mipmap%d", m); - name.append(".tga"); + name.append(savePNG ? ".png" : ".tga"); nv::StdOutputStream stream(name.str()); if (stream.isError()) { @@ -163,7 +176,10 @@ int main(int argc, char *argv[]) return 1; } - nv::ImageIO::saveTGA(stream, &mipmap); + if (savePNG) + nv::ImageIO::savePNG(stream, &mipmap); + else + nv::ImageIO::saveTGA(stream, &mipmap); } }