Minor code review and reformatting

This commit is contained in:
Chuck Walbourn
2019-09-13 17:31:09 -07:00
parent cadc01f3af
commit f4954ce11b
3 changed files with 492 additions and 506 deletions

View File

@@ -123,7 +123,7 @@ const SValue g_pCommands[] =
{ nullptr, 0 }
};
const SValue g_pOptions [] =
const SValue g_pOptions[] =
{
{ L"r", OPT_RECURSIVE },
{ L"w", OPT_WIDTH },
@@ -150,7 +150,7 @@ const SValue g_pOptions [] =
#define DEFFMT(fmt) { L#fmt, DXGI_FORMAT_ ## fmt }
const SValue g_pFormats [] =
const SValue g_pFormats[] =
{
// List does not include _TYPELESS or depth/stencil formats
DEFFMT(R32G32B32A32_FLOAT),
@@ -224,7 +224,7 @@ const SValue g_pFormats [] =
{ nullptr, DXGI_FORMAT_UNKNOWN }
};
const SValue g_pFormatAliases [] =
const SValue g_pFormatAliases[] =
{
{ L"RGBA", DXGI_FORMAT_R8G8B8A8_UNORM },
{ L"BGRA", DXGI_FORMAT_B8G8R8A8_UNORM },
@@ -235,7 +235,7 @@ const SValue g_pFormatAliases [] =
{ nullptr, DXGI_FORMAT_UNKNOWN }
};
const SValue g_pFilters [] =
const SValue g_pFilters[] =
{
{ L"POINT", TEX_FILTER_POINT },
{ L"LINEAR", TEX_FILTER_LINEAR },
@@ -258,7 +258,7 @@ const SValue g_pFilters [] =
{ nullptr, TEX_FILTER_DEFAULT }
};
#define CODEC_DDS 0xFFFF0001
#define CODEC_DDS 0xFFFF0001
#define CODEC_TGA 0xFFFF0002
#define CODEC_HDR 0xFFFF0005
@@ -266,7 +266,7 @@ const SValue g_pFilters [] =
#define CODEC_EXR 0xFFFF0006
#endif
const SValue g_pExtFileTypes [] =
const SValue g_pExtFileTypes[] =
{
{ L".BMP", WIC_CODEC_BMP },
{ L".JPG", WIC_CODEC_JPEG },
@@ -551,10 +551,10 @@ namespace
case CODEC_HDR:
return SaveToHDRFile(img, szOutputFile);
#ifdef USE_OPENEXR
#ifdef USE_OPENEXR
case CODEC_EXR:
return SaveToEXRFile(img, szOutputFile);
#endif
#endif
default:
return SaveToWICFile(img, WIC_FLAGS_NONE, GetWICCodec(static_cast<WICCodecs>(fileType)), szOutputFile);
@@ -758,7 +758,7 @@ namespace
}
else if (iframe > 0)
{
hr = frameImage->InitializeFromImage(*loadedImages[iframe-1]->GetImage(0, 0, 0));
hr = frameImage->InitializeFromImage(*loadedImages[iframe - 1]->GetImage(0, 0, 0));
}
else
{
@@ -934,7 +934,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
HRESULT hr = hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
if (FAILED(hr))
{
wprintf(L"Failed to initialize COM (%08X)\n", hr);
wprintf(L"Failed to initialize COM (%08X)\n", static_cast<unsigned int>(hr));
return 1;
}
@@ -1129,46 +1129,46 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
break;
case OPT_FILELIST:
{
std::wifstream inFile(pValue);
if (!inFile)
{
std::wifstream inFile(pValue);
wprintf(L"Error opening -flist file %ls\n", pValue);
return 1;
}
wchar_t fname[1024] = {};
for (;;)
{
inFile >> fname;
if (!inFile)
break;
if (*fname == L'#')
{
wprintf(L"Error opening -flist file %ls\n", pValue);
// Comment
}
else if (*fname == L'-')
{
wprintf(L"Command-line arguments not supported in -flist file\n");
return 1;
}
wchar_t fname[1024] = {};
for (;;)
else if (wcspbrk(fname, L"?*") != nullptr)
{
inFile >> fname;
if (!inFile)
break;
if (*fname == L'#')
{
// Comment
}
else if (*fname == L'-')
{
wprintf(L"Command-line arguments not supported in -flist file\n");
return 1;
}
else if (wcspbrk(fname, L"?*") != nullptr)
{
wprintf(L"Wildcards not supported in -flist file\n");
return 1;
}
else
{
SConversion conv;
wcscpy_s(conv.szSrc, MAX_PATH, fname);
conversion.push_back(conv);
}
inFile.ignore(1000, '\n');
wprintf(L"Wildcards not supported in -flist file\n");
return 1;
}
inFile.close();
else
{
SConversion conv;
wcscpy_s(conv.szSrc, MAX_PATH, fname);
conversion.push_back(conv);
}
inFile.ignore(1000, '\n');
}
break;
inFile.close();
}
break;
case OPT_GIF_BGCOLOR:
if (dwCommand != CMD_GIF)
@@ -1259,7 +1259,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = LoadAnimatedGif(conversion.front().szSrc, loadedImages, (dwOptions & (1 << OPT_GIF_BGCOLOR)) != 0);
if (FAILED(hr))
{
wprintf(L" FAILED (%x)\n", hr);
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
}
@@ -1320,7 +1320,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = LoadFromDDSFile(pConv->szSrc, DDS_FLAGS_NONE, &info, *image);
if (FAILED(hr))
{
wprintf(L" FAILED (%x)\n", hr);
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
@@ -1347,7 +1347,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = LoadFromDDSFile(pConv->szSrc, DDS_FLAGS_NONE, &info, *image);
if (FAILED(hr))
{
wprintf(L" FAILED (%x)\n", hr);
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
@@ -1370,7 +1370,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = LoadFromDDSFile(pConv->szSrc, DDS_FLAGS_NONE, &info, *image);
if (FAILED(hr))
{
wprintf(L" FAILED (%x)\n", hr);
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
@@ -1387,7 +1387,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = LoadFromTGAFile(pConv->szSrc, &info, *image);
if (FAILED(hr))
{
wprintf(L" FAILED (%x)\n", hr);
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
}
@@ -1396,7 +1396,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = LoadFromHDRFile(pConv->szSrc, &info, *image);
if (FAILED(hr))
{
wprintf(L" FAILED (%x)\n", hr);
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
}
@@ -1406,7 +1406,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = LoadFromEXRFile(pConv->szSrc, &info, *image);
if (FAILED(hr))
{
wprintf(L" FAILED (%x)\n", hr);
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
continue;
}
}
@@ -1424,7 +1424,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = LoadFromWICFile(pConv->szSrc, dwFilter | WIC_FLAGS_ALL_FRAMES, &info, *image);
if (FAILED(hr))
{
wprintf(L" FAILED (%x)\n", hr);
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
}
@@ -1453,7 +1453,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = ConvertToSinglePlane(img, nimg, info, *timage);
if (FAILED(hr))
{
wprintf(L" FAILED [converttosingleplane] (%x)\n", hr);
wprintf(L" FAILED [converttosingleplane] (%x)\n", static_cast<unsigned int>(hr));
continue;
}
@@ -1489,7 +1489,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = Decompress(img, nimg, info, DXGI_FORMAT_UNKNOWN /* picks good default */, *timage.get());
if (FAILED(hr))
{
wprintf(L" FAILED [decompress] (%x)\n", hr);
wprintf(L" FAILED [decompress] (%x)\n", static_cast<unsigned int>(hr));
continue;
}
@@ -1537,7 +1537,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = PremultiplyAlpha(img, nimg, info, TEX_PMALPHA_REVERSE | dwSRGB, *timage);
if (FAILED(hr))
{
wprintf(L" FAILED [demultiply alpha] (%x)\n", hr);
wprintf(L" FAILED [demultiply alpha] (%x)\n", static_cast<unsigned int>(hr));
continue;
}
@@ -1577,7 +1577,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = Resize(image->GetImages(), image->GetImageCount(), image->GetMetadata(), width, height, dwFilter | dwFilterOpts, *timage.get());
if (FAILED(hr))
{
wprintf(L" FAILED [resize] (%x)\n", hr);
wprintf(L" FAILED [resize] (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
@@ -1611,58 +1611,58 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
XMVECTOR maxLum = XMVectorZero();
hr = EvaluateImage(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
[&](const XMVECTOR* pixels, size_t w, size_t y)
{
UNREFERENCED_PARAMETER(y);
for (size_t j = 0; j < w; ++j)
{
static const XMVECTORF32 s_luminance = { { { 0.3f, 0.59f, 0.11f, 0.f } } };
UNREFERENCED_PARAMETER(y);
XMVECTOR v = *pixels++;
for (size_t j = 0; j < w; ++j)
{
static const XMVECTORF32 s_luminance = { { { 0.3f, 0.59f, 0.11f, 0.f } } };
v = XMVector3Dot(v, s_luminance);
XMVECTOR v = *pixels++;
maxLum = XMVectorMax(v, maxLum);
}
});
v = XMVector3Dot(v, s_luminance);
maxLum = XMVectorMax(v, maxLum);
}
});
if (FAILED(hr))
{
wprintf(L" FAILED [tonemap maxlum] (%x)\n", hr);
wprintf(L" FAILED [tonemap maxlum] (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
// Reinhard et al, "Photographic Tone Reproduction for Digital Images"
// Reinhard et al, "Photographic Tone Reproduction for Digital Images"
// http://www.cs.utah.edu/~reinhard/cdrom/
maxLum = XMVectorMultiply(maxLum, maxLum);
hr = TransformImage(image->GetImages(), image->GetImageCount(), image->GetMetadata(),
[&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t w, size_t y)
{
UNREFERENCED_PARAMETER(y);
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = inPixels[j];
UNREFERENCED_PARAMETER(y);
XMVECTOR scale = XMVectorDivide(
XMVectorAdd(g_XMOne, XMVectorDivide(value, maxLum)),
XMVectorAdd(g_XMOne, value));
XMVECTOR nvalue = XMVectorMultiply(value, scale);
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = inPixels[j];
value = XMVectorSelect(value, nvalue, g_XMSelect1110);
XMVECTOR scale = XMVectorDivide(
XMVectorAdd(g_XMOne, XMVectorDivide(value, maxLum)),
XMVectorAdd(g_XMOne, value));
XMVECTOR nvalue = XMVectorMultiply(value, scale);
outPixels[j] = value;
}
}, *timage);
value = XMVectorSelect(value, nvalue, g_XMSelect1110);
outPixels[j] = value;
}
}, *timage);
if (FAILED(hr))
{
wprintf(L" FAILED [tonemap apply] (%x)\n", hr);
wprintf(L" FAILED [tonemap apply] (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
#ifndef NDEBUG
#ifndef NDEBUG
auto& tinfo = timage->GetMetadata();
#endif
#endif
assert(info.width == tinfo.width);
assert(info.height == tinfo.height);
@@ -1694,7 +1694,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
dwFilter | dwFilterOpts | dwSRGB, TEX_THRESHOLD_DEFAULT, *timage.get());
if (FAILED(hr))
{
wprintf(L" FAILED [convert] (%x)\n", hr);
wprintf(L" FAILED [convert] (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
@@ -1801,7 +1801,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = result.Initialize2D(format, twidth, theight, 1, 1);
if (FAILED(hr))
{
wprintf(L"FAILED setting up result image (%x)\n", hr);
wprintf(L"FAILED setting up result image (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
@@ -1872,7 +1872,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = CopyRectangle(*img, rect, *dest, dwFilter | dwFilterOpts, offsetx, offsety);
if (FAILED(hr))
{
wprintf(L"FAILED building result image (%x)\n", hr);
wprintf(L"FAILED building result image (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
}
@@ -1895,7 +1895,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = SaveImageFile(*dest, fileType, szOutputFile);
if (FAILED(hr))
{
wprintf(L" FAILED (%x)\n", hr);
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
break;
@@ -1908,7 +1908,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = alphaImage.Initialize2D(DXGI_FORMAT_R32_FLOAT, width, height, 1, 1);
if (FAILED(hr))
{
wprintf(L"FAILED setting up alpha image (%x)\n", hr);
wprintf(L"FAILED setting up alpha image (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
@@ -1916,21 +1916,21 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = EvaluateImage(*loadedImages[1]->GetImage(0, 0, 0),
[&](const XMVECTOR* pixels, size_t w, size_t y)
{
auto alphaPtr = reinterpret_cast<float*>(img.pixels + img.rowPitch * y);
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = pixels[j];
auto alphaPtr = reinterpret_cast<float*>(img.pixels + img.rowPitch * y);
// DXTex's Open Alpha onto Surface always loaded alpha from the blue channel
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = pixels[j];
*alphaPtr++ = XMVectorGetZ(value);
}
});
// DXTex's Open Alpha onto Surface always loaded alpha from the blue channel
*alphaPtr++ = XMVectorGetZ(value);
}
});
if (FAILED(hr))
{
wprintf(L" FAILED [reading alpha image] (%x)\n", hr);
wprintf(L" FAILED [reading alpha image] (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
@@ -1939,23 +1939,23 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
ScratchImage result;
hr = TransformImage(rgb, [&](XMVECTOR* outPixels, const XMVECTOR* inPixels, size_t w, size_t y)
{
auto alphaPtr = reinterpret_cast<float*>(img.pixels + img.rowPitch * y);
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = inPixels[j];
auto alphaPtr = reinterpret_cast<float*>(img.pixels + img.rowPitch * y);
XMVECTOR nvalue = XMVectorReplicate(*alphaPtr++);
for (size_t j = 0; j < w; ++j)
{
XMVECTOR value = inPixels[j];
value = XMVectorSelect(nvalue, value, g_XMSelect1110);
XMVECTOR nvalue = XMVectorReplicate(*alphaPtr++);
outPixels[j] = value;
}
}, result);
value = XMVectorSelect(nvalue, value, g_XMSelect1110);
outPixels[j] = value;
}
}, result);
if (FAILED(hr))
{
wprintf(L" FAILED [merge image] (%x)\n", hr);
wprintf(L" FAILED [merge image] (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
@@ -1977,7 +1977,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = SaveImageFile(*result.GetImage(0, 0, 0), fileType, szOutputFile);
if (FAILED(hr))
{
wprintf(L" FAILED (%x)\n", hr);
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
break;
@@ -1992,7 +1992,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = result.Initialize2D(format, twidth, theight, 1, 1);
if (FAILED(hr))
{
wprintf(L"FAILED setting up result image (%x)\n", hr);
wprintf(L"FAILED setting up result image (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
@@ -2020,7 +2020,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = CopyRectangle(*img, rect, *dest, dwFilter | dwFilterOpts, offsetx, offsety);
if (FAILED(hr))
{
wprintf(L"FAILED building result image (%x)\n", hr);
wprintf(L"FAILED building result image (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
}
@@ -2043,7 +2043,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = SaveImageFile(*dest, fileType, szOutputFile);
if (FAILED(hr))
{
wprintf(L" FAILED (%x)\n", hr);
wprintf(L" FAILED (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
break;
@@ -2088,7 +2088,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (FAILED(hr))
{
wprintf(L"FAILED building result image (%x)\n", hr);
wprintf(L"FAILED building result image (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
@@ -2112,7 +2112,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
szOutputFile);
if (FAILED(hr))
{
wprintf(L"\nFAILED (%x)\n", hr);
wprintf(L"\nFAILED (%x)\n", static_cast<unsigned int>(hr));
return 1;
}
break;