From 8ac914ee3885ead89dd3974a9d73b1960470baa9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Mon, 16 Sep 2013 14:18:05 +0100 Subject: [PATCH] image: Yet another fix for the PFM dumping. --- image/image.hpp | 4 +++- image/image_pnm.cpp | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/image/image.hpp b/image/image.hpp index 857e062..8e6b51f 100644 --- a/image/image.hpp +++ b/image/image.hpp @@ -49,6 +49,7 @@ public: unsigned height; unsigned channels; ChannelType channelType; + unsigned bytesPerChannel; unsigned bytesPerPixel; // Flipped vertically or not @@ -62,7 +63,8 @@ public: height(h), channels(c), channelType(t), - bytesPerPixel(channels * (t == TYPE_FLOAT ? 4 : 1)), + bytesPerChannel(t == TYPE_FLOAT ? 4 : 1), + bytesPerPixel(channels * bytesPerChannel), flipped(f), pixels(new unsigned char[h*w*bytesPerPixel]) {} diff --git a/image/image_pnm.cpp b/image/image_pnm.cpp index 79db1c6..0473ac6 100644 --- a/image/image_pnm.cpp +++ b/image/image_pnm.cpp @@ -99,7 +99,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 +174,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); } } -- 2.43.0