Fixed printf portability issues

This commit is contained in:
Chuck Walbourn 2019-11-15 00:13:05 -08:00
parent 138efff1b9
commit 12fff67438
3 changed files with 52 additions and 52 deletions

View File

@ -399,7 +399,7 @@ namespace
{ {
if (static_cast<DXGI_FORMAT>(pFormat->dwValue) == Format) if (static_cast<DXGI_FORMAT>(pFormat->dwValue) == Format)
{ {
wprintf(pFormat->pName); wprintf(L"%ls", pFormat->pName);
break; break;
} }
} }
@ -425,17 +425,17 @@ namespace
switch (info.dimension) switch (info.dimension)
{ {
case TEX_DIMENSION_TEXTURE1D: case TEX_DIMENSION_TEXTURE1D:
wprintf((info.arraySize > 1) ? L" 1DArray" : L" 1D"); wprintf(L"%ls", (info.arraySize > 1) ? L" 1DArray" : L" 1D");
break; break;
case TEX_DIMENSION_TEXTURE2D: case TEX_DIMENSION_TEXTURE2D:
if (info.IsCubemap()) if (info.IsCubemap())
{ {
wprintf((info.arraySize > 6) ? L" CubeArray" : L" Cube"); wprintf(L"%ls", (info.arraySize > 6) ? L" CubeArray" : L" Cube");
} }
else else
{ {
wprintf((info.arraySize > 1) ? L" 2DArray" : L" 2D"); wprintf(L"%ls", (info.arraySize > 1) ? L" 2DArray" : L" 2D");
} }
break; break;

View File

@ -570,7 +570,7 @@ namespace
{ {
if (static_cast<DXGI_FORMAT>(pFormat->dwValue) == Format) if (static_cast<DXGI_FORMAT>(pFormat->dwValue) == Format)
{ {
wprintf(pFormat->pName); wprintf(L"%ls", pFormat->pName);
return; return;
} }
} }
@ -579,7 +579,7 @@ namespace
{ {
if (static_cast<DXGI_FORMAT>(pFormat->dwValue) == Format) if (static_cast<DXGI_FORMAT>(pFormat->dwValue) == Format)
{ {
wprintf(pFormat->pName); wprintf(L"%ls", pFormat->pName);
return; return;
} }
} }
@ -606,17 +606,17 @@ namespace
switch (info.dimension) switch (info.dimension)
{ {
case TEX_DIMENSION_TEXTURE1D: case TEX_DIMENSION_TEXTURE1D:
wprintf((info.arraySize > 1) ? L" 1DArray" : L" 1D"); wprintf(L"%ls", (info.arraySize > 1) ? L" 1DArray" : L" 1D");
break; break;
case TEX_DIMENSION_TEXTURE2D: case TEX_DIMENSION_TEXTURE2D:
if (info.IsCubemap()) if (info.IsCubemap())
{ {
wprintf((info.arraySize > 6) ? L" CubeArray" : L" Cube"); wprintf(L"%ls", (info.arraySize > 6) ? L" CubeArray" : L" Cube");
} }
else else
{ {
wprintf((info.arraySize > 1) ? L" 2DArray" : L" 2D"); wprintf(L"%ls", (info.arraySize > 1) ? L" 2DArray" : L" 2D");
} }
break; break;
@ -1523,7 +1523,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
break; break;
case OPT_COLORKEY: case OPT_COLORKEY:
if (swscanf_s(pValue, L"%x", &colorKey) != 1) if (swscanf_s(pValue, L"%lx", &colorKey) != 1)
{ {
printf("Invalid value specified with -c (%ls)\n", pValue); printf("Invalid value specified with -c (%ls)\n", pValue);
printf("\n"); printf("\n");
@ -3144,7 +3144,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (sizewarn) if (sizewarn)
{ {
wprintf(L"\nWARNING: Target size exceeds maximum size for feature level (%u)\n", maxSize); wprintf(L"\nWARNING: Target size exceeds maximum size for feature level (%lu)\n", maxSize);
} }
if (nonpow2warn && maxSize <= 4096) if (nonpow2warn && maxSize <= 4096)

View File

@ -478,7 +478,7 @@ namespace
{ {
if (static_cast<DXGI_FORMAT>(pFormat->dwValue) == Format) if (static_cast<DXGI_FORMAT>(pFormat->dwValue) == Format)
{ {
wprintf(pFormat->pName); wprintf(L"%ls", pFormat->pName);
return; return;
} }
} }
@ -487,7 +487,7 @@ namespace
{ {
if (static_cast<DXGI_FORMAT>(pFormat->dwValue) == Format) if (static_cast<DXGI_FORMAT>(pFormat->dwValue) == Format)
{ {
wprintf(pFormat->pName); wprintf(L"%ls", pFormat->pName);
return; return;
} }
} }
@ -836,7 +836,7 @@ namespace
for (size_t j = 1; j <= 14; ++j) for (size_t j = 1; j <= 14; ++j)
{ {
if (blockHist[j] > 0) if (blockHist[j] > 0)
wprintf(L"\t Mode %02Iu blocks - %zu\n", j, blockHist[j]); wprintf(L"\t Mode %02zu blocks - %zu\n", j, blockHist[j]);
} }
if (blockHist[0] > 0) if (blockHist[0] > 0)
wprintf(L"\tReserved mode blcks - %zu\n", blockHist[0]); wprintf(L"\tReserved mode blcks - %zu\n", blockHist[0]);
@ -847,7 +847,7 @@ namespace
for (size_t j = 0; j <= 7; ++j) for (size_t j = 0; j <= 7; ++j)
{ {
if (blockHist[j] > 0) if (blockHist[j] > 0)
wprintf(L"\t Mode %02Iu blocks - %zu\n", j, blockHist[j]); wprintf(L"\t Mode %02zu blocks - %zu\n", j, blockHist[j]);
} }
if (blockHist[8] > 0) if (blockHist[8] > 0)
wprintf(L"\tReserved mode blcks - %zu\n", blockHist[8]); wprintf(L"\tReserved mode blcks - %zu\n", blockHist[8]);
@ -3425,7 +3425,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (info1.depth > 1) if (info1.depth > 1)
{ {
wprintf(L"Results by mip (%3Iu) and slice (%3Iu)\n\n", info1.mipLevels, info1.depth); wprintf(L"Results by mip (%3zu) and slice (%3zu)\n\n", info1.mipLevels, info1.depth);
size_t depth = info1.depth; size_t depth = info1.depth;
for (size_t mip = 0; mip < info1.mipLevels; ++mip) for (size_t mip = 0; mip < info1.mipLevels; ++mip)
@ -3440,7 +3440,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|| img1->height != img2->height || img1->height != img2->height
|| img1->width != img2->width) || img1->width != img2->width)
{ {
wprintf(L"ERROR: Unexpected mismatch at slice %3Iu, mip %3Iu\n", slice, mip); wprintf(L"ERROR: Unexpected mismatch at slice %3zu, mip %3zu\n", slice, mip);
return 1; return 1;
} }
else else
@ -3449,7 +3449,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = ComputeMSE(*img1, *img2, mse, mseV); hr = ComputeMSE(*img1, *img2, mse, mseV);
if (FAILED(hr)) if (FAILED(hr))
{ {
wprintf(L"Failed comparing images at slice %3Iu, mip %3Iu (%08X)\n", slice, mip, static_cast<unsigned int>(hr)); wprintf(L"Failed comparing images at slice %3zu, mip %3zu (%08X)\n", slice, mip, static_cast<unsigned int>(hr));
return 1; return 1;
} }
@ -3466,7 +3466,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
++total_images; ++total_images;
wprintf(L"[%3Iu,%3Iu]: %f (%f %f %f %f) PSNR %f dB\n", mip, slice, mse, mseV[0], mseV[1], mseV[2], mseV[3], wprintf(L"[%3zu,%3zu]: %f (%f %f %f %f) PSNR %f dB\n", mip, slice, mse, mseV[0], mseV[1], mseV[2], mseV[3],
10.0 * log10(3.0 / (double(mseV[0]) + double(mseV[1]) + double(mseV[2])))); 10.0 * log10(3.0 / (double(mseV[0]) + double(mseV[1]) + double(mseV[2]))));
} }
} }
@ -3477,7 +3477,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
} }
else else
{ {
wprintf(L"Results by item (%3Iu) and mip (%3Iu)\n\n", info1.arraySize, info1.mipLevels); wprintf(L"Results by item (%3zu) and mip (%3zu)\n\n", info1.arraySize, info1.mipLevels);
for (size_t item = 0; item < info1.arraySize; ++item) for (size_t item = 0; item < info1.arraySize; ++item)
{ {
@ -3491,7 +3491,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
|| img1->height != img2->height || img1->height != img2->height
|| img1->width != img2->width) || img1->width != img2->width)
{ {
wprintf(L"ERROR: Unexpected mismatch at item %3Iu, mip %3Iu\n", item, mip); wprintf(L"ERROR: Unexpected mismatch at item %3zu, mip %3zu\n", item, mip);
return 1; return 1;
} }
else else
@ -3500,7 +3500,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = ComputeMSE(*img1, *img2, mse, mseV); hr = ComputeMSE(*img1, *img2, mse, mseV);
if (FAILED(hr)) if (FAILED(hr))
{ {
wprintf(L"Failed comparing images at item %3Iu, mip %3Iu (%08X)\n", item, mip, static_cast<unsigned int>(hr)); wprintf(L"Failed comparing images at item %3zu, mip %3zu (%08X)\n", item, mip, static_cast<unsigned int>(hr));
return 1; return 1;
} }
@ -3517,7 +3517,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
++total_images; ++total_images;
wprintf(L"[%3Iu,%3Iu]: %f (%f %f %f %f) PSNR %f dB\n", item, mip, mse, mseV[0], mseV[1], mseV[2], mseV[3], wprintf(L"[%3zu,%3zu]: %f (%f %f %f %f) PSNR %f dB\n", item, mip, mse, mseV[0], mseV[1], mseV[2], mseV[3],
10.0 * log10(3.0 / (double(mseV[0]) + double(mseV[1]) + double(mseV[2])))); 10.0 * log10(3.0 / (double(mseV[0]) + double(mseV[1]) + double(mseV[2]))));
} }
} }
@ -3581,17 +3581,17 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
switch (info.dimension) switch (info.dimension)
{ {
case TEX_DIMENSION_TEXTURE1D: case TEX_DIMENSION_TEXTURE1D:
wprintf((info.arraySize > 1) ? L"1DArray\n" : L"1D\n"); wprintf(L"%ls", (info.arraySize > 1) ? L"1DArray\n" : L"1D\n");
break; break;
case TEX_DIMENSION_TEXTURE2D: case TEX_DIMENSION_TEXTURE2D:
if (info.IsCubemap()) if (info.IsCubemap())
{ {
wprintf((info.arraySize > 6) ? L"CubeArray\n" : L"Cube\n"); wprintf(L"%ls", (info.arraySize > 6) ? L"CubeArray\n" : L"Cube\n");
} }
else else
{ {
wprintf((info.arraySize > 1) ? L"2DArray\n" : L"2D\n"); wprintf(L"%ls", (info.arraySize > 1) ? L"2DArray\n" : L"2D\n");
} }
break; break;
@ -3643,7 +3643,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (info.depth > 1) if (info.depth > 1)
{ {
wprintf(L"Writing by mip (%3Iu) and slice (%3Iu)...", info.mipLevels, info.depth); wprintf(L"Writing by mip (%3zu) and slice (%3zu)...", info.mipLevels, info.depth);
size_t depth = info.depth; size_t depth = info.depth;
for (size_t mip = 0; mip < info.mipLevels; ++mip) for (size_t mip = 0; mip < info.mipLevels; ++mip)
@ -3654,7 +3654,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (!img) if (!img)
{ {
wprintf(L"ERROR: Unexpected error at slice %3Iu, mip %3Iu\n", slice, mip); wprintf(L"ERROR: Unexpected error at slice %3zu, mip %3zu\n", slice, mip);
return 1; return 1;
} }
else else
@ -3662,11 +3662,11 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
wchar_t subFname[_MAX_FNAME]; wchar_t subFname[_MAX_FNAME];
if (info.mipLevels > 1) if (info.mipLevels > 1)
{ {
swprintf_s(subFname, L"%ls_slice%03Iu_mip%03Iu", fname, slice, mip); swprintf_s(subFname, L"%ls_slice%03zu_mip%03zu", fname, slice, mip);
} }
else else
{ {
swprintf_s(subFname, L"%ls_slice%03Iu", fname, slice); swprintf_s(subFname, L"%ls_slice%03zu", fname, slice);
} }
_wmakepath_s(szOutputFile, nullptr, nullptr, subFname, ext); _wmakepath_s(szOutputFile, nullptr, nullptr, subFname, ext);
@ -3687,7 +3687,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
} }
else else
{ {
wprintf(L"Writing by item (%3Iu) and mip (%3Iu)...", info.arraySize, info.mipLevels); wprintf(L"Writing by item (%3zu) and mip (%3zu)...", info.arraySize, info.mipLevels);
for (size_t item = 0; item < info.arraySize; ++item) for (size_t item = 0; item < info.arraySize; ++item)
{ {
@ -3697,7 +3697,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (!img) if (!img)
{ {
wprintf(L"ERROR: Unexpected error at item %3Iu, mip %3Iu\n", item, mip); wprintf(L"ERROR: Unexpected error at item %3zu, mip %3zu\n", item, mip);
return 1; return 1;
} }
else else
@ -3705,11 +3705,11 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
wchar_t subFname[_MAX_FNAME]; wchar_t subFname[_MAX_FNAME];
if (info.mipLevels > 1) if (info.mipLevels > 1)
{ {
swprintf_s(subFname, L"%ls_item%03Iu_mip%03Iu", fname, item, mip); swprintf_s(subFname, L"%ls_item%03zu_mip%03zu", fname, item, mip);
} }
else else
{ {
swprintf_s(subFname, L"%ls_item%03Iu", fname, item); swprintf_s(subFname, L"%ls_item%03zu", fname, item);
} }
_wmakepath_s(szOutputFile, nullptr, nullptr, subFname, ext); _wmakepath_s(szOutputFile, nullptr, nullptr, subFname, ext);
@ -3749,7 +3749,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (info.depth > 1) if (info.depth > 1)
{ {
wprintf(L"Results by mip (%3Iu) and slice (%3Iu)\n", info.mipLevels, info.depth); wprintf(L"Results by mip (%3zu) and slice (%3zu)\n", info.mipLevels, info.depth);
size_t depth = info.depth; size_t depth = info.depth;
for (size_t mip = 0; mip < info.mipLevels; ++mip) for (size_t mip = 0; mip < info.mipLevels; ++mip)
@ -3760,17 +3760,17 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (!img) if (!img)
{ {
wprintf(L"ERROR: Unexpected error at slice %3Iu, mip %3Iu\n", slice, mip); wprintf(L"ERROR: Unexpected error at slice %3zu, mip %3zu\n", slice, mip);
return 1; return 1;
} }
else else
{ {
wprintf(L"\n[%3Iu, %3Iu]:\n", mip, slice); wprintf(L"\n[%3zu, %3zu]:\n", mip, slice);
hr = DumpBCImage(*img, pixelx, pixely); hr = DumpBCImage(*img, pixelx, pixely);
if (FAILED(hr)) if (FAILED(hr))
{ {
wprintf(L"ERROR: Failed dumping image at slice %3Iu, mip %3Iu (%08X)\n", slice, mip, static_cast<unsigned int>(hr)); wprintf(L"ERROR: Failed dumping image at slice %3zu, mip %3zu (%08X)\n", slice, mip, static_cast<unsigned int>(hr));
return 1; return 1;
} }
} }
@ -3788,7 +3788,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
} }
else else
{ {
wprintf(L"Results by item (%3Iu) and mip (%3Iu)\n", info.arraySize, info.mipLevels); wprintf(L"Results by item (%3zu) and mip (%3zu)\n", info.arraySize, info.mipLevels);
for (size_t item = 0; item < info.arraySize; ++item) for (size_t item = 0; item < info.arraySize; ++item)
{ {
@ -3801,19 +3801,19 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (!img) if (!img)
{ {
wprintf(L"ERROR: Unexpected error at item %3Iu, mip %3Iu\n", item, mip); wprintf(L"ERROR: Unexpected error at item %3zu, mip %3zu\n", item, mip);
return 1; return 1;
} }
else else
{ {
if (image->GetImageCount() > 1) if (image->GetImageCount() > 1)
{ {
wprintf(L"\n[%3Iu, %3Iu]:\n", item, mip); wprintf(L"\n[%3zu, %3zu]:\n", item, mip);
} }
hr = DumpBCImage(*img, tpixelx, tpixely); hr = DumpBCImage(*img, tpixelx, tpixely);
if (FAILED(hr)) if (FAILED(hr))
{ {
wprintf(L"ERROR: Failed dumping image at item %3Iu, mip %3Iu (%08X)\n", item, mip, static_cast<unsigned int>(hr)); wprintf(L"ERROR: Failed dumping image at item %3zu, mip %3zu (%08X)\n", item, mip, static_cast<unsigned int>(hr));
return 1; return 1;
} }
} }
@ -3867,7 +3867,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (info.depth > 1) if (info.depth > 1)
{ {
wprintf(L"Results by mip (%3Iu) and slice (%3Iu)\n\n", info.mipLevels, info.depth); wprintf(L"Results by mip (%3zu) and slice (%3zu)\n\n", info.mipLevels, info.depth);
size_t depth = info.depth; size_t depth = info.depth;
for (size_t mip = 0; mip < info.mipLevels; ++mip) for (size_t mip = 0; mip < info.mipLevels; ++mip)
@ -3878,7 +3878,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (!img) if (!img)
{ {
wprintf(L"ERROR: Unexpected error at slice %3Iu, mip %3Iu\n", slice, mip); wprintf(L"ERROR: Unexpected error at slice %3zu, mip %3zu\n", slice, mip);
return 1; return 1;
} }
else else
@ -3887,11 +3887,11 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = Analyze(*img, data); hr = Analyze(*img, data);
if (FAILED(hr)) if (FAILED(hr))
{ {
wprintf(L"ERROR: Failed analyzing image at slice %3Iu, mip %3Iu (%08X)\n", slice, mip, static_cast<unsigned int>(hr)); wprintf(L"ERROR: Failed analyzing image at slice %3zu, mip %3zu (%08X)\n", slice, mip, static_cast<unsigned int>(hr));
return 1; return 1;
} }
wprintf(L"Result slice %3Iu, mip %3Iu:\n", slice, mip); wprintf(L"Result slice %3zu, mip %3zu:\n", slice, mip);
data.Print(); data.Print();
} }
@ -3901,7 +3901,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = AnalyzeBC(*img, data); hr = AnalyzeBC(*img, data);
if (FAILED(hr)) if (FAILED(hr))
{ {
wprintf(L"ERROR: Failed analyzing BC image at slice %3Iu, mip %3Iu (%08X)\n", slice, mip, static_cast<unsigned int>(hr)); wprintf(L"ERROR: Failed analyzing BC image at slice %3zu, mip %3zu (%08X)\n", slice, mip, static_cast<unsigned int>(hr));
return 1; return 1;
} }
@ -3916,7 +3916,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
} }
else else
{ {
wprintf(L"Results by item (%3Iu) and mip (%3Iu)\n\n", info.arraySize, info.mipLevels); wprintf(L"Results by item (%3zu) and mip (%3zu)\n\n", info.arraySize, info.mipLevels);
for (size_t item = 0; item < info.arraySize; ++item) for (size_t item = 0; item < info.arraySize; ++item)
{ {
@ -3926,7 +3926,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
if (!img) if (!img)
{ {
wprintf(L"ERROR: Unexpected error at item %3Iu, mip %3Iu\n", item, mip); wprintf(L"ERROR: Unexpected error at item %3zu, mip %3zu\n", item, mip);
return 1; return 1;
} }
else else
@ -3935,13 +3935,13 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = Analyze(*img, data); hr = Analyze(*img, data);
if (FAILED(hr)) if (FAILED(hr))
{ {
wprintf(L"ERROR: Failed analyzing image at item %3Iu, mip %3Iu (%08X)\n", item, mip, static_cast<unsigned int>(hr)); wprintf(L"ERROR: Failed analyzing image at item %3zu, mip %3zu (%08X)\n", item, mip, static_cast<unsigned int>(hr));
return 1; return 1;
} }
if (image->GetImageCount() > 1) if (image->GetImageCount() > 1)
{ {
wprintf(L"Result item %3Iu, mip %3Iu:\n", item, mip); wprintf(L"Result item %3zu, mip %3zu:\n", item, mip);
} }
data.Print(); data.Print();
} }
@ -3952,7 +3952,7 @@ int __cdecl wmain(_In_ int argc, _In_z_count_(argc) wchar_t* argv[])
hr = AnalyzeBC(*img, data); hr = AnalyzeBC(*img, data);
if (FAILED(hr)) if (FAILED(hr))
{ {
wprintf(L"ERROR: Failed analyzing BC image at item %3Iu, mip %3Iu (%08X)\n", item, mip, static_cast<unsigned int>(hr)); wprintf(L"ERROR: Failed analyzing BC image at item %3zu, mip %3zu (%08X)\n", item, mip, static_cast<unsigned int>(hr));
return 1; return 1;
} }