@@ -1261,6 +1261,10 @@ private ColorRgba32[][] DecodeInternal(DdsFile file, bool allMipMaps, Cancellati
1261
1261
/// <returns>The decoded Rgba32 image.</returns>
1262
1262
private ColorRgba32 [ ] DecodeRawInternal ( ReadOnlyMemory < byte > input , int pixelWidth , int pixelHeight , CompressionFormat format , CancellationToken token )
1263
1263
{
1264
+ if ( format == CompressionFormat . Unknown )
1265
+ {
1266
+ throw new ArgumentException ( $ "Unsupported compression format: { format } ") ;
1267
+ }
1264
1268
if ( input . Length % GetBlockSize ( format ) != 0 )
1265
1269
{
1266
1270
throw new ArgumentException ( "The size of the input buffer does not align with the compression format." ) ;
@@ -1387,6 +1391,11 @@ private Memory2D<ColorRgbFloat>[] DecodeFromStreamInternalHdr2D(Stream stream, b
1387
1391
/// <returns>An array of decoded Rgba32 images.</returns>
1388
1392
private ColorRgbFloat [ ] [ ] DecodeInternalHdr ( KtxFile file , bool allMipMaps , CancellationToken token )
1389
1393
{
1394
+ if ( GetCompressionFormat ( file . header . GlInternalFormat ) == CompressionFormat . Unknown )
1395
+ {
1396
+ throw new ArgumentException ( $ "Unsupported compression format: { file . header . GlInternalFormat } ") ;
1397
+ }
1398
+
1390
1399
var mipMaps = allMipMaps ? file . MipMaps . Count : 1 ;
1391
1400
var colors = new ColorRgbFloat [ mipMaps ] [ ] ;
1392
1401
@@ -1439,7 +1448,25 @@ private ColorRgbFloat[][] DecodeInternalHdr(KtxFile file, bool allMipMaps, Cance
1439
1448
/// <returns>An array of decoded Rgba32 images.</returns>
1440
1449
private ColorRgbFloat [ ] [ ] DecodeInternalHdr ( DdsFile file , bool allMipMaps , CancellationToken token )
1441
1450
{
1451
+ if ( file == null )
1452
+ {
1453
+ throw new ArgumentNullException ( nameof ( file ) ) ;
1454
+ }
1455
+
1456
+ var dxtFormat = file . header . ddsPixelFormat . IsDxt10Format
1457
+ ? file . dx10Header . dxgiFormat
1458
+ : file . header . ddsPixelFormat . DxgiFormat ;
1459
+
1460
+ if ( GetCompressionFormat ( file ) == CompressionFormat . Unknown )
1461
+ {
1462
+ throw new ArgumentException ( $ "Unsupported compression format: { dxtFormat } ") ;
1463
+ }
1464
+
1442
1465
var mipMaps = allMipMaps ? file . header . dwMipMapCount : 1 ;
1466
+
1467
+ // Assume at least 1 mip map
1468
+ mipMaps = Math . Max ( 1 , mipMaps ) ;
1469
+
1443
1470
var colors = new ColorRgbFloat [ mipMaps ] [ ] ;
1444
1471
1445
1472
var context = new OperationContext
@@ -1455,9 +1482,7 @@ private ColorRgbFloat[][] DecodeInternalHdr(DdsFile file, bool allMipMaps, Cance
1455
1482
1456
1483
context . Progress = new OperationProgress ( Options . Progress , totalBlocks ) ;
1457
1484
1458
- var dxtFormat = file . header . ddsPixelFormat . IsDxt10Format
1459
- ? file . dx10Header . dxgiFormat
1460
- : file . header . ddsPixelFormat . DxgiFormat ;
1485
+
1461
1486
var format = GetCompressionFormat ( file ) ;
1462
1487
var decoder = GetRgbFloatDecoder ( format ) ;
1463
1488
@@ -1499,6 +1524,10 @@ private ColorRgbFloat[][] DecodeInternalHdr(DdsFile file, bool allMipMaps, Cance
1499
1524
/// <returns>The decoded Rgba32 image.</returns>
1500
1525
private ColorRgbFloat [ ] DecodeRawInternalHdr ( ReadOnlyMemory < byte > input , int pixelWidth , int pixelHeight , CompressionFormat format , CancellationToken token )
1501
1526
{
1527
+ if ( format == CompressionFormat . Unknown )
1528
+ {
1529
+ throw new ArgumentException ( $ "Unsupported compression format: { format } ") ;
1530
+ }
1502
1531
if ( input . Length % GetBlockSize ( format ) != 0 )
1503
1532
{
1504
1533
throw new ArgumentException ( "The size of the input buffer does not align with the compression format." ) ;
0 commit comments