Beispiel #1
0
 private static long CalculateActualHash(string fileName)
 {
     using var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
     using var image      = PpmReader.ImageFromPpm(fileStream);
     ImagePipeline.FromImage(image).Webp(new WebpOptions(100, 100, true)).ToBuffer(out var actual);
     return(DifferenceHash.HashLong(actual));
 }
Beispiel #2
0
        public UserBrowserActivity()
        {
            IEnumerable <string> missingFolders = UserKnownFolders.Where(f => !Directory.Exists(f));

            if (missingFolders.Count() > 0)
            {
                Warn("The following folders do not exist and will not be monitored: {0}", missingFolders);
                UserKnownFolders.RemoveAll(f => !Directory.Exists(f));
            }
            if (UserKnownFolders.Count == 0)
            {
                Error("No directories to monitor.");
                Status = ApiStatus.FileNotFound;
                return;
            }

            Monitors.Add(new DirectoryChangesMonitor(UserKnownFolders.ToArray(),
                                                     BasicImageWildcardExtensions.ToArray(), this));

            List <IMonitor> browserWindowMonitors = new List <IMonitor>()
            {
                new AppWindowMonitor(this, "chrome"),
                new AppWindowMonitor(this, "firefox"),
                new AppWindowMonitor(this, "MicrosoftEdgeCP"),
            };

            Monitors.AddRange(browserWindowMonitors);

            Pipeline = new ImagePipeline(this);
            Status   = Pipeline.Status;
        }
        public void Should_Use_Default_Processors()
        {
            pipeline = new ImagePipeline(container, settings, logger.Object);

            Assert.IsInstanceOf<AssignHashProcessor>(pipeline[0]);
            Assert.IsInstanceOf<UrlAssignmentProcessor<ImageBundle>>(pipeline[1]);
        }
 public void SharpSharpBufferBuffer()
 {
     ImagePipeline
     .FromBuffer(buffer)
     .Resize(Width, Height)
     .ToBuffer(out var data);
 }
 public DifferenceHashBenchmark()
 {
     ImagePipeline
     .FromFile(TestFiles.InputJpg)
     .Png()
     .ToBuffer(out var b);
     buffer = b;
 }
 public void SharpSharp()
 {
     using var output = TestFiles.OutputJpg();
     ImagePipeline
     .FromBuffer(buffer)
     .Resize(Width, Height)
     .ToFile(output.Path);
 }
 public static void read_stream_write_buffer()
 {
     using var inputStream = new FileStream(TestFiles.InputJpg, FileMode.Open, FileAccess.Read);
     ImagePipeline
     .FromStream(inputStream)
     .TestActions()
     .ToBuffer(VerifyImageInfo, out _);
 }
 public void SharpSharpFileFile()
 {
     using var output = TestFiles.OutputJpg();
     ImagePipeline
     .FromFile(TestFiles.InputJpg)
     .Resize(Width, Height)
     .ToFile(output.Path);
 }
Beispiel #9
0
 private int GetFirstImageId(ImagePipeline pipe)
 {
     if (pipe.Color.HasImages)
     {
         return(pipe.Color.FirstImageId);
     }
     return(pipe.Alpha.FirstImageId);
 }
 public StatisticModel(ImageFramework.Model.Models models, DisplayModel display, int index)
 {
     this.models              = models;
     this.display             = display;
     pipe                     = this.models.Pipelines[index];
     pipe.PropertyChanged    += PipeOnPropertyChanged;
     display.PropertyChanged += DisplayOnPropertyChanged;
 }
 private void OnPipelineChanged(ImagePipeline pipe, PropertyChangedEventArgs e, int id)
 {
     switch (e.PropertyName)
     {
     case nameof(ImagePipeline.Image):
         currentView?.UpdateImage(id, pipe.Image);
         break;
     }
 }
 public static void read_stream_write_file()
 {
     using var inputStream = new FileStream(TestFiles.InputJpg, FileMode.Open, FileAccess.Read);
     using var outputFile  = TestFiles.OutputJpg();
     ImagePipeline
     .FromStream(inputStream)
     .TestActions()
     .ToFile(outputFile.Path, VerifyImageInfo);
 }
 public static void read_file_write_stream()
 {
     using var outputFile   = TestFiles.OutputJpg();
     using var outputStream = new FileStream(outputFile.Path, FileMode.Open, FileAccess.Write);
     ImagePipeline
     .FromFile(TestFiles.InputJpg)
     .TestActions()
     .ToStream(outputStream, VerifyImageInfo);
 }
        public static void read_buffer_write_stream()
        {
            var buffer = File.ReadAllBytes(TestFiles.InputJpg);

            using var outputFile   = TestFiles.OutputJpg();
            using var outputStream = new FileStream(outputFile.Path, FileMode.Open, FileAccess.Write);
            ImagePipeline
            .FromBuffer(buffer)
            .TestActions()
            .ToStream(outputStream, VerifyImageInfo);
        }
 private void PipelineFormulaOnPropertyChanged(ImagePipeline pipe, FormulaModel formula, PropertyChangedEventArgs e)
 {
     switch (e.PropertyName)
     {
     case nameof(FormulaModel.Converted):
         // verify if the new formula is still valid
         UpdateFormulaValidity(pipe, models.Images.NumImages);
         pipe.HasChanges = true;
         break;
     }
 }
Beispiel #16
0
        public StatisticViewModel(int index, ModelsEx models, StatisticsViewModel viewModel)
        {
            this.index     = index;
            this.models    = models;
            this.viewModel = viewModel;
            this.model     = models.Statistics[index];
            this.pipe      = models.Pipelines[index];

            viewModel.PropertyChanged += ViewModelOnPropertyChanged;
            model.PropertyChanged     += ModelOnPropertyChanged;
            pipe.PropertyChanged      += PipeOnPropertyChanged;
        }
Beispiel #17
0
        private static void Main()
        {
            ImagePipeline
            .FromFile(TestFiles.InputJpg)
            .Png()
            .ToBuffer(out var b);
            var hashLong  = DifferenceHash.HashLong(b);
            var hashShort = DifferenceHash.HashShort(b);

            Console.WriteLine(Reverse(Convert.ToString(hashLong, 2)));
            Console.WriteLine(Reverse(Convert.ToString(hashShort, 2)));
        }
Beispiel #18
0
        private static void Configure()
        {
            var compositeLoader = new CompositeImageLoader();

            compositeLoader.RegisterLoader(new BasicImageLoader());
            compositeLoader.RegisterLoader(new SvgImageLoader());
            compositeLoader.RegisterLoader(new NetpbmImageLoader());

            var compositeExporter = new CompositeImageExporter();

            compositeExporter.RegisterExporter(new BasicImageExporter());
            compositeExporter.RegisterExporter(new IconImageExporter());

            imagePipeline = new ImagePipeline(compositeLoader, compositeExporter);

            excelPipeline = new ExcelPipeline(new ClosedXMLExcelLoader(), new ExtensionBasedSeparatorCsvExporter());
        }
Beispiel #19
0
        public EquationViewModel(ModelsEx models, int imageId)
        {
            this.model             = models.Pipelines[imageId];
            this.statistics        = models.Statistics[imageId];
            this.models            = models;
            this.imageId           = imageId;
            this.Color             = new FormulaViewModel(model.Color, models.Images, this);
            this.Alpha             = new FormulaViewModel(model.Alpha, models.Images, this);
            Color.PropertyChanged += FormulaOnPropertyChanged;
            Alpha.PropertyChanged += FormulaOnPropertyChanged;

            this.useFilter = model.UseFilter;

            this.model.PropertyChanged           += ModelOnPropertyChanged;
            this.models.Display.PropertyChanged  += DisplayOnPropertyChanged;
            this.models.Settings.PropertyChanged += SettingsOnPropertyChanged;
            this.statistics.PropertyChanged      += StatisticsOnPropertyChanged;
        }
        private void PipelineOnPropertyChanged(ImagePipeline sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case nameof(ImagePipeline.HasChanges):
                if (sender.HasChanges)
                {
                    sender.ResetImage(models.TextureCache);
                }
                break;

            case nameof(ImagePipeline.IsValid):
                if (sender.IsValid && sender.HasChanges)
                {
                    // TODO shedule work?
                }
                break;
            }
        }
Beispiel #21
0
        public EquationViewModel(ModelsEx models, int imageId)
        {
            this.model             = models.Pipelines[imageId];
            this.statistics        = models.Statistics[imageId];
            this.models            = models;
            this.imageId           = imageId;
            this.Color             = new FormulaViewModel(model.Color, models.Images, this);
            this.Alpha             = new FormulaViewModel(model.Alpha, models.Images, this);
            Color.PropertyChanged += FormulaOnPropertyChanged;
            Alpha.PropertyChanged += FormulaOnPropertyChanged;

            this.useFilter = model.UseFilter;

            this.model.PropertyChanged           += ModelOnPropertyChanged;
            this.models.Display.PropertyChanged  += DisplayOnPropertyChanged;
            this.models.Settings.PropertyChanged += SettingsOnPropertyChanged;
            this.statistics.PropertyChanged      += StatisticsOnPropertyChanged;

            ToggleAlphaCommand      = new ActionCommand(() => AutoAlpha = !AutoAlpha);
            ToggleVisibilityCommand = new ActionCommand(() => IsVisible = !IsVisible);

            AdjustAlphaFormula();
        }
 private static ImagePipeline TestActions(this ImagePipeline imagePipeline) => imagePipeline.Resize(TestWidth, TestHeight).Jpeg();
 private void UpdateFormulaValidity(ImagePipeline pipe, int numImages)
 {
     pipe.IsValid = pipe.Color.MaxImageId < numImages && pipe.Alpha.MaxImageId < numImages;
 }
Beispiel #24
0
 private static ImagePipeline TestPipeline() =>
 ImagePipeline
 .FromFile(TestFiles.InputJpg)
 .Resize(320, 240);
Beispiel #25
0
 private static long CalculateExpectedHash(string fileName)
 {
     ImagePipeline.FromFile(fileName).Webp(new WebpOptions(100, 100, true)).ToBuffer(out var expected);
     return(DifferenceHash.HashLong(expected));
 }