4 using System.Collections.Generic;
6 using SiliconStudio.Core;
8 namespace SiliconStudio.TextureConverter
16 public IntPtr Data {
get;
internal set; }
17 public int DataSize {
get;
internal set; }
18 public int Width {
get;
internal set; }
19 public int Height {
get;
internal set; }
20 public int Depth {
get;
internal set; }
21 public int RowPitch {
get;
internal set; }
22 public int SlicePitch {
get;
internal set; }
26 public int ArraySize {
get;
internal set; }
27 public int MipmapCount {
get;
internal set; }
28 public SubImage[] SubImageArray {
get;
internal set; }
30 public string Name {
get; set; }
33 public int FaceCount {
get;
internal set; }
36 internal ITexLibrary DisposingLibrary {
get; set; }
37 internal ITexLibrary CurrentLibrary {
get; set; }
38 internal Dictionary<ITexLibrary, ITextureLibraryData> LibraryData {
get; set; }
59 public IntPtr Data {
get; set; }
60 public int DataSize {
get; set; }
61 public int Width {
get; set; }
62 public int Height {
get; set; }
63 public int RowPitch {
get; set; }
64 public int SlicePitch {
get; set; }
68 return "Size:"+ DataSize +
"\nwidth:" + Width +
"\nheight:" + Height +
"\nrowPitch:" + RowPitch +
"\nslicePitch:" + SlicePitch +
"\nData:" + Data;
80 Dimension = TextureDimension.Texture2D;
83 SubImageArray =
new SubImage[1];
84 Format = SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_UNorm;
86 LibraryData =
new Dictionary<ITexLibrary, ITextureLibraryData>();
105 public TexImage(IntPtr data,
int dataSize,
int width,
int height,
int depth, SiliconStudio.Paradox.Graphics.PixelFormat
format,
int mipmapCount,
int arraySize,
TextureDimension dimension,
int faceCount = 1)
113 MipmapCount = mipmapCount;
114 ArraySize = arraySize;
115 Dimension = dimension;
116 FaceCount = faceCount;
122 int subImagePerArrayElementCount = 0;
123 int curDepth = Depth;
124 for (
int i = 0; i < MipmapCount; ++i)
126 subImagePerArrayElementCount += curDepth;
127 curDepth = curDepth > 1 ? curDepth >>= 1 : curDepth;
130 imageCount = (int)(ArraySize * FaceCount * subImagePerArrayElementCount);
134 imageCount = (int)(ArraySize * FaceCount * MipmapCount);
137 SubImageArray =
new SubImage[imageCount];
139 int rowPitch, slicePitch, curHeight, curWidth;
141 Tools.ComputePitch(Format, Width, Height, out rowPitch, out slicePitch);
143 SlicePitch = slicePitch;
145 for (uint i = 0; i < FaceCount; ++i)
147 for (uint j = 0; j < ArraySize; ++j)
150 for (uint k = 0; k < MipmapCount; ++k)
154 Tools.ComputePitch(Format, curWidth, curHeight, out rowPitch, out slicePitch);
156 for (
int l = 0; l < depth; ++l)
159 SubImageArray[ct].Width = curWidth;
160 SubImageArray[ct].Height = curHeight;
161 SubImageArray[ct].RowPitch = rowPitch;
162 SubImageArray[ct].SlicePitch = slicePitch;
163 SubImageArray[ct].DataSize = slicePitch;
164 SubImageArray[ct].Data =
new IntPtr(Data.ToInt64() + l * slicePitch);
167 depth = depth > 1 ? depth >>= 1 : depth;
172 LibraryData =
new Dictionary<ITexLibrary, ITextureLibraryData>();
180 if (ReferenceEquals(null, obj))
return false;
181 if (ReferenceEquals(
this, obj))
return true;
182 if (obj.GetType() != this.GetType())
return false;
186 if (SubImageArray.Length != img.
SubImageArray.Length)
return false;
187 for (
int i = 0; i < SubImageArray.Length; ++i)
197 return Width == img.Width
198 && Height == img.Height
199 && Depth == img.Depth
200 && Format == img.Format
201 && MipmapCount == img.MipmapCount
202 && ArraySize == img.ArraySize
203 && FaceCount == img.FaceCount
204 && Dimension == img.Dimension
205 && DataSize == img.DataSize
206 && RowPitch == img.RowPitch
207 && SlicePitch == img.SlicePitch;
214 return Width*Height*Depth*(int)Format*MipmapCount*ArraySize;
241 virtual public Object
Clone(
bool CopyMemory)
243 if (this.CurrentLibrary != null) { this.CurrentLibrary.EndLibrary(
this); this.CurrentLibrary = null; }
248 Data = CopyMemory?System.Runtime.InteropServices.Marshal.AllocHGlobal(this.DataSize):this.Data,
249 DataSize = this.DataSize,
251 Height = this.Height,
253 RowPitch = this.RowPitch,
254 SlicePitch = this.SlicePitch,
255 Format = this.Format,
258 ArraySize = this.ArraySize,
259 FaceCount = this.FaceCount,
260 MipmapCount = this.MipmapCount,
261 SubImageArray =
new SubImage[this.SubImageArray.Length],
262 Dimension =
this.Dimension,
266 DisposingLibrary =
this.DisposingLibrary,
267 CurrentLibrary =
this.CurrentLibrary,
268 LibraryData =
new Dictionary<ITexLibrary, ITextureLibraryData>(),
271 Disposed = this.Disposed,
274 if (CopyMemory) Utilities.CopyMemory(newTex.Data, this.Data, this.DataSize);
277 for (
int i = 0; i < this.SubImageArray.Length; ++i)
279 newTex.SubImageArray[i] = this.SubImageArray[i];
280 if (CopyMemory) newTex.SubImageArray[i].Data =
new IntPtr(newTex.
Data.ToInt64() + offset);
281 offset += newTex.SubImageArray[i].DataSize;
284 if (CopyMemory && this.DisposingLibrary != null)
286 this.DisposingLibrary.StartLibrary(newTex);
288 else if (!CopyMemory)
290 newTex.DisposingLibrary = null;
302 if (CurrentLibrary != null) CurrentLibrary.EndLibrary(
this);
303 CurrentLibrary = null;
315 internal virtual void Rescale(
int width,
int height)
327 internal virtual void Flip(
Orientation orientation) {}
335 internal virtual void Save(
string file) { }
343 if (CurrentLibrary != null) CurrentLibrary.EndLibrary(
this);
344 if (Disposed)
return;
345 if (DisposingLibrary != null) DisposingLibrary.Dispose(
this);
352 return "Image - Dimension:" + Dimension +
" - Format:" + Format +
" - " + Width +
" x " + Height +
" x " + Depth +
" - MipmapCount:" + MipmapCount +
" - ArraySize:" + ArraySize +
" - SubImageArray Length:" + SubImageArray.Length;
override string ToString()
Object Clone()
Creates a new object that is a copy of the current instance.
TextureDimension
The Different types of texture
override bool Equals(object obj)
void Update()
Forces the last current library to update the image data.
void Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resourc...
override String ToString()
virtual Object Clone(bool CopyMemory)
Creates a new object that is a copy of the current instance.
override int GetHashCode()
TexImage(IntPtr data, int dataSize, int width, int height, int depth, SiliconStudio.Paradox.Graphics.PixelFormat format, int mipmapCount, int arraySize, TextureDimension dimension, int faceCount=1)
Initializes a new instance of the TexImage class.
The audio engine is disposed. The current instance cannot be used to play or create sounds anymore...
A structure describing an image of one mip map level (of one member in an array texture).
Temporary format containing texture data and information. Used as buffer between texture libraries...
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
Android.Widget.Orientation Orientation
PixelFormat
Defines various types of pixel formats.