public void PackingTypeTest() { ImageAssembleBase target = new NonphotoIndexedAssemble(new WebGreaseContext(new WebGreaseConfiguration())); const SpritePackingType expected = SpritePackingType.Vertical; SpritePackingType actual = target.PackingType; Assert.AreEqual(expected, actual); }
internal static ImageMap AssembleImages(ReadOnlyCollection <InputImage> inputImages, SpritePackingType packingType, string assembleFileFolder, string mapFileName, string pngOptimizerToolCommand, bool dedup, IWebGreaseContext context, int?imagePadding = null, ImageAssemblyAnalysisLog imageAssemblyAnalysisLog = null, ImageType?forcedImageType = null) { // deduping is optional. CssPipelineTask already has deduping built into it, so it skips deduping in ImageAssembleTool. var inputImagesDeduped = dedup ? DedupImages(inputImages, context) : inputImages; var xmlMap = new ImageMap(mapFileName); Safe.LockFiles( inputImages.Select(ii => new FileInfo(ii.AbsoluteImagePath)).ToArray(), () => { var separatedLists = SeparateByImageType(inputImagesDeduped, forcedImageType); #if DEBUG foreach (ImageType imageType in Enum.GetValues(typeof(ImageType))) { Console.WriteLine(); Console.WriteLine(Enum.GetName(typeof(ImageType), imageType)); foreach (var entry in separatedLists[imageType]) { Console.WriteLine(entry.InputImage.OriginalImagePath); } } #endif var padding = imagePadding ?? DefaultPadding; var registeredAssemblers = RegisterAvailableAssemblers(context); List <BitmapContainer> separatedList = null; foreach (var registeredAssembler in registeredAssemblers) { var assembled = false; try { // Set Image orientation as passed registeredAssembler.PackingType = packingType; // Set Xml Image Xml Map registeredAssembler.ImageXmlMap = xmlMap; xmlMap.AppendPadding(padding.ToString(CultureInfo.InvariantCulture)); registeredAssembler.PaddingBetweenImages = padding; // Set PNG Optimizer tool path for PngAssemble registeredAssembler.OptimizerToolCommand = pngOptimizerToolCommand; // Assemble images of this type separatedList = separatedLists[registeredAssembler.Type]; if (separatedList.Any()) { // Set Assembled Image Name registeredAssembler.AssembleFileName = GenerateAssembleFileName(separatedList.Select(s => s.InputImage), assembleFileFolder) + registeredAssembler.DefaultExtension; assembled = registeredAssembler.Assemble(separatedList); } } finally { if (assembled) { foreach (var entry in separatedList) { if (entry.Bitmap != null) { if (imageAssemblyAnalysisLog != null) { imageAssemblyAnalysisLog.UpdateSpritedImage(registeredAssembler.Type, entry.InputImage.OriginalImagePath, registeredAssembler.AssembleFileName); } context.Cache.CurrentCacheSection.AddSourceDependency(entry.InputImage.AbsoluteImagePath); entry.Bitmap.Dispose(); } } } } } var notSupportedList = separatedLists[ImageType.NotSupported]; if (notSupportedList != null && notSupportedList.Count > 0) { var message = new StringBuilder("The following files were not assembled because their formats are not supported:"); foreach (var entry in notSupportedList) { message.Append(" " + entry.InputImage.OriginalImagePath); } #if DEBUG Console.WriteLine(message.ToString()); #endif throw new ImageAssembleException(message.ToString()); } }); return(xmlMap); }
/// <summary>Invokes Assemble method of appropriate Image Assembler depending upon /// the type of images to be Assembled.</summary> /// <param name="inputImages">List of InputImage</param> /// <param name="packingType">Image Packing Type(Horizontal/Vertical)</param> /// <param name="assembleFileFolder">folder path where the assembled file will be created.</param> /// <param name="pngOptimizerToolCommand">PNG Optimizer tool command</param> /// <param name="dedup">Remove duplicate images</param> /// <param name="context">The webgrease context</param> /// <param name="imagePadding">The image padding</param> /// <param name="imageAssemblyAnalysisLog">The image Assembly Analysis Log.</param> /// <param name="forcedImageType">The forced image type to override detection.</param> /// <returns>The <see cref="ImageMap"/>.</returns> internal static ImageMap AssembleImages(ReadOnlyCollection <InputImage> inputImages, SpritePackingType packingType, string assembleFileFolder, string pngOptimizerToolCommand, bool dedup, IWebGreaseContext context, int?imagePadding = null, ImageAssemblyAnalysisLog imageAssemblyAnalysisLog = null, ImageType?forcedImageType = null) { return(AssembleImages(inputImages, packingType, assembleFileFolder, null, pngOptimizerToolCommand, dedup, context, imagePadding, imageAssemblyAnalysisLog, forcedImageType)); }