DrawPaletteMappedStrip8 |
DrawPaletteMappedStrip8 Xpos, Ypos, Address, Length, Mask |
|
Parameters: Xpos = The output X coordinate of this strip of pixels Ypos = The output Y coordinate of this strip of pixels Address = The Address of the series of bytes to get the colour indexes from Length = Number of pixels / byte in this strip Mask = Mask to apply to the colour index before reading the palette.
|
Returns: NONE |
|
DrawPaletteMappedStrip8 reads a sequential run of bytes from memory and renders them out to the current surface using a user defined colour palette (SetPalette). So it treats each 8bit byte as the index to the palette array, where the palette contains an array of 32bit (ARGB) colours.
Using this command we can simulate a classic 8bit (256 colour) screen mode, and effects like raster bars, mirrors and glez vectors to name a few.
FACTS:
* Palette Mapping is used in a classic computer/game console display systems since it's very efficient way of storing images.
Example:
This following example creates a conceptual 256 colour screen in memory (in a PlayBASIC bank). The program the fills the conceptual screen with colour index byte values. These values are written to form a sinus arc (See SIN) ranging from 0 to 255, where and each row displaced by one pixel. Creating a sort of curved diagonal pattern. Each frame we colour cycle the 256 colour palette with all of the shades of the current random colour. So it appears to move, even though we never have to modify the pixel data once it's created.
|
|
Example Source: Download This Example // Include the palette Mapping library #Include "paletteMapping" // Define Dim Palette(256) SetPalette(Palette()) // ------------------------------------ // CReate a palette mapped Screen in memory // ------------------------------------ Width=800 Height=600 // Alloc a bank that we'll use as the screen ScreenBank=NewBank(Width*Height) // Fill the bank with colour values.. For ylp =0 To Height-1 // Compute the address of this strip RowAddress=GetBankPtr(ScreenBank)+Width*ylp // Fill this row of bytes with For Xlp=0 To Width-1 Pos=WrapValue(Xlp+ylp,0,Width) // Compute the colour index using sinus ColourIndex = Sin( (180.0/Width) *Pos)* 255 // copy it to the screen buffer PokeByte RowAddress+Xlp, ColourINdex Next Next ; Limit the program to 100 frames per second or less SetFPS 100 Do // ------------------------------------ // Pick the Palette main colour // ------------------------------------ If ScrollX=0 // pick a random colour that we'll use to seed the palette ThisColour =RndRGB() EndIf // ------------------------------------ // Fill the palette with all 256 shades // ------------------------------------ // fill the palette array with all the shades of thsi colour For lp =0 To 255 Pos=(ScrollX+lp) And 255 Palette(pos)=RgbAlphaMult(ThisColour,RGB(lp,lp,lp)) Next // offset the palette creation it's a little more interesting ScrollX=(ScrollX-2) And 255 // ----------------------------------------------------------- // Draw this 8bit palette mapped data to the actual screen // ----------------------------------------------------------- LockBuffer ; read a point from the output surface to make sure ; it's seeded for raw direct output rendering ThisRgb=Point(0,0) ; Run down the scan lines and draw them to the screen For ylp =0 To Height-1 // Compute the address of this strip RowAddress=GetBankPtr(ScreenBank)+Width*ylp DrawPaletteMappedStrip8(0,ylp,RowAddress,Width,255) Next UnLockBuffer Sync Loop EscKey()=true |
|