]> git.cworth.org Git - apitrace/blobdiff - image/image_pnm.cpp
backtrace: Allow to build without libbacktrace.
[apitrace] / image / image_pnm.cpp
index 79db1c6e78249e945b9b5a6c2f45fb89b3dc7788..58e2cd359058f8ffc9f014fb3db4a697b83447f1 100644 (file)
@@ -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:
@@ -99,7 +103,7 @@ Image::writePNM(std::ostream &os, const char *comment) const
          * Need to add/remove channels, one pixel at a time.
          */
 
-        unsigned char *tmp = new unsigned char[width*bytesPerPixel];
+        unsigned char *tmp = new unsigned char[width*outChannels*bytesPerChannel];
 
         if (channelType == TYPE_UNORM8) {
             /*
@@ -174,7 +178,7 @@ Image::writePNM(std::ostream &os, const char *comment) const
                         *dst++ = 0;
                     }
                 }
-                os.write((const char *)tmp, width*bytesPerPixel);
+                os.write((const char *)tmp, width*outChannels*bytesPerChannel);
             }
         }
 
@@ -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;
     }