Ejemplo n.º 1
0
 /// <summary>
 ///		Pastes the contents of a PixelMap onto this PixelMap.
 /// </summary>
 /// <param name="pixelMap">pixelMap to paste.</param>
 /// <param name="x">Position on the x-axis to start pasting from.</param>
 /// <param name="y">Position on the y-axis to start pasting from.</param>
 public void Paste(PixelMap pixelMap, int x, int y)
 {
     for (int _x = 0; _x < pixelMap.Width; _x++)
     {
         for (int _y = 0; _y < pixelMap.Height; _y++)
         {
             int _xPos = x + _x;
             int _yPos = y + _y;
             if (_xPos >= 0 && _yPos >= 0 && _xPos < _width && _yPos < _height)
             {
                 _pixels[_xPos + (_yPos * _width)] = pixelMap.Data[_x + (_y * pixelMap.Width)];
             }
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        ///		Creates an copy of a specific area of this PixelMap and returns it.
        /// </summary>
        /// <param name="sectionX">Position on the x-axis to start copying from.</param>
        /// <param name="sectionY">Position on the y-axis to start copying from.</param>
        /// <param name="sectionWidth">Width of section to copy.</param>
        /// <param name="sectionHeight">Height of section to copy.</param>
        /// <returns>The newly copied PixelMap.</returns>
        public PixelMap Copy(int sectionX, int sectionY, int sectionWidth, int sectionHeight)
        {
            PixelMap pixelMap = new PixelMap(sectionWidth, sectionHeight);

            for (int x = 0; x < sectionWidth; x++)
            {
                for (int y = 0; y < sectionHeight; y++)
                {
                    pixelMap[x, y] = this[sectionX + x, sectionY + y];
                }
            }
            //pixelMap.Data[x + (y * sectionWidth)] = _pixels[(x + sectionX) + ((y + sectionY) * _width)];

            return(pixelMap);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///		Initilizes a new image from a file.
        /// </summary>
        /// <param name="path">Memory location (or url) of image file to load.</param>
        public Image(object path, ImageFlags flags)
        {
            if ((path is PixelMap) == false)
            {
                if (path is string)
                {
                    _url = (string)path;
                }
                _fullPixelMap = PixelMapFactory.LoadPixelMap(path);
            }
            else
            {
                _fullPixelMap = (path as PixelMap).Copy();
            }

            if (_fullPixelMap == null)
            {
                return;
            }

            PixelMap map = _fullPixelMap.Copy();

            map.Mask(GraphicsManager.ColorKey);
            _mask = GraphicsManager.ColorKey;

            _width  = _fullPixelMap.Width;
            _height = _fullPixelMap.Height;
            _flags  = flags;

            _frames[0] = GraphicsManager.CreateImageFrame(map);

            // Are we dynamic? If not we don't need the full pixelmaps data so lets destroy it and
            // free up a bit of memory.
            if ((_flags & ImageFlags.Dynamic) == 0 && _fullPixelMap != null)
            {
                _fullPixelMap.Data = null;

                _frames[0].PixelMap.Data = null;

                //GC.Collect();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///		Initilizes a new image with mutliple frame cells spaced evenly out from a file.
        /// </summary>
        /// <param name="path">Memory location (or url) of image file to load.</param>
        /// <param name="cellW">Width of each cell in image.</param>
        /// <param name="cellH">Height of each cell in image.</param>
        /// <param name="cellHSeperation">Vertical seperation of each cell in image.</param>
        /// <param name="cellVSeperation">Horizontal seperation of each cell in image.</param>
        public Image(object path, int cellW, int cellH, int cellHSeperation, int cellVSeperation, ImageFlags flags)
        {
            if ((path is PixelMap) == false)
            {
                if (path is string)
                {
                    _url = (string)path;
                }
                _fullPixelMap = PixelMapFactory.LoadPixelMap(path);
            }
            else
            {
                _fullPixelMap = (path as PixelMap).Copy();
            }

            if (_fullPixelMap == null)
            {
                return;
            }

            _width    = cellW;
            _height   = cellH;
            _hSpacing = cellHSeperation;
            _vSpacing = cellVSeperation;
            _flags    = flags;

            CreateFrames();

            // Are we dynamic? If not we don't need the full pixelmaps data so lets destroy it and
            // free up a bit of memory.
            if ((_flags & ImageFlags.Dynamic) == 0 && _fullPixelMap != null)
            {
                _fullPixelMap.Data = null;
                for (int i = 0; i < _frames.Length; i++)
                {
                    _frames[i].PixelMap.Data = null;
                }
                //GC.Collect();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///		Recreates the pixel maps and resources required to render this image.
        /// </summary>
        public void CreateFrames()
        {
            if (_frames == null)
            {
                return;
            }
            if (_fullPixelMap != null)
            {
                if (_width > _fullPixelMap.Width)
                {
                    _width = _fullPixelMap.Width;
                }
                if (_height > _fullPixelMap.Height)
                {
                    _height = _fullPixelMap.Height;
                }

                int cellsH = (_fullPixelMap.Width / (_width + _hSpacing));
                int cellsV = (_fullPixelMap.Height / (_height + _vSpacing));
                _frames = new IImageFrame[cellsH * cellsV];
                for (int i = 0; i < _frames.Length; i++)
                {
                    int      px  = (i % cellsH) * _width;
                    int      py  = (i / cellsH) * _height;
                    PixelMap map = _fullPixelMap.Copy(px + ((i % cellsH) * _hSpacing), py + ((i / cellsH) * _vSpacing), _width, _height);
                    map.Mask(GraphicsManager.ColorKey);

                    _frames[i] = GraphicsManager.CreateImageFrame(map);
                }
            }
            else
            {
                for (int i = 0; i < _frames.Length; i++)
                {
                    _frames[i] = GraphicsManager.CreateImageFrame(new PixelMap(_width, _height));
                }
            }
            _mask = GraphicsManager.ColorKey;
        }
Ejemplo n.º 6
0
        /// <summary>
        ///		Initilizes a new image with mutliple frame cells spaced evenly out from a file.
        /// </summary>
        /// <param name="path">Memory location (or url) of image file to load.</param>
        /// <param name="cellW">Width of each cell in image.</param>
        /// <param name="cellH">Height of each cell in image.</param>
        /// <param name="cellHSeperation">Vertical seperation of each cell in image.</param>
        /// <param name="cellVSeperation">Horizontal seperation of each cell in image.</param>
        public Image(object path, int cellW, int cellH, int cellHSeperation, int cellVSeperation, ImageFlags flags)
        {
            if ((path is PixelMap) == false)
            {
                if (path is string) _url = (string)path;
                _fullPixelMap = PixelMapFactory.LoadPixelMap(path);
            }
            else
                _fullPixelMap = (path as PixelMap).Copy();

            if (_fullPixelMap == null)
                return;

            _width = cellW;
            _height = cellH;
            _hSpacing = cellHSeperation;
            _vSpacing = cellVSeperation;
            _flags = flags;

            CreateFrames();

            // Are we dynamic? If not we don't need the full pixelmaps data so lets destroy it and
            // free up a bit of memory.
            if ((_flags & ImageFlags.Dynamic) == 0 && _fullPixelMap != null)
            {
               _fullPixelMap.Data = null;
                   for (int i = 0; i < _frames.Length; i++)
                       _frames[i].PixelMap.Data = null;
               //GC.Collect();
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 ///		Creates a new valid image frame from a pixelmap.
 ///
 ///		This is mainly used by the Image class to recreate images whenever the driver changes
 /// </summary>
 /// <param name="pixelMap">Pixelmap to create new image frame from.</param>
 public static IImageFrame CreateImageFrame(PixelMap pixelMap)
 {
     return(_driver.CreateImageFrame(pixelMap));
 }
Ejemplo n.º 8
0
 /// <summary>
 ///     This method is called when PixelMap save is requested, if it returns true
 ///		the calling method will stop illiterating through the PixelMapFactorys and 
 ///		return success to the user.
 /// </summary>
 /// <param name="path">File path or object of the image to load.</param>
 /// <param name="pixelMap">PixelMap to save.</param>
 /// <param name="flags">Bitmask of flags defining how the pixel map should be saved.</param>
 /// <returns>True if the save was successfull else false.</returns>
 protected abstract bool RequestSave(object path, PixelMap pixelMap, PixelMapSaveFlags flags);
Ejemplo n.º 9
0
 public static void SavePixelMap(object path, PixelMap pixelMap)
 {
     SavePixelMap(path, pixelMap, 0);
 }
Ejemplo n.º 10
0
 /// <summary>
 ///     This method is called when a PixelMap save is requested, it illiterates through all
 ///     the registered PixelMapFactory instances to see if there is one capable to saving the
 ///     given format.
 /// </summary>
 /// <param name="path">File path or save pixel map to.</param>
 /// <param name="flags">Bitmask of flags to define how the pixel map should be saved.</param>
 /// <returns>True if save was successfull else false.</returns>
 public static bool SavePixelMap(object path, PixelMap pixelMap, PixelMapSaveFlags flags)
 {
     foreach (PixelMapFactory factory in _loaderList)
     {
         if (factory.RequestSave(path, pixelMap, flags) == true) return true;
     }
     return false;
 }
Ejemplo n.º 11
0
 /// <summary>
 ///		Pastes the contents of a PixelMap onto this PixelMap.
 /// </summary>
 /// <param name="pixelMap">pixelMap to paste.</param>
 /// <param name="x">Position on the x-axis to start pasting from.</param>
 /// <param name="y">Position on the y-axis to start pasting from.</param>
 public void Paste(PixelMap pixelMap, int x, int y)
 {
     for (int _x = 0; _x < pixelMap.Width; _x++)
         for (int _y = 0; _y < pixelMap.Height; _y++)
         {
             int _xPos = x + _x;
             int _yPos = y + _y;
             if (_xPos >= 0 && _yPos >= 0 && _xPos < _width && _yPos < _height)
             {
                 _pixels[_xPos + (_yPos * _width)] = pixelMap.Data[_x + (_y * pixelMap.Width)];
             }
         }
 }
Ejemplo n.º 12
0
 /// <summary>
 ///		Creates an exact copy of this PixelMap and returns it.
 /// </summary>
 /// <returns>The newly copied PixelMap.</returns>
 public PixelMap Copy()
 {
     PixelMap pixelMap = new PixelMap(_width,_height);
     pixelMap.Data = (int[])_pixels.Clone();
     pixelMap.MaskColor = _maskColor;
     pixelMap.IgnoreAlphaChannel = _ignoreAlphaChannel;
     return pixelMap;
 }
Ejemplo n.º 13
0
 /// <summary>
 ///		Creates a new valid image frame from a pixelmap.
 /// 
 ///		This is mainly used by the Image class to recreate images whenever the driver changes 
 /// </summary>
 /// <param name="pixelMap">Pixelmap to create new image frame from.</param>
 public static IImageFrame CreateImageFrame(PixelMap pixelMap)
 {
     return _driver.CreateImageFrame(pixelMap);
 }
Ejemplo n.º 14
0
 public static void SavePixelMap(object path, PixelMap pixelMap)
 {
     SavePixelMap(path, pixelMap, 0);
 }
Ejemplo n.º 15
0
 /// <summary>
 ///     This method is called when PixelMap save is requested, if it returns true
 ///		the calling method will stop illiterating through the PixelMapFactorys and
 ///		return success to the user.
 /// </summary>
 /// <param name="path">File path or object of the image to load.</param>
 /// <param name="pixelMap">PixelMap to save.</param>
 /// <param name="flags">Bitmask of flags defining how the pixel map should be saved.</param>
 /// <returns>True if the save was successfull else false.</returns>
 protected abstract bool RequestSave(object path, PixelMap pixelMap, PixelMapSaveFlags flags);
Ejemplo n.º 16
0
 /// <summary>
 ///		Disposes of all resources used by this image.
 /// </summary>
 public void Dispose()
 {
     _fullPixelMap = null;
     if (_frames == null) return;
     for (int i = 0; i < _frames.Length; i++)
     {
         _frames[i] = null;
     }
     _frames = null;
 }
Ejemplo n.º 17
0
        /// <summary>
        ///		Initilizes a new image from a file.
        /// </summary>
        /// <param name="path">Memory location (or url) of image file to load.</param>
        public Image(object path, ImageFlags flags)
        {
            if ((path is PixelMap) == false)
            {
                if (path is string) _url = (string)path;
                _fullPixelMap = PixelMapFactory.LoadPixelMap(path);
            }
            else
                _fullPixelMap = (path as PixelMap).Copy();

            if (_fullPixelMap == null)
                return;

            PixelMap map = _fullPixelMap.Copy();
            map.Mask(GraphicsManager.ColorKey);
            _mask = GraphicsManager.ColorKey;

            _width = _fullPixelMap.Width;
            _height = _fullPixelMap.Height;
            _flags = flags;

            _frames[0] = GraphicsManager.CreateImageFrame(map);

            // Are we dynamic? If not we don't need the full pixelmaps data so lets destroy it and
            // free up a bit of memory.
            if ((_flags & ImageFlags.Dynamic) == 0 && _fullPixelMap != null)
            {
               _fullPixelMap.Data = null;

                 _frames[0].PixelMap.Data = null;

               //GC.Collect();
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        ///		Creates an copy of a specific area of this PixelMap and returns it.
        /// </summary>
        /// <param name="sectionX">Position on the x-axis to start copying from.</param>
        /// <param name="sectionY">Position on the y-axis to start copying from.</param>
        /// <param name="sectionWidth">Width of section to copy.</param>
        /// <param name="sectionHeight">Height of section to copy.</param>
        /// <returns>The newly copied PixelMap.</returns>
        public PixelMap Copy(int sectionX,int sectionY,int sectionWidth,int sectionHeight)
        {
            PixelMap pixelMap = new PixelMap(sectionWidth, sectionHeight);

            for (int x = 0; x < sectionWidth; x++)
                for (int y = 0; y < sectionHeight; y++)
                    pixelMap[x,y] = this[sectionX + x, sectionY + y];
                    //pixelMap.Data[x + (y * sectionWidth)] = _pixels[(x + sectionX) + ((y + sectionY) * _width)];

            return pixelMap;
        }