private static void PerformDuplicationDetection(ScanSettings settings)
        {
            List <string> actionFiles = settings.RootDirectory == null ? settings.FilesToScan : GetFiles(settings);

            foreach (var actionFile in actionFiles)
            {
                var           currentImage  = new MyImageInfo(actionFile);
                List <string> matchingFiles = manager.GetMatchingFilesToCompare(currentImage);
                foreach (var matchingFile in matchingFiles)
                {
                    var imi = new MyImageInfo(matchingFile);
                    if (ImageCompare.Comapre(currentImage, imi))
                    {
                        manager.SaveMatch(currentImage, imi);
                    }
                }
            }
        }
        private void Comapre(MyImageInfo other)
        {
            var thisfn  = FileName;
            var otherfn = other.FileName;

            bool      equals = true;
            Rectangle rect1  = new Rectangle(0, 0, iBitmap.Width, iBitmap.Height);
            Rectangle rect2  = new Rectangle(0, 0, other.iBitmap.Width, other.iBitmap.Height);

            if (rect1.Width == rect2.Width && rect1.Height == rect2.Height)
            {
                BitmapData bmpData1 = iBitmap.LockBits(rect1, ImageLockMode.ReadOnly, iBitmap.PixelFormat);
                BitmapData bmpData2 = other.iBitmap.LockBits(rect1, ImageLockMode.ReadOnly, other.iBitmap.PixelFormat);
                unsafe
                {
                    byte *ptr1  = (byte *)bmpData1.Scan0.ToPointer();
                    byte *ptr2  = (byte *)bmpData2.Scan0.ToPointer();
                    int   width = rect1.Width * 3; // for 24bpp pixel data
                    for (int y = 0; equals && y < rect1.Height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            if (*ptr1 != *ptr2)
                            {
                                equals = false;
                                break;
                            }
                            ptr1++;
                            ptr2++;
                        }
                        ptr1 += bmpData1.Stride - width;
                        ptr2 += bmpData2.Stride - width;
                    }
                }
                iBitmap.UnlockBits(bmpData1);
                other.iBitmap.UnlockBits(bmpData2);

                if (equals)
                {
                    Clones.Add(other);
                    other.Clones.Add(this);
                }
            }
        }
Esempio n. 3
0
        public static bool Comapre(MyImageInfo imageInfo1, MyImageInfo imageInfo2)
        {
            bool      equals = true;
            Rectangle rect1  = new Rectangle(0, 0, imageInfo1.iBitmap.Width, imageInfo1.iBitmap.Height);
            Rectangle rect2  = new Rectangle(0, 0, imageInfo2.iBitmap.Width, imageInfo2.iBitmap.Height);

            if (rect1.Width == rect2.Width && rect1.Height == rect2.Height)
            {
                BitmapData bmpData1 = imageInfo1.iBitmap.LockBits(rect1, ImageLockMode.ReadOnly, imageInfo1.iBitmap.PixelFormat);
                BitmapData bmpData2 = imageInfo2.iBitmap.LockBits(rect1, ImageLockMode.ReadOnly, imageInfo2.iBitmap.PixelFormat);
                unsafe
                {
                    byte *ptr1  = (byte *)bmpData1.Scan0.ToPointer();
                    byte *ptr2  = (byte *)bmpData2.Scan0.ToPointer();
                    int   width = rect1.Width * 3; // for 24bpp pixel data
                    for (int y = 0; equals && y < rect1.Height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            if (*ptr1 != *ptr2)
                            {
                                equals = false;
                                break;
                            }
                            ptr1++;
                            ptr2++;
                        }
                        ptr1 += bmpData1.Stride - width;
                        ptr2 += bmpData2.Stride - width;
                    }
                }
                imageInfo1.iBitmap.UnlockBits(bmpData1);
                imageInfo2.iBitmap.UnlockBits(bmpData2);
            }
            return(equals);
        }