diff options
author | thestig <thestig@chromium.org> | 2016-07-29 19:34:20 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-07-29 19:34:20 -0700 |
commit | c54bb4340324fab9e860fd625b4b380b6135c385 (patch) | |
tree | 8e1e0f1f1316b88ac1b5426a3577d2347d42927b /fpdfsdk/fpdfeditimg.cpp | |
parent | 9c987e9d233c855951db2611433b9cbc4f1b648f (diff) | |
download | pdfium-c54bb4340324fab9e860fd625b4b380b6135c385.tar.xz |
Simplify some FPDF edit functions.
Fix an unlikely memory leak in FPDFPage_InsertObject().
BUG=pdfium:545
Review-Url: https://codereview.chromium.org/2195643002
Diffstat (limited to 'fpdfsdk/fpdfeditimg.cpp')
-rw-r--r-- | fpdfsdk/fpdfeditimg.cpp | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/fpdfsdk/fpdfeditimg.cpp b/fpdfsdk/fpdfeditimg.cpp index 4429dcd201..b2c25779c6 100644 --- a/fpdfsdk/fpdfeditimg.cpp +++ b/fpdfsdk/fpdfeditimg.cpp @@ -17,9 +17,9 @@ FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); if (!pDoc) return nullptr; + CPDF_ImageObject* pImageObj = new CPDF_ImageObject; - CPDF_Image* pImg = new CPDF_Image(pDoc); - pImageObj->m_pImage = pImg; + pImageObj->m_pImage = new CPDF_Image(pDoc); return pImageObj; } @@ -32,13 +32,12 @@ FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages, return FALSE; IFX_FileRead* pFile = new CPDF_CustomAccess(fileAccess); - CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object; + CPDF_ImageObject* pImgObj = reinterpret_cast<CPDF_ImageObject*>(image_object); pImgObj->m_GeneralState.GetModify(); for (int index = 0; index < nCount; index++) { CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]); - if (!pPage) - continue; - pImgObj->m_pImage->ResetCache(pPage, nullptr); + if (pPage) + pImgObj->m_pImage->ResetCache(pPage, nullptr); } pImgObj->m_pImage->SetJpegImage(pFile); @@ -54,13 +53,14 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object, double f) { if (!image_object) return FALSE; - CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object; - pImgObj->m_Matrix.a = (FX_FLOAT)a; - pImgObj->m_Matrix.b = (FX_FLOAT)b; - pImgObj->m_Matrix.c = (FX_FLOAT)c; - pImgObj->m_Matrix.d = (FX_FLOAT)d; - pImgObj->m_Matrix.e = (FX_FLOAT)e; - pImgObj->m_Matrix.f = (FX_FLOAT)f; + + CPDF_ImageObject* pImgObj = reinterpret_cast<CPDF_ImageObject*>(image_object); + pImgObj->m_Matrix.a = static_cast<FX_FLOAT>(a); + pImgObj->m_Matrix.b = static_cast<FX_FLOAT>(b); + pImgObj->m_Matrix.c = static_cast<FX_FLOAT>(c); + pImgObj->m_Matrix.d = static_cast<FX_FLOAT>(d); + pImgObj->m_Matrix.e = static_cast<FX_FLOAT>(e); + pImgObj->m_Matrix.f = static_cast<FX_FLOAT>(f); pImgObj->CalcBoundingBox(); return TRUE; } @@ -71,17 +71,15 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages, FPDF_BITMAP bitmap) { if (!image_object || !bitmap || !pages) return FALSE; - CFX_DIBitmap* pBmp = nullptr; - pBmp = (CFX_DIBitmap*)bitmap; - CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object; + + CPDF_ImageObject* pImgObj = reinterpret_cast<CPDF_ImageObject*>(image_object); pImgObj->m_GeneralState.GetModify(); for (int index = 0; index < nCount; index++) { CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]); - if (!pPage) - continue; - pImgObj->m_pImage->ResetCache(pPage, nullptr); + if (pPage) + pImgObj->m_pImage->ResetCache(pPage, nullptr); } - pImgObj->m_pImage->SetImage(pBmp, FALSE); + pImgObj->m_pImage->SetImage(reinterpret_cast<CFX_DIBitmap*>(bitmap), FALSE); pImgObj->CalcBoundingBox(); return TRUE; } |