Hi Lei, this should be the last API of this set. PTAL, thanks!
To view, visit change 10130. To unsubscribe, or for help writing mail filters, visit settings.
3 comments:
Patch Set #3, Line 9: Added FPDFImageObj_GetImageFilters() for retrieving a space-delimited
Out of date with patch set 3?
Patch Set #3, Line 216: CPDF_Object* pFilter = CPDFPageObjectFromFPDFPageObject(image_object)
If you use a temporary variable somewhere in here, will the result be less than 5 lines?
Patch Set #3, Line 225: wsFilters = pFilter->AsArray()->GetUnicodeTextAt(index);
How do you know it's going to be an array?
To view, visit change 10130. To unsubscribe, or for help writing mail filters, visit settings.
Jane Liu uploaded patch set #4 to this change.
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.
Bug=pdfium:677
Change-Id: I398790a2cad33fea4ca16a0eb0889c04caa6b962
---
M fpdfsdk/fpdfedit_embeddertest.cpp
M fpdfsdk/fpdfeditimg.cpp
M fpdfsdk/fpdfview_c_api_test.c
M public/fpdf_edit.h
M testing/resources/embedded_images.pdf
5 files changed, 111 insertions(+), 0 deletions(-)
To view, visit change 10130. To unsubscribe, or for help writing mail filters, visit settings.
Thanks!
3 comments:
Patch Set #3, Line 9: Added FPDFImageObj_GetImageFilterCount() and
Out of date with patch set 3?
Done
Patch Set #3, Line 216: CPDF_PageObject* pObj = CPDFPageObjectFromFPDFPageObject(image_object);
If you use a temporary variable somewhere in here, will the result be less
Done
Patch Set #3, Line 225: return Utf16EncodeMaybeCopyAndReturnLength(wsFilters, buffer, buflen);
How do you know it's going to be an array?
Because FPDFImageObj_GetImageFilterCount() already checks that - the count output will only be >0 if it's either a name or an array; and if count is 0, then the check on L213 will fail.
To view, visit change 10130. To unsubscribe, or for help writing mail filters, visit settings.
2 comments:
File fpdfsdk/fpdfedit_embeddertest.cpp:
Patch Set #4, Line 1034: TEST_F(FPDFEditEmbeddertest, DestroyPageObject) {
FPDF_EditEmbedderTest
Patch Set #4, Line 339: // Get the number of filters (i.e. decoders) of the image in |image_object|.
Should we add a note here on what order the filters need to be applied in? Do we go from the start or the end to remove all the filters? i.e. for your example is it ASCIIHexDecode -> DCTDecode or DCTDecode -> ASCIIHexDecode?
To view, visit change 10130. To unsubscribe, or for help writing mail filters, visit settings.
2 comments:
Patch Set #4, Line 1034: TEST_F(FPDFEditEmbeddertest, DestroyPageObject) {
FPDF_EditEmbedderTest
Where is this convention from?
Patch Set #4, Line 339: // Get the number of filters (i.e. decoders) of the image in |image_object|.
Should we add a note here on what order the filters need to be applied in?
Done
To view, visit change 10130. To unsubscribe, or for help writing mail filters, visit settings.
1 comment:
Patch Set #4, Line 1034: TEST_F(FPDFEditEmbeddertest, DestroyPageObject) {
Where is this convention from?
My brain, heh. I don't know if it is a convention, just seemed like it made sense with the fpdf_edit.h file header to have FPDF_Edit? The capitol T for test makes sense as it's a new camel case word.
To view, visit change 10130. To unsubscribe, or for help writing mail filters, visit settings.
1 comment:
Patch Set #4, Line 1034: TEST_F(FPDFEditEmbeddertest, DestroyPageObject) {
My brain, heh. I don't know if it is a convention, just seemed like it made
:). Well all the current embedder tests follow FPDF*Embeddertest, so unless we want to change all of them?
To view, visit change 10130. To unsubscribe, or for help writing mail filters, visit settings.
1 comment:
Patch Set #4, Line 1034: TEST_F(FPDFEditEmbeddertest, DestroyPageObject) {
:). Well all the current embedder tests follow FPDF*Embeddertest, so unless
Leave it for now.
To view, visit change 10130. To unsubscribe, or for help writing mail filters, visit settings.
Patch set 6:Code-Review +1
Can you briefly describe what changed in embedded_images.pdf for those of us that are too lazy to look?
1 comment:
File fpdfsdk/fpdfedit_embeddertest.cpp:
Patch Set #6, Line 1042: TEST_F(FPDFEditEmbeddertest, GetImageFilters) {
Add a separate test case for testing an invalid object, and out of bound indices?
To view, visit change 10130. To unsubscribe, or for help writing mail filters, visit settings.
Jane Liu uploaded patch set #7 to this change.
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
---
M fpdfsdk/fpdfedit_embeddertest.cpp
M fpdfsdk/fpdfeditimg.cpp
M fpdfsdk/fpdfview_c_api_test.c
M public/fpdf_edit.h
M testing/resources/embedded_images.pdf
5 files changed, 111 insertions(+), 0 deletions(-)
To view, visit change 10130. To unsubscribe, or for help writing mail filters, visit settings.
Jane Liu uploaded patch set #9 to this change.
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
---
M fpdfsdk/fpdfedit_embeddertest.cpp
M fpdfsdk/fpdfeditimg.cpp
M fpdfsdk/fpdfview_c_api_test.c
M public/fpdf_edit.h
M testing/resources/embedded_images.pdf
5 files changed, 118 insertions(+), 0 deletions(-)
To view, visit change 10130. To unsubscribe, or for help writing mail filters, visit settings.
Patch Set 6:
(1 comment)
Can you briefly describe what changed in embedded_images.pdf for those of us that are too lazy to look?
Updated the commit message to explain the change.
Thanks!
1 comment:
Patch Set #6, Line 1042: TEST_F(FPDFEditEmbeddertest, GetImageFilters) {
Add a separate test case for testing an invalid object, and out of bound in
Done
To view, visit change 10130. To unsubscribe, or for help writing mail filters, visit settings.
Patch set 9:Code-Review +1
Patch set 9:Commit-Queue +2
Chromium commit bot merged this change.
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 <the...@chromium.org>
Reviewed-by: dsinclair <dsin...@chromium.org>
Commit-Queue: Jane Liu <janel...@google.com>
---
M fpdfsdk/fpdfedit_embeddertest.cpp
M fpdfsdk/fpdfeditimg.cpp
M fpdfsdk/fpdfview_c_api_test.c
M public/fpdf_edit.h
M testing/resources/embedded_images.pdf
5 files changed, 118 insertions(+), 0 deletions(-)
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp
index c381b25..e62ef21 100644
--- a/fpdfsdk/fpdfedit_embeddertest.cpp
+++ b/fpdfsdk/fpdfedit_embeddertest.cpp
@@ -1038,3 +1038,49 @@
// 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);
+}
diff --git a/fpdfsdk/fpdfeditimg.cpp b/fpdfsdk/fpdfeditimg.cpp
index 0d0c546..b4254e9 100644
--- a/fpdfsdk/fpdfeditimg.cpp
+++ b/fpdfsdk/fpdfeditimg.cpp
@@ -10,6 +10,8 @@
#include "core/fpdfapi/page/cpdf_image.h"
#include "core/fpdfapi/page/cpdf_imageobject.h"
#include "core/fpdfapi/page/cpdf_pageobject.h"
+#include "core/fpdfapi/parser/cpdf_array.h"
+#include "core/fpdfapi/parser/cpdf_name.h"
#include "fpdfsdk/fsdk_define.h"
#include "third_party/base/ptr_util.h"
@@ -179,3 +181,46 @@
return len;
}
+
+DLLEXPORT int STDCALL
+FPDFImageObj_GetImageFilterCount(FPDF_PAGEOBJECT image_object) {
+ CPDF_PageObject* pObj = CPDFPageObjectFromFPDFPageObject(image_object);
+ if (!pObj || !pObj->IsImage())
+ return 0;
+
+ CFX_RetainPtr<CPDF_Image> pImg = pObj->AsImage()->GetImage();
+ if (!pImg)
+ return 0;
+
+ CPDF_Dictionary* pDict = pImg->GetDict();
+ CPDF_Object* pFilter = pDict ? pDict->GetDirectObjectFor("Filter") : nullptr;
+ if (!pFilter)
+ return 0;
+
+ if (pFilter->IsArray())
+ return pFilter->AsArray()->GetCount();
+ if (pFilter->IsName())
+ return 1;
+
+ return 0;
+}
+
+DLLEXPORT unsigned long STDCALL
+FPDFImageObj_GetImageFilter(FPDF_PAGEOBJECT image_object,
+ int index,
+ void* buffer,
+ unsigned long buflen) {
+ if (index < 0 || index >= FPDFImageObj_GetImageFilterCount(image_object))
+ return 0;
+
+ CPDF_PageObject* pObj = CPDFPageObjectFromFPDFPageObject(image_object);
+ CPDF_Object* pFilter =
+ pObj->AsImage()->GetImage()->GetDict()->GetDirectObjectFor("Filter");
+ CFX_WideString wsFilters;
+ if (pFilter->IsName())
+ wsFilters = pFilter->AsName()->GetUnicodeText();
+ else
+ wsFilters = pFilter->AsArray()->GetUnicodeTextAt(index);
+
+ return Utf16EncodeMaybeCopyAndReturnLength(wsFilters, buffer, buflen);
+}
diff --git a/fpdfsdk/fpdfview_c_api_test.c b/fpdfsdk/fpdfview_c_api_test.c
index ef5b804..8276eb6 100644
--- a/fpdfsdk/fpdfview_c_api_test.c
+++ b/fpdfsdk/fpdfview_c_api_test.c
@@ -136,6 +136,8 @@
CHK(FPDFImageObj_GetBitmap);
CHK(FPDFImageObj_GetImageDataDecoded);
CHK(FPDFImageObj_GetImageDataRaw);
+ CHK(FPDFImageObj_GetImageFilterCount);
+ CHK(FPDFImageObj_GetImageFilter);
CHK(FPDFPageObj_CreateNewPath);
CHK(FPDFPageObj_CreateNewRect);
CHK(FPDFPath_SetStrokeColor);
diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
index aab48af..54127d8 100644
--- a/public/fpdf_edit.h
+++ b/public/fpdf_edit.h
@@ -336,6 +336,31 @@
void* buffer,
unsigned long buflen);
+// Get the number of filters (i.e. decoders) of the image in |image_object|.
+//
+// image_object - handle to an image object.
+//
+// Returns the number of |image_object|'s filters.
+DLLEXPORT int STDCALL
+FPDFImageObj_GetImageFilterCount(FPDF_PAGEOBJECT image_object);
+
+// Get the filter at |index| of |image_object|'s list of filters. Note that the
+// filters need to be applied in order, i.e. the first filter should be applied
+// first, then the second, etc. |buffer| is only modified if |buflen| is longer
+// than the length of the filter string.
+//
+// image_object - handle to an image object.
+// index - the index of the filter requested.
+// buffer - buffer for holding filter string, encoded in UTF16-LE.
+// buflen - length of the buffer.
+//
+// Returns the length of the filter string.
+DLLEXPORT unsigned long STDCALL
+FPDFImageObj_GetImageFilter(FPDF_PAGEOBJECT image_object,
+ int index,
+ void* buffer,
+ unsigned long buflen);
+
// Create a new path object at an initial position.
//
// x - initial horizontal position.
diff --git a/testing/resources/embedded_images.pdf b/testing/resources/embedded_images.pdf
index 8184582..82adbea 100644
--- a/testing/resources/embedded_images.pdf
+++ b/testing/resources/embedded_images.pdf
Binary files differ
To view, visit change 10130. To unsubscribe, or for help writing mail filters, visit settings.