4 using System.Collections.Generic;
5 using System.Runtime.InteropServices;
8 using SiliconStudio.Core.Diagnostics;
9 using SiliconStudio.TextureConverter.PvrttWrapper;
10 using SiliconStudio.TextureConverter.Requests;
12 namespace SiliconStudio.TextureConverter.TexLibraries
18 internal class PvrTextureLibraryData : ITextureLibraryData
29 public PVRTextureHeader Header;
35 internal class PvrttTexLib : ITexLibrary
37 private static object lockObject =
new object();
38 private static Logger Log = GlobalLogger.GetLogger(
"PvrttTexLib");
43 public PvrttTexLib() {}
48 public void Dispose() {}
51 public void Dispose(TexImage image)
53 if (!image.LibraryData.ContainsKey(
this))
return;
54 PvrTextureLibraryData libraryData = (PvrTextureLibraryData)image.LibraryData[
this];
56 if (libraryData.Texture != null)
58 libraryData.Header = null;
59 libraryData.Texture.Dispose();
64 public bool SupportBGRAOrder()
69 public bool CanHandleRequest(TexImage image, IRequest request)
74 case RequestType.Loading:
75 LoadingRequest loader = (LoadingRequest)request;
76 return loader.Mode == LoadingRequest.LoadingMode.FilePath && (Path.GetExtension(loader.FilePath).Equals(
".pvr") || Path.GetExtension(loader.FilePath).Equals(
".ktx"));
78 case RequestType.Compressing:
79 CompressingRequest compress = (CompressingRequest)request;
80 return SupportFormat(compress.Format) && SupportFormat(image.Format);
82 case RequestType.Export:
83 ExportRequest export = (ExportRequest)request;
84 return SupportFormat(image.Format) && (Path.GetExtension(export.FilePath).Equals(
".pvr") || Path.GetExtension(export.FilePath).Equals(
".ktx"));
86 case RequestType.Decompressing:
87 return SupportFormat(image.Format);
89 case RequestType.MipMapsGeneration:
90 return ((MipMapsGenerationRequest)request).Filter != Filter.MipMapGeneration.Box;
92 case RequestType.Rescaling:
93 Filter.Rescaling filter = ((RescalingRequest)request).Filter;
94 return filter == Filter.Rescaling.Bicubic || filter == Filter.Rescaling.Bilinear || filter == Filter.Rescaling.Nearest;
96 case RequestType.PreMultiplyAlpha:
97 case RequestType.SwitchingChannels:
98 case RequestType.Flipping:
99 case RequestType.NormalMapGeneration:
108 public void StartLibrary(TexImage image)
110 PvrTextureLibraryData libraryData =
new PvrTextureLibraryData();
112 int imageArraySize = image.Dimension == TexImage.TextureDimension.TextureCube ? image.ArraySize/6 : image.ArraySize;
113 int imageFaceCount = image.Dimension == TexImage.TextureDimension.TextureCube ? 6 : 1;
116 ulong
format = RetrieveNativeFormat(image.Format);
117 EPVRTColourSpace colorSpace = RetrieveNativeColorSpace(image.Format);
118 EPVRTVariableType pixelType = RetrieveNativePixelType(image.Format);
119 libraryData.Header =
new PVRTextureHeader(format, image.Height, image.Width, image.Depth, image.MipmapCount, imageArraySize, imageFaceCount, colorSpace, pixelType);
122 int depth = image.Depth;
123 libraryData.Texture =
new PVRTexture(libraryData.Header, IntPtr.Zero);
128 for (uint i = 0; i < imageFaceCount; ++i)
130 for (uint j = 0; j < imageArraySize; ++j)
132 for (uint k = 0; k < image.MipmapCount; ++k)
134 Core.Utilities.CopyMemory(libraryData.Texture.GetDataPtr(k, j, i), image.SubImageArray[imageCount].Data, image.SubImageArray[imageCount].DataSize * depth);
137 depth = depth > 1 ? depth >>= 1 : depth;
142 catch (AccessViolationException e)
144 libraryData.Texture.Dispose();
145 Log.Error(
"Failed to convert texture to PvrTexLib native data, check your texture settings. ", e);
146 throw new TextureToolsException(
"Failed to convert texture to PvrTexLib native data, check your texture settings. ", e);
150 if (image.DisposingLibrary != null) image.DisposingLibrary.Dispose(image);
152 image.LibraryData[
this] = libraryData;
154 image.DisposingLibrary =
this;
158 public void EndLibrary(TexImage image)
161 if (!image.LibraryData.ContainsKey(
this))
return;
162 PvrTextureLibraryData libraryData = (PvrTextureLibraryData)image.LibraryData[
this];
165 UpdateImage(image, libraryData);
173 int imageCount, depth;
174 if (image.Dimension == TexImage.TextureDimension.Texture3D)
176 int subImagePerArrayElementCount = 0;
177 int curDepth = image.Depth;
178 for (
int i = 0; i < image.MipmapCount; ++i)
180 subImagePerArrayElementCount += curDepth;
181 curDepth = curDepth > 1 ? curDepth >>= 1 : curDepth;
184 imageCount = (int)(image.ArraySize * image.FaceCount * subImagePerArrayElementCount);
188 imageCount = (int)(image.ArraySize * image.FaceCount * image.MipmapCount);
191 image.SubImageArray =
new TexImage.SubImage[imageCount];
193 int rowPitch, slicePitch, height, width;
195 for (uint i = 0; i < image.FaceCount; ++i)
197 for (uint j = 0; j < image.ArraySize; ++j)
200 for (uint k = 0; k < image.MipmapCount; ++k)
202 width = (int)libraryData.Header.GetWidth(k);
203 height = (int)libraryData.Header.GetHeight(k);
204 Tools.ComputePitch(image.Format, width, height, out rowPitch, out slicePitch);
206 for (
int l = 0; l < depth; ++l)
208 image.SubImageArray[ct] =
new TexImage.SubImage();
209 image.SubImageArray[ct].Width = width;
210 image.SubImageArray[ct].Height = height;
211 image.SubImageArray[ct].RowPitch = rowPitch;
212 image.SubImageArray[ct].SlicePitch = slicePitch;
213 image.SubImageArray[ct].DataSize = slicePitch;
214 image.SubImageArray[ct].Data =
new IntPtr(libraryData.Texture.GetDataPtr(k, j, i).ToInt64() + l*slicePitch);
217 depth = depth > 1 ? depth >>= 1 : depth;
223 image.ArraySize = image.ArraySize * image.FaceCount;
226 image.DisposingLibrary =
this;
230 public void Execute(TexImage image, IRequest request)
232 PvrTextureLibraryData libraryData = image.LibraryData.ContainsKey(
this) ? (PvrTextureLibraryData)image.LibraryData[this] : null;
236 case RequestType.Loading:
237 Load(image, (LoadingRequest)request);
240 case RequestType.Compressing:
241 Compress(image, libraryData, (CompressingRequest)request);
244 case RequestType.Export:
245 Export(image, libraryData, (ExportRequest)request);
248 case RequestType.Decompressing:
252 case RequestType.MipMapsGeneration:
253 GenerateMipMaps(image, libraryData, (MipMapsGenerationRequest)request);
256 case RequestType.SwitchingChannels:
257 SwitchChannels(image, libraryData, (SwitchingBRChannelsRequest)request);
260 case RequestType.Rescaling:
261 Rescale(image, libraryData, (RescalingRequest)request);
264 case RequestType.Flipping:
265 Flip(image, libraryData, (FlippingRequest)request);
268 case RequestType.NormalMapGeneration:
272 case RequestType.PreMultiplyAlpha:
277 Log.Error(
"FITexLib (FreeImage) can't handle this request: " + request.Type);
278 throw new TextureToolsException(
"FITexLib (FreeImage) can't handle this request: " + request.Type);
288 private void Load(TexImage image, LoadingRequest request)
290 Log.Info(
"Loading " + request.FilePath +
" ...");
292 PvrTextureLibraryData libraryData =
new PvrTextureLibraryData();
293 image.LibraryData[
this] = libraryData;
295 libraryData.Texture =
new PVRTexture(request.FilePath);
296 libraryData.Header = libraryData.Texture.GetHeader();
298 image.Width = (int)libraryData.Header.GetWidth();
299 image.Height = (int)libraryData.Header.GetHeight();
300 image.Depth = (int)libraryData.Header.GetDepth();
301 image.Format = RetrieveFormatFromNativeData(libraryData.Header);
304 Tools.ComputePitch(image.Format, (int)image.Width, (
int)image.Height, out pitch, out slice);
305 image.RowPitch = pitch;
306 image.SlicePitch = slice;
308 image.DisposingLibrary =
this;
310 UpdateImage(image, libraryData);
312 if (image.FaceCount > 1 && image.FaceCount % 6 == 0)
313 image.Dimension = TexImage.TextureDimension.TextureCube;
314 else if(image.Depth > 1)
315 image.Dimension = TexImage.TextureDimension.Texture3D;
316 else if (image.Height > 0)
317 image.Dimension = TexImage.TextureDimension.Texture2D;
319 image.Dimension = TexImage.TextureDimension.Texture1D;
330 private void Rescale(TexImage image, PvrTextureLibraryData libraryData, RescalingRequest request)
332 int width = request.ComputeWidth(image);
333 int height = request.ComputeHeight(image);
335 Log.Info(
"Rescaling to " + width +
"x" + height +
" ...");
338 switch(request.Filter)
340 case Filter.Rescaling.Bilinear:
341 filter = EResizeMode.eResizeLinear;
343 case Filter.Rescaling.Bicubic:
344 filter = EResizeMode.eResizeCubic;
346 case Filter.Rescaling.Nearest:
347 filter = EResizeMode.eResizeNearest;
350 filter = EResizeMode.eResizeCubic;
354 Utilities.Resize(libraryData.Texture, (uint)width, (uint)height, (uint)image.Depth, filter);
355 UpdateImage(image, libraryData);
358 image.Rescale(width, height);
368 private void Export(TexImage image, PvrTextureLibraryData libraryData, ExportRequest request)
370 Log.Info(
"Exporting to " + request.FilePath +
" ...");
372 if (request.MinimumMipMapSize > 1)
374 int newMipMapCount = image.MipmapCount;
375 for (
int i = image.MipmapCount - 1; i > 0; --i)
377 if (libraryData.Header.GetWidth((uint)i) >= request.MinimumMipMapSize || libraryData.Header.GetHeight((uint)i) >= request.MinimumMipMapSize)
385 PVRTextureHeader header =
new PVRTextureHeader(RetrieveNativeFormat(image.Format), image.Height, image.Width, image.Depth, newMipMapCount, image.ArraySize, image.FaceCount);
386 PVRTexture texture =
new PVRTexture(header, IntPtr.Zero);
390 for (uint i = 0; i < image.FaceCount; ++i)
392 for (uint j = 0; j < image.ArraySize; ++j)
394 for (uint k = 0; k < newMipMapCount; ++k)
396 Core.Utilities.CopyMemory(texture.GetDataPtr(k, j, i), libraryData.Texture.GetDataPtr(k, j, i), (int)libraryData.Header.GetDataSize((
int)k,
false,
false));
401 catch (AccessViolationException e)
404 Log.Error(
"Failed to export texture with the mipmap minimum size request. ", e);
405 throw new TextureToolsException(
"Failed to export texture with the mipmap minimum size request. ", e);
409 texture.Save(request.FilePath);
414 libraryData.Texture.Save(request.FilePath);
417 image.Save(request.FilePath);
428 private void SwitchChannels(TexImage image, PvrTextureLibraryData libraryData, SwitchingBRChannelsRequest request)
430 Log.Info(
"Switching channels B and R ...");
432 switch (image.Format)
434 case SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_UNorm:
435 image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm;
break;
436 case SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_Typeless:
437 image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_Typeless;
break;
438 case SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_UNorm_SRgb:
439 image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm_SRgb;
break;
440 case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_Typeless:
441 image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_Typeless;
break;
442 case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm:
443 image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_UNorm;
break;
444 case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm_SRgb:
445 image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_UNorm_SRgb;
break;
447 Log.Error(
"Unsuported format for channel switching.");
448 throw new TextureToolsException(
"Unsuported format for channel switching.");
451 PVRTexture textureTemp =
new PVRTexture(libraryData.Header, libraryData.Texture.GetDataPtr());
453 EChannelName e1 = EChannelName.eBlue;
454 EChannelName e2 = EChannelName.eRed;
456 Utilities.CopyChannels(libraryData.Texture, textureTemp, 1, out e1, out e2);
457 Utilities.CopyChannels(libraryData.Texture, textureTemp, 1, out e2, out e1);
459 textureTemp.Dispose();
461 UpdateImage(image, libraryData);
472 private void Compress(TexImage image, PvrTextureLibraryData libraryData, CompressingRequest compress)
474 Log.Info(
"Compressing to " + compress.Format +
" ...");
476 ulong format = RetrieveNativeFormat(compress.Format);
477 EPVRTColourSpace colorSpace = RetrieveNativeColorSpace(compress.Format);
478 EPVRTVariableType pixelType = RetrieveNativePixelType(compress.Format);
482 if (!
Utilities.Transcode(libraryData.Texture, format, pixelType, colorSpace, (ECompressorQuality)compress.Quality,
false))
484 Log.Error(
"Compression failed!");
485 throw new TextureToolsException(
"Compression failed!");
489 image.Format = compress.Format;
491 Tools.ComputePitch(image.Format, image.Width, image.Height, out pitch, out slice);
492 image.RowPitch = pitch;
493 image.SlicePitch = slice;
495 UpdateImage(image, libraryData);
505 public void Decompress(TexImage image, PvrTextureLibraryData libraryData)
507 Log.Info(
"Decompressing texture ...");
509 if (!
Utilities.Transcode(libraryData.Texture, PixelType.Standard8PixelType, libraryData.Header.GetChannelType(), libraryData.Header.GetColourSpace(), ECompressorQuality.ePVRTCNormal,
true))
511 Log.Error(
"Decompression failed!");
512 throw new TextureToolsException(
"Decompression failed!");
515 image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm;
518 Tools.ComputePitch(image.Format, image.Width, image.Height, out pitch, out slice);
519 image.RowPitch = pitch;
520 image.SlicePitch = slice;
522 UpdateImage(image, libraryData);
532 private void GenerateMipMaps(TexImage image, PvrTextureLibraryData libraryData, MipMapsGenerationRequest request)
534 Log.Info(
"Generating Mipmaps ... ");
537 switch (request.Filter)
539 case Filter.MipMapGeneration.Linear:
540 filter = EResizeMode.eResizeLinear;
542 case Filter.MipMapGeneration.Cubic:
543 filter = EResizeMode.eResizeCubic;
545 case Filter.MipMapGeneration.Nearest:
546 filter = EResizeMode.eResizeNearest;
549 filter = EResizeMode.eResizeCubic;
553 libraryData.Texture.GenerateMIPMaps(filter);
555 UpdateImage(image, libraryData);
566 private void Flip(TexImage image, PvrTextureLibraryData libraryData, FlippingRequest request)
568 Log.Info(
"Flipping texture : " + request.Flip +
" ... ");
572 case Orientation.Horizontal:
573 if (!
Utilities.Flip(libraryData.Texture, EPVRTAxis.ePVRTAxisX))
575 Log.Error(
"Flipping failed.");
576 throw new TextureToolsException(
"Flipping failed.");
579 case Orientation.Vertical:
580 if (!
Utilities.Flip(libraryData.Texture, EPVRTAxis.ePVRTAxisY))
582 Log.Error(
"Flipping failed.");
583 throw new TextureToolsException(
"Flipping failed.");
588 image.Flip(request.Flip);
590 UpdateImage(image, libraryData);
602 Log.Info(
"Generating Normal Map ... ");
605 request.NormalMap =
new TexImage();
606 PvrTextureLibraryData normalMapLibraryData =
new PvrTextureLibraryData();
607 request.NormalMap.LibraryData[
this] = normalMapLibraryData;
609 normalMapLibraryData.Texture =
new PVRTexture(libraryData.Header, libraryData.Texture.GetDataPtr());
610 request.NormalMap.Format = SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm;
611 request.NormalMap.CurrentLibrary =
this;
612 request.NormalMap.DisposingLibrary =
this;
614 if (!
Utilities.GenerateNormalMap(normalMapLibraryData.Texture, request.
Amplitude,
"xyzh"))
616 Log.Error(
"Failed to generate normal map.");
617 throw new TextureToolsException(
"Failed to generate normal map.");
620 UpdateImage(request.
NormalMap, normalMapLibraryData);
622 request.NormalMap.DisposingLibrary =
this;
632 public void PreMultiplyAlpha(TexImage image, PvrTextureLibraryData libraryData)
634 Log.Info(
"Premultiplying alpha ... ");
636 if (!
Utilities.PreMultipliedAlpha(libraryData.Texture))
638 Log.Info(
"Failed to premultiply the alpha.");
639 throw new TextureToolsException(
"Failed to premultiply the alpha.");
649 private void UpdateImage(TexImage image, PvrTextureLibraryData libraryData)
651 image.Data = libraryData.Texture.GetDataPtr();
652 libraryData.Header = libraryData.Texture.GetHeader();
653 image.DataSize = (int)libraryData.Header.GetDataSize();
654 image.MipmapCount = (int)libraryData.Header.GetNumMIPLevels();
655 image.ArraySize = (int)libraryData.Header.GetNumArrayMembers();
656 image.FaceCount = (int)libraryData.Header.GetNumFaces();
667 private bool SupportFormat(SiliconStudio.Paradox.Graphics.PixelFormat format)
671 case SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_Float:
672 case SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32_Float:
673 case SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_UInt:
674 case SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32_UInt:
675 case SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_SInt:
676 case SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32_SInt:
677 case SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_UNorm:
678 case SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_UInt:
679 case SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_SNorm:
680 case SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_SInt:
681 case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm_SRgb:
682 case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm:
683 case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UInt:
684 case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_SNorm:
685 case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_SInt:
686 case SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_UNorm_SRgb:
687 case SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_UNorm:
689 case SiliconStudio.Paradox.Graphics.PixelFormat.PVRTC_2bpp_RGB:
690 case SiliconStudio.Paradox.Graphics.PixelFormat.PVRTC_2bpp_RGBA:
691 case SiliconStudio.Paradox.Graphics.PixelFormat.PVRTC_4bpp_RGB:
692 case SiliconStudio.Paradox.Graphics.PixelFormat.PVRTC_4bpp_RGBA:
693 case SiliconStudio.Paradox.Graphics.PixelFormat.PVRTC_II_2bpp:
694 case SiliconStudio.Paradox.Graphics.PixelFormat.PVRTC_II_4bpp:
695 case SiliconStudio.Paradox.Graphics.PixelFormat.ETC1:
696 case SiliconStudio.Paradox.Graphics.PixelFormat.ETC2_RGB:
697 case SiliconStudio.Paradox.Graphics.PixelFormat.ETC2_RGBA:
698 case SiliconStudio.Paradox.Graphics.PixelFormat.ETC2_RGB_A1:
699 case SiliconStudio.Paradox.Graphics.PixelFormat.EAC_R11_Unsigned:
700 case SiliconStudio.Paradox.Graphics.PixelFormat.EAC_R11_Signed:
701 case SiliconStudio.Paradox.Graphics.PixelFormat.EAC_RG11_Unsigned:
702 case SiliconStudio.Paradox.Graphics.PixelFormat.EAC_RG11_Signed:
715 private UInt64 RetrieveNativeFormat(SiliconStudio.Paradox.Graphics.PixelFormat format)
719 case SiliconStudio.Paradox.Graphics.PixelFormat.PVRTC_2bpp_RGB:
721 case SiliconStudio.Paradox.Graphics.PixelFormat.PVRTC_2bpp_RGBA:
723 case SiliconStudio.Paradox.Graphics.PixelFormat.PVRTC_4bpp_RGB:
725 case SiliconStudio.Paradox.Graphics.PixelFormat.PVRTC_4bpp_RGBA:
727 case SiliconStudio.Paradox.Graphics.PixelFormat.PVRTC_II_2bpp:
729 case SiliconStudio.Paradox.Graphics.PixelFormat.PVRTC_II_4bpp:
731 case SiliconStudio.Paradox.Graphics.PixelFormat.ETC1:
733 case SiliconStudio.Paradox.Graphics.PixelFormat.ETC2_RGB:
735 case SiliconStudio.Paradox.Graphics.PixelFormat.ETC2_RGBA:
737 case SiliconStudio.Paradox.Graphics.PixelFormat.ETC2_RGB_A1:
739 case SiliconStudio.Paradox.Graphics.PixelFormat.EAC_R11_Unsigned:
741 case SiliconStudio.Paradox.Graphics.PixelFormat.EAC_R11_Signed:
743 case SiliconStudio.Paradox.Graphics.PixelFormat.EAC_RG11_Unsigned:
745 case SiliconStudio.Paradox.Graphics.PixelFormat.EAC_RG11_Signed:
747 case SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_Float:
748 case SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32_Float:
749 case SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_UInt:
750 case SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32_UInt:
751 case SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_SInt:
752 case SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32_SInt:
753 return Utilities.ConvertPixelType(PixelType.Standard32PixelType);
754 case SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_UNorm:
755 case SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_UInt:
756 case SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_SNorm:
757 case SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_SInt:
758 return Utilities.ConvertPixelType(PixelType.Standard16PixelType);
759 case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm_SRgb:
760 case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm:
761 case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UInt:
762 case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_SNorm:
763 case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_SInt:
764 return Utilities.ConvertPixelType(PixelType.Standard8PixelType);
766 Log.Error(
"UnHandled compression format by PowerVC Texture Tool.");
767 throw new TextureToolsException(
"UnHandled compression format by PowerVC Texture Tool.");
772 private EPVRTVariableType RetrieveNativePixelType(SiliconStudio.Paradox.Graphics.PixelFormat format)
776 case SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_Float:
777 case SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32_Float:
778 return EPVRTVariableType.ePVRTVarTypeFloat;
781 case SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_UInt:
782 case SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32_UInt:
783 return EPVRTVariableType.ePVRTVarTypeUnsignedInteger;
784 case SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_SInt:
785 case SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32_SInt:
786 return EPVRTVariableType.ePVRTVarTypeSignedInteger;
788 case SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_UNorm:
789 return EPVRTVariableType.ePVRTVarTypeUnsignedShortNorm;
790 case SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_UInt:
791 return EPVRTVariableType.ePVRTVarTypeUnsignedShort;
792 case SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_SNorm:
793 return EPVRTVariableType.ePVRTVarTypeSignedShortNorm;
794 case SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_SInt:
795 return EPVRTVariableType.ePVRTVarTypeSignedShort;
798 case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm_SRgb:
799 case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm:
800 return EPVRTVariableType.ePVRTVarTypeUnsignedByteNorm;
801 case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UInt:
802 return EPVRTVariableType.ePVRTVarTypeUnsignedByte;
803 case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_SNorm:
804 return EPVRTVariableType.ePVRTVarTypeSignedByteNorm;
805 case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_SInt:
806 return EPVRTVariableType.ePVRTVarTypeSignedByte;
809 return EPVRTVariableType.ePVRTVarTypeUnsignedByteNorm;
817 if (format == SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_Float)
819 switch (header.GetChannelType())
821 case EPVRTVariableType.ePVRTVarTypeFloat:
822 return SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_Float;
823 case EPVRTVariableType.ePVRTVarTypeUnsignedInteger:
824 return SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_UInt;
825 case EPVRTVariableType.ePVRTVarTypeSignedInteger:
826 return SiliconStudio.Paradox.Graphics.PixelFormat.R32G32B32A32_SInt;
829 else if(format == SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_UNorm)
831 switch (header.GetChannelType())
833 case EPVRTVariableType.ePVRTVarTypeUnsignedShortNorm:
834 return SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_UNorm;
835 case EPVRTVariableType.ePVRTVarTypeUnsignedShort:
836 return SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_UInt;
837 case EPVRTVariableType.ePVRTVarTypeSignedShortNorm:
838 return SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_SNorm;
839 case EPVRTVariableType.ePVRTVarTypeSignedShort:
840 return SiliconStudio.Paradox.Graphics.PixelFormat.R16G16B16A16_SInt;
843 else if(format == SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm)
845 switch (header.GetChannelType())
847 case EPVRTVariableType.ePVRTVarTypeUnsignedByteNorm:
849 if (header.GetColourSpace() == EPVRTColourSpace.ePVRTCSpacelRGB)
850 return SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm;
852 return SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm_SRgb;
854 case EPVRTVariableType.ePVRTVarTypeUnsignedByte:
855 return SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UInt;
856 case EPVRTVariableType.ePVRTVarTypeSignedByteNorm:
857 return SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_SNorm;
858 case EPVRTVariableType.ePVRTVarTypeSignedByte:
859 return SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_SInt;
866 private EPVRTColourSpace RetrieveNativeColorSpace(SiliconStudio.Paradox.Graphics.PixelFormat format)
870 case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm_SRgb:
871 return EPVRTColourSpace.ePVRTCSpaceSRgb;
873 return EPVRTColourSpace.ePVRTCSpacelRGB;
HRESULT GenerateMipMaps(_In_ const Image &baseImage, _In_ DWORD filter, _In_ size_t levels, _Inout_ ScratchImage &mipChain, _In_ bool allow1D=false)
Base implementation for ILogger.
SiliconStudio.Core.Utilities Utilities
Same as Deferred mode, except sprites are sorted by texture prior to drawing. This can improve perfor...
HRESULT Decompress(_In_ const Image &cImage, _In_ DXGI_FORMAT format, _Out_ ScratchImage &image)
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
Output message to log right away.
PixelFormat
Defines various types of pixel formats.
HRESULT Compress(_In_ const Image &srcImage, _In_ DXGI_FORMAT format, _In_ DWORD compress, _In_ float alphaRef, _Out_ ScratchImage &cImage)