.macro PNGtoKOALA(PNGpicture,BMPData,Chardata,D800data,BGC) { // Create RGB to C64 color index .var RGBtoC64 = Hashtable() .eval RGBtoC64.put(Black,0) .eval RGBtoC64.put(White,1) .eval RGBtoC64.put(Red,2) .eval RGBtoC64.put(Cyan,3) .eval RGBtoC64.put(Purple,4) .eval RGBtoC64.put(Green,5) .eval RGBtoC64.put(Blue,6) .eval RGBtoC64.put(Yellow,7) .eval RGBtoC64.put(L_brown,8) .eval RGBtoC64.put(D_brown,9) .eval RGBtoC64.put(L_red,10) .eval RGBtoC64.put(D_grey,11) .eval RGBtoC64.put(Grey,12) .eval RGBtoC64.put(L_green,13) .eval RGBtoC64.put(L_blue,14) .eval RGBtoC64.put(L_grey,15) // Hashtable for Storing all the colors. .var RGBColorTable = Hashtable() // Create a list to hold all the Bitmap and collor data .var AllData = List(10000) // Load the picture into the data list Graphics .var Graphics = LoadPicture(PNGpicture,List()) // Convert and return the Background Color .var BackgroundColor = FindBackgroundColor() .pc = BMPData "KOALA - Bitmap Graphics" .fill 8000,AllData.get(i) .pc = Chardata "KOALA - Character Color Data" .fill 1000,AllData.get(i+8000) .pc = D800data "KOALA - D800 Color Data" .fill 1000,AllData.get(i+9000) .pc = BGC "KOALA - Background Collor" .fill 1,BackgroundColor } //============================================================================= // ColorTable-Hashtable has to be defined outside the function. .function FindBackgroundColor() { // Hastable for storing 4x8 block colordata .var BlockColors = Hashtable() // Hashtable for potential background Colors from inside one block .var BG = Hashtable() // Hashtable for keeping track of background color candidates from all blocks .var BGCandidate = List(4) // Declare some variables .var CurrentBlock = 0 // Keeps track of which block is being checked .var BGRemaining = 4 // Remaining backgound color candidates (begins with 4 since the first block get's it's 4 colors copied into the BGCandidate Hastable) .var ColorCounter = 0 // Counter for keeping track of how many colors are found inside each block .var FirstMatch = true // Used to diferensiate between the first 4 color block (It has to contain the backgound color) and the rest of the blocks // Loop for checking all 1000 blocks .for (CurrentBlock=0 ; CurrentBlock<1000 ; CurrentBlock++) { // Clear out any block colors from the hashtable .eval BlockColors = Hashtable() // Fetch 4x8 pixel block colors (32 total) .for (var Pixel = 0 ; Pixel < 32 ; Pixel++) { .var PixelColor = Graphics.getPixel([8*CurrentBlock+[[Pixel<<1]&7]]-[320*[floor(CurrentBlock/40)]] , [8*floor(CurrentBlock/40)]+[Pixel>>2]) .eval BlockColors.put(PixelColor,Pixel) } // Reset the block color counter .eval ColorCounter = 0 // Store the block colors in BG .if (BlockColors.containsKey(Black) ==true) { .eval BG.put(ColorCounter,Black) .eval RGBColorTable.put([ColorCounter+[4*CurrentBlock]],Black) .eval ColorCounter=ColorCounter+1 } .if (BlockColors.containsKey(White) ==true) { .eval BG.put(ColorCounter,White) .eval RGBColorTable.put([ColorCounter+[4*CurrentBlock]],White) .eval ColorCounter=ColorCounter+1 } .if (BlockColors.containsKey(Red) ==true) { .eval BG.put(ColorCounter,Red) .eval RGBColorTable.put([ColorCounter+[4*CurrentBlock]],Red) .eval ColorCounter=ColorCounter+1 } .if (BlockColors.containsKey(Cyan) ==true) { .eval BG.put(ColorCounter,Cyan) .eval RGBColorTable.put([ColorCounter+[4*CurrentBlock]],Cyan) .eval ColorCounter=ColorCounter+1 } .if (BlockColors.containsKey(Purple) ==true) { .eval BG.put(ColorCounter,Purple) .eval RGBColorTable.put([ColorCounter+[4*CurrentBlock]],Purple) .eval ColorCounter=ColorCounter+1 } .if (BlockColors.containsKey(Green) ==true) { .eval BG.put(ColorCounter,Green) .eval RGBColorTable.put([ColorCounter+[4*CurrentBlock]],Green) .eval ColorCounter=ColorCounter+1 } .if (BlockColors.containsKey(Blue) ==true) { .eval BG.put(ColorCounter,Blue) .eval RGBColorTable.put([ColorCounter+[4*CurrentBlock]],Blue) .eval ColorCounter=ColorCounter+1 } .if (BlockColors.containsKey(Yellow) ==true) { .eval BG.put(ColorCounter,Yellow) .eval RGBColorTable.put([ColorCounter+[4*CurrentBlock]],Yellow) .eval ColorCounter=ColorCounter+1 } .if (BlockColors.containsKey(L_brown)==true) { .eval BG.put(ColorCounter,L_brown) .eval RGBColorTable.put([ColorCounter+[4*CurrentBlock]],L_brown) .eval ColorCounter=ColorCounter+1 } .if (BlockColors.containsKey(D_brown)==true) { .eval BG.put(ColorCounter,D_brown) .eval RGBColorTable.put([ColorCounter+[4*CurrentBlock]],D_brown) .eval ColorCounter=ColorCounter+1 } .if (BlockColors.containsKey(L_red) ==true) { .eval BG.put(ColorCounter,L_red) .eval RGBColorTable.put([ColorCounter+[4*CurrentBlock]],L_red) .eval ColorCounter=ColorCounter+1 } .if (BlockColors.containsKey(D_grey) ==true) { .eval BG.put(ColorCounter,D_grey) .eval RGBColorTable.put([ColorCounter+[4*CurrentBlock]],D_grey) .eval ColorCounter=ColorCounter+1 } .if (BlockColors.containsKey(Grey) ==true) { .eval BG.put(ColorCounter,Grey) .eval RGBColorTable.put([ColorCounter+[4*CurrentBlock]],Grey) .eval ColorCounter=ColorCounter+1 } .if (BlockColors.containsKey(L_green)==true) { .eval BG.put(ColorCounter,L_green) .eval RGBColorTable.put([ColorCounter+[4*CurrentBlock]],L_green) .eval ColorCounter=ColorCounter+1 } .if (BlockColors.containsKey(L_blue) ==true) { .eval BG.put(ColorCounter,L_blue) .eval RGBColorTable.put([ColorCounter+[4*CurrentBlock]],L_blue) .eval ColorCounter=ColorCounter+1 } .if (BlockColors.containsKey(L_grey) ==true) { .eval BG.put(ColorCounter,L_grey) .eval RGBColorTable.put([ColorCounter+[4*CurrentBlock]],L_grey) .eval ColorCounter=ColorCounter+1 } // Carry out a background color check when there are 4 colors in a block .if (ColorCounter == 4 && BGCandidate.size()>1) { // Check if it is the first block with 4 collors .if (FirstMatch) { // Copy the 4 collors as possible candidates .eval BGCandidate.add(BG.get(0)) .eval BGCandidate.add(BG.get(1)) .eval BGCandidate.add(BG.get(2)) .eval BGCandidate.add(BG.get(3)) .eval FirstMatch = false } else { .for (var i = 0 ; i < BGCandidate.size() ; i++) { .if (BGCandidate.get(i) != BG.get(0)) { .if (BGCandidate.get(i) != BG.get(1)) { .if (BGCandidate.get(i) != BG.get(2)) { .if (BGCandidate.get(i) != BG.get(3)) { .eval BGCandidate.remove(i) } } } } } } } } .var BackgroundColor = BGCandidate.get(0) // Test BG Color .print BackgroundColor // Variable for keeping track of which byte is in use .var ByteNumber = 0 // Create hashtable and ascociate bitmap patterns to RGB Colors (one for bit patterns and one for collor referance) .var ColorIndex = Hashtable() .var ColorIndex2 = Hashtable() // Define the BG Color into the Color Indexes .eval ColorIndex.put(BackgroundColor,0) .eval ColorIndex2.put(0,BackgroundColor) .for (var BlockNumber = 0 ; BlockNumber < 1000 ; BlockNumber++) { // Variable for keeping track of which collor is to be used inside the block .var colpos = 1 // Place the RGB color data into the color indexes (Multicolor Bit-combinations 01, 10 & 11 assigned the 3 colors) .for (var i = 0 ; i < 4 ; i++) { .if (RGBColorTable.get(i+[BlockNumber*4]) != BackgroundColor) { .if (RGBColorTable.get(i+[BlockNumber*4]) != null) { .eval ColorIndex.put(RGBColorTable.get(i+[BlockNumber*4]),colpos) .eval ColorIndex2.put(colpos,RGBColorTable.get(i+[BlockNumber*4])) .eval colpos = colpos+1 } } } // Read Pixel Collors in current block and fill in BMPData accordingly .for (var Byte = 0 ; Byte < 8 ; Byte++) { // Temp Storage for bitmap byte, bitmap pattern and the pixelcolor .var BMPByte = 0 .var BMPPattern = 0 .var PixelColor = 0 // Find the pixel collors and cross ref. with the bit patterns to create the BMP data .for (var Pixel = 0 ; Pixel < 4 ; Pixel++) { .eval PixelColor = Graphics.getPixel([[8*BlockNumber]+[[Pixel<<1]&7]]-[320*[floor(BlockNumber/40)]] , [8*floor(BlockNumber/40)]+Byte) .eval BMPPattern = ColorIndex.get(PixelColor) .eval BMPByte = BMPByte|[BMPPattern << [6 - Pixel*2]] } // Set the done BMP data into final data storage .eval AllData.set(ByteNumber,BMPByte) .eval ByteNumber = ByteNumber+1 } // Create the color data .var CharacterColor = 0 .var D800Color = 0 .if (RGBtoC64.get(ColorIndex2.get(1)) != null) { .eval CharacterColor = [RGBtoC64.get(ColorIndex2.get(1))<<4] } .if (RGBtoC64.get(ColorIndex2.get(2)) != null) { .eval CharacterColor = CharacterColor|RGBtoC64.get(ColorIndex2.get(2)) } .if (RGBtoC64.get(ColorIndex2.get(3)) != null) { .eval D800Color = RGBtoC64.get(ColorIndex2.get(3)) } // Store the colors into final data storage .eval AllData.set(8000+BlockNumber,CharacterColor) .eval AllData.set(9000+BlockNumber,D800Color) } // Return background color: .return BackgroundColor }
.macro PNGtoKOALA(PNGpicture,BMPData,Chardata,D800data,BGC)