source: other-projects/playing-in-the-street/summer-2013/trunk/Microsoft.Samples.Kinect.Webserver/Sensor/Serialization/BackgroundRemovalStreamMessage.cs@ 28896

Last change on this file since 28896 was 28896, checked in by davidb, 10 years ago

Core Web Server that connects to the Kinect device

File size: 4.1 KB
Line 
1// -----------------------------------------------------------------------
2// <copyright file="BackgroundRemovalStreamMessage.cs" company="Microsoft">
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// </copyright>
5// -----------------------------------------------------------------------
6
7namespace Microsoft.Samples.Kinect.Webserver.Sensor.Serialization
8{
9 using System;
10 using System.Diagnostics.CodeAnalysis;
11
12 using Microsoft.Kinect.Toolkit.BackgroundRemoval;
13
14 /// <summary>
15 /// Serializable representation of a background removed color stream message to send to client.
16 /// </summary>
17 [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter",
18 Justification = "Lower case names allowed for JSON serialization.")]
19 public class BackgroundRemovalStreamMessage : ImageHeaderStreamMessage
20 {
21 /// <summary>
22 /// Bytes per pixel const.
23 /// </summary>
24 private const int BytesPerPixel = 4;
25
26 /// <summary>
27 /// Tracking ID of the player currently being tracked. Pixels that do not belong
28 /// to this player are removed.
29 /// </summary>
30 /// <remarks>
31 /// This value will be 0 if no player is found in the corresponding color frame.
32 /// </remarks>
33 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "tracked", Justification = "Lower case names allowed for JSON serialization.")]
34 public int trackedPlayerId { get; set; }
35
36 /// <summary>
37 /// The average depth of the pixels corresponding to the foreground player.
38 /// </summary>
39 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "average", Justification = "Lower case names allowed for JSON serialization.")]
40 public short averageDepth { get; set; }
41
42 /// <summary>
43 /// Buffer that holds background removed color image.
44 /// </summary>
45 internal byte[] Buffer { get; private set; }
46
47 /// <summary>
48 /// Update background removed color frame.
49 /// </summary>
50 /// <param name="frame">The input frame.</param>
51 public void UpdateBackgroundRemovedColorFrame(BackgroundRemovedColorFrame frame)
52 {
53 if (frame == null)
54 {
55 throw new ArgumentNullException("frame");
56 }
57
58 this.timestamp = frame.Timestamp;
59 this.width = frame.Width;
60 this.height = frame.Height;
61 this.bufferLength = frame.PixelDataLength;
62 this.trackedPlayerId = frame.TrackedPlayerId;
63 this.averageDepth = frame.AverageDepth;
64
65 if ((this.Buffer == null) || (this.Buffer.Length != this.bufferLength))
66 {
67 this.Buffer = new byte[this.bufferLength];
68 }
69
70 unsafe
71 {
72 fixed (byte* messageDataPtr = this.Buffer)
73 {
74 fixed (byte* frameDataPtr = frame.GetRawPixelData())
75 {
76 byte* messageDataPixelPtr = messageDataPtr;
77 byte* frameDataPixelPtr = frameDataPtr;
78
79 byte* messageDataPixelPtrEnd = messageDataPixelPtr + this.bufferLength;
80
81 while (messageDataPixelPtr != messageDataPixelPtrEnd)
82 {
83 // Convert from BGRA to RGBA format
84 *(messageDataPixelPtr++) = *(frameDataPixelPtr + 2);
85 *(messageDataPixelPtr++) = *(frameDataPixelPtr + 1);
86 *(messageDataPixelPtr++) = *frameDataPixelPtr;
87 *(messageDataPixelPtr++) = *(frameDataPixelPtr + 3);
88
89 frameDataPixelPtr += BytesPerPixel;
90 }
91 }
92 }
93 }
94 }
95 }
96}
Note: See TracBrowser for help on using the repository browser.