Support non-full-depth uint16 PNM input (10/12/14-bit)#202
Open
chemag wants to merge 1 commit intogoogle:mainfrom
Open
Support non-full-depth uint16 PNM input (10/12/14-bit)#202chemag wants to merge 1 commit intogoogle:mainfrom
chemag wants to merge 1 commit intogoogle:mainfrom
Conversation
The encoder rejected uint16 input unless bits_per_sample was exactly 16,
causing failures for valid PGM files with maxval other than 65535 (e.g.
10-bit maxval=1023, 12-bit maxval=4095, 14-bit maxval=16383).
Fix by converting non-full-depth uint16 data to float with proper
normalization (value / (2^N - 1)) before feeding to jpegli, which
internally works in float anyway.
Tested encode/decode roundtrip (cjpegli -q 90 + djpegli) with all 8-16
bit depth PNM files in testdata/. PSNR and per-pixel error (in 8-bit
units) are consistent across all depths:
Grayscale (PGM) - flower_small
Depth PSNR (dB) Mean Median StdDev Max
------------------------------------------------------------------------
8 45.88 0.946 1.000 0.885 9.000
9 45.79 1.018 0.804 0.822 9.603
10 45.86 1.007 0.827 0.820 8.654
11 45.88 0.981 0.921 0.846 8.217
12 45.89 0.964 0.952 0.864 8.941
13 45.88 0.956 0.983 0.874 8.979
14 45.88 0.951 0.992 0.880 8.982
15 45.88 0.948 0.999 0.883 8.999
16 45.88 0.946 1.000 0.885 9.000
RGB (PPM) - flower_small
Depth PSNR (dB) Mean Median StdDev Max
------------------------------------------------------------------------
8 41.58 1.542 1.000 1.464 32.000
9 41.51 1.597 1.231 1.430 32.740
10 41.56 1.584 1.226 1.426 32.361
11 41.57 1.567 1.114 1.441 32.047
12 41.58 1.554 1.055 1.451 32.077
13 41.58 1.548 1.027 1.457 32.061
14 41.58 1.545 1.013 1.460 32.022
15 41.58 1.543 1.004 1.463 32.010
16 41.58 1.542 1.000 1.464 32.000
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The encoder rejected uint16 input unless bits_per_sample was exactly 16, causing failures for valid PGM files with maxval other than 65535 (e.g. 10-bit maxval=1023, 12-bit maxval=4095, 14-bit maxval=16383).
Fix by converting non-full-depth uint16 data to float with proper normalization (value / (2^N - 1)) before feeding to jpegli, which internally works in float anyway.
Tested with all 8-16 bit depth PNM files in testdata/:
$ for f in $(find testdata -type f ( -name ".pgm" -o -name ".ppm" -o -name ".pnm" -o -name ".pfm" -o -name ".pam" ) | grep -vP '.depth[1-7].' | sort); do ./build/tools/cjpegli "$f" "/tmp/$(basename ${f%.}).jpg" -q 90; done Read 320x320 image, 1228816 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 20762 bytes (1.622 bpp).
320 x 320, 33.281 MP/s, 1 threads.
Read 2268x1512 image, 3429233 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 479651 bytes (1.119 bpp).
2268 x 1512, 69.906 MP/s, 1 threads.
Read 2268x1512 image, 10287665 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 588499 bytes (1.373 bpp).
2268 x 1512, 38.805 MP/s, 1 threads.
Read 510x532 image, 1085356 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 42514 bytes (1.254 bpp).
510 x 532, 55.436 MP/s, 1 threads.
Read 510x532 image, 1085356 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 42539 bytes (1.254 bpp).
510 x 532, 57.930 MP/s, 1 threads.
Read 510x532 image, 1085356 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 42498 bytes (1.253 bpp).
510 x 532, 58.650 MP/s, 1 threads.
Read 510x532 image, 1085356 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 42507 bytes (1.253 bpp).
510 x 532, 57.904 MP/s, 1 threads.
Read 510x532 image, 1085357 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 42504 bytes (1.253 bpp).
510 x 532, 57.796 MP/s, 1 threads.
Read 510x532 image, 1085357 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 42485 bytes (1.253 bpp).
510 x 532, 57.631 MP/s, 1 threads.
Read 510x532 image, 1085357 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 42492 bytes (1.253 bpp).
510 x 532, 49.802 MP/s, 1 threads.
Read 510x532 image, 542715 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 42492 bytes (1.253 bpp).
510 x 532, 50.964 MP/s, 1 threads.
Read 510x532 image, 1085355 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 42551 bytes (1.255 bpp).
510 x 532, 56.318 MP/s, 1 threads.
Read 510x532 image, 542656 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 42514 bytes (1.254 bpp).
510 x 532, 55.254 MP/s, 1 threads.
Read 510x532 image, 542656 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 42539 bytes (1.254 bpp).
510 x 532, 57.512 MP/s, 1 threads.
Read 510x532 image, 542656 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 42498 bytes (1.253 bpp).
510 x 532, 55.191 MP/s, 1 threads.
Read 510x532 image, 542656 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 42507 bytes (1.253 bpp).
510 x 532, 57.439 MP/s, 1 threads.
Read 510x532 image, 542657 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 42504 bytes (1.253 bpp).
510 x 532, 57.402 MP/s, 1 threads.
Read 510x532 image, 542657 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 42485 bytes (1.253 bpp).
510 x 532, 57.802 MP/s, 1 threads.
Read 510x532 image, 542657 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 42492 bytes (1.253 bpp).
510 x 532, 63.444 MP/s, 1 threads.
Read 510x532 image, 271335 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 42492 bytes (1.253 bpp).
510 x 532, 65.117 MP/s, 1 threads.
Read 510x532 image, 542655 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 42551 bytes (1.255 bpp).
510 x 532, 56.888 MP/s, 1 threads.
Read 510x532 image, 2170630 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 55546 bytes (1.638 bpp).
510 x 532, 32.474 MP/s, 1 threads.
Read 510x532 image, 2170630 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 55536 bytes (1.638 bpp).
510 x 532, 31.938 MP/s, 1 threads.
Read 510x532 image, 2170630 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 55508 bytes (1.637 bpp).
510 x 532, 32.667 MP/s, 1 threads.
Read 510x532 image, 2170630 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 55515 bytes (1.637 bpp).
510 x 532, 32.037 MP/s, 1 threads.
Read 510x532 image, 2170631 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 55507 bytes (1.637 bpp).
510 x 532, 32.238 MP/s, 1 threads.
Read 510x532 image, 2170631 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 55527 bytes (1.637 bpp).
510 x 532, 31.883 MP/s, 1 threads.
Read 510x532 image, 2170631 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 55540 bytes (1.638 bpp).
510 x 532, 31.580 MP/s, 1 threads.
Read 510x532 image, 1085349 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 55540 bytes (1.638 bpp).
510 x 532, 31.792 MP/s, 1 threads.
Read 510x532 image, 2170629 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 55458 bytes (1.635 bpp).
510 x 532, 31.598 MP/s, 1 threads.
Read 510x532 image, 1627936 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 55546 bytes (1.638 bpp).
510 x 532, 31.344 MP/s, 1 threads.
Read 510x532 image, 1627936 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 55536 bytes (1.638 bpp).
510 x 532, 32.518 MP/s, 1 threads.
Read 510x532 image, 1627936 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 55508 bytes (1.637 bpp).
510 x 532, 32.627 MP/s, 1 threads.
Read 510x532 image, 1627936 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 55515 bytes (1.637 bpp).
510 x 532, 32.560 MP/s, 1 threads.
Read 510x532 image, 1627937 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 55507 bytes (1.637 bpp).
510 x 532, 32.853 MP/s, 1 threads.
Read 510x532 image, 1627937 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 55527 bytes (1.637 bpp).
510 x 532, 32.485 MP/s, 1 threads.
Read 510x532 image, 1627937 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 55540 bytes (1.638 bpp).
510 x 532, 35.257 MP/s, 1 threads.
Read 510x532 image, 813975 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 55540 bytes (1.638 bpp).
510 x 532, 35.527 MP/s, 1 threads.
Read 510x532 image, 1627935 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 55458 bytes (1.635 bpp).
510 x 532, 33.397 MP/s, 1 threads.
Read 320x320 image, 1228816 bytes.
Encoding [YUV d1.000 AQ p2 OPT]
Compressed to 5167 bytes (0.404 bpp).
320 x 320, 46.631 MP/s, 1 threads.
Description
Pull Request Checklist
./ci.sh lintfor automatic code formatting.Please review the full contributing guidelines for more details.