📄 dsutils.cs
字号:
#region license
/************************************************************************
DirectShowLib - Provide access to DirectShow interfaces via .NET
Copyright (C) 2006
http://sourceforge.net/projects/directshownet/
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**************************************************************************/
#endregion
using System;
using System.Collections;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Reflection;
using DirectShowLib.Dvd;
#if !USING_NET11
using System.Runtime.InteropServices.ComTypes;
#endif
namespace DirectShowLib
{
#region Declarations
/// <summary>
/// Not from DirectShow
/// </summary>
public enum PinConnectedStatus
{
Unconnected,
Connected
}
/// <summary>
/// From BITMAPINFO
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct BitmapInfo
{
public BitmapInfoHeader bmiHeader;
public int [] bmiColors;
}
/// <summary>
/// From BITMAPINFOHEADER
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack=2)]
public class BitmapInfoHeader
{
public int Size;
public int Width;
public int Height;
public short Planes;
public short BitCount;
public int Compression;
public int ImageSize;
public int XPelsPerMeter;
public int YPelsPerMeter;
public int ClrUsed;
public int ClrImportant;
}
/// <summary>
/// From DDPIXELFORMAT
/// </summary>
[StructLayout(LayoutKind.Explicit)]
public struct DDPixelFormat
{
[FieldOffset(0)] public int dwSize;
[FieldOffset(4)] public int dwFlags;
[FieldOffset(8)] public int dwFourCC;
[FieldOffset(12)] public int dwRGBBitCount;
[FieldOffset(12)] public int dwYUVBitCount;
[FieldOffset(12)] public int dwZBufferBitDepth;
[FieldOffset(12)] public int dwAlphaBitDepth;
[FieldOffset(16)] public int dwRBitMask;
[FieldOffset(16)] public int dwYBitMask;
[FieldOffset(20)] public int dwGBitMask;
[FieldOffset(20)] public int dwUBitMask;
[FieldOffset(24)] public int dwBBitMask;
[FieldOffset(24)] public int dwVBitMask;
[FieldOffset(28)] public int dwRGBAlphaBitMask;
[FieldOffset(28)] public int dwYUVAlphaBitMask;
[FieldOffset(28)] public int dwRGBZBitMask;
[FieldOffset(28)] public int dwYUVZBitMask;
}
/// <summary>
/// From CAUUID
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct DsCAUUID
{
public int cElems;
public IntPtr pElems;
/// <summary>
/// Perform a manual marshaling of pElems to retrieve an array of System.Guid.
/// Assume this structure has been already filled by the ISpecifyPropertyPages.GetPages() method.
/// </summary>
/// <returns>A managed representation of pElems (cElems items)</returns>
public Guid[] ToGuidArray()
{
Guid[] retval = new Guid[this.cElems];
for (int i=0; i<this.cElems; i++)
{
// In 32Bits OSs IntPtr constructor cast Int64 as Int32.
// It should work on 32Bits and 64 Bits OSs...
IntPtr ptr = new IntPtr(this.pElems.ToInt64() + (IntPtr.Size * i));
retval[i] = (Guid) Marshal.PtrToStructure(ptr, typeof(Guid));
}
return retval;
}
}
/// <summary>
/// DirectShowLib.DsLong is a wrapper class around a <see cref="System.Int64"/> value type.
/// </summary>
/// <remarks>
/// This class is necessary to enable null paramters passing.
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
public class DsLong
{
private long Value;
/// <summary>
/// Constructor
/// Initialize a new instance of DirectShowLib.DsLong with the Value parameter
/// </summary>
/// <param name="Value">Value to assign to this new instance</param>
public DsLong(long Value)
{
this.Value = Value;
}
/// <summary>
/// Get a string representation of this DirectShowLib.DsLong Instance.
/// </summary>
/// <returns>A string representing this instance</returns>
public override string ToString()
{
return this.Value.ToString();
}
public override int GetHashCode()
{
return this.Value.GetHashCode();
}
/// <summary>
/// Define implicit cast between DirectShowLib.DsLong and System.Int64 for languages supporting this feature.
/// VB.Net doesn't support implicit cast. <see cref="DirectShowLib.DsLong.ToInt64"/> for similar functionality.
/// <code>
/// // Define a new DsLong instance
/// DsLong dsL = new DsLong(9876543210);
/// // Do implicit cast between DsLong and Int64
/// long l = dsL;
///
/// Console.WriteLine(l.ToString());
/// </code>
/// </summary>
/// <param name="g">DirectShowLib.DsLong to be cast</param>
/// <returns>A casted System.Int64</returns>
public static implicit operator long(DsLong l)
{
return l.Value;
}
/// <summary>
/// Define implicit cast between System.Int64 and DirectShowLib.DsLong for languages supporting this feature.
/// VB.Net doesn't support implicit cast. <see cref="DirectShowLib.DsGuid.FromInt64"/> for similar functionality.
/// <code>
/// // Define a new Int64 instance
/// long l = 9876543210;
/// // Do implicit cast between Int64 and DsLong
/// DsLong dsl = l;
///
/// Console.WriteLine(dsl.ToString());
/// </code>
/// </summary>
/// <param name="g">System.Int64 to be cast</param>
/// <returns>A casted DirectShowLib.DsLong</returns>
public static implicit operator DsLong(long l)
{
return new DsLong(l);
}
/// <summary>
/// Get the System.Int64 equivalent to this DirectShowLib.DsLong instance.
/// </summary>
/// <returns>A System.Int64</returns>
public long ToInt64()
{
return this.Value;
}
/// <summary>
/// Get a new DirectShowLib.DsLong instance for a given System.Int64
/// </summary>
/// <param name="g">The System.Int64 to wrap into a DirectShowLib.DsLong</param>
/// <returns>A new instance of DirectShowLib.DsLong</returns>
public static DsLong FromInt64(long l)
{
return new DsLong(l);
}
}
/// <summary>
/// DirectShowLib.DsGuid is a wrapper class around a System.Guid value type.
/// </summary>
/// <remarks>
/// This class is necessary to enable null paramters passing.
/// </remarks>
[StructLayout(LayoutKind.Explicit)]
public class DsGuid
{
[FieldOffset(0)]
private Guid guid;
public static readonly DsGuid Empty = Guid.Empty;
/// <summary>
/// Empty constructor.
/// Initialize it with System.Guid.Empty
/// </summary>
public DsGuid()
{
this.guid = Guid.Empty;
}
/// <summary>
/// Constructor.
/// Initialize this instance with a given System.Guid string representation.
/// </summary>
/// <param name="g">A valid System.Guid as string</param>
public DsGuid(string g)
{
this.guid = new Guid(g);
}
/// <summary>
/// Constructor.
/// Initialize this instance with a given System.Guid.
/// </summary>
/// <param name="g">A System.Guid value type</param>
public DsGuid(Guid g)
{
this.guid = g;
}
/// <summary>
/// Get a string representation of this DirectShowLib.DsGuid Instance.
/// </summary>
/// <returns>A string representing this instance</returns>
public override string ToString()
{
return this.guid.ToString();
}
/// <summary>
/// Get a string representation of this DirectShowLib.DsGuid Instance with a specific format.
/// </summary>
/// <param name="format"><see cref="System.Guid.ToString"/> for a description of the format parameter.</param>
/// <returns>A string representing this instance according to the format parameter</returns>
public string ToString(string format)
{
return this.guid.ToString(format);
}
public override int GetHashCode()
{
return this.guid.GetHashCode();
}
/// <summary>
/// Define implicit cast between DirectShowLib.DsGuid and System.Guid for languages supporting this feature.
/// VB.Net doesn't support implicit cast. <see cref="DirectShowLib.DsGuid.ToGuid"/> for similar functionality.
/// <code>
/// // Define a new DsGuid instance
/// DsGuid dsG = new DsGuid("{33D57EBF-7C9D-435e-A15E-D300B52FBD91}");
/// // Do implicit cast between DsGuid and Guid
/// Guid g = dsG;
///
/// Console.WriteLine(g.ToString());
/// </code>
/// </summary>
/// <param name="g">DirectShowLib.DsGuid to be cast</param>
/// <returns>A casted System.Guid</returns>
public static implicit operator Guid(DsGuid g)
{
return g.guid;
}
/// <summary>
/// Define implicit cast between System.Guid and DirectShowLib.DsGuid for languages supporting this feature.
/// VB.Net doesn't support implicit cast. <see cref="DirectShowLib.DsGuid.FromGuid"/> for similar functionality.
/// <code>
/// // Define a new Guid instance
/// Guid g = new Guid("{B9364217-366E-45f8-AA2D-B0ED9E7D932D}");
/// // Do implicit cast between Guid and DsGuid
/// DsGuid dsG = g;
///
/// Console.WriteLine(dsG.ToString());
/// </code>
/// </summary>
/// <param name="g">System.Guid to be cast</param>
/// <returns>A casted DirectShowLib.DsGuid</returns>
public static implicit operator DsGuid(Guid g)
{
return new DsGuid(g);
}
/// <summary>
/// Get the System.Guid equivalent to this DirectShowLib.DsGuid instance.
/// </summary>
/// <returns>A System.Guid</returns>
public Guid ToGuid()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -