001package armyc2.c2sd.renderer.utilities;
002
003import android.annotation.TargetApi;
004import android.graphics.Bitmap;
005import android.graphics.Canvas;
006import android.graphics.Point;
007import android.graphics.Rect;
008import android.graphics.Bitmap.Config;
009import android.os.Build;
010
011public class ImageInfo {
012        
013        private Point _centerPoint = null;
014        private Rect _symbolBounds = null;
015        private Rect _imageBounds = null;
016        private Bitmap _image = null;
017        private int _byteCount = 0;
018        
019        public ImageInfo(ImageInfo original)
020        {
021                _centerPoint = new Point(original.getCenterPoint());
022                _symbolBounds = new Rect(original.getSymbolBounds());
023                _image = original.getImage();
024                _imageBounds = new Rect(original.getImageBounds());
025                _byteCount = original.getByteCount();
026        }
027
028
029        public ImageInfo(Bitmap image, Point centerPoint, Rect symbolBounds)
030        {
031                _centerPoint = centerPoint;
032                _symbolBounds = symbolBounds;
033                _image = image;
034                
035                _imageBounds = RectUtilities.makeRect(0, 0, image.getWidth(), image.getHeight());
036                
037                _byteCount = image.getAllocationByteCount();
038
039        }
040        
041        /**
042         * Not a full clone.  Only centerPoint and symbolBounds are copies.  Bitmap is still a reference. 
043         */
044        public ImageInfo getLightClone()
045        {
046                return new ImageInfo(_image, new Point(_centerPoint), new Rect(_symbolBounds));
047        }
048        
049        public ImageInfo getClone(ImageInfo original)
050        {
051                Point centerPoint = new Point(original.getCenterPoint());
052                Rect symbolBounds = new Rect(original.getSymbolBounds());
053                Bitmap image = original.getImage().copy(Config.ARGB_8888, false);
054                return new ImageInfo(_image, new Point(_centerPoint), new Rect(_symbolBounds));
055        }
056        
057        public Bitmap getImage()
058        {
059                return _image;
060        }
061        
062        public Point getCenterPoint()
063        {
064                return _centerPoint;
065        }
066        
067        public Rect getSymbolBounds()
068        {
069                return _symbolBounds;
070        }
071        
072        public Rect getImageBounds()
073        {
074                return _imageBounds;
075        }
076
077        public int getByteCount()
078        {
079                return _byteCount;
080        }
081        
082        public ImageInfo getSquareImageInfo()
083        {
084                ImageInfo ii = null;
085        int iwidth, iheight, x, y;
086        int width = this._imageBounds.width();
087        int height = this._imageBounds.height();
088        
089        if(this._imageBounds.width() > this._imageBounds.height())
090        {
091            iwidth = this._imageBounds.width();
092            iheight = this._imageBounds.width();
093            x=0;
094            y=(iheight - height)/2;
095        }
096        else if(this._imageBounds.width() < this._imageBounds.height())
097        {
098            iwidth = this._imageBounds.height();
099            iheight = this._imageBounds.height();
100            x = (iwidth - width)/2;
101            y = 0;
102        }
103        else
104        {
105            iwidth = this._imageBounds.width();
106            iheight = this._imageBounds.height();
107            x=0;
108            y=0;
109        }
110
111      //Draw glyphs to bitmap
112                Bitmap bmp = Bitmap.createBitmap(iwidth, iheight, Config.ARGB_8888);
113                Canvas ctx = new Canvas(bmp);
114
115        
116        ctx.drawBitmap(_image,x,y,null);
117        
118        //create new ImageInfo
119        Point center = new Point(_centerPoint);
120        center.offset(x,y);
121        Rect symbolBounds = new Rect(_symbolBounds);
122        symbolBounds.offset(x,y);
123
124        ii = new ImageInfo(bmp,center, symbolBounds);
125        
126        
127        return ii;
128        }
129}