Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: core/src/fxge/dib/fx_dib_main.cpp

Issue 1297713003: Don't bother checking pointers before delete[] and FX_Free(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fxge/dib/fx_dib_engine.cpp ('k') | core/src/fxge/ge/fx_ge_font.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../../include/fxge/fx_dib.h" 7 #include "../../../include/fxge/fx_dib.h"
8 #include "../../../include/fxge/fx_ge.h" 8 #include "../../../include/fxge/fx_ge.h"
9 #include "../../../include/fxcodec/fx_codec.h" 9 #include "../../../include/fxcodec/fx_codec.h"
10 #include "dib_int.h" 10 #include "dib_int.h"
(...skipping 30 matching lines...) Expand all
41 } 41 }
42 CFX_DIBSource::CFX_DIBSource() { 42 CFX_DIBSource::CFX_DIBSource() {
43 m_bpp = 0; 43 m_bpp = 0;
44 m_AlphaFlag = 0; 44 m_AlphaFlag = 0;
45 m_Width = m_Height = 0; 45 m_Width = m_Height = 0;
46 m_Pitch = 0; 46 m_Pitch = 0;
47 m_pPalette = NULL; 47 m_pPalette = NULL;
48 m_pAlphaMask = NULL; 48 m_pAlphaMask = NULL;
49 } 49 }
50 CFX_DIBSource::~CFX_DIBSource() { 50 CFX_DIBSource::~CFX_DIBSource() {
51 if (m_pPalette) { 51 FX_Free(m_pPalette);
52 FX_Free(m_pPalette);
53 }
54 delete m_pAlphaMask; 52 delete m_pAlphaMask;
55 } 53 }
56 CFX_DIBitmap::CFX_DIBitmap() { 54 CFX_DIBitmap::CFX_DIBitmap() {
57 m_bExtBuf = FALSE; 55 m_bExtBuf = FALSE;
58 m_pBuffer = NULL; 56 m_pBuffer = NULL;
59 m_pPalette = NULL; 57 m_pPalette = NULL;
60 } 58 }
61 #define _MAX_OOM_LIMIT_ 12000000 59 #define _MAX_OOM_LIMIT_ 12000000
62 FX_BOOL CFX_DIBitmap::Create(int width, 60 FX_BOOL CFX_DIBitmap::Create(int width,
63 int height, 61 int height,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 m_pBuffer = FX_Alloc(uint8_t, size); 93 m_pBuffer = FX_Alloc(uint8_t, size);
96 } 94 }
97 } 95 }
98 m_Width = width; 96 m_Width = width;
99 m_Height = height; 97 m_Height = height;
100 m_Pitch = pitch; 98 m_Pitch = pitch;
101 if (HasAlpha() && format != FXDIB_Argb) { 99 if (HasAlpha() && format != FXDIB_Argb) {
102 FX_BOOL ret = TRUE; 100 FX_BOOL ret = TRUE;
103 ret = BuildAlphaMask(); 101 ret = BuildAlphaMask();
104 if (!ret) { 102 if (!ret) {
105 if (!m_bExtBuf && m_pBuffer) { 103 if (!m_bExtBuf) {
106 FX_Free(m_pBuffer); 104 FX_Free(m_pBuffer);
107 m_pBuffer = NULL; 105 m_pBuffer = NULL;
108 m_Width = m_Height = m_Pitch = 0; 106 m_Width = m_Height = m_Pitch = 0;
109 return FALSE; 107 return FALSE;
110 } 108 }
111 } 109 }
112 } 110 }
113 return TRUE; 111 return TRUE;
114 } 112 }
115 FX_BOOL CFX_DIBitmap::Copy(const CFX_DIBSource* pSrc) { 113 FX_BOOL CFX_DIBitmap::Copy(const CFX_DIBSource* pSrc) {
116 if (m_pBuffer) { 114 if (m_pBuffer) {
117 return FALSE; 115 return FALSE;
118 } 116 }
119 if (!Create(pSrc->GetWidth(), pSrc->GetHeight(), pSrc->GetFormat())) { 117 if (!Create(pSrc->GetWidth(), pSrc->GetHeight(), pSrc->GetFormat())) {
120 return FALSE; 118 return FALSE;
121 } 119 }
122 CopyPalette(pSrc->GetPalette()); 120 CopyPalette(pSrc->GetPalette());
123 CopyAlphaMask(pSrc->m_pAlphaMask); 121 CopyAlphaMask(pSrc->m_pAlphaMask);
124 for (int row = 0; row < pSrc->GetHeight(); row++) { 122 for (int row = 0; row < pSrc->GetHeight(); row++) {
125 FXSYS_memcpy(m_pBuffer + row * m_Pitch, pSrc->GetScanline(row), m_Pitch); 123 FXSYS_memcpy(m_pBuffer + row * m_Pitch, pSrc->GetScanline(row), m_Pitch);
126 } 124 }
127 return TRUE; 125 return TRUE;
128 } 126 }
129 CFX_DIBitmap::~CFX_DIBitmap() { 127 CFX_DIBitmap::~CFX_DIBitmap() {
130 if (m_pBuffer && !m_bExtBuf) { 128 if (!m_bExtBuf) {
131 FX_Free(m_pBuffer); 129 FX_Free(m_pBuffer);
132 } 130 }
133 m_pBuffer = NULL; 131 m_pBuffer = NULL;
134 } 132 }
135 void CFX_DIBitmap::TakeOver(CFX_DIBitmap* pSrcBitmap) { 133 void CFX_DIBitmap::TakeOver(CFX_DIBitmap* pSrcBitmap) {
136 if (m_pBuffer && !m_bExtBuf) { 134 if (!m_bExtBuf) {
137 FX_Free(m_pBuffer); 135 FX_Free(m_pBuffer);
138 } 136 }
139 if (m_pPalette) { 137 FX_Free(m_pPalette);
140 FX_Free(m_pPalette);
141 }
142 delete m_pAlphaMask; 138 delete m_pAlphaMask;
143 m_pBuffer = pSrcBitmap->m_pBuffer; 139 m_pBuffer = pSrcBitmap->m_pBuffer;
144 m_pPalette = pSrcBitmap->m_pPalette; 140 m_pPalette = pSrcBitmap->m_pPalette;
145 m_pAlphaMask = pSrcBitmap->m_pAlphaMask; 141 m_pAlphaMask = pSrcBitmap->m_pAlphaMask;
146 pSrcBitmap->m_pBuffer = NULL; 142 pSrcBitmap->m_pBuffer = NULL;
147 pSrcBitmap->m_pPalette = NULL; 143 pSrcBitmap->m_pPalette = NULL;
148 pSrcBitmap->m_pAlphaMask = NULL; 144 pSrcBitmap->m_pAlphaMask = NULL;
149 m_bpp = pSrcBitmap->m_bpp; 145 m_bpp = pSrcBitmap->m_bpp;
150 m_bExtBuf = pSrcBitmap->m_bExtBuf; 146 m_bExtBuf = pSrcBitmap->m_bExtBuf;
151 m_AlphaFlag = pSrcBitmap->m_AlphaFlag; 147 m_AlphaFlag = pSrcBitmap->m_AlphaFlag;
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 dest_color_pos += comps; 531 dest_color_pos += comps;
536 *dest_alpha_pos++ = (alpha * (*src_scan++) / 255); 532 *dest_alpha_pos++ = (alpha * (*src_scan++) / 255);
537 } 533 }
538 } 534 }
539 } 535 }
540 } 536 }
541 return TRUE; 537 return TRUE;
542 } 538 }
543 void CFX_DIBSource::CopyPalette(const FX_DWORD* pSrc, FX_DWORD size) { 539 void CFX_DIBSource::CopyPalette(const FX_DWORD* pSrc, FX_DWORD size) {
544 if (pSrc == NULL || GetBPP() > 8) { 540 if (pSrc == NULL || GetBPP() > 8) {
545 if (m_pPalette) { 541 FX_Free(m_pPalette);
546 FX_Free(m_pPalette);
547 }
548 m_pPalette = NULL; 542 m_pPalette = NULL;
549 } else { 543 } else {
550 FX_DWORD pal_size = 1 << GetBPP(); 544 FX_DWORD pal_size = 1 << GetBPP();
551 if (m_pPalette == NULL) { 545 if (m_pPalette == NULL) {
552 m_pPalette = FX_Alloc(FX_DWORD, pal_size); 546 m_pPalette = FX_Alloc(FX_DWORD, pal_size);
553 } 547 }
554 if (pal_size > size) { 548 if (pal_size > size) {
555 pal_size = size; 549 pal_size = size;
556 } 550 }
557 FXSYS_memcpy(m_pPalette, pSrc, pal_size * sizeof(FX_DWORD)); 551 FXSYS_memcpy(m_pPalette, pSrc, pal_size * sizeof(FX_DWORD));
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 delete m_pBitmap; 1506 delete m_pBitmap;
1513 } 1507 }
1514 CFX_FilteredDIB::CFX_FilteredDIB() { 1508 CFX_FilteredDIB::CFX_FilteredDIB() {
1515 m_pScanline = NULL; 1509 m_pScanline = NULL;
1516 m_pSrc = NULL; 1510 m_pSrc = NULL;
1517 } 1511 }
1518 CFX_FilteredDIB::~CFX_FilteredDIB() { 1512 CFX_FilteredDIB::~CFX_FilteredDIB() {
1519 if (m_bAutoDropSrc) { 1513 if (m_bAutoDropSrc) {
1520 delete m_pSrc; 1514 delete m_pSrc;
1521 } 1515 }
1522 if (m_pScanline) { 1516 FX_Free(m_pScanline);
1523 FX_Free(m_pScanline);
1524 }
1525 } 1517 }
1526 void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc) { 1518 void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc) {
1527 m_pSrc = pSrc; 1519 m_pSrc = pSrc;
1528 m_bAutoDropSrc = bAutoDropSrc; 1520 m_bAutoDropSrc = bAutoDropSrc;
1529 m_Width = pSrc->GetWidth(); 1521 m_Width = pSrc->GetWidth();
1530 m_Height = pSrc->GetHeight(); 1522 m_Height = pSrc->GetHeight();
1531 FXDIB_Format format = GetDestFormat(); 1523 FXDIB_Format format = GetDestFormat();
1532 m_bpp = (uint8_t)format; 1524 m_bpp = (uint8_t)format;
1533 m_AlphaFlag = (uint8_t)(format >> 8); 1525 m_AlphaFlag = (uint8_t)(format >> 8);
1534 m_Pitch = (m_Width * (format & 0xff) + 31) / 32 * 4; 1526 m_Pitch = (m_Width * (format & 0xff) + 31) / 32 * 4;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 if (!m_pBitmap->Create(width, height, src_format)) { 1718 if (!m_pBitmap->Create(width, height, src_format)) {
1727 delete m_pBitmap; 1719 delete m_pBitmap;
1728 m_pBitmap = NULL; 1720 m_pBitmap = NULL;
1729 return FALSE; 1721 return FALSE;
1730 } 1722 }
1731 if (pSrcPalette) { 1723 if (pSrcPalette) {
1732 m_pBitmap->CopyPalette(pSrcPalette); 1724 m_pBitmap->CopyPalette(pSrcPalette);
1733 } 1725 }
1734 return TRUE; 1726 return TRUE;
1735 } 1727 }
OLDNEW
« no previous file with comments | « core/src/fxge/dib/fx_dib_engine.cpp ('k') | core/src/fxge/ge/fx_ge_font.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698