// Load image private void loadInvoke() { busy = true; Delegate info = new controlDelegate(updateInfoText); Delegate code = new controlDelegate(updateCodeText); Delegate img = new controlDelegate(updatePic); BeginInvoke(info, (object)"Loading..."); if (!greyImage.load(file)) { BeginInvoke(info, (object)("Error opening image: " + greyImage.lastError())); MessageBox.Show("Error opening image: " + greyImage.lastError(), "Image error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { int w = greyImage.getImage().Width; int h = greyImage.getImage().Height; string strInfo = "Width: " + w + " | Height: " + h + " | Total size: " + String.Format("{0:n0}", w * h) + "B"; string strCode = greyImage.getCode(); BeginInvoke(info, (object)strInfo); if (strCode.Length > 80000) { strCode = "Too much data to fit here, click save instead"; } BeginInvoke(code, (object)strCode); BeginInvoke(img, (object)greyImage.getImage()); } busy = false; }
private void exportAll() { mDelegate dcUpdateStatus = new mDelegate(updateStatus); controlDelegate cDisable = new controlDelegate(disableControls); controlDelegate cEnable = new controlDelegate(enableControls); this.Invoke(cDisable); int iEA, jEA; Bitmap tempBitmap; for (iEA = 0; iEA <= totalTextures; iEA++) { this.Invoke(dcUpdateStatus, "Exporting texture " + iEA + " of " + totalTextures); tempBitmap = getTexture((long)(4096 + (iEA * 256 * 256 * 2))); tempBitmap.Save(exportPath + "\\Texture-" + zeroFill(iEA.ToString(), 5) + ".PNG", System.Drawing.Imaging.ImageFormat.Png); } this.Invoke(cEnable); this.Invoke(dcUpdateStatus, "Ready"); }
private void exportCurrent() { controlDelegate cDisable = new controlDelegate(disableControls); controlDelegate cEnable = new controlDelegate(enableControls); mDelegate dcUpdateStatus = new mDelegate(updateStatus); this.Invoke(cDisable); this.Invoke(dcUpdateStatus, "Exporting current texture"); try { bufferImage.Save(exportPath, System.Drawing.Imaging.ImageFormat.Png); } catch (Exception ex) { MessageBox.Show("There was an error saving the file. Try a different location and/or filename.", "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Invoke(cEnable); this.Invoke(dcUpdateStatus, "Ready"); }
// Load image private void loadInvoke() { Delegate info = new controlDelegate(updateInfoText); Delegate code = new controlDelegate(updateCodeText); Delegate img = new controlDelegate(updatePic); BeginInvoke(info, (object)"Loading..."); if (!greyImage.load(files[0], cbHorizontal.Checked)) { BeginInvoke(info, (object)("Error opening image: " + greyImage.lastError())); MessageBox.Show("Error opening image: " + greyImage.lastError(), "Image error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { int w = greyImage.getImage().Width; int h = greyImage.getImage().Height; string strInfo = "Width: " + w + " | Height: " + h + " | Total size: " + String.Format("{0:n0}", w * h) + "B"; string strCode = greyImage.getCode(); BeginInvoke(info, (object)strInfo); if (strCode.Length > 80000) strCode = "Too much data to fit here, click save instead"; BeginInvoke(code, (object)strCode); BeginInvoke(img, (object)greyImage.getImage()); } busy = false; }
private void importAll() { mDelegate dcUpdateStatus = new mDelegate(updateStatus); controlDelegate cDisable = new controlDelegate(disableControls); controlDelegate cEnable = new controlDelegate(enableControls); this.Invoke(cDisable); DirectoryInfo directoryInfo = new DirectoryInfo(importPath); FileInfo[] fileInfos = directoryInfo.GetFiles("*.png", SearchOption.TopDirectoryOnly); System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("Texture-([0-9]+).(PNG)"); System.Collections.Generic.SortedDictionary <uint, string> dictionary = new System.Collections.Generic.SortedDictionary <uint, string>(); uint highestID = 0; foreach (FileInfo fileInfo in fileInfos) { if (regex.IsMatch(fileInfo.Name)) { string[] tokens = regex.Split(fileInfo.Name); if (tokens.Length == 4 && UInt32.TryParse(tokens[1], out uint index)) { dictionary.Add(index, fileInfo.Name); if (index > highestID) { highestID = index; } } } } if (dictionary.Count > 0) { totalTextures = highestID; fStream.Position = 0; int iEA, jEA; Bitmap tempBitmap = null; for (iEA = 0; iEA <= totalTextures; iEA++) { this.Invoke(dcUpdateStatus, "Exporting texture " + iEA + " of " + totalTextures); if (dictionary.ContainsKey((uint)iEA)) { tempBitmap = new Bitmap(Path.Combine(importPath, dictionary[(uint)iEA])); if ((tempBitmap.Size.Width != textureWidth) || (tempBitmap.Size.Height != textureHeight)) { tempBitmap.Dispose(); tempBitmap = new Bitmap(textureWidth, textureHeight); } } else { tempBitmap = new Bitmap(textureWidth, textureHeight); } int iGT, jGT; ushort a, r, g, b, pixelData; int aFactor, rFactor, gFactor, bFactor; Color colour; aFactor = 1; rFactor = 3; gFactor = 3; bFactor = 3; colour = new Color(); fStream.Seek(getTextureOffset(iEA), SeekOrigin.Begin); for (iGT = 0; iGT < textureHeight; iGT++) { for (jGT = 0; jGT < textureWidth; jGT++) { colour = tempBitmap.GetPixel(jGT, iGT); a = (ushort)(colour.A >> aFactor); r = (ushort)(colour.R >> rFactor); g = (ushort)(colour.G >> gFactor); b = (ushort)(colour.B >> bFactor); a <<= 15; r <<= 10; g <<= 5; pixelData = (ushort)(a | r | g | b); bWriter.Write(pixelData); } } tempBitmap.Dispose(); } fileLength = fStream.Length; fStream.Seek(2, SeekOrigin.Begin); bWriter.Write((ushort)dictionary.Count); fStream.Seek(0, SeekOrigin.Begin); //bufferImage = getTexture(getTextureOffset(currentTexture)); //imageUpdated = true; } this.Invoke(cEnable); this.Invoke(dcUpdateStatus, "Ready"); }
private void importCurrent() { mDelegate dcUpdateStatus = new mDelegate(updateStatus); controlDelegate cDisable = new controlDelegate(disableControls); controlDelegate cEnable = new controlDelegate(enableControls); this.Invoke(cDisable); this.Invoke(dcUpdateStatus, "Importing replacement texture"); Bitmap tempBitmap; tempBitmap = new Bitmap(importPath); if ((tempBitmap.Size.Width != textureWidth) || (tempBitmap.Size.Height != textureHeight)) { MessageBox.Show("You MUST use a PNG image that is textureWidthxtextureHeight pixels", "Incorrect File Format", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int iGT, jGT; ushort a, r, g, b, pixelData; int aFactor, rFactor, gFactor, bFactor; Color colour; aFactor = 1; rFactor = 3; gFactor = 3; bFactor = 3; colour = new Color(); fStream.Seek(getTextureOffset((int)currentTexture), SeekOrigin.Begin); for (iGT = 0; iGT < textureHeight; iGT++) { for (jGT = 0; jGT < textureWidth; jGT++) { colour = tempBitmap.GetPixel(jGT, iGT); a = (ushort)(colour.A >> aFactor); r = (ushort)(colour.R >> rFactor); g = (ushort)(colour.G >> gFactor); b = (ushort)(colour.B >> bFactor); a <<= 15; r <<= 10; g <<= 5; pixelData = (ushort)(a | r | g | b); bWriter.Write(pixelData); } } this.Invoke(dcUpdateStatus, "Loading rewritten texture"); cboCurrentTexture.SelectedIndex = (int)currentTexture; bufferImage = getTexture(getTextureOffset((int)currentTexture)); imageUpdated = true; this.Invoke(cEnable); this.Invoke(dcUpdateStatus, "Ready"); }