ColorGlove.Filter.MatchColors C# (CSharp) Method

MatchColors() public static method

public static MatchColors ( ProcessorState state ) : void
state ProcessorState
return void
        public static void MatchColors(ProcessorState state)
        {
            byte[] rgb_tmp = new byte[3];
            Array.Clear(state.depth_label_, 0, state.depth_label_.Length);  // background label is 0. So can use Clear method.
            for (int i = 0; i < state.depth.Length; i++)
            {
                int depthVal = state.depth[i] >> DepthImageFrame.PlayerIndexBitmaskWidth;
                if ((depthVal <= state.upper.Value) && (depthVal > state.lower.Value))
                {
                    ColorImagePoint point = state.data_.mapped()[i];
                    int baseIndex = Util.toID(point.X, point.Y, width, height, kColorStride);

                    if (point.X > state.crop.Value.X && point.X <= (state.crop.Value.X + state.crop.Value.Width) &&
                        point.Y > state.crop.Value.Y && point.Y <= (state.crop.Value.Y + state.crop.Value.Height))
                    {
                        rgb_tmp[0] = state.rgb[baseIndex + 2];
                        rgb_tmp[1] = state.rgb[baseIndex + 1];
                        rgb_tmp[2] = state.rgb[baseIndex];

                        byte label = NearestColor(rgb_tmp, state);
                        state.depth_label_[i] = label;

                        state.bitmap_bits[baseIndex] = rgb_tmp[2];
                        state.bitmap_bits[baseIndex + 1] = rgb_tmp[1];
                        state.bitmap_bits[baseIndex + 2] = rgb_tmp[0];
                    }
                }
            }
        }