Storing Images in data statements

Started by kevin, February 01, 2008, 11:26:38 AM

Previous topic - Next topic

kevin

Storing Images in data statements

   This example demonstrates a very simple approach for storing Image media within your program as data statements.   The example comes with a decoder function and a little  Space Invader sprite set.  The sprites were made by Phaelax.



Related articles:

   * Resource Binding in PlayBASIC V1.64O  (bind media into your EXEs. much better than the data option!)





kevin

#1
  Load Palette Mapped Image From Data Statements

    This is an alternative way of loading image data from internal data statements.  The first example is the usage example and includes a converted image as an example.      

PlayBASIC Code: [Select]
; PROJECT : Load Palette Mapped Image From Data Statements
; AUTHOR : PlayBASIC Tutor
; CREATED : 4/3/2015
; EDITED : 4/3/2015
; ---------------------------------------------------------------------

ThisImage=LoadDataStatementImage("fluppi.bmp")

drawimage THisIMage,100,100,false

SYnc
waitkey


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// --------------[ LOAD (PALETTE MAPPED) DATA STATEMENT IMAGE ]---------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------


Function LoadDataStatementImage(Filename$)

Index=FindData(Filename$)
if Index>-1
olddatapos=getdatapointer()

restore index+1

width =Readdata()
height =Readdata()
palettesize =Readdata()

Dim Palette(PaletteSize)
For lp=0 to PaletteSize-1
Palette(lp)=readdata()
next

ThisImage=newimage(Width,Height,2)

oldsurface=getsurface()
rendertoimage THisIMage
lockbuffer
ThisRGb=Point(0,0)
For ylp=0 to height-1
For xlp=0 to width-1
fastDot xlp,ylp,Palette(ReadData())
next
next
unlockbuffer

rendertoimage oldsurface
restore OldDataPos
endif

EndFUnction ThisImage





// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// --------[ fluppi.bmp IMAGE LOAD Converted to DATA STATEMENTS ]------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------

Data "fluppi.bmp"
Data 58
Data 46
Data 134
Data 0,12422966,15198251,15396144,15578669,15623243,15657264,15689291,15710254,15754827,15776046,15776302,15789359,15842093,15908651,15951435,15951691,15973421,16016715,16082763,16119717,16148555,16148556,16170797,16171053,16171309,16171564,16182565,16213579,16314149,16345419,16367916
Data 16368172,16368940,16379173,16380194,16380195,16380196,16380197,16380199,16380200,16380452,16381481,16382952,16383287,16383606,16383787,16383789,16383790,16383798,16433964,16434731,16444965,16445988,16446244,16447478,16447527,16447531,16447990,16448503,16448724,16448739,16448745,16448747
Data 16448750,16448754,16448760,16448949,16448978,16448987,16449328,16449334,16499756,16511780,16512035,16512036,16514282,16514283,16514291,16514297,16514524,16514798,16514861,16565548,16577827,16578851,16580060,16580088,16580089,16580331,16580385,16580388,16580395,16580396,16580465,16580534
Data 16580592,16645369,16645882,16645883,16646138,16646139,16709411,16710966,16711409,16711675,16738891,16739659,16756425,16764203,16774947,16775202,16775970,16776225,16776226,16776230,16776482,16776700,16776993,16776994,16777002,16777003,16777004,16777012,16777013,16777178,16777179,16777201
Data 16777204,16777207,16777210,16777212,16777214,16777215
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,122,47,47,47,47,93,122,121,0,0,0,0,133,105,105,105,133,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,103,44,44,44,71,0,0,0,0,0,0,0,133,100,100,100,133,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,70,70,70,57,40,40,40,40,115,0,0,0,0,0,0,0,100,100,100,100,100,105,131,133,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,120,122,82,47,48,56,35,36,36,36,113,0,0,0,0,133,131,105,100,100,100,100,100,132,133,133,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,37,37,37,37,37,42,36,37,37,37,114,0,0,0,0,133,88,98,105,100,100,100,105,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,39,38,37,37,37,37,114,0,0,0,0,117,133,58,105,100,100,100,133,0,0,0,0,133,133,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,111,74,37,37,37,37,114,0,0,0,0,133,133,58,105,100,100,100,133,0,0,0,0,133,133,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,37,37,114,0,0,0,0,133,133,133,133,100,100,100,133,0,0,0,0,133,133,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,0,43,43,43,43,43,43,43,43,43,104,0,0,0,0,0,37,37,37,114,0,0,0,0,133,133,133,133,100,100,100,133,0,0,0,0,133,133,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,0,89,89,89,89,89,89,89,89,89,128,0,0,0,0,0,102,73,37,116,0,0,0,0,133,55,97,133,133,105,100,133,0,0,0,0,133,133,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,127,62,62,62,62,62,62,62,62,62,127,0,0,0,0,0,0,0,54,112,0,0,0,0,0,0,0,133,133,100,105,133,0,0,0,0,133,133,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,127,62,62,62,62,62,62,62,62,62,76,0,0,0,0,0,0,0,114,53,29,27,85,0,0,0,0,117,133,133,133,101,88,59,59,87,101,133,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,129,64,63,62,62,62,62,62,62,62,62,81,96,130,0,0,0,0,37,37,54,75,119,0,0,0,0,133,133,99,133,133,133,133,133,133,133,133,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,125,68,61,63,62,62,62,62,62,62,77,69,68,126,0,0,0,0,37,37,37,37,114,0,0,0,0,0,0,133,133,133,133,133,133,133,133,133,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,123,48,67,65,62,62,62,62,62,62,78,45,46,123,0,0,0,0,114,37,37,37,53,37,37,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,120,91,95,66,64,64,64,64,64,64,79,94,90,120,0,0,0,0,116,37,37,37,37,37,37,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,6,2,20,80,60,60,60,60,60,60,86,0,0,0,0,0,0,0,112,37,37,37,54,37,37,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108
Data 108,108,108,108,0,0,0,0,0,0,0,124,49,49,49,49,49,49,124,0,0,0,0,0,0,0,53,37,0,0,0,0,0,0,0,0,0,0,0,28,28,28,28,28,28,28,28,28,28,28,28,30,0,0,0,0,108,108
Data 108,108,108,108,108,0,0,0,0,0,0,120,92,92,92,92,92,92,120,0,0,0,0,118,84,54,41,41,0,0,0,0,0,0,0,107,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,107,0,0,0,0,108,108
Data 108,108,108,108,108,0,0,0,0,0,0,12,3,3,3,3,3,0,0,0,0,0,0,110,34,34,34,52,0,0,0,0,0,0,0,7,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,9,0,108,108,108,108,108
Data 108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25,11,25,51,33,33,32,109,0,0,0,0,22,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,32,32,50,31,32,32,32,32,0,0,0,0,107,107,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,32,32,32,32,32,32,32,32,0,0,0,0,15,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,0,0,0,1,24,10,10,10,8,23,32,32,32,32,32,32,32,32,32,32,32,0,0,0,0,19,18,18,18,18,18,18,18,18,18,18,18,18,21,0,0,0,0,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,0,0,0,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,72,83,32,0,0,0,0,107,106,106,106,106,106,106,106,106,106,106,106,106,107,0,0,0,0,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,0,0,0,0,24,10,10,10,8,23,50,32,32,32,32,32,32,32,32,32,32,0,0,0,0,19,18,18,18,18,18,18,18,18,18,18,18,18,21,0,0,0,0,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,32,32,32,32,32,32,32,32,32,32,32,17,4,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,26,13,13,13,13,13,13,13,13,13,13,32,32,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108







     Conversion Code

       This example uses the Palette mapping library to palette map the input image, then  dumps the data out to data statements.   You could use this same principal  to make your own custom image format to protect your media if you really wanted.  Of course to do that you'd be dumping the pixel information out to file instead of data statements

PlayBASIC Code: [Select]
   // Include the palette Mapping library
#include "PaletteMapping"


Filename$="img/fluppi.bmp"

Convert_Image_File_To_Data_Statements(Filename$)

Sync
waitkey

end

Function Convert_Image_File_To_Data_Statements(Filename$)


// 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)

// This number of colours currently in our palette
ColourCount=1


oldsurface=getsurface()


// Load the Ship image from the media folder to folders down
ShipImage=LoadNewFXIMage(Filename$)

// Convert the images normally RGB formated pixels into our
// current palette
ColourCount=PaletteMapRGBImage(ShipImage,Palette(), ColourCount)

rendertoimage shipimage
lockbuffer
THisRGB=point(0,0)

#print " Data "+chr$(34)+getfilename$(Filename$)+chr$(34)
#print " Data "+str$(getimagewidth(ShipIMage))
#print " Data "+str$(getimageheight(ShipIMage))
#print " Data "+str$(ColourCount)

row$=""
RowCount=0
for lp=0 to colourcount-1

Row$+=str$(Palette(lp))
RowCount++
if RowCount=32
#print " Data "+row$
RowCount=0
Row$=""
else
Row$+=","
endif
next

if RowCount
#print " Data "+trimright$(row$,",")
endif

for ylp=0 to getimageheight(ShipIMage)-1
Row$=" Data "
for xlp=0 to getimagewidth(ShipIMage)-1
// Read the Colour Index from the palette mapped screen directly
ColourIndex= PaletteMappedPoint(xlp,ylp)
Row$+=str$(ColourIndex)+","
next
#print trimright$(row$,",")
next
unlockbuffer
rendertoimage oldsurface

EndFUnction










kevin

#2
  Load Compressed 8bit Palette Mapped Images from Data Statements


     This is another variation of the previous example code above, the main difference being that the colour table from palette mapped image is run length compressed before being output.    The packer library only supports compressing bytes, so if the colour table exceeds 256 (2^8) colours then it stores the data raw..


PlayBASIC Code: [Select]
      ThisImage=LoadDataStatementImage("rock.bmp")

cls 255

drawimage THisIMage,100,100,false

SYnc
waitkey




#include "packer"

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// -------[ LOAD (COMPRESSED PALETTE MAPPED) DATA STATEMENT IMAGE ]-----------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------


Function LoadDataStatementImage(Filename$)

Index=FindData(Filename$)
if Index>-1
olddatapos=getdatapointer()

restore index+1

width =Readdata()
height =Readdata()
palettesize =Readdata()

Dim Palette(PaletteSize)
For lp=0 to PaletteSize-1
Palette(lp)=readdata()
next

ThisImage=newimage(Width,Height,2)


oldsurface=getsurface()
rendertoimage THisIMage
lockbuffer
ThisRGb=Point(0,0)

if PaletteSize<256


packedsize =Readdata()
unpackedsize =(width*Height)+256

SrcBank=newBank(unpackedsize)
DestBank=newBank(unpackedsize)

for address=0 to packedsize-1 step 4
PokeBankInt SrcBank,Address, readdata()
next

// depack the bytes
if DepackBytes(getbankptr(SrcBank),GetBankPtr(DestBank))=1
Address=0
// colour the colours out
For ylp=0 to height-1
For xlp=0 to width-1
fastDot xlp,ylp,Palette(PeekBankByte(DestBank,Address))
Address++
next
next
endif

DeleteBank SrcBank
DeleteBank DestBank


else

// the image has more than 256 colours, so store it RAW
For ylp=0 to height-1
For xlp=0 to width-1
fastDot xlp,ylp,Palette(ReadData())
next
next

endif

unlockbuffer

rendertoimage oldsurface
restore OldDataPos
endif

EndFUnction ThisImage





// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// --------[ ROCK.bmp IMAGE Converted to DATA STATEMENTS ]------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------

Data "rock.bmp"
Data 80,80,9
Data 0,8,2097152,4194304,8396800,10502144,12607488,14721024,14737632
Data 2348
data $6B504250,$190000,$40000,$1D0003,$6030581,$4050582,$3E050700,$6058200,$6840704,$9000005,$83003C05,$5060605,$C068107,$84003A05,$6060505,$6810706,$39050B,$6030503,$6820706,$82040505,$6050505,$5050035,$7060603,$3050682,$5058404,$7030606,$310604,$6810508,$6840707,$3050405,$4070606,$5002E06
data $81060405,$84070805,$6060506,$603070A,$503002C,$5060682,$8068107,$6068307,$3070C05,$84002A06,$6060505,$6830710,$70B0506,$280605,$6060583,$603070F,$7090503,$5060684,$26060405,$6068200,$606070C,$6810505,$6820706,$4050506,$81002406,$81070706,$B070605,$7038105,$50604,$4810503,$4810021,$8810708
data $6030706,$2820508,$3820003,$5040303,$5030005,$20030482,$E048100,$7060507,$2018505,$3060303,$4038207,$6820504,$82050306,$200304,$70E0481,$5070605,$2010184,$83070506,$6040306,$3048305,$85001D03,$4060605,$81070C06,$83050C06,$7060403,$3068307,$81050604,$89001D03,$7070605,$6050504,$83070906,$3040506
data $6048105,$6048205,$6820709,$1C050703,$6058500,$5070706,$5058204,$7860604,$5050607,$81050304,$81050604,$81070B04,$1A050806,$5058700,$7070606,$82040803,$6030505,$B050582,$C038104,$19050807,$3050300,$3078306,$81040E03,$84040803,$5040303,$404070B,$5050582,$5001506,$1060305,$382040D,$4040503,$5820003
data $3070906,$5058404,$7030606,$110604,$6810508,$4050304,$3040386,$4040304,$3060003,$81000581,$84060805,$5040505,$7060603,$E0604,$6040505,$3060581,$6010481,$4030804,$3038304,$85050804,$6050604,$3070A06,$3000C06,$6068205,$6820705,$81030707,$C060705,$5068207,$84050700,$5060604,$603070C,$584000A
data $A060605,$82030507,$7140605,$50682,$4810505,$5810603,$605070B,$5830008,$70D0606,$6068201,$682070F,$82070506,$3000506,$6048305,$9050307,$6068407,$6040505,$6820006,$4070C06,$5038406,$70F0606,$6060682,$5058207,$6830404,$5030707,$7060681,$5060682,$4060405,$7068100,$6058107,$4050507,$82070E06
data $7060808,$50582,$3060582,$81050307,$6040703,$5030005,$4000483,$8810708,$6030706,$6060581,$6830714,$81000505,$3060405,$3028205,$3038200,$5050403,$83050300,$E040304,$81060307,$13060805,$5068307,$5080005,$3020185,$7030603,$4040382,$6068205,$4830503,$70E0403,$711060D,$5040681,$5080481,$2010184
data $83070506,$6040306,$3048505,$C060403,$4068107,$10060A05,$4068107,$5070005,$6040383,$6830707,$5050403,$30488,$6050504,$83070906,$4040506,$82060705,$70F0605,$6000506,$6048205,$6830709,$5030403,$38200,$5820405,$88060405,$5060707,$4050405,$6030504,$82000581,$70D0605,$5060681,$81050600,$82070B04
data $4040606,$30384,$82040803,$6030505,$4050582,$5050504,$6058204,$681070C,$4820506,$3050303,$D038104,$3068107,$38504,$E030300,$5038104,$5058204,$5820407,$81070A06,$89050806,$5050403,$4030304,$81070C05,$83040306,$1000003,$382040D,$82040E03,$7090606,$5080681,$5040384,$82000105,$7090605,$4040681
data $00383,$4050304,$3040386,$A040304,$82040903,$6040505,$6070783,$4840509,$1050403,$81000581,$81060805,$83040505,$6000003,$1048103,$3830406,$6050503,$40D0581,$3050582,$82050906,$4060304,$4030383,$4820508,$83040405,$7000003,$3038302,$83050504,$5050104,$5058206,$6810410,$4830509,$4050103,$1020384
data $84030802,$3040302,$3028100,$81020500,$5080003,$5030605,$3820409,$8040603,$3048505,$4030101,$2038404,$20A0102,$3040385,$60203,$30282,$6050508,$4090504,$6030382,$83050604,$3030403,$4038101,$3038104,$A018102,$3038102,$82000502,$40B0302,$5050604,$5820409,$9040605,$3048505,$3030301,$3038104
data $1018202,$5020D,$40C0381,$5060603,$5060411,$5810603,$3038200,$4038100,$6010902,$81000502,$81040303,$82040803,$5070606,$5050411,$5810605,$2050100,$281010E,$3810005,$5810403,$6810408,$4110508,$6050504,$5060585,$2070104,$2060181,$2810107,$3810005,$582040A,$11050904,$7050404,$5058306,$87020601
data $3020101,$7020203,$6028101,$9038100,$4058304,$83041A03,$9040505,$4038206,$10103,$1840304,$4030301,$82000702,$4070303,$3040584,$82041A03,$60B0405,$1040381,$1850307,$3020201,$80203,$1040701,$60C041C,$283010F,$90203,$41B030D,$60C0381,$283010E,$A0203,$407030D,$4040381,$4060308,$5040383
data $10D060B,$3030283,$30C000C,$3010405,$4030A04,$3038204,$A058100,$83010C06,$D030302,$2028200,$403030A,$81000305,$8040303,$81010003,$5810005,$5820608,$81010A02,$D0102,$2010185,$4000302,$4028203,$4820307,$8040503,$83040503,$8040303,$3048205,$E01020A,$83010400,$30202,$2090381,$4030383,$4820505
data $81020601,$84040303,$2010203,$2820308,$83030A04,$E030304,$5028100,$2028301,$81020303,$81020501,$5070003,$4010382,$4038102,$2038404,$2090102,$7040382,$3820003,$5001003,$82010A02,$9000302,$1038505,$5030202,$3038104,$8018102,$82040A02,$120303,$81010281,$84010602,$3020103,$183040D,$4060302,$2030381
data $7010182,$3040302,$82040305,$140303,$5010281,$E030402,$2028304,$81040503,$9020403,$5050001,$3030483,$2810016,$1040301,$3030282,$A038104,$1028304,$5030502,$9010902,$82001803,$4050302,$20384,$81040303,$83040905,$B010203,$6018102,$81010702,$7001C02,$08302,$87040A03,$3030405,$9010102,$1018702
data $2030302,$81010702,$81002602,$82040903,$3040405,$3010184,$1010403,$84030400,$3030101,$270204,$7030382,$4058404,$1050303,$7010401,$1018503,$3030202,$1002802,$17010407,$3028301,$D002902,$83011603,$2A020302,$5030D00,$2028201,$283010E,$2C0303,$104030C,$10C0204,$3030283,$282002D,$3030A02,$2028601
data $2020303,$281010A,$85002D01,$2020101,$3040003,$3030282,$A030502,$2E0102,$2830104,$81000302,$5020503,$A048103,$3048303,$81002E03,$83010502,$4030202,$5018102,$3048303,$30704,$30030382,$7020500,$84020301,$3040303,$382040A,$81003203,$2810102,$83010106,$4030302,$3050304,$3038204,$2810034,$1020501
data $30281,$5000381,$3048305,$81003603,$4030102,$5028101,$38030900,$3028200,$3820405,$7004802,$80002F02






 Compression Code

 This function creates the compressed data statement code to the console, so you'll need to run the program in a debug mode. F6/F7

PlayBASIC Code: [Select]
  // Include the palette Mapping library
#include "PaletteMapping"
#include "packer"


Filename$=path$+"rock.bmp"

Convert_Image_File_To_Data_Statements(Filename$)

Sync
waitkey

end

Function Convert_Image_File_To_Data_Statements(Filename$)


// 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)

// This number of colours currently in our palette
ColourCount=1


oldsurface=getsurface()


// Load the Ship image from the media folder to folders down
ShipImage=LoadNewFXIMage(Filename$)

// Convert the images normally RGB formated pixels into our
// current palette
ColourCount=PaletteMapRGBImage(ShipImage,Palette(), ColourCount)

rendertoimage shipimage
lockbuffer
THisRGB=point(0,0)

Width=getimagewidth(ShipIMage)
Height=getimageHeight(ShipIMage)

#print " Data "+chr$(34)+getfilename$(Filename$)+chr$(34)
#print " Data "+str$(Width)+","+str$(Height)+","+str$(ColourCount)

row$=""
RowCount=0
for lp=0 to colourcount-1

Row$+=str$(Palette(lp))
RowCount++
if RowCount=32
#print " Data "+row$
RowCount=0
Row$=""
else
Row$+=","
endif

next

if RowCount
#print " Data "+trimright$(row$,",")
endif


if ColourCount<256

// 8 bit palette mapped image, so we compress it
SrcBank =NewBank((Width*Height)+256)
DestBank =NewBank((Width*Height)+256)


// copy the colour indexes to the abank
address=0
for ylp=0 to Height-1
for xlp=0 to Width-1
// Read the Colour Index from the palette mapped screen directly
ColourIndex= PaletteMappedPoint(xlp,ylp)
pokebankbyte srcbank,address,ColourINdex
address++
next
next

PackedSize=Packbytes(GetBankPtr(SrcBank),Address,GetBankpTr(DestBank))
#print " Data "+str$(packedsize)

RowCount=0
Row$=""

for address=0 to (packedsize-1) step 4

ThisINt=PeekBankInt(DestBank,Address)
Row$+=hex$(Thisint)+","
RowCount++
if RowCount=>32
row$=trimright$(row$,",")
row$=replace$(row$,"$00","$")
row$=replace$(row$,"$0","$")
#print " data "+row$
row$=""
RowCount=0
endif

next

if rowcount
row$=trimright$(row$,",")
row$=replace$(row$,"$00","$")
row$=replace$(row$,"$0","$")
#print " data "+row$
endif

DeleteBank SrcBank
DeleteBank DestBank

else

for ylp=0 to Height-1
Row$=" Data "
for xlp=0 to Width-1
// Read the Colour Index from the palette mapped screen directly
ColourIndex= PaletteMappedPoint(xlp,ylp)
Row$+=str$(ColourIndex)+","
next
#print trimright$(row$,",")
next

endif

unlockbuffer
rendertoimage oldsurface

EndFUnction