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