/// <summary> /// Initializes a new instance of the <see cref="ReplayColorFrame"/> class /// based on the specified <c>ColorFrame</c> and <c>byte</c> array. /// </summary> /// <param name="frame">The frame.</param> /// <param name="bytes">The bytes.</param> public ReplayColorFrame(ColorFrame frame, byte[] bytes) { this.Codec = ColorCodecs.Raw; this.FrameType = FrameTypes.Color; this.RelativeTime = frame.RelativeTime; this.Width = frame.FrameDescription.Width; this.Height = frame.FrameDescription.Height; this.FrameDataSize = this.Width * this.Height * 4; // BGRA is 4 bytes per pixel this._frameData = bytes; }
/// <summary> /// Initializes a new instance of the <see cref="ReplayColorFrame"/> class /// by reading from the specified <c>BinaryReader</c> using the specified /// <c>IColorCodec</c>. /// </summary> /// <param name="reader">The reader.</param> /// <param name="codec">The codec.</param> /// <returns>The <c>ReplayColorFrame</c></returns> /// <exception cref="System.IO.IOException">The recording appears to be corrupt.</exception> public static ReplayColorFrame FromReader(BinaryReader reader, IColorCodec codec) { var frame = new ReplayColorFrame(); frame.FrameType = FrameTypes.Color; frame.RelativeTime = TimeSpan.FromMilliseconds(reader.ReadDouble()); frame.FrameSize = reader.ReadInt64(); long frameStartPos = reader.BaseStream.Position; frame.Codec = codec; frame.Codec.ReadHeader(reader, frame); frame.Stream = reader.BaseStream; frame.StreamPosition = frame.Stream.Position; frame.Stream.Position += frame.FrameDataSize; // Do Frame Integrity Check var isGoodFrame = false; try { if (reader.ReadString() == ReplayFrame.EndOfFrameMarker) { isGoodFrame = true; } } catch { } if (!isGoodFrame) { System.Diagnostics.Debug.WriteLine("BAD FRAME...RESETTING"); reader.BaseStream.Position = frameStartPos + frame.FrameSize; try { if (reader.ReadString() != ReplayFrame.EndOfFrameMarker) { throw new IOException("The recording appears to be corrupt."); } return(null); } catch { throw new IOException("The recording appears to be corrupt."); } } return(frame); }
/// <summary> /// Initializes a new instance of the <see cref="ReplayColorFrame"/> class /// based on the specified <c>ColorFrame</c>. /// </summary> /// <param name="frame">The frame.</param> public ReplayColorFrame(ColorFrame frame) { this.Codec = ColorCodecs.Raw; this.FrameType = FrameTypes.Color; this.RelativeTime = frame.RelativeTime; this.Width = frame.FrameDescription.Width; this.Height = frame.FrameDescription.Height; this.FrameDataSize = this.Width * this.Height * 4; // BGRA is 4 bytes per pixel this._frameData = new Byte[this.FrameDataSize]; if (frame.RawColorImageFormat == ColorImageFormat.Bgra) { frame.CopyRawFrameDataToArray(_frameData); } else { frame.CopyConvertedFrameDataToArray(_frameData, ColorImageFormat.Bgra); } }
/// <summary> /// Initializes a new instance of the <see cref="ReplayColorFrame"/> class /// based on the specified <c>ColorFrame</c>. /// </summary> /// <param name="frame">The frame.</param> internal ReplayColorFrame(ColorFrame frame) { this.Codec = ColorCodecs.Raw; this.FrameType = FrameTypes.Color; this.RelativeTime = frame.RelativeTime; this.Width = frame.FrameDescription.Width; this.Height = frame.FrameDescription.Height; this.FrameDataSize = this.Width * this.Height * 4; // BGRA is 4 bytes per pixel this._frameData = new Byte[this.FrameDataSize]; if (frame.RawColorImageFormat == ColorImageFormat.Bgra) { frame.CopyRawFrameDataToArray(_frameData); } else { frame.CopyConvertedFrameDataToArray(_frameData, ColorImageFormat.Bgra); } }
/// <summary> /// Initializes a new instance of the <see cref="ReplayColorFrame"/> class /// by reading from the specified <c>BinaryReader</c> using the specified /// <c>IColorCodec</c>. /// </summary> /// <param name="reader">The reader.</param> /// <param name="codec">The codec.</param> /// <returns>The <c>ReplayColorFrame</c></returns> /// <exception cref="System.IO.IOException">The recording appears to be corrupt.</exception> internal static ReplayColorFrame FromReader(BinaryReader reader, IColorCodec codec) { var frame = new ReplayColorFrame(); frame.FrameType = FrameTypes.Color; frame.RelativeTime = TimeSpan.FromMilliseconds(reader.ReadDouble()); frame.FrameSize = reader.ReadInt64(); long frameStartPos = reader.BaseStream.Position; frame.Codec = codec; frame.Codec.ReadHeader(reader, frame); frame.Stream = reader.BaseStream; frame.StreamPosition = frame.Stream.Position; frame.Stream.Position += frame.FrameDataSize; // Do Frame Integrity Check var isGoodFrame = false; try { if (reader.ReadString() == ReplayFrame.EndOfFrameMarker) { isGoodFrame = true; } } catch { } if (!isGoodFrame) { System.Diagnostics.Debug.WriteLine("BAD FRAME...RESETTING"); reader.BaseStream.Position = frameStartPos + frame.FrameSize; try { if (reader.ReadString() != ReplayFrame.EndOfFrameMarker) { throw new IOException("The recording appears to be corrupt."); } return null; } catch { throw new IOException("The recording appears to be corrupt."); } } return frame; }
/// <summary> /// Initializes a new instance of the <see cref="ReplayColorFrame"/> class /// based on the specified <c>ColorFrame</c> and <c>byte</c> array. /// </summary> /// <param name="frame">The frame.</param> /// <param name="bytes">The bytes.</param> internal ReplayColorFrame(ColorFrame frame, byte[] bytes) { this.Codec = ColorCodecs.Raw; this.FrameType = FrameTypes.Color; this.RelativeTime = frame.RelativeTime; this.Width = frame.FrameDescription.Width; this.Height = frame.FrameDescription.Height; this.FrameDataSize = this.Width * this.Height * 4; // BGRA is 4 bytes per pixel this._frameData = bytes; }
/// <summary> /// Initializes the <see cref="ColorCodecs"/> class. /// </summary> static ColorCodecs() { Raw = new RawColorCodec(); Jpeg = new JpegColorCodec(); }
/// <summary> /// Initializes a new instance of the <see cref="ColorRecorder"/> class. /// </summary> /// <param name="writer">The writer.</param> public ColorRecorder(BinaryWriter writer) { this._writer = writer; this._codec = new RawColorCodec(); }
/// <summary> /// Initializes a new instance of the <see cref="ReplayColorSystem"/> class. /// </summary> /// <param name="codec">The codec.</param> public ReplayColorSystem(IColorCodec codec) { this._codec = codec; }