protected void Output()
{
lock (this.lockObject)
{
var bitmap = (Bitmap)this.currentData[DataElements.PixelBitmap];
float brightness = (float)(double)this.currentData[DataElements.Brightness];
float whiteout = (float)Executor.Current.Whiteout.Value;
float blackout = (float)Executor.Current.Blackout.Value;
//TODO: Optimize
this.brightnessMatrix.Matrix40 = whiteout;
this.brightnessMatrix.Matrix41 = whiteout;
this.brightnessMatrix.Matrix42 = whiteout;
using (var imageAttributes = new ImageAttributes())
{
imageAttributes.SetColorMatrix(this.brightnessMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
this.output.DrawImage(bitmap,
this.outputRectangle,
0,
0,
bitmap.Width,
bitmap.Height,
GraphicsUnit.Pixel,
imageAttributes);
}
this.brightnessMatrix.Matrix40 = -1 + brightness - blackout;
this.brightnessMatrix.Matrix41 = -1 + brightness - blackout;
this.brightnessMatrix.Matrix42 = -1 + brightness - blackout;
using (var imageAttributes = new ImageAttributes())
{
imageAttributes.SetColorMatrix(this.brightnessMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
this.output.DrawImage(this.outputBitmap,
this.outputRectangle,
0,
0,
bitmap.Width,
bitmap.Height,
GraphicsUnit.Pixel,
imageAttributes);
}
BitmapData bitmapData = this.outputBitmap.LockBits(this.outputRectangle, ImageLockMode.ReadOnly, this.outputBitmap.PixelFormat);
System.Runtime.InteropServices.Marshal.Copy(bitmapData.Scan0, this.tempPixels, 0, this.tempPixels.Length);
this.outputBitmap.UnlockBits(bitmapData);
foreach (var pixelDevice in this.devices)
{
pixelDevice.DrawImage(this.tempPixels);
}
this.imageChanged.OnNext(this.outputBitmap);
}
}