MFDB planes data into RGB 24bits

C and PASCAL (or any other high-level languages) in here please

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 11990
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

MFDB planes data into RGB 24bits

Postby wongck » Tue Mar 15, 2016 2:48 pm

I just cannot wrap my head around this....
I need to convert some image in MFDB structure into 24bit RGB image. The MFDB will be in VDI standard format.

My guess is I need to pick each corresponding bit in each plane and turn it into the index of colour look up table (CLUT), then figure our what that colour is and turn that into 24bits RBG data. This should be for each pixel.

I cannot figure out a code to do this. I am not good using C bit-wise ops.
Does anyone know of code fragment to do this?
Any docs ?
My Stuff: FB/Falcon CT63+CTPCI_ATI_RTL8139 14+512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

User avatar
dml
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 3472
Joined: Sat Jun 30, 2012 9:33 am

Re: MFDB planes data into RGB 24bits

Postby dml » Tue Mar 15, 2016 3:26 pm

Sorry I don't have time to test this quickly cobbled piece of code - so a big caution - but you probably want something like the code below. Assuming you want to convert a 4-plane VDI image with an arbitrary plane format, stored in Motorola/BigEndian order.

If the planes are stored separately, 'planestride' should be 1. If they are stored interleaved as they are on an ST screen, 'planestride' should be 4.

If it's being used on an Intel/ARM/LittleEndian host, then the plane words *might* be byte-swapped. In which case you'll need to un-swap them as they are fetched (This will be easy to spot because the output image will be correct but in fractured columns of 8 pixels).

If the image appears correct, but colours are wrong, the planes might be back-to-front. Just reverse the order.

The C fragment below just produces the 8-bit indexed colourmap from raw plane data. And no - it's not the fastest way to do it. But the idea should be clear. You'll need to convert to RGB by looking up each palette entry with each index. That's easy enough, but detail depends on how the palette is formatted so I didn't bother...

Code: Select all

typedef signed short s16;
typedef unsigned short u16;
typedef signed int s32;
typedef unsigned int u32;

void convert4PLToIndexed(s16 width, s16 height, u8 *indexmap, u16 *plane0, u16 *plane1, u16 *plane2, u16 *plane3, s16 planestride)
{
   u16 p0d, p1d, p2d, p3d;
   s16 pix, xw, xwsize;
   u16 bitmask;
   u8 index;

   xwsize = width>>4; /* display-word-width of source image */

   /* process all image lines */

   for (y = 0; y < height; y++)
   {
      /* process all display-words per image line */

      for (xw = 0; xw < xwsize; xw++)
      {
         p0d = *plane0; plane0 += planestride;
         p1d = *plane1; plane1 += planestride;
         p2d = *plane2; plane2 += planestride;
         p3d = *plane3; plane3 += planestride;

         /* process all planes of each display-word */

         bitmask = 0x8000;
         for (pix = 16-1; pix >= 0; pix—-)
         {
            /* create the index from the planes at bit position ‘bitmask’ */

            index  =  ((p3d & bitmask) >> pix); index <<= 1;
            index |= ((p2d & bitmask) >> pix); index <<= 1;
            index |= ((p1d & bitmask) >> pix); index <<= 1;
            index |= ((p0d & bitmask) >> pix);
            bitmask >>= 1;

            /* store the colour index */

            *indexmap++ = index;
         }
      }
   }
}

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 11990
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: MFDB planes data into RGB 24bits

Postby wongck » Tue Mar 15, 2016 11:48 pm

Thanks !! :)
I will try it out tonight.
My Stuff: FB/Falcon CT63+CTPCI_ATI_RTL8139 14+512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 11990
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: MFDB planes data into RGB 24bits

Postby wongck » Tue Mar 15, 2016 11:56 pm

Another question now, the MFDB structure has

Code: Select all

C-declaration:

typedef struct mfdb
{
   VOID *fd_addr;                /* Pointer to the start of the
                                    memory block, e.g. the
                                    screen memory base address  */
   WORD  fd_w;                   /* Width in pixels             */
   WORD  fd_h;                   /* Height in pixels            */
   WORD  fd_wdwidth;             /* Width of a line in words    */
   WORD  fd_stand;               /* 0 = Device-specific format  */
                                 /* 1 = Standard format         */
   WORD  fd_nplanes;             /* Number of planes            */
   WORD  fd_r1, fd_r2, fd_r3;    /* Reserved, must be 0         */
} MFDB;


The fd_addr holds the data, what is the formula to work out the beginning of each planes ?
fd_h * fd_wdwidth ?
My Stuff: FB/Falcon CT63+CTPCI_ATI_RTL8139 14+512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

User avatar
Anima
Atari Super Hero
Atari Super Hero
Posts: 654
Joined: Fri Mar 06, 2009 9:43 am
Contact:

Re: MFDB planes data into RGB 24bits

Postby Anima » Wed Mar 16, 2016 6:19 am

wongck wrote:The fd_addr holds the data, what is the formula to work out the beginning of each planes ?
fd_h * fd_wdwidth ?

The VDI standard raster format stores each plane in a contiguous memory block. So in order to feed the function with the contents of the MFDB I would alter some lines:

Code: Select all

typedef signed short s16;
typedef unsigned short u16;
typedef signed int s32;
typedef unsigned int u32;

void convertVdiBitmapToIndexed(MFDB *mfdb, u8 *indexmap)
{
   s16 y, xw;
   u16 bitmask;
   u8 index;
   u32 plane_offset;
   u16 plane_index;
   u16 *bitmap;
   u32 bitmap_increment;

   bitmap = (u16 *)(mfdb->fd_addr);
   bitmap_increment = mfdb->fd_stand ? 1 : mfdb->fd_nplanes;
   plane_offset = mfdb->fd_stand ? mfdb->fd_wdwidth * fd_wdwidth->fd_h : 1;

   for (y = 0; y < mfdb->fd_w; y++)
   {
      for (xw = 0; xw < mfdb->fd_wdwidth; xw++)
      {
         for(bitmask = 0x8000; bitmask; bitmask >>= 1)
         {
            index = 0;
           
            for(plane_index = mfdb->fd_nplanes - 1; plane_index >= 0; plane_index--)
            {
               index += index;

               if(bitmap[plane_offset * plane_index] & bitmask)
                  index += 1;
            }

            *indexmap++ = index;
         }
         
         bitmap += bitmap_increment;
      }
   }
}


Edit: bug fixing. ;)

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 11990
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: MFDB planes data into RGB 24bits

Postby wongck » Wed Mar 16, 2016 10:44 am

Thanks again !!!
:-)
My Stuff: FB/Falcon CT63+CTPCI_ATI_RTL8139 14+512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list


Social Media

     

Return to “C / PASCAL etc.”

Who is online

Users browsing this forum: No registered users and 2 guests