summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfedit_embeddertest.cpp
diff options
context:
space:
mode:
authorJane Liu <janeliulwq@google.com>2017-08-03 16:33:40 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-03 21:20:23 +0000
commit548334e57cae1039824d3db97bab5348fbe674e2 (patch)
tree5c547cc35c48fe5703fde77afd208f1bd1d01029 /fpdfsdk/fpdfedit_embeddertest.cpp
parent6a5b7872c838ba9e24ea6e1f9a306bb95a80ae6c (diff)
downloadpdfium-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/fpdfedit_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdfedit_embeddertest.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp
index dcaeb945d7..f1bbb87422 100644
--- a/fpdfsdk/fpdfedit_embeddertest.cpp
+++ b/fpdfsdk/fpdfedit_embeddertest.cpp
@@ -5,6 +5,7 @@
#include <memory>
#include <string>
#include <utility>
+#include <vector>
#include "core/fpdfapi/font/cpdf_font.h"
#include "core/fpdfapi/page/cpdf_page.h"
@@ -979,3 +980,53 @@ TEST_F(FPDFEditEmbeddertest, ExtractImageBitmap) {
FPDFBitmap_Destroy(bitmap);
UnloadPage(page);
}
+
+TEST_F(FPDFEditEmbeddertest, GetImageData) {
+ EXPECT_TRUE(OpenDocument("embedded_images.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+ ASSERT_EQ(39, FPDFPage_CountObject(page));
+
+ // Retrieve an image object with flate-encoded data stream.
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 33);
+ ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
+
+ // Check that the raw image data has the correct length and hash value.
+ unsigned long len = FPDFImageObj_GetImageDataRaw(obj, nullptr, 0);
+ std::vector<char> buf(len);
+ EXPECT_EQ(4091u, FPDFImageObj_GetImageDataRaw(obj, buf.data(), len));
+ EXPECT_EQ("f73802327d2e88e890f653961bcda81a",
+ GenerateMD5Base16(reinterpret_cast<uint8_t*>(buf.data()), len));
+
+ // Check that the decoded image data has the correct length and hash value.
+ len = FPDFImageObj_GetImageDataDecoded(obj, nullptr, 0);
+ buf.clear();
+ buf.resize(len);
+ EXPECT_EQ(28776u, FPDFImageObj_GetImageDataDecoded(obj, buf.data(), len));
+ EXPECT_EQ("cb3637934bb3b95a6e4ae1ea9eb9e56e",
+ GenerateMD5Base16(reinterpret_cast<uint8_t*>(buf.data()), len));
+
+ // Retrieve an image obejct with DCTDecode-encoded data stream.
+ obj = FPDFPage_GetObject(page, 37);
+ ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
+
+ // Check that the raw image data has the correct length and hash value.
+ len = FPDFImageObj_GetImageDataRaw(obj, nullptr, 0);
+ buf.clear();
+ buf.resize(len);
+ EXPECT_EQ(4370u, FPDFImageObj_GetImageDataRaw(obj, buf.data(), len));
+ EXPECT_EQ("6aae1f3710335023a9e12191be66b64b",
+ GenerateMD5Base16(reinterpret_cast<uint8_t*>(buf.data()), len));
+
+ // Check that the decoded image data has the correct length and hash value,
+ // which should be the same as those of the raw data, since this image is
+ // encoded by a single DCTDecode filter and decoding is a noop.
+ len = FPDFImageObj_GetImageDataDecoded(obj, nullptr, 0);
+ buf.clear();
+ buf.resize(len);
+ EXPECT_EQ(4370u, FPDFImageObj_GetImageDataDecoded(obj, buf.data(), len));
+ EXPECT_EQ("6aae1f3710335023a9e12191be66b64b",
+ GenerateMD5Base16(reinterpret_cast<uint8_t*>(buf.data()), len));
+
+ UnloadPage(page);
+}