-
Notifications
You must be signed in to change notification settings - Fork 449
Resize
DirectXTex |
---|
Resize an image or set of images.
If given a set of images, the resulting ScratchImage will always have mipLevels of 1 (i.e. any mipmaps from the original are discarded). You can generate mipmaps at the new size using GenerateMipMaps / GenerateMipMaps3D.
HRESULT Resize( const Image& srcImage,
size_t width, size_t height, TEX_FILTER_FLAGS filter,
ScratchImage& image );
HRESULT Resize( const Image* srcImages, size_t nimages,
const TexMetadata& metadata,
size_t width, size_t height, TEX_FILTER_FLAGS filter,
ScratchImage& result );
filter: One or more Filter Flags. The default value is TEX_FILTER_DEFAULT
.
If using TEX_FILTER_DEFAULT
, this routine will default to using FANT if using the WIC code paths. If using the non-WIC codepaths, it defaults to BOX if the destination image is half the size in both dimensions of the source image, otherwise it defaults to LINEAR.
If you have a 2D array of pixel data of 640 x 480 in 32 bit-per-pixel BGRA format, this products a new image 320 x 200 in size:
Image image;
image.width = 640;
image.height = 480;
image.format = DXGI_FORMAT_B8G8R8A8_UNORM;
image.rowPitch = sizeof(uint32_t) * 640;
image.slicePitch = sizeof(uint32_t) * 640 * 480;
image.pixels = reinterpret_cast<const uint8_t*>( pixelData );
ScratchImage destImage;
hr = Resize( image, 320, 200, TEX_FILTER_DEFAULT, destImage );
if ( FAILED(hr) )
...
// result is auto img = destImage.GetImage(0,0,0); where
// img->width = 320, img->height = 200, img->format = DXGI_FORMAT_B8G8R8A8_UNORM;
// img->rowPitch = sizeof(uint32_t) * 320, img->slicePitch = sizeof(uint32_t) * 320 * 200
// img->pixels is the image data
If you have an existing ScratchImage
, you can resize all the images in it via this function:
ScratchImage srcImage;
...
ScratchImage destImage;
hr = Resize( srcImage.GetImages(), srcImage.GetImageCount(),
srcImage.GetMetadata(),
100, 50, TEX_FILTER_DEFAULT, destImage );
if ( FAILED(hr) )
...
This function does not operate directly on block compressed images. See Decompress and Compress.
This function cannot operate directly on a planar format image. See ConvertToSinglePlane for a method for converting planar data to a format that is supported by this routine.
The second version of Resize is intended for working with 1D arrays, 2D arrays, cubemaps, and cubemap arrays with mipmaps.
This function is implemented with both WIC and non-WIC code paths. The WIC code paths are used for > 8-bit color depth formats, sRGB color formats, or when WRAP/MIRROR semantics are requested.
-
When resizing HDR images, be sure to stick with the default of
TEX_FILTER_FANT
when using WIC as theIWICBitmapScalar
has limited supported for high bit-depth and extended range formats. By default, the DirectXTex library chooses to use non-WIC codepaths when resizing for > 8 color-depth images with LINEAR or CUBIC filtering, with sRGB images, with MIRROR/WRAP semantics, or when using TRIANGLE filtering. It will also select non-WIC paths when dealing with 16k textures that are too large for WIC. -
On Windows 10 Creators Update (16299) or later, WIC has better handling when using the
IWICBitmapScalar
with 10:10:10:2 and float16 formats. On older versions of Windows, it will return the results for these formats as 32bpp which is then reconverted to the target format but with a loss of precision. You may want to useTEX_FILTER_FORCE_NON_WIC
if the results you are getting appear to be losing precision on older releases of Windows.
All content and source code for this package are subject to the terms of the MIT License.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
- Universal Windows Platform apps
- Windows desktop apps
- Windows 11
- Windows 10
- Windows 8.1
- Windows 7 Service Pack 1
- Xbox One
- Xbox Series X|S
- Windows Subsystem for Linux
- x86
- x64
- ARM64
- Visual Studio 2022
- Visual Studio 2019 (16.11)
- clang/LLVM v12 - v18
- GCC 10.5, 11.4, 12.3
- MinGW 12.2, 13.2
- CMake 3.20
DirectX Tool Kit for DirectX 11