/// <summary> /// The convert dd sto bitm info. /// </summary> /// <param name="dds">The dds.</param> /// <returns></returns> /// <remarks></remarks> public static ParsedBitmap.BitmapInfo convertDDStoBitmInfo(DDS.DDS_HEADER_STRUCTURE dds) { ParsedBitmap.BitmapInfo bi = new ParsedBitmap.BitmapInfo(DDS.getBitmapFormat(dds), false); bi.width = (ushort)dds.ddsd.width; bi.height = (ushort)dds.ddsd.height; bi.depth = (ushort)dds.ddsd.depth; bi.mipMapCount = (ushort)dds.ddsd.MipMapCount; bi.bitsPerPixel = (ushort)dds.ddsd.ddfPixelFormat.RGBBitCount; bi.format = (ushort)bi.formatname; bi.type = (ushort)bi.typename; bi.tagtype = "mtib".ToCharArray(); bi.flags = (ushort)dds.ddsd.flags; return bi; }
/// <summary> /// The display bitmap. /// </summary> /// <param name="bitmap">The bitmap.</param> /// <param name="chunk">The chunk.</param> /// <param name="mipmap">The mipmap.</param> /// <remarks></remarks> public void DisplayBitmap(int bitmap, int chunk, int mipmap) { pictureBox1.Image = pm.FindChunkAndDecode( bitmap, chunk, mipmap, ref map.SelectedMeta, map, chunk, 0); ParsedBitmap.BitmapInfo bmInfo = new ParsedBitmap.BitmapInfo( pm.Properties[0].formatname, pm.Properties[0].swizzle); ////////////// Remove this. For testing Decoding/Encoding /////////////// // if (!pm.Properties[0].formatname.ToString().ToUpper().Contains("DXT")) // pictureBox1.Image = DDS_Convert.DecodeDDS(DDS_Convert.EncodeDDS((Bitmap)pictureBox1.Image, ref bmInfo), bmInfo); pictureBox1.Width = (pictureBox1.Image.Width * trackBar1.Value) / 2; pictureBox1.Height = (pictureBox1.Image.Height * trackBar1.Value) / 2; pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; }
/// <summary> /// The btn save image_ click. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> /// <remarks></remarks> private void btnSaveImage_Click(object sender, EventArgs e) { SaveFileDialog saveImage = new SaveFileDialog(); saveImage.InitialDirectory = Prefs.pathBitmapsFolder; saveImage.DefaultExt = "dds"; saveImage.Filter = "DDS files (*.dds)|*.dds"; if (saveImage.ShowDialog() == DialogResult.OK) { Prefs.pathBitmapsFolder = saveImage.FileName.Substring(0, saveImage.FileName.LastIndexOf('\\')); DDS.DDS_HEADER_STRUCTURE dds = new DDS.DDS_HEADER_STRUCTURE(); ParsedBitmap.BitmapInfo bi = new ParsedBitmap.BitmapInfo( ParsedBitmap.BitmapFormat.BITM_FORMAT_A8R8G8B8, false); bi.width = 224; bi.height = 207; bi.depth = 1; bi.bitsPerPixel = 32; dds.generate(ref bi); FileStream fs = new FileStream(saveImage.FileName, FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); dds.WriteStruct(ref bw); bw.Write( currentLevels[lbMapListing.SelectedIndex].screenShotRaw.MS.ToArray(), 0, (int)currentLevels[lbMapListing.SelectedIndex].screenShotRaw.MS.Length); bw.Close(); fs.Close(); } }
/// <summary> /// The save bitmap tool strip menu item_ click. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> /// <remarks></remarks> private void saveBitmapToolStripMenuItem_Click(object sender, EventArgs e) { string[] s = map.SelectedMeta.name.Split('\\'); saveBitmapDialog1.FileName = s[s.Length - 1]; saveBitmapDialog1.InitialDirectory = Prefs.pathBitmapsFolder; if (saveBitmapDialog1.ShowDialog() == DialogResult.Cancel) { return; } Prefs.pathBitmapsFolder = saveBitmapDialog1.FileName.Substring( 0, saveBitmapDialog1.FileName.LastIndexOf('\\')); // for (int index = 0; index < Map.SelectedMeta.raw.rawChunks.Count; index++) // { switch (saveBitmapDialog1.FilterIndex) { // DDS case 1: // Split save name up into parts s = new string[3]; s[0] = saveBitmapDialog1.FileName.Substring(0, saveBitmapDialog1.FileName.LastIndexOf('\\') + 1); s[1] = saveBitmapDialog1.FileName.Substring( s[0].Length, saveBitmapDialog1.FileName.LastIndexOf('.') - s[0].Length); s[2] = saveBitmapDialog1.FileName.Substring(saveBitmapDialog1.FileName.LastIndexOf('.')); int numDDS = 1; for (int i = 0; i < map.SelectedMeta.items.Count; i++) { if (map.SelectedMeta.items[i].offset == 68) { numDDS = ((MetaScanner.XReflex)map.SelectedMeta.items[i]).chunkcount; break; } } // If there is more than 1 DDS images, make a directory to hold them if (numDDS > 1) { Directory.CreateDirectory(s[0] + s[1]); } ParsedBitmap bm = new ParsedBitmap(ref map.SelectedMeta, map); bool convert = false; /* if (MessageBox.Show("Do you wish to save in the original format?", "DDS Extraction", MessageBoxButtons.YesNo) == DialogResult.No) convert = true; */ List<extractionInfo> extractInfo = new List<extractionInfo>(); // # of DDS files (not raw chunks as some are mipmaps) for (int index = 0; index < numDDS; index++) { FileStream fs; // Create the file, either in the direcotry if multiple or the single file if (numDDS > 1) { fs = new FileStream( s[0] + s[1] + "\\" + s[1] + "_" + index.ToString().PadLeft(2, '0') + s[2], FileMode.Create); } else { fs = new FileStream(saveBitmapDialog1.FileName, FileMode.Create); } BinaryWriter br = new BinaryWriter(fs); ParsedBitmap.BitmapInfo chunkInfo = null; // Conversion section disabled ATM. Maybe add it later... if (convert) { // Create Form to choose Bitmap Format Form tf = new Form(); tf.ControlBox = false; tf.Size = new Size(250, 120); tf.Text = "DDS output format"; Label tl = new Label(); tl.AutoSize = true; tl.Location = new Point(10, 2); tl.Text = "Select output format:"; ComboBox tcb = new ComboBox(); tcb.DropDownStyle = ComboBoxStyle.DropDownList; tcb.Location = new Point(10, 20); tcb.Size = new Size(200, 20); DDS.DDSFileFormat ff = DDS.getDDSType(bm.Properties[index]); string[] sa = Enum.GetNames(typeof(DDS.DDSFileFormats)); foreach (string st in sa) { tcb.Items.Add(st.Replace('_', ' ')); if (ff.Format.ToString() == st) { tcb.SelectedIndex = tcb.Items.Count - 1; } } Button tb = new Button(); tb.Location = new Point(80, 50); tb.DialogResult = DialogResult.OK; tb.Text = "&Save"; tf.Controls.Add(tl); tf.Controls.Add(tcb); tf.Controls.Add(tb); tf.ShowDialog(); string n = Enum.GetName(typeof(DDS.H2DDSFormats), tcb.SelectedIndex); ParsedBitmap.BitmapInfo bi = new ParsedBitmap.BitmapInfo(ParsedBitmap.BitmapFormat.BITM_FORMAT_A8R8G8B8, false); // DDS_Convert.DecodeDDS(); chunkInfo = DDS.ExtractDDS(map.SelectedMeta, bm, ref br, index, bi); } else { chunkInfo = DDS.ExtractDDS(map.SelectedMeta, bm, ref br, index); } // This is used to tell user expected DDS format when reinjecting DDS.DDSFileFormat DDSFF = DDS.getDDSType(chunkInfo); for (int count = 0; count <= extractInfo.Count; count++) { if (count == extractInfo.Count) { extractInfo.Add( new extractionInfo( DDSFF.Description, fs.Name.Substring(fs.Name.LastIndexOf("\\") + 1))); break; } else if (extractInfo[count].name == DDSFF.Format.ToString()) { extractInfo[count].lists.Add(fs.Name.Substring(fs.Name.LastIndexOf("\\") + 1)); } } br.Close(); fs.Close(); } // string tempS = "When reinjecting, make sure the following files are saved as the type specified:\n\n"; int retCount = 0; string tempS = "The following files have been saved as the type specified:\n\n"; for (int i = 0; i < extractInfo.Count; i++) { for (int ii = 0; ii < extractInfo[i].lists.Count; ii++) { tempS += extractInfo[i].lists[ii].PadRight(50) + " " + extractInfo[i].name + "\n"; retCount++; } } int maxLength = Screen.PrimaryScreen.Bounds.Height / 20 - 4; while (retCount > maxLength) { int ret = 0; for (int cc = 0; cc < maxLength; cc++) { ret = tempS.IndexOf('\n', ret + 1); if (ret == -1) { break; } } if (ret == -1) { break; } MessageBox.Show(tempS.Substring(0, ret)); tempS = tempS.Substring(ret); retCount -= maxLength; } MessageBox.Show(tempS); break; // BMP case 2: pictureBox1.Image.Save(saveBitmapDialog1.FileName, ImageFormat.Bmp); break; // JPG case 3: pictureBox1.Image.Save(saveBitmapDialog1.FileName, ImageFormat.Jpeg); break; } // } }