diff options
author | Jane Liu <janeliulwq@google.com> | 2017-08-03 16:33:40 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-08-03 21:20:23 +0000 |
commit | 548334e57cae1039824d3db97bab5348fbe674e2 (patch) | |
tree | 5c547cc35c48fe5703fde77afd208f1bd1d01029 /fpdfsdk/fpdfeditimg.cpp | |
parent | 6a5b7872c838ba9e24ea6e1f9a306bb95a80ae6c (diff) | |
download | pdfium-548334e57cae1039824d3db97bab5348fbe674e2.tar.xz |
APIs and tests for retrieving raw/decoded data from image objects
Added FPDFImageObj_GetImageDataDecoded() for retrieving the uncompressed
data of an image, and FPDFImageObj_GetImageDataRaw() for retrieving the
raw data of an image.
* Refactored out DecodeStreamMaybeCopyAndReturnLength(), which is
used to decode both attachment data and image data.
* Within DecodeStreamMaybeCopyAndReturnLength(), used a different
decoder function which takes care of multiple filters if exist. As
a result, CPDF_StreamParser::DecodeInlineStream() which was made
static previously is now moved back into namespace.
Bug=pdfium:677
Change-Id: I22a22c99acaca98ef8c15f88911f2646a2c854d5
Reviewed-on: https://pdfium-review.googlesource.com/9811
Commit-Queue: Jane Liu <janeliulwq@google.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfeditimg.cpp')
-rw-r--r-- | fpdfsdk/fpdfeditimg.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfeditimg.cpp b/fpdfsdk/fpdfeditimg.cpp index bfd12b2441..0d0c54604b 100644 --- a/fpdfsdk/fpdfeditimg.cpp +++ b/fpdfsdk/fpdfeditimg.cpp @@ -137,3 +137,45 @@ FPDFImageObj_GetBitmap(FPDF_PAGEOBJECT image_object) { return pBitmap.Leak(); } + +DLLEXPORT unsigned long STDCALL +FPDFImageObj_GetImageDataDecoded(FPDF_PAGEOBJECT image_object, + void* buffer, + unsigned long buflen) { + 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_Stream* pImgStream = pImg->GetStream(); + if (!pImgStream) + return 0; + + return DecodeStreamMaybeCopyAndReturnLength(pImgStream, buffer, buflen); +} + +DLLEXPORT unsigned long STDCALL +FPDFImageObj_GetImageDataRaw(FPDF_PAGEOBJECT image_object, + void* buffer, + unsigned long buflen) { + 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_Stream* pImgStream = pImg->GetStream(); + if (!pImgStream) + return 0; + + uint32_t len = pImgStream->GetRawSize(); + if (buffer && buflen >= len) + memcpy(buffer, pImgStream->GetRawData(), len); + + return len; +} |