DEPS include_rules no longer allows core/ -> fpsdfsk/ inclusion.
[pdfium.git] / fpdfsdk / src / fpdfeditimg.cpp
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.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "../../public/fpdf_edit.h"
8 #include "../include/fsdk_define.h"
9
10 DLLEXPORT FPDF_PAGEOBJECT STDCALL
11 FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) {
12   CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
13   if (!pDoc)
14     return nullptr;
15   CPDF_ImageObject* pImageObj = new CPDF_ImageObject;
16   CPDF_Image* pImg = new CPDF_Image(pDoc);
17   pImageObj->m_pImage = pImg;
18   return pImageObj;
19 }
20
21 DLLEXPORT FPDF_BOOL STDCALL
22 FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages,
23                           int nCount,
24                           FPDF_PAGEOBJECT image_object,
25                           FPDF_FILEACCESS* fileAccess) {
26   if (!image_object || !fileAccess || !pages)
27     return FALSE;
28
29   IFX_FileRead* pFile = new CPDF_CustomAccess(fileAccess);
30   CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
31   pImgObj->m_GeneralState.GetModify();
32   for (int index = 0; index < nCount; index++) {
33     CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]);
34     if (!pPage)
35       continue;
36     pImgObj->m_pImage->ResetCache(pPage, NULL);
37   }
38   pImgObj->m_pImage->SetJpegImage(pFile);
39
40   return TRUE;
41 }
42
43 DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object,
44                                                    double a,
45                                                    double b,
46                                                    double c,
47                                                    double d,
48                                                    double e,
49                                                    double f) {
50   if (!image_object)
51     return FALSE;
52   CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
53   pImgObj->m_Matrix.a = (FX_FLOAT)a;
54   pImgObj->m_Matrix.b = (FX_FLOAT)b;
55   pImgObj->m_Matrix.c = (FX_FLOAT)c;
56   pImgObj->m_Matrix.d = (FX_FLOAT)d;
57   pImgObj->m_Matrix.e = (FX_FLOAT)e;
58   pImgObj->m_Matrix.f = (FX_FLOAT)f;
59   pImgObj->CalcBoundingBox();
60   return TRUE;
61 }
62
63 DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages,
64                                                    int nCount,
65                                                    FPDF_PAGEOBJECT image_object,
66                                                    FPDF_BITMAP bitmap) {
67   if (!image_object || !bitmap || !pages)
68     return FALSE;
69   CFX_DIBitmap* pBmp = NULL;
70   pBmp = (CFX_DIBitmap*)bitmap;
71   CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
72   pImgObj->m_GeneralState.GetModify();
73   for (int index = 0; index < nCount; index++) {
74     CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]);
75     if (!pPage)
76       continue;
77     pImgObj->m_pImage->ResetCache(pPage, NULL);
78   }
79   pImgObj->m_pImage->SetImage(pBmp, FALSE);
80   pImgObj->CalcBoundingBox();
81   return TRUE;
82 }