7#include "public/fpdf_edit.h"
12#include "core/fpdfapi/page/cpdf_dib.h"
13#include "core/fpdfapi/page/cpdf_image.h"
14#include "core/fpdfapi/page/cpdf_imageobject.h"
15#include "core/fpdfapi/page/cpdf_page.h"
16#include "core/fpdfapi/page/cpdf_pageobject.h"
17#include "core/fpdfapi/parser/cpdf_array.h"
18#include "core/fpdfapi/parser/cpdf_dictionary.h"
19#include "core/fpdfapi/parser/cpdf_name.h"
20#include "core/fpdfapi/parser/cpdf_stream.h"
21#include "core/fpdfapi/parser/cpdf_stream_acc.h"
22#include "core/fpdfapi/render/cpdf_imagerenderer.h"
23#include "core/fpdfapi/render/cpdf_rendercontext.h"
24#include "core/fpdfapi/render/cpdf_renderstatus.h"
25#include "core/fxcrt/stl_util.h"
26#include "core/fxge/cfx_defaultrenderdevice.h"
27#include "core/fxge/dib/cfx_dibitmap.h"
28#include "fpdfsdk/cpdfsdk_customaccess.h"
29#include "fpdfsdk/cpdfsdk_helpers.h"
30#include "third_party/base/notreached.h"
38 "kDeviceGray value mismatch");
41 "kDeviceRGB value mismatch");
44 "kDeviceCMYK value mismatch");
47 "kCalGray value mismatch");
50 "kCalRGB value mismatch");
53 "kLab value mismatch");
56 "kICCBased value mismatch");
59 "kSeparation value mismatch");
62 "kDeviceN value mismatch");
65 "kIndexed value mismatch");
68 "kPattern value mismatch");
71 FPDF_FILEACCESS* pFileAccess) {
72 return pdfium::MakeRetain<CPDFSDK_CustomAccess>(pFileAccess);
75CPDF_ImageObject* CPDFImageObjectFromFPDFPageObject(
76 FPDF_PAGEOBJECT image_object) {
78 return pPageObject ? pPageObject
->AsImage() :
nullptr;
81bool LoadJpegHelper(FPDF_PAGE* pages,
83 FPDF_PAGEOBJECT image_object,
84 FPDF_FILEACCESS* file_access,
86 CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object);
94 for (
int index = 0; index < count; index++) {
97 pImgObj->GetImage()->ResetCache(pPage);
103 pImgObj->GetImage()->SetJpegImageInline(std::move(pFile));
105 pImgObj->GetImage()->SetJpegImage(std::move(pFile));
119 auto pImageObj =
std::make_unique<CPDF_ImageObject>();
120 pImageObj->SetImage(pdfium::MakeRetain<CPDF_Image>(pDoc));
123 return FPDFPageObjectFromCPDFPageObject(pImageObj.release());
129 FPDF_PAGEOBJECT image_object,
130 FPDF_FILEACCESS* file_access) {
131 return LoadJpegHelper(pages, count, image_object, file_access,
false);
137 FPDF_PAGEOBJECT image_object,
138 FPDF_FILEACCESS* file_access) {
139 return LoadJpegHelper(pages, count, image_object, file_access,
true);
150 CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object);
155 static_cast<
float>(a)
, static_cast<
float>(b)
, static_cast<
float>(c)
,
156 static_cast<
float>(d)
, static_cast<
float>(e)
, static_cast<
float>(f)
));
164 FPDF_PAGEOBJECT image_object,
165 FPDF_BITMAP bitmap) {
166 CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object);
174 for (
int index = 0; index < count; index++) {
177 pImgObj->GetImage()->ResetCache(pPage);
181 RetainPtr<CFX_DIBitmap> holder(CFXDIBitmapFromFPDFBitmap(bitmap));
182 pImgObj->GetImage()->SetImage(holder);
190 CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object);
194 RetainPtr<CPDF_Image> pImg = pImgObj->GetImage();
211 enum class ConversionOp {
218 switch (pSource->GetFormat()) {
223 CHECK(!pSource->HasPalette());
224 op = ConversionOp::kConvertTo8bppRgb;
229 op = pSource->HasPalette() ? ConversionOp::kConvertToRgb
230 : ConversionOp::kConvertTo8bppRgb;
235 op = pSource->HasPalette() ? ConversionOp::kConvertToRgb
236 : ConversionOp::kRealize;
242 CHECK(!pSource->HasPalette());
243 op = ConversionOp::kRealize;
247 NOTREACHED_NORETURN();
253 case ConversionOp::kRealize:
254 pBitmap = pSource->Realize();
256 case ConversionOp::kConvertTo8bppRgb:
259 case ConversionOp::kConvertToRgb:
264 CHECK(!pBitmap->HasPalette());
267 return FPDFBitmapFromCFXDIBitmap(pBitmap.Leak());
273 FPDF_PAGEOBJECT image_object) {
282 CPDF_ImageObject* image = CPDFImageObjectFromFPDFPageObject(image_object);
288 int output_width = image_matrix
.a;
289 int output_height = image_matrix
.d;
290 auto result_bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
295 RetainPtr<CPDF_Dictionary> page_resources =
296 optional_page ? optional_page->GetMutablePageResources() :
nullptr;
299 CFX_DefaultRenderDevice device;
311 bool should_continue = renderer
.Start(image
, render_matrix
,
313 while (should_continue)
319#if defined(PDF_USE_SKIA)
320 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
321 result_bitmap->UnPreMultiply();
326 return FPDFBitmapFromCFXDIBitmap(result_bitmap.Leak());
332 unsigned long buflen) {
333 CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object);
337 RetainPtr<CPDF_Image> pImg = pImgObj->GetImage();
341 RetainPtr<
const CPDF_Stream> pImgStream = pImg->GetStream();
345 return DecodeStreamMaybeCopyAndReturnLength(
346 std::move(pImgStream),
347 {
static_cast<uint8_t*>(buffer),
static_cast<size_t>(buflen)});
353 unsigned long buflen) {
354 CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object);
358 RetainPtr<CPDF_Image> pImg = pImgObj->GetImage();
362 RetainPtr<
const CPDF_Stream> pImgStream = pImg->GetStream();
366 return GetRawStreamMaybeCopyAndReturnLength(
367 std::move(pImgStream),
368 {
static_cast<uint8_t*>(buffer),
static_cast<size_t>(buflen)});
373 CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object);
377 RetainPtr<CPDF_Image> pImg = pImgObj->GetImage();
381 RetainPtr<
const CPDF_Dictionary> pDict = pImg->GetDict();
389 if (pFilter->IsArray())
390 return fxcrt::CollectionSize<
int>(*pFilter->AsArray());
392 if (pFilter->IsName())
402 unsigned long buflen) {
408 pObj->AsImage()->GetImage()->GetDict();
410 ByteString bsFilter = pFilter->IsName()
411 ? pFilter->AsName()->GetString()
412 : pFilter->AsArray()->GetByteStringAt(index);
420 FPDF_IMAGEOBJ_METADATA* metadata) {
421 CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object);
422 if (!pImgObj || !metadata)
425 RetainPtr<CPDF_Image> pImg = pImgObj->GetImage();
430 pImgObj->GetContentMarks()->GetMarkedContentID();
432 const int nPixelWidth = pImg->GetPixelWidth();
433 const int nPixelHeight = pImg->GetPixelHeight();
437 const float nWidth = pImgObj
->GetRect().Width();
438 const float nHeight = pImgObj
->GetRect().Height();
439 constexpr int nPointsPerInch = 72;
440 if (nWidth != 0 && nHeight != 0) {
456 RetainPtr<CPDF_DIB> pSource = pImg->CreateNewDIB();
457 CPDF_DIB::
LoadState ret = pSource->StartLoadDIBBase(
458 false,
nullptr, pPage->GetPageResources().Get(),
false,
464 if (pSource->GetColorSpace()) {
466 static_cast<
int>(pSource->GetColorSpace()->GetFamily());
474 unsigned int* height) {
475 CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object);
476 if (!pImgObj || !width || !height) {
480 RetainPtr<CPDF_Image> pImg = pImgObj->GetImage();
485 *width = pImg->GetPixelWidth();
486 *height = pImg->GetPixelHeight();
bool Attach(RetainPtr< CFX_DIBitmap > pBitmap)
CFX_Matrix(float a1, float b1, float c1, float d1, float e1, float f1)
void Translate(float x, float y)
void SetImageMatrix(const CFX_Matrix &matrix)
const CFX_Matrix & matrix() const
CPDF_ImageRenderer(CPDF_RenderStatus *pStatus)
bool Continue(PauseIndicatorIface *pPause)
bool Start(CPDF_ImageObject *pImageObject, const CFX_Matrix &mtObj2Device, bool bStdCS, BlendMode blendType)
void SetDirty(bool value)
const CFX_FloatRect & GetRect() const
virtual CPDF_ImageObject * AsImage()
CPDF_Document * GetDocument() const override
unsigned long NulTerminateMaybeCopyAndReturnLength(const ByteString &text, void *buffer, unsigned long buflen)
CPDF_Page * CPDFPageFromFPDFPage(FPDF_PAGE page)
CPDF_Document * CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc)
CPDF_PageObject * CPDFPageObjectFromFPDFPageObject(FPDF_PAGEOBJECT page_object)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFImageObj_SetBitmap(FPDF_PAGE *pages, int count, FPDF_PAGEOBJECT image_object, FPDF_BITMAP bitmap)
#define FPDF_COLORSPACE_UNKNOWN
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFImageObj_LoadJpegFile(FPDF_PAGE *pages, int count, FPDF_PAGEOBJECT image_object, FPDF_FILEACCESS *file_access)
#define FPDF_COLORSPACE_DEVICECMYK
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFImageObj_GetImageMetadata(FPDF_PAGEOBJECT image_object, FPDF_PAGE page, FPDF_IMAGEOBJ_METADATA *metadata)
#define FPDF_COLORSPACE_CALGRAY
FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFImageObj_GetRenderedBitmap(FPDF_DOCUMENT document, FPDF_PAGE page, FPDF_PAGEOBJECT image_object)
#define FPDF_COLORSPACE_DEVICEN
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFImageObj_GetImageDataRaw(FPDF_PAGEOBJECT image_object, void *buffer, unsigned long buflen)
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFImageObj_GetImageFilter(FPDF_PAGEOBJECT image_object, int index, void *buffer, unsigned long buflen)
FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFImageObj_GetBitmap(FPDF_PAGEOBJECT image_object)
#define FPDF_COLORSPACE_DEVICEGRAY
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object, double a, double b, double c, double d, double e, double f)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFImageObj_LoadJpegFileInline(FPDF_PAGE *pages, int count, FPDF_PAGEOBJECT image_object, FPDF_FILEACCESS *file_access)
FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPageObj_NewImageObj(FPDF_DOCUMENT document)
#define FPDF_COLORSPACE_PATTERN
FPDF_EXPORT int FPDF_CALLCONV FPDFImageObj_GetImageFilterCount(FPDF_PAGEOBJECT image_object)
#define FPDF_COLORSPACE_SEPARATION
#define FPDF_COLORSPACE_LAB
#define FPDF_COLORSPACE_INDEXED
#define FPDF_COLORSPACE_CALRGB
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFImageObj_GetImagePixelSize(FPDF_PAGEOBJECT image_object, unsigned int *width, unsigned int *height)
#define FPDF_COLORSPACE_ICCBASED
FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFImageObj_GetImageDataDecoded(FPDF_PAGEOBJECT image_object, void *buffer, unsigned long buflen)
#define FPDF_COLORSPACE_DEVICERGB