@@ -23,34 +23,6 @@ using namespace Xbox;
23
23
24
24
namespace
25
25
{
26
- const DDS_PIXELFORMAT DDSPF_XBOX =
27
- { sizeof (DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC (' X' ,' B' ,' O' ,' X' ), 0 , 0 , 0 , 0 , 0 };
28
-
29
- #pragma pack(push,1)
30
-
31
- struct DDS_HEADER_XBOX
32
- // Must match structure in XboxDDSTextureLoader module
33
- {
34
- DXGI_FORMAT dxgiFormat;
35
- uint32_t resourceDimension;
36
- uint32_t miscFlag; // see DDS_RESOURCE_MISC_FLAG
37
- uint32_t arraySize;
38
- uint32_t miscFlags2; // see DDS_MISC_FLAGS2
39
- uint32_t tileMode; // see XG_TILE_MODE / XG_SWIZZLE_MODE
40
- uint32_t baseAlignment;
41
- uint32_t dataSize;
42
- uint32_t xdkVer; // matching _XDK_VER / _GXDK_VER
43
- };
44
-
45
- #pragma pack(pop)
46
-
47
- constexpr uint32_t XBOX_TILEMODE_SCARLETT = 0x1000000 ;
48
-
49
- static_assert (sizeof (DDS_HEADER_XBOX) == 36 , " DDS XBOX Header size mismatch" );
50
- static_assert (sizeof (DDS_HEADER_XBOX) >= sizeof (DDS_HEADER_DXT10), " DDS XBOX Header should be larger than DX10 header" );
51
-
52
- constexpr size_t XBOX_HEADER_SIZE = sizeof (uint32_t ) + sizeof (DDS_HEADER) + sizeof (DDS_HEADER_XBOX);
53
-
54
26
// -------------------------------------------------------------------------------------
55
27
// Decodes DDS header using XBOX extended header (variant of DX10 header)
56
28
// -------------------------------------------------------------------------------------
@@ -86,7 +58,7 @@ namespace
86
58
*ddPixelFormat = {};
87
59
}
88
60
89
- if (size < ( sizeof (DDS_HEADER) + sizeof ( uint32_t )) )
61
+ if (size < DDS_MIN_HEADER_SIZE )
90
62
{
91
63
return HRESULT_FROM_WIN32 (ERROR_INVALID_DATA);
92
64
}
@@ -120,13 +92,13 @@ namespace
120
92
}
121
93
122
94
// Buffer must be big enough for both headers and magic value
123
- if (size < XBOX_HEADER_SIZE )
95
+ if (size < DDS_XBOX_HEADER_SIZE )
124
96
{
125
97
return E_FAIL;
126
98
}
127
99
128
100
auto xboxext = reinterpret_cast <const DDS_HEADER_XBOX*>(
129
- reinterpret_cast <const uint8_t *>(pSource) + sizeof ( uint32_t ) + sizeof (DDS_HEADER) );
101
+ reinterpret_cast <const uint8_t *>(pSource) + DDS_MIN_HEADER_SIZE );
130
102
131
103
metadata.arraySize = xboxext->arraySize ;
132
104
if (metadata.arraySize == 0 )
@@ -263,7 +235,7 @@ HRESULT Xbox::EncodeDDSHeader(
263
235
if (!pDestination)
264
236
return E_INVALIDARG;
265
237
266
- if (maxsize < XBOX_HEADER_SIZE )
238
+ if (maxsize < DDS_XBOX_HEADER_SIZE )
267
239
return E_NOT_SUFFICIENT_BUFFER;
268
240
269
241
*reinterpret_cast <uint32_t *>(pDestination) = DDS_MAGIC;
@@ -492,16 +464,16 @@ HRESULT Xbox::GetMetadataFromDDSFileEx(
492
464
}
493
465
494
466
// Need at least enough data to fill the standard header and magic number to be a valid DDS
495
- if (fileInfo.EndOfFile .LowPart < ( sizeof (DDS_HEADER) + sizeof ( uint32_t )) )
467
+ if (fileInfo.EndOfFile .LowPart < DDS_MIN_HEADER_SIZE )
496
468
{
497
469
return E_FAIL;
498
470
}
499
471
500
472
// Read the header in (including extended header if present)
501
- uint8_t header[XBOX_HEADER_SIZE ] = {};
473
+ uint8_t header[DDS_XBOX_HEADER_SIZE ] = {};
502
474
503
475
DWORD bytesRead = 0 ;
504
- if (!ReadFile (hFile.get (), header, XBOX_HEADER_SIZE , &bytesRead, nullptr ))
476
+ if (!ReadFile (hFile.get (), header, DDS_XBOX_HEADER_SIZE , &bytesRead, nullptr ))
505
477
{
506
478
return HRESULT_FROM_WIN32 (GetLastError ());
507
479
}
@@ -567,13 +539,13 @@ HRESULT Xbox::LoadFromDDSMemoryEx(
567
539
return E_FAIL;
568
540
}
569
541
570
- if (size <= XBOX_HEADER_SIZE )
542
+ if (size <= DDS_XBOX_HEADER_SIZE )
571
543
{
572
544
return E_FAIL;
573
545
}
574
546
575
547
// Copy tiled data
576
- const size_t remaining = size - XBOX_HEADER_SIZE ;
548
+ const size_t remaining = size - DDS_XBOX_HEADER_SIZE ;
577
549
578
550
if (remaining < dataSize)
579
551
{
@@ -586,7 +558,7 @@ HRESULT Xbox::LoadFromDDSMemoryEx(
586
558
587
559
assert (xbox.GetPointer () != nullptr );
588
560
589
- memcpy (xbox.GetPointer (), reinterpret_cast <const uint8_t *>(pSource) + XBOX_HEADER_SIZE , dataSize);
561
+ memcpy (xbox.GetPointer (), reinterpret_cast <const uint8_t *>(pSource) + DDS_XBOX_HEADER_SIZE , dataSize);
590
562
591
563
if (metadata)
592
564
memcpy (metadata, &mdata, sizeof (TexMetadata));
@@ -645,16 +617,16 @@ HRESULT Xbox::LoadFromDDSFileEx(
645
617
}
646
618
647
619
// Need at least enough data to fill the standard header and magic number to be a valid DDS
648
- if (fileInfo.EndOfFile .LowPart < ( sizeof (DDS_HEADER) + sizeof ( uint32_t )) )
620
+ if (fileInfo.EndOfFile .LowPart < DDS_MIN_HEADER_SIZE )
649
621
{
650
622
return E_FAIL;
651
623
}
652
624
653
625
// Read the header in (including extended header if present)
654
- uint8_t header[XBOX_HEADER_SIZE ] = {};
626
+ uint8_t header[DDS_XBOX_HEADER_SIZE ] = {};
655
627
656
628
DWORD bytesRead = 0 ;
657
- if (!ReadFile (hFile.get (), header, XBOX_HEADER_SIZE , &bytesRead, nullptr ))
629
+ if (!ReadFile (hFile.get (), header, DDS_XBOX_HEADER_SIZE , &bytesRead, nullptr ))
658
630
{
659
631
return HRESULT_FROM_WIN32 (GetLastError ());
660
632
}
@@ -678,7 +650,7 @@ HRESULT Xbox::LoadFromDDSFileEx(
678
650
}
679
651
680
652
// Read tiled data
681
- const DWORD remaining = fileInfo.EndOfFile .LowPart - XBOX_HEADER_SIZE ;
653
+ const DWORD remaining = fileInfo.EndOfFile .LowPart - DDS_XBOX_HEADER_SIZE ;
682
654
if (remaining == 0 )
683
655
return E_FAIL;
684
656
@@ -717,24 +689,24 @@ HRESULT Xbox::SaveToDDSMemory(const XboxImage& xbox, Blob& blob)
717
689
718
690
blob.Release ();
719
691
720
- HRESULT hr = blob.Initialize (XBOX_HEADER_SIZE + xbox.GetSize ());
692
+ HRESULT hr = blob.Initialize (DDS_XBOX_HEADER_SIZE + xbox.GetSize ());
721
693
if (FAILED (hr))
722
694
return hr;
723
695
724
696
// Copy header
725
697
auto pDestination = reinterpret_cast <uint8_t *>(blob.GetBufferPointer ());
726
698
assert (pDestination);
727
699
728
- hr = EncodeDDSHeader (xbox, pDestination, XBOX_HEADER_SIZE );
700
+ hr = EncodeDDSHeader (xbox, pDestination, DDS_XBOX_HEADER_SIZE );
729
701
if (FAILED (hr))
730
702
{
731
703
blob.Release ();
732
704
return hr;
733
705
}
734
706
735
707
// Copy tiled data
736
- const size_t remaining = blob.GetBufferSize () - XBOX_HEADER_SIZE ;
737
- pDestination += XBOX_HEADER_SIZE ;
708
+ const size_t remaining = blob.GetBufferSize () - DDS_XBOX_HEADER_SIZE ;
709
+ pDestination += DDS_XBOX_HEADER_SIZE ;
738
710
739
711
if (!remaining)
740
712
{
@@ -764,8 +736,8 @@ HRESULT Xbox::SaveToDDSFile(const XboxImage& xbox, const wchar_t* szFile)
764
736
return E_INVALIDARG;
765
737
766
738
// Create DDS Header
767
- uint8_t header[XBOX_HEADER_SIZE ] = {};
768
- HRESULT hr = EncodeDDSHeader (xbox, header, XBOX_HEADER_SIZE );
739
+ uint8_t header[DDS_XBOX_HEADER_SIZE ] = {};
740
+ HRESULT hr = EncodeDDSHeader (xbox, header, DDS_XBOX_HEADER_SIZE );
769
741
if (FAILED (hr))
770
742
return hr;
771
743
@@ -783,12 +755,12 @@ HRESULT Xbox::SaveToDDSFile(const XboxImage& xbox, const wchar_t* szFile)
783
755
}
784
756
785
757
DWORD bytesWritten;
786
- if (!WriteFile (hFile.get (), header, static_cast <DWORD>(XBOX_HEADER_SIZE ), &bytesWritten, nullptr ))
758
+ if (!WriteFile (hFile.get (), header, static_cast <DWORD>(DDS_XBOX_HEADER_SIZE ), &bytesWritten, nullptr ))
787
759
{
788
760
return HRESULT_FROM_WIN32 (GetLastError ());
789
761
}
790
762
791
- if (bytesWritten != XBOX_HEADER_SIZE )
763
+ if (bytesWritten != DDS_XBOX_HEADER_SIZE )
792
764
{
793
765
return E_FAIL;
794
766
}
0 commit comments