+ else
+ {
+ (void) image.LoadFile("horse.png");
+ }
+ CPPUNIT_ASSERT( image.IsOk() );
+
+ wxMemoryOutputStream memOut;
+ image.SetOption(option, value);
+
+ CPPUNIT_ASSERT(image.SaveFile(memOut, wxBITMAP_TYPE_TIFF));
+
+ wxMemoryInputStream memIn(memOut);
+ CPPUNIT_ASSERT(memIn.IsOk());
+
+ wxImage savedImage(memIn);
+ CPPUNIT_ASSERT(savedImage.IsOk());
+
+ WX_ASSERT_EQUAL_MESSAGE(("While checking for option %s", option),
+ true, savedImage.HasOption(option));
+
+ WX_ASSERT_EQUAL_MESSAGE(("While testing for %s", option),
+ value, savedImage.GetOptionInt(option));
+
+ WX_ASSERT_EQUAL_MESSAGE(("HasAlpha() not equal"), image.HasAlpha(), savedImage.HasAlpha());
+}
+
+void ImageTestCase::SaveTIFF()
+{
+ TestTIFFImage(wxIMAGE_OPTION_TIFF_BITSPERSAMPLE, 1);
+ TestTIFFImage(wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL, 1);
+ TestTIFFImage(wxIMAGE_OPTION_TIFF_PHOTOMETRIC, 0/*PHOTOMETRIC_MINISWHITE*/);
+ TestTIFFImage(wxIMAGE_OPTION_TIFF_PHOTOMETRIC, 1/*PHOTOMETRIC_MINISBLACK*/);
+
+ wxImage alphaImage("horse.png");
+ CPPUNIT_ASSERT( alphaImage.IsOk() );
+ SetAlpha(&alphaImage);
+
+ // RGB with alpha
+ TestTIFFImage(wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL, 4, &alphaImage);
+
+ // Grey with alpha
+ TestTIFFImage(wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL, 2, &alphaImage);
+
+ // B/W with alpha
+ alphaImage.SetOption(wxIMAGE_OPTION_TIFF_BITSPERSAMPLE, 1);
+ TestTIFFImage(wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL, 2, &alphaImage);
+}
+
+void ImageTestCase::SaveAnimatedGIF()
+{
+#if wxUSE_PALETTE
+ wxImage image("horse.gif");
+ CPPUNIT_ASSERT( image.IsOk() );
+
+ wxImageArray images;
+ images.Add(image);
+ int i;
+ for (i = 0; i < 4-1; ++i)
+ {
+ images.Add( images[i].Rotate90() );
+
+ images[i+1].SetPalette(images[0].GetPalette());
+ }
+
+ wxMemoryOutputStream memOut;
+ CPPUNIT_ASSERT( wxGIFHandler().SaveAnimation(images, &memOut) );
+
+ wxGIFHandler handler;
+ wxMemoryInputStream memIn(memOut);
+ CPPUNIT_ASSERT(memIn.IsOk());
+ const int imageCount = handler.GetImageCount(memIn);
+ CPPUNIT_ASSERT_EQUAL(4, imageCount);
+
+ for (i = 0; i < imageCount; ++i)
+ {
+ wxFileOffset pos = memIn.TellI();
+ CPPUNIT_ASSERT( handler.LoadFile(&image, memIn, true, i) );
+ memIn.SeekI(pos);
+
+ WX_ASSERT_EQUAL_MESSAGE
+ (
+ ("Compare test for GIF frame number %d failed", i),
+ images[i],
+ image
+ );
+ }
+#endif // #if wxUSE_PALETTE
+}
+
+void ImageTestCase::ReadCorruptedTGA()
+{
+ static unsigned char corruptTGA[18+1+3] =
+ {
+ 0,
+ 0,
+ 10, // RLE compressed image.
+ 0, 0,
+ 0, 0,
+ 0,
+ 0, 0,
+ 0, 0,
+ 1, 0, // Width is 1.
+ 1, 0, // Height is 1.
+ 24, // Bits per pixel.
+ 0,
+
+ 0xff, // Run length (repeat next pixel 127+1 times).
+ 0xff, 0xff, 0xff // One 24-bit pixel.
+ };
+
+ wxMemoryInputStream memIn(corruptTGA, WXSIZEOF(corruptTGA));
+ CPPUNIT_ASSERT(memIn.IsOk());
+
+ wxImage tgaImage;
+ CPPUNIT_ASSERT( !tgaImage.LoadFile(memIn) );
+