Skip to content
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

Alpha distance #2117

Merged
merged 1 commit into from Feb 10, 2023
Merged

Alpha distance #2117

merged 1 commit into from Feb 10, 2023

Conversation

jonsneyers
Copy link
Member

Adds an option to the API to set the distance for extra channels separately, addressing #2111 .

This e.g. allows doing lossless alpha while the color is lossy, or in general to set the alpha quality independently of the color quality. We might want to experiment with this and set more sensible defaults. (Note: we can't really rely on the metrics though, since they don't really look at alpha, they just use it to blend the image to a solid background.)

Adds a parameter D to benchmark_xl and --alpha_distance to cjxl.

Flyby fix: correct the modular quantization adjustment to compensate for the actual bitdepth of extra channels (instead of assuming that all channels have the same bitdepth).

Encoding       kPixels    Bytes          BPP  E MP/s  D MP/s     Max norm  SSIMULACRA2        pnorm       BPP*pnorm   Bugs
--------------------------------------------------------------------------------------------------------------------------
jxl:d0.5          4312  1326476    2.4608889   1.247   9.371   1.46619773  93.29027781   0.32387099  0.797010517600      0
jxl:d0.5:D0       4312  1535745    2.8491264   1.296   9.113   1.52147913  93.17293088   0.29785035  0.848613285350      0
jxl:d1            4312   923797    1.7138356   1.526   9.811   2.18971467  88.25578150   0.54898038  0.940862091175      0
jxl:d1:D0         4312  1262339    2.3419014   1.246   8.648   2.03960395  88.48580332   0.50947993  1.193151755443      0
jxl:d1:D2         4312   824846    1.5302609   1.487  10.698   2.32580400  88.42132275   0.64015614  0.979605903443      0
jxl:d2            4312   630823    1.1703079   1.507   9.813   3.26052332  82.49513662   0.88900277  1.040406932615      0
jxl:d2:D4         4312   558300    1.0357626   1.391   9.768   3.80601859  82.32916682   1.01417959  1.050449298471      0
jxl:d3            4312   491437    0.9117178   1.425   7.479   4.17905045  78.08833075   1.16395135  1.061195208251      0
jxl:d3:D6         4312   434096    0.8053384   1.468   8.684   4.96663904  77.92568643   1.30559641  1.051446871010      0
Aggregate:        4312   808263    1.4994954   1.395   9.222   2.62748584  85.65005370   0.65969720  0.989212882981      0

For some images, doing alpha losslessly results in smaller files than doing it lossy, e.g.:

Encoding       kPixels    Bytes          BPP  E MP/s  D MP/s     Max norm  SSIMULACRA2        pnorm       BPP*pnorm   Bugs
--------------------------------------------------------------------------------------------------------------------------
jxl:d0.5           409    47889    0.9353320   0.999  10.693   0.76884204  97.97876012   0.29019442  0.271428139716      0
jxl:d0.5:D0        409    46700    0.9121094   1.014  12.442   0.76884204  98.26795927   0.29005663  0.264563367873      0
jxl:d1             409    31685    0.6188477   1.017  10.603   1.19141257  91.69366061   0.47456421  0.293682948235      0
jxl:d1:D0          409    31095    0.6073242   1.045  11.505   1.19293487  91.82356930   0.47412265  0.287946168915      0
jxl:d2             409    20969    0.4095508   1.021  10.966   2.02522826  86.19662382   0.75935998  0.310996471061      0
jxl:d2:D0          409    20971    0.4095898   1.039  11.696   2.02522278  86.03497192   0.75843025  0.310645329176      0
jxl:d3             409    16549    0.3232227   1.004   9.977   2.59280419  82.55876856   0.97508168  0.315168489608      0
jxl:d3:D0          409    16891    0.3299023   0.985   8.871   2.64150572  82.59064968   0.97371519  0.321230921912      0
Aggregate:         409    26859    0.5245902   1.015  10.794   1.48461947  89.45138936   0.56480591  0.296291627848      0

So maybe we should reconsider the default behavior, and do alpha losslessly when doing high quality lossy, and only make alpha lossy when the quality is low enough. To be investigated later...

@jonsneyers jonsneyers added enhancement New feature or request encoder Related to the libjxl encoder api Related to the libjxl API labels Jan 27, 2023
@veluca93
Copy link
Member

Can you split the all_color_aware commit in another PR?

@jonsneyers
Copy link
Member Author

Can you split the all_color_aware commit in another PR?

Yes, that one is already merged (#2116).

Rebased and fixed the merge conflict.

lib/jxl/enc_modular.cc Outdated Show resolved Hide resolved
lib/jxl/encode.cc Outdated Show resolved Hide resolved
@mo271
Copy link
Member

mo271 commented Feb 10, 2023

Could you add an entry to the changelog?

@jonsneyers
Copy link
Member Author

Could you add an entry to the changelog?

Done, thanks for the reminder!

@jonsneyers jonsneyers merged commit 6280645 into libjxl:main Feb 10, 2023
jonsneyers added a commit to jonsneyers/libjxl that referenced this pull request Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to the libjxl API encoder Related to the libjxl encoder enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants