// OPT: not terribly efficient... /// <summary> /// /// </summary> public FrameSet this[int i] { get { FrameSet[] afrms = new FrameSet[Items.Count]; Items.Values.CopyTo(afrms, 0); return(afrms[i]); } }
// OPT: not terribly efficient... /// <summary> /// /// </summary> public FrameSet this[int i] { get { FrameSet[] afrms = new FrameSet[Items.Count]; Items.Values.CopyTo(afrms, 0); return afrms[i]; } }
/// <summary> /// /// </summary> /// <param name="strFrameSet"></param> /// <param name="strFrame"></param> /// <param name="frm"></param> /// <returns></returns> public bool AddFrame(string strFrameSet, string strFrame, Frame frm) { FrameSet frms; if (Items.Contains(strFrameSet)) { frms = (FrameSet)Items[strFrameSet]; } else { frms = new FrameSet(strFrameSet); Items.Add(strFrameSet, frms); } frms.Add(frm); return(true); }
// Write the .ani file and create a _ani subdirectory populated with one // .png for each frame public static bool SaveAs(AnimSet anis, string strFileName) { if (strFileName == null) { strFileName = anis.Name + ".ani"; } XmlTextWriter xwtr = new XmlTextWriter(strFileName, null); xwtr.Formatting = Formatting.Indented; anis.Serialize(xwtr); xwtr.Close(); // Delete/create _ani subdirectory string strDir = strFileName.Replace(".ani", "_ani"); if (Directory.Exists(strDir)) { Directory.Delete(strDir, true); } Directory.CreateDirectory(strDir); // Write all the frames as .png files into the _ani subdir foreach (DictionaryEntry deAnimSet in anis.Items) { Anim ani = (Anim)deAnimSet.Value; foreach (DictionaryEntry deAnim in ani.Items) { FrameSet frms = (FrameSet)deAnim.Value; foreach (Frame frm in frms) { frm.Bitmap.Save(strDir + @"\" + anis.Name + "_" + ani.Name + "_" + frms.Name + "_" + frm.Index + ".png", ImageFormat.Png); } } } return(true); }
void ResetTreeView() { trvAnimSet.Nodes.Clear(); foreach (DictionaryEntry deAnimSet in m_anis.Items) { Anim ani = (Anim)deAnimSet.Value; TreeNode trn = new TreeNode(ani.Name); trvAnimSet.Nodes.Add(trn); // Sort the framesets using a numeric sort FrameSet[] afrms = new FrameSet[ani.Items.Count]; int i = 0; foreach (DictionaryEntry deAnim in ani.Items) afrms[i++] = (FrameSet)deAnim.Value; Array.Sort(afrms, new FrameSetComparer()); // Add the framesets to the tree foreach (FrameSet frms in afrms) { trn.Nodes.Add(new TreeNode(frms.Name)); } trn.Expand(); } }
// Write the .anir file and .bmps or .tbms, depending on fCrunch public static bool Export(AnimSet anis, string strExportPath, Palette pal, bool fCrunch, bool fValidateColors) { Color clrTransparent = Color.FromArgb(0xff, 0, 0xff); SolidBrush brTransparent = new SolidBrush(clrTransparent); if (strExportPath == null) { strExportPath = "."; } ASCIIEncoding enc = new ASCIIEncoding(); FileStream stm = new FileStream(strExportPath + @"\" + anis.Name + ".anir", FileMode.Create, FileAccess.Write); BinaryWriter stmw = new BinaryWriter(stm); // Count the number of FrameSets (aka Strips) ushort cstpd = 0; foreach (DictionaryEntry deAnimSet in anis.Items) { Anim ani = (Anim)deAnimSet.Value; cstpd += (ushort)ani.Items.Count; } // Write AnimationFileHeader.cstpd stmw.Write(Misc.SwapUShort(cstpd)); // Write array of offsets to StripDatas (AnimationFileHeader.aoffStpd) ushort offStpd = (ushort)(2 + (2 * cstpd)); byte ibm = 0; ArrayList albm = new ArrayList(); foreach (DictionaryEntry deAnimSet in anis.Items) { Anim ani = (Anim)deAnimSet.Value; foreach (DictionaryEntry deAnim in ani.Items) { FrameSet frms = (FrameSet)deAnim.Value; stmw.Write(Misc.SwapUShort(offStpd)); // Advance offset to where the next StripData will be offStpd += (ushort)((26 + 1 + 1 + 2) /* sizeof(StripData) - sizeof(FrameData) */ + ((1 + 1 + 1 + 1 + 1 + 1) /* sizeof(FrameData) */ * frms.Count)); } } // Write array of StripDatas foreach (DictionaryEntry deAnimSet in anis.Items) { Anim ani = (Anim)deAnimSet.Value; foreach (DictionaryEntry deAnim in ani.Items) { FrameSet frms = (FrameSet)deAnim.Value; // Write StripData.Name string strName = ani.Name + " " + frms.Name; byte[] abT = new byte[26]; enc.GetBytes(strName, 0, Math.Min(strName.Length, 25), abT, 0); abT[25] = 0; stmw.Write(abT); // Write StripData.cDelay stmw.Write((byte)0); // Write StripData.bfFlags stmw.Write((byte)0); // Write StripData.cfrmd ushort cfrmd = (ushort)frms.Count; stmw.Write(Misc.SwapUShort(cfrmd)); // Write array of FrameDatas foreach (Frame frm in frms) { // Write FrameData.ibm (the index of the Bitmap as it will be in the Bitmap array) stmw.Write((byte)ibm); ibm++; // Add the Frame's Bitmap for output Bitmap bm = frm.Bitmap; if (fCrunch) { albm.Add(bm); } else { // If not crunching then we need to go through some special work to preserve // the origin point. Since the origin point is determined by finding the center // of the imported bitmap we preserve it at export by creating a new bitmap // sized so that he origin will be in its center. // The '+2' at the end gives us a pixel of transparent space padding the left // and right sides of the bitmap. We don't require this for any particular // reason but it comes in handy. int cxNew = (Math.Max(frm.OriginX, bm.Width - frm.OriginX) * 2) + 2; // The '+2' at the end is to ensure a single blank scanline at the top // which Import relies on to determine the transparent color. int cyNew = (Math.Max(frm.OriginY, bm.Height - frm.OriginY) * 2) + 2; using (Bitmap bmNew = new Bitmap(cxNew, cyNew, bm.PixelFormat)) { using (Graphics g = Graphics.FromImage(bmNew)) { g.FillRectangle(brTransparent, 0, 0, cxNew, cyNew); g.DrawImage(bm, cxNew / 2 - frm.OriginX, cyNew / 2 - frm.OriginY); } strName = anis.Name + "_" + ani.Name + "_" + frms.Name + "_" + frm.Index.ToString(); bmNew.Save(strExportPath + @"\" + strName + ".png", ImageFormat.Png); } } // Write FrameData.xOrigin, FrameData.yOrigin stmw.Write((byte)frm.OriginX); stmw.Write((byte)frm.OriginY); // Write FrameData.bCustomData1, FrameData.bCustomData2, FrameData.bCustomData3 stmw.Write((byte)0); stmw.Write((byte)0); stmw.Write((byte)0); } } } stmw.Close(); // Write out .tbm if (albm.Count != 0) { string strFileName = strExportPath + @"\" + anis.Name + ".tbm"; if (gfSuperVerbose) { Console.WriteLine("Crunching and writing " + strFileName); } TBitmap.Save((Bitmap[])albm.ToArray(typeof(Bitmap)), pal, strFileName); } return(true); }
/// <summary> /// /// </summary> /// <param name="strFrameSet"></param> /// <param name="strFrame"></param> /// <param name="frm"></param> /// <returns></returns> public bool AddFrame(string strFrameSet, string strFrame, Frame frm) { FrameSet frms; if (Items.Contains(strFrameSet)) { frms = (FrameSet)Items[strFrameSet]; } else { frms = new FrameSet(strFrameSet); Items.Add(strFrameSet, frms); } frms.Add(frm); return true; }