> Logan wrote:
>
> "You could just MemCmp()
> the whole entire pixel data, but there is no guarantee that there
> aren't unused bytes (or at least bits) between rows that might
> be filled with random garbage. (In other words, rowbytes doesn't
> necessarily equal 2 * bitmapwidth for all 16-bit bitmaps, and
> it certainly doesn't equal bitmapwidth / 2 for all 4-bit bitmaps,
> especially if bitmapwidth is an odd number!)"
Aryeh Teitelbaum wrote:
> I had a problem with bitmaps format storage .
> How can I know the line length if is it not constant ?
> There is any kind of compression used in bitmap storage ?
If you create the bitmap yourself with BmpRsrcCreate(), you can
tell it not to use compression. You can also tell it which pixel
format to use. For example:
bmp = BmpRsrcCreate (100, 100, 16, NULL, kDensityLow, pixelFormat565);
When you call this, the pixel format is 16-bits per pixel, with 5 for
red, 6 for green, and 5 for blue. Then you just need to call
BmpRsrcGetRowBytes() and BmpRsrcGetBits() (or their built-in
equivalents) to get at the pixel data.
If you do not use BmpRsrcCreate() (or you own code) to create a
bitmap and let the system create it for you instead, then it is
not safe to access the internals. There is no general way to
access the internals of any bitmaps, because newer version of
Palm OS may create some kind of bitmap that existing code may
not understand.
Having said that, let me answer your question more directly:
the only time the bitmap's line length will not be constant
is if the bitmap is using compression. But then it is not
practical to access the raw bitmap data without uncompressing.
However, if the bitmap is not compressed and if it was created
by BmpRsrcCreate(), then it is in a known format and the line
length IS a constant. However, in general, one might be
tempted to access the pixel data for point (X,Y) using the
following math:
// this is wrong
pointer = BmpGetBits (bmp) + (width * y + x) * bytesperpixel;
The reason this is wrong is that there may be padding between
the rows. For example, with 8-bit, it could be padded on word
boundaries to make copying easier or something. So, instead,
you must do something like this:
// this is better
BmpGetDimensions (bmp, NULL, NULL, rowbytes);
pointer = BmpGetBits (bmp) + (rowbytes * y + x) * bytesperpixel;
Of course, this formula only works if bytesperpixel is an integer!
It doesn't work for 1-bit, 2-bit, or 4-bit bitmaps!
- Logan
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/