Add support for PNG in nvdecompress. Patch by Frank Richter. Fixes issue 80.
This commit is contained in:
parent
7741a99b90
commit
17790a34df
@ -41,6 +41,7 @@ int main(int argc, char *argv[])
|
|||||||
bool forcenormal = false;
|
bool forcenormal = false;
|
||||||
bool mipmaps = false;
|
bool mipmaps = false;
|
||||||
bool faces = false;
|
bool faces = false;
|
||||||
|
bool savePNG = false;
|
||||||
|
|
||||||
nv::Path input;
|
nv::Path input;
|
||||||
nv::Path output;
|
nv::Path output;
|
||||||
@ -60,6 +61,19 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
faces = true;
|
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] != '-')
|
else if (argv[i][0] != '-')
|
||||||
{
|
{
|
||||||
input = argv[i];
|
input = argv[i];
|
||||||
@ -71,8 +85,6 @@ int main(int argc, char *argv[])
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
output.copy(input.str());
|
output.copy(input.str());
|
||||||
output.stripExtension();
|
|
||||||
output.append(".tga");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -85,16 +97,17 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
printf("usage: nvdecompress [options] infile [outfile]\n\n");
|
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("Input options:\n");
|
||||||
printf(" -forcenormal \tThe input image is a normal map.\n");
|
printf(" -forcenormal \tThe input image is a normal map.\n");
|
||||||
printf(" -mipmaps \tDecompress all mipmaps.\n");
|
printf(" -mipmaps \tDecompress all mipmaps.\n");
|
||||||
printf(" -faces \tDecompress all faces.\n");
|
printf(" -faces \tDecompress all faces.\n");
|
||||||
|
printf(" -format <format>\tOutput format ('tga' or 'png').\n");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load surface.
|
// Load surface.
|
||||||
nv::DirectDrawSurface dds(input);
|
nv::DirectDrawSurface dds(input);
|
||||||
if (!dds.isValid())
|
if (!dds.isValid())
|
||||||
@ -155,7 +168,7 @@ int main(int argc, char *argv[])
|
|||||||
name.copy(output);
|
name.copy(output);
|
||||||
if (faces) name.appendFormat("_face%d", f);
|
if (faces) name.appendFormat("_face%d", f);
|
||||||
if (mipmaps) name.appendFormat("_mipmap%d", m);
|
if (mipmaps) name.appendFormat("_mipmap%d", m);
|
||||||
name.append(".tga");
|
name.append(savePNG ? ".png" : ".tga");
|
||||||
|
|
||||||
nv::StdOutputStream stream(name.str());
|
nv::StdOutputStream stream(name.str());
|
||||||
if (stream.isError()) {
|
if (stream.isError()) {
|
||||||
@ -163,7 +176,10 @@ int main(int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
nv::ImageIO::saveTGA(stream, &mipmap);
|
if (savePNG)
|
||||||
|
nv::ImageIO::savePNG(stream, &mipmap);
|
||||||
|
else
|
||||||
|
nv::ImageIO::saveTGA(stream, &mipmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user