These functions perform file I/O for .DDS files. These functions support many legacy Direct3D 9 .DDS files and all Direct3D 10.x/11.x era "DX10" extension .DDS files

GetMetadataFromDDSMemory
GetMetadataFromDDSFile
Returns the TexMetadata from a .DDS file.

HRESULT GetMetadataFromDDSMemory( _In_reads_bytes_(size) LPCVOID pSource,
    _In_ size_t size, _In_ DWORD flags,
    _Out_ TexMetadata& metadata );

HRESULT GetMetadataFromDDSFile( _In_z_ LPCWSTR szFile,
    _In_ DWORD flags, _Out_ TexMetadata& metadata );

LoadFromDDSMemory
LoadFromDDSFile
Loads a .DDS file.

HRESULT LoadFromDDSMemory( _In_reads_bytes_(size) LPCVOID pSource,
    _In_ size_t size, _In_ DWORD flags,
    _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );

HRESULT LoadFromDDSFile( _In_z_ LPCWSTR szFile,
    _In_ DWORD flags,
    _Out_opt_ TexMetadata* metadata, _Out_ ScratchImage& image );

SaveToDDSMemory
SaveToDDSFile
Saves a single image or a set of images to a .DDS file.

HRESULT SaveToDDSMemory( _In_ const Image& image, _In_ DWORD flags,
    _Out_ Blob& blob );

HRESULT SaveToDDSMemory( _In_reads_(nimages) const Image* images,
    _In_ size_t nimages, _In_ const TexMetadata& metadata, _In_ DWORD flags,
    _Out_ Blob& blob );

HRESULT SaveToDDSFile( _In_ const Image& image, _In_ DWORD flags
     _In_z_ LPCWSTR szFile );

HRESULT SaveToDDSFile( _In_reads_(nimages) const Image* images, _In_ size_t nimages,
    _In_ const TexMetadata& metadata, _In_ DWORD flags, _In_z_ LPCWSTR szFile );

Examples

This is a simple loading example. A DDS file can potentially include any kind of Direct3D resource in any DXGI format, so the TexMetadata info is needed to understand the full content of the file.

TexMetadata info;
unique_ptr<ScratchImage> image ( new ScratchImage );
HRESULT hr = LoadFromDDSFile( L"TEXTURE.DDS", DDS_FLAGS_NONE, &info, *image );
if ( FAILED(hr) )
    // error

When saving a DDS file, it can contain one or more images (mipmaps, arrays, volumes, cubemaps, etc.).
Therefore, the writer needs the TexMetadata info to know how to interpret the image set.

const Image* img = image->GetImages();
assert( img );
size_t nimg = image->GetImageCount();
assert( nimg > 0 );
HRESULT hr = SaveToDDSFile( img, nimg, image->GetMetadata(),
     DDS_FLAGS_NONE, L"NEW_TEXTURE.DDS" );
if ( FAILED(hr) )
    // error

You can also save data directly from memory without using the intermediate ScratchImage at all. This example assumes a single 2D image is being written out.

Image img;
img.width = /*<width of pixel data>*/;
img.height = /*<height of pixel data>*/;
img.format = /*<any DXGI format>*/;
img.rowPitch = /*<number of bytes in a scanline of the source data>*/;
img.slicePitch = /*<number of bytes in the entire 2D image>*/;
img.pixels = /*<pointer to pixel data>*/;
HRESULT hr = SaveToDDSFile( img, DDS_FLAGS_NONE, L"NEW_TEXTURE.DDS" );
if ( FAILED(hr) )
    // error

Related Flags

Remarks

Many older Direct3D 9 formats that do not directly map to DXGI formats are converted at load-time. For example, D3DFMT_R8G8B8 is always converted to DXGI_FORMAT_R8G8B8A8_UNORM since there is no 24bpp DXGI format.

The 'DX10' header is not supported by D3DX9, older Direct3D 9 era texture tools, or the legacy DirectX SDK DXTex.exe tool. Therefore, the default behavior is to prefer to use 'legacy' pixel formats when possible.

Note that for Direct3D 11.1 video formats, only DXGI_FORMAT_YUY2 is supported by Direct3D 9. Legacy DDS files containing FourCC "UYVY" are converted to YUY2 at load-time.

Windows Store apps

Load

If you wish to load a texture from a file that is specified by the user from a WinRT picker, you will need to copy the file locally to a temporary location before you can use LoadFromDDSFile on it. This is because you either won't have file access rights to the user's file location, or the StorageFile is actually not a local file system path (i.e. it's a URL).

create_task(openPicker->PickSingleFileAsync()).then([this](StorageFile^ file)
{
    if (file)
    {
        auto tempFolder = Windows::Storage::ApplicationData::Current->TemporaryFolder;
        create_task(file->CopyAsync( tempFolder, file->Name, NameCollisionOption::GenerateUniqueName )).then([this](StorageFile^ tempFile)
        {
            if ( tempFile )
            {
                HRESULT hr = LoadFromDDSFile( ..., tempFile->Path->Data(), ... );
                DX::ThrowIfFailed(hr);
            }
        });
    });

http://msdn.microsoft.com/en-us/library/windows/apps/hh758319.aspx

Save

For SaveToDDSFile to succeed, the application must have write access to the destination path. For Windows Store apps, the file access permissions are rather restricted so you'll need to make sure you use a fully qualified path to a valid write folder. A good location to use is the app data folder:

auto folder = Windows::Storage::ApplicationData::Current->LocalFolder;
// use folder->Path->Data() as the path base

If you are going to immediately copy it to another location via StorageFolder, then use the app's temporary folder:

auto folder = Windows::Storage::ApplicationData::Current->TemporaryFolder;
// use folder->Path->Data() as the path base

http://msdn.microsoft.com/en-us/library/windows/apps/hh967755.aspx