| 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/fx_coordinates.h" | 10 #include "core/fxcrt/fx_coordinates.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 if (!m_pData) { | 112 if (!m_pData) { |
| 113 return; | 113 return; |
| 114 } | 114 } |
| 115 if (hFrom < 0 || hFrom >= m_nHeight) { | 115 if (hFrom < 0 || hFrom >= m_nHeight) { |
| 116 JBIG2_memset(m_pData + hTo * m_nStride, 0, m_nStride); | 116 JBIG2_memset(m_pData + hTo * m_nStride, 0, m_nStride); |
| 117 } else { | 117 } else { |
| 118 JBIG2_memcpy(m_pData + hTo * m_nStride, m_pData + hFrom * m_nStride, | 118 JBIG2_memcpy(m_pData + hTo * m_nStride, m_pData + hFrom * m_nStride, |
| 119 m_nStride); | 119 m_nStride); |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 void CJBig2_Image::fill(FX_BOOL v) { | 122 void CJBig2_Image::fill(bool v) { |
| 123 if (!m_pData) { | 123 if (!m_pData) { |
| 124 return; | 124 return; |
| 125 } | 125 } |
| 126 JBIG2_memset(m_pData, v ? 0xff : 0, m_nStride * m_nHeight); | 126 JBIG2_memset(m_pData, v ? 0xff : 0, m_nStride * m_nHeight); |
| 127 } | 127 } |
| 128 FX_BOOL CJBig2_Image::composeTo(CJBig2_Image* pDst, | 128 bool CJBig2_Image::composeTo(CJBig2_Image* pDst, |
| 129 int32_t x, | 129 int32_t x, |
| 130 int32_t y, | 130 int32_t y, |
| 131 JBig2ComposeOp op) { | 131 JBig2ComposeOp op) { |
| 132 if (!m_pData) { | 132 if (!m_pData) { |
| 133 return FALSE; | 133 return false; |
| 134 } | 134 } |
| 135 return composeTo_opt2(pDst, x, y, op); | 135 return composeTo_opt2(pDst, x, y, op); |
| 136 } | 136 } |
| 137 FX_BOOL CJBig2_Image::composeTo(CJBig2_Image* pDst, | 137 bool CJBig2_Image::composeTo(CJBig2_Image* pDst, |
| 138 int32_t x, | 138 int32_t x, |
| 139 int32_t y, | 139 int32_t y, |
| 140 JBig2ComposeOp op, | 140 JBig2ComposeOp op, |
| 141 const FX_RECT* pSrcRect) { | 141 const FX_RECT* pSrcRect) { |
| 142 if (!m_pData) | 142 if (!m_pData) |
| 143 return FALSE; | 143 return false; |
| 144 | 144 |
| 145 if (!pSrcRect || *pSrcRect == FX_RECT(0, 0, m_nWidth, m_nHeight)) | 145 if (!pSrcRect || *pSrcRect == FX_RECT(0, 0, m_nWidth, m_nHeight)) |
| 146 return composeTo_opt2(pDst, x, y, op); | 146 return composeTo_opt2(pDst, x, y, op); |
| 147 | 147 |
| 148 return composeTo_opt2(pDst, x, y, op, pSrcRect); | 148 return composeTo_opt2(pDst, x, y, op, pSrcRect); |
| 149 } | 149 } |
| 150 | 150 |
| 151 FX_BOOL CJBig2_Image::composeFrom(int32_t x, | 151 bool CJBig2_Image::composeFrom(int32_t x, |
| 152 int32_t y, | 152 int32_t y, |
| 153 CJBig2_Image* pSrc, | 153 CJBig2_Image* pSrc, |
| 154 JBig2ComposeOp op) { | 154 JBig2ComposeOp op) { |
| 155 if (!m_pData) { | 155 if (!m_pData) { |
| 156 return FALSE; | 156 return false; |
| 157 } | 157 } |
| 158 return pSrc->composeTo(this, x, y, op); | 158 return pSrc->composeTo(this, x, y, op); |
| 159 } | 159 } |
| 160 FX_BOOL CJBig2_Image::composeFrom(int32_t x, | 160 bool CJBig2_Image::composeFrom(int32_t x, |
| 161 int32_t y, | 161 int32_t y, |
| 162 CJBig2_Image* pSrc, | 162 CJBig2_Image* pSrc, |
| 163 JBig2ComposeOp op, | 163 JBig2ComposeOp op, |
| 164 const FX_RECT* pSrcRect) { | 164 const FX_RECT* pSrcRect) { |
| 165 if (!m_pData) { | 165 if (!m_pData) { |
| 166 return FALSE; | 166 return false; |
| 167 } | 167 } |
| 168 return pSrc->composeTo(this, x, y, op, pSrcRect); | 168 return pSrc->composeTo(this, x, y, op, pSrcRect); |
| 169 } | 169 } |
| 170 #define JBIG2_GETDWORD(buf) \ | 170 #define JBIG2_GETDWORD(buf) \ |
| 171 ((uint32_t)(((buf)[0] << 24) | ((buf)[1] << 16) | ((buf)[2] << 8) | (buf)[3])) | 171 ((uint32_t)(((buf)[0] << 24) | ((buf)[1] << 16) | ((buf)[2] << 8) | (buf)[3])) |
| 172 CJBig2_Image* CJBig2_Image::subImage(int32_t x, | 172 CJBig2_Image* CJBig2_Image::subImage(int32_t x, |
| 173 int32_t y, | 173 int32_t y, |
| 174 int32_t w, | 174 int32_t w, |
| 175 int32_t h) { | 175 int32_t h) { |
| 176 int32_t m, n, j; | 176 int32_t m, n, j; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 pDst[2] = (uint8_t)(wTmp >> 8); | 222 pDst[2] = (uint8_t)(wTmp >> 8); |
| 223 pDst[3] = (uint8_t)wTmp; | 223 pDst[3] = (uint8_t)wTmp; |
| 224 } | 224 } |
| 225 pLineSrc += m_nStride; | 225 pLineSrc += m_nStride; |
| 226 pLineDst += pImage->m_nStride; | 226 pLineDst += pImage->m_nStride; |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 return pImage; | 229 return pImage; |
| 230 } | 230 } |
| 231 | 231 |
| 232 void CJBig2_Image::expand(int32_t h, FX_BOOL v) { | 232 void CJBig2_Image::expand(int32_t h, bool v) { |
| 233 if (!m_pData || h <= m_nHeight || h > kMaxImageBytes / m_nStride) | 233 if (!m_pData || h <= m_nHeight || h > kMaxImageBytes / m_nStride) |
| 234 return; | 234 return; |
| 235 | 235 |
| 236 if (m_bOwnsBuffer) { | 236 if (m_bOwnsBuffer) { |
| 237 m_pData = FX_Realloc(uint8_t, m_pData, h * m_nStride); | 237 m_pData = FX_Realloc(uint8_t, m_pData, h * m_nStride); |
| 238 } else { | 238 } else { |
| 239 uint8_t* pExternalBuffer = m_pData; | 239 uint8_t* pExternalBuffer = m_pData; |
| 240 m_pData = FX_Alloc(uint8_t, h * m_nStride); | 240 m_pData = FX_Alloc(uint8_t, h * m_nStride); |
| 241 JBIG2_memcpy(m_pData, pExternalBuffer, m_nHeight * m_nStride); | 241 JBIG2_memcpy(m_pData, pExternalBuffer, m_nHeight * m_nStride); |
| 242 m_bOwnsBuffer = true; | 242 m_bOwnsBuffer = true; |
| 243 } | 243 } |
| 244 JBIG2_memset(m_pData + m_nHeight * m_nStride, v ? 0xff : 0, | 244 JBIG2_memset(m_pData + m_nHeight * m_nStride, v ? 0xff : 0, |
| 245 (h - m_nHeight) * m_nStride); | 245 (h - m_nHeight) * m_nStride); |
| 246 m_nHeight = h; | 246 m_nHeight = h; |
| 247 } | 247 } |
| 248 | 248 |
| 249 FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, | 249 bool CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, |
| 250 int32_t x, | 250 int32_t x, |
| 251 int32_t y, | 251 int32_t y, |
| 252 JBig2ComposeOp op) { | 252 JBig2ComposeOp op) { |
| 253 int32_t xs0 = 0, ys0 = 0, xs1 = 0, ys1 = 0, xd0 = 0, yd0 = 0, xd1 = 0, | 253 int32_t xs0 = 0, ys0 = 0, xs1 = 0, ys1 = 0, xd0 = 0, yd0 = 0, xd1 = 0, |
| 254 yd1 = 0, xx = 0, yy = 0, w = 0, h = 0, middleDwords = 0, lineLeft = 0; | 254 yd1 = 0, xx = 0, yy = 0, w = 0, h = 0, middleDwords = 0, lineLeft = 0; |
| 255 | 255 |
| 256 uint32_t s1 = 0, d1 = 0, d2 = 0, shift = 0, shift1 = 0, shift2 = 0, tmp = 0, | 256 uint32_t s1 = 0, d1 = 0, d2 = 0, shift = 0, shift1 = 0, shift2 = 0, tmp = 0, |
| 257 tmp1 = 0, tmp2 = 0, maskL = 0, maskR = 0, maskM = 0; | 257 tmp1 = 0, tmp2 = 0, maskL = 0, maskR = 0, maskM = 0; |
| 258 | 258 |
| 259 if (!m_pData) | 259 if (!m_pData) |
| 260 return FALSE; | 260 return false; |
| 261 | 261 |
| 262 if (x < -1048576 || x > 1048576 || y < -1048576 || y > 1048576) | 262 if (x < -1048576 || x > 1048576 || y < -1048576 || y > 1048576) |
| 263 return FALSE; | 263 return false; |
| 264 | 264 |
| 265 if (y < 0) { | 265 if (y < 0) { |
| 266 ys0 = -y; | 266 ys0 = -y; |
| 267 } | 267 } |
| 268 if (y + m_nHeight > pDst->m_nHeight) { | 268 if (y + m_nHeight > pDst->m_nHeight) { |
| 269 ys1 = pDst->m_nHeight - y; | 269 ys1 = pDst->m_nHeight - y; |
| 270 } else { | 270 } else { |
| 271 ys1 = m_nHeight; | 271 ys1 = m_nHeight; |
| 272 } | 272 } |
| 273 if (x < 0) { | 273 if (x < 0) { |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 dp[2] = (uint8_t)(tmp >> 8); | 667 dp[2] = (uint8_t)(tmp >> 8); |
| 668 dp[3] = (uint8_t)tmp; | 668 dp[3] = (uint8_t)tmp; |
| 669 } | 669 } |
| 670 lineSrc += m_nStride; | 670 lineSrc += m_nStride; |
| 671 lineDst += pDst->m_nStride; | 671 lineDst += pDst->m_nStride; |
| 672 } | 672 } |
| 673 } | 673 } |
| 674 } | 674 } |
| 675 return 1; | 675 return 1; |
| 676 } | 676 } |
| 677 FX_BOOL CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, | 677 bool CJBig2_Image::composeTo_opt2(CJBig2_Image* pDst, |
| 678 int32_t x, | 678 int32_t x, |
| 679 int32_t y, | 679 int32_t y, |
| 680 JBig2ComposeOp op, | 680 JBig2ComposeOp op, |
| 681 const FX_RECT* pSrcRect) { | 681 const FX_RECT* pSrcRect) { |
| 682 if (!m_pData) { | 682 if (!m_pData) { |
| 683 return FALSE; | 683 return false; |
| 684 } | 684 } |
| 685 // TODO(weili): Check whether the range check is correct. Should x>=1048576? | 685 // TODO(weili): Check whether the range check is correct. Should x>=1048576? |
| 686 if (x < -1048576 || x > 1048576 || y < -1048576 || y > 1048576) { | 686 if (x < -1048576 || x > 1048576 || y < -1048576 || y > 1048576) { |
| 687 return FALSE; | 687 return false; |
| 688 } | 688 } |
| 689 int32_t sw = pSrcRect->Width(); | 689 int32_t sw = pSrcRect->Width(); |
| 690 int32_t sh = pSrcRect->Height(); | 690 int32_t sh = pSrcRect->Height(); |
| 691 int32_t ys0 = y < 0 ? -y : 0; | 691 int32_t ys0 = y < 0 ? -y : 0; |
| 692 int32_t ys1 = y + sh > pDst->m_nHeight ? pDst->m_nHeight - y : sh; | 692 int32_t ys1 = y + sh > pDst->m_nHeight ? pDst->m_nHeight - y : sh; |
| 693 int32_t xs0 = x < 0 ? -x : 0; | 693 int32_t xs0 = x < 0 ? -x : 0; |
| 694 int32_t xs1 = x + sw > pDst->m_nWidth ? pDst->m_nWidth - x : sw; | 694 int32_t xs1 = x + sw > pDst->m_nWidth ? pDst->m_nWidth - x : sw; |
| 695 if ((ys0 >= ys1) || (xs0 >= xs1)) { | 695 if ((ys0 >= ys1) || (xs0 >= xs1)) { |
| 696 return 0; | 696 return 0; |
| 697 } | 697 } |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 dp[2] = (uint8_t)(tmp >> 8); | 1087 dp[2] = (uint8_t)(tmp >> 8); |
| 1088 dp[3] = (uint8_t)tmp; | 1088 dp[3] = (uint8_t)tmp; |
| 1089 } | 1089 } |
| 1090 lineSrc += m_nStride; | 1090 lineSrc += m_nStride; |
| 1091 lineDst += pDst->m_nStride; | 1091 lineDst += pDst->m_nStride; |
| 1092 } | 1092 } |
| 1093 } | 1093 } |
| 1094 } | 1094 } |
| 1095 return 1; | 1095 return 1; |
| 1096 } | 1096 } |
| OLD | NEW |