public int ImageFormats() { using (var img = TgaReader.Load(new MemoryStream(data))) { return(img.Width); } }
/// <summary> /// /// </summary> private void PopulateGameInformation() { textBox1.Text = information.Name; textBox2.Text = information.ProductCode; textBox3.Text = information.SaveDir; textBox4.Text = information.TitleId; textBox5.Text = information.LaunchFile; textBox6.Text = information.GroupId; textBox7.Text = information.Region; textBox8.Text = information.Publisher; textBox9.Text = information.Size; textBox10.Text = information.GameSetting.PreferedVersion; textBox11.Text = information.GameSetting.OfficialEmulationState.ToString(); textBox12.Text = information.CompanyCode; textBox13.Text = information.LaunchFileName; textBox14.Text = information.Comments; linkLabel1.Text = information.GameSetting.CompatibilityUrl; string iconFile = information.LaunchFile.Replace(information.LaunchFileName, "").Replace("code" + Path.DirectorySeparatorChar, "meta" + Path.DirectorySeparatorChar + "iconTex.tga"); string logoFile = information.LaunchFile.Replace(information.LaunchFileName, "").Replace("code" + Path.DirectorySeparatorChar, "meta" + Path.DirectorySeparatorChar + "bootLogoTex.tga"); if (File.Exists(iconFile)) { pictureBox1.Image = TgaReader.Load(iconFile); } if (File.Exists(logoFile)) { pictureBox2.Image = TgaReader.Load(logoFile); } trackBar1.Value = information.GameSetting.Volume; }
public Bitmap CreateBitmapFromTgaSource(string directoryPath, string fileName) { using (var fs = new FileStream($@"{directoryPath}\{fileName}", FileMode.Open, FileAccess.Read, FileShare.Read)) { return(TgaReader.Load(fs)); } }
private void LoadMaterialData(StreamReader source, string sourceFolder) { while (!source.EndOfStream) { string line = source.ReadLine().Trim(); string[] decomp = line.Split(' '); switch (decomp[0].Trim()) { case "Ka": AmbientColors[0] = new Color(Convert.ToSingle(decomp[1]), Convert.ToSingle(decomp[2]), Convert.ToSingle(decomp[3]), 1); break; case "Kd": MaterialColors[0] = new Color(Convert.ToSingle(decomp[1]), Convert.ToSingle(decomp[2]), Convert.ToSingle(decomp[3]), 1); break; case "map_Kd": Bitmap bmp = null; string texPath = ""; string texName = ""; // If the name is rooted, we need to extract the path. if (System.IO.Path.IsPathRooted(decomp[1])) { texPath = line.Substring(7); string[] splitPathForName = texPath.Split('\\'); texName = splitPathForName[splitPathForName.Length - 1]; } // Otherwise, we need to take the file name and create a path for it. else { texPath = sourceFolder + @"\" + decomp[1]; texName = decomp[1]; } // Test for which type we're loading if (texPath.EndsWith(".tga")) { bmp = TgaReader.Load(texPath); } else if (texPath.EndsWith(".png")) { bmp = new Bitmap(texPath); } else { Console.WriteLine("Unknown texture format!"); return; } SetTexture(texName, bmp); break; case "newmtl": return; } } }
private ObservableCollection <BinaryTextureImage> LoadImages(string[] paths) { if (ImageList == null) { ImageList = new ObservableCollection <BinaryTextureImage>(); } ObservableCollection <BinaryTextureImage> tempList = ImageList; foreach (string path in paths) { BinaryTextureImage openedImage = null; // Open a BTI if (path.EndsWith(".bti")) { using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { EndianBinaryReader reader = new EndianBinaryReader(stream, Endian.Big); openedImage = new BinaryTextureImage(); openedImage.Load(reader, path, 0); } } // Open a PNG else if (path.EndsWith(".png") || path.EndsWith(".PNG")) { Bitmap input = new Bitmap(path); openedImage = new BinaryTextureImage(path, input, BinaryTextureImage.TextureFormats.PNG); } // Open a TGA else if (path.EndsWith(".tga")) { Bitmap input = TgaReader.Load(path); openedImage = new BinaryTextureImage(path, input, BinaryTextureImage.TextureFormats.TGA); } tempList.Add(openedImage); } return(tempList); }
/// <summary> /// Load texture from file /// </summary> /// <param name="device">Device</param> /// <param name="filename">Filename</param> /// <returns>Shader Resource View</returns> public static ShaderResourceView LoadTextureFromFile(this SharpDevice device, string filename) { string ext = System.IO.Path.GetExtension(filename); if (ext.ToLower( ) == ".dds") { bool isCube; return(CreateTextureFromDDS(device.Device, device.DeviceContext, System.IO.File.ReadAllBytes(filename), out isCube)); } if (ext.ToLower( ) == ".tga") { return(CreateTextureFromBitmap(device.Device, device.DeviceContext, TgaReader.Load(filename))); } { return(CreateTextureFromBitmap(device.Device, device.DeviceContext, filename)); } }
public Bitmap Load(string fileNameBase, Color?tintColor = null) { string completePath = Path.Combine(rootPath_, "textures", "blocks", fileNameBase); Bitmap result = null; if (File.Exists(completePath + ".png")) { result = Image.FromFile(completePath + ".png") as Bitmap; } else if (File.Exists(completePath + ".tga")) { result = TgaReader.Load(completePath + ".tga"); } else if (File.Exists(completePath + ".bmp")) { result = Image.FromFile(completePath + ".bmp") as Bitmap; } else { throw new FileNotFoundException("Could not find a resource in the specified location; tried .png, .tga, .bmp.", completePath); } if (result.Width != result.Height) { // non-square textures are always vertically oriented var replacement = new Bitmap(result.Width, result.Width, result.PixelFormat); using (Graphics g = Graphics.FromImage(replacement)) { g.DrawImage(result, new Rectangle(0, 0, result.Width, result.Width), 0, 0, result.Width, result.Width, GraphicsUnit.Pixel); } result.Dispose(); result = replacement; } if (tintColor.HasValue) { TintSourceBitmap(result, tintColor.Value); } return(result); }
public Bitmap LoadImage(string path) { try { if (path.EndsWith("webp")) { return(WebP.Value.LoadImage(path)); } if (path.EndsWith("tga")) { return(TgaReader.Load(path)); } return((Bitmap)Image.FromFile(path)); } catch (Exception ex) { Console.WriteLine($"Error loading {path}, because {ex}"); throw new LoadImageException(path, ex); } }
/// <summary> /// Not thread safe /// </summary> /// <param name="info"></param> /// <returns></returns> public Bitmap GetTextureImage(TextureInfo info) { if (info == null) { return(null); } var localPath = info.Filename; localPath = localPath.Replace("textures/", ""); localPath = localPath.Replace('/', Path.DirectorySeparatorChar); if (Cache.ContainsKey(info)) { return(Cache[info]); } try { string extension = ".jpg"; string filepath = Path.Combine(path, localPath); Bitmap b = null; if (File.Exists(filepath + ".png")) { extension = ".png"; b = new Bitmap(filepath + extension); } else if (File.Exists(filepath + ".tga")) { extension = ".tga"; b = TgaReader.Load(filepath + extension); } if (b == null) { Console.WriteLine("Could not find {0}", filepath); } if (info.Translation != null) { var bnew = new Bitmap(16, 16); using (var gnew = Graphics.FromImage(bnew)) { gnew.DrawImage(b, info.Translation.Dest, info.Translation.Source, GraphicsUnit.Pixel); } b = bnew; } if (info.Rotation != RotateFlipType.RotateNoneFlipNone) { b.RotateFlip(info.Rotation); } if (!Cache.ContainsKey(info)) { Cache.Add(info, b); } return(b); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(null); }
public Material(Grendgine_Collada_Phong source, Batch batch, string modelPath, Grendgine_Collada_Image[] textures) { MatBatch = batch; Name = batch.MaterialName; Flag = 1; IndTexEntry = new IndirectTexturing(); CullMode = GXCullMode.Back; MaterialColors = new Color?[2] { new Color(1, 1, 1, 1), new Color(1, 1, 1, 1) }; ChannelControls = new ChannelControl[4] { new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.Clamp, GXAttenuationFn.Spot, GXColorSrc.Register), new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.Clamp, GXAttenuationFn.Spot, GXColorSrc.Register), new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.Signed, GXAttenuationFn.Spec, GXColorSrc.Register), new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.None, GXAttenuationFn.None, GXColorSrc.Register), }; AmbientColors = new Color?[2] { new Color(0.1960f, 0.1960f, 0.1960f, 0.1960f), new Color(0, 0, 0, 0) }; LightingColors = new Color?[8]; TexCoord1Gens = new TexCoordGen[8]; TexCoord2Gens = new TexCoordGen[8]; TexMatrix1 = new TexMatrix[10]; TexMatrix2 = new TexMatrix[20]; Textures = new BinaryTextureImage[8]; TevOrders = new TevOrder[16]; TevOrders[0] = new TevOrder(GXTexCoordSlot.Null, 0, GXColorChannelId.Color0A0); ColorSels = new GXKonstColorSel[16]; AlphaSels = new GXKonstAlphaSel[16]; for (int i = 0; i < 16; i++) { ColorSels[i] = GXKonstColorSel.KCSel_K0; AlphaSels[i] = GXKonstAlphaSel.KASel_K0_A; } TevColors = new Color?[4] { new Color(0, 0, 0, 1), new Color(1, 1, 1, 1), new Color(0, 0, 0, 0), new Color(1, 1, 1, 1) }; KonstColors = new Color?[4] { new Color(1, 1, 1, 1), new Color(1, 1, 1, 1), new Color(1, 1, 1, 1), new Color(1, 1, 1, 1) }; TevStages = new TevStage[16]; TevStages[0] = new TevStage(new GXCombineColorInput[] { GXCombineColorInput.Zero, GXCombineColorInput.Zero, GXCombineColorInput.Zero, GXCombineColorInput.Zero }, GXTevOp.Add, GXTevBias.Zero, GXTevScale.Scale_1, true, 0, new GXCombineAlphaInput[] { GXCombineAlphaInput.RasAlpha, GXCombineAlphaInput.Zero, GXCombineAlphaInput.Zero, GXCombineAlphaInput.Zero, }, GXTevOp.Add, GXTevBias.Zero, GXTevScale.Scale_1, true, 0); SwapModes = new TevSwapMode[16]; SwapModes[0] = new TevSwapMode(); SwapModes[1] = new TevSwapMode(); SwapTables = new TevSwapModeTable[4] { new TevSwapModeTable(0, 1, 2, 3), new TevSwapModeTable(0, 1, 2, 3), new TevSwapModeTable(0, 1, 2, 3), new TevSwapModeTable(0, 1, 2, 3) }; FogInfo = new Fog(); AlphCompare = new AlphaCompare(GXCompareType.Always, 0, GXAlphaOp.Or, GXCompareType.Always, 0); BMode = new BlendMode(GXBlendMode.None, GXBlendModeControl.One, GXBlendModeControl.Zero, GXLogicOp.Copy); ZMode = new ZMode(true, GXCompareType.LEqual, true); ZCompLoc = true; Dither = true; // Add texture to TEV stage data if there is one if (source.Diffuse.Texture != null) { string texName = source.Diffuse.Texture.Texture; string path = textures.First(x => x.ID == texName).Init_From.Replace("file://", ""); if (!Path.IsPathRooted(path)) { string modelDir = Path.GetDirectoryName(modelPath); string texPath = string.Format("{0}\\{1}", modelDir, path); if (File.Exists(texPath)) { path = texPath; } else { throw new ArgumentException(string.Format("Could not find texture \"{0}\" at \"{1}\"!", path, texPath)); } } string imageExt = Path.GetExtension(path).ToLower(); Bitmap imageData = null; switch (imageExt) { case ".png": case ".bmp": imageData = new Bitmap(path); break; case ".tga": imageData = TgaReader.Load(path); break; default: throw new ArgumentException(string.Format("Texture {0} was a {1}. Only PNG, BMP, or TGA images are supported!", path, imageExt)); } if (imageData == null) { throw new ArgumentException(string.Format("Texture {0} could not be loaded!", path)); } SetTexture(source.Diffuse.Texture, Path.GetFileNameWithoutExtension(path), imageData); } // Add vertex colors to the shader if there are any if (batch.Attributes.Contains(VertexAttributes.Color0)) { ChannelControls = new ChannelControl[4] { new ChannelControl(false, GXColorSrc.Vertex, GXLightId.None, GXDiffuseFn.Clamp, GXAttenuationFn.Spot, GXColorSrc.Register), new ChannelControl(false, GXColorSrc.Vertex, GXLightId.None, GXDiffuseFn.Clamp, GXAttenuationFn.Spot, GXColorSrc.Register), new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.Signed, GXAttenuationFn.Spec, GXColorSrc.Register), new ChannelControl(false, GXColorSrc.Register, GXLightId.None, GXDiffuseFn.None, GXAttenuationFn.None, GXColorSrc.Register), }; TevStages[1] = TevStages[0]; TevStages[1].ColorIn[0] = GXCombineColorInput.ColorPrev; TevStages[0] = new TevStage(new GXCombineColorInput[] { GXCombineColorInput.C0, GXCombineColorInput.TexColor, GXCombineColorInput.RasColor, GXCombineColorInput.Zero }, GXTevOp.Add, GXTevBias.Zero, GXTevScale.Scale_1, true, 0, new GXCombineAlphaInput[] { GXCombineAlphaInput.A0, GXCombineAlphaInput.TexAlpha, GXCombineAlphaInput.Zero, GXCombineAlphaInput.Zero, }, GXTevOp.Add, GXTevBias.Zero, GXTevScale.Scale_1, true, 0); TevOrders[1] = new TevOrder(GXTexCoordSlot.TexCoord0, 0, GXColorChannelId.Color0A0); } foreach (ChannelControl chan in ChannelControls) { if (chan != null) { ColorChannelControlsCount++; } } foreach (TexCoordGen gen in TexCoord1Gens) { if (gen != null) { NumTexGensCount++; } } foreach (TevStage stage in TevStages) { if (stage != null) { NumTevStagesCount++; } } }