(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
05-29-24 03:13 AM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - GBA RLE Compression
  
User name:
Password:
Reply:
 
Options: - -
Quik-Attach:
Preview for more options

Max size 1.00 MB, types: png, gif, jpg, txt, zip, rar, tar, gz, 7z, ace, mp3, ogg, mid, ips, bz2, lzh, psd

UserPost
interdpth
Posts: 158/362
Before any and all help is greatly appreiciated!
Ok, so my new function kind of works but it's off badly
Here's bytes to compress
1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D
1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D
1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D7070
7070707070707070707070707070FFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FF010203040506000910BBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBAAAAAAAAAAAAAAAAFFFFFFFFFFFFFFFF
FFFFFFFFFFFF5F5F5F5F5F5F

Compressed it should look like

C01D 9070 9FFF 0801 0203 0405 0600 0910 A2BB 9AAA 8EFF 865F

What my algorithm outputs as compressed
BC1D021D1D8C700270709BFF0BFFFF0102030405060009109EB
B02BBBB84AA02AAAA8AFF02FFFF825F025F5F


Here's my function

Private Function RLComp(decmpsize As Long, Source() As Byte, Dest() As Byte)
Dim i As Long, xIn As Long, xOut As Long, tmpin As Long
Dim length As Long, ctrl As Long
Dim data As Byte, Buffer(0 To &H80) As Byte


While (decmpsize > xIn)
If tmpin = decmpsize Then Exit Function
data = Source(xIn)
xIn = xIn + 1
tmpin = xIn
Do While (Source(tmpin) = data)
tmpin = tmpin + 1
If (tmpin >= decmpsize) Then Exit Do
Loop

length = (tmpin - xIn)
If (length >= 3) Then

If (ctrl > 0) Then FLUSH_RLE ctrl, xOut, Dest(), Buffer()
length = length - 3
If (length > &H7F) Then length = &H7F
Dest(xOut) = (length + &H80)
xOut = xOut + 1
Dest(xOut) = data
xOut = xOut + 1
xIn = xIn + (length + 1)

Else
Buffer(ctrl) = data
ctrl = ctrl + 1
If (ctrl = &H80) Then FLUSH_RLE ctrl, xOut, Dest(), Buffer()



End If
Wend
If (ctrl > 0) Then FLUSH_RLE ctrl, xOut, Dest(), Buffer()
RLComp = xOut + 4
End Function


Private Function FLUSH_RLE(ByRef ctrl As Long, ByRef out As Long, ByRef Dest() As Byte, ByRef Buffer() As Byte)


Dest(out) = ctrl
out = out + 1
For i = 0 To ctrl - 1
Dest(out) = Buffer(i)
out = out + 1
Next i
ctrl = 0
End Function
HyperHacker
Posts: 1908/5072
Jeez, your variable names and comments don't explain much. I noticed you only used the variable "det" in two places, once comparing it:
If (d = det) Then 'handle repeitition
and once assigning its value to another variable:
'buffer(Rawcnt) = det
This seems like a typo, unless you've declared this elsewhere, but I don't see why you'd do that. FYI, in the options in VB's IDE is a "Require variable declaration" or some such option that will add the line "Option Explicit" to the beginning of all new files; this will make it warn you if you use a variable without defining it (Dim x as y) first. I really can't imagine what the person who decided this should be optional, let alone off by default, was thinking.

Also, might help to uncomment that last End If.
interdpth
Posts: 136/362

Top part is repeating bottom is raw data which is commented out because I have no clue how to handle that and any help would be oh so appreciated.

Private Function RLComp(decmpsize As Long, source() As Byte, dest() As Byte)
Dim i As Long, xIn As Long, xout As Long
Dim d As Byte, data As Byte, repcnt As Byte, tmpxin As Byte, PstByte As Byte
Dim buffer(1 To 128) As Byte
For xIn = 0 To decmpsize

'next byte
If (d = det) Then 'handle repeitition
data = source(xIn)
xIn = xIn + 1

Do While (source(xIn) = data)
tmpxin = tmpxin + 1
If (tmpxin >= &H7F) Then Exit Do
Loop
xIn = xIn + tmpxin
dest(xout) = &H80 + tmpxin
xout = xout + 1
dest(xout) = data
xout = xout + 1
tmpxin = 0
' Else 'raw data

' l = l + 1
' For i = 1 To l - 1 'agaxin, not sure...
' Dest(xOut) = Source(xIn)
' xOut = xOut + 1
'xIn = xIn + 1
'size = size - 1
'If size = 0 Then UnCompRL = xIn
'Next i
' Rawcnt = Rawcnt + 1
' buffer(Rawcnt) = d
' Rawcnt = Rawcnt + 1
'buffer(Rawcnt) = det
'For i = 0 To 125
'Bufe
'End If



Next xIn
End Function
HyperHacker
Posts: 1907/5072
Why not post your compression code?
interdpth
Posts: 135/362
It's outputted as binary. All I have to do is fix this and I can get level editing possible.
HyperHacker
Posts: 1900/5072
Make sure your files aren't opened in text mode. Sounds like a "no duh" thing, but I somehow manage to forget this every time I write a compression function, and it always offsets the output by 3 bytes.
interdpth
Posts: 133/362
Anychance I can see some code for handling it the code i'm using does the first compression right then the repetition code for the rest loses 3 bytes somehow. And I can't get the raw data compression to work. I need some serious help.
labmaster
Posts: 24/51


SWI 14h (GBA/NDS7/NDS9) - RLUnCompWram
SWI 15h (GBA/NDS7/NDS9) - RLUnCompVram (NDS: with Callback)
Expands run-length compressed data. The Wram function is faster, and writes in units of 8bits. For the Vram function the destination must be halfword aligned, data is written in units of 16bits.
If the size of the compressed data is not a multiple of 4, please adjust it as much as possible by padding with 0. Align the source address to a 4Byte boundary.


r0 Source Address, pointing to data as such:
Data header (32bit)
Bit 0-3 Reserved
Bit 4-7 Compressed type (must be 3 for run-length)
Bit 8-31 Size of decompressed data
Repeat below. Each Flag Byte followed by one or more Data Bytes.
Flag data (8bit)
Bit 0-6 Expanded Data Length (uncompressed N-1, compressed N-3)
Bit 7 Flag (0=uncompressed, 1=compressed)
Data Byte(s) - N uncompressed bytes, or 1 byte repeated N times
r1 Destination Address
r2 Callback parameter (NDS SWI 15h only, see Callback notes below)
r3 Callback structure (NDS SWI 15h only, see Callback notes below)

Return: No return value, Data written to destination address.




It's RLE, so it'll be really easy to write a compressor based on the data info. You've basically got two types of chunks - a byte that is repeated N amount of times (at least 3 times), or a string of N bytes that doesn't have any repeats in it.
interdpth
Posts: 127/362
Well i've been searching for a GBA compatible RLE function for VB6. I've tried converting ones I found in to to VB. The decompression method I converted from the GBAdecomp.dll if anyone would like to take a crack at the compression or could reverse the decompression function I have now. please let me know. Or if you have a proper compression algo please let me know this is very important. Thanks!
Acmlm's Board - I3 Archive - Programming - GBA RLE Compression


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.012 seconds; used 360.06 kB (max 403.63 kB)