public ImageDifferenceResultEnum TryCalculateCombinedDifference(byte differenceThreshold) { if (this.CurrentDifferenceState != ImageDifferenceEnum.Combined) { return(ImageDifferenceResultEnum.NotCalculable); } // We need three valid images: the current one, the previous one, and the next one. if (this.Current == null || this.Current.IsVideo || this.Current.IsDisplayable(this.Database.FolderPath) == false) { this.CurrentDifferenceState = ImageDifferenceEnum.Unaltered; return(ImageDifferenceResultEnum.CurrentImageNotAvailable); } if (this.TryGetPreviousBitmapAsWriteable(out WriteableBitmap previousBitmap) == false) { return(ImageDifferenceResultEnum.PreviousImageNotAvailable); } if (this.TryGetNextBitmapAsWriteable(out WriteableBitmap nextBitmap) == false) { return(ImageDifferenceResultEnum.NextImageNotAvailable); } WriteableBitmap unalteredBitmap = this.differenceBitmapCache[ImageDifferenceEnum.Unaltered].AsWriteable(); this.differenceBitmapCache[ImageDifferenceEnum.Unaltered] = unalteredBitmap; // all three images are available, so calculate and cache difference BitmapSource differenceBitmap = unalteredBitmap.CombinedDifference(previousBitmap, nextBitmap, differenceThreshold); this.differenceBitmapCache[ImageDifferenceEnum.Combined] = differenceBitmap; return(differenceBitmap != null ? ImageDifferenceResultEnum.Success : ImageDifferenceResultEnum.NotCalculable); }
public ImageCache(FileDatabase fileDatabase) : base(fileDatabase) { this.TryMoveToFile(Constant.DatabaseValues.InvalidRow); this.CurrentDifferenceState = ImageDifferenceEnum.Unaltered; this.differenceBitmapCache = new Dictionary <ImageDifferenceEnum, BitmapSource>(); this.mostRecentlyUsedIDs = new RecencyOrderedList <long>(Constant.ImageValues.BitmapCacheSize); this.prefetechesByID = new ConcurrentDictionary <long, Task>(); this.unalteredBitmapsByID = new ConcurrentDictionary <long, BitmapSource>(); }
public void MoveToNextStateInPreviousNextDifferenceCycle() { // If we are looking at the combined differenced image, then always go to the unaltered image. if (this.CurrentDifferenceState == ImageDifferenceEnum.Combined) { this.CurrentDifferenceState = ImageDifferenceEnum.Unaltered; return; } // If the current image is marked as corrupted, we will only show the original (replacement) image if (!this.Current.IsDisplayable(this.Database.FolderPath)) { this.CurrentDifferenceState = ImageDifferenceEnum.Unaltered; return; } else { // We are going around in a cycle, so go back to the beginning if we are at the end of it. this.CurrentDifferenceState = (this.CurrentDifferenceState >= ImageDifferenceEnum.Next) ? ImageDifferenceEnum.Previous : ++this.CurrentDifferenceState; } // Because we can always display the unaltered image, we don't have to do any more tests if that is the current one in the cyle if (this.CurrentDifferenceState == ImageDifferenceEnum.Unaltered) { return; } // We can't actually show the previous or next image differencing if we are on the first or last image in the set respectively // Nor can we do it if the next image in the sequence is a corrupted one. // If that is the case, skip to the next one in the sequence if (this.CurrentDifferenceState == ImageDifferenceEnum.Previous && this.CurrentRow == 0) { // Already at the beginning this.MoveToNextStateInPreviousNextDifferenceCycle(); } else if (this.CurrentDifferenceState == ImageDifferenceEnum.Next && this.CurrentRow == this.Database.CountAllCurrentlySelectedFiles - 1) { // Already at the end this.MoveToNextStateInPreviousNextDifferenceCycle(); } else if (this.CurrentDifferenceState == ImageDifferenceEnum.Next && !this.Database.IsFileDisplayable(this.CurrentRow + 1)) { // Can't use the next image as its corrupted this.MoveToNextStateInPreviousNextDifferenceCycle(); } else if (this.CurrentDifferenceState == ImageDifferenceEnum.Previous && !this.Database.IsFileDisplayable(this.CurrentRow - 1)) { // Can't use the previous image as its corrupted this.MoveToNextStateInPreviousNextDifferenceCycle(); } }
public void MoveToNextStateInCombinedDifferenceCycle() { // if this method and MoveToNextStateInPreviousNextDifferenceCycle() returned bool they'd be consistent MoveNext() and MovePrevious() // however, there's no way for them to fail and there's not value in always returning true if (this.CurrentDifferenceState == ImageDifferenceEnum.Next || this.CurrentDifferenceState == ImageDifferenceEnum.Previous || this.CurrentDifferenceState == ImageDifferenceEnum.Combined) { this.CurrentDifferenceState = ImageDifferenceEnum.Unaltered; } else { this.CurrentDifferenceState = ImageDifferenceEnum.Combined; } }
public ImageDifferenceResultEnum TryCalculateDifference() { if (this.Current == null || this.Current.IsVideo || this.Current.IsDisplayable(this.Database.FolderPath) == false) { this.CurrentDifferenceState = ImageDifferenceEnum.Unaltered; return(ImageDifferenceResultEnum.CurrentImageNotAvailable); } // determine which image to use for differencing WriteableBitmap comparisonBitmap; if (this.CurrentDifferenceState == ImageDifferenceEnum.Previous) { if (this.TryGetPreviousBitmapAsWriteable(out comparisonBitmap) == false) { return(ImageDifferenceResultEnum.PreviousImageNotAvailable); } } else if (this.CurrentDifferenceState == ImageDifferenceEnum.Next) { if (this.TryGetNextBitmapAsWriteable(out comparisonBitmap) == false) { return(ImageDifferenceResultEnum.NextImageNotAvailable); } } else { return(ImageDifferenceResultEnum.NotCalculable); } WriteableBitmap unalteredBitmap = this.differenceBitmapCache[ImageDifferenceEnum.Unaltered].AsWriteable(); this.differenceBitmapCache[ImageDifferenceEnum.Unaltered] = unalteredBitmap; BitmapSource differenceBitmap = unalteredBitmap.Subtract(comparisonBitmap); this.differenceBitmapCache[this.CurrentDifferenceState] = differenceBitmap; return(differenceBitmap != null ? ImageDifferenceResultEnum.Success : ImageDifferenceResultEnum.NotCalculable); }