Erico Franco wrote:
I'm trying know to write the header and data stuff separated by using 3
dmwrite: one for header, other for data and the last for indirect bit:
I don't see how just writing those three pieces in succession could
possibly create a valid bitmap. Obviously, if the pixel data is
indirect, this means that the bitmap must have, somewhere inside it,
a pointer to the pixel data. (In fact, the documentation for the
BitmapFlagsType struct's "indirect" flag confirms this. It says,
"If true, the address to the bitmap's data is stored where the
bitmap itself would normally be stored. The actual bitmap data is
stored elsewhere.")
So, once you delete the original bitmap, this pointer will become
invalid and the bitmap will be invalid because it contains a bogus
pointer.
Therefore, if you want to just lock the resource and then draw the
bitmap, then an indirect bitmap will never be suitable for that,
because the resource will always have a pointer that would need to
be updated before the resource would be valid.
Furthermore, even if you wanted to update the pointer inside the
bitmap to make it valid again, you would be breaking the API's
contract by doing so. The documentation for BitmapTypeV3 has this
warning:
Bitmaps created by Palm OS are not guaranteed to adhere
to this structure; you cannot cast a bitmap created by
the Palm OS to this structure and expect to be able to
directly access the structure's fields.
In other words, the structures you see documented in the Bitmaps
chapter of the API docs are a *subset* of the set of valid bitmaps.
This means if you create one yourself following those structures,
then it would be valid. But it also means that if the system
creates one for you (as with BmpCreateBitmapV3(), for example,
since that's what pnoJpegLib uses if I remember right), then that
bitmap isn't guaranteed to conform.
So, in a case where you need to create a bitmap whose format is
known, the easiest thing to do is to use the BitmapRsrc code that
is in the knowledge base at kb.palmsource.com. That may not be
what pnoJpegLib does, but if so, that is a limitation of pnoJpegLib.
Of course, if you really want to do what you're trying to do
and you don't want to modify pnoJpegLib to do it, you could
do the following:
1. Create a bitmap with pnoJpegLib.
2. Create another bitmap with the BitmapRsrc routines,
making sure it's the same dimensions, same density,
and same pixel depth.
3. Wrap the second bitmap with a window by calling
WinCreateBitmapWindow().
4. Use WinDrawBitmap() to draw the first bitmap into
the window (and thus into the second bitmap).
5. Remove the window wrapper with WinDeleteWindow().
6. Delete the first bitmap.
7. Write the second bitmap into a resource.
Of course, that requires lots of temporary memory (two copies
of the bitmap's pixel data), but it should work...
- Logan
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/