-
Notifications
You must be signed in to change notification settings - Fork 619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TGA: RLE encoding #2056
TGA: RLE encoding #2056
Conversation
Looking at this code, I wonder whether it would make sense to do a prepass over the image to determine whether RLE compression would produce a smaller output than storing the pixels uncompressed. With that logic implemented, it might even make sense to not even expose the |
Even in run-length encoded TGA images there can be packets without RLE (high bit = 0). Could look like this: [RLE packet header with counter = 4] PIXEL |
I think we should probably add raw packets then. Having your RGB image 0.3% larger because you enabled compression is probably OK, while having it become 33% larger is more frustrating |
Got it working, I think. My (very noisy) test image now only goes to 8.8 MB, instead of 10.8 MB. |
Could you make RLE the default but instead of removing uncompressed encoding, swap the builder method to be |
Changed enable_rle to disable_rle
…/image-rs into feat/tga/rle-encoding
This should be it! I added another test to make sure RLE is used by default, and that disabling it increases the encoded size of an embarrassingly compressible example image. |
I license past and future contributions under the dual MIT/Apache-2.0 license,
allowing licensees to choose either at their option.
This is my first pass of RLE encoding support for TGA encoding. It currently supports ImageType::RunTrueColor and ImageType::RunGrayScale.
Here's a run down:
Header::from_pixel_info
to support anuse_rle
flag and set image_type accordinglyuse_rle
to enable RLE on aTgaEncoder
TgaEncoder::new
defaults to rle = falseTgaEncoder::write_rle_encoded_packet
to write a run-length encoded packet (high bit = 1) to a writerTgaEncoder::run_length_encode
which does the actual run-length encodingTgaEncoder::encode
to check for the RLE flag and then use RLEround_trip_bw
), I added a test file inside thetests/
folder, I hope that's okayConsiderations
RunColorMap
falls back to uncompressed encoding... should this throw an Unsupported error, because it does not fulfill user expectations?