From d79c9a22244ebc7aba491ad50ef2edced6c00d88 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Jos=C3=A9=20Fonseca?= <jfonseca@vmware.com>
Date: Mon, 16 Sep 2013 14:57:30 +0100
Subject: [PATCH] image: Non-standard PNM format variant for 4-float images.

---
 image/image_pnm.cpp    | 12 ++++++++++--
 scripts/retracediff.py |  4 ++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/image/image_pnm.cpp b/image/image_pnm.cpp
index 0473ac6..58e2cd3 100644
--- a/image/image_pnm.cpp
+++ b/image/image_pnm.cpp
@@ -62,9 +62,13 @@ Image::writePNM(std::ostream &os, const char *comment) const
         if (channels == 1) {
             identifier = "Pf";
             outChannels = 1;
-        } else {
+        } else if (channels <= 3) {
             identifier = "PF";
-            outChannels = 3;
+            outChannels = 4;
+        } else {
+            // Non-standard extension for 4 floats
+            identifier = "PX";
+            outChannels = 4;
         }
         break;
     default:
@@ -235,6 +239,10 @@ readPNMHeader(const char *buffer, size_t bufferSize, PNMInfo &info)
         info.channels = 3;
         info.channelType = TYPE_FLOAT;
         break;
+    case 'X':
+        info.channels = 4;
+        info.channelType = TYPE_FLOAT;
+        break;
     default:
         return NULL;
     }
diff --git a/scripts/retracediff.py b/scripts/retracediff.py
index c0518df..71e9f06 100755
--- a/scripts/retracediff.py
+++ b/scripts/retracediff.py
@@ -148,6 +148,10 @@ def read_pnm(stream):
         channels = 3
         bytesPerChannel = 4
         mode = 'RGB'
+    elif magic == 'PX':
+        channels = 4
+        bytesPerChannel = 4
+        mode = 'RGB'
     else:
         raise Exception('Unsupported magic `%s`' % magic)
     comment = ''
-- 
2.45.2