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 574415 - Can't display 12-bit PGM files
Can't display 12-bit PGM files
Status: RESOLVED DUPLICATE of bug 74224
Product: GIMP
Classification: Other
Component: General
2.6.1
Other All
: Normal enhancement
: ---
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2009-03-06 19:59 UTC by don.levin
Modified: 2009-03-06 22:56 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description don.levin 2009-03-06 19:59:05 UTC
Gimp can't display 12-bit, 1344 by 1024 PGM images.  We in the scientific community love them.  Code below can make one just like my camera takes.
Currently the x and y location of the mouse is displayed at lower, left.  I'd like the pixel value displayed there too.  I dumbed the image down to 8 bits.  Gimp opens it, but the x and y pixel values change by 0.5 pixels, but this should be 1.  The depth is 0 to 1023 but cols are 0 to 1342.5, not 0 to 1343.
Cinepaint displays hi-res PGM but requires manually adjusting brightness since they assumed 16 bit, but I have 12.  I have trouble installing Cinepaint on Ubuntu Linux 8.10.  The Eye On Gnome viewer displays them great, inc thumbnails, but doesn't give pixel values.  What I'm asking for is very few lines of code to do this right.  

Please fix Gimp.  Thanks

#include <iostream> 
#include <fstream> 
#include <algorithm> // copy 
#include <netinet/in.h> // htons 


using namespace std; 


void arrayToPGM(int nCols, int nRows, int maxPixelValue, 
  unsigned short *pixels){ 
  ofstream m_outfile("don.pgm", 
    ios_base::out&ios_base::binary); 


  unsigned short *tmp = new unsigned short[nCols * nRows]; 


  // Convert from "Little Endian" (pc) byte order to 
  // "Big Endian" byte order 
  transform(pixels, pixels + nCols * nRows, 
    tmp, htons); 


  // The magic number MUST be written first. 
  string sMagic = "P5"; 
  m_outfile << sMagic << endl; 


  // Add number of columns, rows, and max pixel value. 
  m_outfile << 
    nCols                     << endl << 
    nRows                     << endl << 
    maxPixelValue             << endl; 


  // Write pixel gray level values into the file. 
  m_outfile.write( (char *) tmp, 
    nCols * nRows * sizeof(unsigned short) ); 
  m_outfile.close(); 


  delete [] tmp; 



} 


int main(){ 
  int nCols = 1344; 
  int nRows = 1024; 
  unsigned short *pixels = new unsigned short[nCols * nRows]; 
  int i, j, k; 
  for(i=0; i<nRows; i++){ 
    for(j = 0; j < nCols; j++){ 
      k = i * nCols + j; 
      if(i > 400 && i < 700 && j > 400 && j < 700) 
        pixels[k] = 4095; 
      else 
        pixels[k] = 0; 
    } 
  } 
  int maxPixelValue = 4095; 
  arrayToPGM(nCols, nRows, maxPixelValue, pixels); 
  delete [] pixels; 
}
Comment 1 Martin Nordholts 2009-03-06 20:08:52 UTC
Hi! If it's just a few lines, why not create a patch for GIMP and attach it here?
Comment 2 don.levin 2009-03-06 21:24:44 UTC
(In reply to comment #1)
> Hi! If it's just a few lines, why not create a patch for GIMP and attach it
> here?

Sorry, I don't know the "big picture" of Gimp, or how to "patch it".
Someone who knows Gimp should be able to look at how Cinepaint did it, and use the 4095 in PGM header to adjust for the 12 bits.  I don't know where to begin in the huge code in Gimp.  I wish I did.  
Comment 3 david gowers 2009-03-06 22:17:02 UTC
plug-ins/common/file-pnm.c is the only file that has any relation to PGM loading.
Comment 4 Sven Neumann 2009-03-06 22:48:57 UTC
This is basically a request for higher bit depths. We are working on it.

In the meantime you might want to contribute a PGM loader to GEGL that supports this. That will help you to get support for these PGM files into GIMP.

*** This bug has been marked as a duplicate of 74224 ***
Comment 5 don.levin 2009-03-06 22:56:51 UTC
I have the file-pnm executable in plug-ins but nowhere is the .c of it.
I have libgimp2.0-dev pkg which should have the src.
I'll read up on what "PGM loader to GEGL" means.
Thanks.