7#include "public/fpdf_edit.h"
14#include "core/fpdfapi/page/cpdf_dib.h"
15#include "core/fpdfapi/page/cpdf_image.h"
16#include "core/fpdfapi/page/cpdf_imageobject.h"
17#include "core/fpdfapi/page/cpdf_page.h"
18#include "core/fpdfapi/page/cpdf_pageobject.h"
19#include "core/fpdfapi/parser/cpdf_array.h"
20#include "core/fpdfapi/parser/cpdf_dictionary.h"
21#include "core/fpdfapi/parser/cpdf_name.h"
22#include "core/fpdfapi/parser/cpdf_stream.h"
23#include "core/fpdfapi/parser/cpdf_stream_acc.h"
24#include "core/fpdfapi/render/cpdf_imagerenderer.h"
25#include "core/fpdfapi/render/cpdf_rendercontext.h"
26#include "core/fpdfapi/render/cpdf_renderstatus.h"
27#include "core/fxcrt/compiler_specific.h"
28#include "core/fxcrt/notreached.h"
29#include "core/fxcrt/stl_util.h"
30#include "core/fxge/cfx_defaultrenderdevice.h"
31#include "core/fxge/dib/cfx_dibitmap.h"
32#include "fpdfsdk/cpdfsdk_customaccess.h"
33#include "fpdfsdk/cpdfsdk_helpers.h"
41 "kDeviceGray value mismatch");
44 "kDeviceRGB value mismatch");
47 "kDeviceCMYK value mismatch");
50 "kCalGray value mismatch");
53 "kCalRGB value mismatch");
56 "kLab value mismatch");
59 "kICCBased value mismatch");
62 "kSeparation value mismatch");
65 "kDeviceN value mismatch");
68 "kIndexed value mismatch");
71 "kPattern value mismatch");
74 FPDF_FILEACCESS* pFileAccess) {
75 return pdfium::MakeRetain<CPDFSDK_CustomAccess>(pFileAccess);
78CPDF_ImageObject* CPDFImageObjectFromFPDFPageObject(
79 FPDF_PAGEOBJECT image_object) {
81 return pPageObject ? pPageObject
->AsImage() :
nullptr;
84bool LoadJpegHelper(FPDF_PAGE* pages,
86 FPDF_PAGEOBJECT image_object,
87 FPDF_FILEACCESS* file_access,
89 CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object);
97 for (
int index = 0; index < count; index++) {
100 pImgObj->GetImage()->ResetCache(pPage);
107 pImgObj->GetImage()->SetJpegImageInline(std::move(pFile));
109 pImgObj->GetImage()->SetJpegImage(std::move(pFile));
123 auto pImageObj =
std::make_unique<CPDF_ImageObject>();
124 pImageObj->SetImage(
pdfium::MakeRetain<CPDF_Image>(pDoc));
127 return FPDFPageObjectFromCPDFPageObject(pImageObj.release());
133 FPDF_PAGEOBJECT image_object,
134 FPDF_FILEACCESS* file_access) {
135 return LoadJpegHelper(pages, count, image_object, file_access,
false);
141 FPDF_PAGEOBJECT image_object,
142 FPDF_FILEACCESS* file_access) {
143 return LoadJpegHelper(pages, count, image_object, file_access,
true);
154 CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object);
159 static_cast<
float>(a)
, static_cast<
float>(b)
, static_cast<
float>(c)
,
160 static_cast<
float>(d)
, static_cast<
float>(e)
, static_cast<
float>(f)
));
168 FPDF_PAGEOBJECT image_object,
169 FPDF_BITMAP bitmap) {
170 CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object);
175 RetainPtr<CFX_DIBitmap> holder(CFXDIBitmapFromFPDFBitmap(bitmap));
179 CHECK(!holder->IsPremultiplied());
182 for (
int index = 0; index < count; index++) {
185 pImgObj->GetImage()->ResetCache(pPage);
190 pImgObj->GetImage()->SetImage(holder);
198 CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object);
202 RetainPtr<CPDF_Image> pImg = pImgObj->GetImage();
219 enum class ConversionOp {
226 switch (pSource->GetFormat()) {
231 CHECK(!pSource->HasPalette());
232 op = ConversionOp::kConvertTo8bppRgb;
238 op = pSource->HasPalette() ? ConversionOp::kConvertToRgb
239 : ConversionOp::kConvertTo8bppRgb;
248 op = pSource->HasPalette() ? ConversionOp::kConvertToRgb
249 : ConversionOp::kRealize;
255#if defined(PDF_USE_SKIA)
256 case FXDIB_Format::kBgraPremul: {
259 NOTREACHED_NORETURN();
266 case ConversionOp::kRealize:
267 pBitmap = pSource->Realize();
269 case ConversionOp::kConvertTo8bppRgb:
272 case ConversionOp::kConvertToRgb:
280 CHECK(!pBitmap->HasPalette());
281 CHECK(!pBitmap->IsPremultiplied());
284 return FPDFBitmapFromCFXDIBitmap(pBitmap.Leak());
290 FPDF_PAGEOBJECT image_object) {
299 CPDF_ImageObject* image = CPDFImageObjectFromFPDFPageObject(image_object);
305 float output_width =
std::ceil(hypotf(image_matrix
.a, image_matrix
.c));
306 float output_height =
std::ceil(hypotf(image_matrix
.b, image_matrix
.d));
307 auto result_bitmap =
pdfium::MakeRetain<CFX_DIBitmap>();
308 if (!result_bitmap->Create(
static_cast<
int>(output_width),
309 static_cast<
int>(output_height),
316 optional_page ? optional_page->GetMutablePageResources() :
nullptr;
319 CFX_DefaultRenderDevice device;
328 float min_x = image_matrix
.e +
std::min(image_matrix
.a, image_matrix
.c);
329 float min_y = image_matrix
.f +
std::min(image_matrix
.b, image_matrix
.d);
333 bool should_continue = renderer
.Start(image
, render_matrix
, false);
334 while (should_continue) {
341 CHECK(!result_bitmap->IsPremultiplied());
344 return FPDFBitmapFromCFXDIBitmap(result_bitmap.Leak());
350 unsigned long buflen) {
351 CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object);
355 RetainPtr<CPDF_Image> pImg = pImgObj->GetImage();
359 RetainPtr<
const CPDF_Stream> pImgStream = pImg->GetStream();
364 return DecodeStreamMaybeCopyAndReturnLength(
365 std::move(pImgStream),
367 static_cast<size_t>(buflen))));
373 unsigned long buflen) {
374 CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object);
378 RetainPtr<CPDF_Image> pImg = pImgObj->GetImage();
382 RetainPtr<
const CPDF_Stream> pImgStream = pImg->GetStream();
387 return GetRawStreamMaybeCopyAndReturnLength(
388 std::move(pImgStream),
390 static_cast<size_t>(buflen))));
395 CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object);
399 RetainPtr<CPDF_Image> pImg = pImgObj->GetImage();
411 if (pFilter->IsArray())
412 return fxcrt::CollectionSize<
int>(*pFilter->AsArray());
414 if (pFilter->IsName())
424 unsigned long buflen) {
430 pObj->AsImage()->GetImage()->GetDict();
433 ? pFilter->AsName()->GetString()
434 : pFilter->AsArray()->GetByteStringAt(index);
437 return NulTerminateMaybeCopyAndReturnLength(
444 FPDF_IMAGEOBJ_METADATA* metadata) {
445 CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object);
446 if (!pImgObj || !metadata)
449 RetainPtr<CPDF_Image> pImg = pImgObj->GetImage();
454 pImgObj->GetContentMarks()->GetMarkedContentID();
456 const int nPixelWidth = pImg->GetPixelWidth();
457 const int nPixelHeight = pImg->GetPixelHeight();
461 const float nWidth = pImgObj
->GetRect().Width();
462 const float nHeight = pImgObj
->GetRect().Height();
463 constexpr int nPointsPerInch = 72;
464 if (nWidth != 0 && nHeight != 0) {
480 RetainPtr<CPDF_DIB> pSource = pImg->CreateNewDIB();
481 CPDF_DIB::
LoadState ret = pSource->StartLoadDIBBase(
482 false,
nullptr, pPage->GetPageResources().Get(),
false,
488 if (pSource->GetColorSpace()) {
490 static_cast<
int>(pSource->GetColorSpace()->GetFamily());
498 unsigned int* height) {
499 CPDF_ImageObject* pImgObj = CPDFImageObjectFromFPDFPageObject(image_object);
500 if (!pImgObj || !width || !height) {
504 RetainPtr<CPDF_Image> pImg = pImgObj->GetImage();
509 *width = pImg->GetPixelWidth();
510 *height = pImg->GetPixelHeight();
fxcrt::ByteString ByteString
bool Attach(RetainPtr< CFX_DIBitmap > pBitmap)
constexpr CFX_Matrix(float a1, float b1, float c1, float d1, float e1, float f1)
void Translate(float x, float y)
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
void SetImageMatrix(const CFX_Matrix &matrix)
const CFX_Matrix & matrix() const
CPDF_ImageRenderer(CPDF_RenderStatus *pStatus)
bool Start(CPDF_ImageObject *pImageObject, const CFX_Matrix &mtObj2Device, bool bStdCS)
bool Continue(PauseIndicatorIface *pPause)
void SetDirty(bool value)
const CFX_FloatRect & GetRect() const
virtual CPDF_ImageObject * AsImage()
CPDF_Document * GetDocument() const override
#define UNSAFE_BUFFERS(...)
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
#define NOTREACHED_NORETURN()