]> git.saurik.com Git - wxWidgets.git/commitdiff
Added support for saving greyscale TIFF images.
authorDimitri Schoolwerth <dimitri.schoolwerth@gmail.com>
Fri, 19 Aug 2011 02:35:48 +0000 (02:35 +0000)
committerDimitri Schoolwerth <dimitri.schoolwerth@gmail.com>
Fri, 19 Aug 2011 02:35:48 +0000 (02:35 +0000)
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
tests/image/image.cpp

index e852fc00f056c7acd60bd1758b72adff520e52d4..d8d449c5cff755d596a0e4db737990f9841c9dd2 100644 (file)
@@ -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++ )
index 010bc1d278b625db151bef2d44bea7171395e0cc..9135e433b916fca61ebd7288a22f9ab88d0b0568 100644 (file)
@@ -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()