Arithmetic composite effect

Arithmetic composite effect

Use the arithmetic composite effect to combine 2 images using a weighted sum of pixels from the input images.

The CLSID for this effect is CLSID_D2D1ArithmeticComposite.


The formula here is used to compute this effect.

Outputrgba = C₁ * Sourcergba * Destinationrgba + C₂ * Sourcergba + C₃ * Destinationrgba + C₄

Where C₁, C₂, C₃, C₄ are coefficients that you set.

The coefficients map to the values in a D2D1_VECTOR_4F (x, y, z, w):

  • x = C₁
  • y = C₂
  • z = C₃
  • w = C₄

Example image

A simple example is to add the source and destination pixels. In the example, 2 rounded rectangles are composited together. The source rectangle is blue and the destination is red.

The image here is the output of the Arithmetic Composite effect with the coefficients of the equation set to the values here.

  • C₁ = 0
  • C₂ = 1
  • C₃ = 1
  • C₄ = 0

An example image showing 2 rounded rectangles of the same size that overlap using the arithmetic composite effect.

The result is that the pixel values for the source and destination are added. The regions where the rectangles don't overlap the RGBA values are all 0. Where the rectangles overlap the color is magenta because the R and B values are both at maximum.

Here's another example image with code.

Before image 1
The first source image before the effect.
Before image 2
The second image before the effect.
The image after the transform.


ComPtr<ID2D1Effect> arithmeticCompositeEffect;
m_d2dContext->CreateEffect(CLSID_D2D1ArithmeticComposite, &arithmeticCompositeEffect);

arithmeticCompositeEffect->SetInput(0, bitmap);
arithmeticCompositeEffect->SetInput(1, bitmapTwo);
arithmeticCompositeEffect->SetValue(D2D1_ARITHMETICCOMPOSITE_PROP_COEFFICIENTS, D2D1::Vector4F(0.0f, 0.5f, 0.5f, 0.0f));


Effect properties

Display name and index enumerationDescription



The coefficients for the equation used to composite the two input images. The coefficients are unitless and unbounded.

Type is D2D1_VECTOR_4F.

Default value is {1.0f, 0.0f, 0.0f, 0.0f}.



The effect clamps color values to between 0 and 1 before the effect passes the values to the next effect in the graph.

If you set this to TRUE the effect will clamp the values. If you set this to FALSE, the effect will not clamp the color values, but other effects and the output surface may clamp the values if they are not of high enough precision.

Type is BOOL.

Default value is FALSE.


Output bitmap

The output bitmap depends on the coefficient values. These are the possible output bitmap sizes.

  • If C₁ is the only non-zero coefficient, the output size is the intersection of the input rectangles.
  • If C₂ is the only non-zero coefficient, the output size is the size of the Source rectangle.
  • If C₃ is the only non-zero coefficient, the output size is the size of the Destination rectangle..
  • If all coefficients are zero, the output size is an empty rectangle.
  • For all other coefficient values, the output size is the union of the input rectangles.


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]
Libraryd2d1.lib, dxguid.lib


Related topics




© 2016 Microsoft