#endif // WX_PRECOMP
#include "wx/anidecod.h" // wxImageArray
-#include "wx/image.h"
#include "wx/palette.h"
#include "wx/url.h"
#include "wx/log.h"
#include "wx/zstream.h"
#include "wx/wfstream.h"
+#include "testimage.h"
+
struct testData {
const char* file;
wxBitmapType type;
CPPUNIT_TEST( SaveAnimatedGIF );
CPPUNIT_TEST( ReadCorruptedTGA );
CPPUNIT_TEST( GIFComment );
+ CPPUNIT_TEST( DibPadding );
+ CPPUNIT_TEST( BMPFlippingAndRLECompression );
CPPUNIT_TEST_SUITE_END();
void LoadFromSocketStream();
void SaveAnimatedGIF();
void ReadCorruptedTGA();
void GIFComment();
+ void DibPadding();
+ void BMPFlippingAndRLECompression();
DECLARE_NO_COPY_CLASS(ImageTestCase)
};
CPPUNIT_ASSERT_EQUAL( actual.GetSize().x, expected.GetSize().x );
CPPUNIT_ASSERT_EQUAL( actual.GetSize().y, expected.GetSize().y );
- const unsigned data_len = 3 * expected.GetHeight() * expected.GetWidth();
-
- WX_ASSERT_MESSAGE
+ WX_ASSERT_EQUAL_MESSAGE
(
("Resize test #%u: (%d, %d), (%d, %d)", i, st.w, st.h, st.dx, st.dy),
- memcmp(actual.GetData(), expected.GetData(), data_len) == 0
+ expected, actual
);
}
}
wxImage expected24("horse.png");
CPPUNIT_ASSERT( expected24.IsOk() );
- const size_t dataLen = expected8.GetWidth() * expected8.GetHeight() * 3;
-
for (size_t i=0; i<WXSIZEOF(g_testfiles); i++)
{
if ( !(g_testfiles[i].bitDepth == 8 || g_testfiles[i].bitDepth == 24)
}
- WX_ASSERT_MESSAGE
+ WX_ASSERT_EQUAL_MESSAGE
(
("Compare test '%s' for loading failed", g_testfiles[i].file),
-
- memcmp(actual.GetData(),
- (g_testfiles[i].bitDepth == 8)
- ? expected8.GetData()
- : expected24.GetData(),
- dataLen) == 0
+ g_testfiles[i].bitDepth == 8 ? expected8 : expected24,
+ actual
);
}
if ( testPalette
&& ( !(type == wxBITMAP_TYPE_BMP
|| type == wxBITMAP_TYPE_GIF
+ || type == wxBITMAP_TYPE_ICO
|| type == wxBITMAP_TYPE_PNG)
|| type == wxBITMAP_TYPE_XPM) )
{
return;
}
- if (type == wxBITMAP_TYPE_JPEG /* skip lossy JPEG */
- || type == wxBITMAP_TYPE_TIF)
+ if (type == wxBITMAP_TYPE_JPEG /* skip lossy JPEG */)
{
- /*
- TIFF is skipped because the memory stream can't be loaded. Libtiff
- looks for a TIFF directory at offset 120008 while the memory
- stream size is only 120008 bytes (when saving as a file
- the file size is 120280 bytes).
- */
return;
}
CPPUNIT_ASSERT( actual.GetSize() == expected->GetSize() );
unsigned bitsPerPixel = testPalette ? 8 : (testAlpha ? 32 : 24);
- WX_ASSERT_MESSAGE
+ WX_ASSERT_EQUAL_MESSAGE
(
("Compare test '%s (%d-bit)' for saving failed",
handler.GetExtension(), bitsPerPixel),
-
- memcmp(actual.GetData(), expected->GetData(),
- expected->GetWidth() * expected->GetHeight() * 3) == 0
+ *expected,
+ actual
);
#if wxUSE_PALETTE
return;
}
- WX_ASSERT_MESSAGE
+ WX_ASSERT_EQUAL_MESSAGE
(
("Compare alpha test '%s' for saving failed", handler.GetExtension()),
-
- memcmp(actual.GetAlpha(), expected->GetAlpha(),
- expected->GetWidth() * expected->GetHeight()) == 0
+ *expected,
+ actual
);
}
CPPUNIT_ASSERT( handler.LoadFile(&image, memIn, true, i) );
memIn.SeekI(pos);
- WX_ASSERT_MESSAGE
+ WX_ASSERT_EQUAL_MESSAGE
(
("Compare test for GIF frame number %d failed", i),
- memcmp(image.GetData(), images[i].GetData(),
- images[i].GetWidth() * images[i].GetHeight() * 3) == 0
+ images[i],
+ image
);
}
#endif // #if wxUSE_PALETTE
}
}
+void ImageTestCase::DibPadding()
+{
+ /*
+ There used to be an error with calculating the DWORD aligned scan line
+ pitch for a BMP/ICO resulting in buffer overwrites (with at least MSVC9
+ Debug this gave a heap corruption assertion when saving the mask of
+ an ICO). Test for it here.
+ */
+ wxImage image("horse.gif");
+ CPPUNIT_ASSERT( image.IsOk() );
+
+ image = image.Scale(99, 99);
+
+ wxMemoryOutputStream memOut;
+ CPPUNIT_ASSERT( image.SaveFile(memOut, wxBITMAP_TYPE_ICO) );
+}
+
+static void CompareBMPImage(const wxString& file1, const wxString& file2)
+{
+ wxImage image1(file1);
+ CPPUNIT_ASSERT( image1.IsOk() );
+
+ wxImage image2(file2);
+ CPPUNIT_ASSERT( image2.IsOk() );
+
+ CompareImage(*wxImage::FindHandler(wxBITMAP_TYPE_BMP), image1, 0, &image2);
+}
+
+void ImageTestCase::BMPFlippingAndRLECompression()
+{
+ CompareBMPImage("image/horse_grey.bmp", "image/horse_grey_flipped.bmp");
+
+ CompareBMPImage("image/horse_rle8.bmp", "image/horse_grey.bmp");
+ CompareBMPImage("image/horse_rle8.bmp", "image/horse_rle8_flipped.bmp");
+
+ CompareBMPImage("image/horse_rle4.bmp", "image/horse_rle4_flipped.bmp");
+}
#endif //wxUSE_IMAGE