Quantcast
Viewing all 1174 articles
Browse latest View live

New Post: How to use DirectXTex's CopyRectangle ?

I want to get Image2 from Image1.

Finally, The output of Image2 is empty.

I need your suggestion.

Below is my code and pictrue to define variable.

Image may be NSFW.
Clik here to view.
Image

DirectX::ScratchImage DxImage;
HRESULT hr_0 = DirectX::CaptureTexture(  m_d3dDevice.Get() , m_d3dContext.Get() , d3DTexture.Get() , DxImage );
const Image* mage_1 = DxImage.GetImages();
Image Image_2;
        
DirectX::Rect rect( x1, y1, x2, y2 );
DirectX::CopyRectangle( *Image_1.GetImages(), rect , Image_2 , DirectX::TEX_FILTER_DEFAULT, x1, y1);

New Post: How to use DirectXTex's CopyRectangle ?

using namespace DirectX;

ScratchImage DxImage;
HRESULT hr = CaptureTexture(  m_d3dDevice.Get() , m_d3dContext.Get() , d3DTexture.Get() , DxImage );
DX:ThrowIfFailed( hr );

const Image* Image_1 = DxImage.GetImages();

TexMetadata mdata = DxImage.GetMetadata();
mdata.width = x2 - x1 + 1;
mdata.height = y2 - y2 + 1;

ScratchImage CropImage;
hr = CropImage.Initialize( mdata );
DX:ThrowIfFailed( hr );

const Image* Image_2 = CropImage.GetImages();

Rect rect( x1, y1, mdata.width, mdata.height );
hr = CopyRectangle( *Image_1, rect, *Image_2, DirectX::TEX_FILTER_DEFAULT, 0, 0);
DX:ThrowIfFailed( hr );

Commented Unassigned: How to use DirectXTex's CopyRectangle ? [1103]

I want to get Image2 from Image1.

Finally, The output of Image2 is empty.

I need your suggestion.

Below is my code and pictrue to define variable.

![Image](http://social.msdn.microsoft.com/Forums/getfile/403190)
```
DirectX::ScratchImage DxImage;
HRESULT hr_0 = DirectX::CaptureTexture( m_d3dDevice.Get() , m_d3dContext.Get() , d3DTexture.Get() , DxImage );
const Image* mage_1 = DxImage.GetImages();
Image Image_2;

DirectX::Rect rect( x1, y1, x2, y2 );
DirectX::CopyRectangle( *Image_1.GetImages(), rect , Image_2 , DirectX::TEX_FILTER_DEFAULT, x1, y1);
```
Comments: ** Comment from web user: walbourn **

This is more a 'Discussion' than an issue... The 'Issues' area is for feature requests, code bugs, etc. The functionality for doing a 'crop' is already present in the library. Moved to discussion thread [528337](https://directxtex.codeplex.com/discussions/528337).

Reopened Unassigned: How to use DirectXTex's CopyRectangle ? [1103]

I want to get Image2 from Image1.

Finally, The output of Image2 is empty.

I need your suggestion.

Below is my code and pictrue to define variable.

![Image](http://social.msdn.microsoft.com/Forums/getfile/403190)
```
DirectX::ScratchImage DxImage;
HRESULT hr_0 = DirectX::CaptureTexture( m_d3dDevice.Get() , m_d3dContext.Get() , d3DTexture.Get() , DxImage );
const Image* mage_1 = DxImage.GetImages();
Image Image_2;

DirectX::Rect rect( x1, y1, x2, y2 );
DirectX::CopyRectangle( *Image_1.GetImages(), rect , Image_2 , DirectX::TEX_FILTER_DEFAULT, x1, y1);
```

Closed Unassigned: How to use DirectXTex's CopyRectangle ? [1103]

I want to get Image2 from Image1.

Finally, The output of Image2 is empty.

I need your suggestion.

Below is my code and pictrue to define variable.

![Image](http://social.msdn.microsoft.com/Forums/getfile/403190)
```
DirectX::ScratchImage DxImage;
HRESULT hr_0 = DirectX::CaptureTexture( m_d3dDevice.Get() , m_d3dContext.Get() , d3DTexture.Get() , DxImage );
const Image* mage_1 = DxImage.GetImages();
Image Image_2;

DirectX::Rect rect( x1, y1, x2, y2 );
DirectX::CopyRectangle( *Image_1.GetImages(), rect , Image_2 , DirectX::TEX_FILTER_DEFAULT, x1, y1);
```
Comments: This is more a 'Discussion' than an issue... The 'Issues' area is for feature requests, code bugs, etc. The functionality for doing a 'crop' is already present in the library. Moved to discussion thread 528337.

Commented Unassigned: How to use DirectXTex's CopyRectangle ? [1103]

I want to get Image2 from Image1.

Finally, The output of Image2 is empty.

I need your suggestion.

Below is my code and pictrue to define variable.

![Image](http://social.msdn.microsoft.com/Forums/getfile/403190)
```
DirectX::ScratchImage DxImage;
HRESULT hr_0 = DirectX::CaptureTexture( m_d3dDevice.Get() , m_d3dContext.Get() , d3DTexture.Get() , DxImage );
const Image* mage_1 = DxImage.GetImages();
Image Image_2;

DirectX::Rect rect( x1, y1, x2, y2 );
DirectX::CopyRectangle( *Image_1.GetImages(), rect , Image_2 , DirectX::TEX_FILTER_DEFAULT, x1, y1);
```
Comments: ** Comment from web user: walbourn **

This is more a 'Discussion' than an issue... The 'Issues' area is for feature requests, code bugs, etc. The functionality for doing a 'crop' is already present in the library. Moved to discussion thread [528337](https://directxtex.codeplex.com/discussions/528337).

(sorry, had created the discussion in DirectXTK rather than DirectXTex. Fixed).

Updated Wiki: CopyRectangle

Copies a rectangle of pixels from one image to another.

Block compressed images are not supported as either the source or destination. Use Decompress to uncompress BC images before using this function.

HRESULT CopyRectangle( _In_ const Image& srcImage, _In_ const Rect& srcRect,
   _In_ const Image& dstImage,
   _In_ DWORD filter, _In_ size_t xOffset, _In_ size_t yOffset );

Parameters

srcRect: A rectangle described with x, y of the upper right corner, and w and h with the width and height, which indicates pixel location from srcImage to copy. The w and h also define the size of the destination rectangle in dstImage. Both rectangles must be valid for the size of the images (i.e. the API does not support clipping).

filter: See Filter Flags. Source and destination images do not need to be the same format, in which case conversions will use these flags.

xOffset, yOffset: Pixel location of destination rectangle in dstImage. The width and height of the destination rectangle is the same as srcRect.w and srcRect.h.

Remarks

Behavior of this function is not defined if the source and destination image are the same and the source and destination rectangles overlap.

Reopened Unassigned: How to use DirectXTex's CopyRectangle ? [1103]

I want to get Image2 from Image1.

Finally, The output of Image2 is empty.

I need your suggestion.

Below is my code and pictrue to define variable.

![Image](http://social.msdn.microsoft.com/Forums/getfile/403190)
```
DirectX::ScratchImage DxImage;
HRESULT hr_0 = DirectX::CaptureTexture( m_d3dDevice.Get() , m_d3dContext.Get() , d3DTexture.Get() , DxImage );
const Image* mage_1 = DxImage.GetImages();
Image Image_2;

DirectX::Rect rect( x1, y1, x2, y2 );
DirectX::CopyRectangle( *Image_1.GetImages(), rect , Image_2 , DirectX::TEX_FILTER_DEFAULT, x1, y1);
```

Closed Unassigned: How to use DirectXTex's CopyRectangle ? [1103]

I want to get Image2 from Image1.

Finally, The output of Image2 is empty.

I need your suggestion.

Below is my code and pictrue to define variable.

![Image](http://social.msdn.microsoft.com/Forums/getfile/403190)
```
DirectX::ScratchImage DxImage;
HRESULT hr_0 = DirectX::CaptureTexture( m_d3dDevice.Get() , m_d3dContext.Get() , d3DTexture.Get() , DxImage );
const Image* mage_1 = DxImage.GetImages();
Image Image_2;

DirectX::Rect rect( x1, y1, x2, y2 );
DirectX::CopyRectangle( *Image_1.GetImages(), rect , Image_2 , DirectX::TEX_FILTER_DEFAULT, x1, y1);
```
Comments: Note there is also a detail page in the docs now for CopyRectangle.

Updated Wiki: CopyRectangle

Copies a rectangle of pixels from one image to another.

Block compressed images are not supported as either the source or destination. Use Decompress to uncompress BC images before using this function.

HRESULT CopyRectangle( _In_ const Image& srcImage, _In_ const Rect& srcRect,
   _In_ const Image& dstImage,
   _In_ DWORD filter, _In_ size_t xOffset, _In_ size_t yOffset );

Parameters

srcRect: A rectangle described with x, y of the upper right corner, and w and h with the width and height, which indicates pixel location from srcImage to copy. The w and h also define the size of the destination rectangle in dstImage. Both rectangles must be valid for the size of the images (i.e. the API does not support clipping).

filter: See Filter Flags. Source and destination images do not need to be the same format, in which case conversions will use these flags.

xOffset, yOffset: Pixel location of destination rectangle in dstImage. The width and height of the destination rectangle is the same as srcRect.w and srcRect.h.

Example

Here's an example that copies a source image to the location (100,50) location in a new, larger image.

ScratchImage srcImage;

...

ScratchImage destImage;
destImage.Iniitalize2D( ... );

auto mdata = srcImage.GetMetadata();
Rect r( 0, 0, mdata.width, mdata.height );
hr = CopyRectangle( *srcImage.GetImage(0,0,0), r, *dstImage.GetImage(0,0,0), 
   TEX_DEFAULT_FILTER, 100, 50 );
if ( FAILED(hr) )
    ...

Remarks

Behavior of this function is not defined if the source and destination image are the same and the source and destination rectangles overlap.

Updated Wiki: CopyRectangle

Copies a rectangle of pixels from one image to another.

Block compressed images are not supported as either the source or destination. Use Decompress to uncompress BC images before using this function.

HRESULT CopyRectangle( _In_ const Image& srcImage, _In_ const Rect& srcRect,
   _In_ const Image& dstImage,
   _In_ DWORD filter, _In_ size_t xOffset, _In_ size_t yOffset );

Parameters

srcRect: A rectangle described with x, y of the upper right corner, and w and h with the width and height, which indicates pixel location from srcImage to copy. The w and h also define the size of the destination rectangle in dstImage. Both rectangles must be valid for the size of the images (i.e. the API does not support clipping).

filter: See Filter Flags. Source and destination images do not need to be the same format, in which case conversions will use these flags.

xOffset, yOffset: Pixel location of destination rectangle in dstImage. The width and height of the destination rectangle is the same as srcRect.w and srcRect.h.

Example

Here's an example that copies a source image to the location (100,50) location in a new, larger image.

ScratchImage srcImage;

...

ScratchImage destImage;
destImage.Iniitalize2D( ... );

auto mdata = srcImage.GetMetadata();
Rect r( 0, 0, mdata.width, mdata.height );
hr = CopyRectangle( *srcImage.GetImage(0,0,0), r, *dstImage.GetImage(0,0,0), 
   TEX_FILTER_DEFAULT, 100, 50 );
if ( FAILED(hr) )
    ...

Remarks

Behavior of this function is not defined if the source and destination image are the same and the source and destination rectangles overlap.

Source code checked in, #33965

Minor code fixes for some issues found by /Wall

Source code checked in, #33966

DirectXTex: Added IsVolumemap() helper to TexMetadata

Source code checked in, #34041

DDSTextureLoader/ScreenGrab: Updated with support for Direct3D 11 video formats including legacy 'YUY2' DDS files

Commented Feature: Video format support [1027]

DirectXTex currently does not support any of the DirectX 11 video formats.

* DXGI_FORMAT_AYUV
* DXGI_FORMAT_Y410
* DXGI_FORMAT_Y416
* DXGI_FORMAT_NV12
* DXGI_FORMAT_P010
* DXGI_FORMAT_P016
* DXGI_FORMAT_420_OPAQUE
* DXGI_FORMAT_YUY2
* DXGI_FORMAT_Y210
* DXGI_FORMAT_Y216
* DXGI_FORMAT_NV11
* DXGI_FORMAT_AI44
* DXGI_FORMAT_IA44
* DXGI_FORMAT_P8
* DXGI_FORMAT_A8P8

[WIC in Windows 8.1](http://msdn.microsoft.com/en-us/library/windows/desktop/dn280986(v=vs.85).aspx) has some limited support for them.

A minimal amount of support would include loading/saving with DDS files, and perhaps colorspace conversions.
Comments: Associated with changeset 34041: DDSTextureLoader/ScreenGrab: Updated with support for Direct3D 11 video formats including legacy 'YUY2' DDS files

New Post: How to use DirectXTex's CopyRectangle ?

Thank you very much. I don't known how to use wiki doc.

Created Unassigned: About SaveToWICFile save path problem?(Win8 C++/Cx) [1106]

I called SaveToWICFile to save image and assigned the desk path to save it.
The result is fall. __Error:E_ACCESSDENIED General access denied error.
So, It mean that I can't design file path arbitrarily ?
Only use ApplicationData::Current->LocalFolder... and so on ?

Updated Wiki: WIC I/O Functions

These functions use the Windows Imaging Componet (WIC) to read or write an image file. There are built-in WIC codecs in Windows for .BMP, .PNG, .GIF, .TIFF, .JPEG, and JPEG-XR / HD Photo images. Some containers (.GIF and .TIFF) can contain multi-frame bitmaps files.

GetMetadataFromWICMemory
GetMetadataFromWICFile
Returns the TexMetadata from a WIC-supported bitmap file.

LoadFromWICMemory
LoadFromWICFile
Loads a WIC-supported bitmap file.

SaveToWICMemory
SaveToWICFile
Saves a single image or a set of images to a WIC-supported bitmap file. The caller provides the desired WIC container format to use via guidContainerFormat (see Utility functions GetWICCodec for a helper). There is an optional targetFormat to specify a desired WIC pixel format (which will result in an E_FAIL if not supported by the WIC codec)

Examples

This is a simple loading example. Since it only returns a single 2D image, the TexMetadata info is redundant information.

unique_ptr<ScratchImage> image ( new ScratchImage );
HRESULT hr = LoadFromWICFile( L"WINLOGO.BMP", WIC_FLAGS_NONE, nullptr, *image );
if ( FAILED(hr) )
    // error

This is a multi-image loading example which can load an array of 2D images.

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

This is saving a simple 2D image to a specific file container. You can either use the WIC GUID directly or make use of the GetWICCodec helper. Keep in mind that WIC may convert the pixel format in the final output image, so there is an optional additional parameter you can use to request a specific storage pixel format. In this case, we want the file's pixel format to be an 8-bit per channel RGB without an alpha channel.

const Image* img = image->GetImage(0,0,0);
assert( img );
HRESULT hr = SaveToWICFile( *img, WIC_FLAGS_NONE,
    GUID_ContainerFormatPng, L"NEW_IMAGE.PNG", &GUID_WICPixelFormat24bppBGR );
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 since a JPG file cannot contain an image array.

Image img;
img.width = /*<width of pixel data>*/;
img.height = /*<height of pixel data>*/;
img.format = /*<a DXGI format that maps directly to a WIC supported 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 = SaveToWICFile( img, WIC_FLAGS_NONE, GetWICCodec(WIC_CODEC_JPEG), L"NEW_IMAGE.PNG" );
if ( FAILED(hr) )
    // error

When writing WIC files, you can also provide a callback for setting specific encoding options.

const Image* img = image->GetImage(0,0,0);
assert( img );
HRESULT hr = SaveToWICFile( *img, WIC_FLAGS_NONE,
    GUID_ContainerFormatTiff, L"NEW_IMAGE.TIF", nullptr, 
    [&](IPropertyBag2* props)
    {
        PROPBAG2 options[2] = { 0, 0 };
        options[0].pstrName = L"CompressionQuality";
        options[1].pstrName = L"TiffCompressionMethod";

        VARIANT varValues[2];
        varValues[0].vt = VT_R4;
        varValues[0].fltVal = 0.75f;

        varValues[1].vt = VT_UI1;
        varValues[1].bVal = WICTiffCompressionNone;

        (void)props->Write( 2, options, varValues ); 
    });
if ( FAILED(hr) )
    // error

Related Flags

  • WIC_FLAGS_NONE Default flags.
  • WIC_FLAGS_FORCE_RGB By default we map many BGR formats directly to DXGI 1.1 formats. Use of this flag forces the use of DXGI 1.0 RGB formats instead for improved Direct3D 10.0/Windows Vista RTM/WDDM 1.0 driver support.
  • WIC_FLAGS_NO_X2_BIAS By default GUID_WICPixelFormat32bppRGBA1010102XR is loaded as R10G10B10_XR_BIAS_A2_UNORM. Use of this flag will force it to convert to R10G10B10A2_UNORM instead.
  • WIC_FLAGS_NO_16BPP By default, 5:6:5 and 5:5:5:1 formats are returned as DXGI 1.2 formats. If this flag is used, the loader will expand these to R8G8B8A8 instead.
  • WIC_FLAGS_ALLOW_MONO By default, monochrome data is converted to greyscale. By using this flag, this data is loaded as R1_UNORM which is not supported for rendering by Direct3D.
  • WIC_FLAGS_ALL_FRAMES By default, only the first frame of a multi-frame file is loaded. If this flag is provided, all frames are loaded and resized to match the size of the first image to fit the DirectXTex requirements for a 2D array.
  • WIC_FLAGS_IGNORE_SRGB While there is no explicit 'sRGB' pixel format defined for WIC, the load function will check for known metadata tags and may return DXGI_FORMAT_*_SRGB formats if there are equivalents of the same size and channel configuration available. If this flag is specified, any 'sRGB' metadata ignored instead.

These flags control the use of dithering for image conversions. It defaults to 'no' dithering.
  • WIC_FLAGS_DITHER WIC will use 4x4 ordered dithering.
  • WIC_FLAGS_DITHER_DIFFUSION WIC will use error-diffusion (Floyd-Steinberg dithering).

These flags control the use of interpolation modes for image conversions/resizing. It defaults to "Fant"
  • WIC_FLAGS_FILTER_POINT Nearest-neighbor
  • WIC_FLAGS_FILTER_LINEAR - Bilinear interpolation
  • WIC_FLAGS_FILTER_CUBIC - Bicubic interpolation
  • WIC_FLAGS_FILTER_FANT - Fant which is equivalent to 'box' filteirng for down-scaling.

Release Notes

  • JPEG-XR / HD Photo supports nearly all WIC pixel formats including floating-point for both encoding and decoding.
  • TIFF can contain floating-point data (128bpp or 96bpp), but the WIC built-in codec can only decode such images. It always converts floating-point data to unorm when encoding. Windows 7 incorrectly handles decoding 96bpp TIFF files, which is corrected with WIC2 by returning the new format GUID_WICPixelFormat96bppRGBFloat
  • Windows WIC codec for .BMP files does not support alpha channels for 16-bit files. For 32-bit files, the alpha channel is ignored by Windows 7 or earlier. The WIC2 BMP codec can read 32-bit alpha channels if using the BITMAPV5HEADER header. DirectXTex opts into the WIC2 behavior for writing 32-bit alpha channels using the V5 header when available
  • GUID_WICPixelFormat32bppRGBE is an 8:8:8:8 format, which does not match DXGI_FORMAT_R9G9B9E5_SHAREDEXP. This WIC pixel format is therefore converted to GUID_WICPixelFormat128bppRGBAFloat and returns as DXGI_FORMAT_R32G32B32A32_FLOAT.
  • Paletted WIC formats are not supported for writing by the SaveToWIC functions.

WIC2

WIC2 is available on Windows 8 and on Windows 7 Service Pack 1 with KB 2670838 installed.
  • The WIC2 pixel format GUID_WICPixelFormat96bppRGBFloat loads as DXGI_FORMAT_R32G32B32_FLOAT. Otherwise it converts this to DXGI_FORMAT_R32G32B32A32_FLOAT.
  • Conversions cases for WIC2 pixel formats GUID_WICPixelFormat32bppRGB, GUID_WICPixelFormat64bppRGB, and GUID_WICPixelFormat64bppPRGBAHalf are included. The pixel format GUID_WICPixelFormat96bppRGBFixedPoint is converted to DXGI_FORMAT_R32G32B32_FLOAT rather than DXGI_FORMAT_R32G32B32A32_FLOAT
http://support.microsoft.com/kb/2670838

Windows Store apps

Load

If you wish to load an image 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 LoadFromWICFile 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 = LoadFromWICFile( ..., tempFile->Path->Data(), ... );
                DX::ThrowIfFailed(hr);
            }
        });
    });

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

Save

For SaveToWICFile 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

Updated Wiki: DDS I/O Functions

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.

LoadFromDDSMemory
LoadFromDDSFile
Loads a .DDS file.

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

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

  • DDS_FLAGS_NONE is the default
  • DDS_FLAGS_LEGACY_DWORD is used for loading some legacy Direct3D 8 era 24bpp .DDS files that use the non-standard DWORD alignment instead of BYTE. There's no realiable way to determine this from the file, so this requires trial-and-error.
  • DDS_FLAGS_NO_LEGACY_EXPANSION - By default the loader will expand many legacy Direct3D 9 .DDS files to supported formats. The use of this flag prevents expansions that increase the size of the pixels, and will return a failure instead.
  • DDS_FLAGS_NO_R10B10G10A2_FIXUP - By default, the loader uses a work-around for a long-standing issue with the D3DX DDS file format which reverses the RGB bit-masks for 10:10:10:2 formats. If this flag is used, then the loader instead assumes such data was written 'correctly'.
  • DDS_FLAGS_FORCE_RGB - By default we map many BGR formats directly to DXGI 1.1 formats. Use of this flag forces the use of DXGI 1.0 RGB formats instead for improved Direct3D 10.0/Windows Vista RTM/WDDM 1.0 driver support.
  • DDS_FLAGS_NO_16BPP - By default, 5:6:5, 5:5:5:1, and 4:4:4:4 formats are returned as DXGI 1.2 formats. If this flag is used, the loader will expand these to R8G8B8A8 instead.
  • DDS_FLAGS_EXPAND_LUMINANCE - By default, legacy luminance formats are mapped to the same size formats in DXGI (L8 -> R8_UNORM, L16 -> R16_UNORM, A8L8 -> R8G8_UNORM), but this requires some shader swizzling to replicate the original luminance greyscale behavior (.rrr or .rrrg)--this matches the implementation of DDSTextureLoader. Specifying this flag will instead expand these formats on load and replicate the colors to achieve the proper greyscale without any shader changes, but they will be significantly larger (8:8:8:8 or 16:16:16:16).
  • DDS_FLAGS_FORCE_DX10_EXT - When saving DDS files, the writer tries to use legacy Direct3D 9 .DDS file formats if possible rather than the 'DX10' header extension for better compatiblity with older tools. Using this flag, the writer will always generate 'DX10' extension header files which are much faster to parse at load-time. These files are compatible with the legacy D3DX10 or D3DX11 library.
  • DDS_FLAGS_FORCE_DX10_EXT_MISC2 - When saving DDS files, always use the 'DX10' header extension and write miscFlags2 data as needed, if even if the resulting file is not compatible with the legacy D3DX10 or D3DX11 libraries.

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

Updated Wiki: ScreenGrab

A Direct3D 11 2D texture save routine for generating a "screenshot" from a render target texture. There is a function that will dump the 2D texture to a .DDS file, and another that will write using WIC (BMP, JPEG, PNG, TIFF, GIF, JPEG-XR / HD Photo, or other WIC supported file container).

These writers do not support array textures, 1D textures, 3D volume textures, or cubemaps. Mipmaps are also ignored. For those scenarios, use the full DirectXTex library functionality. The ScreenGrab module is really designed to make a quick and light-weight solution for capturing screenshots at runtime.

MSAA textures are resolved before being written.

Also part of DirectXTK http://go.microsoft.com/fwlink/?LinkId=248929

Functions

SaveDDSTextureToFile
Saves a texture to a DDS file on disk. It performs no format conversions, but will try to favor writing legacy .DDS files when possible for improved tool support.

SaveWICTextureToFile
Saves a texture to a WIC-supported bitmap file on disk. The caller provides the desired WIC container format via guidContainerFormat and can optionally specify a desired WIC pixel format via targetFormat (which will result in E_FAIL if the requested pixel format is not supported by the WIC codec). If no WIC pixel format GUID is provided as the targetFormat parameter, it will default to a non-alpha format since 'screenshots' usually ignore the alpha channel in render targets.

NOTE: SaveWICTextureToFile is not supported on Windows Phone 8, because WIC is not available on that platform.

Examples

This example saves a JPEG screenshot given a ID3D11DeviceContext immContext and IDXGISwapChain swapChain.

ID3D11Texture2D* backBuffer = nullptr;
HRESULT hr = swapChain->GetBuffer( 0, __uuidof( *backBuffer ), ( LPVOID* )&backBuffer );
if ( SUCCEEDED(hr) )
{
    hr = SaveWICTextureToFile( immContext, backBuffer,
                GUID_ContainerFormatJpeg, L"SCREENSHOT.JPG" );
    backBuffer->Release();
}
if ( FAILED(hr) )
    // error

Here is an example of explicitly writing a screenshot as a 16-bit (5:6:5) BMP.

ID3D11Texture2D* backBuffer = nullptr;
HRESULT hr = swapChain->GetBuffer( 0, __uuidof( *backBuffer ), ( LPVOID* )&backBuffer );
if ( SUCCEEDED(hr) )
{
    hr = SaveWICTextureToFile( immContext, backBuffer,
                GUID_ContainerFormatBmp, L"SCREENSHOT.BMP",
                &GUID_WICPixelFormat16bppBGR565 );
    backBuffer->Release();
}
if ( FAILED(hr) )
    // error

When writing WIC files, you can also provide a callback for setting specific encoding options.

ID3D11Texture2D* backBuffer = nullptr;
HRESULT hr = swapChain->GetBuffer( 0, __uuidof( *backBuffer ), ( LPVOID* )&backBuffer );
if ( SUCCEEDED(hr) )
{
    hr = SaveWICTextureToFile( immContext, backBuffer,
                GUID_ContainerFormatTiff, L"SCREENSHOT.TIF", nullptr,
                [&](IPropertyBag2* props)
                {
                    PROPBAG2 options[2] = { 0, 0 };
                    options[0].pstrName = L"CompressionQuality";
                    options[1].pstrName = L"TiffCompressionMethod";

                    VARIANT varValues[2];
                    varValues[0].vt = VT_R4;
                    varValues[0].fltVal = 0.75f;

                    varValues[1].vt = VT_UI1;
                    varValues[1].bVal = WICTiffCompressionNone;

                    (void)props->Write( 2, options, varValues ); 
                });
    backBuffer->Release();
}
if ( FAILED(hr) )
    // error

Release Notes

  • If built with #define DXGI_1_2_FORMATS the DDS writer supports BGRA 4:4:4:4 files.
  • JPEG-XR / HD Photo supports nearly all WIC pixel formats including floating-point for both encoding and decoding.
  • TIFF can contain floating-point (128bpp or 96bpp) data, but the WIC built-in codec can only decode such images. It always converts floating-point data to unorm when encoding.
  • Paletted WIC formats are not supported for writing by the SaveWICTextureToFile function.

WIC2

WIC2 is available on Windows 8 and on Windows 7 Service Pack 1 with KB 2670838 installed.
  • If WIC2 is supported, then this function can make use of the new WIC pixel format GUID_WICPixelFormat96bppRGBFloat.
http://support.microsoft.com/kb/2670838

Windows Store apps

For Save*TextureToFile 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
Viewing all 1174 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>