SetBuffer() protected method

protected SetBuffer ( byte newBuffer ) : void
newBuffer byte
return void
示例#1
0
        /// <summary>
        ///    Loads an image from a stream.
        /// </summary>
        /// <remarks>
        ///    This method allows loading an image from a stream, which is helpful for when
        ///    images are being decompressed from an archive into a stream, which needs to be
        ///    loaded as is.
        /// </remarks>
        /// <param name="stream">Stream serving as the data source.</param>
        /// <param name="type">
        ///    Type (i.e. file format) of image.  Used to decide which image decompression codec to use.
        /// </param>
        public static Image FromStream(Stream stream, string type)
        {
            // find the codec for this file type
            ICodec codec = CodecManager.Instance.GetCodec(type);

            MemoryStream decoded = new MemoryStream();

            ImageCodec.ImageData data = (ImageCodec.ImageData)codec.Decode(stream, decoded);

            Image image = new Image();

            // copy the image data
            image.height     = data.height;
            image.width      = data.width;
            image.depth      = data.depth;
            image.format     = data.format;
            image.flags      = data.flags;
            image.numMipMaps = data.numMipMaps;

            // stuff the image data into an array
            byte[] buffer = new byte[decoded.Length];
            decoded.Position = 0;
            decoded.Read(buffer, 0, buffer.Length);
            decoded.Close();

            image.SetBuffer(buffer);

            return(image);
        }
示例#2
0
        /// <summary>
        ///    Loads raw image data from a byte array.
        /// </summary>
        /// <param name="buffer">Raw image buffer.</param>
        /// <param name="width">Width of this image data (in pixels).</param>
        /// <param name="height">Height of this image data (in pixels).</param>
        /// <param name="format">Pixel format used in this texture.</param>
        /// <returns>A new instance of Image containing the raw data supplied.</returns>
        public static Image FromDynamicImage(byte[] buffer, int width, int height, int depth, PixelFormat format)
        {
            Image image = new Image();

            image.width  = width;
            image.height = height;
            image.depth  = depth;
            image.format = format;
            image.size   = width * height * depth * PixelUtil.GetNumElemBytes(format);
            image.SetBuffer(buffer);

            return(image);
        }
示例#3
0
        /// <summary>
        ///    Loads an image file from the file system.
        /// </summary>
        /// <param name="fileName">Full path to the image file on disk.</param>
        public static Image FromFile(string fileName)
        {
            int pos = fileName.LastIndexOf(".");

            if (pos == -1)
            {
                throw new AxiomException("Unable to load image file '{0}' due to invalid extension.", fileName);
            }

            // grab the extension from the filename
            string ext = fileName.Substring(pos + 1, fileName.Length - pos - 1);

            // find a registered codec for this type
            ICodec codec = CodecManager.Instance.GetCodec(ext);

            // TODO: Need ArchiveManager
            Stream       encoded = ResourceManager.FindCommonResourceData(fileName);
            MemoryStream decoded = new MemoryStream();

            // decode the image data
            ImageCodec.ImageData data = (ImageCodec.ImageData)codec.Decode(encoded, decoded);

            Image image = new Image();

            // copy the image data
            image.height     = data.height;
            image.width      = data.width;
            image.depth      = data.depth;
            image.format     = data.format;
            image.flags      = data.flags;
            image.numMipMaps = data.numMipMaps;

            // stuff the image data into an array
            byte[] buffer = new byte[decoded.Length];
            decoded.Position = 0;
            decoded.Read(buffer, 0, buffer.Length);
            decoded.Close();

            image.SetBuffer(buffer);

            return(image);
        }
示例#4
0
        /// <summary>
        ///    Loads an image from a stream.
        /// </summary>
        /// <remarks>
        ///    This method allows loading an image from a stream, which is helpful for when
        ///    images are being decompressed from an archive into a stream, which needs to be
        ///    loaded as is.
        /// </remarks>
        /// <param name="stream">Stream serving as the data source.</param>
        /// <param name="type">
        ///    Type (i.e. file format) of image.  Used to decide which image decompression codec to use.
        /// </param>
        public static Image FromStream(Stream stream, string type)
        {
            // find the codec for this file type
            ICodec codec = CodecManager.Instance.GetCodec(type);

            MemoryStream decoded = new MemoryStream();

            ImageCodec.ImageData data = (ImageCodec.ImageData)codec.Decode(stream, decoded);

            Image image = new Image();

            // copy the image data
            image.height = data.height;
            image.width = data.width;
            image.depth = data.depth;
            image.format = data.format;
            image.flags = data.flags;
            image.numMipMaps = data.numMipMaps;

            // stuff the image data into an array
            byte[] buffer = new byte[decoded.Length];
            decoded.Position = 0;
            decoded.Read(buffer, 0, buffer.Length);
            decoded.Close();

            image.SetBuffer(buffer);

            return image;
        }
示例#5
0
        /// <summary>
        ///    Loads an image file from the file system.
        /// </summary>
        /// <param name="fileName">Full path to the image file on disk.</param>
        public static Image FromFile(string fileName)
        {
            int pos = fileName.LastIndexOf(".");

            if(pos == -1) {
                throw new AxiomException("Unable to load image file '{0}' due to invalid extension.", fileName);
            }

            // grab the extension from the filename
            string ext = fileName.Substring(pos + 1, fileName.Length - pos - 1);

            // find a registered codec for this type
            ICodec codec = CodecManager.Instance.GetCodec(ext);

            // TODO: Need ArchiveManager
            Stream encoded = ResourceManager.FindCommonResourceData(fileName);
            MemoryStream decoded = new MemoryStream();

            // decode the image data
            ImageCodec.ImageData data = (ImageCodec.ImageData)codec.Decode(encoded, decoded);

            Image image = new Image();

            // copy the image data
            image.height = data.height;
            image.width = data.width;
            image.depth = data.depth;
            image.format = data.format;
            image.flags = data.flags;
            image.numMipMaps = data.numMipMaps;

            // stuff the image data into an array
            byte[] buffer = new byte[decoded.Length];
            decoded.Position = 0;
            decoded.Read(buffer, 0, buffer.Length);
            decoded.Close();

            image.SetBuffer(buffer);

            return image;
        }
示例#6
0
        /// <summary>
        ///    Loads raw image data from a byte array.
        /// </summary>
        /// <param name="buffer">Raw image buffer.</param>
        /// <param name="width">Width of this image data (in pixels).</param>
        /// <param name="height">Height of this image data (in pixels).</param>
        /// <param name="format">Pixel format used in this texture.</param>
        /// <returns>A new instance of Image containing the raw data supplied.</returns>
        public static Image FromDynamicImage(byte[] buffer, int width, int height, int depth, PixelFormat format)
        {
            Image image = new Image();

            image.width = width;
            image.height = height;
            image.depth = depth;
            image.format = format;
            image.size = width * height * depth * PixelUtil.GetNumElemBytes(format);
            image.SetBuffer(buffer);

            return image;
        }
示例#7
0
		/// <summary>
		///    Loads an image file from the file system.
		/// </summary>
		/// <param name="fileName">Full path to the image file on disk.</param>
		public static Image FromFile( string fileName )
		{
			Contract.RequiresNotEmpty( fileName, "fileName" );

			int pos = fileName.LastIndexOf( "." );

			if ( pos == -1 )
			{
				throw new AxiomException( "Unable to load image file '{0}' due to missing extension.", fileName );
			}

			// grab the extension from the filename
			string ext = fileName.Substring( pos + 1, fileName.Length - pos - 1 );

			// find a registered codec for this type
			ICodec codec = CodecManager.Instance.GetCodec( ext );

			Stream encoded = ResourceGroupManager.Instance.OpenResource( fileName );
			if ( encoded == null )
			{
				throw new FileNotFoundException( fileName );
			}

			// decode the image data
			MemoryStream decoded = new MemoryStream();
			ImageCodec.ImageData data = (ImageCodec.ImageData)codec.Decode( encoded, decoded );
			encoded.Close();

			Image image = new Image();

			// copy the image data
			image.height = data.height;
			image.width = data.width;
			image.depth = data.depth;
			image.format = data.format;
			image.flags = data.flags;
			image.numMipMaps = data.numMipMaps;

			// stuff the image data into an array
			byte[] buffer = new byte[ decoded.Length ];
			decoded.Position = 0;
			decoded.Read( buffer, 0, buffer.Length );
			decoded.Close();

			image.SetBuffer( buffer );

			return image;
		}