[comp.sys.amiga.graphics] Bitmap data -> BOB data

dmeny@polyslo.CalPoly.EDU (David William Meny) (05/18/91)

   Hello, I am writing an Amiga program in C, using a custom bitmap to store
my graphics data.  I want to add a bob to the screen and I want it's image
data to taken from the bitmap (i.e., graphics from the screen).  I need to
do this many times during the execution of my program, and I do not know
what exactly will be on the screen each time I want to initialize a new bob,
so I can't use a IFF brush conversion program to do this externally.

	Both the bitmap and bob store the graphics in sequential bitplanes, but
the bitmap structure stores the graphics data in byte format, while the bob
stores it in word format.  I am having trouble converting the graphics from
the bitmap format to the bob data format; the Bob graphics resembles colorful
"garbage"!

   I have included a short excerpt from my conversion code.  If anybody can
show me where my problem lies, or show me an easier way to do what I want, it
would be very much appreciated!

   Thank you.                                       --> David W. Meny

******************************************************************************

WORD chip BobData[BOB_DEPTH*BOB_HEIGHT*BOB_WORD_WIDTH];

...

VOID Init_Bob(start_x, start_y)
USHORT start_x, start_y;
{
   register unsigned char depth;
   register USHORT        x, y;
   register UBYTE         msb, lsb;
            PLANEPTR      ptr;

   start_x = (USHORT) (start_x / 8);   /* get byte offset of start pos. */

   /* copy Bitmap graphics into Bob data */
   for (depth=0;depth<BOB_DEPTH;depth++)
   {
      /* get pointer to beginning of plane data */
      ptr = BM.Planes[depth];

      for (y = start_y; y < start_y + BOB_HEIGHT; y++)
      {
         for (x = start_x; x < start_x + (BOB_WIDTH/8); x += 2)
         {
            /* get first and second byte from bitmap data */
            msb = (UBYTE) *(ptr + (y*BITMAP_WIDTH/8) + x);
            lsb = (UBYTE) *(ptr + (y*BITMAP_WIDTH/8) + x + 1);

            /* convert to word and copy into bob data */
            BobData[depth*BOB_WORD_WIDTH*BOB_HEIGHT +
               ((y-start_y)*BOB_WORD_WIDTH) + ((x-start_x)/2)] =
               (WORD) (msb<<8 + lsb);
         }
      }
   }

   /* assign appropriate data to VSprite & Bob structures */
   ...
   /* load bob, etc... */     
   ...
}