Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "core/fxcodec/jbig2/JBig2_Image.h" | 9 #include "core/fxcodec/jbig2/JBig2_Image.h" |
| 10 #include "core/fxcrt/include/fx_coordinates.h" | 10 #include "core/fxcrt/include/fx_coordinates.h" |
| 11 #include "core/fxcrt/include/fx_safe_types.h" | 11 #include "core/fxcrt/include/fx_safe_types.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 = nullptr; |
| 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 = FX_Alloc2D(uint8_t, 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 = nullptr; |
| 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(const CJBig2_Image& im) { | 39 CJBig2_Image::CJBig2_Image(const CJBig2_Image& im) { |
| 40 m_nWidth = im.m_nWidth; | 40 m_nWidth = im.m_nWidth; |
| 41 m_nHeight = im.m_nHeight; | 41 m_nHeight = im.m_nHeight; |
| 42 m_nStride = im.m_nStride; | 42 m_nStride = im.m_nStride; |
| 43 if (im.m_pData) { | 43 if (im.m_pData) { |
| 44 m_pData = FX_Alloc2D(uint8_t, m_nStride, m_nHeight); | 44 m_pData = FX_Alloc2D(uint8_t, m_nStride, m_nHeight); |
| 45 JBIG2_memcpy(m_pData, im.m_pData, m_nStride * m_nHeight); | 45 JBIG2_memcpy(m_pData, im.m_pData, m_nStride * m_nHeight); |
| 46 } else { | 46 } else { |
| 47 m_pData = NULL; | 47 m_pData = nullptr; |
| 48 } | 48 } |
| 49 m_bNeedFree = TRUE; | 49 m_bNeedFree = TRUE; |
| 50 } | 50 } |
| 51 CJBig2_Image::~CJBig2_Image() { | 51 CJBig2_Image::~CJBig2_Image() { |
| 52 if (m_bNeedFree) { | 52 if (m_bNeedFree) { |
| 53 FX_Free(m_pData); | 53 FX_Free(m_pData); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 FX_BOOL CJBig2_Image::getPixel(int32_t x, int32_t y) { | 56 FX_BOOL CJBig2_Image::getPixel(int32_t x, int32_t y) { |
| 57 if (!m_pData) { | 57 if (!m_pData) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 return composeTo_opt2(pDst, x, y, op); | 116 return composeTo_opt2(pDst, x, y, op); |
| 117 } | 117 } |
| 118 FX_BOOL CJBig2_Image::composeTo(CJBig2_Image* pDst, | 118 FX_BOOL CJBig2_Image::composeTo(CJBig2_Image* pDst, |
| 119 int32_t x, | 119 int32_t x, |
| 120 int32_t y, | 120 int32_t y, |
| 121 JBig2ComposeOp op, | 121 JBig2ComposeOp op, |
| 122 const FX_RECT* pSrcRect) { | 122 const FX_RECT* pSrcRect) { |
| 123 if (!m_pData) { | 123 if (!m_pData) { |
| 124 return FALSE; | 124 return FALSE; |
| 125 } | 125 } |
| 126 if (NULL == pSrcRect || *pSrcRect == FX_RECT(0, 0, m_nWidth, m_nHeight)) { | 126 if (nullptr == pSrcRect || *pSrcRect == FX_RECT(0, 0, m_nWidth, m_nHeight)) { |
|
Tom Sepez
2016/06/02 20:09:49
nit: !pSrcRect
Lei Zhang
2016/06/07 07:33:23
Done.
| |
| 127 return composeTo_opt2(pDst, x, y, op); | 127 return composeTo_opt2(pDst, x, y, op); |
| 128 } | 128 } |
| 129 return composeTo_opt2(pDst, x, y, op, pSrcRect); | 129 return composeTo_opt2(pDst, x, y, op, pSrcRect); |
| 130 } | 130 } |
| 131 | 131 |
| 132 FX_BOOL CJBig2_Image::composeFrom(int32_t x, | 132 FX_BOOL CJBig2_Image::composeFrom(int32_t x, |
| 133 int32_t y, | 133 int32_t y, |
| 134 CJBig2_Image* pSrc, | 134 CJBig2_Image* pSrc, |
| 135 JBig2ComposeOp op) { | 135 JBig2ComposeOp op) { |
| 136 if (!m_pData) { | 136 if (!m_pData) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 152 ((uint32_t)(((buf)[0] << 24) | ((buf)[1] << 16) | ((buf)[2] << 8) | (buf)[3])) | 152 ((uint32_t)(((buf)[0] << 24) | ((buf)[1] << 16) | ((buf)[2] << 8) | (buf)[3])) |
| 153 CJBig2_Image* CJBig2_Image::subImage(int32_t x, | 153 CJBig2_Image* CJBig2_Image::subImage(int32_t x, |
| 154 int32_t y, | 154 int32_t y, |
| 155 int32_t w, | 155 int32_t w, |
| 156 int32_t h) { | 156 int32_t h) { |
| 157 int32_t m, n, j; | 157 int32_t m, n, j; |
| 158 uint8_t *pLineSrc, *pLineDst; | 158 uint8_t *pLineSrc, *pLineDst; |
| 159 uint32_t wTmp; | 159 uint32_t wTmp; |
| 160 uint8_t *pSrc, *pSrcEnd, *pDst, *pDstEnd; | 160 uint8_t *pSrc, *pSrcEnd, *pDst, *pDstEnd; |
| 161 if (w == 0 || h == 0) { | 161 if (w == 0 || h == 0) { |
| 162 return NULL; | 162 return nullptr; |
| 163 } | 163 } |
| 164 CJBig2_Image* pImage = new CJBig2_Image(w, h); | 164 CJBig2_Image* pImage = new CJBig2_Image(w, h); |
| 165 if (!m_pData) { | 165 if (!m_pData) { |
| 166 pImage->fill(0); | 166 pImage->fill(0); |
| 167 return pImage; | 167 return pImage; |
| 168 } | 168 } |
| 169 if (!pImage->m_pData) { | 169 if (!pImage->m_pData) { |
| 170 return pImage; | 170 return pImage; |
| 171 } | 171 } |
| 172 pLineSrc = m_pData + m_nStride * y; | 172 pLineSrc = m_pData + m_nStride * y; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, | 236 FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, |
| 237 int32_t x, | 237 int32_t x, |
| 238 int32_t y, | 238 int32_t y, |
| 239 JBig2ComposeOp op) { | 239 JBig2ComposeOp op) { |
| 240 int32_t xs0 = 0, ys0 = 0, xs1 = 0, ys1 = 0, xd0 = 0, yd0 = 0, xd1 = 0, | 240 int32_t xs0 = 0, ys0 = 0, xs1 = 0, ys1 = 0, xd0 = 0, yd0 = 0, xd1 = 0, |
| 241 yd1 = 0, xx = 0, yy = 0, w = 0, h = 0, middleDwords = 0, lineLeft = 0; | 241 yd1 = 0, xx = 0, yy = 0, w = 0, h = 0, middleDwords = 0, lineLeft = 0; |
| 242 | 242 |
| 243 uint32_t s1 = 0, d1 = 0, d2 = 0, shift = 0, shift1 = 0, shift2 = 0, tmp = 0, | 243 uint32_t s1 = 0, d1 = 0, d2 = 0, shift = 0, shift1 = 0, shift2 = 0, tmp = 0, |
| 244 tmp1 = 0, tmp2 = 0, maskL = 0, maskR = 0, maskM = 0; | 244 tmp1 = 0, tmp2 = 0, maskL = 0, maskR = 0, maskM = 0; |
| 245 | 245 |
| 246 uint8_t *lineSrc = NULL, *lineDst = NULL, *sp = NULL, *dp = NULL; | 246 uint8_t *lineSrc = nullptr, *lineDst = nullptr, *sp = nullptr, *dp = nullptr; |
|
Tom Sepez
2016/06/02 20:09:49
one per line
Lei Zhang
2016/06/07 07:33:23
Done.
| |
| 247 | 247 |
| 248 if (!m_pData) { | 248 if (!m_pData) { |
| 249 return FALSE; | 249 return FALSE; |
| 250 } | 250 } |
| 251 if (x < -1048576 || x > 1048576 || y < -1048576 || y > 1048576) { | 251 if (x < -1048576 || x > 1048576 || y < -1048576 || y > 1048576) { |
| 252 return FALSE; | 252 return FALSE; |
| 253 } | 253 } |
| 254 if (y < 0) { | 254 if (y < 0) { |
| 255 ys0 = -y; | 255 ys0 = -y; |
| 256 } | 256 } |
| (...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1073 dp[2] = (uint8_t)(tmp >> 8); | 1073 dp[2] = (uint8_t)(tmp >> 8); |
| 1074 dp[3] = (uint8_t)tmp; | 1074 dp[3] = (uint8_t)tmp; |
| 1075 } | 1075 } |
| 1076 lineSrc += m_nStride; | 1076 lineSrc += m_nStride; |
| 1077 lineDst += pDst->m_nStride; | 1077 lineDst += pDst->m_nStride; |
| 1078 } | 1078 } |
| 1079 } | 1079 } |
| 1080 } | 1080 } |
| 1081 return 1; | 1081 return 1; |
| 1082 } | 1082 } |
| OLD | NEW |