Skip to content

Commit 2f37de7

Browse files
authored
Minor code review change for PPM/PFM code (#548)
1 parent 4602b8e commit 2f37de7

6 files changed

+39
-3
lines changed

DDSTextureLoader/DDSTextureLoader11.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ namespace
502502
_In_ size_t width,
503503
_In_ size_t height,
504504
_In_ DXGI_FORMAT fmt,
505-
size_t* outNumBytes,
505+
_Out_opt_ size_t* outNumBytes,
506506
_Out_opt_ size_t* outRowBytes,
507507
_Out_opt_ size_t* outNumRows) noexcept
508508
{
@@ -516,6 +516,9 @@ namespace
516516
size_t bpe = 0;
517517
switch (fmt)
518518
{
519+
case DXGI_FORMAT_UNKNOWN:
520+
return E_INVALIDARG;
521+
519522
case DXGI_FORMAT_BC1_TYPELESS:
520523
case DXGI_FORMAT_BC1_UNORM:
521524
case DXGI_FORMAT_BC1_UNORM_SRGB:
@@ -569,6 +572,15 @@ namespace
569572
bpe = 2;
570573
break;
571574

575+
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
576+
577+
case DXGI_FORMAT_P208:
578+
planar = true;
579+
bpe = 2;
580+
break;
581+
582+
#endif
583+
572584
case DXGI_FORMAT_P010:
573585
case DXGI_FORMAT_P016:
574586
if ((height % 2) != 0)

DDSTextureLoader/DDSTextureLoader12.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ namespace
581581
_In_ size_t width,
582582
_In_ size_t height,
583583
_In_ DXGI_FORMAT fmt,
584-
size_t* outNumBytes,
584+
_Out_opt_ size_t* outNumBytes,
585585
_Out_opt_ size_t* outRowBytes,
586586
_Out_opt_ size_t* outNumRows) noexcept
587587
{
@@ -595,6 +595,9 @@ namespace
595595
size_t bpe = 0;
596596
switch (fmt)
597597
{
598+
case DXGI_FORMAT_UNKNOWN:
599+
return E_INVALIDARG;
600+
598601
case DXGI_FORMAT_BC1_TYPELESS:
599602
case DXGI_FORMAT_BC1_UNORM:
600603
case DXGI_FORMAT_BC1_UNORM_SRGB:

DDSTextureLoader/DDSTextureLoader9.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ namespace
416416
_In_ size_t width,
417417
_In_ size_t height,
418418
_In_ D3DFORMAT fmt,
419-
size_t* outNumBytes,
419+
_Out_opt_ size_t* outNumBytes,
420420
_Out_opt_ size_t* outRowBytes,
421421
_Out_opt_ size_t* outNumRows) noexcept
422422
{
@@ -429,6 +429,9 @@ namespace
429429
size_t bpe = 0;
430430
switch (static_cast<int>(fmt))
431431
{
432+
case D3DFMT_UNKNOWN:
433+
return E_INVALIDARG;
434+
432435
case D3DFMT_DXT1:
433436
bc = true;
434437
bpe = 8;

DirectXTex/DirectXTexCompressGPU.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ HRESULT DirectX::CompressEx(
261261
|| IsTypeless(srcImage.format) || IsPlanar(srcImage.format) || IsPalettized(srcImage.format))
262262
return HRESULT_E_NOT_SUPPORTED;
263263

264+
if (!srcImage.pixels)
265+
return E_POINTER;
266+
264267
// Setup GPU compressor
265268
std::unique_ptr<GPUCompressBC> gpubc(new (std::nothrow) GPUCompressBC);
266269
if (!gpubc)

DirectXTex/DirectXTexUtil.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,9 @@ HRESULT DirectX::ComputePitch(DXGI_FORMAT fmt, size_t width, size_t height,
972972

973973
switch (static_cast<int>(fmt))
974974
{
975+
case DXGI_FORMAT_UNKNOWN:
976+
return E_INVALIDARG;
977+
975978
case DXGI_FORMAT_BC1_TYPELESS:
976979
case DXGI_FORMAT_BC1_UNORM:
977980
case DXGI_FORMAT_BC1_UNORM_SRGB:
@@ -1192,6 +1195,9 @@ size_t DirectX::ComputeScanlines(DXGI_FORMAT fmt, size_t height) noexcept
11921195
{
11931196
switch (static_cast<int>(fmt))
11941197
{
1198+
case DXGI_FORMAT_UNKNOWN:
1199+
return 0;
1200+
11951201
case DXGI_FORMAT_BC1_TYPELESS:
11961202
case DXGI_FORMAT_BC1_UNORM:
11971203
case DXGI_FORMAT_BC1_UNORM_SRGB:

Texconv/PortablePixMap.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ namespace
8686

8787
HRESULT ReadData(_In_z_ const wchar_t* szFile, std::unique_ptr<uint8_t[]>& blob, size_t& blobSize)
8888
{
89+
if (!szFile)
90+
return E_INVALIDARG;
91+
8992
blob.reset();
9093

9194
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
@@ -361,6 +364,9 @@ HRESULT __cdecl SaveToPortablePixMap(
361364
_In_ const Image& image,
362365
_In_z_ const wchar_t* szFile) noexcept
363366
{
367+
if (!szFile)
368+
return E_INVALIDARG;
369+
364370
switch (image.format)
365371
{
366372
case DXGI_FORMAT_R8G8B8A8_UNORM:
@@ -688,6 +694,9 @@ HRESULT __cdecl SaveToPortablePixMapHDR(
688694
_In_ const Image& image,
689695
_In_z_ const wchar_t* szFile) noexcept
690696
{
697+
if (!szFile)
698+
return E_INVALIDARG;
699+
691700
switch (image.format)
692701
{
693702
case DXGI_FORMAT_R32G32B32A32_FLOAT:

0 commit comments

Comments
 (0)