1
Lua / [Library] Compress
« 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
Changelog: http://ourl.ca/19010/351502
Version 0.0.3 :
https://mega.co.nz/#!UxYBAZQR!BfvEC079-PEB0j98wG58RGjTjJRrt4GDA5xsJMV1KYY
Changelog: http://ourl.ca/19010/350707
Version 0.0.2 :
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
Converts every image in img/ to lua files in 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)
If your path selector targets non image file, an error will be thrown.
Example :
Version 0.0.1 :
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".
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
Changelog: http://ourl.ca/19010/351502
Version 0.0.3 :
https://mega.co.nz/#!UxYBAZQR!BfvEC079-PEB0j98wG58RGjTjJRrt4GDA5xsJMV1KYY
Changelog: http://ourl.ca/19010/350707
Version 0.0.2 :
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
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".