/// <summary>
        ///
        /// </summary>
        /// <param name="buildContext"></param>
        public override void Build(BuildContext buildContext)
        {
            var fileNames = buildContext.ExpandAndResolveSearchPatterns(Dependencies);
            var images    = fileNames
                            .Select(fn => Image.LoadTga(fn))
                            .OrderByDescending(img0 => img0.Width * img0.Height)
                            .ThenByDescending(img1 => img1.Width)
                            .ThenByDescending(img2 => img2.Height)
                            .ToList();

            if (!images.Any())
            {
                throw new InvalidOperationException("At least one subimage must be added to teh texture atlas");
            }


            //
            //	Pack atlas :
            //
            AtlasNode root = new AtlasNode(0, 0, Width, Height, Padding);

            foreach (var img in images)
            {
                var n = root.Insert(img);
                if (n == null)
                {
                    throw new InvalidOperationException("No enough room to place image");
                }
            }

            //
            //	Create image and fill it with atlas elements :
            //
            var targetImage = new Image(Width, Height);

            targetImage.Fill(FillColor);

            root.WriteImages(targetImage);

            //
            //	Save and compress :
            //
            var tgaOutput = buildContext.GetTempFileName(AssetPath, ".tga", true);
            var ddsOutput = buildContext.GetTempFileName(AssetPath, ".dds", true);

            Image.SaveTga(targetImage, tgaOutput);

            var compression = UseDXT ? ImageFileTextureAsset.TextureCompression.BC3 : ImageFileTextureAsset.TextureCompression.RGB;

            ImageFileTextureAsset.RunNVCompress(buildContext, tgaOutput, ddsOutput, NoMips, false, false, true, true, false, compression);


            //
            //	Write binary blob (text + dds texture):
            //
            using (var fs = buildContext.TargetStream(this)) {
                var bw = new BinaryWriter(fs);

                bw.Write(new[] { 'A', 'T', 'L', 'S' });
                bw.Write(images.Count);

                root.WriteLayout(bw);

                bw.Write((int)(new FileInfo(ddsOutput).Length));

                using (var dds = File.OpenRead(ddsOutput)) {
                    dds.CopyTo(fs);
                }
            }
        }
		/// <summary>
		/// 
		/// </summary>
		/// <param name="buildContext"></param>
		public override void Build ( BuildContext buildContext )
		{
			var fileNames	=	buildContext.ExpandAndResolveSearchPatterns( Dependencies );
			var images		=	fileNames
								.Select( fn => Image.LoadTga( fn ) )
								.OrderByDescending( img0 => img0.Width * img0.Height )
								.ThenByDescending( img1 => img1.Width )
								.ThenByDescending( img2 => img2.Height )
								.ToList();

			if (!images.Any()) {
				throw new InvalidOperationException("At least one subimage must be added to teh texture atlas");
			}


			//
			//	Pack atlas :
			//			
			AtlasNode root = new AtlasNode(0,0, Width, Height, Padding );

			foreach ( var img in images ) {
				var n = root.Insert( img );
				if (n==null) {
					throw new InvalidOperationException("No enough room to place image");
				}
			}

			//
			//	Create image and fill it with atlas elements :
			//	
			var targetImage	=	new Image( Width, Height );
			targetImage.Fill( FillColor );

			root.WriteImages( targetImage );

			//
			//	Save and compress :
			//
			var tgaOutput	=	buildContext.GetTempFileName( AssetPath, ".tga" );
			var ddsOutput	=	buildContext.GetTempFileName( AssetPath, ".dds" );
			Image.SaveTga( targetImage, tgaOutput );

			var compression =	UseDXT ? ImageFileTextureAsset.TextureCompression.BC3 : ImageFileTextureAsset.TextureCompression.RGB;
			ImageFileTextureAsset.RunNVCompress( buildContext, tgaOutput, ddsOutput, NoMips, false, false, true, true, false, compression );


			//
			//	Write binary blob (text + dds texture):
			//
			using ( var fs = buildContext.OpenTargetStream( this ) ) {
				var bw = new BinaryWriter( fs );

				bw.Write(new[]{'A','T','L','S'});
				bw.Write( images.Count ); 

				root.WriteLayout( bw );

				bw.Write( (int)(new FileInfo(ddsOutput).Length) );
				
				using ( var dds = File.OpenRead( ddsOutput ) ) {
					dds.CopyTo( fs );
				}
			}
		}