Author Topic: RLE compression  (Read 8853 times)

0 Members and 1 Guest are viewing this topic.

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: RLE compression
« Reply #15 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.
In-progress: Graviter (...)

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: RLE compression
« Reply #16 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.