/// <summary> /// Updates the displayed image by redrawing the sprite /// </summary> private void UpdateImage() { if (ActiveBNSA == null) { return; } int animationIndex = Convert.ToInt32(animationIndexUpDown.Value); int frameIndex = Convert.ToInt32(frameIndexUpDown.Value); Animation anim = ActiveBNSA.Animations[animationIndex]; BNSA_Unpacker.classes.Frame frame = anim.Frames[frameIndex]; Bitmap bm = DrawSprite(frame, anim.CalculateAnimationBoundingBox()); //PresentationSource source = PresentationSource.FromVisual(this); //double dpiX = 96, dpiY = 96; //if (source != null) //{ // dpiX *= source.CompositionTarget.TransformToDevice.M11; // dpiY *= source.CompositionTarget.TransformToDevice.M22; //} frameImage.Source = loadBitmap(bm); //Do not remove! Huge memory spike if you do. Should probably cache the sprites at their current drawing level. or something. GC.Collect(); GC.WaitForPendingFinalizers(); }
/// <summary> /// Draws the sprite to a 256*256 (x scale) bitmap for displaying or writing to disk /// </summary> /// <param name="frame">Frame to draw</param> /// <returns>Bitmap of drawn sprite</returns> private Bitmap DrawSprite(BNSA_Unpacker.classes.Frame frame, Rectangle rectangle) { int size = Math.Max(rectangle.Height, rectangle.Width); Bitmap picture = new Bitmap(size, size); Palette palette = ActiveBNSA.WorkingPalettes[Convert.ToInt32(paletteIndexUpDown.Value)]; OAMDataListGroup frameData = frame.ResolvedOAMDataListGroup; //int[] paletteData = getUsablePaletteColors(palette.Memory); //int animationoffset = offset + getint32(spritefile, offset + (4 * animationIndex)); //int gpointer = offset + getint32(spritefile, animationoffset + (5 * 4 * frameIndex)); //int ppointer = offset + getint32(spritefile, animationoffset + (5 * 4 * frameIndex) + 4) + (int)(numericUpDown3.Value * 0x20); //UpdatePaletteDisplay(palette.Colors); //int opointer = offset + getint32(spritefile, animationoffset + (5 * 4 * frameIndex) + 4 + 4 + 4); //Pointer to OAM Data UpdateInfoBox(frame); Graphics g = Graphics.FromImage(picture); //int num = getint32(spritefile, opointer + subFrameIndex * 4); int i = 0; foreach (OAMDataListEntry entry in frameData.OAMDataLists[0].OAMDataListEntries) { //Draw Sprite into Graphics //Bitmap part = Read4BBP(entry.ObjectWidth, entry.ObjectHeight, frame.ResolvedTileset.Memory, paletteData); byte[] tileData = getTile(frame.ResolvedTileset.Memory, entry.TileNumber, entry.ObjectWidth, entry.ObjectHeight); Bitmap tileBitMap = Read4BBP(entry.ObjectWidth, entry.ObjectHeight, tileData, palette.Colors); if (entry.HorizontalFlip & entry.VerticalFlip) { tileBitMap.RotateFlip(RotateFlipType.RotateNoneFlipXY); } else if (entry.HorizontalFlip) { tileBitMap.RotateFlip(RotateFlipType.RotateNoneFlipX); } else if (entry.VerticalFlip) { tileBitMap.RotateFlip(RotateFlipType.RotateNoneFlipY); } System.Drawing.Point drawPos = new System.Drawing.Point( /*(picture.Width / 2) + */ entry.X - rectangle.Left, /*(picture.Height / 2) + */ entry.Y - rectangle.Top); //yes, minus, confusing, i know... //Console.WriteLine("Drawing OAM " + i + " w TN " + entry.TileNumber + ": " + drawPos.X + "," + drawPos.Y); g.DrawImageUnscaled(tileBitMap, drawPos); i++; } //Scale image int scale = (int)drawScaleUpDown.Value; Bitmap returnpicture = resizeImage(picture, scale * picture.Width, scale * picture.Height); //Graphics finalgraphics = Graphics.FromImage(returnpicture); //finalgraphics.DrawImage(new Bitmap(256, 256, g), returnpicture.Width, returnpicture.Height); //g.DrawRectangle(Pens.Black, new Rectangle(0, 0, picture.Width-1, picture.Height-1)); return(returnpicture); }
private void UpdateInfoBox(BNSA_Unpacker.classes.Frame frame) { infoListbox.Items.Clear(); infoListbox.Items.Add("Current Frame Info:"); //infoListbox.Items.Add("Start of Sprite File:\t0x" + offset.ToString("X8")); //infoListbox.Items.Add("Animation Pointer:\t0x" + animationpointer.ToString("X8")); infoListbox.Items.Add("Tileset Index:\t" + frame.ResolvedTileset.Index); infoListbox.Items.Add("Tileset Pointer:\t0x" + frame.ResolvedTileset.Pointer.ToString("X8")); infoListbox.Items.Add("# of Tiles Used:\t" + frame.ResolvedOAMDataListGroup.OAMDataLists[0].OAMDataListEntries.Count); //infoListbox.Items.Add("Palette Pointer:\t0x" + ppointer.ToString("X8")); infoListbox.Items.Add("OAM Data List Idx:\t" + frame.ResolvedOAMDataListGroup.Index); infoListbox.Items.Add("OAM Data List Ptr:\t0x" + frame.ResolvedOAMDataListGroup.OAMDataLists[0].Pointer.ToString("X8")); }