Ejemplo n.º 1
0
        public Mask(BinaryPSDReader reader, Layer layer)
            : base(layer)
        {
            this._layer = layer;

            int nLength = (int)reader.ReadUInt32();
            if (nLength == 0)
                return;

            long nStart = reader.BaseStream.Position;

            this.Rectangle = reader.ReadPSDRectangle(); //new Rectangle(reader).ToERectangle();

            this._color = reader.ReadByte();

            this._flags = reader.ReadByte();

            if (nLength == 20)
                reader.ReadUInt16(); //padding
            else if (nLength == 36)
            {
                this._flags2 = reader.ReadByte();//same flags as above according to docs!?!?
                this._maskBg = reader.ReadByte(); //Real user mask background. Only 0 or 255 - ie bool?!?
                this._otherRectangle = reader.ReadPSDRectangle(); //new Rectangle(reader).ToERectangle(); //same as above rectangle according to docs?!?!
            }

            reader.BaseStream.Position = nStart + nLength;
        }
Ejemplo n.º 2
0
        public Mask(BinaryReverseReader reader, Layer layer)
        {
            this._layer = layer;

            int nLength = (int)reader.ReadUInt32();
            if (nLength == 0)
                return;

            long nStart = reader.BaseStream.Position;

            this.Rectangle = new ERectangle();
            this.Rectangle.Y = reader.ReadInt32();
            this.Rectangle.X = reader.ReadInt32();
            this.Rectangle.Height = reader.ReadInt32() - Rectangle.Y;
            this.Rectangle.Width = reader.ReadInt32() - Rectangle.X;

            byte color = reader.ReadByte();

            byte flags = reader.ReadByte();

            if (nLength == 36)
            {
                int someOtherFlags = reader.ReadByte();

                byte maskBg = reader.ReadByte();

                ERectangle rect = new ERectangle();
                rect.Y = reader.ReadInt32();
                rect.X = reader.ReadInt32();
                rect.Height = reader.ReadInt32() - rect.Y;
                rect.Width = reader.ReadInt32() - rect.X;
            }

            reader.BaseStream.Position = nStart + nLength;
        }
Ejemplo n.º 3
0
        public Slices(ImageResource imgRes)
            : base(imgRes)
        {
            BinaryPSDReader reader = imgRes.GetDataReader();
            this.Version = reader.ReadUInt32();
            this.Rectangle = reader.ReadPSDRectangle(); // new Rectangle(reader).ToERectangle();
            this.SlicesName = reader.ReadPSDUnicodeString();

            int cnt = (int)reader.ReadUInt32();
            this.SliceList = new List<Slice>();
            for (int i = 0; i < cnt; i++)
                this.SliceList.Add(new Slice(reader));

            int unknown1 = (int)reader.ReadUInt32();
            int unknown2 = (int)reader.ReadUInt32();
            ushort unknown3 = reader.ReadUInt16();
            string unknown4 = DynVal.ReadSpecialString(reader);
            int unknown5 = (int)reader.ReadUInt32();

            this.Values = new List<DynVal>();
            while (reader.BytesToEnd > 0)
            {
                DynVal val = DynVal.ReadValue(reader, false);
                this.Values.Add(val);
            }
            //this.Values = DynVal.ReadValues(reader);
            //this.Data = reader.ReadBytes((int)reader.BytesToEnd);
            reader.Close();
        }
Ejemplo n.º 4
0
 public Endogine.ERectangle ReadPSDRectangle()
 {
     Endogine.ERectangle rct = new ERectangle();
     rct.Y      = this.ReadInt32();
     rct.X      = this.ReadInt32();
     rct.Height = this.ReadInt32() - rct.Y;
     rct.Width  = this.ReadInt32() - rct.X;
     return(rct);
 }
        public static ERectangle GetRectangle()
        {
            IUnityContainer container = new UnityContainer();

            container.RegisterType <ERectangle>();
            ERectangle rectangle = container.Resolve <ERectangle>();

            return(rectangle);
        }
Ejemplo n.º 6
0
        public PackNode Insert(Image img)
        {
            if (!this.IsLeaf)             //we're not a leaf so try inserting into a child
            {
                PackNode newNode = _children[0].Insert(img);
                if (newNode != null)
                {
                    return(newNode);
                }
                // no room in first, insert into second
                return(_children[1].Insert(img));
            }
            //if there's already a lightmap here, return
            if (_imgId >= 0)
            {
                return(null);
            }

            //if we're too small, return
            if (_rct.Width + 1 < img.Size.Width || _rct.Height + 1 < img.Size.Height)
            {
                return(null);
            }

            //if we're just right, accept
            if (_rct.Width + 1 == img.Size.Width && _rct.Height + 1 == img.Size.Height)
            {
                return(this);
            }

            //otherwise, gotta split this node and create some kids
            _children    = new PackNode[2];
            _children[0] = new PackNode();
            _children[1] = new PackNode();

            //decide which way to split
            int dw = this._rct.Width - img.Width;
            int dh = this._rct.Height - img.Height;

            if (dw > dh)
            {
                _children[0]._rct = ERectangle.FromLTRB(_rct.Left, _rct.Top, _rct.Left + img.Width - 1, _rct.Bottom);
                _children[1]._rct = ERectangle.FromLTRB(_rct.Left + img.Width, _rct.Top, _rct.Right, _rct.Bottom);
            }
            else
            {
                _children[0]._rct = ERectangle.FromLTRB(_rct.Left, _rct.Top, _rct.Right, _rct.Top + img.Height - 1);
                _children[1]._rct = ERectangle.FromLTRB(_rct.Left, _rct.Top + img.Height, _rct.Right, _rct.Bottom);
            }

            //insert into first child we created
            return(this._children[0].Insert(img));
        }
        public void TestDrawRectangle()
        {
            ERectangle rectangle = RectangleFactory.GetRectangle();

            rectangle.FirstpointXCoordinate  = 40;
            rectangle.FirstpointYCoordinate  = 40;
            rectangle.SecondpointXCoordinate = 60;
            rectangle.SecondpointYCoordinate = 60;

            IRectangleOperation rectangleOperation = RectangleOperationFactory.GetRectangleOperation();

            rectangleOperation.Draw(rectangle);
        }
Ejemplo n.º 8
0
        public Bitmap RenderToBitmap(int nTwipSize)
        {
            EPoint ptOffset;
            Bitmap bmp = Shape.RenderToBitmap(nTwipSize, this.CommandList, this.FillStyles, this.LineStyles, out ptOffset);

            if (bmp == null)
            {
                return(null);
            }
            this.Bounds = new ERectangle(0, 0, bmp.Width, bmp.Height);
            this.Bounds.Offset(ptOffset);
            //this.Bounds*=nTwipSize;
            return(bmp);
        }
Ejemplo n.º 9
0
        public Smoke()
        {
            this.MouseActive   = true;
            this.TextureFilter = Sprite.TextureFilters.High;
            this.Scaling       = new EPointF(5, 5);
            this.Ink           = RasterOps.ROPs.AddPin;

            this.Create(100, 100);

            lwidth  = this.Width / res;
            lheight = this.Height / res;

            v = new vsquare[lwidth + 1][];
            for (int i = 0; i < v.Length; i++)
            {
                v[i] = new vsquare[lheight + 1];
            }

            vbuf = new vbuffer[lwidth + 1][];
            for (int i = 0; i < vbuf.Length; i++)
            {
                vbuf[i] = new vbuffer[lheight + 1];
            }

            p = new particle[pnum];

            CurrentColor = Color.FromArgb(2, 255, 0, 0);

            ERectangle emitter = ERectangle.FromLTRB(this.Width / 2 - 20, this.Height - 20, this.Width / 2 + 20, this.Height);

            for (int i = 0; i < pnum; i++)
            {
                p[i] = new particle(emitter, this);
                p[i].Init();
            }
            for (int i = 0; i <= lwidth; i++)
            {
                for (int u = 0; u <= lheight; u++)
                {
                    v[i][u]    = new vsquare(i * res, u * res, this);
                    vbuf[i][u] = new vbuffer(i * res, u * res, this);
                }
            }

            RandomGust = new Gust();
        }
Ejemplo n.º 10
0
        public static void SplitImage(Document psd, int layerIndex, string outputFilePrefix)
        {
            ImageResources.GridGuidesInfo guidesInfo = (ImageResources.GridGuidesInfo)psd.GetResource(typeof(ImageResources.GridGuidesInfo));

            List <int> vertical = new List <int>();
            List <ImageResources.GridGuidesInfo.GridGuide> guides = guidesInfo.GetGuidesByAlignment(false);

            foreach (ImageResources.GridGuidesInfo.GridGuide gg in guides)
            {
                vertical.Add((int)gg.LocationInPixels);
            }
            vertical.Add((int)psd.Header.Rows);

            List <int> horizontal = new List <int>();

            guides = guidesInfo.GetGuidesByAlignment(true);
            foreach (ImageResources.GridGuidesInfo.GridGuide gg in guides)
            {
                horizontal.Add((int)gg.LocationInPixels);
            }
            horizontal.Add((int)psd.Header.Columns);

            Bitmap bmp   = psd.Layers[layerIndex].Bitmap;
            int    lastX = 0;
            int    cnt   = 0;

            foreach (int x in horizontal)
            {
                int lastY = 0;
                foreach (int y in vertical)
                {
                    ERectangle rct    = ERectangle.FromLTRB(lastX, lastY, x, y);
                    Bitmap     bmpNew = new Bitmap(rct.Width, rct.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    Graphics   g      = Graphics.FromImage(bmpNew);
                    g.DrawImage(bmp, new Rectangle(0, 0, rct.Width, rct.Height), rct.ToRectangle(), GraphicsUnit.Pixel);
                    g.Dispose();

                    //TODO: examine bitmap and see if it can be reduced (e.g. middle parts are probably the same)

                    Endogine.BitmapHelpers.BitmapHelper.Save(bmpNew, outputFilePrefix + "_slice" + cnt + ".png");
                    cnt++;
                    lastY = y;
                }
                lastX = x;
            }
        }
Ejemplo n.º 11
0
        public ERectangle ReadRect()
        {
            long nNumBitsPerValue = this.ReadBits(5, false);

            long[] a = this.ReadBitArray(4, (int)nNumBitsPerValue, true);
            //ERectangle rct = ERectangle.FromLTRB((int)a[0], (int)a[2], (int)a[1], (int)a[3]); //according to docs - but they're wrong
            ERectangle rct = new ERectangle((int)a[0], (int)a[2], (int)a[1], (int)a[3]);

            if (rct.Width < 0)
            {
                rct.Width = -rct.Width;
            }
            if (rct.Height < 0)
            {
                rct.Height = -rct.Height;
            }
            this.JumpToNextByteStart();             //opposed to the documentation...
            return(rct);
        }
Ejemplo n.º 12
0
        public CaveWalls()
        {
            m_noise           = new Endogine.Procedural.Noise();
            m_noise.Frequency = 0.1f;
            m_noise.Octaves   = 4;
            m_noise.Decay     = 0.5f;

            m_wallSprites = new ArrayList();
            m_locYPairs   = new SortedList();

            m_rctPlayArea = new ERectangle(0, 0, 640, 480);
            m_fCaveHeight = m_rctPlayArea.Height * 0.8f;

            m_rnd = new Random();
            for (int i = 0; i < m_rctPlayArea.Width / m_nTileWidth + 1; i++)
            {
                this.CreateNewTiles(i * m_nTileWidth);
            }
        }
Ejemplo n.º 13
0
        public GameMain()
        {
            m_starField  = new StarField();
            m_player     = new Player(this);
            m_aAsteroids = new ArrayList();

            //The aOKLocs is generated so no asteroids will appear close to the ship
            EPoint     pntStageSize     = EndogineHub.Instance.Stage.Size;
            ArrayList  aOKLocs          = new ArrayList();
            EPoint     pntNumPositions  = new EPoint(6, 6);
            ERectangle rctFreePositions = new ERectangle(2, 2, 2, 2);

            for (int y = 0; y < pntNumPositions.Y; y++)
            {
                if (y >= rctFreePositions.Y && y < rctFreePositions.Bottom)
                {
                    y += rctFreePositions.Height;
                }
                for (int x = 0; x < pntNumPositions.X; x++)
                {
                    if (x >= rctFreePositions.X && x < rctFreePositions.Right)
                    {
                        x += rctFreePositions.Width;
                    }
                    EPoint pnt = new EPoint(x, y) * pntStageSize / (pntNumPositions - new EPoint(1, 1)) - pntStageSize / 2;;
                    aOKLocs.Add(pnt);
                }
            }

            Random rnd = new Random();

            for (int i = 0; i < 4; i++)
            {
                Asteroid asteroid = new Asteroid(this, 3);
                asteroid.Velocity = new EPointF((float)rnd.NextDouble() - 0.5f, (float)rnd.NextDouble() - 0.5f);

                int    nRndPos = rnd.Next(aOKLocs.Count);
                EPoint pntLoc  = (EPoint)aOKLocs[nRndPos];
                aOKLocs.RemoveAt(nRndPos);
                asteroid.Loc = pntLoc.ToEPointF();
            }
        }
Ejemplo n.º 14
0
            public Slice(BinaryPSDReader reader)
            {
                this.ID                  = reader.ReadUInt32();
                this.GroupID             = reader.ReadUInt32();
                this.Origin              = reader.ReadUInt32();
                this.Name                = reader.ReadPSDUnicodeString();
                this.Type                = reader.ReadUInt32();
                this.Rectangle           = reader.ReadPSDRectangleReversed(); //new Rectangle(reader).ToERectangle();
                this.URL                 = reader.ReadPSDUnicodeString();
                this.Target              = reader.ReadPSDUnicodeString();
                this.Message             = reader.ReadPSDUnicodeString();
                this.AltTag              = reader.ReadPSDUnicodeString();
                this.CellTextIsHtml      = reader.ReadBoolean();
                this.CellText            = reader.ReadPSDUnicodeString();
                this.HorizontalAlignment = reader.ReadUInt32();
                this.VerticalAlignment   = reader.ReadUInt32();
                this.Color               = reader.ReadPSDColor(8, true);

                //TODO: same info seems to follow in another format!
            }
Ejemplo n.º 15
0
        public void FillRectangle(Color color, ERectangle rectangle)
        {
            this.Locked = true;
            int clr = color.ToArgb();

            if (rectangle == null)
            {
                rectangle = this.Rectangle;
            }

            int oppositeX = rectangle.OppositeX;

            for (int y = rectangle.Y; y < rectangle.OppositeY; y++)
            {
                for (int x = rectangle.X; x < oppositeX; x++)
                {
                    this.SetPixelInt(x, y, clr);
                }
            }
        }
Ejemplo n.º 16
0
        public static System.Xml.XmlDocument CreateDocFromRectsAndOffsets(ERectangle[] rects, EPoint[] offsets, string[] optionalNames)
        {
            Node infoNode = new Node();
            infoNode = infoNode.CreateChild("Files");

            for (int i = 0; i<rects.Length; i++)
            {
                Node frameNode = infoNode.CreateChild("Bitmap");
                if (optionalNames!=null)
                    frameNode.Value = optionalNames[i];
                else
                    frameNode.Value = i.ToString();

                Node subNode = frameNode.CreateChild("Rect");
                subNode.Value = rects[i].ToString();
                subNode = frameNode.CreateChild("Offset");
                subNode.Value = offsets[i].ToString();
            }
            return infoNode.RootNode.CreateXmlDocument();
        }
Ejemplo n.º 17
0
        public override void Init(Record record)
        {
            base.Init(record);

            BinaryFlashReader reader = record.GetDataReader();

            //TODO: Is this a correct assumption about DefineShape5?
            this.UseAlpha  = (this.Tag == Flash.Tags.DefineShape3 || this.Tag == Flash.Tags.DefineShape5)?true:false;
            this._extended = (this.Tag == Flash.Tags.DefineShape)?false:true;
            this._hasX     = (this.Tag == Flash.Tags.DefineShape4 || this.Tag == Flash.Tags.DefineShape5)?true:false;
            this.Id        = reader.ReadUInt16();
            this.Bounds    = reader.ReadRect();

            if (this.Tag == Flash.Tags.DefineShape4)
            {
                reader.ReadRect();                 //TODO: what's this rect for?
            }
            this.ReadShapeWithStyle(reader);

            this.InitDone();
        }
Ejemplo n.º 18
0
        public AStarSearch(int[,] occupiedGrid)
        {
            this.m_rctBounds = new ERectangle(0,0,occupiedGrid.GetLength(0)-1, occupiedGrid.GetLength(1)-1);

            _TheMap = new AStarNode[this.m_rctBounds.Width+1,this.m_rctBounds.Height+1];

            for(int i=0; i<_TheMap.GetLength(0); i++)
            {
                for(int j=0; j<_TheMap.GetLength(1); j++)
                {
                    AStarNode node = new AStarNode(i,j);
                    _TheMap[i,j] = node;

                    if (occupiedGrid[i,j]==0)
                        node.Walkable = true;
                    else
                        node.Walkable = false;
                }
            }

            for (int i=0; i<8; i++) point[i] = new Point();
        }
Ejemplo n.º 19
0
        public Mask(BinaryReverseReader reader, Layer layer)
        {
            this._layer = layer;

            int nLength = (int)reader.ReadUInt32();

            if (nLength == 0)
            {
                return;
            }

            long nStart = reader.BaseStream.Position;

            this.Rectangle        = new ERectangle();
            this.Rectangle.Y      = reader.ReadInt32();
            this.Rectangle.X      = reader.ReadInt32();
            this.Rectangle.Height = reader.ReadInt32() - Rectangle.Y;
            this.Rectangle.Width  = reader.ReadInt32() - Rectangle.X;

            byte color = reader.ReadByte();

            byte flags = reader.ReadByte();

            if (nLength == 36)
            {
                int someOtherFlags = reader.ReadByte();

                byte maskBg = reader.ReadByte();

                ERectangle rect = new ERectangle();
                rect.Y      = reader.ReadInt32();
                rect.X      = reader.ReadInt32();
                rect.Height = reader.ReadInt32() - rect.Y;
                rect.Width  = reader.ReadInt32() - rect.X;
            }

            reader.BaseStream.Position = nStart + nLength;
        }
Ejemplo n.º 20
0
        public static Bitmap TreePack(Image[] images, out ERectangle[] rects, out EPoint[] offsets)
        {
            //EPoint[] offsetsOrg = new EPoint[images.Length];
            offsets = new EPoint[images.Length];
            ArrayList originalOrder = new ArrayList();

            for (int i = 0; i < images.Length; i++)
            {
                EPoint pntMid = new EPoint(images[i].Width, images[i].Height) / 2;
                EPoint pnt    = new EPoint();
                images[i]  = Endogine.BitmapHelpers.BitmapHelper.TrimWhitespace((Bitmap)images[i], out pnt);
                offsets[i] = pntMid - pnt + new EPoint(1, 1);

                originalOrder.Add(images[i]);
            }

            int  numPixelsMinimum;
            Size maxWnH, minWnH;

            GetImagesStatistics(images, out numPixelsMinimum, out maxWnH, out minWnH);

            int side     = (int)Math.Sqrt(numPixelsMinimum);
            int exponent = (int)Math.Ceiling(Math.Log(side, 2));

            side = (int)Math.Pow(2, exponent);
            Size textureSize = new Size(side, side);

            if (side * side / 2 > numPixelsMinimum)
            {
                textureSize.Height /= 2;
            }

            images = Endogine.BitmapHelpers.TexturePacking.SortImagesBySize(images);

            while (true)
            {
                EPoint[] locsInTexture = null;
                Image[]  unpacked      = null;
                Bitmap   bmp           = Endogine.BitmapHelpers.TexturePacking.TreePack(textureSize, images, out unpacked, out locsInTexture);
                if (unpacked.Length == 0)
                {
                    //offsets = new EPoint[images.Length];
                    rects = new ERectangle[images.Length];
                    for (int i = 0; i < images.Length; i++)
                    {
                        Image img      = images[i];
                        int   orgIndex = originalOrder.IndexOf(img);
                        rects[orgIndex] = new ERectangle(locsInTexture[i], new EPoint(img.Width, img.Height));
                        //offsets[orgIndex] = offsetsOrg[orgIndex]; //don't need it, correct order to begin with...
                    }
                    return(bmp);
                }

                if (textureSize.Width > textureSize.Height)
                {
                    textureSize.Height *= 2;
                }
                else
                {
                    textureSize.Width *= 2;
                }
            }
        }
Ejemplo n.º 21
0
 public Endogine.ERectangle ReadPSDRectangleReversed()
 {
     Endogine.ERectangle rct = new ERectangle();
     rct.X = this.ReadInt32();
     rct.Y = this.ReadInt32();
     rct.Width = this.ReadInt32() - rct.X;
     rct.Height = this.ReadInt32() - rct.Y;
     return rct;
 }
Ejemplo n.º 22
0
        private void CalcSourceRects()
        {
            MemberSpriteBitmap mb = this.Member;

            this._cuttingRectPixels = ERectangle.FromLTRB(
                (int)(this._cuttingRectFract.Left*mb.Size.X),
                (int)(this._cuttingRectFract.Top*mb.Size.Y),
                (int)(this._cuttingRectFract.Right*mb.Size.X),
                (int)(this._cuttingRectFract.Bottom*mb.Size.Y));

            if (this._cuttingRectFract.Width > 0.001f && this._cuttingRectPixels.Width == 0)
                this._cuttingRectPixels.Width++;
            if (this._cuttingRectFract.Height > 0.001f && this._cuttingRectPixels.Height == 0)
                this._cuttingRectPixels.Height++;

            ERectangleF[,] rects = this.CreateRectanglesFromCuttingRect(this._cuttingRectPixels.ToERectangleF(), this.Member.Size.ToEPointF());
            this._midSection = rects[1,1].ToERectangle();

            for (int x=0; x<3; x++)
            {
                for (int y=0; y<3; y++)
                {
                    ERectangleF rct = rects[x,y];
                    if (rct.Width == 0 || rct.Height == 0)
                    {
                        if (this._spriteArray[x,y] != null)
                        {
                            this._spriteArray[x,y].Dispose();
                            this._spriteArray[x,y] = null;
                        }
                    }
                    else
                    {
                        Sprite sp = this._spriteArray[x,y];
                        if (sp == null)
                        {
                            sp = new Sprite();
                            sp.Parent = this;
                            sp.Name = x.ToString()+";"+y.ToString();
                            this._spriteArray[x,y] = sp;
                        }
                        sp.Member = this.Member;
                        sp.SourceRect = rct.ToERectangle();
                        sp.RegPoint = sp.SourceRect.Location;
                    }
                }
            }

            this.m_aSprites.Clear();
            for (int x=0; x<3; x++)
                for (int y=0; y<3; y++)
                    if (this._spriteArray[x,y]!=null)
                        this.m_aSprites.Add(this._spriteArray[x,y]);
        }
Ejemplo n.º 23
0
        public static Bitmap TreePack(Image[] images, out ERectangle[] rects, out EPoint[] offsets)
        {
            //EPoint[] offsetsOrg = new EPoint[images.Length];
            offsets = new EPoint[images.Length];
            ArrayList originalOrder = new ArrayList();
            for (int i=0; i<images.Length; i++)
            {
                EPoint pntMid = new EPoint(images[i].Width, images[i].Height)/2;
                EPoint pnt = new EPoint();
                images[i] = Endogine.BitmapHelpers.BitmapHelper.TrimWhitespace((Bitmap)images[i], out pnt);
                offsets[i] = pntMid - pnt + new EPoint(1,1);

                originalOrder.Add(images[i]);
            }

            int numPixelsMinimum;
            Size maxWnH, minWnH;
            GetImagesStatistics(images, out numPixelsMinimum, out maxWnH, out minWnH);

            int side = (int)Math.Sqrt(numPixelsMinimum);
            int exponent = (int)Math.Ceiling(Math.Log(side, 2));
            side = (int)Math.Pow(2, exponent);
            Size textureSize = new Size(side,side);
            if (side*side/2 > numPixelsMinimum)
                textureSize.Height/=2;

            images = Endogine.BitmapHelpers.TexturePacking.SortImagesBySize(images);

            while (true)
            {
                EPoint[] locsInTexture = null;
                Image[] unpacked = null;
                Bitmap bmp = Endogine.BitmapHelpers.TexturePacking.TreePack(textureSize, images, out unpacked, out locsInTexture);
                if (unpacked.Length == 0)
                {
                    //offsets = new EPoint[images.Length];
                    rects = new ERectangle[images.Length];
                    for (int i=0; i<images.Length; i++)
                    {
                        Image img = images[i];
                        int orgIndex = originalOrder.IndexOf(img);
                        rects[orgIndex] = new ERectangle(locsInTexture[i], new EPoint(img.Width, img.Height));
                        //offsets[orgIndex] = offsetsOrg[orgIndex]; //don't need it, correct order to begin with...
                    }
                    return bmp;
                }

                if (textureSize.Width > textureSize.Height)
                    textureSize.Height*=2;
                else
                    textureSize.Width*=2;
            }
        }
Ejemplo n.º 24
0
        public static void TreePack(Size textureSize, string[] filenames, string outputFilename)
        {
            System.Drawing.Image[] images = new Image[filenames.Length];
//			for (int i=0; i<filenames.Length; i++)
//			{
//				files[i] = new System.IO.FileInfo(filenames[i]);
//				images[i] = System.Drawing.Bitmap.FromFile(filenames[i]);
//			}
//			ERectangle[] rects;
//			EPoint[] offsets;
//			Bitmap bmp = TreePack(images, out rects, out offsets);
//			bmp.Save(outputFilename);

            EPoint[]             offsets       = new EPoint[filenames.Length];
            System.IO.FileInfo[] files         = new System.IO.FileInfo[filenames.Length];
            PropList             originalOrder = new PropList();

            for (int i = 0; i < filenames.Length; i++)
            {
                files[i]  = new System.IO.FileInfo(filenames[i]);
                images[i] = System.Drawing.Bitmap.FromFile(filenames[i]);

                EPoint pntMid = new EPoint(images[i].Width, images[i].Height) / 2;
                EPoint pnt    = new EPoint();
                images[i]  = Endogine.BitmapHelpers.BitmapHelper.TrimWhitespace((Bitmap)images[i], out pnt);
                offsets[i] = pntMid - pnt + new EPoint(1, 1);

                originalOrder.Add(filenames[i], images[i]);
            }

            Image[] unpacked = null;

            int  numPixelsMinimum;
            Size maxWnH, minWnH;

            GetImagesStatistics(images, out numPixelsMinimum, out maxWnH, out minWnH);

            if (textureSize.Width == 0 || textureSize.Height == 0)
            {
                int side  = (int)Math.Sqrt(numPixelsMinimum);
                int asdas = (int)Math.Ceiling(Math.Log(side, 2));
                textureSize = new Size(side, side);
            }

            if (numPixelsMinimum >= textureSize.Width * textureSize.Height)
            {
                throw new Exception("Not enough space to pack in");
            }

            images = Endogine.BitmapHelpers.TexturePacking.SortImagesBySize(images);


            Random rnd = new Random();

            int nNumTries = 1;

            for (int i = 0; i < nNumTries; i++)
            {
                //Irritating, but since we can't find index of an item in a standard array...:
                ArrayList aImagesNewOrder = new ArrayList();
                foreach (Image image in images)
                {
                    aImagesNewOrder.Add(image);
                }

                EPoint[] locsInTexture = null;
                Bitmap   bmp           = Endogine.BitmapHelpers.TexturePacking.TreePack(textureSize, images, out unpacked, out locsInTexture);
                int      areaExcluded  = Endogine.BitmapHelpers.TexturePacking.GetTotalArea(unpacked);

                if (unpacked.Length > 0)
                {
                    throw new Exception("Couldn't fit all images. Total pixels excluded = " + areaExcluded.ToString() + " (side = " + ((int)Math.Sqrt(areaExcluded)).ToString() + ")");
                }

                ArrayList aUnpacked = new ArrayList();
                foreach (Image image in unpacked)
                {
                    aUnpacked.Add(image);
                }
                int areaUnused = 0;
                foreach (Image image in images)
                {
                    if (!aUnpacked.Contains(image))
                    {
                        areaUnused += image.Size.Width * image.Size.Height;
                    }
                }

                if (areaUnused > textureSize.Width * textureSize.Height / 2)
                {
                    //TODO: we could maybe make the texture at least half as big
                }

                Node infoNode = new Node();
                infoNode = infoNode.CreateChild("Files");

                //TODO: go by the list of images that was actually used!
                for (int orgIndex = 0; orgIndex < originalOrder.Count; orgIndex++)
                {
                    Image image = (Image)originalOrder.GetByIndex(orgIndex);
                    if (aUnpacked.Contains(image))
                    {
                        continue;
                    }

                    int newIndex = aImagesNewOrder.IndexOf(image);

                    //create the file entry (File, Rect, Offset)
                    ERectangle rctInTexture = new ERectangle(
                        locsInTexture[newIndex].X, locsInTexture[newIndex].Y, image.Width, image.Height);
                    Node frameNode = infoNode.CreateChild("File");
                    //remove extension from filename:
                    frameNode.Value = files[orgIndex].Name.Substring(0, files[orgIndex].Name.LastIndexOf(files[orgIndex].Extension));
                    //frameNode.Value = files[orgIndex].Name;
                    Node subNode = frameNode.CreateChild("Rect");
                    subNode.Value = rctInTexture.ToString();
                    subNode       = frameNode.CreateChild("Offset");
                    subNode.Value = offsets[orgIndex].ToString();
                }

                System.Xml.XmlDocument doc = infoNode.RootNode.CreateXmlDocument();

                string sOut = null;
                if (nNumTries > 1)
                {
                    sOut = outputFilename + areaExcluded.ToString() + "-" + i.ToString();
                }
                else
                {
                    sOut = outputFilename;
                }

                doc.Save(sOut + ".xml");
                bmp.Save(sOut + ".png");

                //randomize order to see if we get better results:
                ArrayList aImages = new ArrayList();
                for (int j = 0; j < images.Length; j++)
                {
                    aImages.Add(images[j]);
                }

                Image[] randomOrder = new Image[images.Length];
                for (int j = images.Length - 1; j >= 0; j--)
                {
                    int pos = 0;
                    if (j > 0)
                    {
                        pos = Math.Min(rnd.Next(j), j - 1);
                    }
                    randomOrder[j] = (Image)aImages[pos];
                    aImages.RemoveAt(pos);
                }
                images = randomOrder;
            }
        }
Ejemplo n.º 25
0
        //public void AddChannel(Channel ch)
        //{
        //    this._channels.Add(ch.Usage, ch);
        //}

        public Layer(BinaryPSDReader reader, Document document)
        {
            this._document = document;

            this._rect = reader.ReadPSDRectangle();

            ushort numChannels = reader.ReadUInt16();

            this._channels = new Dictionary <int, Channel>();
            for (int channelNum = 0; channelNum < numChannels; channelNum++)
            {
                Channel ch = new Channel(reader, this);
                if (this._channels.ContainsKey(ch.Usage))
                {
                    continue; //TODO: !!
                }
                this._channels.Add(ch.Usage, ch);
            }

            string sHeader = new string(reader.ReadPSDChars(4));

            if (sHeader != "8BIM")
            {
                throw(new Exception("Layer Channelheader error!"));
            }

            //'levl'=Levels 'curv'=Curves 'brit'=Brightness/contrast 'blnc'=Color balance 'hue '=Old Hue/saturation, Photoshop 4.0 'hue2'=New Hue/saturation, Photoshop 5.0 'selc'=Selective color 'thrs'=Threshold 'nvrt'=Invert 'post'=Posterize
            this.BlendKey = new string(reader.ReadPSDChars(4));
            int nBlend = -1;

            try
            {
                nBlend = (int)Enum.Parse(typeof(_blendKeysPsd), this.BlendKey);
            }
            catch
            {
                throw new Exception("Unknown blend key: " + this.BlendKey);
            }
            if (nBlend >= 0)
            {
                BlendKeys key = (BlendKeys)nBlend;
                this.BlendKey = Enum.GetName(typeof(BlendKeys), key);
            }

            this.Opacity  = reader.ReadByte();
            this.Clipping = reader.ReadByte();
            this.Flags    = reader.ReadByte();

            reader.ReadByte();     //padding


            uint extraDataSize  = reader.ReadUInt32();
            long nChannelEndPos = reader.BaseStream.Position + (long)extraDataSize;

            if (extraDataSize > 0)
            {
                uint nLength;

                this._mask = new Mask(reader, this);
                if (this._mask.Rectangle == null)
                {
                    this._mask = null;
                }

                //blending ranges
                this._blendRanges = new List <System.Drawing.Color>();
                nLength           = reader.ReadUInt32();
                //First come Composite gray blend source / destination; Contains 2 black values followed by 2 white values. Present but irrelevant for Lab & Grayscale.
                //Then 4+4 for each channel (source + destination colors)
                for (uint i = 0; i < nLength / 8; i++)
                {
                    this._blendRanges.Add(System.Drawing.Color.FromArgb((int)reader.ReadUInt32()));
                    this._blendRanges.Add(System.Drawing.Color.FromArgb((int)reader.ReadUInt32()));
                }

                //Name
                //nLength = (uint)reader.ReadByte();
                //reader.BaseStream.Position -= 1; //TODO: wtf did I do here?
                this.Name = reader.ReadPascalString();

                //TODO: sometimes there's a 2-byte padding here, but it's not 4-aligned... What is it?
                long posBefore = reader.BaseStream.Position;
                sHeader = new string(reader.ReadPSDChars(4));
                if (sHeader != "8BIM")
                {
                    reader.BaseStream.Position -= 2;
                    sHeader = new string(reader.ReadPSDChars(4));
                }
                if (sHeader != "8BIM")
                {
                    reader.BaseStream.Position = posBefore;
                }
                else
                {
                    reader.BaseStream.Position -= 4;
                    this._resources             = LayerResource.ReadLayerResources(reader, null);
                }
                if (reader.BaseStream.Position != nChannelEndPos)
                {
                    reader.BaseStream.Position = nChannelEndPos;
                }
            }
        }
Ejemplo n.º 26
0
        public Layer(BinaryReverseReader reader, Document document)
        {
            this._document = document;

            this._rect = new ERectangle();
            this._rect.Y = reader.ReadInt32();
            this._rect.X = reader.ReadInt32();
            this._rect.Height = reader.ReadInt32() - this._rect.Y;
            this._rect.Width = reader.ReadInt32() - this._rect.X;

            this.NumChannels = reader.ReadUInt16();
            this._channels = new Dictionary<int, Channel>();
            for (int channelNum = 0; channelNum < this.NumChannels; channelNum++)
            {
                Channel ch = new Channel(reader, this);
                this._channels.Add(ch.Usage, ch);
            }

            string sHeader = new string(reader.ReadChars(4));
            if (sHeader != "8BIM")
                throw(new Exception("Layer Channelheader error!"));

            this.BlendKey = new string(reader.ReadChars(4));
            int nBlend = -1;
            try
            {
                nBlend = (int)Enum.Parse(typeof(_blendKeysPsd), this.BlendKey);
            }
            catch { }
            if (nBlend >= 0)
            {
                BlendKeys key = (BlendKeys)nBlend;
                this.BlendKey = Enum.GetName(typeof(BlendKeys), key);
            }

            this.Opacity = reader.ReadByte(); //(byte)(255 - (int)reader.ReadByte());
            //paLayerInfo[#Opacity] = 256 - m_oReader.readUC() --256-ScaleCharToQuantum(ReadBlobByte(image))
            this.Clipping = reader.ReadByte();
            this.Flags = reader.ReadByte();

            reader.ReadByte(); //padding

            uint nSize = reader.ReadUInt32();
            long nChannelEndPos = reader.BaseStream.Position + (long)nSize;
            if (nSize > 0)
            {
                uint nLength;
                //uint nCombinedlength = 0;

                this._mask = new Mask(reader, this);
                if (this._mask.Rectangle == null)
                    this._mask = null;

                //reader.BaseStream.Position+=nLength-16;

                //nCombinedlength+= nLength + 4;

                //blending ranges
                nLength = reader.ReadUInt32();
                for (uint i = 0; i < nLength/8; i++)
                {
                    uint color1 = reader.ReadUInt32();
                    uint color2 = reader.ReadUInt32();
                }
                //nCombinedlength+= nLength + 4;

                //Name
                nLength = (uint)reader.ReadByte();
                reader.BaseStream.Position-=1;
                this.Name = reader.ReadPascalString();
                //nCombinedlength+= nLength + 4;

                #region Adjustment etc layers
                //TODO: there's probably a 2-byte padding here
                sHeader = new string(reader.ReadChars(4));
                if (sHeader != "8BIM")
                {
                    reader.BaseStream.Position-=2;
                    sHeader = new string(reader.ReadChars(4));
                }
                reader.BaseStream.Position-=4;

                do
                {
                    try
                    {
                        this.ReadPSDChannelTag(reader);
                    }
                    catch
                    {
                        //dunno what the last bytes are for, just skip them:
                        reader.BaseStream.Position = nChannelEndPos;
                    }
                }
                while(reader.BaseStream.Position < nChannelEndPos);

                #endregion
            }
        }
Ejemplo n.º 27
0
        //, ref string actualFilename)
        public Bitmap LoadIntoBitmap(string a_sFilename)
        {
            //string sOrg = a_sFilename; //for debugging
            //a_sFilename = m_endogine.CastLib.FindFile(a_sFilename);
            a_sFilename = AppSettings.Instance.FindFile(a_sFilename);
            if (a_sFilename.Length == 0)
            {
                if (true) // || m_endogine.CastLib.UseDummiesForFilesNotFound)
                {
                    //TODO: generalized dummy function
                    a_sFilename = m_endogine.CastLib.DirectoryPath + "Cross.bmp";
                }
            }

            System.IO.FileInfo finfo = new System.IO.FileInfo(a_sFilename);

            Name = finfo.Name.Replace(finfo.Extension, "");
            FileFullName = a_sFilename;

            if (!finfo.Exists)
            {
                throw new System.IO.FileNotFoundException("Member file not found: "+a_sFilename);
            }

            //TODO: only allow >= 24 bpp PixelFormat.Format8bppIndexed - otherwise convert!

            Bitmap bmpDst = null;
            bool bStandardLoad = true;
            if (a_sFilename.IndexOf(".gif") > 0)
            {
                Image img = System.Drawing.Image.FromFile(a_sFilename);
                System.Drawing.Imaging.FrameDimension oDimension = new System.Drawing.Imaging.FrameDimension(img.FrameDimensionsList[0]);
                int nNumFrames = img.GetFrameCount(oDimension);

                //calc how big the destination bitmap must be (make it as square as possible)
                //TODO: it's OK if there's a few uninhabited tiles at end?
                int nNumFramesOnX = (int)Math.Sqrt(nNumFrames);
                for (; nNumFramesOnX > 0; nNumFramesOnX--)
                {
                    if (nNumFrames/nNumFramesOnX*nNumFramesOnX == nNumFrames)
                        break;
                }

                bmpDst = new Bitmap(
                    img.Size.Width*nNumFramesOnX, img.Size.Height*nNumFrames/nNumFramesOnX,
                    PixelFormat.Format24bppRgb);
                Graphics g = Graphics.FromImage(bmpDst);

                if (nNumFrames > 1)
                {
                    bStandardLoad = false;
                    //TODO: let picRefs handle the generation animation...
                    for(int i = 0; i < nNumFrames; i++)
                    {
                        int x = i%nNumFramesOnX;
                        int y = i/nNumFramesOnX;
                        img.SelectActiveFrame(oDimension, i);
                        ERectangle rctDst = new ERectangle(x*img.Size.Width, y*img.Size.Height, img.Size.Width, img.Size.Height);
                        g.DrawImageUnscaled(img, rctDst.X, rctDst.Y, rctDst.Width, rctDst.Height);
                    }
                    g.Dispose();
                    this.m_sizeTotal = new EPoint(bmpDst.Width, bmpDst.Height);

                    this.m_bGotAnimation = true;
                    PicRef.CreatePicRefs(this, nNumFramesOnX, nNumFrames);
                    //AnimateWithinSize = new EPoint(img.Size.Width, img.Size.Height);
                }
                img.Dispose();
            }

            if (!bStandardLoad)
            {
            }
            else
            {
                bmpDst = (Bitmap)System.Drawing.Bitmap.FromFile(a_sFilename);
            }

            m_sizeTotal = new EPoint(bmpDst.Width, bmpDst.Height);

            m_bmpThumbnail = new Bitmap(32,32, PixelFormat.Format24bppRgb);
            Graphics g2 = Graphics.FromImage(m_bmpThumbnail);
            g2.DrawImage(bmpDst, 0,0, m_bmpThumbnail.Width, m_bmpThumbnail.Height);
            g2.Dispose();

            this.LoadResourceFile(a_sFilename);

            return bmpDst;
        }
Ejemplo n.º 28
0
        public static void TreePack(Size textureSize, string[] filenames, string outputFilename)
        {
            System.Drawing.Image[] images = new Image[filenames.Length];
            //			for (int i=0; i<filenames.Length; i++)
            //			{
            //				files[i] = new System.IO.FileInfo(filenames[i]);
            //				images[i] = System.Drawing.Bitmap.FromFile(filenames[i]);
            //			}
            //			ERectangle[] rects;
            //			EPoint[] offsets;
            //			Bitmap bmp = TreePack(images, out rects, out offsets);
            //			bmp.Save(outputFilename);

            EPoint[] offsets = new EPoint[filenames.Length];
            System.IO.FileInfo[] files = new System.IO.FileInfo[filenames.Length];
            PropList originalOrder = new PropList();
            for (int i=0; i<filenames.Length; i++)
            {
                files[i] = new System.IO.FileInfo(filenames[i]);
                images[i] = System.Drawing.Bitmap.FromFile(filenames[i]);

                EPoint pntMid = new EPoint(images[i].Width, images[i].Height)/2;
                EPoint pnt = new EPoint();
                images[i] = Endogine.BitmapHelpers.BitmapHelper.TrimWhitespace((Bitmap)images[i], out pnt);
                offsets[i] = pntMid - pnt + new EPoint(1,1);

                originalOrder.Add(filenames[i], images[i]);
            }

            Image[] unpacked = null;

            int numPixelsMinimum;
            Size maxWnH, minWnH;
            GetImagesStatistics(images, out numPixelsMinimum, out maxWnH, out minWnH);

            if (textureSize.Width == 0 || textureSize.Height == 0)
            {
                int side = (int)Math.Sqrt(numPixelsMinimum);
                int asdas = (int)Math.Ceiling(Math.Log(side, 2));
                textureSize = new Size(side,side);
            }

            if (numPixelsMinimum >= textureSize.Width*textureSize.Height)
                throw new Exception("Not enough space to pack in");

            images = Endogine.BitmapHelpers.TexturePacking.SortImagesBySize(images);

            Random rnd = new Random();

            int nNumTries = 1;
            for (int i=0; i<nNumTries; i++)
            {
                //Irritating, but since we can't find index of an item in a standard array...:
                ArrayList aImagesNewOrder = new ArrayList();
                foreach (Image image in images)
                    aImagesNewOrder.Add(image);

                EPoint[] locsInTexture = null;
                Bitmap bmp = Endogine.BitmapHelpers.TexturePacking.TreePack(textureSize, images, out unpacked, out locsInTexture);
                int areaExcluded = Endogine.BitmapHelpers.TexturePacking.GetTotalArea(unpacked);

                if (unpacked.Length > 0)
                    throw new Exception("Couldn't fit all images. Total pixels excluded = "+areaExcluded.ToString() + " (side = "+((int)Math.Sqrt(areaExcluded)).ToString()+")");

                ArrayList aUnpacked = new ArrayList();
                foreach (Image image in unpacked)
                    aUnpacked.Add(image);
                int areaUnused = 0;
                foreach (Image image in images)
                {
                    if (!aUnpacked.Contains(image))
                        areaUnused+=image.Size.Width*image.Size.Height;
                }

                if (areaUnused > textureSize.Width*textureSize.Height/2)
                {
                    //TODO: we could maybe make the texture at least half as big
                }

                Node infoNode = new Node();
                infoNode = infoNode.CreateChild("Files");

                //TODO: go by the list of images that was actually used!
                for (int orgIndex = 0; orgIndex<originalOrder.Count; orgIndex++)
                {
                    Image image = (Image)originalOrder.GetByIndex(orgIndex);
                    if (aUnpacked.Contains(image))
                        continue;

                    int newIndex = aImagesNewOrder.IndexOf(image);

                    //create the file entry (File, Rect, Offset)
                    ERectangle rctInTexture = new ERectangle(
                        locsInTexture[newIndex].X, locsInTexture[newIndex].Y, image.Width, image.Height);
                    Node frameNode = infoNode.CreateChild("File");
                    //remove extension from filename:
                    frameNode.Value = files[orgIndex].Name.Substring(0,files[orgIndex].Name.LastIndexOf(files[orgIndex].Extension));
                    //frameNode.Value = files[orgIndex].Name;
                    Node subNode = frameNode.CreateChild("Rect");
                    subNode.Value = rctInTexture.ToString();
                    subNode = frameNode.CreateChild("Offset");
                    subNode.Value = offsets[orgIndex].ToString();
                }

                System.Xml.XmlDocument doc = infoNode.RootNode.CreateXmlDocument();

                string sOut = null;
                if (nNumTries > 1)
                    sOut = outputFilename+areaExcluded.ToString()+"-"+i.ToString();
                else
                    sOut = outputFilename;

                doc.Save(sOut+".xml");
                bmp.Save(sOut+".png");

                //randomize order to see if we get better results:
                ArrayList aImages = new ArrayList();
                for (int j=0; j<images.Length;j++)
                    aImages.Add(images[j]);

                Image[] randomOrder = new Image[images.Length];
                for (int j=images.Length-1;j>=0;j--)
                {
                    int pos = 0;
                    if (j > 0)
                        pos = Math.Min(rnd.Next(j), j-1);
                    randomOrder[j] = (Image)aImages[pos];
                    aImages.RemoveAt(pos);
                }
                images = randomOrder;
            }
        }
Ejemplo n.º 29
0
        public Bitmap LoadIntoBitmap(string a_sFilename)         //, ref string actualFilename)
        {
            //string sOrg = a_sFilename; //for debugging
            //a_sFilename = m_endogine.CastLib.FindFile(a_sFilename);
            a_sFilename = AppSettings.Instance.FindFile(a_sFilename);
            if (a_sFilename.Length == 0)
            {
                if (true)                 // || m_endogine.CastLib.UseDummiesForFilesNotFound)
                {
                    //TODO: generalized dummy function
                    a_sFilename = m_endogine.CastLib.DirectoryPath + "Cross.bmp";
                }
            }

            System.IO.FileInfo finfo = new System.IO.FileInfo(a_sFilename);

            Name         = finfo.Name.Replace(finfo.Extension, "");
            FileFullName = a_sFilename;


            if (!finfo.Exists)
            {
                throw new System.IO.FileNotFoundException("Member file not found: " + a_sFilename);
            }


            //TODO: only allow >= 24 bpp PixelFormat.Format8bppIndexed - otherwise convert!

            Bitmap bmpDst        = null;
            bool   bStandardLoad = true;

            if (a_sFilename.IndexOf(".gif") > 0)
            {
                Image img = System.Drawing.Image.FromFile(a_sFilename);
                System.Drawing.Imaging.FrameDimension oDimension = new System.Drawing.Imaging.FrameDimension(img.FrameDimensionsList[0]);
                int nNumFrames = img.GetFrameCount(oDimension);

                //calc how big the destination bitmap must be (make it as square as possible)
                //TODO: it's OK if there's a few uninhabited tiles at end?
                int nNumFramesOnX = (int)Math.Sqrt(nNumFrames);
                for (; nNumFramesOnX > 0; nNumFramesOnX--)
                {
                    if (nNumFrames / nNumFramesOnX * nNumFramesOnX == nNumFrames)
                    {
                        break;
                    }
                }

                bmpDst = new Bitmap(
                    img.Size.Width * nNumFramesOnX, img.Size.Height * nNumFrames / nNumFramesOnX,
                    PixelFormat.Format24bppRgb);
                Graphics g = Graphics.FromImage(bmpDst);

                if (nNumFrames > 1)
                {
                    bStandardLoad = false;
                    //TODO: let picRefs handle the generation animation...
                    for (int i = 0; i < nNumFrames; i++)
                    {
                        int x = i % nNumFramesOnX;
                        int y = i / nNumFramesOnX;
                        img.SelectActiveFrame(oDimension, i);
                        ERectangle rctDst = new ERectangle(x * img.Size.Width, y * img.Size.Height, img.Size.Width, img.Size.Height);
                        g.DrawImageUnscaled(img, rctDst.X, rctDst.Y, rctDst.Width, rctDst.Height);
                    }
                    g.Dispose();
                    this.m_sizeTotal = new EPoint(bmpDst.Width, bmpDst.Height);

                    this.m_bGotAnimation = true;
                    PicRef.CreatePicRefs(this, nNumFramesOnX, nNumFrames);
                    //AnimateWithinSize = new EPoint(img.Size.Width, img.Size.Height);
                }
                img.Dispose();
            }

            if (!bStandardLoad)
            {
            }
            else
            {
                bmpDst = (Bitmap)System.Drawing.Bitmap.FromFile(a_sFilename);
            }

            m_sizeTotal = new EPoint(bmpDst.Width, bmpDst.Height);

            m_bmpThumbnail = new Bitmap(32, 32, PixelFormat.Format24bppRgb);
            Graphics g2 = Graphics.FromImage(m_bmpThumbnail);

            g2.DrawImage(bmpDst, 0, 0, m_bmpThumbnail.Width, m_bmpThumbnail.Height);
            g2.Dispose();

            this.LoadResourceFile(a_sFilename);

            return(bmpDst);
        }
Ejemplo n.º 30
0
        public override void Init(Record record)
        {
            base.Init (record);

            BinaryFlashReader reader = record.GetDataReader();
            //TODO: Is this a correct assumption about DefineShape5?
            this.UseAlpha = (this.Tag==Flash.Tags.DefineShape3 || this.Tag==Flash.Tags.DefineShape5)?true:false;
            this._extended = (this.Tag==Flash.Tags.DefineShape)?false:true;
            this._hasX = (this.Tag==Flash.Tags.DefineShape4 || this.Tag==Flash.Tags.DefineShape5)?true:false;
            this.Id = reader.ReadUInt16();
            this.Bounds = reader.ReadRect();

            if (this.Tag==Flash.Tags.DefineShape4)
                reader.ReadRect(); //TODO: what's this rect for?

            this.ReadShapeWithStyle(reader);

            this.InitDone();
        }
Ejemplo n.º 31
0
            public Slice(BinaryPSDReader reader)
            {
                this.ID = reader.ReadUInt32();
                this.GroupID = reader.ReadUInt32();
                this.Origin = reader.ReadUInt32();
                this.Name = reader.ReadPSDUnicodeString();
                this.Type = reader.ReadUInt32();
                this.Rectangle = reader.ReadPSDRectangleReversed(); //new Rectangle(reader).ToERectangle();
                this.URL = reader.ReadPSDUnicodeString();
                this.Target = reader.ReadPSDUnicodeString();
                this.Message = reader.ReadPSDUnicodeString();
                this.AltTag = reader.ReadPSDUnicodeString();
                this.CellTextIsHtml = reader.ReadBoolean();
                this.CellText = reader.ReadPSDUnicodeString();
                this.HorizontalAlignment = reader.ReadUInt32();
                this.VerticalAlignment = reader.ReadUInt32();
                this.Color = reader.ReadPSDColor(8, true);

                //TODO: same info seems to follow in another format!
            }
Ejemplo n.º 32
0
        public static void MaskFiles(string filesearch, Bitmap mask24Bit, string outputPath, EPoint offset)
        {
            if (offset == null)
            {
                offset = new EPoint();
            }

            Bitmap   bmpSrc     = mask24Bit;
            Graphics g          = null;
            Bitmap   bmpA       = null;
            EPoint   pntNewSize = new EPoint();

            System.IO.FileInfo[] files = Endogine.Files.FileFinder.GetFiles(filesearch);
            foreach (System.IO.FileInfo fi in files)
            {
                Bitmap bmpDst = new Bitmap(fi.FullName);
                //Find the rect that encloses both bitmaps
                ERectangle rctCommon = new ERectangle(0, 0, bmpSrc.Width, bmpSrc.Height);
                rctCommon.Offset(offset);
                rctCommon.Expand(new ERectangle(0, 0, bmpDst.Width, bmpDst.Height));

                //and make both bitmaps the same size (without scaling)
                Bitmap bmpX;
                EPoint pnt;

                bmpX = new Bitmap(bmpDst, rctCommon.Size.ToSize());
                g    = Graphics.FromImage(bmpX);
                //g.FillRectangle(new SolidBrush(Color.FromArgb(255,255,255,255)), 0,0,bmpX.Width,bmpX.Height);
                g.Clear(Color.FromArgb(0, 0, 0, 0));
                pnt = new EPoint();
                if (offset.X < 0)
                {
                    pnt.X = -offset.X;
                }
                if (offset.Y < 0)
                {
                    pnt.Y = -offset.Y;
                }
                g.DrawImage(bmpDst,
                            new Rectangle(pnt.X, pnt.Y, bmpDst.Width, bmpDst.Height),
                            0, 0, bmpDst.Width, bmpDst.Height, GraphicsUnit.Pixel);
                //g.DrawImageUnscaled(bmpDst, pnt.X,pnt.Y, bmpDst.Width, bmpDst.Height); //(bmpX.Width-bmpDst.Width)/2,  (bmpX.Height-bmpDst.Height)/2);
                bmpDst = bmpX;

                bmpX = new Bitmap(bmpSrc, rctCommon.Size.ToSize());
                g    = Graphics.FromImage(bmpX);
                g.FillRectangle(new SolidBrush(Color.Black), 0, 0, bmpX.Width, bmpX.Height);
                pnt = new EPoint();
                if (offset.X > 0)
                {
                    pnt.X = offset.X;
                }
                if (offset.Y > 0)
                {
                    pnt.Y = offset.Y;
                }
                g.DrawImage(bmpSrc,
                            new Rectangle(pnt.X, pnt.Y, bmpSrc.Width, bmpSrc.Height),
                            0, 0, bmpSrc.Width, bmpSrc.Height, GraphicsUnit.Pixel);

                //g.DrawImageUnscaled(bmpSrc, pnt.X,pnt.Y); //(bmpX.Width-bmpSrc.Width)/2,  (bmpX.Height-bmpSrc.Height)/2);
                bmpSrc = bmpX;

                if (true)
                {
                    //this will be done the first time, and each time the bmpDst.Size is different from the last
                    //with the resizing above, this will only happen once
                    if (bmpDst.Size != pntNewSize.ToSize())
                    {
                        pntNewSize = new EPoint(bmpDst.Size.Width, bmpDst.Size.Height);
                        bmpA       = new Bitmap(bmpDst.Size.Width, bmpDst.Size.Height, PixelFormat.Format24bppRgb);
                        g          = Graphics.FromImage(bmpA);
                        g.DrawImage(bmpSrc,
                                    new Rectangle(0, 0, bmpDst.Width, bmpDst.Height),
                                    new Rectangle(0, 0, bmpSrc.Width, bmpSrc.Height), GraphicsUnit.Pixel);
                        bmpA = Endogine.BitmapHelpers.BitmapHelper.ExtractChannel(bmpA, 0);
                        //bmpA.Save(fi.DirectoryName+"\\a__maskX"+fi.Name);
                    }
                }

                Endogine.BitmapHelpers.BitmapHelper.Mask(bmpDst, bmpA);
                string sOut = outputPath + fi.Name;
                bmpDst.Save(sOut);
            }
        }
Ejemplo n.º 33
0
        public static Bitmap PackBitmapsIntoOneLarge(ArrayList bmps, EPoint pntPreferredLayout, out Node infoRoot)
        {
            //If no specification of number of tiles on X and Y, make a guess:
            if (pntPreferredLayout == null)
            {
                int nNumOnX = (int)Math.Sqrt(bmps.Count);
                if (nNumOnX * nNumOnX < bmps.Count)
                {
                    nNumOnX++;
                }
                int nNumOnY = bmps.Count / nNumOnX;
                if (nNumOnX * nNumOnY < bmps.Count)
                {
                    nNumOnY++;
                }

                pntPreferredLayout = new EPoint(nNumOnX, nNumOnY);
            }

            bool bTrimWhiteSpace = true;

            //when packing the bitmap tightly, must store the offsets of bitmap frames so they don't wiggle on playback:
            bool bUseIndividualOffsets = true;

            infoRoot = new Node();
            Node node = infoRoot.AppendChild("root");

            node.AppendChild("NumFramesTotal").Value = bmps.Count;
            node.AppendChild("NumFramesOnX").Value   = pntPreferredLayout.X;

            Node subNode;

            subNode = node.AppendChild("Animations");
            //subNode.AppendChild("Default").Value = "0 0-4";

            EPoint[] offsets = new EPoint[bmps.Count];

            //this is the smallest rectangle that can encompass all frames:
            ERectangle rctBounds = ERectangle.FromLTRB(9999, 9999, -9999, -9999);

            //Trim white space from all bitmaps
            subNode = node.AppendChild("Frames");
            for (int i = 0; i < bmps.Count; i++)
            {
                Bitmap bmp = (Bitmap)bmps[i];

                if (bTrimWhiteSpace)
                {
                    EPoint pntMid = new EPoint(bmp.Size.Width, bmp.Size.Height) / 2;
                    EPoint pntTopLeftCorner;
                    bmp     = BitmapHelper.TrimWhitespace(bmp, out pntTopLeftCorner);
                    bmps[i] = bmp;

                    offsets[i] = pntTopLeftCorner;

                    if (bUseIndividualOffsets)                     //make more compact (but offset values are needed):
                    {
                        rctBounds.Expand(new ERectangle(0, 0, bmp.Width, bmp.Height));
                        //make offset to middle of input bitmap
                        offsets[i] = pntMid - pntTopLeftCorner;
                    }
                    else                     //Expand bounds so no offset values are needed:
                    {
                        rctBounds.Expand(new ERectangle(pntTopLeftCorner.X, pntTopLeftCorner.Y, bmp.Width, bmp.Height));
                    }
                }
                else
                {
                    rctBounds.Expand(new ERectangle(0, 0, bmp.Width, bmp.Height));
                }
            }

            //Create the merged bitmap:
            EPoint   totalSize = rctBounds.Size * pntPreferredLayout;
            Bitmap   largeBmp  = new Bitmap(totalSize.X, totalSize.Y);
            Graphics g         = Graphics.FromImage(largeBmp);

            for (int i = 0; i < bmps.Count; i++)
            {
                Bitmap bmp    = (Bitmap)bmps[i];
                EPoint pntDst = new EPoint((i % pntPreferredLayout.X) * rctBounds.Size.X, (i / pntPreferredLayout.X) * rctBounds.Size.Y);

                Node subsub = subNode.AppendChild("Frame");
                subsub.Value = i.ToString();

                if (bUseIndividualOffsets)
                {
                    //subsub.AppendChild("Offset").Value = (offsets[i]+rctBounds.TopLeft).ToString();
                    subsub.AppendChild("Offset").Value = offsets[i].ToString();
                }
                else
                {
                    //pntDst is upper left corner of destination rectangle.
                    //Since we don't use individual offset, we want to move it according to offset:
                    pntDst = pntDst - rctBounds.TopLeft + offsets[i];
                }
                g.DrawImage(bmp, new RectangleF(pntDst.ToPoint(), new Size(bmp.Width, bmp.Height)));
            }

            if (bUseIndividualOffsets)
            {
                node.AppendChild("RegPoint").Value = new EPoint().ToString();
            }
            else
            {
                node.AppendChild("RegPoint").Value = rctBounds.TopLeft.ToString();
            }

            return(largeBmp);
        }
Ejemplo n.º 34
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            int ChoiceOfShape = 0;

            do
            {
                Console.WriteLine("Enter Your Choice to Draw Shape");
                Console.WriteLine("1.Line");
                Console.WriteLine("2.Circle");
                Console.WriteLine("3.Rectangle");
                Console.WriteLine("4.Exit");

                ChoiceOfShape = int.Parse(Console.ReadLine());

                switch (ChoiceOfShape)
                {
                case 1:

                    Console.WriteLine("1.Line");
                    Line line = LineFactory.GetLine();

                    Console.WriteLine("Enter X Co-ordinate of First point");
                    int XLineFirst = int.Parse(Console.ReadLine());

                    Console.WriteLine("Enter Y Co-ordinate of First point");
                    int YLineFirst = int.Parse(Console.ReadLine());

                    Console.WriteLine("Enter X Co-ordinate of Second point");
                    int XLineSecond = int.Parse(Console.ReadLine());

                    Console.WriteLine("Enter Y Co-ordinate of Second point");
                    int YLineSecond = int.Parse(Console.ReadLine());

                    line.FirstpointXCoordinate  = XLineFirst;    //100
                    line.FirstpointYCoordinate  = YLineFirst;    //200
                    line.SecondpointXCoordinate = XLineSecond;   //400
                    line.SecondpointYCoordinate = YLineSecond;   //300

                    ILineOperation lineOperation = LineOperationFactory.GetLineOperation();

                    //IShapeOperation lineOperation = ShapeOperationFactory.GetLineOperation();

                    lineOperation.Draw(line);
                    log.InfoFormat("Line Created");


                    break;

                case 2:

                    Console.WriteLine("2.Circle");

                    Circle circle = CircleFactory.GetCircle();

                    Console.WriteLine("Enter X & Y Co-ordinate of Centre point");
                    int XCircleFirst = int.Parse(Console.ReadLine());
                    int YCircleFirst = int.Parse(Console.ReadLine());

                    Console.WriteLine("Enter X & Y Equidistance Points of Radius");
                    int XCircleSecond = int.Parse(Console.ReadLine());
                    int YCircleSecond = int.Parse(Console.ReadLine());

                    circle.FirstpointXCoordinate  = XCircleFirst;      //10
                    circle.FirstpointYCoordinate  = YCircleFirst;      //10
                    circle.SecondpointXCoordinate = XCircleSecond;     //50
                    circle.SecondpointYCoordinate = YCircleSecond;     //50

                    ICircleOperation circleOperation = CircleOperationalFactory.GetCircleOperation();
                    circleOperation.Draw(circle);

                    log.InfoFormat("Circle Created");

                    break;

                case 3:

                    Console.WriteLine("3.Rectangle");

                    ERectangle rectangle = RectangleFactory.GetRectangle();

                    Console.WriteLine("Enter X & Y Co-ordinate of First point of Rectangle");
                    int XRectFirst = int.Parse(Console.ReadLine());
                    int YRectFirst = int.Parse(Console.ReadLine());

                    Console.WriteLine("Enter X & Y Co-ordinate of Second Point of Rectangle");
                    int XRectSecond = int.Parse(Console.ReadLine());
                    int YRectSecond = int.Parse(Console.ReadLine());

                    rectangle.FirstpointXCoordinate  = XRectFirst;
                    rectangle.FirstpointYCoordinate  = YRectFirst;
                    rectangle.SecondpointXCoordinate = XRectSecond;
                    rectangle.SecondpointYCoordinate = YRectSecond;

                    IRectangleOperation rectangleOperation = RectangleOperationFactory.GetRectangleOperation();
                    rectangleOperation.Draw(rectangle);

                    log.InfoFormat("Rectangle Created");

                    break;

                case 4:


                    Console.WriteLine("4.Exit");
                    Console.WriteLine("Welcome Again!!");

                    System.Environment.Exit(0);

                    break;

                default:

                    Console.WriteLine("Wrong Choice ! ");
                    break;
                }
            } while (ChoiceOfShape != 3);
        }
Ejemplo n.º 35
0
        public void Read(string a_sFilename)
        {
            FileStream stream = new FileStream(a_sFilename,
                                               FileMode.Open, FileAccess.Read);

            this.reader = new BinaryFlashReader(stream);

            //Header
            //Compressed or uncompressed?
            bool bCompressed = (this.reader.ReadChar().ToString() == "C")?true:false;

            //char 2-3 is always WS:
            string sWS = new string(this.reader.ReadChars(2));

            if (sWS != "WS")
            {
                throw(new Exception("Not a Flash file"));
            }

            //Testing: I'm writing some data to an XML doc in order to see what the parser's results are
            //TODO: instead, the whole Flash data structure (after parsing) should be serializable to XML
            //I.e. a Flash->XML->Flash converter is a must later on. Or preferably XAML.
//			XmlDocument xdoc = new XmlDocument();
//			XmlNode xnode = xdoc.CreateElement("root");
//			xdoc.AppendChild(xnode);

            int Version = this.reader.ReadByte();

//			this.AddNodeAndValue(xnode, "Version", Version.ToString());

            long nFileLength = this.reader.ReadUInt32();

            //rect for the bounding rect of the whole Flash file:
            ERectangle boundingRect = this.reader.ReadRect();

//			this.AddNodeAndValue(xnode, "BoundingRect", boundingRect.ToString());

            this.FrameRate = this.reader.ReadFixed16();
            int FrameCount = this.reader.ReadUInt16();

//			this.AddNodeAndValue(xnode, "FrameRate", FrameRate.ToString());
//			this.AddNodeAndValue(xnode, "FrameCount", FrameCount.ToString());


            this.AllReadObjects = new ArrayList();
            this.Characters     = new Hashtable();
            this.Members        = new Hashtable();

            //read tag by tag until end of file:
            while (true)
            {
                Record record    = new Record(reader, this);
                Record newRecord = null;
                switch (record.Tag)
                {
                case Tags.SetBackgroundColor:
                    EH.Instance.Stage.Color = record.GetDataReader().ReadRGB();
                    break;

                case Tags.ShowFrame:
                    newRecord = record;
                    break;

                case Tags.DefineBits:
                case Tags.DefineBitsJPEG2:
                case Tags.DefineBitsJPEG3:
                case Tags.DefineBitsLossless:
                case Tags.DefineBitsLossless2:
                    if (record.Tag == Tags.DefineBits)
                    {
                        newRecord = new Shape.Image(this._jpegTables);
                    }
                    else
                    {
                        newRecord = new Shape.Image();
                    }
                    break;

                case Tags.JPEGTables:
                    if (this._jpegTables == null)
                    {
                        BinaryFlashReader subReader = record.GetDataReader();
                        this._jpegTables = subReader.ReadBytes((int)record.TagLength - 2);
                        if (subReader.ReadUInt16() != 0xd9ff)
                        {
                            throw new Exception("JPEG error");
                        }
                    }
                    break;


                case Tags.DefineFont:
                    newRecord = new Text.Font();                            //record
                    break;

                case Tags.DefineFontInfo:
                    break;

                case Tags.DefineText2:
                    newRecord = new Text.Text();                            //record
                    break;

                case Tags.DefineShape:
                case Tags.DefineShape2:
                case Tags.DefineShape3:
                case Tags.DefineShape4:
                case Tags.DefineShape5:
                    newRecord = new Shape.Shape();
                    break;

                case Tags.DefineMorphShape:
                    newRecord = new Shape.MorphShape();
                    break;

                case Tags.PlaceObject:
                case Tags.PlaceObject2:
                    newRecord = new Placement.Placement();
                    break;

                case Tags.RemoveObject:
                case Tags.RemoveObject2:
                    newRecord = new Placement.Remove();
                    break;

                case Tags.DoAction:
                case Tags.DoInitAction:
                    //newRecord = new Action.DoAnAction();
                    break;
                }

                if (newRecord != null)
                {
                    if (!newRecord.Inited)
                    {
                        newRecord.Init(record);
                    }
                    this.AllReadObjects.Add(newRecord);
                }

                if (record.Tag == Tags.End)
                {
                    break;
                }
                if (this.reader.BaseStream.Position >= nFileLength - 1)
                {
                    break;
                }
            }

            //xdoc.Save(a_sFilename+".xml");
            //zoom in:
            //this.TwipSize = 1; //20
            this._executedRecordIndex    = -1;
            this._objectByDepth          = new SortedList();
            this.CharacterIdsByDepth     = new Hashtable();
            EH.Instance.EnterFrameEvent += new EnterFrame(Instance_EnterFrameEvent);
        }
Ejemplo n.º 36
0
        public ERectangle GetTrimmedRect(int channelNum, int trimRangeStart, int trimRangeEnd)
        {
            int shift = (3 - channelNum) * 8;

            this.Locked = true;

            ERectangle rctBounds = this.Rectangle.Copy();

            for (int side = 0; side < 2; side++)
            {
                int yDir = 1;
                int yUse = 0;
                if (side == 1)
                {
                    yDir = -1;
                    yUse = this.Height - 2;
                }

                bool bFound = false;
                for (int y = 0; y < this.Height; y++)
                {
                    for (int x = this.Width - 1; x >= 0; x--)
                    {
                        int val = (this.GetPixelInt(x, yUse) >> shift) & 0xff;
                        if (val < trimRangeStart || val > trimRangeEnd)
                        {
                            if (side == 0)
                            {
                                rctBounds.Top = yUse;
                            }
                            else
                            {
                                rctBounds.Bottom = yUse;
                            }

                            bFound = true;
                            break;
                        }
                    }
                    if (bFound)
                    {
                        break;
                    }
                    yUse += yDir;
                }
            }

            for (int side = 0; side < 2; side++)
            {
                int xDir = 1;
                int xUse = 0;
                if (side == 1)
                {
                    xDir = -1;
                    xUse = this.Width - 1;
                }

                bool bFound = false;
                for (int x = 0; x < this.Width; x++)
                {
                    xUse += xDir;
                    for (int y = this.Height - 1; y >= 0; y--)
                    {
                        int val = (this.GetPixelInt(xUse, y) >> shift) & 0xff;
                        if (val < trimRangeStart || val > trimRangeEnd)
                        {
                            if (side == 0)
                            {
                                rctBounds.Right = xUse;
                            }
                            else
                            {
                                rctBounds.Left = xUse;
                            }

                            bFound = true;
                            break;
                        }
                    }
                    if (bFound)
                    {
                        break;
                    }
                }
            }

            this.Locked = false;

            return(rctBounds);
        }
Ejemplo n.º 37
0
        //public void AddChannel(Channel ch)
        //{
        //    this._channels.Add(ch.Usage, ch);
        //}
        public Layer(BinaryPSDReader reader, Document document)
        {
            this._document = document;

            this._rect = reader.ReadPSDRectangle();

            ushort numChannels = reader.ReadUInt16();
            this._channels = new Dictionary<int, Channel>();
            for (int channelNum = 0; channelNum < numChannels; channelNum++)
            {
                Channel ch = new Channel(reader, this);
                if (this._channels.ContainsKey(ch.Usage))
                    continue; //TODO: !!
                this._channels.Add(ch.Usage, ch);
            }

            string sHeader = new string(reader.ReadPSDChars(4));
            if (sHeader != "8BIM")
                throw(new Exception("Layer Channelheader error!"));

            //'levl'=Levels 'curv'=Curves 'brit'=Brightness/contrast 'blnc'=Color balance 'hue '=Old Hue/saturation, Photoshop 4.0 'hue2'=New Hue/saturation, Photoshop 5.0 'selc'=Selective color 'thrs'=Threshold 'nvrt'=Invert 'post'=Posterize
            this.BlendKey = new string(reader.ReadPSDChars(4));
            int nBlend = -1;
            try
            {
                nBlend = (int)Enum.Parse(typeof(_blendKeysPsd), this.BlendKey);
            }
            catch
            {
                throw new Exception("Unknown blend key: " + this.BlendKey);
            }
            if (nBlend >= 0)
            {
                BlendKeys key = (BlendKeys)nBlend;
                this.BlendKey = Enum.GetName(typeof(BlendKeys), key);
            }

            this.Opacity = reader.ReadByte();
            this.Clipping = reader.ReadByte();
            this.Flags = reader.ReadByte();

            reader.ReadByte(); //padding

            uint extraDataSize = reader.ReadUInt32();
            long nChannelEndPos = reader.BaseStream.Position + (long)extraDataSize;
            if (extraDataSize > 0)
            {
                uint nLength;

                this._mask = new Mask(reader, this);
                if (this._mask.Rectangle == null)
                    this._mask = null;

                //blending ranges
                this._blendRanges = new List<System.Drawing.Color>();
                nLength = reader.ReadUInt32();
                //First come Composite gray blend source / destination; Contains 2 black values followed by 2 white values. Present but irrelevant for Lab & Grayscale.
                //Then 4+4 for each channel (source + destination colors)
                for (uint i = 0; i < nLength/8; i++)
                {
                    this._blendRanges.Add(System.Drawing.Color.FromArgb((int)reader.ReadUInt32()));
                    this._blendRanges.Add(System.Drawing.Color.FromArgb((int)reader.ReadUInt32()));
                }

                //Name
                //nLength = (uint)reader.ReadByte();
                //reader.BaseStream.Position -= 1; //TODO: wtf did I do here?
                this.Name = reader.ReadPascalString();

                //TODO: sometimes there's a 2-byte padding here, but it's not 4-aligned... What is it?
                long posBefore = reader.BaseStream.Position;
                sHeader = new string(reader.ReadPSDChars(4));
                if (sHeader != "8BIM")
                {
                    reader.BaseStream.Position-=2;
                    sHeader = new string(reader.ReadPSDChars(4));
                }
                if (sHeader != "8BIM")
                    reader.BaseStream.Position = posBefore;
                else
                {
                    reader.BaseStream.Position -= 4;
                    this._resources = LayerResource.ReadLayerResources(reader, null);
                }
                if (reader.BaseStream.Position != nChannelEndPos)
                    reader.BaseStream.Position = nChannelEndPos;
            }
        }
Ejemplo n.º 38
0
        public static void MaskFiles(string filesearch, Bitmap mask24Bit, string outputPath, EPoint offset)
        {
            if (offset == null)
                offset = new EPoint();

            Bitmap bmpSrc = mask24Bit;
            Graphics g = null;
            Bitmap bmpA = null;
            EPoint pntNewSize = new EPoint();
            System.IO.FileInfo[] files = Endogine.Files.FileFinder.GetFiles(filesearch);
            foreach (System.IO.FileInfo fi in files)
            {
                Bitmap bmpDst = new Bitmap(fi.FullName);
                //Find the rect that encloses both bitmaps
                ERectangle rctCommon = new ERectangle(0,0,bmpSrc.Width,bmpSrc.Height);
                rctCommon.Offset(offset);
                rctCommon.Expand(new ERectangle(0,0,bmpDst.Width,bmpDst.Height));

                //and make both bitmaps the same size (without scaling)
                Bitmap bmpX;
                EPoint pnt;

                bmpX = new Bitmap(bmpDst, rctCommon.Size.ToSize());
                g = Graphics.FromImage(bmpX);
                //g.FillRectangle(new SolidBrush(Color.FromArgb(255,255,255,255)), 0,0,bmpX.Width,bmpX.Height);
                g.Clear(Color.FromArgb(0,0,0,0));
                pnt = new EPoint();
                if (offset.X < 0) pnt.X = -offset.X;
                if (offset.Y < 0) pnt.Y = -offset.Y;
                g.DrawImage(bmpDst,
                    new Rectangle(pnt.X,pnt.Y, bmpDst.Width, bmpDst.Height),
                    0,0,bmpDst.Width, bmpDst.Height, GraphicsUnit.Pixel);
                //g.DrawImageUnscaled(bmpDst, pnt.X,pnt.Y, bmpDst.Width, bmpDst.Height); //(bmpX.Width-bmpDst.Width)/2,  (bmpX.Height-bmpDst.Height)/2);
                bmpDst = bmpX;

                bmpX = new Bitmap(bmpSrc, rctCommon.Size.ToSize());
                g = Graphics.FromImage(bmpX);
                g.FillRectangle(new SolidBrush(Color.Black), 0,0, bmpX.Width,bmpX.Height);
                pnt = new EPoint();
                if (offset.X > 0) pnt.X = offset.X;
                if (offset.Y > 0) pnt.Y = offset.Y;
                g.DrawImage(bmpSrc,
                    new Rectangle(pnt.X,pnt.Y, bmpSrc.Width, bmpSrc.Height),
                    0,0,bmpSrc.Width, bmpSrc.Height, GraphicsUnit.Pixel);

                //g.DrawImageUnscaled(bmpSrc, pnt.X,pnt.Y); //(bmpX.Width-bmpSrc.Width)/2,  (bmpX.Height-bmpSrc.Height)/2);
                bmpSrc = bmpX;

                if (true)
                {
                    //this will be done the first time, and each time the bmpDst.Size is different from the last
                    //with the resizing above, this will only happen once
                    if (bmpDst.Size != pntNewSize.ToSize())
                    {
                        pntNewSize = new EPoint(bmpDst.Size.Width,bmpDst.Size.Height);
                        bmpA = new Bitmap(bmpDst.Size.Width,bmpDst.Size.Height, PixelFormat.Format24bppRgb);
                        g = Graphics.FromImage(bmpA);
                        g.DrawImage(bmpSrc,
                            new Rectangle(0,0,bmpDst.Width,bmpDst.Height),
                            new Rectangle(0,0,bmpSrc.Width,bmpSrc.Height), GraphicsUnit.Pixel);
                        bmpA = Endogine.BitmapHelpers.BitmapHelper.ExtractChannel(bmpA,0);
                        //bmpA.Save(fi.DirectoryName+"\\a__maskX"+fi.Name);
                    }
                }

                Endogine.BitmapHelpers.BitmapHelper.Mask(bmpDst, bmpA);
                string sOut = outputPath+fi.Name;
                bmpDst.Save(sOut);
            }
        }
Ejemplo n.º 39
0
        public override void SubDraw()
        {
            ERectangleF rctDraw = _sp.CalcRectInDrawTarget();

            //attribs.SetColorMatrix(new ColorMatrix(), ColorMatrixFlag.Default, ColorAdjustType.Bitmap);


            if (_sp.Ink == RasterOps.ROPs.Copy || _sp.Ink == RasterOps.ROPs.BgTransparent || _sp.DrawToSprite == null)             //TODO: allow RasterOps on root sprite.
            //if (false)
            {
                if (_sp.Rect.Width <= 0 || _sp.Rect.Height <= 0)
                {
                    return;
                }

                PointF   ulCorner1 = new PointF(rctDraw.X, rctDraw.Y);
                PointF   urCorner1 = new PointF(rctDraw.OppositeX, rctDraw.Y);
                PointF   llCorner1 = new PointF(rctDraw.X, rctDraw.OppositeY);
                PointF[] destPara1 = { ulCorner1, urCorner1, llCorner1 };

                ERectangle rctSrc = _sp.SourceRect;                 //m_sp.Member.GetRectForFrame(m_sp.MemberAnimationFrame);
                //RectangleF rctfCropped = m_sp.GetPortionOfMemberToDisplay();

                //g.FillRectangle(new SolidBrush(Color.Red), rctDraw);

                Graphics        g       = Graphics.FromImage(_sp.DrawToSprite.Member.Bitmap);
                ImageAttributes attribs = new ImageAttributes();
                attribs.SetWrapMode(WrapMode.Tile);
                if (_sp.Ink == RasterOps.ROPs.BgTransparent)
                {
                    attribs.SetColorKey(_sp.Member.ColorKey, _sp.Member.ColorKey);
                }

                g.SmoothingMode      = SmoothingMode.None;
                g.CompositingMode    = CompositingMode.SourceOver;
                g.CompositingQuality = CompositingQuality.Invalid;
                g.DrawImage(_sp.Member.Bitmap, destPara1, rctSrc.ToRectangleF(), GraphicsUnit.Pixel, attribs);
                g.Dispose();
            }
            else
            {
                //since it's difficult to write a RasterOp algorithm that both does effects and scales/interpolates properly,
                //I cheat by creating a temporary scaled bitmap
                if (_sp.Rect.ToERectangle().Width <= 0 || _sp.Rect.ToERectangle().Height <= 0)
                {
                    return;
                }

                Bitmap     bmp    = _sp.Member.Bitmap;
                ERectangle rctSrc = _sp.SourceRect;
                if (_sp.Scaling.X != 1 || _sp.Scaling.Y != 1 || _sp.Color != Color.White)
                {
                    //TODO: other/faster resizing algorithms at
                    //http://www.codeproject.com/csharp/ImgResizOutperfGDIPlus.asp
                    rctSrc = _sp.Rect.ToERectangle();
                    rctSrc.Offset(-rctSrc.X, -rctSrc.Y);
                    bmp = new Bitmap(_sp.Rect.ToERectangle().Width, _sp.Rect.ToERectangle().Height, _sp.Member.Bitmap.PixelFormat);                     //m_sp.Member.Bitmap, new Size(m_sp.RectInt.Width, m_sp.RectInt.Height));
                    Graphics        g       = Graphics.FromImage(bmp);
                    ImageAttributes attribs = new ImageAttributes();

                    ColorMatrix colorMatrix = new ColorMatrix();
                    colorMatrix.Matrix00 = (float)_sp.Color.R / 255;
                    colorMatrix.Matrix11 = (float)_sp.Color.G / 255;
                    colorMatrix.Matrix22 = (float)_sp.Color.B / 255;
                    colorMatrix.Matrix33 = 1.00f;                     // alpha
                    colorMatrix.Matrix44 = 1.00f;                     // w
                    attribs.SetColorMatrix(colorMatrix);

                    g.DrawImage(_sp.Member.Bitmap, rctSrc.ToRectangle(),
                                _sp.SourceRect.X, _sp.SourceRect.Y, _sp.SourceRect.Width, _sp.SourceRect.Height,
                                GraphicsUnit.Pixel, attribs);
                    g.Dispose();
                }

                RasterOps.CopyPixels(_sp.DrawToSprite.Member.Bitmap, bmp,
                                     rctDraw, rctSrc, _sp.DrawToSprite.SourceRect, (int)_sp.Ink, _sp.Blend);
            }
        }
Ejemplo n.º 40
0
 public ERectangle ReadRect()
 {
     long nNumBitsPerValue = this.ReadBits(5, false);
     long[] a = this.ReadBitArray(4, (int)nNumBitsPerValue, true);
     //ERectangle rct = ERectangle.FromLTRB((int)a[0], (int)a[2], (int)a[1], (int)a[3]); //according to docs - but they're wrong
     ERectangle rct = new ERectangle((int)a[0], (int)a[2], (int)a[1], (int)a[3]);
     if (rct.Width < 0)
         rct.Width = -rct.Width;
     if (rct.Height < 0)
         rct.Height = -rct.Height;
     this.JumpToNextByteStart(); //opposed to the documentation...
     return rct;
 }
Ejemplo n.º 41
0
        public override void Init(Record record)
        {
            base.Init(record);

            BinaryFlashReader reader = this.GetDataReader();

            this.Id = reader.ReadUInt16();

            bool      wideOffsets = false;
            ArrayList offsets     = new ArrayList();
            int       nNumChars;
            bool      hasLayout = false;

            if (this.Tag == Flash.Tags.DefineFont2)
            {
                byte flags = reader.ReadByte();
                hasLayout = (flags & 128) > 0;
                bool shiftJIS = (flags & 64) > 0;
                this.Small      = (flags & 32) > 0;
                this.Ansi       = (flags & 16) > 0;
                wideOffsets     = (flags & 8) > 0;
                this.DoubleByte = (flags & 4) > 0;
                this.Italic     = (flags & 2) > 0;
                this.Bold       = (flags & 1) > 0;

                this.LanguageCode = reader.ReadByte();
                this.Name         = reader.ReadPascalString();
                nNumChars         = reader.ReadUInt16();
            }
            else
            {
                ushort firstOffset = reader.ReadUInt16();
                offsets.Add(firstOffset);
                nNumChars = firstOffset / 2;
            }

            for (int charNum = offsets.Count; charNum < nNumChars; charNum++)
            {
                if (wideOffsets)
                {
                    offsets.Add(reader.ReadUInt32());
                }
                else
                {
                    offsets.Add((uint)reader.ReadUInt16());
                }
            }

            foreach (uint offset in offsets)
            {
                Record      recordX = new Record(reader, this.Owner);
                Shape.Shape shape   = new Endogine.Serialization.Flash.Shape.Shape();
                shape.Init(recordX);
            }

            if (this.Tag == Flash.Tags.DefineFont2)
            {
                ArrayList codeTable = new ArrayList();
                for (int charNum = 0; charNum < nNumChars; charNum++)
                {
                    if (this.DoubleByte)
                    {
                        codeTable.Add(reader.ReadUInt16());
                    }
                    else
                    {
                        codeTable.Add((ushort)reader.ReadByte());
                    }
                }

                if (hasLayout)
                {
                    short     ascent       = reader.ReadInt16();
                    short     descent      = reader.ReadInt16();
                    short     leading      = reader.ReadInt16();
                    ArrayList advanceTable = new ArrayList();
                    for (int i = 0; i < nNumChars; i++)
                    {
                        advanceTable.Add(reader.ReadInt16());
                    }
                    ArrayList boundsTable = new ArrayList();
                    for (int i = 0; i < nNumChars; i++)
                    {
                        ERectangle rect = reader.ReadRect();
                        boundsTable.Add(rect);
                    }
                    ushort kerningCount = reader.ReadUInt16();
                    for (int i = 0; i < kerningCount; i++)
                    {
                        //Kerning record
                    }
                }
            }
        }
Ejemplo n.º 42
0
 public Bitmap RenderToBitmap(int nTwipSize)
 {
     EPoint ptOffset;
     Bitmap bmp = Shape.RenderToBitmap(nTwipSize, this.CommandList, this.FillStyles, this.LineStyles, out ptOffset);
     if (bmp == null)
         return null;
     this.Bounds = new ERectangle(0,0,bmp.Width,bmp.Height);
     this.Bounds.Offset(ptOffset);
     //this.Bounds*=nTwipSize;
     return bmp;
 }
Ejemplo n.º 43
0
            public ERectangle Source; //TODO: use in future when texture anims don't have to be grids

            #endregion Fields

            #region Constructors

            public Frame(string id)
            {
                this.ID = id;
                this.Offset = new EPoint();
                this.Source = new ERectangle();
            }
Ejemplo n.º 44
0
        private void CalcSourceRects()
        {
            MemberSpriteBitmap mb = this.Member;

            this._cuttingRectPixels = ERectangle.FromLTRB(
                (int)(this._cuttingRectFract.Left * mb.Size.X),
                (int)(this._cuttingRectFract.Top * mb.Size.Y),
                (int)(this._cuttingRectFract.Right * mb.Size.X),
                (int)(this._cuttingRectFract.Bottom * mb.Size.Y));

            if (this._cuttingRectFract.Width > 0.001f && this._cuttingRectPixels.Width == 0)
            {
                this._cuttingRectPixels.Width++;
            }
            if (this._cuttingRectFract.Height > 0.001f && this._cuttingRectPixels.Height == 0)
            {
                this._cuttingRectPixels.Height++;
            }


            ERectangleF[,] rects = this.CreateRectanglesFromCuttingRect(this._cuttingRectPixels.ToERectangleF(), this.Member.Size.ToEPointF());
            this._midSection     = rects[1, 1].ToERectangle();

            for (int x = 0; x < 3; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    ERectangleF rct = rects[x, y];
                    if (rct.Width == 0 || rct.Height == 0)
                    {
                        if (this._spriteArray[x, y] != null)
                        {
                            this._spriteArray[x, y].Dispose();
                            this._spriteArray[x, y] = null;
                        }
                    }
                    else
                    {
                        Sprite sp = this._spriteArray[x, y];
                        if (sp == null)
                        {
                            sp        = new Sprite();
                            sp.Parent = this;
                            sp.Name   = x.ToString() + ";" + y.ToString();
                            this._spriteArray[x, y] = sp;
                        }
                        sp.Member     = this.Member;
                        sp.SourceRect = rct.ToERectangle();
                        sp.RegPoint   = sp.SourceRect.Location;
                    }
                }
            }

            this.m_aSprites.Clear();
            for (int x = 0; x < 3; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    if (this._spriteArray[x, y] != null)
                    {
                        this.m_aSprites.Add(this._spriteArray[x, y]);
                    }
                }
            }
        }
Ejemplo n.º 45
0
        public static Bitmap RenderToBitmap(int nTwipSize, ArrayList commandList, ArrayList fillStyles, ArrayList lineStyles, out EPoint ptOffset)
        {
            EPoint pntCurrentLoc = new EPoint();

            ArrayList pathInfos       = new ArrayList();
            PathInfo  pathInfoCurrent = new PathInfo();

            pathInfos.Add(pathInfoCurrent);

            bool hasDrawnSinceLastStyleChange = false;

            EPointF ptScale = new EPointF(1, 1) / nTwipSize;

            string sDebug = "";

            foreach (ShapeCommand.Base cmd in commandList)
            {
                if (cmd.MovesTurtle)
                {
                    if (cmd.Draws)
                    {
                        ((ShapeCommand.Draw)cmd).AddToPath(pathInfoCurrent.Path, pntCurrentLoc, ptScale.X);
                        if (Shape.Debug)
                        {
                            ArrayList pts = ((ShapeCommand.Draw)cmd).GeneratePoints(pntCurrentLoc);
                            if (cmd is ShapeCommand.Curve)
                            {
                                sDebug += "Curve";
                            }
                            else
                            {
                                sDebug += "Line";
                            }
                            sDebug += "\r\n";

                            foreach (EPointF pt in pts)
                            {
                                sDebug += pt.ToString() + "\r\n";
                            }
                        }
                        hasDrawnSinceLastStyleChange = true;
                    }
                    else
                    {
                        pathInfoCurrent.Path.CloseAllFigures();
                        pathInfoCurrent.Path.StartFigure();
                    }
                    pntCurrentLoc = cmd.GetNewLoc(pntCurrentLoc);
                }
                else
                {
                    if (hasDrawnSinceLastStyleChange)
                    {
                        pathInfoCurrent = new PathInfo();
                        pathInfos.Add(pathInfoCurrent);
                    }

                    if (cmd is ShapeCommand.FillStyle)
                    {
                        ShapeCommand.FillStyle fs = (ShapeCommand.FillStyle)cmd;
                        Brush brush = null;
                        if (fs.StyleId > 0)
                        {
                            brush = ((Style.FillStyle)fillStyles[fs.StyleId - 1]).GetBrush();
                        }
                        if (fs.Side == 0)
                        {
                            pathInfoCurrent.Brush0 = brush;
                        }
                        else
                        {
                            pathInfoCurrent.Brush1 = brush;
                        }
                    }
                    else if (cmd is ShapeCommand.LineStyle)
                    {
                        ShapeCommand.LineStyle ls = (ShapeCommand.LineStyle)cmd;
                        Pen pen = null;
                        if (ls.StyleId > 0)
                        {
                            pen = ((Style.LineStyle)lineStyles[ls.StyleId - 1]).GetPen();
                        }
                        pathInfoCurrent.Pen = pen;

                        if (pen != null)
                        {
                            pen.Width *= ptScale.X;
                        }
                    }

                    hasDrawnSinceLastStyleChange = false;
                }
            }

            Matrix transform = new Matrix();

            transform.Scale(ptScale.X, ptScale.Y);

            ERectangle bounds = ERectangle.FromLTRB(99999, 99999, -99999, -99999);

            foreach (PathInfo pathInfo in pathInfos)
            {
                //pathInfo.Path.Transform(transform);
                bounds.Expand(pathInfo.GetBounds().ToERectangle());
            }
            ptOffset = bounds.TopLeft;

            if (bounds.Width == 0 || bounds.Height == 0)
            {
                return(null);
            }
            //this.Bounds = bounds;

            if (Shape.Debug)
            {
                Endogine.Files.FileReadWrite.Write("__s.txt", sDebug);
            }


            transform = new Matrix();
            transform.Translate(-bounds.X, -bounds.Y);
            foreach (PathInfo pathInfo in pathInfos)
            {
                pathInfo.Path.Transform(transform);
            }

            Bitmap bmp = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb);

            Endogine.BitmapHelpers.Canvas canvas = Endogine.BitmapHelpers.Canvas.Create(bmp);
            canvas.Locked = true;
            canvas.Fill(Color.FromArgb(0, 255, 255, 255));
            canvas.Dispose();
            Graphics g = Graphics.FromImage(bmp);

            g.SmoothingMode = SmoothingMode.HighQuality;
            foreach (PathInfo pathInfo in pathInfos)
            {
                if (pathInfo.Pen != null)
                {
                    g.DrawPath(pathInfo.Pen, pathInfo.Path);
                }
                if (pathInfo.Brush0 != null)
                {
                    g.FillPath(pathInfo.Brush0, pathInfo.Path);
                }
                if (pathInfo.Brush1 != null)               //TODO: can GDI+ handle Flash's two different fills (0 and 1)?
                {
                    g.FillPath(pathInfo.Brush1, pathInfo.Path);
                }
            }

            return(bmp);
        }
Ejemplo n.º 46
0
        public static unsafe Bitmap TrimWhitespace(Bitmap bmp, out EPoint topLeftCorner)
        {
            //TODO: name should be TrimAlpha
            int    nThreshold = 0;
            Canvas canvas     = Canvas.Create(bmp);

            canvas.Locked = true;

            ERectangle rctBounds = ERectangle.FromLTRB(0, 0, canvas.Width, canvas.Height);

            for (int side = 0; side < 2; side++)
            {
                int yDir = 1;
                int yUse = 0;
                if (side == 1)
                {
                    yDir = -1;
                    yUse = canvas.Height - 2;
                }

                bool bFound = false;
                for (int y = 0; y < canvas.Height; y++)
                {
                    for (int x = 0; x < canvas.Width; x++)
                    {
                        if (canvas.GetPixel(x, yUse).A > nThreshold)
                        {
                            if (side == 0)
                            {
                                rctBounds.Top = yUse;
                            }
                            else
                            {
                                rctBounds.Bottom = yUse;
                            }

                            bFound = true;
                            break;
                        }
                    }
                    if (bFound)
                    {
                        break;
                    }
                    yUse += yDir;
                }
            }

            for (int side = 0; side < 2; side++)
            {
                int xDir = 1;
                int xUse = 0;
                if (side == 1)
                {
                    xDir = -1;
                    xUse = canvas.Width - 1;
                }

                bool bFound = false;
                for (int x = 0; x < canvas.Width; x++)
                {
                    xUse += xDir;
                    for (int y = 0; y < canvas.Height; y++)
                    {
                        if (canvas.GetPixel(xUse, y).A > nThreshold)
                        {
                            if (side == 0)
                            {
                                rctBounds.Left = xUse;
                            }
                            else
                            {
                                rctBounds.Right = xUse;
                            }

                            bFound = true;
                            break;
                        }
                    }
                    if (bFound)
                    {
                        break;
                    }
                }
            }

            canvas.Locked = false;

            if (rctBounds.Width == 0 || rctBounds.Height == 0)
            {
                topLeftCorner = new EPoint();
                return(null);
            }

            Bitmap   trimmedBmp = new Bitmap(rctBounds.Width, rctBounds.Height);
            Graphics g          = Graphics.FromImage(trimmedBmp);

            g.DrawImage(bmp, new Rectangle(0, 0, rctBounds.Width, rctBounds.Height),
                        rctBounds.X, rctBounds.Y, rctBounds.Width, rctBounds.Height,
                        GraphicsUnit.Pixel);

            topLeftCorner = new EPoint(rctBounds.X, rctBounds.Y);

            return(trimmedBmp);
        }
Ejemplo n.º 47
0
        public Layer(BinaryReverseReader reader, Document document)
        {
            this._document = document;

            this._rect        = new ERectangle();
            this._rect.Y      = reader.ReadInt32();
            this._rect.X      = reader.ReadInt32();
            this._rect.Height = reader.ReadInt32() - this._rect.Y;
            this._rect.Width  = reader.ReadInt32() - this._rect.X;


            this.NumChannels = reader.ReadUInt16();
            this._channels   = new Dictionary <int, Channel>();
            for (int channelNum = 0; channelNum < this.NumChannels; channelNum++)
            {
                Channel ch = new Channel(reader, this);
                this._channels.Add(ch.Usage, ch);
            }

            string sHeader = new string(reader.ReadChars(4));

            if (sHeader != "8BIM")
            {
                throw(new Exception("Layer Channelheader error!"));
            }

            this.BlendKey = new string(reader.ReadChars(4));
            int nBlend = -1;

            try
            {
                nBlend = (int)Enum.Parse(typeof(_blendKeysPsd), this.BlendKey);
            }
            catch { }
            if (nBlend >= 0)
            {
                BlendKeys key = (BlendKeys)nBlend;
                this.BlendKey = Enum.GetName(typeof(BlendKeys), key);
            }

            this.Opacity = reader.ReadByte(); //(byte)(255 - (int)reader.ReadByte());
            //paLayerInfo[#Opacity] = 256 - m_oReader.readUC() --256-ScaleCharToQuantum(ReadBlobByte(image))
            this.Clipping = reader.ReadByte();
            this.Flags    = reader.ReadByte();

            reader.ReadByte();     //padding


            uint nSize          = reader.ReadUInt32();
            long nChannelEndPos = reader.BaseStream.Position + (long)nSize;

            if (nSize > 0)
            {
                uint nLength;
                //uint nCombinedlength = 0;

                this._mask = new Mask(reader, this);
                if (this._mask.Rectangle == null)
                {
                    this._mask = null;
                }

                //reader.BaseStream.Position+=nLength-16;

                //nCombinedlength+= nLength + 4;

                //blending ranges
                nLength = reader.ReadUInt32();
                for (uint i = 0; i < nLength / 8; i++)
                {
                    uint color1 = reader.ReadUInt32();
                    uint color2 = reader.ReadUInt32();
                }
                //nCombinedlength+= nLength + 4;

                //Name
                nLength = (uint)reader.ReadByte();
                reader.BaseStream.Position -= 1;
                this.Name = reader.ReadPascalString();
                //nCombinedlength+= nLength + 4;


                #region Adjustment etc layers
                //TODO: there's probably a 2-byte padding here
                sHeader = new string(reader.ReadChars(4));
                if (sHeader != "8BIM")
                {
                    reader.BaseStream.Position -= 2;
                    sHeader = new string(reader.ReadChars(4));
                }
                reader.BaseStream.Position -= 4;

                do
                {
                    try
                    {
                        this.ReadPSDChannelTag(reader);
                    }
                    catch
                    {
                        //dunno what the last bytes are for, just skip them:
                        reader.BaseStream.Position = nChannelEndPos;
                    }
                }while(reader.BaseStream.Position < nChannelEndPos);

                #endregion
            }
        }
 public void Draw(ERectangle rectangle)
 {
     Application.Run(new RectangleForm(rectangle));
 }
Ejemplo n.º 49
0
        public void FillRectangle(Color color, ERectangle rectangle)
        {
            this.Locked = true;
            int clr = color.ToArgb();
            if (rectangle == null)
                rectangle = this.Rectangle;

            int oppositeX = rectangle.OppositeX;
            for (int y = rectangle.Y; y < rectangle.OppositeY; y++)
            {
                for (int x = rectangle.X; x < oppositeX; x++)
                {
                    this.SetPixelInt(x, y, clr);
                }
            }
        }