Example #1
0
 public void SetFrames(Frame[] frames)
 {
     this.frames = (Frame[])frames.Clone();
 }
Example #2
0
        public void Generate(Stream paletteStr, Stream imgLinealStr, Stream imgTiledStr, Stream spriteStr)
        {
            Pixel[] pixelsLin;
            Pixel[] pixelsHori;
            Color[][] palettes;
            this.CreateData(out pixelsLin, out pixelsHori, out palettes);

            // Get frame list
            Frame[] frames = new Frame[this.frameData.Count];
            for (int i = 0; i < this.frameData.Count; i++)
                frames[i] = this.frameData[i].Item1;

            // Create palette format
            Nclr nclr = new Nclr() {
                Extended = false,
                Format   = this.Format
            };
            nclr.SetPalette(palettes);

            // Create image format
            Ncgr ncgrLineal = new Ncgr() {
                RegDispcnt  = this.DispCnt,
                Unknown     = this.UnknownChar,
                InvalidSize = true
            };
            ncgrLineal.Width  = (pixelsLin.Length > 256) ? 256 : pixelsLin.Length;
            ncgrLineal.Height = (int)Math.Ceiling(pixelsLin.Length / (double)ncgrLineal.Width);
            ncgrLineal.SetData(pixelsLin, PixelEncoding.Lineal, this.Format, this.TileSize);

            Ncgr ncgrTiled = new Ncgr() {
                RegDispcnt  = this.DispCnt,
                Unknown     = this.UnknownChar,
                InvalidSize = true
            };
            ncgrTiled.Width  = ncgrLineal.Width;
            ncgrTiled.Height = ncgrLineal.Height;
            if (ncgrTiled.Height % this.TileSize.Height != 0)
                ncgrTiled.Height += this.TileSize.Height - (ncgrTiled.Height % this.TileSize.Height);
            ncgrTiled.SetData(pixelsHori, PixelEncoding.HorizontalTiles, this.Format, this.TileSize);

            // Create sprite format
            Ncer ncer = new Ncer() {
                TileSize = 128,
                IsRectangularArea = this.UseRectangularArea
            };
            ncer.SetFrames(frames);

            // Write data
            if (paletteStr != null)
                nclr.Write(paletteStr);
            if (imgLinealStr != null)
                ncgrLineal.Write(imgLinealStr);
            if (imgTiledStr != null)
                ncgrTiled.Write(imgTiledStr);
            if (spriteStr != null)
                ncer.Write(spriteStr);
        }
Example #3
0
        public Frame Split(EmguImage frame)
        {
            // Trim image
            Point startPos = TrimImage(ref frame);

            // Create objects
            List<Obj> objs = new List<Obj>();
            this.CreateObjects(frame, objs, 0, 0, frame.Height);

            // Update coordinates. Sets to absolute values.
            foreach (Obj obj in objs) {
                obj.CoordX = (short)(obj.CoordX + startPos.X);
                obj.CoordY = (sbyte)(obj.CoordY + startPos.Y);
            }

            // Return new frame
            Frame f = new Frame();
            f.SetObjects(objs.ToArray());
            f.VisibleArea = new Rectangle(startPos.X - 256, startPos.Y - 128, frame.Width - 1, frame.Height - 1);
            return f;
        }
Example #4
0
        public void AddFrame(EmguImage image, Frame frame)
        {
            this.frameData.Add(Tuple.Create(frame, image));

            // Since flip it is not supported still, disable it
            foreach (Obj obj in frame.GetObjects()) {
                obj.VerticalFlip   = false;
                obj.HorizontalFlip = false;
            }
        }
Example #5
0
            protected override void ReadData(Stream strIn)
            {
                BinaryReader br = new BinaryReader(strIn);
                long blockStart = strIn.Position;

                ushort numFrames  = br.ReadUInt16();
                this.TypeFrame    = br.ReadUInt16();
                uint frameOffset  = br.ReadUInt32();
                this.TileSize     = 1 << (5 + (int)(br.ReadUInt32() & 0xFF));
                int frameInfoSize = ((this.TypeFrame & 1) != 0) ? 0x10 : 0x08;

                this.UnknownOffset1 = br.ReadUInt32();	// Offset to unknown block
                this.Unknown        = br.ReadUInt32();	// Unknown
                this.UnknownOffset2 = br.ReadUInt32();	// Unknown offset

                #if VERBOSE
                if (this.UnknownOffset1 != 0)
                    Console.WriteLine("\t* UnknownOffset1 -> {0:x8}", this.UnknownOffset1);
                if (this.Unknown != 0)
                    Console.WriteLine("\t* Unknown -> {0:x8}", this.Unknown);
                if (this.UnknownOffset2 != 0)
                    Console.WriteLine("\t* UnknownOffset2 -> {0:X8}", this.UnknownOffset2);
                #endif

                this.Frames = new Frame[numFrames];
                for (int i = 0; i < numFrames; i++) {
                    strIn.Position = blockStart + frameOffset + i * frameInfoSize;
                    Frame frame    = new Frame();
                    frame.TileSize = this.TileSize;

                    ushort numObjs  = br.ReadUInt16();
                    ushort areaInfo = br.ReadUInt16();
                    uint objOffset  = br.ReadUInt32();

                    // Get area info
                    bool squareSizeFlag = ((areaInfo >> 11) & 1) == 0;
                    Rectangle frameArea = new Rectangle();
                    if ((this.TypeFrame & 1) != 0 && !squareSizeFlag) {
                        short xend = br.ReadInt16();
                        short yend = br.ReadInt16();
                        short xstart = br.ReadInt16();
                        short ystart = br.ReadInt16();

                        frameArea.Location = new Point(xstart, ystart);
                        frameArea.Width    = xend - xstart;
                        frameArea.Height   = yend - ystart;
                    } else if (!squareSizeFlag) {
                        throw new FormatException("Obj area info is square but areaInfo is set");
                    } else {
                        int squareSize = (areaInfo & 0x3F) << 2;
                        squareSize *= 2;

                        frameArea.Width  = squareSize;
                        frameArea.Height = squareSize;
                    }

                    // Read Objs
                    strIn.Position = blockStart + frameOffset + numFrames * frameInfoSize + objOffset;
                    Obj[] objs = new Obj[numObjs];
                    for (int j = 0; j < numObjs; j++) {
                        objs[j] = Obj.FromUshort(br.ReadUInt16(), br.ReadUInt16(), br.ReadUInt16());
                        objs[j].Id = (ushort)j;
                    }

                    // TODO: Detect frame position for square size

                    frame.SetObjects(objs);
                    frame.VisibleArea = frameArea;
                    this.Frames[i] = frame;
                }
            }