diff options
author | Jane Liu <janeliulwq@google.com> | 2017-08-09 14:09:34 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-08-09 18:35:54 +0000 |
commit | be63ab97e0385b4024ef84fda79fc84dc111ab23 (patch) | |
tree | bd56d9e46aefc7f9617f27da624831df1abe67b0 /fpdfsdk/fpdfedit_embeddertest.cpp | |
parent | d24b97ee1d065eff482355ea3ff82be59bb528b1 (diff) | |
download | pdfium-be63ab97e0385b4024ef84fda79fc84dc111ab23.tar.xz |
API and test for retrieving image filters from image objects
Added FPDFImageObj_GetImageFilterCount() and
FPDFImageObj_GetImageFilters() for retrieving image filters of image
objects.
* Added a corresponding embedder test.
* Changed the filter of an image object in embedded_image.pdf from
DCTDecode to ASCIIHexDecode + DCTDecode, so we have a test case
for images with more than one filter.
Bug=pdfium:677
Change-Id: I398790a2cad33fea4ca16a0eb0889c04caa6b962
Reviewed-on: https://pdfium-review.googlesource.com/10130
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Jane Liu <janeliulwq@google.com>
Diffstat (limited to 'fpdfsdk/fpdfedit_embeddertest.cpp')
-rw-r--r-- | fpdfsdk/fpdfedit_embeddertest.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp index c381b25efa..e62ef2149b 100644 --- a/fpdfsdk/fpdfedit_embeddertest.cpp +++ b/fpdfsdk/fpdfedit_embeddertest.cpp @@ -1038,3 +1038,49 @@ TEST_F(FPDFEditEmbeddertest, DestroyPageObject) { // There should be no memory leaks with a call to FPDFPageObj_Destroy(). FPDFPageObj_Destroy(rect); } + +TEST_F(FPDFEditEmbeddertest, GetImageFilters) { + EXPECT_TRUE(OpenDocument("embedded_images.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_TRUE(page); + + // Verify that retrieving the filter of a non-image object would fail. + FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 32); + ASSERT_NE(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); + ASSERT_EQ(0, FPDFImageObj_GetImageFilterCount(obj)); + EXPECT_EQ(0u, FPDFImageObj_GetImageFilter(obj, 0, nullptr, 0)); + + // Verify the returned filter string for an image object with a single filter. + obj = FPDFPage_GetObject(page, 33); + ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); + ASSERT_EQ(1, FPDFImageObj_GetImageFilterCount(obj)); + unsigned long len = FPDFImageObj_GetImageFilter(obj, 0, nullptr, 0); + std::vector<char> buf(len); + EXPECT_EQ(24u, FPDFImageObj_GetImageFilter(obj, 0, buf.data(), len)); + EXPECT_STREQ(L"FlateDecode", + GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data())) + .c_str()); + EXPECT_EQ(0u, FPDFImageObj_GetImageFilter(obj, 1, nullptr, 0)); + + // Verify all the filters for an image object with a list of filters. + obj = FPDFPage_GetObject(page, 38); + ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj)); + ASSERT_EQ(2, FPDFImageObj_GetImageFilterCount(obj)); + len = FPDFImageObj_GetImageFilter(obj, 0, nullptr, 0); + buf.clear(); + buf.resize(len); + EXPECT_EQ(30u, FPDFImageObj_GetImageFilter(obj, 0, buf.data(), len)); + EXPECT_STREQ(L"ASCIIHexDecode", + GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data())) + .c_str()); + + len = FPDFImageObj_GetImageFilter(obj, 1, nullptr, 0); + buf.clear(); + buf.resize(len); + EXPECT_EQ(20u, FPDFImageObj_GetImageFilter(obj, 1, buf.data(), len)); + EXPECT_STREQ(L"DCTDecode", + GetPlatformWString(reinterpret_cast<unsigned short*>(buf.data())) + .c_str()); + + UnloadPage(page); +} |