phoboslab / qoi

The “Quite OK Image Format” for fast, lossless image compression
MIT License
6.97k stars 330 forks source link

SIMD Encoder : an AVX2 implementation #143

Closed MKCG closed 2 years ago

MKCG commented 2 years ago

Hello, this pull request implements an AVX2 based encoder.

It also introduces a new structure named qoi_encoder_t that could be use to implement a streaming encoder.

When encoding the images provided on the official website, I get those results :

branch type encode ms encode mpps branches branches misses
master any 14.4 157.28 28 137 276 765 1 492 397 899
this pull request any 7.9 284.32 11 348 182 313 714 559 161
master RGB 40.0 132.31 21 054 094 125 1 322 613 445
this pull request RGB 23.0 229.90 9 418 298 665 633 968 387
master RGBA 3.4 281.22 7 080 735 865 172 313 079
this pull request before 2672a47 RGBA 1.8 524.59 1 834 707 343 79 617 576
this pull request after 2672a47 RGBA 1.5 648.99 1 880 977 270 79 359 904

Note: 2672a47 avoids performing cpu intensive operations when the next 8 pixels belong to the same run. Only images with flat surfaces like screenshots will benefit from it.

Note: RGB images are a bit tricky to encode using AVX2 instructions, and this implementation can still be improved.

MKCG commented 2 years ago

My PHP library use a C library defining a chunk based encoder to lower the memory footprint : https://github.com/MKCG/php-qoi/blob/main/src/FFI/lib/qoi.c#L112

I will probably open a pull request here to implement a streaming encoder.

phoboslab commented 2 years ago

This is very cool, but I'm sorry to say that I will not merge it. I want this "reference" encoder here to stay as simple as possible. Also, I neither have the expertise nor the desire to maintain this SIMD implementation.

If you publish your encoder under a different name (fastqoi? rapidqoi? simdqoi?) I will happily mention it in the readme here!

MKCG commented 2 years ago

Actually I add little hope that it would be accepted since I already knew you weren't very familiar with AVX2 instructions from a previous comment on the final specification thread.

"simdqoi" would work for me, that would be a nice tribute to the amazing work of Daniel Lemire, Geoff Langdale and so many others. I guess that now I also have to make an AVX2 based decoder before publishing it.

Thanks for your time.