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

Side by Side Diff: core/src/fxcodec/jbig2/JBig2_Image.cpp

Issue 1326953006: Remove CJBig2_Object, CJBig2_Module, and friends. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 5 years, 3 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/fxcodec/jbig2/JBig2_Image.h ('k') | core/src/fxcodec/jbig2/JBig2_Module.h » ('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 <limits.h> 7 #include <limits.h>
8 8
9 #include "../../../include/fxcrt/fx_coordinates.h" 9 #include "../../../include/fxcrt/fx_coordinates.h"
10 #include "../../../include/fxcrt/fx_safe_types.h" 10 #include "../../../include/fxcrt/fx_safe_types.h"
11 #include "JBig2_Image.h" 11 #include "JBig2_Image.h"
12 12
13 CJBig2_Image::CJBig2_Image(int32_t w, int32_t h) { 13 CJBig2_Image::CJBig2_Image(int32_t w, int32_t h) {
14 m_nWidth = w; 14 m_nWidth = w;
15 m_nHeight = h; 15 m_nHeight = h;
16 if (m_nWidth <= 0 || m_nHeight <= 0 || m_nWidth > INT_MAX - 31) { 16 if (m_nWidth <= 0 || m_nHeight <= 0 || m_nWidth > INT_MAX - 31) {
17 m_pData = NULL; 17 m_pData = NULL;
18 m_bNeedFree = FALSE; 18 m_bNeedFree = FALSE;
19 return; 19 return;
20 } 20 }
21 m_nStride = ((w + 31) >> 5) << 2; 21 m_nStride = ((w + 31) >> 5) << 2;
22 if (m_nStride * m_nHeight > 0 && 104857600 / (int)m_nStride > m_nHeight) { 22 if (m_nStride * m_nHeight > 0 && 104857600 / (int)m_nStride > m_nHeight) {
23 m_pData = (uint8_t*)m_pModule->JBig2_Malloc2(m_nStride, m_nHeight); 23 m_pData = FX_Alloc2D(uint8_t, m_nStride, m_nHeight);
24 } else { 24 } else {
25 m_pData = NULL; 25 m_pData = NULL;
26 } 26 }
27 m_bNeedFree = TRUE; 27 m_bNeedFree = TRUE;
28 } 28 }
29 CJBig2_Image::CJBig2_Image(int32_t w, 29 CJBig2_Image::CJBig2_Image(int32_t w,
30 int32_t h, 30 int32_t h,
31 int32_t stride, 31 int32_t stride,
32 uint8_t* pBuf) { 32 uint8_t* pBuf) {
33 m_nWidth = w; 33 m_nWidth = w;
34 m_nHeight = h; 34 m_nHeight = h;
35 m_nStride = stride; 35 m_nStride = stride;
36 m_pData = pBuf; 36 m_pData = pBuf;
37 m_bNeedFree = FALSE; 37 m_bNeedFree = FALSE;
38 } 38 }
39 CJBig2_Image::CJBig2_Image(CJBig2_Image& im) { 39 CJBig2_Image::CJBig2_Image(CJBig2_Image& im) {
40 m_pModule = im.m_pModule;
41 m_nWidth = im.m_nWidth; 40 m_nWidth = im.m_nWidth;
42 m_nHeight = im.m_nHeight; 41 m_nHeight = im.m_nHeight;
43 m_nStride = im.m_nStride; 42 m_nStride = im.m_nStride;
44 if (im.m_pData) { 43 if (im.m_pData) {
45 m_pData = (uint8_t*)m_pModule->JBig2_Malloc2(m_nStride, m_nHeight); 44 m_pData = FX_Alloc2D(uint8_t, m_nStride, m_nHeight);
46 JBIG2_memcpy(m_pData, im.m_pData, m_nStride * m_nHeight); 45 JBIG2_memcpy(m_pData, im.m_pData, m_nStride * m_nHeight);
47 } else { 46 } else {
48 m_pData = NULL; 47 m_pData = NULL;
49 } 48 }
50 m_bNeedFree = TRUE; 49 m_bNeedFree = TRUE;
51 } 50 }
52 CJBig2_Image::~CJBig2_Image() { 51 CJBig2_Image::~CJBig2_Image() {
53 if (m_bNeedFree && m_pData) { 52 if (m_bNeedFree) {
54 m_pModule->JBig2_Free(m_pData); 53 FX_Free(m_pData);
55 } 54 }
56 } 55 }
57 FX_BOOL CJBig2_Image::getPixel(int32_t x, int32_t y) { 56 FX_BOOL CJBig2_Image::getPixel(int32_t x, int32_t y) {
58 if (!m_pData) { 57 if (!m_pData) {
59 return 0; 58 return 0;
60 } 59 }
61 int32_t m, n; 60 int32_t m, n;
62 if (x < 0 || x >= m_nWidth) { 61 if (x < 0 || x >= m_nWidth) {
63 return 0; 62 return 0;
64 } 63 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 return FALSE; 147 return FALSE;
149 } 148 }
150 return pSrc->composeTo(this, x, y, op, pSrcRect); 149 return pSrc->composeTo(this, x, y, op, pSrcRect);
151 } 150 }
152 #define JBIG2_GETDWORD(buf) \ 151 #define JBIG2_GETDWORD(buf) \
153 ((FX_DWORD)(((buf)[0] << 24) | ((buf)[1] << 16) | ((buf)[2] << 8) | (buf)[3])) 152 ((FX_DWORD)(((buf)[0] << 24) | ((buf)[1] << 16) | ((buf)[2] << 8) | (buf)[3]))
154 CJBig2_Image* CJBig2_Image::subImage(int32_t x, 153 CJBig2_Image* CJBig2_Image::subImage(int32_t x,
155 int32_t y, 154 int32_t y,
156 int32_t w, 155 int32_t w,
157 int32_t h) { 156 int32_t h) {
158 CJBig2_Image* pImage;
159 int32_t m, n, j; 157 int32_t m, n, j;
160 uint8_t *pLineSrc, *pLineDst; 158 uint8_t *pLineSrc, *pLineDst;
161 FX_DWORD wTmp; 159 FX_DWORD wTmp;
162 uint8_t *pSrc, *pSrcEnd, *pDst, *pDstEnd; 160 uint8_t *pSrc, *pSrcEnd, *pDst, *pDstEnd;
163 if (w == 0 || h == 0) { 161 if (w == 0 || h == 0) {
164 return NULL; 162 return NULL;
165 } 163 }
166 JBIG2_ALLOC(pImage, CJBig2_Image(w, h)); 164 CJBig2_Image* pImage = new CJBig2_Image(w, h);
167 if (!m_pData) { 165 if (!m_pData) {
168 pImage->fill(0); 166 pImage->fill(0);
169 return pImage; 167 return pImage;
170 } 168 }
171 if (!pImage->m_pData) { 169 if (!pImage->m_pData) {
172 return pImage; 170 return pImage;
173 } 171 }
174 pLineSrc = m_pData + m_nStride * y; 172 pLineSrc = m_pData + m_nStride * y;
175 pLineDst = pImage->m_pData; 173 pLineDst = pImage->m_pData;
176 m = (x >> 5) << 2; 174 m = (x >> 5) << 2;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 215 }
218 FX_DWORD dwH = pdfium::base::checked_cast<FX_DWORD>(h); 216 FX_DWORD dwH = pdfium::base::checked_cast<FX_DWORD>(h);
219 FX_DWORD dwStride = pdfium::base::checked_cast<FX_DWORD>(m_nStride); 217 FX_DWORD dwStride = pdfium::base::checked_cast<FX_DWORD>(m_nStride);
220 FX_DWORD dwHeight = pdfium::base::checked_cast<FX_DWORD>(m_nHeight); 218 FX_DWORD dwHeight = pdfium::base::checked_cast<FX_DWORD>(m_nHeight);
221 FX_SAFE_DWORD safeMemSize = dwH; 219 FX_SAFE_DWORD safeMemSize = dwH;
222 safeMemSize *= dwStride; 220 safeMemSize *= dwStride;
223 if (!safeMemSize.IsValid()) { 221 if (!safeMemSize.IsValid()) {
224 return; 222 return;
225 } 223 }
226 // The guaranteed reallocated memory is to be < 4GB (unsigned int). 224 // The guaranteed reallocated memory is to be < 4GB (unsigned int).
227 m_pData = 225 m_pData = FX_Realloc(uint8_t, m_pData, safeMemSize.ValueOrDie());
228 (uint8_t*)m_pModule->JBig2_Realloc(m_pData, safeMemSize.ValueOrDie()); 226
229 // The result of dwHeight * dwStride doesn't overflow after the 227 // The result of dwHeight * dwStride doesn't overflow after the
230 // checking of safeMemSize. 228 // checking of safeMemSize.
231 // The same as the result of (dwH - dwHeight) * dwStride) because 229 // The same as the result of (dwH - dwHeight) * dwStride) because
232 // dwH - dwHeight is always less than dwH(h) which is checked in 230 // dwH - dwHeight is always less than dwH(h) which is checked in
233 // the calculation of dwH * dwStride. 231 // the calculation of dwH * dwStride.
234 JBIG2_memset(m_pData + dwHeight * dwStride, v ? 0xff : 0, 232 JBIG2_memset(m_pData + dwHeight * dwStride, v ? 0xff : 0,
235 (dwH - dwHeight) * dwStride); 233 (dwH - dwHeight) * dwStride);
236 m_nHeight = h; 234 m_nHeight = h;
237 } 235 }
238 FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, 236 FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst,
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 dp[2] = (uint8_t)(tmp >> 8); 1090 dp[2] = (uint8_t)(tmp >> 8);
1093 dp[3] = (uint8_t)tmp; 1091 dp[3] = (uint8_t)tmp;
1094 } 1092 }
1095 lineSrc += m_nStride; 1093 lineSrc += m_nStride;
1096 lineDst += pDst->m_nStride; 1094 lineDst += pDst->m_nStride;
1097 } 1095 }
1098 } 1096 }
1099 } 1097 }
1100 return 1; 1098 return 1;
1101 } 1099 }
OLDNEW
« no previous file with comments | « core/src/fxcodec/jbig2/JBig2_Image.h ('k') | core/src/fxcodec/jbig2/JBig2_Module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698