public void TestLoadDraw(ImageFileType sourceFormat) { Skip.If(sourceFormat == ImageFileType.Wmp, "no input image of this format."); Skip.If(sourceFormat == ImageFileType.Wmp || sourceFormat == ImageFileType.Tga, "TODO remove this when Load/Save methods are implemented for those types."); Skip.If(Platform.Type == PlatformType.Android && sourceFormat == ImageFileType.Tiff, "TODO remove this when Load/Save methods are implemented for this type."); PerformDrawTest( (game, context) => { game.TestName = $"{nameof(TestLoadDraw)}({sourceFormat})"; context.CommandList.Clear(context.CommandList.RenderTarget, new Color4(Color.Green).ToColorSpace(ColorSpace.Linear)); context.CommandList.Clear(context.CommandList.DepthStencilBuffer, DepthStencilClearOptions.DepthBuffer); var device = game.GraphicsDevice; var fileName = sourceFormat.ToFileExtension().Substring(1) + "Image"; var filePath = "ImageTypes/" + fileName; // Load an image from a file and dispose it. Texture texture; using (var inStream = game.Content.OpenAsStream(filePath, StreamFlags.None)) texture = Texture.Load(device, inStream, loadAsSRGB: true); game.GraphicsContext.DrawTexture(texture, BlendStates.AlphaBlend); }, GraphicsProfile.Level_9_1); }
public void TestLoadSave(ImageFileType sourceFormat) { if (Platform.Type == PlatformType.Android && ( sourceFormat == ImageFileType.Xenko || sourceFormat == ImageFileType.Dds || // TODO remove this when mipmap copy is supported on OpenGL by the engine. sourceFormat == ImageFileType.Tiff)) // TODO remove when the tiff format is supported on android. { Assert.Ignore(); } PerformTest( game => { var intermediateFormat = ImageFileType.Xenko; if (sourceFormat == ImageFileType.Wmp) // no input image of this format. { return; } if (sourceFormat == ImageFileType.Wmp || sourceFormat == ImageFileType.Tga) // TODO remove this when Load/Save methods are implemented for those types. { return; } var device = game.GraphicsDevice; var fileName = sourceFormat.ToFileExtension().Substring(1) + "Image"; var filePath = "ImageTypes/" + fileName; var testMemoryBefore = GC.GetTotalMemory(true); var clock = Stopwatch.StartNew(); // Load an image from a file and dispose it. Texture texture; using (var inStream = game.Content.OpenAsStream(filePath, StreamFlags.None)) texture = Texture.Load(device, inStream); var tempStream = new MemoryStream(); texture.Save(game.GraphicsContext.CommandList, tempStream, intermediateFormat); tempStream.Position = 0; texture.Dispose(); using (var inStream = game.Content.OpenAsStream(filePath, StreamFlags.None)) using (var originalImage = Image.Load(inStream)) { using (var textureImage = Image.Load(tempStream)) { TestImage.CompareImage(originalImage, textureImage, false, 0, fileName); } } tempStream.Dispose(); var time = clock.ElapsedMilliseconds; clock.Stop(); GC.Collect(); GC.WaitForPendingFinalizers(); var testMemoryAfter = GC.GetTotalMemory(true); Log.Info($"Test loading {fileName} GPU texture / saving to {intermediateFormat} and compare with original Memory {testMemoryAfter - testMemoryBefore} delta bytes, in {time}ms"); }, GraphicsProfile.Level_9_1); }
private void SaveAndCompareTexture(Image outputImage, string fileName, ImageFileType extension = ImageFileType.Png) { // save Directory.CreateDirectory(ImageOutputPath); outputImage.Save(new FileStream(ImageOutputPath + fileName + extension.ToFileExtension(), FileMode.Create), extension); // Compare using (var texTool = new TextureTool()) { var referenceImage = LoadImage(texTool, new UFile(GoldImagePath + "/" + fileName + extension.ToFileExtension())); Assert.True(CompareImages(outputImage, referenceImage), "The texture outputted differs from the gold image."); } }
private void ProcessFiles(Game game, ImageFileType sourceFormat, ImageFileType intermediateFormat) { var testMemoryBefore = GC.GetTotalMemory(true); Log.Info($"Testing {intermediateFormat}"); Console.Out.Flush(); var imageCount = 0; var clock = Stopwatch.StartNew(); // Load an image from a file and dispose it. var fileName = sourceFormat.ToFileExtension().Substring(1) + "Image"; var filePath = "ImageTypes/" + fileName; Image image; using (var inStream = game.Content.OpenAsStream(filePath, StreamFlags.None)) image = Image.Load(inStream); image.Dispose(); // Load an image from a buffer byte[] buffer; using (var inStream = game.Content.OpenAsStream(filePath, StreamFlags.None)) { var bufferSize = inStream.Length; buffer = new byte[bufferSize]; inStream.Read(buffer, 0, (int)bufferSize); } using (image = Image.Load(buffer)) { // Write this image to a memory stream using DDS format. var tempStream = new MemoryStream(); image.Save(tempStream, intermediateFormat); tempStream.Position = 0; // Save to a file on disk var extension = intermediateFormat.ToFileExtension(); using (var outStream = VirtualFileSystem.ApplicationCache.OpenStream(fileName + extension, VirtualFileMode.Create, VirtualFileAccess.Write)) image.Save(outStream, intermediateFormat); if (intermediateFormat == ImageFileType.Xenko || intermediateFormat == ImageFileType.Dds || (sourceFormat == intermediateFormat && intermediateFormat != ImageFileType.Gif)) // TODO: remove this when Giff compression/decompression is fixed { int allowSmallDifferences; switch (intermediateFormat) { case ImageFileType.Tiff: // TODO: remove this when tiff encryption implementation is stable case ImageFileType.Png: // TODO: remove this when png encryption implementation is stable allowSmallDifferences = 1; break; case ImageFileType.Jpg: // TODO: remove this when jepg encryption implementation is stable allowSmallDifferences = 30; break; default: allowSmallDifferences = 0; break; } // Reload the image from the memory stream. var image2 = Image.Load(tempStream); CompareImage(image, image2, false, allowSmallDifferences, fileName); image2.Dispose(); } } imageCount++; var time = clock.ElapsedMilliseconds; clock.Stop(); GC.Collect(); GC.WaitForPendingFinalizers(); var testMemoryAfter = GC.GetTotalMemory(true); Log.Info($"Loaded {imageCount} and convert to (Dds, Jpg, Png, Gif, Bmp, Tiff) image from DirectXSDK test Memory: {testMemoryAfter - testMemoryBefore} bytes, in {time}ms"); }
private void SaveAndCompareTexture(Image outputImage, string fileName, ImageFileType extension = ImageFileType.Png) { // save Directory.CreateDirectory(ImageOutputPath); outputImage.Save(new FileStream(ImageOutputPath + fileName + extension.ToFileExtension(), FileMode.Create), extension); // Compare using(var texTool = new TextureTool()) { var referenceImage = LoadImage(texTool, new UFile(GoldImagePath + "/" + fileName + extension.ToFileExtension())); Assert.IsTrue(CompareImages(outputImage, referenceImage), "The texture outputted differs from the gold image."); } }
private void ProcessFiles(Game game, ImageFileType sourceFormat, ImageFileType intermediateFormat) { Log.Info("Testing {0}", intermediateFormat); Console.Out.Flush(); var imageCount = 0; var clock = Stopwatch.StartNew(); // Load an image from a file and dispose it. var fileName = sourceFormat.ToFileExtension().Substring(1) + "Image"; var filePath = "ImageTypes/" + fileName; Image image; using (var inStream = game.Asset.OpenAsStream(filePath, StreamFlags.None)) image = Image.Load(inStream); image.Dispose(); // Load an image from a buffer byte[] buffer; using (var inStream = game.Asset.OpenAsStream(filePath, StreamFlags.None)) { var bufferSize = inStream.Length; buffer = new byte[bufferSize]; inStream.Read(buffer, 0, (int)bufferSize); } using (image = Image.Load(buffer)) { // Write this image to a memory stream using DDS format. var tempStream = new MemoryStream(); image.Save(tempStream, intermediateFormat); tempStream.Position = 0; // Save to a file on disk var extension = intermediateFormat.ToFileExtension(); using (var outStream = VirtualFileSystem.ApplicationCache.OpenStream(fileName + extension, VirtualFileMode.Create, VirtualFileAccess.Write)) image.Save(outStream, intermediateFormat); if (intermediateFormat == ImageFileType.Xenko || intermediateFormat == ImageFileType.Dds || (sourceFormat == intermediateFormat && intermediateFormat != ImageFileType.Gif)) // TODO: remove this when Giff compression/decompression is fixed { int allowSmallDifferences; switch (intermediateFormat) { case ImageFileType.Tiff:// TODO: remove this when tiff encryption implementation is stable case ImageFileType.Png: // TODO: remove this when png encryption implementation is stable allowSmallDifferences = 1; break; case ImageFileType.Jpg: // TODO: remove this when jepg encryption implementation is stable allowSmallDifferences = 30; break; default: allowSmallDifferences = 0; break; } // Reload the image from the memory stream. var image2 = Image.Load(tempStream); CompareImage(image, image2, false, allowSmallDifferences, fileName); image2.Dispose(); } } imageCount++; var time = clock.ElapsedMilliseconds; clock.Stop(); GC.Collect(); GC.WaitForPendingFinalizers(); var testMemoryAfter = GC.GetTotalMemory(true); Log.Info("Loaded {0} and convert to (Dds, Jpg, Png, Gif, Bmp, Tiff) image from DirectXSDK test Memory: {1} bytes, in {2}ms", imageCount, testMemoryAfter - testMemoryBefore, time); }