Register | Login | |||||
Main
| Memberlist
| Active users
| Calendar
| Chat
| Online users Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album |
| |
0 users currently in Programming. |
User | Post |
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 |
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! |