At 10:47 AM 5/18/2004, you wrote:
Hi guys,
I am getting some stupid result with for loop! Can anyone please help me with this?
previewWidth = 320; previewHeight = 240;
for(UInt32 i=0;i<previewWidth*previewHeight;i++) { Red = bmpData[i] >> 11; Green = (bmpData[i] & (0x07e0))>>5; Blue = bmpData[i] & (0x001f); Avg = (Red+Green+Blue)/3;
grayedImage[i] = ((UInt8)Avg); }
The value of "i" outside this loop is 11,264 rather than 76,800. It doesn't go beyond 11,264 in the loop for value of "i";
If previewWidth and previewHeight are declared as 16-bit variables, the multiplication will be done using 16-bit math which will overflow. The incorrect value will then be promoted to 32-bits for the comparision against i.
Change the for line to
for(UInt32 i=0;i<(Int32)previewWidth*(Int32)previewHeight;i++)
and you should be fine.
-- Ben Combee, DTS technical lead, PalmSource, Inc. Read "Combee on Palm OS" at http://palmos.combee.net/
-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
