X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=image%2Fimage_pnm.cpp;h=58e2cd359058f8ffc9f014fb3db4a697b83447f1;hb=d6c02fd58feb2b48be13a2405d0eb738ed62925a;hp=79db1c6e78249e945b9b5a6c2f45fb89b3dc7788;hpb=4dbf7c9e3f4b669ec38600c04ba8a67926d10cc7;p=apitrace diff --git a/image/image_pnm.cpp b/image/image_pnm.cpp index 79db1c6..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: @@ -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; }