From 8e28cc4701896761cd2c306525be2a31eb622cf4 Mon Sep 17 00:00:00 2001 From: Dimitri Schoolwerth Date: Fri, 19 Aug 2011 02:35:48 +0000 Subject: [PATCH] Added support for saving greyscale TIFF images. When saving with a samples per pixel value of 1 the TIFF handler still treated the image as RGB, resulting in corrupted images. Handle the greyscale case and added a unit test for it. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68784 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/imagtiff.cpp | 7 +++++++ tests/image/image.cpp | 1 + 2 files changed, 8 insertions(+) diff --git a/src/common/imagtiff.cpp b/src/common/imagtiff.cpp index e852fc00f0..d8d449c5cf 100644 --- a/src/common/imagtiff.cpp +++ b/src/common/imagtiff.cpp @@ -659,6 +659,13 @@ bool wxTIFFHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbo // color image memcpy(buf, ptr, image->GetWidth()); } + else if (spp * bps == 8) // greyscale image + { + for ( int column = 0; column < linebytes; column++ ) + { + buf[column] = ptr[column*3 + 1]; + } + } else // black and white image { for ( int column = 0; column < linebytes; column++ ) diff --git a/tests/image/image.cpp b/tests/image/image.cpp index 010bc1d278..9135e433b9 100644 --- a/tests/image/image.cpp +++ b/tests/image/image.cpp @@ -1115,6 +1115,7 @@ static void TestTIFFImage(const wxString& option, int value) void ImageTestCase::SaveTIFF() { TestTIFFImage(wxIMAGE_OPTION_TIFF_BITSPERSAMPLE, 1); + TestTIFFImage(wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL, 1); } void ImageTestCase::SaveAnimatedGIF()