public Codec(string name, Media.Codec.MediaType mediaType, Common.Binary.ByteOrder defaultByteOrder, int defaultComponentCount, int defaultBitsPerComponent) { MediaTypes = mediaType; if (string.IsNullOrWhiteSpace(name)) { throw new System.InvalidOperationException("name cannot be null or consist only of whitespace."); } Name = name; try { Id = ParseGuidAttribute(GetType()); } catch { Id = Guid.NewGuid(); } DefaultComponentCount = defaultComponentCount; DefaultBitsPerComponent = defaultBitsPerComponent; Codecs.TryRegisterCodec(this); }
public AudioFormat(int sampleRate, bool signed, Common.Binary.ByteOrder byteOrder, Codec.DataLayout dataLayout, System.Collections.Generic.IEnumerable <Codec.MediaComponent> components) : base(Codec.MediaType.Audio, byteOrder, dataLayout, components) { SampleRate = sampleRate; IsSigned = signed; }
/// <summary> /// Gets the amount of channels. /// </summary> //public int Channels { get { return m_Channels; } } /// <summary> /// Gets the size in bits of a single sample. /// </summary> //public int SampleSize { get { return m_SampleSize; } } /// <summary> /// Gets the sample rate. /// </summary> //public int SampleRate { get { return m_SampleRate; } } /// <summary> /// Gets the <see cref="Media.Common.Binary.ByteOrder"/> of the format. /// </summary> //public Common.Binary.ByteOrder ByteOrder { get { return m_ByteOrder; } } /// <summary> /// Indicates if the sample data is signed, useful for determining the mid point. /// </summary> //public bool IsSigned { get { return m_Signed; } } #endregion #endregion #region Constructor /// <summary> /// Constructs a new AudioFormat with the given configuration /// </summary> /// <param name="sampleRate">The sample rate</param> /// <param name="sampleSizeInBits">The size in bits of a single sample</param> /// <param name="channelCount">The amount of channels</param> /// <param name="signed">True if the data is signed, otherwise false</param> /// <param name="byteOrder">The <see cref="Common.Binary.ByteOrder"/> of the format</param> public AudioFormat(int sampleRate, bool signed, Common.Binary.ByteOrder byteOrder, Codec.DataLayout dataLayout, params Codec.MediaComponent[] components) : base(Codec.MediaType.Audio, byteOrder, dataLayout, components) { SampleRate = sampleRate; IsSigned = signed; }
public static ImageFormat RGB(int bitsPerComponent, Common.Binary.ByteOrder byteOrder = Common.Binary.ByteOrder.Little, Codec.DataLayout dataLayout = Codec.DataLayout.Packed) { return(new ImageFormat(byteOrder, dataLayout, new Codec.MediaComponent[] { new Codec.MediaComponent(RedChannelId, bitsPerComponent), new Codec.MediaComponent(GreenChannelId, bitsPerComponent), new Codec.MediaComponent(BlueChannelId, bitsPerComponent) })); }
public static ImageFormat YUV_565(Common.Binary.ByteOrder byteOrder = Common.Binary.ByteOrder.Little, Codec.DataLayout dataLayout = Codec.DataLayout.Packed) { return(new ImageFormat(byteOrder, dataLayout, new Codec.MediaComponent[] { new Codec.MediaComponent(LumaChannelId, 5), new Codec.MediaComponent(ChromaMajorChannelId, 6), new Codec.MediaComponent(ChromaMinorChannelId, 5) })); }
public static ImageFormat VariableRGB(int[] sizes, Common.Binary.ByteOrder byteOrder = Common.Binary.ByteOrder.Little, Codec.DataLayout dataLayout = Codec.DataLayout.Packed) { return(new ImageFormat(byteOrder, dataLayout, new Codec.MediaComponent[] { new Codec.MediaComponent(RedChannelId, sizes[0]), new Codec.MediaComponent(GreenChannelId, sizes[1]), new Codec.MediaComponent(BlueChannelId, sizes[2]) })); }
//Supports 565 formats... etc. public static ImageFormat VariableYUV(int[] sizes, Common.Binary.ByteOrder byteOrder = Common.Binary.ByteOrder.Little, Codec.DataLayout dataLayout = Codec.DataLayout.Packed) { return(new ImageFormat(byteOrder, dataLayout, new Codec.MediaComponent[] { new Codec.MediaComponent(LumaChannelId, sizes[0]), new Codec.MediaComponent(ChromaMajorChannelId, sizes[1]), new Codec.MediaComponent(ChromaMinorChannelId, sizes[2]) })); }
public static ImageFormat ARGB(int bitsPerComponent, Common.Binary.ByteOrder byteOrder = Common.Binary.ByteOrder.Little, Codec.DataLayout dataLayout = Codec.DataLayout.Packed, bool premultipliedAlpha = false) { return(new ImageFormat(byteOrder, dataLayout, new Codec.MediaComponent[] { new Codec.MediaComponent(premultipliedAlpha ? PreMultipliedAlphaChannelId :AlphaChannelId, bitsPerComponent), new Codec.MediaComponent(RedChannelId, bitsPerComponent), new Codec.MediaComponent(GreenChannelId, bitsPerComponent), new Codec.MediaComponent(BlueChannelId, bitsPerComponent) })); }
//32 bit -> 2 bit alpha 10 bit r, g, b public static ImageFormat ARGB_230(Common.Binary.ByteOrder byteOrder = Common.Binary.ByteOrder.Little, Codec.DataLayout dataLayout = Codec.DataLayout.Packed) { return(new ImageFormat(byteOrder, dataLayout, new Codec.MediaComponent[] { new Codec.MediaComponent((byte)'a', 2), new Codec.MediaComponent(RedChannelId, 10), new Codec.MediaComponent(GreenChannelId, 10), new Codec.MediaComponent(BlueChannelId, 10) })); }
public static ImageFormat AVUY(int bitsPerComponent, Common.Binary.ByteOrder byteOrder = Common.Binary.ByteOrder.Little, Codec.DataLayout dataLayout = Codec.DataLayout.Packed, bool premultipliedAlpha = false) { return(new ImageFormat(byteOrder, dataLayout, new Codec.MediaComponent[] { new Codec.MediaComponent(AlphaChannelId, bitsPerComponent), new Codec.MediaComponent(ChromaMinorChannelId, bitsPerComponent), new Codec.MediaComponent(ChromaMajorChannelId, bitsPerComponent), new Codec.MediaComponent(premultipliedAlpha ? PreMultipliedAlphaChannelId : LumaChannelId, bitsPerComponent) })); }
public static ImageFormat YUV(int bitsPerComponent, Common.Binary.ByteOrder byteOrder = Common.Binary.ByteOrder.Little, Codec.DataLayout dataLayout = Codec.DataLayout.Packed) { //Uglier version of the constructor //public static readonly ImageFormat YUV = new ImageFormat(Common.Binary.ByteOrder.Little, Codec.DataLayout.Packed, 3, 8, new byte[] { LumaChannelId, ChromaMajorChannelId, ChromaMinorChannelId }); return(new ImageFormat(byteOrder, dataLayout, new Codec.MediaComponent[] { new Codec.MediaComponent(LumaChannelId, bitsPerComponent), new Codec.MediaComponent(ChromaMajorChannelId, bitsPerComponent), new Codec.MediaComponent(ChromaMinorChannelId, bitsPerComponent) })); }
public void WriteEndian(Int64 source, Common.Binary.ByteOrder byteOrder) { byte[] intBytes = BitConverter.GetBytes(source); if (m_ByteOrder == Binary.ByteOrder.Little) { Array.Reverse(intBytes); } m_Source.Write(Common.Binary.ConvertFromBigEndian(intBytes, byteOrder), 0, Common.Binary.BytesPerLong); }
public MediaFormat(MediaType mediaType, Common.Binary.ByteOrder byteOrder, DataLayout dataLayout, int components, int[] componentSizes, byte[] componentIds) { //Assign the media type MediaType = mediaType; if (byteOrder == Common.Binary.ByteOrder.Unknown) { throw new System.ArgumentException("byteOrder", "Cannot be Unknown"); } ByteOrder = byteOrder; //Validate the datalayout if (dataLayout == Media.Codec.DataLayout.Unknown) { throw new System.ArgumentException("dataLayout", "Cannot be Unknown"); } DataLayout = dataLayout; //Validate the amount of components if (components < 1) { throw new System.ArgumentException("components", "Must be greater than 0."); } //Create the array Components = new MediaComponent[components]; long length; //Validate the sizes array if (Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(componentSizes, out length) || length < components) { throw new System.ArgumentException("componentSizes", "Must have the amount of elements indicated by 'components'"); } //Validate the length of the id array if (Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(componentIds, out length) || length < components) { throw new System.ArgumentException("componentIds", "Must have the amount of elements indicated by 'components'"); } //Creates each component for (int i = 0; i < components; ++i) { length = componentSizes[i]; int ilen = (int)length; Components[i] = new MediaComponent(componentIds[i], ilen); Size += ilen; } }
public MediaFormat(MediaType mediaType, Common.Binary.ByteOrder byteOrder, DataLayout dataLayout, System.Collections.Generic.IEnumerable <MediaComponent> components) { //Assign the media type MediaType = mediaType; if (byteOrder == Common.Binary.ByteOrder.Unknown) { throw new System.ArgumentException("byteOrder", "Cannot be Unknown"); } ByteOrder = byteOrder; //Validate the dataLayout if (dataLayout == Media.Codec.DataLayout.Unknown) { throw new System.ArgumentException("dataLayout", "Cannot be Unknown"); } DataLayout = dataLayout; if (components == null) { throw new System.ArgumentNullException("components"); } //Assign the components Components = System.Linq.Enumerable.ToArray <MediaComponent>(components); //Validate the amount of components if (Components.Length < 1) { throw new System.ArgumentException("components", "Must be greater than 0."); } //Calulcate the size foreach (MediaComponent mc in Components) { Size += mc.Size; } }
public ImageFormat(Common.Binary.ByteOrder byteOrder, Codec.DataLayout dataLayout, System.Collections.Generic.IEnumerable <Codec.MediaComponent> components) : base(Codec.MediaType.Image, byteOrder, dataLayout, components) { //No sub sampling Heights = Widths = new int[Components.Length]; }
//Write8 //Write16 //Write24 //Write32 //Write64 //WriteNBit public void WriteEndian(byte[] data, Common.Binary.ByteOrder byteOrder) { m_Source.Write(Common.Binary.ConvertFromBigEndian(data, byteOrder), 0, data.Length); }
/// <summary> /// Constructs a new AudioFormat which is a derivative of the given AudioFormat with a different byte order. /// </summary> /// <param name="format">The existing AudioFormat</param> /// <param name="newByteOrder">The new byte order</param> public AudioFormat(AudioFormat format, Common.Binary.ByteOrder newByteOrder) : this(format.SampleRate, format.IsSigned, format.ByteOrder, format.DataLayout) { }
public MediaFormat(MediaFormat other, Common.Binary.ByteOrder byteOrder, DataLayout dataLayout, params MediaComponent[] additionalComponents) : this(other.MediaType, byteOrder, dataLayout, System.Linq.Enumerable.Concat(other.Components, additionalComponents ?? System.Linq.Enumerable.Empty <MediaComponent>())) { }
public ImageFormat(Common.Binary.ByteOrder byteOrder, Codec.DataLayout dataLayout, int components, int[] componentSizes, byte[] componentIds) : base(Codec.MediaType.Image, byteOrder, dataLayout, components, componentSizes, componentIds) { //No sub sampling Heights = Widths = new int[components]; }
public void WriteEndian(string source, Common.Binary.ByteOrder byteOrder) { m_Source.Write(Common.Binary.ConvertFromBigEndian(Encoding.UTF8.GetBytes(source), byteOrder), 0, source.Length); }
public VideoCodec(string name, Common.Binary.ByteOrder defaultByteOrder = Common.Binary.ByteOrder.Unknown, int defaultComponentCount = 0, int defaultBitsPerComponent = 0) : base(name, Codec.MediaType.Video, defaultByteOrder, defaultComponentCount, defaultBitsPerComponent) { }
public ImageFormat(Common.Binary.ByteOrder byteOrder, Codec.DataLayout dataLayout, params Codec.MediaComponent[] components) : base(Codec.MediaType.Image, byteOrder, dataLayout, components) { //No sub sampling Heights = Widths = new int[Components.Length]; }