/// <summary> /// Apply an opacity mask based on the alpha values of a brush. /// </summary> public void ApplyOpacityMask(Brush brush) { if (brush == null) { return; } Color[,] colors = TextureGenerator.RenderBrushToColorArray(brush, width, height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { double opacity = ColorOperations.ByteToDouble(colors[x, y].A); frameBuffer[x, y] = ColorOperations.PreMultipliedOpacityScale(frameBuffer[x, y], opacity); } } }
/// <summary> /// Clip the regions specified by the Geometry out of the frame buffer. /// </summary> public void ApplyClip(Geometry clip) { if (clip == null) { return; } Color[,] clipColors = TextureGenerator.RenderBrushToColorArray(GetClipBrush(clip), width, height); // Clipping is anti-aliased. Need tolerance around clip edges. Color[,] tolColors = TextureGenerator.RenderBrushToColorArray(GetClipTolerance(clip), width, height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { double opacity = ColorOperations.ByteToDouble(clipColors[x, y].A); frameBuffer[x, y] = ColorOperations.PreMultipliedOpacityScale(frameBuffer[x, y], opacity); Color tolerance = new Color(); tolerance.A = tolerance.R = tolerance.G = tolerance.B = tolColors[x, y].A; toleranceBuffer[x, y] = ColorOperations.Add(toleranceBuffer[x, y], tolerance); } } }