/// <summary> /// Compresses the specified image. /// </summary> /// <param name="image">The image.</param> /// <param name="libraryData">The library data.</param> /// <param name="compress">The compress.</param> /// <exception cref="TexLibraryException">Compression failed</exception> private void Compress(TexImage image, PvrTextureLibraryData libraryData, CompressingRequest compress) { Log.Info("Compressing to " + compress.Format + " ..."); ulong format = RetrieveNativeFormat(compress.Format); EPVRTColourSpace colorSpace = RetrieveNativeColorSpace(compress.Format); EPVRTVariableType pixelType = RetrieveNativePixelType(compress.Format); lock (lockObject) { if (!Utilities.Transcode(libraryData.Texture, format, pixelType, colorSpace, (ECompressorQuality)compress.Quality, false)) { Log.Error("Compression failed!"); throw new TextureToolsException("Compression failed!"); } } image.Format = compress.Format; int pitch, slice; Tools.ComputePitch(image.Format, image.Width, image.Height, out pitch, out slice); image.RowPitch = pitch; image.SlicePitch = slice; UpdateImage(image, libraryData); }
public void StartLibrary(TexImage image) { PvrTextureLibraryData libraryData = new PvrTextureLibraryData(); int imageArraySize = image.Dimension == TexImage.TextureDimension.TextureCube ? image.ArraySize / 6 : image.ArraySize; int imageFaceCount = image.Dimension == TexImage.TextureDimension.TextureCube ? 6 : 1; // Creating native header corresponding to the TexImage instance ulong format = RetrieveNativeFormat(image.Format); EPVRTColourSpace colorSpace = RetrieveNativeColorSpace(image.Format); EPVRTVariableType pixelType = RetrieveNativePixelType(image.Format); libraryData.Header = new PVRTextureHeader(format, image.Height, image.Width, image.Depth, image.MipmapCount, imageArraySize, imageFaceCount, colorSpace, pixelType); int imageCount = 0; int depth = image.Depth; libraryData.Texture = new PVRTexture(libraryData.Header, IntPtr.Zero); // Initializing a new native texture, allocating memory. // Copying TexImage data into the native texture allocated memory try { for (uint i = 0; i < imageFaceCount; ++i) { for (uint j = 0; j < imageArraySize; ++j) { for (uint k = 0; k < image.MipmapCount; ++k) { Core.Utilities.CopyMemory(libraryData.Texture.GetDataPtr(k, j, i), image.SubImageArray[imageCount].Data, image.SubImageArray[imageCount].DataSize * depth); imageCount += depth; depth = depth > 1 ? depth >>= 1 : depth; } } } } catch (AccessViolationException e) { libraryData.Texture.Dispose(); Log.Error("Failed to convert texture to PvrTexLib native data, check your texture settings. ", e); throw new TextureToolsException("Failed to convert texture to PvrTexLib native data, check your texture settings. ", e); } // Freeing previous image data if (image.DisposingLibrary != null) { image.DisposingLibrary.Dispose(image); } image.LibraryData[this] = libraryData; image.DisposingLibrary = this; }
public PVRTextureHeader(UInt64 pixelFormat, int height = 1, int width = 1, int depth = 1, int numMipMaps = 1, int numArrayMembers = 1, int numFaces = 1, EPVRTColourSpace eColourSpace = EPVRTColourSpace.ePVRTCSpacelRGB, EPVRTVariableType eChannelType = EPVRTVariableType.ePVRTVarTypeUnsignedByteNorm, bool bPreMultiplied = false) { header = pvrttCreateTextureHeaderFromCompressedTexture(pixelFormat, height, width, depth, numMipMaps, numArrayMembers, numFaces, eColourSpace, eChannelType, bPreMultiplied); }
private extern static IntPtr pvrttCreateTextureHeaderFromCompressedTexture(UInt64 pixelFormat, int height, int width, int depth, int numMipMaps, int numArrayMembers, int numFaces, EPVRTColourSpace eColourSpace, EPVRTVariableType eChannelType, bool bPreMultiplied);
public static bool Transcode(PVRTexture sTexture, UInt64 ptFormat, EPVRTVariableType eChannelType, EPVRTColourSpace eColourspace, ECompressorQuality eQuality = ECompressorQuality.ePVRTCNormal, bool bDoDither = false) { return(pvrttTranscode(sTexture.texture, ptFormat, eChannelType, eColourspace, eQuality, bDoDither)); }
private extern static bool pvrttTranscode(IntPtr texture, UInt64 ptFormat, EPVRTVariableType eChannelType, EPVRTColourSpace eColourspace, ECompressorQuality eQuality, bool bDoDither);
public PVRTextureHeader(UInt64 pixelFormat, int height=1, int width=1, int depth=1, int numMipMaps=1, int numArrayMembers=1, int numFaces=1, EPVRTColourSpace eColourSpace=EPVRTColourSpace.ePVRTCSpacelRGB, EPVRTVariableType eChannelType=EPVRTVariableType.ePVRTVarTypeUnsignedByteNorm, bool bPreMultiplied=false) { header = pvrttCreateTextureHeaderFromCompressedTexture(pixelFormat, height, width, depth, numMipMaps, numArrayMembers, numFaces, eColourSpace, eChannelType, bPreMultiplied); }
public static bool Transcode(PVRTexture sTexture, UInt64 ptFormat, EPVRTVariableType eChannelType, EPVRTColourSpace eColourspace, ECompressorQuality eQuality = ECompressorQuality.ePVRTCNormal, bool bDoDither = false) { return pvrttTranscode(sTexture.texture, ptFormat, eChannelType, eColourspace, eQuality, bDoDither); }