Bitmap source effect

Use the bitmap source effect to generate an ID2D1Image from a IWICBitmapSource for use as an input in an effect graph. This effect performs scaling and rotation on the CPU. It can also optionally generate a system memory mipmap, which can be a performance optimization for actively scaling very large images at various reduced resolutions.

Note  The bitmap source effect takes its input as a property, not as an image input. You must use the SetValue method, not the SetInput method. The WicBitmapSource property is where you specify the image input data.

The CLSID for this effect is CLSID_D2D1BitmapSource.

Effect properties

Display name and index enumerationType and default valueDescription

WicBitmapSource

D2D1_BITMAPSOURCE_PROP_WIC_BITMAP_SOURCE

IWICBitmapSource

NULL

The IWICBitmapSource containing the image data to be loaded.

Scale

D2D1_BITMAPSOURCE_PROP_SCALE

D2D1_VECTOR_2F

{1.0f, 1.0f}

The scale amount in the X and Y direction. The effect multiplies the width by the X value and the height by the Y value. This property is a D2D1_VECTOR_2F defined as: (X scale, Y scale). The scale amounts are FLOAT, unitless, and must be positive or 0.

InterpolationMode

D2D1_BITMAPSOURCE_PROP_INTERPOLATION_MODE

D2D1_BITMAPSOURCE_INTERPOLATION_MODE

D2D1_BITMAPSOURCE_INTERPOLATION_MODE_LINEAR

The interpolation mode used to scale the image. See Interpolation modes for more info.

If the mode disables the mipmap, then BitmapSouce will cache the image at the resolution determined by the Scale and EnableDPICorrection properties.

EnableDPICorrection

D2D1_BITMAPSOURCE_PROP_ENABLE_DPI_CORRECTION

BOOL

FALSE

If you set this to TRUE, the effect will scale the input image to convert the DPI reported by IWICBitmapSource to the DPI of the device context. The effect uses the interpolation mode you set with the InterpolationMode property. If you set this to FALSE, the effect uses a DPI of 96.0 for the output image.

AlphaMode

D2D1_BITMAPSOURCE_PROP_ALPHA_MODE

D2D1_BITMAPSOURCE_ALPHA_MODE

D2D1_BITMAPSOURCE_ALPHA_MODE_PREMULTIPLIED

The alpha mode of the output. This can be either premultiplied or straight. See Alpha modes for more info.

Orientation

D2D1_BITMAPSOURCE_PROP_ORIENTATION

D2D1_BITMAPSOURCE_ORIENTATION

D2D1_BITMAPSOURCE_ORIENTATION_DEFAULT

A flip and/or rotation operation to be performed on the image. See Orientation for more info.

 

Interpolation modes

The effect interpolates using this mode when it scales an image or when it corrects the DPI. The interpolation modes this effect uses are calculated by the CPU, not the GPU.

NameDescription
D2D1_BITMAPSOURCE_INTERPOLATION_MODE_NEAREST_NEIGHBORSamples the nearest single point and uses that. Doesn't generate a mipmap.
D2D1_BITMAPSOURCE_INTERPOLATION_MODE_LINEARUses a four point sample and linear interpolation. Doesn't generate a mipmap.
D2D1_BITMAPSOURCE_INTERPOLATION_MODE_CUBICUses a 16 sample cubic kernel for interpolation. Doesn't generate a mipmap.
D2D1_BITMAPSOURCE_INTERPOLATION_MODE_FANTUses the WIC fant interpolation, the same as the IWICBitmapScaler interface. Doesn't generate a mipmap.
D2D1_BITMAPSOURCE_INTERPOLATION_MODE_MIPMAP_LINEARGenerates mipmap chain in system memory using bilinear interpolation. For each mipmap the effect scales to the nearest multiple of 0.5 using bilinear interpolation and then scales the remaining amount using linear interpolation.

 

Orientation

The Orientation property can be used to apply an EXIF orientation flag that is embedded within an image.

NameDescription
D2D1_BITMAPSOURCE_ORIENTATION_DEFAULTDefault. The effect doesn't change the orientation of the input.
D2D1_BITMAPSOURCE_ORIENTATION_FLIP_HORIZONTALFlips the image horizontally.
D2D1_BITMAPSOURCE_ORIENTATION_ROTATE_CLOCKWISE180Rotates the image clockwise 180 degrees.
D2D1_BITMAPSOURCE_ORIENTATION_ROTATE_CLOCKWISE180_FLIP_HORIZONTALRotates the image clockwise 180 degrees and flips it horizontally.
D2D1_BITMAPSOURCE_ORIENTATION_ROTATE_CLOCKWISE270_FLIP_HORIZONTALRotates the image clockwise 270 degrees and flips it horizontally.
D2D1_BITMAPSOURCE_ORIENTATION_ROTATE_CLOCKWISE90Rotates the image clockwise 90 degrees.
D2D1_BITMAPSOURCE_ORIENTATION_ROTATE_CLOCKWISE90_FLIP_HORIZONTALRotates the image clockwise 90 degrees and flips it horizontally.
D2D1_BITMAPSOURCE_ORIENTATION_ROTATE_CLOCKWISE270Rotates the image clockwise 270 degrees.

 

This code snippet demonstrates how to convert from EXIF orientation values (defined in propkey.h) to D2D1_BITMAPSOURCE_ORIENTATION values.


#include <propkey.h>
#include <d2d1effects.h>

D2D1_BITMAPSOURCE_ORIENTATION GetBitmapSourceOrientation(unsigned short PhotoOrientation)
{
       switch (PhotoOrientation)
       {
       case PHOTO_ORIENTATION_NORMAL:
              return D2D1_BITMAPSOURCE_ORIENTATION_DEFAULT;
       case PHOTO_ORIENTATION_FLIPHORIZONTAL:
              return D2D1_BITMAPSOURCE_ORIENTATION_FLIP_HORIZONTAL;
       case PHOTO_ORIENTATION_ROTATE180:
              return D2D1_BITMAPSOURCE_ORIENTATION_ROTATE_CLOCKWISE180;
       case PHOTO_ORIENTATION_FLIPVERTICAL:
              return D2D1_BITMAPSOURCE_ORIENTATION_ROTATE_CLOCKWISE180_FLIP_HORIZONTAL;
       case PHOTO_ORIENTATION_TRANSPOSE: 
              return D2D1_BITMAPSOURCE_ORIENTATION_ROTATE_CLOCKWISE90_FLIP_HORIZONTAL;
       case PHOTO_ORIENTATION_ROTATE270:
              return D2D1_BITMAPSOURCE_ORIENTATION_ROTATE_CLOCKWISE90;
       case PHOTO_ORIENTATION_TRANSVERSE:
              return D2D1_BITMAPSOURCE_ORIENTATION_ROTATE_CLOCKWISE270_FLIP_HORIZONTAL;
       case PHOTO_ORIENTATION_ROTATE90:
              return D2D1_BITMAPSOURCE_ORIENTATION_ROTATE_CLOCKWISE270;
       default:
              return D2D1_BITMAPSOURCE_ORIENTATION_DEFAULT;
       }
}


Alpha modes

NameDescription
D2D1_BITMAPSOURCE_ALPHA_MODE_PREMULTIPLIED

The effect output uses premultiplied alpha.

D2D1_BITMAPSOURCE_ALPHA_MODE_STRAIGHT

The effect output uses straight alpha.

 

Remarks

To optimize performance when using WIC and Direct2D together, you should use IWICFormatConverter to convert to an appropriate pixel format based your app’s scenario and the image’s native precision.

In most cases, either your app’s Direct2D pipeline only requires 8 bits per channel (bpc) of precision, or the image only provides 8 bpc precision, and therefore you should convert to GUID_WICPixelFormat32bppPBGRA. However, if you want to take advantage of extra precision provided by an image (for example, a JPEG-XR or TIFF stored with greater than 8 bpc precision), you should use an RGBA-based pixel format. The below table provides more details.

Desired precisionNative precision of the imageRecommended pixel format
8 bits per channel<= 8 bits per channelGUID_WICPixelFormat32bppPBGRA
As high as possible<= 8 bits per channelGUID_WICPixelFormat32bppPBGRA
As high as possible> 8 bits per channelRGBA channel order, premultiplied alpha

 

Because many image formats support multiple levels of precision, you should use IWICBitmapSource::GetPixelFormat to obtain the image’s native pixel format, and then use IWICPixelFormatInfo to determine how many bits per channel of precision are available for that format. Also, note that not all hardware supports high precision pixel formats. In those cases your app may need to fall back to the WARP device to support high precision.

Requirements

Minimum supported clientWindows 8 and Platform Update for Windows 7 [desktop apps | Windows Store apps]
Minimum supported serverWindows 8 and Platform Update for Windows 7 [desktop apps | Windows Store apps]
Headerd2d1effects.h
Libraryd2d1.lib, dxguid.lib

 

Related topics

ID2D1Effect

 

 

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.