[EMAIL PROTECTED] wrote:
> For me to compare both the bitmap can I not do something like this?

> const BYTE * pOldImage = (const BYTE *)BmpGetBits(currBitmap);
> const BYTE * pNewImage = (const BYTE *)BmpGetBits(g_prevBitmap);
> 
>       
>               for (I = 0; I < dataSize; ++I)
>               {
>                       if (*(pOldImage + I) != *(pNewImage + I))
>                               return true;//They have changed so return
>               
>               }

I am not sure whether that will work.  It probably will work, but
there is a reason it might not.

The reason is this:  the OS will tell you the number of bytes used
to store a row of pixel data for a bitmap (call it rowbytes), and
it will tell you the number of pixels in a row (width) and the number
of bytes per pixel (pixelsize).

Now, we can assume that rowbytes is never smaller than width * pixelsize.
If it were smaller, then the data would not fit!

But we cannot assume rowbytes is never larger than width * pixelsize.
If it were never larger, then why would the OS provide a separate
system call to find rowbytes?  Also, the OS may want the beginning
of each row to be word-aligned for performance reasons.  Or it may
not want that.  The trouble is, there are no guarantees.  All we
know is that rowbytes >= width * pixelsize.  We do not know for sure
that rowbytes == width * pixelsize.  (Or maybe there is some
guarantee, and I just do not know about it personally.)

Why does it matter?  Well, let's a take a concrete example to see
why it might matter.  Let's say you have a bitmap that is 9 pixels
wide, and the pixels are 8 bits (one byte) each.  And let's suppose
the OS makes rowbytes 10 for this bitmap, because (hypothetically)
it wants keep the rows word-aligned.  Then you have 9 bytes of
pixel data and one byte of, well, what exactly IS in that byte?
Is it always 0?  Is it garbage data?  Will it be the same in both
bitmaps if you try to compare them?  The trouble is, *if* that
byte exists, then I'm not sure *what* its value is going to be.

Unfortunately, it's a little more complicated than even that.  It's
possible to have two 16-bit bitmaps and have one with little-endian
pixel data (pixelFormat565LE) and one with big-endian data
(pixelFormat565).  And then there is the matter of compression;
two bitmaps might contain the same pixel data but use different
compression formats.

So, comparing the raw pixel data will not always give the correct
answer.  There are probably many situations (when the format is
very similar) where it will give the right answer, but I can't
say the code above is truly correct.  However, if all you're using
it for is to determine whether to refresh the screen, and it won't
hurt you to think two bitmaps are different when they are really
the same, the above code might be good enough.  I would, however,
replace your loop with "return MemCmp (pOldImage, pNewImage, dataSize);".
And I would also find dataSize for both bitmaps and return if it's
not the same, just in case one is larger than another.

  - Logan

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/

Reply via email to