summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfedit_embeddertest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/fpdfedit_embeddertest.cpp')
-rw-r--r--fpdfsdk/fpdfedit_embeddertest.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfedit_embeddertest.cpp b/fpdfsdk/fpdfedit_embeddertest.cpp
index e62ef2149b..6dc177e2b5 100644
--- a/fpdfsdk/fpdfedit_embeddertest.cpp
+++ b/fpdfsdk/fpdfedit_embeddertest.cpp
@@ -1084,3 +1084,50 @@ TEST_F(FPDFEditEmbeddertest, GetImageFilters) {
UnloadPage(page);
}
+
+TEST_F(FPDFEditEmbeddertest, GetImageMetadata) {
+ ASSERT_TRUE(OpenDocument("embedded_images.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+
+ // Check that getting the metadata of a null object would fail.
+ FPDF_IMAGEOBJ_METADATA metadata;
+ EXPECT_FALSE(FPDFImageObj_GetImageMetadata(nullptr, page, &metadata));
+
+ // Check that receiving the metadata with a null metadata object would fail.
+ FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 35);
+ EXPECT_FALSE(FPDFImageObj_GetImageMetadata(obj, page, nullptr));
+
+ // Check that when retrieving an image object's metadata without passing in
+ // |page|, all values are correct, with the last two being default values.
+ ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
+ ASSERT_TRUE(FPDFImageObj_GetImageMetadata(obj, nullptr, &metadata));
+ EXPECT_EQ(92u, metadata.width);
+ EXPECT_EQ(68u, metadata.height);
+ EXPECT_NEAR(96.000000, metadata.horizontal_dpi, 0.001);
+ EXPECT_NEAR(96.000000, metadata.vertical_dpi, 0.001);
+ EXPECT_EQ(0u, metadata.bits_per_pixel);
+ EXPECT_EQ(FPDF_COLORSPACE_UNKNOWN, metadata.colorspace);
+
+ // Verify the metadata of a bitmap image with indexed colorspace.
+ ASSERT_TRUE(FPDFImageObj_GetImageMetadata(obj, page, &metadata));
+ EXPECT_EQ(92u, metadata.width);
+ EXPECT_EQ(68u, metadata.height);
+ EXPECT_NEAR(96.000000, metadata.horizontal_dpi, 0.001);
+ EXPECT_NEAR(96.000000, metadata.vertical_dpi, 0.001);
+ EXPECT_EQ(1u, metadata.bits_per_pixel);
+ EXPECT_EQ(FPDF_COLORSPACE_INDEXED, metadata.colorspace);
+
+ // Verify the metadata of an image with RGB colorspace.
+ obj = FPDFPage_GetObject(page, 37);
+ ASSERT_EQ(FPDF_PAGEOBJ_IMAGE, FPDFPageObj_GetType(obj));
+ ASSERT_TRUE(FPDFImageObj_GetImageMetadata(obj, page, &metadata));
+ EXPECT_EQ(126u, metadata.width);
+ EXPECT_EQ(106u, metadata.height);
+ EXPECT_NEAR(162.173752, metadata.horizontal_dpi, 0.001);
+ EXPECT_NEAR(162.555878, metadata.vertical_dpi, 0.001);
+ EXPECT_EQ(24u, metadata.bits_per_pixel);
+ EXPECT_EQ(FPDF_COLORSPACE_DEVICERGB, metadata.colorspace);
+
+ UnloadPage(page);
+}