forked from crskycode/BCnEncoder.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextureData.cs
More file actions
661 lines (585 loc) · 21.8 KB
/
Copy pathTextureData.cs
File metadata and controls
661 lines (585 loc) · 21.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BCnEncoder.Decoder;
using BCnEncoder.Decoder.Options;
using BCnEncoder.Encoder;
using BCnEncoder.Shared.Colors;
using BCnEncoder.TextureFormats;
using CommunityToolkit.HighPerformance;
namespace BCnEncoder.Shared
{
public enum CubeMapFaceDirection
{
/// <summary>
/// Right face
/// </summary>
XPositive = 0,
/// <summary>
/// Left face
/// </summary>
XNegative = 1,
/// <summary>
/// Top face
/// </summary>
YPositive = 2,
/// <summary>
/// Bottom face
/// </summary>
YNegative = 3,
/// <summary>
/// Back face
/// </summary>
ZPositive = 4,
/// <summary>
/// Front face
/// </summary>
ZNegative = 5
}
/// <summary>
/// Indicates how the alpha channel in texture data is encoded in relation to the color channels.
/// </summary>
public enum AlphaChannelHint
{
/// <summary>
/// The alpha encoding type is not known or not specified.
/// </summary>
Unknown,
/// <summary>
/// Alpha is straight/non-premultiplied (color values are independent of alpha).
/// This is the typical format for standard image formats like PNG.
/// </summary>
Straight,
/// <summary>
/// Alpha is premultiplied (color channels are already multiplied by alpha).
/// This is commonly used in GPU texture formats and during rendering.
/// </summary>
Premultiplied
}
public class BCnTextureData
{
/// <summary>
/// Creates a new BCnTexture object
/// </summary>
/// <param name="inputFormat">The compression format of the texture</param>
/// <param name="width">Width of the texture in pixels</param>
/// <param name="height">Height of the texture in pixels</param>
/// <param name="depth">Depth of the texture for volume textures, default is 1</param>
/// <param name="numMips">Number of mip map levels, default is 0 (no mipmaps)</param>
/// <param name="numArrayElements">Number of array elements for texture arrays, default is 0 (not an array)</param>
/// <param name="isCubeMap">Whether this texture is a cubemap (6 faces), default is false</param>
/// <param name="allocateBuffers">Whether to allocate memory buffers for the texture data, default is false</param>
/// <param name="alphaChannelHint">Hint about how the alpha channel is encoded (straight, premultiplied, or unknown), default is Unknown</param>
public BCnTextureData(CompressionFormat inputFormat, int width, int height, int depth = 1, int numMips = 0, int numArrayElements = 0, bool isCubeMap = false, bool allocateBuffers = false, AlphaChannelHint alphaChannelHint = AlphaChannelHint.Unknown)
{
if (width <= 0)
throw new ArgumentException($"Invalid texture size width: {width}", nameof(width));
if (height <= 0)
throw new ArgumentException($"Invalid texture size height: {height}", nameof(height));
Format = inputFormat;
Width = width;
Height = height;
Depth = Math.Max(depth, 1);
NumFaces = isCubeMap ? 6 : 1;
NumMips = Math.Max(numMips, 1);
NumArrayElements = Math.Max(numArrayElements, 1);
AlphaChannelHint = alphaChannelHint;
Mips = new MipMapLevel[NumMips];
for (int i = 0; i < NumMips; i++)
{
Mips[i] = new MipMapLevel(this, i, NumFaces, NumArrayElements, allocateBuffers);
}
}
public class MipMapLevel
{
private readonly BCnTextureData texture;
public int Width { get; set; }
public int Height { get; set; }
public int Depth { get; set; }
public long SizeInBytes { get; set; }
private TexData[] textureData;
public TexData this[CubeMapFaceDirection face, int arrayIndex = 0]
{
get => textureData[(int)face * texture.NumArrayElements + arrayIndex];
set => textureData[(int)face * texture.NumArrayElements + arrayIndex] = value;
}
public TexData First => textureData[0];
internal MipMapLevel(BCnTextureData texture, int level, int numFaces, int numArrayElements, bool allocateBuffers)
{
if (level >= texture.NumMips)
throw new ArgumentException("Invalid mip level");
this.texture = texture;
MipMapper.CalculateMipLevelSize(texture.Width, texture.Height, texture.Depth, level, out var mipWidth, out var mipHeight, out var mipDepth);
if (mipWidth == 0 || mipHeight == 0 || mipDepth == 0)
throw new ArgumentException("Invalid mip level size");
if (numFaces != 1 && numFaces != 6)
throw new ArgumentException("Invalid number of faces");
if (numArrayElements < 1)
throw new ArgumentException("Invalid number of array items");
this.Width = mipWidth;
this.Height = mipHeight;
this.Depth = mipDepth;
this.SizeInBytes = texture.Format.CalculateMipByteSize(mipWidth, mipHeight, mipDepth);
this.textureData = new TexData[numFaces * numArrayElements];
for (var f = 0; f < numFaces; f++)
{
for (var a = 0; a < numArrayElements; a++)
{
byte[] data = null;
if (allocateBuffers)
{
data = new byte[SizeInBytes];
}
textureData[f * numArrayElements + a] = new TexData((CubeMapFaceDirection)f, a, this, data);
}
}
}
}
public class TexData
{
public CubeMapFaceDirection Direction { get; private set; }
public int ArrayIndex { get; private set; }
private MipMapLevel Mip { get; }
private byte[] data;
public byte[] Data
{
get => data;
set
{
if (value != null && value.LongLength != Mip.SizeInBytes)
throw new ArgumentException("Data size does not match expected mip size! Please provide a buffer of the correct size.");
data = value;
}
}
public int Width => Mip.Width;
public int Height => Mip.Height;
public int Depth => Mip.Depth;
public long SizeInBytes => Mip.SizeInBytes;
public TexData(CubeMapFaceDirection direction, int arrayIndex, MipMapLevel mip, byte[] data)
{
Direction = direction;
ArrayIndex = arrayIndex;
Mip = mip;
Data = data;
}
/// <summary>
/// Potentially dangerous!
/// Please use only when you know for sure the underlying data is of the provided type.
/// I.e. Check that CompressionFormat == <see cref="CompressionFormat.Rgba32"/>
/// before trying to get a <see cref="ColorRgba32"/> memory.
/// </summary>
public Memory2D<T> AsMemory2D<T>() where T : unmanaged
{
if (Unsafe.SizeOf<T>() * Width * Height != Data.Length)
{
throw new InvalidCastException($"The size of {typeof(T).Name} does not match data format!");
}
return Data.AsMemory().Cast<byte, T>()
.AsMemory2D(Height, Width);
}
/// <summary>
/// Potentially dangerous!
/// Please use only when you know for sure the underlying data is of the provided type.
/// I.e. Check that CompressionFormat == <see cref="CompressionFormat.Rgba32"/>
/// before trying to get a <see cref="ColorRgba32"/> memory.
/// </summary>
public Memory<T> AsMemory<T>() where T : unmanaged
{
if (Unsafe.SizeOf<T>() * Width * Height != Data.Length)
{
throw new InvalidCastException($"The size of {typeof(T).Name} does not match data format!");
}
return Data.AsMemory().Cast<byte, T>();
}
}
/// <summary>
/// Width of mip0
/// </summary>
public int Width { get; init; }
/// <summary>
/// Height of mip0
/// </summary>
public int Height { get; init; }
/// <summary>
/// Depth of mip0 (For volume textures only. Otherwise, 1)
/// </summary>
public int Depth { get; init; }
/// <summary>
/// Number of mip maps
/// </summary>
public int NumMips { get; set; }
/// <summary>
/// Number of faces. 1 if normal texture, 6 if cube map
/// </summary>
public int NumFaces { get; set; }
/// <summary>
/// Number of array elements. For texture arrays.
/// </summary>
public int NumArrayElements { get; set; }
/// <summary>
/// The CompressionFormat of this texture data.
/// </summary>
public CompressionFormat Format { get; set; }
/// <summary>
/// Access mip levels. Only mip level 0 is present if the texture has no mip levels.
/// </summary>
public MipMapLevel[] Mips { get; set; }
/// <summary>
/// Access the first texture of the first mip level.
/// This is the default texture for the texture data if there are no mips, no cubemap faces, and no array elements.
/// </summary>
public TexData First => Mips[0].First;
/// <summary>
/// True if texture is cube map
/// </summary>
public bool IsCubeMap => NumFaces > 1;
/// <summary>
/// True if texture has mip levels
/// </summary>
public bool HasMipLevels => NumMips > 1;
/// <summary>
/// True if the texture format is one of the block-compressed formats
/// </summary>
public bool IsBlockCompressed => Format.IsBlockCompressedFormat();
/// <summary>
/// True if the texture is a volume texture. (Z > 1)
/// </summary>
public bool IsVolumeTexture => Depth > 1;
/// <summary>
/// True if the texture is a texture array. (NumArrayElements > 1)
/// </summary>
public bool IsArrayTexture => NumArrayElements > 1;
/// <summary>
/// Hint about how the alpha channel is encoded in relation to color channels.
/// This helps the encoder/decoder make appropriate decisions when processing the texture data.
/// </summary>
public AlphaChannelHint AlphaChannelHint { get; set; } = AlphaChannelHint.Unknown;
public long TotalByteSize => Mips.Sum(m => m.SizeInBytes * NumFaces * NumArrayElements);
public TTexture AsTexture<TTexture>()
where TTexture : class, ITextureFileFormat, new()
{
var tex = new TTexture();
tex.FromTextureData(this);
return tex;
}
public static BCnTextureData CombineCubeMap(
BCnTextureData right,
BCnTextureData left,
BCnTextureData top,
BCnTextureData down,
BCnTextureData back,
BCnTextureData front
)
{
if (
right.Width != left.Width || right.Height != left.Height ||
right.Width != top.Width || right.Height != top.Height ||
right.Width != down.Width || right.Height != down.Height ||
right.Width != back.Width || right.Height != back.Height ||
right.Width != front.Width || right.Height != front.Height
)
{
throw new ArgumentException("All faces of a cubeMap must be of equal width and height!");
}
if (
right.Depth != 1 ||
left.Depth != 1 ||
top.Depth != 1 ||
down.Depth != 1 ||
back.Depth != 1 ||
front.Depth != 1)
{
throw new ArgumentException("All faces of a cubeMap must have a depth of 1!");
}
if (
right.Format != left.Format ||
left.Format != top.Format ||
top.Format != down.Format ||
down.Format != back.Format ||
back.Format != front.Format)
{
throw new ArgumentException("All faces of a cubeMap must have the same format!");
}
if (
right.NumMips != left.NumMips ||
left.NumMips != top.NumMips ||
top.NumMips != down.NumMips ||
down.NumMips != back.NumMips ||
back.NumMips != front.NumMips)
{
throw new ArgumentException("All faces of a cubeMap must have the same amount of mipmaps!");
}
if (
right.NumArrayElements != left.NumArrayElements ||
left.NumArrayElements != top.NumArrayElements ||
top.NumArrayElements != down.NumArrayElements ||
down.NumArrayElements != back.NumArrayElements ||
back.NumArrayElements != front.NumArrayElements)
{
throw new ArgumentException("All faces of a cubeMap must have the same amount of array elements!");
}
if (
right.AlphaChannelHint != left.AlphaChannelHint ||
left.AlphaChannelHint != top.AlphaChannelHint ||
top.AlphaChannelHint != down.AlphaChannelHint ||
down.AlphaChannelHint != back.AlphaChannelHint ||
back.AlphaChannelHint != front.AlphaChannelHint)
{
throw new ArgumentException("All faces of a cubeMap must have the same amount of array elements!");
}
var outData = new BCnTextureData(right.Format, right.Width, right.Height, right.Depth,
right.NumMips,
right.NumArrayElements,
isCubeMap: true,
allocateBuffers: false,
alphaChannelHint: right.AlphaChannelHint);
for (var m = 0; m < right.NumMips; m++)
{
for (var a = 0; a < right.NumArrayElements; a++)
{
outData.Mips[m][CubeMapFaceDirection.XPositive, a].Data = right.Mips[m][CubeMapFaceDirection.XPositive, a].Data;
outData.Mips[m][CubeMapFaceDirection.XNegative, a].Data = left.Mips[m][CubeMapFaceDirection.XNegative, a].Data;
outData.Mips[m][CubeMapFaceDirection.YPositive, a].Data = top.Mips[m][CubeMapFaceDirection.YPositive, a].Data;
outData.Mips[m][CubeMapFaceDirection.YNegative, a].Data = down.Mips[m][CubeMapFaceDirection.YNegative, a].Data;
outData.Mips[m][CubeMapFaceDirection.ZPositive, a].Data = back.Mips[m][CubeMapFaceDirection.ZPositive, a].Data;
outData.Mips[m][CubeMapFaceDirection.ZNegative, a].Data = front.Mips[m][CubeMapFaceDirection.ZNegative, a].Data;
}
}
return outData;
}
/// <summary>
/// Checks if the data is valid.
/// </summary>
/// <returns>True if the data is valid, false otherwise.</returns>
public bool IsValid()
{
if (Width <= 0 || Height <= 0)
return false;
if (NumMips <= 0)
return false;
if (NumFaces != 1 && NumFaces != 6)
return false;
if (NumArrayElements < 1)
return false;
if (Mips.Length != NumMips)
return false;
foreach (var t in Mips)
{
if (t.Width <= 0 || t.Height <= 0)
return false;
if (t.SizeInBytes <= 0)
return false;
for (var f = 0; f < NumFaces; f++)
{
for (var a = 0; a < NumArrayElements; a++)
{
if (t[(CubeMapFaceDirection)f, a].Data == null)
return false;
if (t[(CubeMapFaceDirection)f, a].Data.Length != t.SizeInBytes)
return false;
}
}
}
return true;
}
/// <summary>
/// Validates the texture data. Throws <see cref="InvalidTextureException"/> if the data is invalid.
/// </summary>
public void Validate()
{
if (Width <= 0 || Height <= 0)
{
throw new InvalidTextureException($"Texture has invalid dimensions: Width={Width}, Height={Height}");
}
if (NumMips <= 0)
{
throw new InvalidTextureException("Texture has no mip levels");
}
if (NumFaces != 1 && NumFaces != 6)
{
throw new InvalidTextureException("Texture has invalid number of faces");
}
if (NumArrayElements < 1)
{
throw new InvalidTextureException("Texture has invalid number of array elements");
}
if (Mips.Length != NumMips)
{
throw new InvalidTextureException("Texture has incorrect number of mip levels");
}
for (var i = 0; i < Mips.Length; i++)
{
var mip = Mips[i];
if (mip.Width <= 0 || mip.Height <= 0)
{
throw new InvalidTextureException(
$"Mip level {i} has invalid dimensions: Width={mip.Width}, Height={mip.Height}");
}
if (mip.SizeInBytes <= 0)
throw new InvalidTextureException($"Mip level {i} has invalid size: {mip.SizeInBytes}");
for (var f = 0; f < NumFaces; f++)
{
for (var a = 0; a < NumArrayElements; a++)
{
var texData = mip[(CubeMapFaceDirection)f, a];
if (texData.Data == null)
{
throw new InvalidTextureException(
$"Mip level {i}, face {(CubeMapFaceDirection)f}, array element {a} has null data");
}
if (texData.Data.Length != mip.SizeInBytes)
{
throw new InvalidTextureException(
$"Mip level {i}, face {(CubeMapFaceDirection)f}, array element {a} has incorrect data size");
}
}
}
}
}
/// <summary>
/// Creates a simple BCnTextureData instance from a single byte array with no mips, no array elements, and not a cubemap.
/// </summary>
/// <param name="format">The compression format of the input texture data.</param>
/// <param name="width">The width of the texture.</param>
/// <param name="height">The height of the texture.</param>
/// <param name="data">The texture data as a byte array.</param>
/// <param name="alphaChannelHint">Specifies how the alpha channel is encoded. If set to Unknown, will attempt to guess based on format.</param>
/// <returns>A new BCnTextureData instance.</returns>
public static BCnTextureData FromSingle(CompressionFormat format, int width, int height, byte[] data, AlphaChannelHint alphaChannelHint)
{
if (alphaChannelHint == AlphaChannelHint.Unknown)
{
alphaChannelHint = format.GuessAlphaChannelHint();
}
var texture = new BCnTextureData(format, width, height, 1, 1, 1, false, false, alphaChannelHint);
texture.Mips[0].First.Data = data.ToArray();
return texture;
}
/// <summary>
/// Creates a cubemap BCnTextureData instance from six byte[] faces.
/// </summary>
/// <param name="format">The compression format of the texture data.</param>
/// <param name="size">The size of each cubemap face (assuming square faces).</param>
/// <param name="faces">An IEnumerable of six byte arrays, one for each cubemap face.</param>
/// <param name="alphaChannelHint">Specifies how the alpha channel is encoded. If set to Unknown, will attempt to guess based on format.</param>
/// <returns>A new BCnTextureData instance representing a cubemap.</returns>
/// <exception cref="ArgumentException">Thrown when the number of faces is not exactly 6.</exception>
public static BCnTextureData FromCubemap(CompressionFormat format, int size, IEnumerable<byte[]> faces, AlphaChannelHint alphaChannelHint)
{
var facesArray = faces.ToArray();
if (facesArray.Length != 6)
throw new ArgumentException("Cubemap requires exactly 6 faces", nameof(faces));
if (alphaChannelHint == AlphaChannelHint.Unknown)
{
alphaChannelHint = format.GuessAlphaChannelHint();
}
var texture = new BCnTextureData(format, size, size, depth: 1, numMips: 1, numArrayElements: 1, true, false, alphaChannelHint);
for (int f = 0; f < facesArray.Length; f++)
{
texture.Mips[0][(CubeMapFaceDirection)f, 0].Data = facesArray[f];
}
return texture;
}
/// <summary>
/// Creates a texture array BCnTextureData instance from multiple byte[] slices.
/// </summary>
/// <param name="format">The compression format of the texture data.</param>
/// <param name="width">The width of each texture in the array.</param>
/// <param name="height">The height of each texture in the array.</param>
/// <param name="slices">An IEnumerable of byte arrays, one for each texture in the array.</param>
/// <returns>A new BCnTextureData instance representing a texture array.</returns>
public static BCnTextureData FromTextureArray(CompressionFormat format, int width, int height, IEnumerable<byte[]> slices)
{
var slicesArray = slices.ToArray();
var texture = new BCnTextureData(format, width, height, depth: 1, numMips: 1, slicesArray.Length, false, false);
for (int i = 0; i < slicesArray.Length; i++)
{
texture.Mips[0][0, i].Data = slicesArray[i];
}
return texture;
}
/// <summary>
/// Creates a BCnTextureData instance with multiple mip levels from byte arrays.
/// </summary>
/// <param name="format">The compression format of the texture data.</param>
/// <param name="width">The width of the largest (first) mip level.</param>
/// <param name="height">The height of the largest (first) mip level.</param>
/// <param name="mipLevels">An IEnumerable of byte arrays, one for each mip level.</param>
/// <returns>A new BCnTextureData instance with the specified mip levels.</returns>
public static BCnTextureData FromMipLevels(CompressionFormat format, int width, int height, IEnumerable<byte[]> mipLevels)
{
var mipsArray = mipLevels.ToArray();
var texture = new BCnTextureData(format, width, height, depth: 1, mipsArray.Length, 1, false, false);
for (int i = 0; i < mipsArray.Length; i++)
{
texture.Mips[i].First.Data = mipsArray[i];
}
return texture;
}
}
/// <summary>
/// Thrown when the provided texture data is invalid.
/// </summary>
public class InvalidTextureException : Exception
{
public InvalidTextureException(string message) : base(message)
{
}
}
public static class BCnTextureDataExtensions
{
/// <summary>
/// Convert a <see cref="BCnTextureData"/> to another uncompressed pixel format.
/// </summary>
/// <param name="data"></param>
/// <param name="format"></param>
/// <param name="convertColorspace">Whether to do colorspace conversion when the source format does not match the target format</param>
/// <returns>Returns self if already desired format. New data is created otherwise.</returns>
/// <exception cref="ArgumentException"></exception>
public static BCnTextureData ConvertTo(this BCnTextureData data, CompressionFormat format, bool convertColorspace = false)
{
if (data.Format == format)
return data;
if (format.IsBlockCompressedFormat())
{
throw new ArgumentException(
$"New format should be a non-block-compressed format. Please use {nameof(BcEncoder)} for encoding to compressed formats!");
}
if(data.Format.IsBlockCompressedFormat())
{
throw new ArgumentException(
$"Source format should be a non-block-compressed format. Please use {nameof(BcDecoder)} for decoding from compressed formats!");
}
if (data.Format == format)
{
return data;
}
return ConvertPixelFormat(data, format, convertColorspace);
}
private static BCnTextureData ConvertPixelFormat(BCnTextureData data, CompressionFormat newFormat, bool convertColorspace)
{
var newData = new BCnTextureData(newFormat, data.Width, data.Height, data.Depth, data.NumMips, data.NumArrayElements, data.IsCubeMap, false, data.AlphaChannelHint);
for (var m = 0; m < data.NumMips; m++)
{
for (var f = 0; f < data.NumFaces; f++)
{
for (var a = 0; a < data.NumArrayElements; a++)
{
var converted =
ColorExtensions.InternalConvertToAsBytesFromBytes(
data.Mips[m][(CubeMapFaceDirection)f, a].Data,
data.Format,
newFormat,
convertColorspace ? data.Format.GetColorConversionMode(newFormat) : ColorConversionMode.None);
newData.Mips[m][(CubeMapFaceDirection)f, a].Data = converted;
}
}
}
return newData;
}
}
}