After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 778990 - PNM file plugin doesn't preserve 16-bit image precision
PNM file plugin doesn't preserve 16-bit image precision
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: Plugins
2.9.4
Other All
: Normal normal
: 2.10
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2017-02-20 23:19 UTC by Daniel P. Berrange
Modified: 2017-02-22 15:24 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Preserve 16-bit precision when loading PGM files. (7.49 KB, patch)
2017-02-20 23:20 UTC, Daniel P. Berrange
none Details | Review
Preserve 16-bit precision when saving PGM files (8.80 KB, patch)
2017-02-20 23:20 UTC, Daniel P. Berrange
needs-work Details | Review
v2: Preserve 16-bit precision when loading PGM files (7.56 KB, patch)
2017-02-21 21:38 UTC, Daniel P. Berrange
committed Details | Review
v2: Preserve 16-bit precision when saving PGM files (9.66 KB, patch)
2017-02-21 21:38 UTC, Daniel P. Berrange
committed Details | Review

Description Daniel P. Berrange 2017-02-20 23:19:36 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.
Comment 1 Daniel P. Berrange 2017-02-20 23:20:14 UTC
Created attachment 346289 [details] [review]
Preserve 16-bit precision when loading PGM files.
Comment 2 Daniel P. Berrange 2017-02-20 23:20:38 UTC
Created attachment 346290 [details] [review]
Preserve 16-bit precision when saving PGM files
Comment 3 Michael Natterer 2017-02-21 10:10:53 UTC
Thanks, that looks very good, should go in ASAP.
Comment 4 Daniel P. Berrange 2017-02-21 10:15:14 UTC
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 5 Michael Schumacher 2017-02-21 12:44:23 UTC
Comment on attachment 346290 [details] [review]
Preserve 16-bit precision when saving PGM files

see comment 4
Comment 6 Michael Schumacher 2017-02-21 12:44:53 UTC
Comment on attachment 346289 [details] [review]
Preserve 16-bit precision when loading PGM files.

see comment 3
Comment 7 Daniel P. Berrange 2017-02-21 21:38:05 UTC
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
Comment 8 Daniel P. Berrange 2017-02-21 21:38:57 UTC
Created attachment 346411 [details] [review]
v2: Preserve 16-bit precision when saving PGM files

Fixes writing of files in ascii format wrt previous patch
Comment 9 Daniel P. Berrange 2017-02-21 21:40:46 UTC
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.
Comment 10 Jehan 2017-02-22 13:04:51 UTC
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. :-)
Comment 11 Jehan 2017-02-22 13:08:08 UTC
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.
Comment 12 Daniel P. Berrange 2017-02-22 13:55:07 UTC
(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 :-)
Comment 13 Michael Natterer 2017-02-22 15:21:51 UTC
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(-)
Comment 14 Michael Natterer 2017-02-22 15:22:13 UTC
Sorry saw the other comments only after pushing.