@@ -83,7 +83,7 @@ public static List<Tuple<string, string, double>> GetSimilarity(
8383 Debug . WriteLine ( $ "GetHash: { hashTime } ms; CompareHash: { compareTime } ms") ;
8484
8585 // Sort by similarity
86- return tuples . OrderByDescending ( u => u . Item3 ) . ToList ( ) ;
86+ return tuples . OrderByDescending ( u => u . Item3 ) . ToList ( ) ; // TODO: seldom u=null.
8787 }
8888
8989 public enum HashEnum
@@ -124,7 +124,10 @@ where imageExtensions.Contains(file.Extension)
124124
125125 // Get hashes
126126 var imageHashPairs = new ConcurrentDictionary < string , string > ( ) ;
127- Parallel . ForEach ( imageNames , imageName =>
127+ Parallel . ForEach ( imageNames ,
128+ // TODO: Add performance limitation option
129+ //new ParallelOptions { MaxDegreeOfParallelism = Convert.ToInt32(Math.Ceiling((Environment.ProcessorCount * 0.5) * 1.0)) },
130+ imageName =>
128131 {
129132 string hash = hashMethod ( imageName ) ;
130133 if ( ! string . IsNullOrEmpty ( hash ) )
@@ -272,6 +275,8 @@ private static string GetPerceptualHash(string filename)
272275 g . DrawImage ( originalBmp , 0 , 0 , bmp . Width , bmp . Height ) ;
273276 }
274277
278+ originalBmp . Dispose ( ) ;
279+
275280 watch . Stop ( ) ;
276281 resizeImageTime = watch . ElapsedMilliseconds ;
277282 watch . Restart ( ) ;
@@ -299,8 +304,6 @@ private static string GetPerceptualHash(string filename)
299304 long imageMatrixTime = watch . ElapsedMilliseconds ;
300305 //Debug.WriteLine($"Original: {originalBmpTime,3}ms; Resize: {resizeImageTime,3}ms; Matrix: {imageMatrixTime}ms");
301306
302- originalBmp . Dispose ( ) ;
303-
304307 // Get mean gray
305308 grayMean = graySum / height / width ;
306309
0 commit comments