Revert "Revert "Add type cast definitions for CPDF_Dictionary.""
[pdfium.git] / fpdfsdk / src / fpdfeditimg.cpp
index 3b5272c..73fc251 100644 (file)
@@ -9,10 +9,11 @@
 
 DLLEXPORT FPDF_PAGEOBJECT STDCALL
 FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) {
-  if (!document)
-    return NULL;
+  CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+  if (!pDoc)
+    return nullptr;
   CPDF_ImageObject* pImageObj = new CPDF_ImageObject;
-  CPDF_Image* pImg = new CPDF_Image((CPDF_Document*)document);
+  CPDF_Image* pImg = new CPDF_Image(pDoc);
   pImageObj->m_pImage = pImg;
   return pImageObj;
 }
@@ -22,14 +23,16 @@ FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages,
                           int nCount,
                           FPDF_PAGEOBJECT image_object,
                           FPDF_FILEACCESS* fileAccess) {
-  if (!image_object || !fileAccess)
+  if (!image_object || !fileAccess || !pages)
     return FALSE;
 
   IFX_FileRead* pFile = new CPDF_CustomAccess(fileAccess);
   CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
   pImgObj->m_GeneralState.GetModify();
   for (int index = 0; index < nCount; index++) {
-    CPDF_Page* pPage = (CPDF_Page*)pages[index];
+    CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]);
+    if (!pPage)
+      continue;
     pImgObj->m_pImage->ResetCache(pPage, NULL);
   }
   pImgObj->m_pImage->SetJpegImage(pFile);
@@ -61,14 +64,16 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages,
                                                    int nCount,
                                                    FPDF_PAGEOBJECT image_object,
                                                    FPDF_BITMAP bitmap) {
-  if (!image_object || !bitmap)
+  if (!image_object || !bitmap || !pages)
     return FALSE;
   CFX_DIBitmap* pBmp = NULL;
   pBmp = (CFX_DIBitmap*)bitmap;
   CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
   pImgObj->m_GeneralState.GetModify();
   for (int index = 0; index < nCount; index++) {
-    CPDF_Page* pPage = (CPDF_Page*)pages[index];
+    CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]);
+    if (!pPage)
+      continue;
     pImgObj->m_pImage->ResetCache(pPage, NULL);
   }
   pImgObj->m_pImage->SetImage(pBmp, FALSE);