PaletteMapRGBImage
ColourCount = PaletteMapRGBImage(ThisImage, Palette(), [ColourCount=0])
 
Parameters:

    ThisImage = Index of image to convert RGB colours to Palette Indexes in
    Palette() = 1D array full of palette values (has to be at least 65536 in size)
    [ColourCount=0] = The number of colours in the palette. From 0 to colour Count
Returns:

    ColourCount = The size of the colour palette.
 

     The PaletteMapRGBImage function converts a conventional RGB formatted image, into a palette mapped form. The function runs through the source image and works out all the unique RGB colours, once it's built the unique colour list, it replaces the original RGB formatted pixels with the 16Bit colour index values in the image. Any colours that aren't found the existing palette, are merged at the end of the user supplied palette array also.

      Internally the image you supply PaletteMapRGBImage gets converted to a 16bit FX image using CreateFxImageEx, so PlayBASIC's graphic engine thinks it's just a regular image. This means we can draw this image onto other images that are palette mapped with the same palette also, just like normal RGB images. However, if we try draw an RGB image to the Palette mapped one (or vice versa), we'll get mess.



FACTS:


      * PaletteMapRGBImage creates 16bit FX image image maximum number of colours in the final palette

      * PaletteMapRGBImage colour index zero is assumed to be the transparent colour.

      * PaletteMapRGBImage can be used to create an custom image formats to the protect your programs media.


 
Example Source: Download This Example
  // Include the palette Mapping library
  #Include "PaletteMapping"
  
  
  // -----------------------------------------------------------------
  // -----------------------------------------------------------------
  // Set Up Palette >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  // -----------------------------------------------------------------
  // -----------------------------------------------------------------
  
  // Define a palette big enough to hold 2^16 colours
  Dim Palette($10000)
  
  // Give palette mapping library address of the palette
  // we're using.
  SetPalette(Palette())
  
  // Set Colour Index zero to rgb(0,0,0) BLACK
  Palette(0)     = RGB(0,0,0)
  
  // Set Colour as out 2 as
  Palette(1)     = RGB(30,40,50)
  
  // This number of colours currently in our palette
  ColourCount=2
  
  // Load the Ship image from the media folder to folders down
  ShipImage=LoadNewImage(ProgramDir$()+"Help/Commands/Media/ship.bmp")
  
  
  CenterText 250,80,"ORIGINAL RGB IMAGE"
  DrawImage ShipImage,200,100,false3
  
  // Convert the images normally RGB formated pixels into our
  // current palette
  ColourCount=PaletteMapRGBImage(ShipImage,Palette(), ColourCount)
  CenterText 600,80,"Palette Mapped IMAGE"
  CenterText 600,170,"Colour Count:"+Str$(ColourCount)
  
  DrawImage ShipImage,550,100,false
  
  
  
  Sync
  Wait 1000
  Wait 1000
  
  
  // -----------------------------------------------------------------
  // -----------------------------------------------------------------
  // Create a PB image we'll be using as the Palette Mapped Display
  // -----------------------------------------------------------------
  // -----------------------------------------------------------------
  Screen=NewPaletteMapImage(GetScreenWidth(),GetScreenHeight())
  
  
  Dim BackupPalette($10000)
  CopyArray Palette(),BackUpPalette()
  
  // Limit the program to 75 frames per second or less
  SetFPS 75
  
  
  Do
     
     // direct all Pb rendering to out screen image
     RenderToImage Screen
     
     
     // Fill The Screen with colour index 1.
     // CLS doesn't understand palette mapping, so we have to
     // convert our colur index into RGB form for drawing to
     // the screen
     Cls IndexToRgb(1)
     
     
     // draw our grid of ship images to the screen at the mouses
     // position
     GridImage ShipImage,MouseX(),MouseY(),10,10,true
     
     
     // Draw a rotated version of the palette mapped ship image
     DrawRotatedImage ShipImage,400,300,FadeAngle#,1,1,0,0,true
     
     
     // render our palette mapped screen to the actual screen
     RenderToScreen
     DrawPaletteMapImage(Screen,0,0)
     
     // --------------------------------------
     // Fade palette in and out
     // --------------------------------------
     ScaleLevel=128+Cos(Fadeangle#)*128
     ScaleLevel=ClipRange(ScaleLevel,0,255)
     ShadeRGB=RGB(ScaleLevel,ScaleLevel,ScaleLevel)
     
     For lp =1 To ColourCount
        Palette(lp)=RgbAlphaMult(BackupPalette(lp),ShadeRGB)
     Next
     
     Fadeangle#=WrapAngle(Fadeangle#+1)
     
     
     // show everything to the user
     Sync
  Loop EscKey()=true
  
  
  
  
 
Related Info: CreateFxImageEx :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com