public override unsafe void Replace(string fileName) { string ext = Path.GetExtension(fileName); Bitmap bmp; if (String.Equals(ext, ".tga", StringComparison.OrdinalIgnoreCase)) { bmp = TGA.FromFile(fileName); } else if ( String.Equals(ext, ".png", StringComparison.OrdinalIgnoreCase) || String.Equals(ext, ".tif", StringComparison.OrdinalIgnoreCase) || String.Equals(ext, ".tiff", StringComparison.OrdinalIgnoreCase) || String.Equals(ext, ".bmp", StringComparison.OrdinalIgnoreCase) || String.Equals(ext, ".jpg", StringComparison.OrdinalIgnoreCase) || String.Equals(ext, ".jpeg", StringComparison.OrdinalIgnoreCase) || String.Equals(ext, ".gif", StringComparison.OrdinalIgnoreCase)) { bmp = (Bitmap)Bitmap.FromFile(fileName); } else { base.Replace(fileName); return; } using (Bitmap b = bmp) Replace(b); }
public override unsafe void Replace(string fileName) { Bitmap bmp; if (fileName.EndsWith(".tga")) { bmp = TGA.FromFile(fileName); } else if (fileName.EndsWith(".png") || fileName.EndsWith(".tiff") || fileName.EndsWith(".tif") || fileName.EndsWith(".bmp") || fileName.EndsWith(".jpg") || fileName.EndsWith(".jpeg") || fileName.EndsWith(".gif")) { bmp = (Bitmap)Bitmap.FromFile(fileName); } else { base.Replace(fileName); return; } using (Bitmap b = bmp) Replace(b); }
private void Form1_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop) && e.Effect == DragDropEffects.Move) { string[] Files = (string[])e.Data.GetData(DataFormats.FileDrop); T = TGA.FromFile(Files[0]); ShowTga(); } }
//rgb-"jghsdfag.sdf":a private static Pipe LoadPipe(string pipeString) { int hyphenIndex = pipeString.IndexOf('-'); int colonIndex = pipeString.IndexOf(':'); string outputChannelsStr = pipeString.Substring(0, hyphenIndex); string path = pipeString.Substring(hyphenIndex + 1, colonIndex - hyphenIndex - 1).Replace("\"", string.Empty); string inputChannelsStr = pipeString.Substring(colonIndex + 1, pipeString.Length - colonIndex - 1); Bitmap bitmap = (Bitmap)TGA.FromFile(path); return(new Pipe(ParseChannels(inputChannelsStr), ParseChannels(outputChannelsStr), bitmap)); }
public void Replace() { TEX0Node tNode = Node as TEX0Node; string path; Bitmap bmp = null; switch (Program.OpenFile(Filters.TextureReplaceFilter, out path)) { case 2: case 4: case 5: case 6: case 7: bmp = Bitmap.FromFile(path) as Bitmap; break; case 3: bmp = TGA.FromFile(path); break; case 8: tNode.Replace(path); return; default: return; } try { //if ((bmp.Width != tNode.Width) || (bmp.Height != tNode.Height)) // MessageBox.Show(String.Format("Texture size does not match original! ({0} x {1})", tNode.Width, tNode.Height)); //else tNode.Replace(bmp); //automatically replace multiple nodes //if (_nodePath.Contains("Type1[90]/Textures(NW4R)/InfStc.")) //{ // string id = _nodePath.Substring(_nodePath.LastIndexOf('.')); // ResourceNode node = ResourceCache.FindNode("stage\\melee\\STGRESULT.PAC", "2/Type1[120]/Textures(NW4R)/InfStc" + id); // ((TEX0Node)node).Replace(bmp); //} } finally { bmp.Dispose(); } }
private Bitmap SearchDirectory(string path) { Bitmap bmp = null; if (!String.IsNullOrEmpty(path)) { DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(path)); if (dir.Exists && Name != "<null>") { foreach (FileInfo file in dir.GetFiles(Name + ".*")) { if (File.Exists(file.FullName)) { if (file.Name.EndsWith(".tga")) { Source = file.FullName; bmp = TGA.FromFile(file.FullName); break; } else if ( file.Name.EndsWith(".png") || file.Name.EndsWith(".tiff") || file.Name.EndsWith(".tif") || file.Name.EndsWith(".jpg") || file.Name.EndsWith(".jpeg") || file.Name.EndsWith(".bmp") || file.Name.EndsWith(".gif")) { Source = file.FullName; bmp = CopyImage(file.FullName); break; } } } } } return(bmp); }
private bool LoadImages(string path) { DisposeImages(); if (path.EndsWith(".tga")) { _source = TGA.FromFile(path); } else { _source = (Bitmap)Bitmap.FromFile(path); } //if (_source.PixelFormat != PixelFormat.Format32bppArgb) // using (Bitmap bmp = _source) // _source = bmp.Clone(new Rectangle(0, 0, bmp.Width, bmp.Height), PixelFormat.Format32bppArgb); //_source.SetResolution(96.0f, 96.0f); _preview = new Bitmap(_source.Width, _source.Height, PixelFormat.Format32bppArgb); txtPath.Text = path; lblSize.Text = String.Format("{0} x {1}", _source.Width, _source.Height); _colorInfo = _source.GetColorInformation(); lblColors.Text = _colorInfo.ColorCount.ToString(); lblTransparencies.Text = _colorInfo.AlphaColors.ToString(); //Get max LOD int maxLOD = 1; for (int w = _source.Width, h = _source.Height; (w != 1) && (h != 1); w >>= 1, h >>= 1, maxLOD++) { ; } numLOD.Maximum = maxLOD; return(true); }
/// <summary> /// Converts a byte array of a VTF file into a bitmap var /// </summary> /// <param name="vtf">The byte array read from a VTF</param> /// <param name="launcher">An instance of the Source SDK lib</param> /// <returns></returns> public static Bitmap ToBitmap(byte[] vtf, Launcher launcher) { if (vtf == null || vtf.Length == 0 || launcher == null) { return(null); } string gamePath = launcher.GetCurrentGame().installPath; string modPath = launcher.GetCurrentMod().installPath; string filePath = modPath + "\\materials"; string vtf2tgaPath = gamePath + "\\bin\\vtf2tga.exe"; Directory.CreateDirectory(filePath); File.WriteAllBytes(filePath + "\\temp.vtf", vtf); Process process = new Process(); process.StartInfo.FileName = vtf2tgaPath; process.StartInfo.Arguments = "-i temp -o temp"; process.StartInfo.WorkingDirectory = filePath; process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; process.Start(); process.WaitForExit(); if (!File.Exists(filePath + "\\temp.tga")) { return(null); } Bitmap src = TGA.FromFile(filePath + "\\temp.tga").ToBitmap(); File.Delete(filePath + "\\temp.tga"); File.Delete(filePath + "\\temp.vtf"); return(src); }
private unsafe void Load(int index, int program, PLT0Node palette) { if (_context == null) { return; } Source = null; if (Texture != null) { Texture.Delete(); } Texture = new GLTexture(_context, 0, 0); Texture.Bind(index, program); //ctx._states[String.Format("{0}_TexRef", Name)] = Texture; Bitmap bmp = null; TEX0Node tNode = null; if (_context._states.ContainsKey("_Node_Refs")) { List <ResourceNode> nodes = _context._states["_Node_Refs"] as List <ResourceNode>; List <ResourceNode> searched = new List <ResourceNode>(nodes.Count); foreach (ResourceNode n in nodes) { ResourceNode node = n.RootNode; if (searched.Contains(node)) { continue; } searched.Add(node); //Search node itself first if ((tNode = node.FindChild("Textures(NW4R)/" + Name, true) as TEX0Node) != null) { Source = tNode; if (palette != null) { bmp = tNode.GetImage(0, palette); } else { bmp = tNode.GetImage(0); } } else { //Then search node directory string path = node._origPath; if (path != null) { DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(path)); foreach (FileInfo file in dir.GetFiles(Name + ".*")) { if (file.Name.EndsWith(".tga")) { Source = file.FullName; bmp = TGA.FromFile(file.FullName); break; } else if (file.Name.EndsWith(".png") || file.Name.EndsWith(".tiff") || file.Name.EndsWith(".tif")) { Source = file.FullName; bmp = (Bitmap)Bitmap.FromFile(file.FullName); break; } } } } if (bmp != null) { break; } } searched.Clear(); if (bmp != null) { int w = bmp.Width, h = bmp.Height, size = w * h; Texture._width = w; Texture._height = h; //_context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MagFilter, (int)GLTextureFilter.LINEAR); //_context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MinFilter, (int)GLTextureFilter.NEAREST_MIPMAP_LINEAR); //_context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.BaseLevel, 0); //if (tNode != null) // _context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MaxLevel, tNode.LevelOfDetail); //else // _context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MaxLevel, 0); BitmapData data = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); try { using (UnsafeBuffer buffer = new UnsafeBuffer(size << 2)) { ARGBPixel *sPtr = (ARGBPixel *)data.Scan0; ABGRPixel *dPtr = (ABGRPixel *)buffer.Address; for (int i = 0; i < size; i++) { *dPtr++ = (ABGRPixel)(*sPtr++); } int res = _context.gluBuild2DMipmaps(GLTextureTarget.Texture2D, GLInternalPixelFormat._4, w, h, GLPixelDataFormat.RGBA, GLPixelDataType.UNSIGNED_BYTE, buffer.Address); if (res != 0) { } } } finally { bmp.UnlockBits(data); bmp.Dispose(); } } } }
private unsafe void Load(int index, int program, PLT0Node palette) { if (_context == null) { return; } Source = null; if (Texture != null) { Texture.Delete(); } Texture = new GLTexture(); Texture.Bind(index, program, _context); //ctx._states[String.Format("{0}_TexRef", Name)] = Texture; Bitmap bmp = null; TEX0Node tNode = null; if (_context._states.ContainsKey("_Node_Refs")) { List <ResourceNode> nodes = _context._states["_Node_Refs"] as List <ResourceNode>; List <ResourceNode> searched = new List <ResourceNode>(nodes.Count); foreach (ResourceNode n in nodes) { ResourceNode node = n.RootNode; if (searched.Contains(node)) { continue; } searched.Add(node); //Search node itself first if ((tNode = node.FindChild("Textures(NW4R)/" + Name, true) as TEX0Node) != null) { Source = tNode; if (palette != null) { Texture.Attach(tNode, palette); } else { Texture.Attach(tNode); } return; } else { //Then search node directory string path = node._origPath; if (path != null) { DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(path)); if (dir.Exists && Name != "<null>") { foreach (FileInfo file in dir.GetFiles(Name + ".*")) { if (file.Name.EndsWith(".tga")) { Source = file.FullName; bmp = TGA.FromFile(file.FullName); break; } else if (file.Name.EndsWith(".png") || file.Name.EndsWith(".tiff") || file.Name.EndsWith(".tif")) { Source = file.FullName; bmp = (Bitmap)Bitmap.FromFile(file.FullName); break; } } } } } if (bmp != null) { break; } } searched.Clear(); if (bmp != null) { Texture.Attach(bmp); } } }