Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Kickassembler - Converting .PNG to Koala
2012-02-21 15:04
TWW

Registered: Jul 2009
Posts: 541
Kickassembler - Converting .PNG to Koala

Hey fellow hackers.

I wanted to write a converter in Kickassembler which can take any .PNG MC Bitmap screenshot from VICE (Then I don't need to worry about the RGB values since they are known) and convert into raw data you can use in your productions.

This is the way I imagine doing it:

#1 - Determin the background collor based on the most used collor in the picture
#2 - Verify there is no 4x8 block containing more than 3 collors+BG
#3 - Convert each 4x8 block afterwards and write the data into 3 lists (1 for BMP data, 1 for Charcollors and 1 for collmem).
#4 - Add BG collor at the end :-)

I'm looking for improvement comments on this or maybee I need to revise the way I think about this?
2012-02-21 16:07
Skate

Registered: Jul 2003
Posts: 490
#1 can be a little problematic since graphician might have filled a larger area with a color other than the original bg color. so, if you detect another color as the background color, you might have problems at 2nd step even if color usage is legal. so, i think bg color should be entered manually instead of an autodetection system. autodetection can be optional if parameter is null etc.

rest of the process seems pretty fine to me.
2012-02-21 18:26
chatGPZ

Registered: Dec 2001
Posts: 11114
"Determin the background collor based on the most used collor in the picture"
that does not work generically... you have to count how many colors are used in each 8x8 cell, and then from all 8x8 cells which use 4 colors pick a color that is used in all of these cells.
2012-02-21 19:49
MagerValp

Registered: Dec 2001
Posts: 1055
If you already have the image in VICE, save out the bitmap and color ram instead of taking a screenshot...
2012-02-21 21:17
STE'86

Registered: Jul 2009
Posts: 274
Please follow Skates advice on the autodetect.

most common colour in a bitmap most certainly does not always mean its BG colour. in my stuff anyway.

Steve
2012-02-21 23:16
Cruzer

Registered: Dec 2001
Posts: 1048
I vote for Groepaz's approach.
2012-02-22 01:00
TWW

Registered: Jul 2009
Posts: 541
ok.

Find the common collor in all 4x8 blocks with 4 collors instead of #1.

gotit. thanx
2012-02-22 08:17
The Human Code Machine

Registered: Sep 2005
Posts: 110
Groepaz's approach can also fail, if there are no blocks using 4 colors at the same time. For this I would make it optional to force the color by the user. Groepaz autodetection will always give the right picture, but not always the wanted background color.
2012-02-22 11:37
algorithm

Registered: May 2002
Posts: 702
What magervalp said. No need for any conversion if the image is displayed in vice. Use the d021 color from there and save the data.

bank io
bsave "d800loc" 0 $d800 dbe7
bsave "inkpaploc" 0 $0400 $07e7 ;varies of course
bsave "gfx" 0 $2000 $3f3f ; varies of course
bsave "d021loc" 0 $d021 d021
2012-02-22 11:44
kmeg
Account closed

Registered: Sep 2003
Posts: 5
If there is need for that I can update this tools The CCS64 Gfx Rippers to support Vice...
2012-02-22 12:23
Cruzer

Registered: Dec 2001
Posts: 1048
Quote: What magervalp said. No need for any conversion if the image is displayed in vice. Use the d021 color from there and save the data.

bank io
bsave "d800loc" 0 $d800 dbe7
bsave "inkpaploc" 0 $0400 $07e7 ;varies of course
bsave "gfx" 0 $2000 $3f3f ; varies of course
bsave "d021loc" 0 $d021 d021


This is supposed to be easier than taking a screenshot?
2012-02-22 12:24
JackAsser

Registered: Jun 2002
Posts: 1989
Use Enthusi's excellent vice snapshot grapper. Simply take a VICE snapshot (not screenshot) and use the utility to extract what's on screen.

Vice Snapshot Grabber 4.2
2012-02-22 12:27
Flavioweb

Registered: Nov 2011
Posts: 447
isn't already in vice a menu option to 'save multimedia file' for export pictures in koala format?
2012-02-22 14:25
algorithm

Registered: May 2002
Posts: 702
Quote: This is supposed to be easier than taking a screenshot?

Certainly not easier than that, but easier than going through conversion processes of finding background color, checking 4x8 blocks etc.
2012-02-22 15:26
TWW

Registered: Jul 2009
Posts: 541
I think we are getting a bit off track here.

I want to make a macro which converts a 320x200 picture on the PC (which follows the multicollor limitation of bitmap gfx on the C64) directly into my code in Kickassembler.

I want to use the script language supplied by the powerfull Kickassembler to do it and not a 3rd party tool which will add a step to the process.

I know it is possible but I wanted to get some ideas before diving into the matter.

After giving it some thought, i came up with something like this:

- Fetch all "4 collors" 4x8 blocks store them into a list (ignore blocks with 3, 2 or 1 collor(s)).
- repeat for all 1000 blocks and make a new list for each 4 coll block. (there is probably some nice way to store 2D lists (hastables?) which does this effectivly, still figguring this part out).
- Find the common collor in the stored blocks
- Start converting blocks to 2 bit pixel-data while setting the BG to #%"00" when it is encounterred.
- Store the colldata into seperate lists while each block is converted
- memfill the bmp/coll-data where you want it(set by the macro call).

Later if you modify the picture a little bit or change it with another one, just copy the .PNG file and the assembler does the rest.
2012-02-22 15:43
chatGPZ

Registered: Dec 2001
Posts: 11114
<Post edited by chatGPZ on 22/2-2012 20:24>

Quote:
Groepaz's approach can also fail, if there are no blocks using 4 colors at the same time.

ofcourse, as a first step you must count colors per cell and then sort the cells by how many colors are in them :)

edit: thats nonsense ofcourse. if there is no block with 4 colors then you can pick whatever bg color you like =P

that said, i would also suggest to use a makefile and a small external tool. maybe even hack it up yourself (because it is trivial, and didnt we all? =P). doing something like that in the assembler seems a bit pointless, wrong tool for the job, etc.
2012-02-22 19:09
Slammer

Registered: Feb 2004
Posts: 416
I would use this approach (pseudocode):
   backgrounColorSet =  {color0, color1, .., color15}
   for all blocks
      if (block has 4 colors)
         remove all but the 4 colors from the backgroundColorSet

Kick Assembler doesn't support sets yet, but you can use the keys in a hash table as a set and afterwards use 'hashtable.keys()' to get the possible background colors.
2012-02-22 19:50
Cruzer

Registered: Dec 2001
Posts: 1048
Slammer: Guess a list of 16 booleans indicating whether the colors are candidates for bg colors would do the trick. For each 4-color block, set the 12 others to false.
2012-02-23 00:13
TWW

Registered: Jul 2009
Posts: 541
I got an idea.

#1 - progressivly scan each 4x8 block and find the first one with 4 collors and add those collors to a list
#2 - continue scanning untill next block with 4 collors
#3 - find common collors between the two and discard the rest
#4 - repeat untill 1 collor remains in the list, BG collor set.
(I guess this is what you said^^)


I have 2 specific questions:

#1 - Can this:

    .for (var Id = 0 ; Id < 64 ; Id++) {
        .var PixelCollor = gfx.getPixel([Id>>1]&3, [Id>>3])
        .eval BlockCollors.put(Id,PixelCollor)
    }


be written like:

    .for (var Id = 0 ; Id < 64 ; Id++) {
      .eval BlockCollors.put(Id,gfx.getPixel([Id>>1]&3, [Id>>3]))
    }


somehow? (not very importain but just curios).

#2: - I have the collors from a 4x8 block in a hashtable, what is a good way to figgure out how many variants are stored in the table. Are we talking a long line of .if's here or is there a more smooth method?
2012-02-23 01:36
algorithm

Registered: May 2002
Posts: 702
Even more easier

$d021 col=0

check each 4x8 block, if colors in bitmap exceed limitations, then inc d021 and start over. until you get no clash




2012-02-23 01:40
TWW

Registered: Jul 2009
Posts: 541
Interesting. Assume the BG collor and verify...

How about compilation time if the BG = #$0f vs. method stipulated above?
2012-02-23 08:17
enthusi

Registered: May 2004
Posts: 675
The approach to brute force BG has the advantage that you can as well convert pictures that do not match MCbitmap restrictions that way (weighting via least_clashes, etc...).
In general I personally dislike the idea to integrate such things into kickassembler (or any assembler).
I dont like the simplified interface to implement SID files already. I see hordes of beginners to not get what's working why and how.
But then again, that might just be me thinking that way.

PS:
You can aswell use vice-dumps directly if your method relies on vice bitmaps anyway. There you can simply read out all colors. Check here i.e.:
Vice Snapshot Grabber 4.2
2012-02-23 09:53
Cruzer

Registered: Dec 2001
Posts: 1048
I personally think it's a better idea to have as much import, convert and precalc functionality as an assembler script, since it's much easier to customize for the situation than external tools, which also have a tendency to be windows-only, unlike KickAssembler. The only drawback is that it slows down the assembly time if it's too complex. In these cases I usually save the generated data when it has reached a usable state, and have an option to turn on/off whether to load or regenerate it.
2012-02-23 11:12
TWW

Registered: Jul 2009
Posts: 541
I'm with Cruiser on this one. I've been coding assembler on the 64 since the late eigthies so if I can't figgure that part out then screw it :-) Perhaps for a beginner it would be more prudent to do it the hard way but I'm past that stage and I want it as easy and fast as possible.

There are too many small tools and stuff anyway so why not implement some of the trivial ones yourself. This way I get a chance to learn more about script language in the process^^

I don't know about the sid stuff though.
2012-02-23 15:57
enthusi

Registered: May 2004
Posts: 675
Sorry, dont get me wrong: Coding something like Kickassembler is extremely cool ;-) But that differs from my opinion about its existance :)
2012-02-25 01:19
TWW

Registered: Jul 2009
Posts: 541
Alright, this is what I got so far. It seems to be working but I have feeling it is extreemly bloated. Could some script guru take a look ang give me some pointers is something is done bad/wrong/unoptimized?

(Assuming collor palette is pre-defined)


.macro PNGtoKOALA(PNGpicture,BMPdata,Chardata,D800data) {

    // Hastable for storing 4x8 collordata
    .var BlockCollors = Hashtable()

    // Hash table for holding potential BackGround Collors from a block
    .var BG = Hashtable()

    // Hashtable for keeping track of candidates
    .var BGCandidate  = Hashtable()


    // Declare some variables
    .var Id           = 0
    .var CurrentBlock = 0
    .var BGRemaining  = 4
    .var CollCounter  = 0
    .var FirstMatch   = true
    .var i            = 0

    // Load the picture into gfx
    .var gfx = LoadPicture(PNGpicture,List())

    // Block Pointer Variable
    .for (CurrentBlock=0 ; CurrentBlock<1000&&BGRemaining > 1 ; CurrentBlock++) {

        // Fetch 4x8 pixel block collors
        .for (var Id = 0 ; Id < 32 ; Id++) {
            .var PixelCollor = gfx.getPixel([8*CurrentBlock+[[Id<<1]&7]]-[320*[floor(CurrentBlock/40)]], [8*floor(CurrentBlock/40)]+[Id>>2])
            .eval BlockCollors.put(PixelCollor,Id)
        }

        // First check for 4 collors in a block
        .if (BlockCollors.containsKey(Black)  ==true) { .eval BG.put(CollCounter,Black)   .eval CollCounter=CollCounter+1 }
        .if (BlockCollors.containsKey(White)  ==true) { .eval BG.put(CollCounter,White)   .eval CollCounter=CollCounter+1 }
        .if (BlockCollors.containsKey(Red)    ==true) { .eval BG.put(CollCounter,Red)     .eval CollCounter=CollCounter+1 }
        .if (BlockCollors.containsKey(Cyan)   ==true) { .eval BG.put(CollCounter,Cyan)    .eval CollCounter=CollCounter+1 }
        .if (BlockCollors.containsKey(Purple) ==true) { .eval BG.put(CollCounter,Purple)  .eval CollCounter=CollCounter+1 }
        .if (BlockCollors.containsKey(Green)  ==true) { .eval BG.put(CollCounter,Green)   .eval CollCounter=CollCounter+1 }
        .if (BlockCollors.containsKey(Blue)   ==true) { .eval BG.put(CollCounter,Blue)    .eval CollCounter=CollCounter+1 }
        .if (BlockCollors.containsKey(Yellow) ==true) { .eval BG.put(CollCounter,Yellow)  .eval CollCounter=CollCounter+1 }
        .if (BlockCollors.containsKey(L_brown)==true) { .eval BG.put(CollCounter,L_brown) .eval CollCounter=CollCounter+1 }
        .if (BlockCollors.containsKey(D_brown)==true) { .eval BG.put(CollCounter,D_brown) .eval CollCounter=CollCounter+1 }
        .if (BlockCollors.containsKey(L_red)  ==true) { .eval BG.put(CollCounter,L_red)   .eval CollCounter=CollCounter+1 }
        .if (BlockCollors.containsKey(D_grey) ==true) { .eval BG.put(CollCounter,D_grey)  .eval CollCounter=CollCounter+1 }
        .if (BlockCollors.containsKey(Grey)   ==true) { .eval BG.put(CollCounter,Grey)    .eval CollCounter=CollCounter+1 }
        .if (BlockCollors.containsKey(L_green)==true) { .eval BG.put(CollCounter,L_green) .eval CollCounter=CollCounter+1 }
        .if (BlockCollors.containsKey(L_blue) ==true) { .eval BG.put(CollCounter,L_blue)  .eval CollCounter=CollCounter+1 }
        .if (BlockCollors.containsKey(L_grey) ==true) { .eval BG.put(CollCounter,L_grey)  .eval CollCounter=CollCounter+1 }

        .if (CollCounter == 4) {

            // Check if it is the first block with 4 collors
            .if (FirstMatch) {

                // Copy the 4 collors as possible candidates
                .eval BGCandidate.put(0,BG.get(0))
                .eval BGCandidate.put(1,BG.get(1))
                .eval BGCandidate.put(2,BG.get(2))
                .eval BGCandidate.put(3,BG.get(3))
                .eval FirstMatch = false

            } else {

                // Check BG candidate #0 = BG #0->3 => Next if some match OR Remove value / Decrease BGReamining
                .for (var i = 0 ; i < BGRemaining ; 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)
                                    .eval BGRemaining = BGRemaining-1
                                }
                            }
                        }
                    }
                }
            }
        }

        // Clear out the Block Collors
        .eval BlockCollors = Hashtable()

        // Reset the Block Collor Counter
        .eval CollCounter = 0
    }

    // Verification of BG Coll:
    .print "BG Collor is: " + BGCandidate.get(0)
}

2012-02-25 15:20
Slammer

Registered: Feb 2004
Posts: 416
Try the following:
When you have a time-consuming program, with pure script commands - then place them in a .define block or in a function and it will be faster.

The technical reason for this (which you don't need to know but some might find interesting):
When Kick Assembler evaluates a function or dircetive it saves the result, so it doesn't have to evaluate it in the next pass. The directive will only be reevaluated if the result is invalid (That happens if the result depends on a label that is defined later in the sourcecode). However if you have too many saved intermediate results, it damages the performace and the memory usage. Placing your script inside a function or .define block will save only one result and not all the intermediate results.

So this will be more effective:

.var bgColor = findBgColor(params)
.function findBgColor(params) {
...
}
2012-02-25 15:30
Slammer

Registered: Feb 2004
Posts: 416
Btw. if you dont want to restructure your code then just place a define directive inside your code that takes care of those for-loops.
2012-02-25 20:35
TWW

Registered: Jul 2009
Posts: 541
Ok. Slammer, thanx.

I will try out your suggestions and come back with the result whne it's done. (not today coz I got a party to go to 8-D)
2012-02-26 12:38
TWW

Registered: Jul 2009
Posts: 541
EDIT: EDIT: I am a idiot!

Figgured it out...
2012-02-26 19:40
TWW

Registered: Jul 2009
Posts: 541
Alright. Got the background sorted. I decieded to do a full scan of all blocks to simultaniously extract the collors used which I now have neatly stored into a indexed collor hashtable.

The only thing remaining is to capture the actual bmp-data and make sure the Background collor is mapped with #%00 bitmpair (transparent).

I tried this:

        // Load the picture into the data list Graphics
        .var Graphics = LoadPicture(PNGpicture,List().add(BackgroundColor))

        // Fill in the Bitmap data
        .pc = BMPdata
        .fill 8000,[Graphics.getMulticolorByte(floor(i/8)-40*floor(i/320),i-[floor(i/8)-40*flo or(i/320)]*8-312*floor(i/320))]


Which works perfectly for the BG collor. However I thought if I left out the three last bitpair definitions in the getMulticolorByte function, that any other collor then BG would be treated as if no bitpair collor was defined (I.e. get mapped progressivly by the function using the three last bitpair combinations #%01 #%10 & #%11)

So before I go ahead and make a bigger job out of this and check every pixel on the picture to determine which bitpair should be used, I want to check if I am missing something or doing this in the wrong way.
2012-02-27 13:10
Slammer

Registered: Feb 2004
Posts: 416
getMulticolorByte is for 4 color pictures so you can't use that.

Btw. Have you seen this converter. It might offer some inspiration. http://codebase64.org/doku.php?id=base:double_screen_horizontal..
2012-02-27 21:57
TWW

Registered: Jul 2009
Posts: 541
Ok.

Improvement suggestion: Wouldn't it be cool if you could use the getMCByte on only a part (say a 4x8 pixel block) when you have the BG and the block collors defined 8-D


But then ofcourse Cruizer had done this before. Anyway I like playing around with this to think a little more "scripted".

Now that I know you need to aproach this pixel by pixel it shouldn't be too tough. If it is, atleast there is some inspiration to be found.
2012-02-29 00:13
TWW

Registered: Jul 2009
Posts: 541
Ok, Done. There is definately a lot of improvement potential here but it works.

Thanx for the pointers.


    .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

    }


EDIT: Fixed some bugs and small optimalizations.
2012-04-13 16:09
Total Chaos

Registered: Mar 2006
Posts: 74
Since I'm stupid I don't get where do I put filename and addresses into that one?

Also, could it be modified to handle other size bitmaps (like 348 pixels wide)?

Please talk to me like I'm a 5-year old...

//TC
2012-04-13 18:38
andym00

Registered: Jun 2009
Posts: 44
The very first line of the macro contains the parameters you need to pass in..
.macro PNGtoKOALA(PNGpicture,BMPData,Chardata,D800data,BGC)

So filename and 4 sets of addresses for the respective components of the bitmap..
2012-04-13 19:22
Total Chaos

Registered: Mar 2006
Posts: 74
.macro PNGtoKOALA(PNGpicture,BMPData,Chardata,D800data,BGC)

PNGpicture=name
or just replace it?
2012-04-14 07:25
Total Chaos

Registered: Mar 2006
Posts: 74
PNGtoKOALA(PNGpicture=320x200.png,BMPData=$2000,Chardata=$4000,D800data=$5000,BG C=$6000)
PNGtoKOALA(PNGpicture=320x200.png,BMPData=2000,Chardata=4000,D800data=5000,BGC=6 000)
PNGtoKOALA(320x200.png,$2000,$4000,$5000,$6000)

none of these worked



2012-04-14 09:18
andym00

Registered: Jun 2009
Posts: 44
:PNGtoKOALA("320x200.png", $2000,$4000,$5000,$6000)
2012-04-14 10:36
Total Chaos

Registered: Mar 2006
Posts: 74
Didn't work.
2012-04-17 00:47
TWW

Registered: Jul 2009
Posts: 541
Any chance you could be a little more specific?

Are you sure you have the same RGB values?
Do you get any error messages?
How do you verify it doesen't work if there are no errors?


EDIT: I also posted this code on codebase (Down for maintenance right now) and I am unsure if I made any fixes to it there compared with this one. The codebase one should be the best one atleast (There was some bug I rectified but can't remeber what).
2012-04-17 05:38
Total Chaos

Registered: Mar 2006
Posts: 74
I did warn you I was stupid ;)

The error I get is non-specific, it just says "Error on line .." and it's on the first line of the macro:

// .macro PNGtoKOALA(PNGpicture,BMPData,Chardata,D800data,BGC) {
.macro PNGtoKOALA("320x200.png", $2000, $5000, $6000, $7000) {

parsing
//----------------------------------------------------------

// .macro PNGtoKOALA(PNGpicture,BMPData,Chardata,D800data,BGC) {
.macro PNGtoKOALA("320x200.png", $2000, $5000, $6000, $7000) { <-- Row 81
^

Error: Syntax error
at line 81, column 32 in C:\c64\sources\www.asm

But to be honest, I did not get the Are you sure you have the same RGB values?
I just copy/paste'ed from codebase...

So, I need to set that up first? (and where will I find this info?)

//Total Chaos aka Dumbass
2012-04-17 08:48
Cruzer

Registered: Dec 2001
Posts: 1048
Total Chaos: You seem to have replaced the definition of the macro with the parameters used for calling it. So change it back to:
.macro PNGtoKOALA(PNGpicture,BMPData,Chardata,D800data,BGC) {
And call it with:
:PNGtoKOALA("320x200.png", $2000, $5000, $6000, $7000)

2012-04-17 11:49
Total Chaos

Registered: Mar 2006
Posts: 74
Yes! That was it.. (bangs head on table)
Now to figure out the hash-table-thingy-rgb-stuff...

Thanks guys
2012-10-21 00:37
TWW

Registered: Jul 2009
Posts: 541
    // VICE C64 PALETTE
    .struct RGB {r,g,b}  // Based on standard vice colors
    .const black   = RGB(  0,  0,  0) // #$000000
    .const white   = RGB(255,255,255) // #$FFFFFF
    .const red     = RGB(137, 64, 54) // #$894036
    .const cyan    = RGB(122,191,199) // #$7ABFC7
    .const purple  = RGB(138, 70,174) // #$8A46AE
    .const green   = RGB(104,169, 65) // #$68A941
    .const blue    = RGB( 62, 49,162) // #$3E31A2
    .const yellow  = RGB(208,220,113) // #$D0DC71
    .const l_brown = RGB(144, 95, 37) // #$905F25
    .const d_brown = RGB( 92, 71,  0) // #$5C4700
    .const l_red   = RGB(187,119,109) // #$BB776D
    .const d_grey  = RGB( 85, 85, 85) // #$555555
    .const grey    = RGB(128,128,128) // #$808080
    .const l_green = RGB(172,234,136) // #$ACEA88
    .const l_blue  = RGB(124,112,218) // #$7C70DA
    .const l_grey  = RGB(171,171,171) // #$ABABAB

    .const Black   =   black.r * 65536 +   black.g * 256 +   black.b
    .const White   =   white.r * 65536 +   white.g * 256 +   white.b
    .const Red     =     red.r * 65536 +     red.g * 256 +     red.b
    .const Cyan    =    cyan.r * 65536 +    cyan.g * 256 +    cyan.b
    .const Purple  =  purple.r * 65536 +  purple.g * 256 +  purple.b
    .const Green   =   green.r * 65536 +   green.g * 256 +   green.b
    .const Blue    =    blue.r * 65536 +    blue.g * 256 +    blue.b 
    .const Yellow  =  yellow.r * 65536 +  yellow.g * 256 +  yellow.b
    .const L_brown = l_brown.r * 65536 + l_brown.g * 256 + l_brown.b
    .const D_brown = d_brown.r * 65536 + d_brown.g * 256 + d_brown.b
    .const L_red   =   l_red.r * 65536 +   l_red.g * 256 +   l_red.b
    .const D_grey  =  d_grey.r * 65536 +  d_grey.g * 256 +  d_grey.b
    .const Grey    =    grey.r * 65536 +    grey.g * 256 +    grey.b
    .const L_green = l_green.r * 65536 + l_green.g * 256 + l_green.b
    .const L_blue  =  l_blue.r * 65536 +  l_blue.g * 256 +  l_blue.b
    .const L_grey  =  l_grey.g * 65536 +  l_grey.g * 256 +  l_grey.b




I should have posted this earlier :-)
2013-08-11 15:48
TWW

Registered: Jul 2009
Posts: 541
Necro thread but just to let anyone interested know, I've added a macro alowing you to load up your HiRes PNG pictures as well on codebase:

http://codebase64.org/doku.php?id=base:kick_assembler_macros&#l..
2015-05-29 19:36
xIII

Registered: Nov 2008
Posts: 210
necro thread v2

Can some1 add this list to the kickasm source at codebase ?
2015-05-31 19:37
TWW

Registered: Jul 2009
Posts: 541
I added the collor definition listing to codebase. I do however recomend looking at the routine by Pantaloon as it allows more flexibility.
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Acidchild/Padua
kbs/Pht/Lxt
TheRyk/MYD!
Sentinel/Excess/TREX
Guests online: 121
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Memento Mori  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Wafer Demo  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Organizers
1 Burglar  (9.9)
2 Sixx  (9.8)
3 hedning  (9.7)
4 Irata  (9.7)
5 MWS  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.085 sec.