Skip to content

Commit

Permalink
Merge pull request #686 from SickheadGames/FontProcessor
Browse files Browse the repository at this point in the history
Improvements to the content pipeline
  • Loading branch information
tomspilman committed Aug 17, 2012
2 parents 56f2f87 + 9c3bf46 commit acda02b
Show file tree
Hide file tree
Showing 25 changed files with 941 additions and 454 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace Microsoft.Xna.Framework.Content.Pipeline
/// You can also design custom importers that accept and import types containing specific third-party extensions to the object model.
/// </summary>
public abstract class ContentImporter<T> : IContentImporter
{
{
/// <summary>
/// Initializes a new instance of ContentImporter.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using System.Drawing;
using System.Runtime.InteropServices;

namespace Microsoft.Xna.Framework.Content.Pipeline
{
[ContentImporter(".png", DisplayName="MGTextureImporter", DefaultProcessor="TextureProcessor")]
public class TextureImporter : ContentImporter<TextureContent>
{
public override TextureContent Import(string filename, ContentImporterContext context)
{
var output = new Texture2DContent();
var bmp = new Bitmap(filename);

var bitmapContent = new PixelBitmapContent<Color>(bmp.Width, bmp.Height);


var bitmapData = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
System.Drawing.Imaging.ImageLockMode.ReadOnly,
System.Drawing.Imaging.PixelFormat.DontCare);

var length = bitmapData.Stride * bitmapData.Height;
var imageData = new byte[length];

// Copy bitmap to byte[]
Marshal.Copy(bitmapData.Scan0, imageData, 0, length);
bmp.UnlockBits(bitmapData);

bitmapContent.SetPixelData(imageData);

output.Faces[0].Add(bitmapContent);
return output;
}

}
}
Original file line number Diff line number Diff line change
@@ -1,99 +1,99 @@
#region License
/*
Microsoft Public License (Ms-PL)
MonoGame - Copyright © 2012 The MonoGame Team
All rights reserved.
This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
accept the license, do not use the software.
1. Definitions
The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
U.S. copyright law.
A "contribution" is the original software, or any additions or changes to the software.
A "contributor" is any person that distributes its contribution under this license.
"Licensed patents" are a contributor's patent claims that read directly on its contribution.
2. Grant of Rights
(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
3. Conditions and Limitations
(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
your patent license from such contributor to the software ends automatically.
(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
notices that are present in the software.
(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
code form, you may only do so under a license that complies with this license.
(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
purpose and non-infringement.
*/
#endregion License

using System;

namespace Microsoft.Xna.Framework.Content.Pipeline
{
/// <summary>
/// Provides a base class to use when developing custom processor components. All processors must derive from this class.
/// </summary>
public abstract class ContentProcessor<TInput, TOutput> : IContentProcessor
{
/// <summary>
/// Initializes a new instance of the ContentProcessor class.
/// </summary>
protected ContentProcessor()
{

}

/// <summary>
/// Processes the specified input data and returns the result.
/// </summary>
/// <param name="input">Existing content object being processed.</param>
/// <param name="context">Contains any required custom process parameters.</param>
/// <returns>A typed object representing the processed input.</returns>
public abstract TOutput Process(TInput input, ContentProcessorContext context);

/// <summary>
/// Gets the expected object type of the input parameter to IContentProcessor.Process.
/// </summary>
Type IContentProcessor.InputType
{
get { return typeof(TInput); }
}

/// <summary>
/// Gets the object type returned by IContentProcessor.Process.
/// </summary>
Type IContentProcessor.OutputType
{
get { return typeof(TOutput); }
}

/// <summary>
/// Processes the specified input data and returns the result.
/// </summary>
/// <param name="input">Existing content object being processed.</param>
/// <param name="context">Contains any required custom process parameters.</param>
/// <returns>The processed input.</returns>
object IContentProcessor.Process(object input, ContentProcessorContext context)
{
if (input == null)
throw new ArgumentNullException("input");
if (context == null)
throw new ArgumentNullException("context");
if (!(input is TInput))
throw new InvalidOperationException("input is not of the expected type");
return Process((TInput)input, context);
}
}
}
#region License
/*
Microsoft Public License (Ms-PL)
MonoGame - Copyright © 2012 The MonoGame Team
All rights reserved.
This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
accept the license, do not use the software.
1. Definitions
The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
U.S. copyright law.
A "contribution" is the original software, or any additions or changes to the software.
A "contributor" is any person that distributes its contribution under this license.
"Licensed patents" are a contributor's patent claims that read directly on its contribution.
2. Grant of Rights
(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
3. Conditions and Limitations
(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
your patent license from such contributor to the software ends automatically.
(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
notices that are present in the software.
(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
code form, you may only do so under a license that complies with this license.
(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
purpose and non-infringement.
*/
#endregion License

using System;

namespace Microsoft.Xna.Framework.Content.Pipeline
{
/// <summary>
/// Provides a base class to use when developing custom processor components. All processors must derive from this class.
/// </summary>
public abstract class ContentProcessor<TInput, TOutput> : IContentProcessor
{
/// <summary>
/// Initializes a new instance of the ContentProcessor class.
/// </summary>
protected ContentProcessor()
{

}

/// <summary>
/// Processes the specified input data and returns the result.
/// </summary>
/// <param name="input">Existing content object being processed.</param>
/// <param name="context">Contains any required custom process parameters.</param>
/// <returns>A typed object representing the processed input.</returns>
public abstract TOutput Process(TInput input, ContentProcessorContext context);

/// <summary>
/// Gets the expected object type of the input parameter to IContentProcessor.Process.
/// </summary>
Type IContentProcessor.InputType
{
get { return typeof(TInput); }
}

/// <summary>
/// Gets the object type returned by IContentProcessor.Process.
/// </summary>
Type IContentProcessor.OutputType
{
get { return typeof(TOutput); }
}

/// <summary>
/// Processes the specified input data and returns the result.
/// </summary>
/// <param name="input">Existing content object being processed.</param>
/// <param name="context">Contains any required custom process parameters.</param>
/// <returns>The processed input.</returns>
object IContentProcessor.Process(object input, ContentProcessorContext context)
{
if (input == null)
throw new ArgumentNullException("input");
if (context == null)
throw new ArgumentNullException("context");
if (!(input is TInput))
throw new InvalidOperationException("input is not of the expected type");
return Process((TInput)input, context);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
#region License
/*
Microsoft Public License (Ms-PL)
MonoGame - Copyright © 2012 The MonoGame Team
All rights reserved.
This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
accept the license, do not use the software.
1. Definitions
The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
U.S. copyright law.
A "contribution" is the original software, or any additions or changes to the software.
A "contributor" is any person that distributes its contribution under this license.
"Licensed patents" are a contributor's patent claims that read directly on its contribution.
2. Grant of Rights
(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
3. Conditions and Limitations
(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
your patent license from such contributor to the software ends automatically.
(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
notices that are present in the software.
(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
code form, you may only do so under a license that complies with this license.
(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
purpose and non-infringement.
*/
#endregion License

using System;

namespace Microsoft.Xna.Framework.Content.Pipeline
{
/// <summary>
/// Gets any existing content processor components.
/// </summary>
public class ContentProcessorAttribute : Attribute
{
/// <summary>
/// Gets or sets the string representing the processor in a user interface. This name is not used by the content pipeline and should not be passed to the BuildAssets task (a custom MSBuild task used by XNA Game Studio). It is used for display purposes only.
/// </summary>
public virtual string DisplayName { get; set; }

/// <summary>
/// Initializes an instance of ContentProcessorAttribute.
/// </summary>
public ContentProcessorAttribute()
{
}
}
}
#region License
/*
Microsoft Public License (Ms-PL)
MonoGame - Copyright © 2012 The MonoGame Team
All rights reserved.
This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
accept the license, do not use the software.
1. Definitions
The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
U.S. copyright law.
A "contribution" is the original software, or any additions or changes to the software.
A "contributor" is any person that distributes its contribution under this license.
"Licensed patents" are a contributor's patent claims that read directly on its contribution.
2. Grant of Rights
(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
3. Conditions and Limitations
(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
your patent license from such contributor to the software ends automatically.
(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
notices that are present in the software.
(D) If you distribute any portion of the software in source code form, you may do so only under this license by including
a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
code form, you may only do so under a license that complies with this license.
(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
purpose and non-infringement.
*/
#endregion License

using System;

namespace Microsoft.Xna.Framework.Content.Pipeline
{
/// <summary>
/// Gets any existing content processor components.
/// </summary>
public class ContentProcessorAttribute : Attribute
{
/// <summary>
/// Gets or sets the string representing the processor in a user interface. This name is not used by the content pipeline and should not be passed to the BuildAssets task (a custom MSBuild task used by XNA Game Studio). It is used for display purposes only.
/// </summary>
public virtual string DisplayName { get; set; }

/// <summary>
/// Initializes an instance of ContentProcessorAttribute.
/// </summary>
public ContentProcessorAttribute()
{
}
}
}
Loading

0 comments on commit acda02b

Please sign in to comment.