John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 7 | #include "public/fpdf_edit.h" |
| 8 | |
dsinclair | 39c62fd | 2016-09-29 12:49:17 -0700 | [diff] [blame] | 9 | #include "core/fpdfapi/cpdf_modulemgr.h" |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 10 | #include "core/fpdfapi/page/cpdf_image.h" |
| 11 | #include "core/fpdfapi/page/cpdf_imageobject.h" |
| 12 | #include "core/fpdfapi/page/cpdf_pageobject.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 13 | #include "fpdfsdk/fsdk_define.h" |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 14 | #include "third_party/base/ptr_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 15 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 16 | DLLEXPORT FPDF_PAGEOBJECT STDCALL |
| 17 | FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 18 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 19 | if (!pDoc) |
| 20 | return nullptr; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 21 | |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 22 | CPDF_ImageObject* pImageObj = new CPDF_ImageObject; |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 23 | pImageObj->SetOwnedImage(pdfium::MakeUnique<CPDF_Image>(pDoc)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 24 | return pImageObj; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 25 | } |
| 26 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 27 | DLLEXPORT FPDF_BOOL STDCALL |
| 28 | FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages, |
| 29 | int nCount, |
| 30 | FPDF_PAGEOBJECT image_object, |
| 31 | FPDF_FILEACCESS* fileAccess) { |
| 32 | if (!image_object || !fileAccess || !pages) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 33 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 34 | |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame^] | 35 | CFX_RetainPtr<IFX_SeekableReadStream> pFile = |
| 36 | MakeSeekableReadStream(fileAccess); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 37 | CPDF_ImageObject* pImgObj = reinterpret_cast<CPDF_ImageObject*>(image_object); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 38 | for (int index = 0; index < nCount; index++) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 39 | CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 40 | if (pPage) |
thestig | f41d9dc | 2016-08-05 22:34:58 -0700 | [diff] [blame] | 41 | pImgObj->GetImage()->ResetCache(pPage, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 42 | } |
thestig | f41d9dc | 2016-08-05 22:34:58 -0700 | [diff] [blame] | 43 | pImgObj->GetImage()->SetJpegImage(pFile); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 44 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 45 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 48 | DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object, |
| 49 | double a, |
| 50 | double b, |
| 51 | double c, |
| 52 | double d, |
| 53 | double e, |
| 54 | double f) { |
| 55 | if (!image_object) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 56 | return false; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 57 | |
| 58 | CPDF_ImageObject* pImgObj = reinterpret_cast<CPDF_ImageObject*>(image_object); |
thestig | 8a5e15d | 2016-11-21 14:54:29 -0800 | [diff] [blame] | 59 | pImgObj->set_matrix( |
| 60 | CFX_Matrix(static_cast<FX_FLOAT>(a), static_cast<FX_FLOAT>(b), |
| 61 | static_cast<FX_FLOAT>(c), static_cast<FX_FLOAT>(d), |
| 62 | static_cast<FX_FLOAT>(e), static_cast<FX_FLOAT>(f))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 63 | pImgObj->CalcBoundingBox(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 64 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 67 | DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages, |
| 68 | int nCount, |
| 69 | FPDF_PAGEOBJECT image_object, |
| 70 | FPDF_BITMAP bitmap) { |
| 71 | if (!image_object || !bitmap || !pages) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 72 | return false; |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 73 | |
| 74 | CPDF_ImageObject* pImgObj = reinterpret_cast<CPDF_ImageObject*>(image_object); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 75 | for (int index = 0; index < nCount; index++) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 76 | CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]); |
thestig | c54bb43 | 2016-07-29 19:34:20 -0700 | [diff] [blame] | 77 | if (pPage) |
thestig | f41d9dc | 2016-08-05 22:34:58 -0700 | [diff] [blame] | 78 | pImgObj->GetImage()->ResetCache(pPage, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 79 | } |
thestig | 4ccdb14 | 2016-11-21 15:09:23 -0800 | [diff] [blame] | 80 | pImgObj->GetImage()->SetImage(reinterpret_cast<CFX_DIBitmap*>(bitmap)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 81 | pImgObj->CalcBoundingBox(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 82 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 83 | } |