Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Commit

Permalink
Merge pull request #887 from crowbar27/master
Browse files Browse the repository at this point in the history
Added IFormattable to FourCC to implement fix for FromFourCC.
  • Loading branch information
xoofx authored May 6, 2017
2 parents c45d3fb + a046bb8 commit 5e9be87
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Source/SharpDX.MediaFoundation/VideoFormatGuids.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static partial class VideoFormatGuids
/// <returns>Media foundation unique ID</returns>
public static Guid FromFourCC(SharpDX.Multimedia.FourCC fourCC)
{
return new Guid(string.Concat(fourCC.ToString(), "-0000-0010-8000-00aa00389b71"));
return new Guid(string.Concat(fourCC.ToString("I", null), "-0000-0010-8000-00aa00389b71"));
}
}
}
45 changes: 44 additions & 1 deletion Source/SharpDX/Multimedia/FourCC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Globalization;
using System.Runtime.InteropServices;

namespace SharpDX.Multimedia
Expand All @@ -26,7 +27,7 @@ namespace SharpDX.Multimedia
/// A FourCC descriptor.
/// </summary>
[StructLayout(LayoutKind.Sequential, Size = 4)]
public struct FourCC : IEquatable<FourCC>
public struct FourCC : IEquatable<FourCC>, IFormattable
{
/// <summary>
/// Empty FourCC.
Expand Down Expand Up @@ -175,6 +176,48 @@ public override int GetHashCode()
return (int) value;
}

/// <summary>
/// Provides a custom string representation of the FourCC descriptor.
/// </summary>
/// <remarks>
/// The general format "G" is equivalent to the parameterless.
/// <see cref="FourCC.ToString()"/>. The special format "I" returns a
/// string representation which can be used to construct a Media
/// Foundation format GUID. It is equivalent to "X08".
/// </remarks>
/// <param name="format">The format descriptor, which can be "G" (empty
/// or <c>null</c> is equivalent to "G"), "I" or any valid standard
/// number format.</param>
/// <param name="formatProvider">The format provider for formatting
/// numbers.</param>
/// <returns>The requested string representation.</returns>
/// <exception cref="System.FormatException">In case of
/// <paramref name="format"/> is not "G", "I" or a valid number
/// format.</exception>
public string ToString(string format, IFormatProvider formatProvider)
{
if (string.IsNullOrEmpty(format))
{
format = "G";
}
if (formatProvider == null)
{
formatProvider = CultureInfo.CurrentCulture;
}

switch (format.ToUpperInvariant())
{
case "G":
return this.ToString();

case "I":
return this.value.ToString("X08", formatProvider);

default:
return this.value.ToString(format, formatProvider);
}
}

public static bool operator ==(FourCC left, FourCC right)
{
return left.Equals(right);
Expand Down

0 comments on commit 5e9be87

Please sign in to comment.