/// <summary> /// Switches the channels R and B. /// </summary> /// <param name="image">The image.</param> /// <param name="libraryData">The library data.</param> /// <param name="switchC">The switch request</param> /// <remarks> /// Some libraries can't handle BGRA order so we need to change it to RGBA. /// </remarks> private void SwitchChannels(TexImage image, FreeImageTextureLibraryData libraryData, SwitchingBRChannelsRequest switchC) { Log.Info("Switching channels R and G ..."); for (int i = 0; i < libraryData.Bitmaps.Length; ++i) { FIBITMAP blueChannel = FreeImage.GetChannel(libraryData.Bitmaps[i], FREE_IMAGE_COLOR_CHANNEL.FICC_BLUE); FIBITMAP redChannel = FreeImage.GetChannel(libraryData.Bitmaps[i], FREE_IMAGE_COLOR_CHANNEL.FICC_RED); FreeImage.SetChannel(libraryData.Bitmaps[i], redChannel, FREE_IMAGE_COLOR_CHANNEL.FICC_BLUE); FreeImage.SetChannel(libraryData.Bitmaps[i], blueChannel, FREE_IMAGE_COLOR_CHANNEL.FICC_RED); FreeImage.Unload(blueChannel); FreeImage.Unload(redChannel); } if (image.Format.IsInBGRAOrder()) image.Format = PixelFormat.R8G8B8A8_UNorm; else image.Format = PixelFormat.B8G8R8A8_UNorm; }
/// <summary> /// Switches the channels R and B. /// </summary> /// <param name="image">The image.</param> /// <param name="libraryData">The library data.</param> /// <param name="request">The request.</param> /// <exception cref="TexLibraryException">Unsuported format for channel switching.</exception> private void SwitchChannels(TexImage image, PvrTextureLibraryData libraryData, SwitchingBRChannelsRequest request) { Log.Info("Switching channels B and R ..."); switch (image.Format) { case SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_UNorm: image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm; break; case SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_Typeless: image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_Typeless; break; case SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_UNorm_SRgb: image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm_SRgb; break; case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_Typeless: image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_Typeless; break; case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm: image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_UNorm; break; case SiliconStudio.Paradox.Graphics.PixelFormat.R8G8B8A8_UNorm_SRgb: image.Format = SiliconStudio.Paradox.Graphics.PixelFormat.B8G8R8A8_UNorm_SRgb; break; default: Log.Error("Unsuported format for channel switching."); throw new TextureToolsException("Unsuported format for channel switching."); } PVRTexture textureTemp = new PVRTexture(libraryData.Header, libraryData.Texture.GetDataPtr()); EChannelName e1 = EChannelName.eBlue; EChannelName e2 = EChannelName.eRed; Utilities.CopyChannels(libraryData.Texture, textureTemp, 1, out e1, out e2); Utilities.CopyChannels(libraryData.Texture, textureTemp, 1, out e2, out e1); textureTemp.Dispose(); UpdateImage(image, libraryData); }