blob: cd283019770dde11f2c71674824435e513a219d8 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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 Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Lei Zhangb4e7f302015-11-06 15:52:32 -08007#include "public/fpdf_edit.h"
8
dan sinclair61b2fc72016-03-23 19:21:44 -04009#include "core/fpdfapi/fpdf_page/include/cpdf_image.h"
Dan Sinclair584b1e62016-03-21 09:15:45 -040010#include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h"
11#include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h"
Dan Sinclairaa403d32016-03-15 14:57:22 -040012#include "core/fpdfapi/include/cpdf_modulemgr.h"
Lei Zhangbde53d22015-11-12 22:21:30 -080013#include "fpdfsdk/include/fsdk_define.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070014
Nico Weber9d8ec5a2015-08-04 13:00:21 -070015DLLEXPORT FPDF_PAGEOBJECT STDCALL
16FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) {
Tom Sepez471a1032015-10-15 16:17:18 -070017 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
18 if (!pDoc)
19 return nullptr;
thestigc54bb432016-07-29 19:34:20 -070020
Tom Sepezae51c812015-08-05 12:34:06 -070021 CPDF_ImageObject* pImageObj = new CPDF_ImageObject;
thestigc54bb432016-07-29 19:34:20 -070022 pImageObj->m_pImage = new CPDF_Image(pDoc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070023 return pImageObj;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070024}
25
Nico Weber9d8ec5a2015-08-04 13:00:21 -070026DLLEXPORT FPDF_BOOL STDCALL
27FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages,
28 int nCount,
29 FPDF_PAGEOBJECT image_object,
30 FPDF_FILEACCESS* fileAccess) {
31 if (!image_object || !fileAccess || !pages)
32 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070033
Tom Sepezae51c812015-08-05 12:34:06 -070034 IFX_FileRead* pFile = new CPDF_CustomAccess(fileAccess);
thestigc54bb432016-07-29 19:34:20 -070035 CPDF_ImageObject* pImgObj = reinterpret_cast<CPDF_ImageObject*>(image_object);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070036 pImgObj->m_GeneralState.GetModify();
37 for (int index = 0; index < nCount; index++) {
Tom Sepezdb0be962015-10-16 14:00:21 -070038 CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]);
thestigc54bb432016-07-29 19:34:20 -070039 if (pPage)
thestigf41d9dc2016-08-05 22:34:58 -070040 pImgObj->GetImage()->ResetCache(pPage, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041 }
thestigf41d9dc2016-08-05 22:34:58 -070042 pImgObj->GetImage()->SetJpegImage(pFile);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070043
Nico Weber9d8ec5a2015-08-04 13:00:21 -070044 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070045}
46
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object,
48 double a,
49 double b,
50 double c,
51 double d,
52 double e,
53 double f) {
54 if (!image_object)
55 return FALSE;
thestigc54bb432016-07-29 19:34:20 -070056
57 CPDF_ImageObject* pImgObj = reinterpret_cast<CPDF_ImageObject*>(image_object);
58 pImgObj->m_Matrix.a = static_cast<FX_FLOAT>(a);
59 pImgObj->m_Matrix.b = static_cast<FX_FLOAT>(b);
60 pImgObj->m_Matrix.c = static_cast<FX_FLOAT>(c);
61 pImgObj->m_Matrix.d = static_cast<FX_FLOAT>(d);
62 pImgObj->m_Matrix.e = static_cast<FX_FLOAT>(e);
63 pImgObj->m_Matrix.f = static_cast<FX_FLOAT>(f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064 pImgObj->CalcBoundingBox();
65 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070066}
67
Nico Weber9d8ec5a2015-08-04 13:00:21 -070068DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages,
69 int nCount,
70 FPDF_PAGEOBJECT image_object,
71 FPDF_BITMAP bitmap) {
72 if (!image_object || !bitmap || !pages)
73 return FALSE;
thestigc54bb432016-07-29 19:34:20 -070074
75 CPDF_ImageObject* pImgObj = reinterpret_cast<CPDF_ImageObject*>(image_object);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070076 pImgObj->m_GeneralState.GetModify();
77 for (int index = 0; index < nCount; index++) {
Tom Sepezdb0be962015-10-16 14:00:21 -070078 CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]);
thestigc54bb432016-07-29 19:34:20 -070079 if (pPage)
thestigf41d9dc2016-08-05 22:34:58 -070080 pImgObj->GetImage()->ResetCache(pPage, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070081 }
thestigf41d9dc2016-08-05 22:34:58 -070082 pImgObj->GetImage()->SetImage(reinterpret_cast<CFX_DIBitmap*>(bitmap), FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083 pImgObj->CalcBoundingBox();
84 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070085}