public void WhenCreatingAnImageFromAnUnfoundPathThenThrowException() { string temporaryPath = Path.GetTempPath(); string invalidFilepath = temporaryPath + "\\Hi.jpg"; Assert.Throws <FileNotFoundException>(() => Jpg.Load(invalidFilepath)); }
public void WhenCreatingAnImageFromAFileTypeThatIsNotAnImageThenThrowException() { string temporaryPath = Path.GetTempPath(); string invalidFilepath = temporaryPath + "text.txt"; Assert.Throws <FileNotFoundException>(() => Jpg.Load(invalidFilepath)); }
public void WhenCropingAnJpgImageFromFileGiveACorrectCroppedImage() { //checking with cat image string filepath = SaveEmbeddedResourceToFile(JpegCatLogicalName); Image avatarImage = Jpg.Load(filepath); Image newImage = avatarImage.CircleCrop(0, 0); }
public void WhenCreatingAJpegFromAMalformedPathThenThrowException() { //place holder string to demonstrate what would be the error case string temporaryPath = Path.GetTempPath(); string invalidFilepath = temporaryPath + "\\Hi.jpg"; Assert.Throws <FileNotFoundException>(() => Jpg.Load(invalidFilepath)); }
public void WhenCropingAnJpgImageFromFileGiveACorrectCroppedImage() { //checking with cat image string filepath = @"C:\Users\t-roblo\Pictures\PerfTestImages\jpgcat.jpg"; Image avatarImage = Jpg.Load(filepath); Image newImage = avatarImage.CircleCrop(); Png.WriteToFile(newImage, @"C:\Users\t-roblo\Pictures\jpgcatf.png"); }
private static void ValidateImageJpeg(Image img, string embeddedLogicalName) { Stream toCompare = typeof(GraphicsUnitTests).GetTypeInfo().Assembly.GetManifestResourceStream(embeddedLogicalName); Image comparison = Jpg.Load(toCompare); Assert.Equal(comparison.HeightInPixels, img.HeightInPixels); Assert.Equal(comparison.WidthInPixels, img.WidthInPixels); Assert.Equal(comparison.TrueColor, img.TrueColor); }
public static void WhenAddingANegativeFilterToAJpegGiveAValidGreyScaledImage() { string filepath = SaveEmbeddedResourceToFile(SquareCatLogicalName); Image img1 = Jpg.Load(filepath); img1.ApplyMatrixMultiplier(ImageExtensions.NegativeMatrix); ValidateImageJpeg(img1, SquareCatLogicalName); Jpg.WriteToFile(img1, Path.GetTempPath() + "NegativeCat.jpg"); }
public void WhenCropingAnJpgImageFromFileStreamACorrectCroppedImage() { string filepath = SaveEmbeddedResourceToFile(JpegCatLogicalName); using (FileStream filestream = new FileStream(filepath, FileMode.Open)) { Image avatarImage = Jpg.Load(filestream); Image newImage = avatarImage.CircleCrop(0, 0); } }
public void WhenResizingJpegLoadedFromFileThenGiveAValidatedResizedImage() { //what to do? Have embedded resource stream of expected result? string filepath = SaveEmbeddedResourceToFile(SquareCatLogicalName); Image fromFileResizeSquare = Jpg.Load(filepath); fromFileResizeSquare = fromFileResizeSquare.Resize(200, 200); ValidateCreatedImage(fromFileResizeSquare, 200, 200); File.Delete(filepath); }
public void WhenCropingAnJpgImageFromFileStreamACorrectCroppedImage() { //checking with cat image using (FileStream filestream = new FileStream(@"C:\Users\t-roblo\Pictures\PerfTestImages\jpgcat.jpg", FileMode.Open)) { Image avatarImage = Jpg.Load(filestream); Image newImage = avatarImage.CircleCrop(); Png.WriteToFile(newImage, @"C:\Users\t-roblo\Pictures\jpgcats.png"); } }
public void WhenCreatingAJpegFromAValidStreamThenWriteAValidImageToFile() { string filepath = SaveEmbeddedResourceToFile(SoccerCatLogicalName); using (FileStream filestream = new FileStream(filepath, FileMode.Open)) { Image fromStream = Jpg.Load(filestream); ValidateImageJpeg(fromStream, SoccerCatLogicalName); } File.Delete(filepath); }
public void WhenCreatingAJpegFromAValidFileGiveAValidImage() { //save embedded resource to a file string filepath = SaveEmbeddedResourceToFile(SquareCatLogicalName); //read it Image newJpeg = Jpg.Load(filepath); File.Delete(filepath); //validate it ValidateImageJpeg(newJpeg, SquareCatLogicalName); }
public void WhenWritingABlankCreatedJpegToAValidStreamWriteToAValidStream() { Image img = Image.Create(100, 100); using (MemoryStream stream = new MemoryStream()) { Jpg.WriteToStream(img, stream); stream.Position = 0; Image img2 = Jpg.Load(stream); ValidateCreatedImage(img2, 100, 100); } }
public void WhenWritingAJpegCreatedFromFileToAValidFileWriteAValidImage() { string filepath = SaveEmbeddedResourceToFile(SquareCatLogicalName); Image fromFile = Jpg.Load(filepath); ValidateImageJpeg(fromFile, SquareCatLogicalName); string tempFilePath = Path.ChangeExtension(Path.GetTempFileName(), ".jpg"); Png.WriteToFile(fromFile, tempFilePath); File.Delete(filepath); File.Delete(tempFilePath); }
public void WhenResizingJpegLoadedFromStreamThenGiveAValidatedResizedImage() { string filepath = SaveEmbeddedResourceToFile(SoccerCatLogicalName); using (FileStream filestream = new FileStream(filepath, FileMode.Open)) { Image fromStream = Jpg.Load(filestream); fromStream = fromStream.Resize(400, 400); ValidateCreatedImage(fromStream, 400, 400); } File.Delete(filepath); }
public void WhenWritingAJpegFromFileToAValidStreamWriteAValidImage() { string filepath = SaveEmbeddedResourceToFile(SoccerCatLogicalName); Image img = Jpg.Load(filepath); using (MemoryStream stream = new MemoryStream()) { Jpg.WriteToStream(img, stream); stream.Position = 0; Image img2 = Jpg.Load(stream); ValidateImageJpeg(img2, SoccerCatLogicalName); } File.Delete(filepath); }
public void WhenDrawingAnImageWithTransparencyChangedGiveACorrectWrittenFile() { //black cat load string filepath = SaveEmbeddedResourceToFile(BlackCatLogicalName); Image blackCat = Jpg.Load(filepath); ValidateImagePng(blackCat, BlackCatLogicalName); blackCat.SetAlphaPercentage(0.5); //yellow cat load string filepath2 = SaveEmbeddedResourceToFile(SquareCatLogicalName); Image yellowCat = Jpg.Load(filepath2); ValidateImageJpeg(yellowCat, SquareCatLogicalName); yellowCat.Draw(blackCat, 0, 0); ValidateImageJpeg(yellowCat, SquareCatLogicalName); }
public void WhenWritingAResizedJpegToAValidStreamWriteAValidImage() { string filepath = SaveEmbeddedResourceToFile(SoccerCatLogicalName); Image img = Jpg.Load(filepath); using (MemoryStream stream = new MemoryStream()) { img = img.Resize(40, 40); ValidateCreatedImage(img, 40, 40); Jpg.WriteToStream(img, stream); stream.Position = 0; Image img2 = Jpg.Load(stream); ValidateCreatedImage(img, 40, 40); } File.Delete(filepath); }
private static void LoadFileJpegPerfTest(int numRuns) { for (int i = 0; i < numRuns; i++) { //make sure it's going if (i % 100 == 0) { Console.WriteLine("LoadFileJpegTest :" + i); } stopwatchSingleThread.Start(); Image img = Jpg.Load(jpegCatPath); stopwatchSingleThread.Stop(); img.ReleaseStruct(); } }
public void WhenDrawingTwoImagesWriteACorrectResult() { //open yellow cat image string filepath = SaveEmbeddedResourceToFile(SquareCatLogicalName); Image yellowCat = Jpg.Load(filepath); ValidateImageJpeg(yellowCat, SquareCatLogicalName); //open black cat image string filepath2 = SaveEmbeddedResourceToFile(BlackCatLogicalName); Image blackCat = Jpg.Load(filepath2); ValidateImagePng(blackCat, BlackCatLogicalName); //draw yellowCat.Draw(blackCat, 0, 0); ValidateImageJpeg(yellowCat, SquareCatLogicalName); File.Delete(filepath); File.Delete(filepath2); }
//FIX Write private static void WriteFileJpegPerfTest(int numRuns) { //string dir = Path.GetTempPath(); Image _thisjpgdog = Jpg.Load(jpegDogPath); for (int i = 0; i < numRuns; i++) { //make sure it's going if (i % 100 == 0) { Console.WriteLine("WriteFileJpegTest :" + i); } stopwatchSingleThread.Start(); Jpg.WriteToFile(_thisjpgdog, Path.ChangeExtension(Path.GetTempFileName(), ".jpg")); stopwatchSingleThread.Stop(); } _thisjpgdog.ReleaseStruct(); }
private static void ChangeAlphaJpegPerfTest(int numRuns) { Image _thisjpgcat = Jpg.Load(jpegCatPath); for (int i = 0; i < numRuns; i++) { //make sure it's going if (i % 100 == 0) { Console.WriteLine("ChangeAlphaJpegTest :" + i); } stopwatchSingleThread.Start(); _thisjpgcat.SetAlphaPercentage(0.5); stopwatchSingleThread.Stop(); } _thisjpgcat.ReleaseStruct(); }
private static void ResizeJpegPerfTest(int numRuns) { Image _thisjpgcat = Jpg.Load(jpegCatPath); for (int i = 0; i < numRuns; i++) { //make sure it's going if (i % 100 == 0) { Console.WriteLine("ResizeJpegTest :" + i); } stopwatchSingleThread.Start(); Image img = _thisjpgcat.Resize(100, 100); stopwatchSingleThread.Stop(); img.ReleaseStruct(); } _thisjpgcat.ReleaseStruct(); }
private static void LoadStreamJpegPerfTest(int numRuns) { for (int i = 0; i < numRuns; i++) { //make sure it's going if (i % 100 == 0) { Console.WriteLine("LoadStreamJpegTest :" + i); } using (FileStream filestream = new FileStream(jpegCatPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { stopwatchSingleThread.Start(); Image img = Jpg.Load(filestream); stopwatchSingleThread.Stop(); img.ReleaseStruct(); //filestream.Dispose(); } } }
private static void DrawPngOverJpegPerfTest(int numRuns) { Image _thisjpgdog = Jpg.Load(jpegDogPath); Image _thispngcat = Png.Load(pngCatPath); for (int i = 0; i < numRuns; i++) { //make sure it's going if (i % 100 == 0) { Console.WriteLine("DrawPngOverJpegTest :" + i); } stopwatchSingleThread.Start(); _thisjpgdog.Draw(_thispngcat, 10, 10); stopwatchSingleThread.Stop(); } _thisjpgdog.ReleaseStruct(); _thispngcat.ReleaseStruct(); }
private static void WriteStreamPngPerfTest(int numRuns) { Image _thispngcat = Jpg.Load(pngCatPath); for (int i = 0; i < numRuns; i++) { //make sure it's going if (i % 100 == 0) { Console.WriteLine("WriteStreamPngTest :" + i); } using (MemoryStream stream = new MemoryStream()) { stopwatchSingleThread.Start(); Png.WriteToStream(_thispngcat, stream); stopwatchSingleThread.Stop(); } } _thispngcat.ReleaseStruct(); }
public void WhenSettingTheTransparencyOfAnImageWriteAnImageWithChangedTransparency() { //open black cat image string filepath = SaveEmbeddedResourceToFile(BlackCatLogicalName); Image blackCat0 = Jpg.Load(filepath); ValidateImagePng(blackCat0, BlackCatLogicalName); blackCat0.SetAlphaPercentage(0); ValidateImagePng(blackCat0, BlackCatLogicalName); Image blackCat1 = Jpg.Load(filepath); ValidateImagePng(blackCat1, BlackCatLogicalName); blackCat0.SetAlphaPercentage(0.5); ValidateImagePng(blackCat1, BlackCatLogicalName); Image blackCat2 = Jpg.Load(filepath); ValidateImagePng(blackCat2, BlackCatLogicalName); blackCat0.SetAlphaPercentage(1); ValidateImagePng(blackCat2, BlackCatLogicalName); File.Delete(filepath); }