1e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov// Copyright 2014 PDFium Authors. All rights reserved.
2e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov// Use of this source code is governed by a BSD-style license that can be
3e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov// found in the LICENSE file.
4e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov
5e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov
7e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#include "../../public/fpdf_edit.h"
8e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov#include "../include/fsdk_define.h"
9e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov
10e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov
11e6986e1e8d4a57987f47c215490cb080a65ee29aSvet GanovDLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document)
12e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov{
13e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	if (!document)
14e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov		return NULL;
15e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	CPDF_ImageObject* pImageObj = new CPDF_ImageObject;
16e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	CPDF_Image* pImg = new CPDF_Image((CPDF_Document *)document);
17e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	pImageObj->m_pImage = pImg;
18e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	return pImageObj;
19e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov}
20e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov
21e6986e1e8d4a57987f47c215490cb080a65ee29aSvet GanovDLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages, int nCount,FPDF_PAGEOBJECT image_object, FPDF_FILEACCESS* fileAccess)
22e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov{
23e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	if (!image_object || !fileAccess)
24e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov		return FALSE;
25e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov
26e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	IFX_FileRead* pFile = new CPDF_CustomAccess(fileAccess);
27e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
28e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	pImgObj->m_GeneralState.GetModify();
29e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	for (int index=0;index<nCount;index++)
30e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	{
31e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov		CPDF_Page* pPage = (CPDF_Page*)pages[index];
32e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov		pImgObj->m_pImage->ResetCache(pPage,NULL);
33e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	}
34e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	pImgObj->m_pImage->SetJpegImage(pFile);
35e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov
36e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	return TRUE;
37e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov}
38e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov
39e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov
40e6986e1e8d4a57987f47c215490cb080a65ee29aSvet GanovDLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix	(FPDF_PAGEOBJECT image_object,
41e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov												 double a, double b, double c, double d, double e, double f)
42e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov{
43e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	if (!image_object)
44e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov		return FALSE;
45e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
46e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	pImgObj->m_Matrix.a = (FX_FLOAT)a;
47e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	pImgObj->m_Matrix.b = (FX_FLOAT)b;
48e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	pImgObj->m_Matrix.c = (FX_FLOAT)c;
49e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	pImgObj->m_Matrix.d = (FX_FLOAT)d;
50e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	pImgObj->m_Matrix.e = (FX_FLOAT)e;
51e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	pImgObj->m_Matrix.f = (FX_FLOAT)f;
52e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	pImgObj->CalcBoundingBox();
53e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	return  TRUE;
54e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov}
55e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov
56e6986e1e8d4a57987f47c215490cb080a65ee29aSvet GanovDLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages,int nCount,FPDF_PAGEOBJECT image_object,FPDF_BITMAP bitmap)
57e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov{
58e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	if (!image_object || !bitmap)
59e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov		return FALSE;
60e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	CFX_DIBitmap* pBmp = NULL;
61e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	pBmp = (CFX_DIBitmap*)bitmap;
62e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
63e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	pImgObj->m_GeneralState.GetModify();
64e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	for (int index=0;index<nCount;index++)
65e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	{
66e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov		CPDF_Page* pPage = (CPDF_Page*)pages[index];
67e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov		pImgObj->m_pImage->ResetCache(pPage,NULL);
68e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	}
69e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	pImgObj->m_pImage->SetImage(pBmp,FALSE);
70e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	pImgObj->CalcBoundingBox();
71e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov	return TRUE;
72e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov}
73e6986e1e8d4a57987f47c215490cb080a65ee29aSvet Ganov
74