Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: leafy on February 03, 2011, 09:46:50 pm

Title: RLE compression
Post by: leafy on February 03, 2011, 09:46:50 pm
I'e searched it up, but i can't find out how to compress tilemaps using RLE.  I saw how to decompress using the routine though.
Title: Re: RLE compression
Post by: ztrumpet on February 03, 2011, 10:25:01 pm
Here, [ctrl] [f] "RLE" on this page: http://ourl.ca/7818

Good luck! ;D
Title: Re: RLE compression
Post by: leafy on February 03, 2011, 10:47:48 pm
Yeah I saw that, but it stores the compressed map into an appvar - How do I just get it to display the compressed map data?
EDIT: NEVAR MIND I SEE.
Title: Re: RLE compression
Post by: leafy on February 04, 2011, 12:04:54 pm
How do you determine the size of the compressed map beforehand? I keep getting gibberish when i try to compress a 18 by 12 tilemap
Title: Re: RLE compression
Post by: ztrumpet on February 04, 2011, 04:13:22 pm
Which routine are you using?
Title: Re: RLE compression
Post by: leafy on February 04, 2011, 06:03:18 pm
This one http://www.omnimaga.org/index.php?PHPSESSID=42e30a9bce8fdd375ed37eb181ff9432&topic=1532.msg50859#msg50859
Title: Re: RLE compression
Post by: nemo on February 04, 2011, 06:06:37 pm
This one http://www.omnimaga.org/index.php?PHPSESSID=42e30a9bce8fdd375ed37eb181ff9432&topic=1532.msg50859#msg50859

you could fill a safe ram area with 0's and then rather than export to an appvar, export to the safe ram and then use length([saferam]). or you just could keep a byte counter, everytime you write to the appvar, increment the counter accordingly.
Title: Re: RLE compression
Post by: leafy on February 04, 2011, 06:09:11 pm
I don't quite get it - could you write some pseudocode or something?
Title: Re: RLE compression
Post by: nemo on February 04, 2011, 06:11:20 pm
actually, just kidding. my routine already keeps track of the size. variable D should contain the size.
Title: Re: RLE compression
Post by: leafy on February 07, 2011, 02:01:06 am
Wait, you create the str1 appvar BEFORE D is calculated - so how does this work again?
Title: Re: RLE compression
Post by: Builderboy on February 07, 2011, 02:03:16 am
Try instead of creating the appvar beforehand, compressing the map into L1, or a large piece of memory.  After you finish compression, you know the size and you can create the right sized appvar :)
Title: Re: RLE compression
Post by: leafy on February 07, 2011, 02:04:18 am
So store compressed map into L1 --> Create appvar with size D --> Store L1 into appvar?
Title: Re: RLE compression
Post by: Builderboy on February 07, 2011, 02:07:48 am
Yep, that should work :) That is, are you able to write the compression routine in itself?  or do you need some pointers?
Title: Re: RLE compression
Post by: leafy on February 14, 2011, 08:35:36 pm
Okay, I modified Nemo's compression routine so it works fine except for one thing - it glitches whenever there are more than 16 of any hexadecimal value in a row, at which point it reads off the hex string into char randomness.
How to fix?
Title: Re: RLE compression
Post by: nemo on February 15, 2011, 12:12:37 am
Okay, I modified Nemo's compression routine so it works fine except for one thing - it glitches whenever there are more than 16 of any hexadecimal value in a row, at which point it reads off the hex string into char randomness.
How to fix?

the routine compresses data into two nibbles. the first is frequency, the second is the tile number. though that shouldn't be happening because my routine does check to see if you're trying to put more than 14 (why 14? i can't say, i wrote that a long time ago.) into frequency. if you can give me uncompressed and compressed data, i could better identify the bug.
Title: Re: RLE compression
Post by: leafy on February 25, 2011, 10:28:10 pm
.ROUTINE
mapdata->GDB1

"0123456789ABCDEF"->Str1
"Str1"->Str2
0->C->D
For(G,0,23)    .23 is the size of the map minus one.
If {GDB1+G}->A={GDB1+G+1} and (C!=14)  . "!=" is the does not equal sign
C+1->C
Else
{Str1+C+1}->{L1+D}
{Str1+A}->{L1+D+1}
D+2->D
0->C
End
End
GetCalc(Str2,C)->M
Copy(L1,M,C)
Return

But when there's more than 16 of any character it screws up. I think this could be solved, for instance, if there were 20 zeros just make it F040 or something.
Title: Re: RLE compression
Post by: nemo on February 26, 2011, 03:36:59 pm
.ROUTINE
mapdata->GDB1

"0123456789ABCDEF"->Str1
"Str1"->Str2
0->C->D
For(G,0,23)    .23 is the size of the map minus one.
If {GDB1+G}->A={GDB1+G+1} and (C!=14)  . "!=" is the does not equal sign
C+1->C
Else
{Str1+C+1}->{L1+D}
{Str1+A}->{L1+D+1}
D+2->D
0->C
End
End
GetCalc(Str2,C)->M
Copy(L1,M,C)
Return

But when there's more than 16 of any character it screws up. I think this could be solved, for instance, if there were 20 zeros just make it F040 or something.

that's because this compresses into a tilemap where the first nibble is the length of the run, and the second nibble is the tile number. it shouldn't mess up for a run of length 16+. it should mess up if you have more than 16 tiles, yes.
here's a modified routine [untested] which will RLE compress map data when you have < 256 tiles and the length of the runs are < 256.
Code: [Select]
.COMPRESSION
mapdata->GDB1
"0123456789ABCDEF"->Str1
0->C->D
For(I,0,XX) .XX is the size of the uncompressed map minus 1.
If {GDB1+I}->A={GDB1+I+1} and I != XX
C+1->C
Else
Copy(C>Hex,L1+D,2)
Copy(A>Hex,L1+2+D,2)
D+4->D
0->C
End
End
GetCalc("Str1",D)->A
Copy(L1,A,D)

excuse me if it's inefficient, i haven't coded in axe in awhile.