Omnimaga

Calculator Community => TI Calculators => Lua => Topic started by: Morhaus on June 01, 2013, 04:02:18 pm

Title: [Library] Compress
Post by: Morhaus on June 01, 2013, 04:02:18 pm
Hey guys.

The default image format TI uses doesn't have any compression, which results in very slow loadings and big file size. I've written a small library which allows to compress images or data on your computer and decompress it in Lua on the calculator.

Decompressing in Lua might seem a bit overkill but it actually works out quite nicely, and I've experienced substantial gains in loading speed and file size.

Currently, only two algorithms are supported : RLE (Run-length encoding) and LZW (Lempel-Ziv-Welch). RLE tends to produce lighter files, but they also tend to load slower than those produced by LZW.

The library is located in src/compress.lua. You can use packages lzw.py, rle.py, lua.py and image.py to compress your data or your images. The convert.py utility allows for fast conversion between any image format to lua or tns files. Examples of use can be found below.
The image.py package requires ImageMagick to be installed on your computer and the 'convert' and 'identify' utilities to be in your PATH.
In order to produce tns files, the convert.py package requires luna to be installed on your computer and the 'luna' executable to be in your PATH.

Version 0.0.4 :
https://mega.co.nz/#!owxVXbAQ!MPb4JRfuZbVcEriqC6IqsUbJRjdcQw9CMYDzvEuwahc (https://mega.co.nz/#!owxVXbAQ!MPb4JRfuZbVcEriqC6IqsUbJRjdcQw9CMYDzvEuwahc)
Changelog: http://ourl.ca/19010/351502 (http://ourl.ca/19010/351502)

Version 0.0.3 :
https://mega.co.nz/#!UxYBAZQR!BfvEC079-PEB0j98wG58RGjTjJRrt4GDA5xsJMV1KYY (https://mega.co.nz/#!UxYBAZQR!BfvEC079-PEB0j98wG58RGjTjJRrt4GDA5xsJMV1KYY)
Changelog: http://ourl.ca/19010/350707 (http://ourl.ca/19010/350707)

Version 0.0.2 :
https://mega.co.nz/#!w8hTnIJB!SDoEbCshxMgHZbV3bNXFcxCMy-0d9H3iK7fUiFTpoZ8 (https://mega.co.nz/#!w8hTnIJB!SDoEbCshxMgHZbV3bNXFcxCMy-0d9H3iK7fUiFTpoZ8)

Changelog :
- image.py now uses ImageMagick instead of PIL. It's a bit slower, but should produce a better output and it allows more control on the output. As a consequence, it now requires ImageMagick to be installed on your system and the 'convert' and 'identify' utilities to be in your PATH.
- example.py renamed to convert.py, now takes command line arguments to allow automatic generation of lua or tns files. TNS file generation requires luna to be installed on your system and to be in your PATH.
- lzw.decompress and rle.decompress (lua) now take a table as an optional third argument. It allows to prepend a header directly onto the output instead of concatenating strings.

Examples :
Display help message
Code: [Select]
python convert.py -h
Converts every image in img/ to lua files in lua/
Code: [Select]
python convert.py img/* -o lua/
Converts every png and gif image in img/ to tns files in the same directory, restricted to a palette of 128 colors (default is 256)
Code: [Select]
python convert.py --tns -c 128 img/*.png img/*.gif
If your path selector targets non image file, an error will be thrown.
Example :
Code: [Select]
python convert.py passwords.txt
Traceback (most recent call last):
  File "convert.py", line 23, in <module>
    image = Image(path, colors=args.colors)
  File "/Users/alexandre/Projets/compress/image.py", line 17, in __init__
    raise Exception(stderr_output)
Exception: identify: no decode delegate for this image format `passwords.txt' @ error/constitute.c/ReadImage/550.

Version 0.0.1 :
https://mega.co.nz/#!UwhnDRAJ!Tuad9XC01kTMPOZRa7DztkY7okJrhJ7NgMElQwSm8GQ (https://mega.co.nz/#!UwhnDRAJ!Tuad9XC01kTMPOZRa7DztkY7okJrhJ7NgMElQwSm8GQ)

The library is located in src/compress.lua. You can use packages lzw.py, rle.py, lua.py and image.py to compress your data or your images. Examples can be found in example.py and src/example.lua.
The image.py package requires the PIL to be installed on your computer. If you already have Python 2.7.3/3.X, you can install it via "pip install pillow".
Title: Re: [Library] Compress
Post by: Jim Bauwens on June 01, 2013, 04:40:45 pm
Very interesting!

I've creating a little RLE algorithm for TI.Image some time ago, but I never really used it because it was too slow to my likings. I'll definitely check this out (and look if I can help with optimizations) when I get some time after my exams ^^

Many thanks :)
Title: Re: [Library] Compress
Post by: Sorunome on June 02, 2013, 03:18:08 pm
That's looking interesting, it would indeed be pretty useful to compress some data./me wonders if it would be possible to do something similar for the z80 calcs
Title: Re: [Library] Compress
Post by: Hayleia on June 02, 2013, 03:20:43 pm
Great work, you solved the dilemma that coders were facing: great graphics or fast launch. Now they can have both.

/me wonders if it would be possible to do something similar for the z80 calcs
http://ourl.ca/9960/190945
Title: Re: [Library] Compress
Post by: ElementCoder on June 02, 2013, 03:21:44 pm
This is pretty interesting :D Now I definitely need to get back into Lua :P I'm looking forward to see more of this (and other things).
Title: Re: [Library] Compress
Post by: Morhaus on June 06, 2013, 08:07:38 am
Updated to the last version.

New download link : https://mega.co.nz/#!w8hTnIJB!SDoEbCshxMgHZbV3bNXFcxCMy-0d9H3iK7fUiFTpoZ8 (https://mega.co.nz/#!w8hTnIJB!SDoEbCshxMgHZbV3bNXFcxCMy-0d9H3iK7fUiFTpoZ8)

Changelog :
- image.py now uses ImageMagick instead of PIL. It's a bit slower, but should produce a better output and it allows more control on the output. As a consequence, it now requires ImageMagick to be installed on your system and the 'convert' and 'identify' utilities to be in your PATH.
- example.py renamed to convert.py, now takes command line arguments to allow automatic generation of lua or tns files. TNS file generation requires luna to be installed on your system and to be in your PATH.
- lzw.decompress and rle.decompress (lua) now take a table as an optional third argument. It allows to prepend a header directly onto the output instead of concatenating strings.

Examples :
Display help message
Code: [Select]
python convert.py -h
Converts every image in img/ to lua files in lua/
Code: [Select]
python convert.py img/* -o lua/
Converts every png and gif image in img/ to tns files in the same directory, restricted to a palette of 128 colors (default is 256)
Code: [Select]
python convert.py --tns -c 128 img/*.png img/*.gif
If your path selector targets non image file, an error will be thrown.
Example :
Code: [Select]
python convert.py passwords.txt
Title: Re: [Library] Compress
Post by: Morhaus on June 06, 2013, 08:36:27 am
Minor fixes, if you downloaded the last version before this post, you should download it again now.
Title: Re: [Library] Compress
Post by: Morhaus on June 12, 2013, 02:47:20 pm
New version !
https://mega.co.nz/#!UxYBAZQR!BfvEC079-PEB0j98wG58RGjTjJRrt4GDA5xsJMV1KYY (https://mega.co.nz/#!UxYBAZQR!BfvEC079-PEB0j98wG58RGjTjJRrt4GDA5xsJMV1KYY)

Changelog :
Title: Re: [Library] Compress
Post by: DJ Omnimaga on June 13, 2013, 11:40:14 pm
Heya and welcome here! :)

That's a great tool you have here.
Title: Re: [Library] Compress
Post by: Morhaus on June 18, 2013, 03:49:25 pm
Thanks :)

New version ! 0.0.4
https://mega.co.nz/#!owxVXbAQ!MPb4JRfuZbVcEriqC6IqsUbJRjdcQw9CMYDzvEuwahc (https://mega.co.nz/#!owxVXbAQ!MPb4JRfuZbVcEriqC6IqsUbJRjdcQw9CMYDzvEuwahc)

Title: Re: [Library] Compress
Post by: imath on June 30, 2013, 12:40:37 am
seems good!