本文整理汇总了C#中SiliconStudio.TextureConverter.TexImage类的典型用法代码示例。如果您正苦于以下问题:C# TexImage类的具体用法?C# TexImage怎么用?C# TexImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TexImage类属于SiliconStudio.TextureConverter命名空间,在下文中一共展示了TexImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestEquals
public void TestEquals()
{
TexImage image2 = new TexImage(new IntPtr(), 699104, 512, 512, 1, SiliconStudio.Paradox.Graphics.PixelFormat.BC3_UNorm, 10, 2, TexImage.TextureDimension.Texture2D);
Assert.IsTrue(image.Equals(image2));
image2 = new TexImage(new IntPtr(), 699104, 512, 256, 1, SiliconStudio.Paradox.Graphics.PixelFormat.BC3_UNorm, 10, 2, TexImage.TextureDimension.Texture2D);
Assert.IsFalse(image.Equals(image2));
}
示例2: TexAtlas
/// <summary>
/// Initializes a new instance of the <see cref="TexAtlas"/> class.
/// </summary>
/// <param name="layout">The layout.</param>
/// <param name="atlas">The atlas.</param>
public TexAtlas(TexLayout layout, TexImage atlas)
: base(atlas.Data, atlas.DataSize, atlas.Width, atlas.Height, atlas.Depth, atlas.Format, atlas.MipmapCount, atlas.ArraySize, atlas.Dimension, atlas.FaceCount)
{
RowPitch = atlas.RowPitch;
SlicePitch = atlas.SlicePitch;
SubImageArray = atlas.SubImageArray;
Name = atlas.Name;
DisposingLibrary = atlas.DisposingLibrary;
CurrentLibrary = atlas.CurrentLibrary;
LibraryData = atlas.LibraryData;
Layout = layout;
Name = "";
}
示例3: FlipSub
/// <summary>
/// Flips the specified image horizontally or vertically.
/// </summary>
/// <param name="image">The image.</param>
/// <param name="index">The index of the sub-image.</param>
/// <param name="orientation">The orientation <see cref="Orientation.Flip"/>.</param>
public void FlipSub(TexImage image, int index, Orientation orientation)
{
if (image.Format.IsCompressed())
{
Log.Warning("You can't flip a compressed texture. It will be decompressed first..");
Decompress(image, image.Format.IsSRgb());
}
var request = new FlippingSubRequest(index, orientation);
ExecuteRequest(image, request);
}
示例4: ConvertToParadoxImage
/// <summary>
/// Converts to paradox image.
/// </summary>
/// <param name="image">The image.</param>
/// <returns>The converted Paradox <see cref="SiliconStudio.Paradox.Graphics.Image"/>.</returns>
/// <remarks>The user is the owner of the returned image, and has to dispose it after he finishes using it</remarks>
public SiliconStudio.Paradox.Graphics.Image ConvertToParadoxImage(TexImage image)
{
var request = new ExportToParadoxRequest();
ExecuteRequest(image, request);
return request.PdxImage;
}
示例5: FindSpriteRegion
/// <summary>
/// Find the region of the texture containing the sprite under the specified pixel.
/// </summary>
/// <param name="texture">The texture containing the sprite</param>
/// <param name="pixel">The coordinate of the pixel specifying the sprite</param>
/// <param name="separatorColor">The separator color that delimit the sprites. If null the <see cref="Color.Transparent"/> color is used</param>
/// <param name="separatorMask">The mask specifying which bits of the color should be checked. The bits are ordered as AABBGGRR.</param>
/// <returns></returns>
public unsafe Rectangle FindSpriteRegion(TexImage texture, Int2 pixel, Color? separatorColor = null, uint separatorMask = 0xff000000)
{
if (texture == null) throw new ArgumentNullException(nameof(texture));
var format = texture.Format;
if (texture.Dimension != TexImage.TextureDimension.Texture2D || !(format.IsRGBAOrder() || format.IsBGRAOrder() || format.SizeInBytes() != 4))
throw new NotImplementedException();
// adjust the separator color the mask depending on the color format.
var separator = (uint)(separatorColor ?? Color.Transparent).ToRgba();
if(texture.Format.IsBGRAOrder())
{
separator = RgbaToBgra(separator);
separatorMask = RgbaToBgra(separatorMask);
}
var maskedSeparator = separator & separatorMask;
var ptr = (uint*)texture.Data;
var stride = texture.RowPitch / 4;
// check for empty region (provided pixel is not valid)
var textureRegion = new Rectangle(0, 0, texture.Width, texture.Height);
if (!textureRegion.Contains(pixel) || (ptr[pixel.Y * stride + pixel.X] & separatorMask) == maskedSeparator)
return new Rectangle(pixel.X, pixel.Y, 0, 0);
// initialize the region with the provided pixel
var region = new Rectangle(pixel.X, pixel.Y, 1, 1);
var nextSearchOffsets = new[,]
{
{ new Int2(-1, -1), new Int2( 0, -1) },
{ new Int2( 1, -1), new Int2( 1, 0) },
{ new Int2( 1, 1), new Int2( 0, 1) },
{ new Int2(-1, 1), new Int2(-1, 0) }
};
var contourLeftEgde = pixel;
var rotationDirection = 0;
do
{
// Stage 1: Find an edge of the shape (look to the left of the provided pixel as long as possible)
var startEdge = contourLeftEgde;
var startEdgeDirection = EdgeDirection.Left;
for (int x = startEdge.X; x >= 0; --x)
{
if ((ptr[startEdge.Y * stride + x] & separatorMask) == maskedSeparator)
break;
startEdge.X = x;
}
// Stage 2: Determine the whole contour of the shape and update the region.
// Note: the found contour can correspond to an internal hole contour or the external shape contour.
var currentEdge = startEdge;
var currentEdgeDirection = startEdgeDirection;
do
{
var previousEdgeDirection = currentEdgeDirection;
var diagonalPixel = currentEdge + nextSearchOffsets[(int)currentEdgeDirection, 0];
var diagonalIsSeparator = !textureRegion.Contains(diagonalPixel) || (ptr[diagonalPixel.Y * stride + diagonalPixel.X] & separatorMask) == maskedSeparator;
var neighbourPixel = currentEdge + nextSearchOffsets[(int)currentEdgeDirection, 1];
var neighbourIsSeparator = !textureRegion.Contains(neighbourPixel) || (ptr[neighbourPixel.Y * stride + neighbourPixel.X] & separatorMask) == maskedSeparator;
// determine the next edge position
if (!diagonalIsSeparator)
{
currentEdge = diagonalPixel;
currentEdgeDirection = (EdgeDirection)(((int)currentEdgeDirection + 3) % 4);
}
else if (!neighbourIsSeparator)
{
currentEdge = neighbourPixel;
}
else
{
currentEdgeDirection = (EdgeDirection)(((int)currentEdgeDirection + 1) % 4);
}
// keep record of the point of the edge which is
if (currentEdge.X < contourLeftEgde.X)
contourLeftEgde = currentEdge;
// increase or decrease the rotation counter based on the sequence of edge direction
rotationDirection += RotationDirection(previousEdgeDirection, currentEdgeDirection);
// update the rectangle
region = Rectangle.Union(region, currentEdge);
}
while (currentEdge != startEdge || currentEdgeDirection != startEdgeDirection); // as long as we do not close the contour continue to explore
} // repeat the process as long as the edge found is not the shape external contour.
//.........这里部分代码省略.........
示例6: CreateImageFromAlphaComponent
/// <summary>
/// Create a new image from the alpha component of a reference image.
/// </summary>
/// <param name="texImage">The image from which to take the alpha</param>
/// <returns>The <see cref="TexImage"/> containing the alpha component as rgb color. Note: it is the user responsibility to dispose the returned image.</returns>
public unsafe TexImage CreateImageFromAlphaComponent(TexImage texImage)
{
if (texImage.Dimension != TexImage.TextureDimension.Texture2D || texImage.Format.IsCompressed())
throw new NotImplementedException();
var alphaImage = (TexImage)texImage.Clone(true);
var rowPtr = alphaImage.Data;
for (int i = 0; i < alphaImage.Height; i++)
{
var pByte = (byte*)rowPtr;
for (int x = 0; x < alphaImage.Width; x++)
{
pByte[0] = pByte[3];
pByte[1] = pByte[3];
pByte[2] = pByte[3];
pByte += 4;
}
rowPtr = IntPtr.Add(rowPtr, alphaImage.RowPitch);
}
return alphaImage;
}
示例7: GenerateNormalMap
/// <summary>
/// Generates the normal map.
/// </summary>
/// <param name="heightMap">The height map.</param>
/// <param name="amplitude">The amplitude.</param>
/// <returns>An instance of <see cref="TexImage"/> containig the normal map.</returns>
public TexImage GenerateNormalMap(TexImage heightMap, float amplitude)
{
if (amplitude <= 0)
{
Log.Error("The amplitude must be a positive float.");
throw new TextureToolsException("The amplitude must be a positive float.");
}
if (heightMap.Format.IsCompressed())
{
Log.Warning("You can't generate a normal map from a compressed height hmap. It will be decompressed first..");
Decompress(heightMap, heightMap.Format.IsSRgb());
}
var request = new NormalMapGenerationRequest(amplitude);
ExecuteRequest(heightMap, request);
return request.NormalMap;
}
示例8: Resize
/// <summary>
/// Resizes the specified image to a fixed image size.
/// </summary>
/// <remarks>
/// If the image is in a compressed format, it will be first decompressed.
/// </remarks>
/// <param name="image">The image.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="filter">The filter.</param>
public void Resize(TexImage image, int width, int height, Filter.Rescaling filter)
{
if (width < 1 || height < 1)
{
Log.Error("The new size must be an integer > 0.");
throw new TextureToolsException("The new size must be an integer > 0.");
}
// Texture already has the requested dimension
if (image.Width == width && image.Height == height)
{
return;
}
if (image.Format.IsCompressed())
{
Log.Warning("You can't resize a compressed texture. It will be decompressed first..");
Decompress(image, image.Format.IsSRgb());
}
ExecuteRequest(image, new FixedRescalingRequest(width, height, filter));
}
示例9: CreateTextureArray
/// <summary>
/// Creates a texture array with the given TexImage.
/// </summary>
/// <param name="textureList">The texture list.</param>
/// <returns>An instance of <see cref="TexImage"/> corresponding containing the texture array.</returns>
/// <exception cref="TextureToolsException">
/// No available library could create the array.
/// or
/// The textures must all have the same size and format to be in a texture array.
/// </exception>
public TexImage CreateTextureArray(List<TexImage> textureList)
{
var array = new TexImage();
var request = new ArrayCreationRequest(textureList);
ITexLibrary library = FindLibrary(array, request);
if (library == null)
{
Log.Error("No available library could create the array.");
throw new TextureToolsException("No available library could create the array.");
}
int width = textureList[0].Width;
int height = textureList[0].Height;
int depth = textureList[0].Depth;
array.Format = textureList[0].Format;
foreach (var texture in textureList)
{
texture.Update();
if (texture.Width != width || texture.Height != height || texture.Depth != depth || texture.Format != array.Format)
{
Log.Error("The textures must all have the same size and format to be in a texture array.");
throw new TextureToolsException("The textures must all have the same size and format to be in a texture array.");
}
}
ExecuteRequest(array, request);
return array;
}
示例10: ExecuteRequest
/// <summary>
/// Executes the request.
/// </summary>
/// <param name="image">The image.</param>
/// <param name="request">The request.</param>
/// <exception cref="TextureToolsException">No available library could perform the task : + request.Type</exception>
private void ExecuteRequest(TexImage image, IRequest request)
{
// First Check if the current library can handle the request
if (image.CurrentLibrary != null && image.CurrentLibrary.CanHandleRequest(image, request))
{
image.CurrentLibrary.Execute(image, request);
}
else // Otherwise, it finds another library which can handle the request
{
ITexLibrary library;
if ((library = FindLibrary(image, request)) != null)
{
if (image.Format.IsBGRAOrder() && !library.SupportBGRAOrder())
{
SwitchChannel(image);
}
if(image.CurrentLibrary != null) image.CurrentLibrary.EndLibrary(image); // Ending the use of the previous library (mainly to free memory)
library.StartLibrary(image); // Preparing the new library : converting TexImage format to the library native format
library.Execute(image, request);
image.CurrentLibrary = library;
}
else // If no library could be found, an exception is thrown
{
Log.Error("No available library could perform the task : " + request.Type);
throw new TextureToolsException("No available library could perform the task : " + request.Type);
}
}
}
示例11: CheckConformity
/// <summary>
/// Checks the conformity of a candidate texture with a model one : check the mipmap count and the format.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="candidate">The candidate.</param>
private void CheckConformity(TexImage model, TexImage candidate)
{
if (model.MipmapCount > 1 && candidate.MipmapCount == 1)
{
Log.Warning("The given texture has no mipmaps. They will be generated..");
GenerateMipMaps(candidate, Filter.MipMapGeneration.Box);
}
if (candidate.Format != model.Format)
{
Log.Warning("The given texture format isn't correct. The texture will be converted..");
if (model.Format.IsCompressed())
{
if (candidate.Format.IsCompressed()) Decompress(candidate, candidate.Format.IsSRgb());
Compress(candidate, model.Format);
}
else
{
Decompress(candidate, candidate.Format.IsSRgb());
if (candidate.Format != model.Format) Compress(candidate, model.Format);
}
}
}
示例12: Remove
/// <summary>
/// Removes the texture at a specified position from a texture array.
/// </summary>
/// <param name="array">The array.</param>
/// <param name="indice">The indice.</param>
/// <exception cref="TextureToolsException">
/// The array size must be > 1.
/// or
/// The given indice must be between 0 and + array.ArraySize
/// </exception>
public void Remove(TexImage array, int indice)
{
if (array.ArraySize == 1)
{
Log.Error("The array size must be > 1.");
throw new TextureToolsException("The array size must be > 1.");
}
if (indice < 0 || indice > array.ArraySize-1)
{
Log.Error("The given indice must be between 0 and " + array.ArraySize);
throw new TextureToolsException("The given indice must be between 0 and " + array.ArraySize);
}
ExecuteRequest(array, new ArrayElementRemovalRequest(indice));
}
示例13: Insert
/// <summary>
/// Inserts a texture into a texture array at a specified position.
/// </summary>
/// <param name="array">The array.</param>
/// <param name="texture">The texture to be added.</param>
/// <param name="indice">The indice.</param>
/// <exception cref="TextureToolsException">The given indice must be between 0 and the array size</exception>
public void Insert(TexImage array, TexImage texture, int indice)
{
texture.Update();
if (indice < 0 || indice > array.ArraySize)
{
Log.Error("The given indice must be between 0 and " + array.ArraySize);
throw new TextureToolsException("The given indice must be between 0 and " + array.ArraySize);
}
CheckConformity(array, texture);
ExecuteRequest(array, new ArrayInsertionRequest(texture, indice));
}
示例14: RetrieveAtlas
/// <summary>
/// Retrieves the atlas from a TexImage and its corresponding layout file.
/// </summary>
/// <param name="texture">The texture.</param>
/// <param name="layoutFile">The layout file.</param>
/// <returns>An instance of <see cref="TexAtlas"/>.</returns>
/// <exception cref="TextureToolsException">The layout file doesn't exist. Please check the file path.</exception>
public TexAtlas RetrieveAtlas(TexImage texture, string layoutFile)
{
if (!File.Exists(layoutFile))
{
Log.Error("The file " + layoutFile + " doesn't exist. Please check the file path.");
throw new TextureToolsException("The file " + layoutFile + " doesn't exist. Please check the file path.");
}
return new TexAtlas(TexAtlas.TexLayout.Import(layoutFile), texture);
}
示例15: Update
/// <summary>
/// Updates a specific texture in the texture array with the given TexImage.
/// </summary>
/// <param name="array">The array.</param>
/// <param name="texture">The texture.</param>
/// <param name="indice">The indice.</param>
/// <exception cref="TextureToolsException">
/// The first given texture must be an array texture.
/// or
/// The given indice is out of range in the array texture.
/// </exception>
public void Update(TexImage array, TexImage texture, int indice)
{
texture.Update();
if (array.ArraySize == 1)
{
Log.Error("The first given texture must be an array texture.");
throw new TextureToolsException("The first given texture must be an array texture.");
}
if (array.ArraySize-1 < indice)
{
Log.Error("The given indice is out of range in the array texture.");
throw new TextureToolsException("The given indice is out of range in the array texture.");
}
CheckConformity(array, texture);
ExecuteRequest(array, new ArrayUpdateRequest(texture, indice));
}