diff options
Diffstat (limited to 'testing')
-rw-r--r-- | testing/embedder_test.cpp | 28 | ||||
-rw-r--r-- | testing/resources/embedded_images.pdf | bin | 0 -> 27089 bytes |
2 files changed, 25 insertions, 3 deletions
diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp index 0846d8ccb7..82ffb3b825 100644 --- a/testing/embedder_test.cpp +++ b/testing/embedder_test.cpp @@ -42,6 +42,22 @@ FPDF_BOOL Is_Data_Avail(FX_FILEAVAIL* pThis, size_t offset, size_t size) { void Add_Segment(FX_DOWNLOADHINTS* pThis, size_t offset, size_t size) {} +int GetBitmapBytesPerPixel(FPDF_BITMAP bitmap) { + const int format = FPDFBitmap_GetFormat(bitmap); + switch (format) { + case FPDFBitmap_Gray: + return 1; + case FPDFBitmap_BGR: + return 3; + case FPDFBitmap_BGRx: + case FPDFBitmap_BGRA: + return 4; + default: + ASSERT(false); + return 0; + } +} + } // namespace EmbedderTest::EmbedderTest() @@ -381,8 +397,10 @@ std::string EmbedderTest::HashBitmap(FPDF_BITMAP bitmap, int expected_width, int expected_height) { uint8_t digest[16]; - CRYPT_MD5Generate(static_cast<uint8_t*>(FPDFBitmap_GetBuffer(bitmap)), - expected_width * 4 * expected_height, digest); + CRYPT_MD5Generate( + static_cast<uint8_t*>(FPDFBitmap_GetBuffer(bitmap)), + expected_width * GetBitmapBytesPerPixel(bitmap) * expected_height, + digest); return CryptToBase16(digest); } @@ -393,7 +411,11 @@ void EmbedderTest::CompareBitmap(FPDF_BITMAP bitmap, const char* expected_md5sum) { ASSERT_EQ(expected_width, FPDFBitmap_GetWidth(bitmap)); ASSERT_EQ(expected_height, FPDFBitmap_GetHeight(bitmap)); - const int expected_stride = expected_width * 4; + + // The expected stride is calculated using the same formula as in + // CFX_DIBitmap::CalculatePitchAndSize(), which sets the bitmap stride. + const int expected_stride = + (expected_width * GetBitmapBytesPerPixel(bitmap) * 8 + 31) / 32 * 4; ASSERT_EQ(expected_stride, FPDFBitmap_GetStride(bitmap)); if (!expected_md5sum) diff --git a/testing/resources/embedded_images.pdf b/testing/resources/embedded_images.pdf Binary files differnew file mode 100644 index 0000000000..81845822a4 --- /dev/null +++ b/testing/resources/embedded_images.pdf |