Convert Bitplanes to Chunky pixels

Started by kevin, May 04, 2013, 12:30:33 PM

Previous topic - Next topic

kevin

 Convert Bitplanes to Chunky pixels

    This snippet shows a simple (but fairly slow) method of converting groups of 16bits of bit plane data into chunky pixels.   This can handy when converting  planar formatted images that were used in many legacy platforms such as Amiga/Atari ST.  

     The example code assume the planes are in order from lowest to highest power.   Four bit planes are used in the example code for simplicity.


PlayBASIC Code: [Select]
   Dim Chunky_Pixels(16)

print ""
print "Convert 16 pixels of 4 bit Planar To Chunky"

Planar_To_Chunky(4)


print ""
print "Resulting chunky pixels"

For lp=0 to 15
print Chunky_Pixels(lp)
next

sync
waitkey





Psub Planar_To_Chunky(Planes)
; --------------------------------------------
;
; --------------------------------------------
ClearArray Chunky_Pixels(),0

Shift=1
For Power=1 to Planes
ThisWord=ReadData()
print "Bitplane["+str$(Power)+"] = "+Right$(bin$(ThisWord),16)
For bitlp=15 to 0 step -1
ThisBit=ThisWord and 1
Chunky_Pixels(Bitlp) |= ThisBit*Shift
ThisWord/=2
next
Shift*=2
next

EndPsub

; The mock up bitplane data for a 16 pixel run of 4 colour bitplane data.


Data %0101010101010101 ; Bitplane 0
Data %0011001100110011 ; Bitplane 1
Data %0000111100001111 ; Bitplane 2
Data %0000000011111111 ; Bitplane 3





What's a Bit plane ?

    it might come as shock, but computers use many different ways of storing the information that makes up the images/pictures we see.    Back in the 16/32bit days, bit plane graphics were the method most commonly used.    Unlike 8bit chunky pixel formats found in the VGA/SVGA hardware on the PC for example,  where each byte represents a single pixel (256 possible of colours).   In planar formats the bits are rotated 90 degrees.    So an 8bit pixel is spread across 8 bytes.    Where each bit represents a part of a pixel,  that  can be stacked on to other planes.  


    8 pixels in 4 colour (2 bit) planar.  

   Bitplane 0:%01010101  
   Bitplane 1:%00110011

    So if we convert this to colour indexes, we'd get the following

       Colour Index:   0 ,1 , 2, 3, 0,1 ,2, 3


 
    Bitplanes allow the video hardware to reduce the memory overhead of the screen/image.  Allowing for it to display from 2 colour (1bit),  4 colour (2bit), 8 colour (3bit), 16 colour (4bit)... through to 256 colour (8bit).       So a 2 colour frame buffer of  planar is ((width*height)/8),  which is an 1/8 the size of the 8bit chunky.   4Bitplane is 1/2 the size of the 8bit chunky.    



Related Articles:

    * SPR File Decoder / Loader
    * C64 Styled Sprite Rendering Example
     * Amos To PlayBASIC conversion
     * IFF Pro (Convert Amiga IFF's To Bitmaps)