This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's z80 & ez80 Assembly subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. Z80 & 68k Assembly => z80 & ez80 Assembly
Author Message
hotdog1234


Advanced Member


Joined: 14 Aug 2009
Posts: 291

Posted: 17 Oct 2009 08:42:30 pm    Post subject:

Where can I get information on basic data compression and decompression? I don't need code, just information on compression bit-level wise.
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 17 Oct 2009 09:28:25 pm    Post subject:

Go to ticalc.org, and search ezcmp. It should be the first one on the list. Read how the method works. It can be used recursively, so you could take an entire 16384 byte app page, and turn it into 1/4 of a page. Since you know you are working with 16384 bytes, then you should be able to make it run, say, 50 times. You would not have to store the first 3 bytes it asks for. This is for SAD?
Back to top
hotdog1234


Advanced Member


Joined: 14 Aug 2009
Posts: 291

Posted: 17 Oct 2009 09:46:40 pm    Post subject:

Quote:
This is for SAD?


At least the graphics portion of it. For the moment, I'm putting it to use in the campaign designer
Back to top
Mapar007


Advanced Member


Joined: 04 Oct 2008
Posts: 365

Posted: 17 Oct 2009 11:42:00 pm    Post subject:

You could ask Darkstone Knight, he's been developing a lz77/Huffman coding compression method for one of his games.
Back to top
cjgone
Aw3s0m3


Active Member


Joined: 24 May 2006
Posts: 693

Posted: 18 Oct 2009 10:09:27 pm    Post subject:

Huffman compression is pretty easy compared to other methods and fairly optimal. It requires knowledge of how binary trees work; the steps to use it are fairly straightforward.


The idea is that by finding the frequencies of how often a letter appears in something, you can use these frequencies and a natural order (look this us, a priority queue) and make one binary tree that holds all the letters. You can make a binary code by adding a 1 to every left you take on the tree and a 0 for every right (i don't think it matters if left =0 and right =1).

So in the pic below:

h = 011

a = 01

every letter has a unique binary code and by putting it all together, you can use mutiple letters to make up one byte. So a = 01, thats like 2-bits, so four 'a's is one byte instead of 4 bytes.

more common words are higher up in the tree thru natural order, you have to look that up.


In the pic below is a tree of letter frequencies and the binary value 0 or 1 associated with each one. This is not the correct assemblage of a tree, the method to do so is defined a million times online tho.


It goes something like this tho:

You put a structure or node that contains the letter and its frequency for each character into something called a priorty queue, where thru ordering when you take out the nodes\structures they're in the "natural order". Now you take 2 nodes out, create a new tree combining them and you put it back into the queue and you continue to assemble all the nodes into one whole tree.


Last edited by Guest on 18 Oct 2009 10:27:52 pm; edited 1 time in total
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 18 Oct 2009 10:27:20 pm    Post subject:

Huffman kinda depends on the data being compressed. If you don't use 256 different bytes, huffman is the way to go. If there is just a little over 15 bytes, the one mentioned before is great. If you understand huffman, and think you can do it in asm, then go for it!!
Back to top
cjgone
Aw3s0m3


Active Member


Joined: 24 May 2006
Posts: 693

Posted: 18 Oct 2009 10:32:50 pm    Post subject:

Meh, making a binary tree in assembler doesn't seem to bad other then having to like dynamically allocate memory for nodes.. You could pre define it all tho ;)

A general look would be

Code:
HuffmanNode:
.db letterascii
.db frequency
.dw left_node
.dw right_node


It would be hella tedious tho.

Alternatively, I would reccomend writing the program that does the compression on comp and decompressor on calc.

No idea what grahps method or proposal was tho.. Sounds good too. I'd say Huffman is fairly decent for ur method if you got some datas to compress.


Last edited by Guest on 18 Oct 2009 10:42:23 pm; edited 1 time in total
Back to top
hotdog1234


Advanced Member


Joined: 14 Aug 2009
Posts: 291

Posted: 18 Oct 2009 10:32:58 pm    Post subject:

Huffman is not my intention...I think I'll probably end up doing my own compression routine.
Back to top
cjgone
Aw3s0m3


Active Member


Joined: 24 May 2006
Posts: 693

Posted: 18 Oct 2009 10:38:54 pm    Post subject:

^Your own compression routine? O_OOO_O_O

lol, stick with the already done routines bro, it'll be the most worthwhile time wise anyway.\


There's also another way that finds repeating phrases and searches thru teh data and replaces them with less data thru a table. Which has already been defined too, but it might be slow on a calc.

Write a decompressor on the calc and the compressor on ur comp. That's be the best way.


Last edited by Guest on 18 Oct 2009 10:41:23 pm; edited 1 time in total
Back to top
cjgone
Aw3s0m3


Active Member


Joined: 24 May 2006
Posts: 693

Posted: 18 Oct 2009 10:43:30 pm    Post subject:

You can be extremely cool and find an already written compressor that outputs the compressed data and a necessary lookup table, and then just write a simple decompressor on the calc that uses the lookup table to do the easy find and replace.
Back to top
hotdog1234


Advanced Member


Joined: 14 Aug 2009
Posts: 291

Posted: 19 Oct 2009 01:12:34 am    Post subject:

Quote:
stick with the already done routines bro, it'll be the most worthwhile time wise anyway.


I realize that, but that doesn't mean it's the best. Anyways, I'm doing something similar to run-length encoding, since it has what I'm looking for. Please, please let me know what you guys think--suggestions, approval, etc. Oh, and this is for buildings, units and splash screens, not tiles and program data:

First two bits: Type of compression

00 = No compression of image
01 = White pixels are scattered, but there are lots of patches of black pixels
10 = Black pixels are scattered, but there are lots of patches of white pixels
11 = There are large patches of both black and white pixels

Next Bit: 0 if X = 2 or 1 if X = 3 (more on that later, this is used for additional saving of space depending on how big white or black patches are)

These three bits appear only at the beginning of the file, and do not appear anywhere else, the method is used for the rest of the image.

Method:

As an example, I'll use white pixels scattered and patches of black pixels, such as a black sky with stars. The scattered color is drawn with 1 bit for each pixel, so you would have 00000000 for eight white pixels. For a large patch/line with black pixels, the bit is 1, followed by X bits (in this case, X = 3) telling how many bits it takes to give the length of the black line. So if a black line 64 pixels long is drawn, the first bit is 1, followed by 101 meaning it takes 6 bits to say the length of the line is 64 pixels long. This means the line is stored into 1.25 bytes as opposed to 8 bytes.

For each image I plan to add, I'll test it with all the different compression possiblities and see which is the smallest, and the first 3 bits for that particular image will be determined by the smallest compression possible. The campaign designer will do the same thing.

It is for decompression reasons that the calculator will have a loading screen when S.A.D. is loading data before a game...it keeps the user occupied


Last edited by Guest on 19 Oct 2009 01:17:22 am; edited 1 time in total
Back to top
cjgone
Aw3s0m3


Active Member


Joined: 24 May 2006
Posts: 693

Posted: 19 Oct 2009 05:23:35 pm    Post subject:

If you're just trying to compress ur home screen and big pics with all that black space, you can pretty eassily do that with find and repalce methods.
Back to top
hotdog1234


Advanced Member


Joined: 14 Aug 2009
Posts: 291

Posted: 19 Oct 2009 06:01:40 pm    Post subject:

Quote:
If you're just trying to compress ur home screen and big pics with all that black space, you can pretty eassily do that with find and repalce methods.


I'll have to see if that method saves as much space. While I'm trying not to be obsessed about keeping pictures small, we do have to consider regular Ti-83+ people
Back to top
cjgone
Aw3s0m3


Active Member


Joined: 24 May 2006
Posts: 693

Posted: 20 Oct 2009 01:23:04 am    Post subject:

Archive run your game thru mirageos if memory is a big deal?
Back to top
hotdog1234


Advanced Member


Joined: 14 Aug 2009
Posts: 291

Posted: 20 Oct 2009 01:52:54 am    Post subject:

Quote:
Archive run your game thru mirageos if memory is a big deal?


I don't know if you understand, we're not talking physical memory and a small program. We're talking a 5-6 page application without compression, and a Ti-83+ only holds 10 pages. Add that to the fact that a campain can take 56 KB uncompressed, map packs (add-ons) can take 16 KB uncompressed, and tile packs (also addons) can take 8-16 KB uncompressed. (Which is why some maps and the campaign itself are going to be included as add-ons)

I know you're trying to help me in terms of compression and help me discover the easy ways, and I can't tell you how much I appreciate that, especially since you know more about ASM than I do. But since S.A.D. has been in planning for about two months now, I have a lot of knowledge of the ins and outs of it. You can believe me when I say it needs the best compression it can get.

Not that I don't like your ideas...I actually plan to use something similar to search-and-replace for tilemap compression, and something similar to Huffmann for Campaign text. But for each method I'm trying to find the smallest compression possible, so that people can enjoy a game without having to worry about lack of space. I'm hoping that the game will be enjoyed so much that people won't give a darn about space, but I don't want to take that chance.


Last edited by Guest on 20 Oct 2009 12:06:32 pm; edited 1 time in total
Back to top
FloppusMaximus


Advanced Member


Joined: 22 Aug 2008
Posts: 472

Posted: 20 Oct 2009 06:20:23 pm    Post subject:

Try lots of different techniques. You may find that some of them work better than you expect.

Using (classical, non-adaptive) Huffman coding is easy to decompress, and gives a modest amount of compression for many different kinds of data, so don't be too quick to dismiss it. It's common to use some form of Huffman coding in *addition* to an LZ-like algorithm.

It's perfectly fine to try to invent your own algorithms - take advantage of the particular redundancies of your data set. But then try them out and see how they compare to the more established algorithms.

Remember, too, that the only things that should concern you are the compression ratio and the size and speed of the decompressor. If it takes an hour to compress the data on the PC, who cares?
Back to top
briandm03


Newbie


Joined: 25 May 2009
Posts: 4

Posted: 21 Oct 2009 06:39:45 pm    Post subject:

Im sure you've already found this file, but search for compression techniques at ticalc. This is how i learned the basics of compression, many thanks to the author!
Back to top
hotdog1234


Advanced Member


Joined: 14 Aug 2009
Posts: 291

Posted: 21 Oct 2009 07:39:51 pm    Post subject:

Briandm03, you hit the nail on the head! THANKS! That was JUST the file I needed, but couldn't find and no one else suggested. Now I don't have to come up with my own routines!

I just have to work out which routines to use now. I'm probably going to use SRLE for maps and Huffman for Campaign text, both of which have routines. As for sprites and full-sized pics, I'll have to experiment with different solutions I found.

EDIT: I'm looking at Levi Lansing's bmp2asm converter, which only works for full-sized ti-86 pictures. Since I like the compression ratio, and understand the concept, I'll probably use a modified verion of his decompressor and end up writing my own compressor using his technique.


Last edited by Guest on 21 Oct 2009 07:52:59 pm; edited 1 time in total
Back to top
darkstone knight


Advanced Member


Joined: 07 Sep 2008
Posts: 438

Posted: 22 Oct 2009 04:20:46 pm    Post subject:

Mapar007 wrote:
You could ask Darkstone Knight, he's been developing a lz77/Huffman coding compression method for one of his games.

Good Idea

annyway: im using this algorithm:
http://en.wikipedia.org/wiki/LZ77_and_LZ78

its pretty... effective, it seems to give over 50% compression wihit semi-ramdom data, i guess il post the code here once i finish the decompressor (the compressor is already done, it outputs .db $xx,$xx.... to a string)

haufman is pretty easy to implement, in my situation it gimes me 60% compression, pretty impressive for someting that is 50 lines of code and a 30-byte LUT
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 22 Oct 2009 06:01:07 pm    Post subject:

Hmmm. Is Lz77 the same as zlib .zip compression? It looks like it works the same way.
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    » Goto page 1, 2  Next
» View previous topic :: View next topic  
Page 1 of 2 » All times are UTC - 5 Hours

 

Advertisement