summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrbpotter <rbpotter@chromium.org>2016-12-14 11:44:31 -0800
committerCommit bot <commit-bot@chromium.org>2016-12-14 11:44:31 -0800
commitf085db37c21ad2bd66e349f9307fc89b426217f5 (patch)
tree1743d925a4b6aae683e31b4e58f793166c13c8d1
parent0d73909e89a5c93917b9cb73fe5c03c484f2793d (diff)
downloadpdfium-f085db37c21ad2bd66e349f9307fc89b426217f5.tar.xz
Add inline JPEGs.
Allows JPEG data to be copied into the file rather than left in a separate file. This is needed to allow rasterized PDFs to avoid saving image files for each page. See Chromium issue 2524143003 for chromium changes. BUG=534945, 550205, 480628 Review-Url: https://codereview.chromium.org/2529543003
-rw-r--r--core/fpdfapi/page/cpdf_image.cpp17
-rw-r--r--core/fpdfapi/page/cpdf_image.h1
-rw-r--r--fpdfsdk/fpdfeditimg.cpp34
-rw-r--r--public/fpdf_edit.h22
4 files changed, 68 insertions, 6 deletions
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index a17222e343..c910319aba 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -140,6 +140,23 @@ void CPDF_Image::SetJpegImage(
m_pStream->InitStreamFromFile(pFile, std::move(pDict));
}
+void CPDF_Image::SetJpegImageInline(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFile) {
+ uint32_t size = pdfium::base::checked_cast<uint32_t>(pFile->GetSize());
+ if (!size)
+ return;
+
+ std::vector<uint8_t> data(size);
+ if (!pFile->ReadBlock(data.data(), 0, size))
+ return;
+
+ std::unique_ptr<CPDF_Dictionary> pDict = InitJPEG(data.data(), size);
+ if (!pDict)
+ return;
+
+ m_pStream->InitStream(&(data[0]), size, std::move(pDict));
+}
+
void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) {
int32_t BitmapWidth = pBitmap->GetWidth();
int32_t BitmapHeight = pBitmap->GetHeight();
diff --git a/core/fpdfapi/page/cpdf_image.h b/core/fpdfapi/page/cpdf_image.h
index 1b0d74f123..e0fc761b38 100644
--- a/core/fpdfapi/page/cpdf_image.h
+++ b/core/fpdfapi/page/cpdf_image.h
@@ -52,6 +52,7 @@ class CPDF_Image {
void SetImage(const CFX_DIBitmap* pDIBitmap);
void SetJpegImage(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile);
+ void SetJpegImageInline(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile);
void ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pDIBitmap);
diff --git a/fpdfsdk/fpdfeditimg.cpp b/fpdfsdk/fpdfeditimg.cpp
index 531a9abc8c..56875e233e 100644
--- a/fpdfsdk/fpdfeditimg.cpp
+++ b/fpdfsdk/fpdfeditimg.cpp
@@ -24,11 +24,11 @@ FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) {
return pImageObj;
}
-DLLEXPORT FPDF_BOOL STDCALL
-FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages,
- int nCount,
- FPDF_PAGEOBJECT image_object,
- FPDF_FILEACCESS* fileAccess) {
+FPDF_BOOL FPDFImageObj_LoadJpegHelper(FPDF_PAGE* pages,
+ int nCount,
+ FPDF_PAGEOBJECT image_object,
+ FPDF_FILEACCESS* fileAccess,
+ bool inlineJpeg) {
if (!image_object || !fileAccess || !pages)
return false;
@@ -40,11 +40,33 @@ FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages,
if (pPage)
pImgObj->GetImage()->ResetCache(pPage, nullptr);
}
- pImgObj->GetImage()->SetJpegImage(pFile);
+
+ if (inlineJpeg)
+ pImgObj->GetImage()->SetJpegImageInline(pFile);
+ else
+ pImgObj->GetImage()->SetJpegImage(pFile);
return true;
}
+DLLEXPORT FPDF_BOOL STDCALL
+FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages,
+ int nCount,
+ FPDF_PAGEOBJECT image_object,
+ FPDF_FILEACCESS* fileAccess) {
+ return FPDFImageObj_LoadJpegHelper(pages, nCount, image_object, fileAccess,
+ false);
+}
+
+DLLEXPORT FPDF_BOOL STDCALL
+FPDFImageObj_LoadJpegFileInline(FPDF_PAGE* pages,
+ int nCount,
+ FPDF_PAGEOBJECT image_object,
+ FPDF_FILEACCESS* fileAccess) {
+ return FPDFImageObj_LoadJpegHelper(pages, nCount, image_object, fileAccess,
+ true);
+}
+
DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object,
double a,
double b,
diff --git a/public/fpdf_edit.h b/public/fpdf_edit.h
index dabdbedd48..640d97ed05 100644
--- a/public/fpdf_edit.h
+++ b/public/fpdf_edit.h
@@ -201,6 +201,28 @@ FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages,
FPDF_PAGEOBJECT image_object,
FPDF_FILEACCESS* fileAccess);
+// Load an image from a JPEG image file and then set it into |image_object|.
+//
+// pages - pointer to the start of all loaded pages, may be NULL.
+// nCount - number of |pages|, may be 0.
+// image_object - handle to an image object.
+// fileAccess - file access handler which specifies the JPEG image file.
+//
+// Returns TRUE on success.
+//
+// The image object might already have an associated image, which is shared and
+// cached by the loaded pages. In that case, we need to clear the cached image
+// for all the loaded pages. Pass |pages| and page count (|nCount|) to this API
+// to clear the image cache. If the image is not previously shared, or NULL is a
+// valid |pages| value. This function loads the JPEG image inline, so the image
+// content is copied to the file. This allows |fileAccess| and its associated
+// data to be deleted after this function returns.
+DLLEXPORT FPDF_BOOL STDCALL
+FPDFImageObj_LoadJpegFileInline(FPDF_PAGE* pages,
+ int nCount,
+ FPDF_PAGEOBJECT image_object,
+ FPDF_FILEACCESS* fileAccess);
+
// Set the transform matrix of |image_object|.
//
// image_object - handle to an image object.