Exemplo n.º 1
0
    public void WhenCreatingAnImageFromAnUnfoundPathThenThrowException()
    {
        string temporaryPath   = Path.GetTempPath();
        string invalidFilepath = temporaryPath + "\\Hi.jpg";

        Assert.Throws <FileNotFoundException>(() => Jpg.Load(invalidFilepath));
    }
Exemplo n.º 2
0
    public void WhenCreatingAnImageFromAFileTypeThatIsNotAnImageThenThrowException()
    {
        string temporaryPath   = Path.GetTempPath();
        string invalidFilepath = temporaryPath + "text.txt";

        Assert.Throws <FileNotFoundException>(() => Jpg.Load(invalidFilepath));
    }
Exemplo n.º 3
0
 public void WhenCropingAnJpgImageFromFileGiveACorrectCroppedImage()
 {
     //checking with cat image
     string filepath    = SaveEmbeddedResourceToFile(JpegCatLogicalName);
     Image  avatarImage = Jpg.Load(filepath);
     Image  newImage    = avatarImage.CircleCrop(0, 0);
 }
Exemplo n.º 4
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));
    }
Exemplo n.º 5
0
    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");
    }
Exemplo n.º 6
0
    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);
    }
Exemplo n.º 7
0
    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");
    }
Exemplo n.º 8
0
 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");
     }
 }
Exemplo n.º 9
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);
    }
Exemplo n.º 10
0
    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);
        }
    }
Exemplo n.º 11
0
    public void WhenWritingABlankCreatedJpegToAValidFileWriteToAValidFile()
    {
        Image emptyImage = Image.Create(10, 10);

        ValidateCreatedImage(emptyImage, 10, 10);
        string tempFilePath = Path.ChangeExtension(Path.GetTempFileName(), ".jpg");

        Jpg.WriteToFile(emptyImage, tempFilePath);
        File.Delete(tempFilePath);
    }
Exemplo n.º 12
0
    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);
    }
Exemplo n.º 13
0
    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);
    }
Exemplo n.º 14
0
    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);
        }
    }
Exemplo n.º 15
0
    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);
    }
Exemplo n.º 16
0
    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);
    }
Exemplo n.º 17
0
    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);
    }
Exemplo n.º 18
0
    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);
    }
Exemplo n.º 19
0
    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();
        }
    }
Exemplo n.º 20
0
    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);
    }
Exemplo n.º 21
0
    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);
    }
Exemplo n.º 22
0
    //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();
    }
Exemplo n.º 23
0
    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();
    }
Exemplo n.º 24
0
    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();
    }
Exemplo n.º 25
0
    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();
    }
Exemplo n.º 26
0
    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();
            }
        }
    }
Exemplo n.º 27
0
    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();
    }
Exemplo n.º 28
0
    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);
    }