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); }