summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfeditimg.cpp
diff options
context:
space:
mode:
authorJane Liu <janeliulwq@google.com>2017-08-09 14:09:34 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-09 18:35:54 +0000
commitbe63ab97e0385b4024ef84fda79fc84dc111ab23 (patch)
treebd56d9e46aefc7f9617f27da624831df1abe67b0 /fpdfsdk/fpdfeditimg.cpp
parentd24b97ee1d065eff482355ea3ff82be59bb528b1 (diff)
downloadpdfium-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/fpdfeditimg.cpp')
-rw-r--r--fpdfsdk/fpdfeditimg.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfeditimg.cpp b/fpdfsdk/fpdfeditimg.cpp
index 0d0c54604b..b4254e97c6 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 @@ FPDFImageObj_GetImageDataRaw(FPDF_PAGEOBJECT image_object,
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);
+}