Board index » cppbuilder » I am looking to compare 2 bitmaps to look for "changes" but...

I am looking to compare 2 bitmaps to look for "changes" but...

.. ive become a bit unstuck.  The idea is to find the minimum rectangle
bounding the changes.  so far my idea was:

Byte *ptrStored,*ptrTest;
for (int y = 0; y < Bitmap->Height; y++)
      {
      //  ptrStored=StoredBitmap->ScanLine[y];
        ptrTest=Bitmap->ScanLine[y];
        for (int x = 0; x < Bitmap->Width; x++)
           if(ptrStored[x]!=ptrTest[x])
            {
             if(y<Rect2.top) Rect2.top=y;
             if(y>Rect2.bottom) Rect2.bottom=y;
             if(x<Rect2.left) Rect2.left=x;
             if(x>Rect2.right) Rect2.right=x;
            }
      }

so I scan each line and compare the 2 elements.  If they are different then
I sotred the required results in a RECT.
I got the idea from Borlands help on scanline.  Unfortunately is doesnt work
as im not too sure exactly WHAT scanline returns.  Any ideas or possibly
easier methods?

Cheers

 

Re:I am looking to compare 2 bitmaps to look for "changes" but...


Ive since then had a bit of progress, Ive now changed the "scanlines" to :
 ptrTest=(BYTE *)Bitmap->ScanLine[y];

but the comparison still doesnt happen.
any ideas?

Re:I am looking to compare 2 bitmaps to look for "changes" but...


Quote
M Williams <lb...@hotmail.com> wrote in message news:3b569281$1_1@dnews...
> Ive since then had a bit of progress, Ive now changed the "scanlines" to :
>  ptrTest=(BYTE *)Bitmap->ScanLine[y];

> but the comparison still doesnt happen.
> any ideas?

The size of each element in the ScanLine (ie: each pixel) will depend on the
PixelFormat member of the TBitmap.  Assuming both bitmaps are off-screen,
you can force PixelFormat to a known value to make comparisons easier.  I'd
suggest pf32bit if the images aren't too huge.  That way you can do:

  for (int y = 0; y < bmp1.Height; y++)
    for (int x = 0; x < bmp1.Width; x++)
      if (((int*)bmp1->ScanLine[y])[x] != ((int*)bmp2->ScanLine[y])[x])
      {
        do something
      }

--
Corey Murtagh
The Electric Monk
"Quidquid latine dictum sit, altum viditur."

Re:I am looking to compare 2 bitmaps to look for "changes" but...


Hello...:)

Scanlines is slow. Try to find something to get bits out of the bitmaps,
then compare them like two memory tables.
Besides, remember (and You haven't told us) what kind of bitmaps You work
with - which is important in later stages. Tell more, I'll try to help (priv
maybe? ;)

Regards,

            Jerzy "Doom_" Zientkowski

Re:I am looking to compare 2 bitmaps to look for "changes" but...


Jerzy "Doom_" Zientkowski <d...@nospam.irc.pl> wrote in message
news:3b6d8cef_2@dnews...

Quote
> Hello...:)

> Scanlines is slow. Try to find something to get bits out of the bitmaps,
> then compare them like two memory tables.

Scanlines are only slow when you're writing to on-screen bitmaps (ie:
images, etc).  When reading from a memory bitmap they're about as quick as
you can get without going with API functions.  Using the API ::GetDIBits()
will grab the entire contents of the bitmap into a memory buffer if you give
it the right parms.

--
Corey Murtagh
The Electric Monk
"Quidquid latine dictum sit, altum viditur."

Other Threads