riuson / lcd-image-converter

Tool to create bitmaps and fonts for embedded applications, v.2
https://lcd-image-converter.riuson.com/
GNU General Public License v3.0
337 stars 80 forks source link

RLE Compressor improvement #31

Closed riuson closed 10 years ago

riuson commented 10 years ago

From onwards....@gmail.com on August 12, 2014 04:29:30

What steps will reproduce the problem? 1. Load an image (a photo is a good demo for this, attached my demo pic)

  1. Convert image with RLE on
  2. Count number of sequences
  3. Note filesize
  4. Modify rlecompressor.cpp with this line and repeat steps 1. thru 4.

line 86: -- if (!this->allEquals(&queue) && queue.last() == value) ++ if (!this->allEquals(&queue) && queue.last() == value && queue.last() == input->at(i+1))

results are (from attached image): Original (no code mod) (min size = 2) total sequences+nonsequences = 10781 filesize = 75218 values

Min size = 3 (attached code mod) total sequences+nonsequences = 4321 filesize = 72318 values

Min size = 4 total sequences+nonsequenes = 2783 filesize = 72493 values

A min size of 3 seems to have advantages not just in file size, but also in time to decompress (less sequences = less operations as use a single memcpy() or memset() for each sequence. I was getting less than half the time to decompress on my micro as soon as I went to min=3! As you go to min size of 4.. as you would expect file size starts getting bigger as you get closer to an uncompressed image, and less gains from reduction of number of sequences for decompression time. Not sure if its worth making the min size user settable, but a min size of 3 by default would seem to be worth it.

Please note: my test code has no bounds check on i, it could be addressing past the end of the input list as i approaches the end which may cause problems on some images. What version of the product are you using? On what operating system? Develop version on Windows 7. 16 bit, Color R5G6B5, RLE Please provide any additional information below. Manual example: 1122456888 could be: 2,1,2,2,-3,4,5,6,3,8 or -7,1,1,2,2,4,5,6,3,8

Second one is much faster to decompress as a single memcpy() and a memset instead of 3x memset() + a memcpy() + loading each sequence. Obviously you get less compression however as you start to increase min seq size.

Attachment: DSC06933 crop 320x240.png

Original issue: http://code.google.com/p/lcd-image-converter/issues/detail?id=31

riuson commented 10 years ago

From riu...@gmail.com on August 13, 2014 00:51:01

Try this revision https://code.google.com/p/lcd-image-converter/source/detail?r=c8e21f2a7c578ba39e44ce11cb205ba0df3e7907&name=develop Options -> Conversion -> Image -> RLE min count

Status: Started
Owner: riu...@gmail.com

riuson commented 10 years ago

From onwards....@gmail.com on August 19, 2014 16:37:28

Revision works well, images decompress well and am seeing speed/size improvements with all images and fonts with RLE min count = 3.

Thanks! :-)

riuson commented 10 years ago

From riu...@gmail.com on August 19, 2014 23:34:32

Status: Fixed