diff options
author | Jane Liu <janeliulwq@google.com> | 2017-08-02 21:45:57 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-08-03 20:20:02 +0000 |
commit | 28fb7ba083dba5e09493fd37a11994de51527dfc (patch) | |
tree | de009c28d419bed2a9a123c257f923893db0b053 /testing/embedder_test.cpp | |
parent | 844d5dac8a6c97b2cd3bd92bf07d0cc62158408a (diff) | |
download | pdfium-28fb7ba083dba5e09493fd37a11994de51527dfc.tar.xz |
APIs and tests for extracting bitmaps from image objects
Added FPDFImageObj_GetBitmap() that returns the bitmap of an image
object, and a FPDFBitmap_GetFormat() that returns the format of a
bitmap.
* Fixed a small bitmap conversion bug in cfx_dibsource.cpp.
* Enabled EmbedderTest::CompareBitmap() to support different formats
of bitmaps.
* Added an embedder test and a test PDF file with images of many
different formats.
Bug=pdfium:677
Change-Id: I6a72f9d969cf5f3577db9400ca33197c213622ed
Reviewed-on: https://pdfium-review.googlesource.com/9690
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Jane Liu <janeliulwq@google.com>
Diffstat (limited to 'testing/embedder_test.cpp')
-rw-r--r-- | testing/embedder_test.cpp | 28 |
1 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) |