GNOME Bugzilla – Bug 778990
PNM file plugin doesn't preserve 16-bit image precision
Last modified: 2017-02-22 15:24:12 UTC
When loading a PGM file with a max value field of 65535, the PNM plugin throws away precision by always creating U8 precision images. Similarly when saving an image to PGM file, it will always scale pixels so the max value written out is 255 even if the image precision is greater than U8.
Created attachment 346289 [details] [review] Preserve 16-bit precision when loading PGM files.
Created attachment 346290 [details] [review] Preserve 16-bit precision when saving PGM files
Thanks, that looks very good, should go in ASAP.
FYI, I've just realized there is a bug in the patch for saving PGM files - it doesn't handle 16-bit correctly in the saverow_ascii() method. I'll submit a fixed patch for that later today.
Comment on attachment 346290 [details] [review] Preserve 16-bit precision when saving PGM files see comment 4
Comment on attachment 346289 [details] [review] Preserve 16-bit precision when loading PGM files. see comment 3
Created attachment 346410 [details] [review] v2: Preserve 16-bit precision when loading PGM files Fixes a bug in loading 1-bit precision B&W PBM files in the previous patch
Created attachment 346411 [details] [review] v2: Preserve 16-bit precision when saving PGM files Fixes writing of files in ascii format wrt previous patch
I've now tested these patches loading + saving all the integer format combinations, PBM raw, PBM ascii, PGM 8-bit raw, PGM 8-bit ascii, PGM 16-bit raw, PGM 16-bit ascii, PNM 8-bit raw, PNM 8-bit ascii, PNM 16-bit raw and PNM 16-bit ascii formats. They round trip with no loss of information.
Review of attachment 346410 [details] [review]: I've not tested and don't know much of the PNM format, but it is clean code with no obvious bug in there. If you are sure of your patch this time, just push it. :-)
Review of attachment 346411 [details] [review]: Same here. Clean and no obvious bug. Syntax-wise, just a minor bug (nitpicking mode!), a missing space before a parenthese: > *d = g_htons(*d); Apart from this detail, I'd say just push this if that adds 16-bit support for the file format.
(In reply to Jehan from comment #10) > If you are sure of your patch this time, just push it. :-) To best of my knowledge I don't have privileges to push patches to GIMP git - presumably a GIMP maintainer has to push them :-)
Thanks a lot, pushed to master: commit ad9ccc4b586c401149ac45d6dfcb9114aaed6c14 Author: Daniel P. Berrange <berrange@redhat.com> Date: Mon Feb 20 23:12:05 2017 +0000 Bug 778990 - PNM file plugin doesn't preserve 16-bit image precision Save PNM in 16-bit format with max value of 65536 if the image precision is not U8. plug-ins/common/file-pnm.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 89 insertions(+), 26 deletions(-) commit c87543aaac2a822d379c8a8618a7dc8220af5366 Author: Daniel P. Berrange <berrange@redhat.com> Date: Mon Feb 20 21:46:21 2017 +0000 Bug 778990 - PNM file plugin doesn't preserve 16-bit image precision Create a U16 precision image if loading a PNM file with a max value greater than 255 plug-ins/common/file-pnm.c | 92 ++++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 37 deletions(-)
Sorry saw the other comments only after pushing.