private void RenderAlphaBar() { _boxA.Lock(); var buf = _boxA.Buffer; int w = _boxA.Width; int h = _boxA.Height; var info = new AlphaPixel( (w + 1) / 2, Utils.AlphaShades, _chn[0], _chn[1], _chn[2], 1f ); for (int i = 0; i < buf.Length; i += 4) { int idx = i / 4; info.alpha = 1f - (float)(idx / w) / (float)h; RenderAlphaPixel(info, buf, w, h, idx); } _boxA.Unlock(); }
private void RenderSampleBox() { _boxSample.Lock(); var buf = _boxSample.Buffer; int w = _boxSample.Width; int h = _boxSample.Height; var info = new AlphaPixel( w / 8, Utils.AlphaShades, _chn[0], _chn[1], _chn[2], _chn[3] ); for (int idx = 0; idx < buf.Length / 4; idx++) { RenderAlphaPixel(info, buf, w, h, idx); } _boxSample.Unlock(); }
//[MethodImpl(MethodImplOptions.AggressiveInlining)] private static void RenderAlphaPixel(AlphaPixel info, byte[] buf, int w, int h, int idx) { const int frame = ColorBox.Border; int x = idx % w; int y = idx / w; int xOdd = (x / info.blockSize) % 2; int yOdd = (y / info.blockSize) % 2; float shade = info.shades[xOdd ^ yOdd]; float lum = 255f; if (x < frame || x >= w - frame || y < frame || y >= h - frame) { lum = 255f * dimmed; } int i = idx * 4; buf[i + (int)BGRA.Blue] = (byte)((shade + (info.blue - shade) * info.alpha) * lum); buf[i + (int)BGRA.Green] = (byte)((shade + (info.green - shade) * info.alpha) * lum); buf[i + (int)BGRA.Red] = (byte)((shade + (info.red - shade) * info.alpha) * lum); buf[i + (int)BGRA.Alpha] = 255; }