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 "../../../include/fxge/fx_ge.h" | 7 #include "../../../include/fxge/fx_ge.h" |
| 8 #include "../../../include/fxcodec/fx_codec.h" | 8 #include "../../../include/fxcodec/fx_codec.h" |
| 9 #include "../../../include/fpdfapi/fpdf_module.h" | 9 #include "../../../include/fpdfapi/fpdf_module.h" |
| 10 #include "../../../include/fpdfapi/fpdf_render.h" | 10 #include "../../../include/fpdfapi/fpdf_render.h" |
| (...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1040 } | 1040 } |
| 1041 FX_LPBYTE CPDF_DIBSource::GetBuffer() const | 1041 FX_LPBYTE CPDF_DIBSource::GetBuffer() const |
| 1042 { | 1042 { |
| 1043 if (m_pCachedBitmap) { | 1043 if (m_pCachedBitmap) { |
| 1044 return m_pCachedBitmap->GetBuffer(); | 1044 return m_pCachedBitmap->GetBuffer(); |
| 1045 } | 1045 } |
| 1046 return NULL; | 1046 return NULL; |
| 1047 } | 1047 } |
| 1048 FX_LPCBYTE CPDF_DIBSource::GetScanline(int line) const | 1048 FX_LPCBYTE CPDF_DIBSource::GetScanline(int line) const |
| 1049 { | 1049 { |
| 1050 FX_DWORD src_pitch = (m_Width * m_bpc * m_nComponents + 7) / 8; | 1050 FX_DWORD bpc = GetValidBpc(); |
|
Tom Sepez
2014/08/25 17:30:21
Do we need to check for bcp == 0 error case?
Bo Xu
2014/08/25 18:27:51
Done.
| |
| 1051 FX_SAFE_DWORD src_pitch = m_Width; | |
| 1052 src_pitch *= bpc; | |
| 1053 src_pitch *= m_nComponents; | |
| 1054 src_pitch += 7; | |
| 1055 src_pitch /= 8; | |
| 1056 if (!src_pitch.IsValid()) | |
| 1057 return NULL; | |
| 1051 FX_LPCBYTE pSrcLine = NULL; | 1058 FX_LPCBYTE pSrcLine = NULL; |
| 1059 | |
|
Tom Sepez
2014/08/25 17:30:21
nit: stray blank line here. This codebase seems h
Bo Xu
2014/08/25 18:27:51
Agree, no blank line seems better.
Bo Xu
2014/08/25 18:27:51
Done.
| |
| 1052 if (m_pCachedBitmap) { | 1060 if (m_pCachedBitmap) { |
| 1053 if (line >= m_pCachedBitmap->GetHeight()) { | 1061 if (line >= m_pCachedBitmap->GetHeight()) { |
| 1054 line = m_pCachedBitmap->GetHeight() - 1; | 1062 line = m_pCachedBitmap->GetHeight() - 1; |
| 1055 } | 1063 } |
| 1056 pSrcLine = m_pCachedBitmap->GetScanline(line); | 1064 pSrcLine = m_pCachedBitmap->GetScanline(line); |
| 1057 } else if (m_pDecoder) { | 1065 } else if (m_pDecoder) { |
| 1058 pSrcLine = m_pDecoder->GetScanline(line); | 1066 pSrcLine = m_pDecoder->GetScanline(line); |
| 1059 } else { | 1067 } else { |
| 1060 if (m_pStreamAcc->GetSize() >= (line + 1) * src_pitch) { | 1068 if (m_pStreamAcc->GetSize() >= (line + 1) * src_pitch.ValueOrDie()) { |
|
Tom Sepez
2014/08/25 17:30:21
nit: it may be better to move src_pitch.ValueOrDie
Bo Xu
2014/08/25 18:27:51
Done.
| |
| 1061 pSrcLine = m_pStreamAcc->GetData() + line * src_pitch; | 1069 pSrcLine = m_pStreamAcc->GetData() + line * src_pitch.ValueOrDie(); |
| 1062 } | 1070 } |
| 1063 } | 1071 } |
| 1064 if (pSrcLine == NULL) { | 1072 if (pSrcLine == NULL) { |
| 1065 FX_LPBYTE pLineBuf = m_pMaskedLine ? m_pMaskedLine : m_pLineBuf; | 1073 FX_LPBYTE pLineBuf = m_pMaskedLine ? m_pMaskedLine : m_pLineBuf; |
| 1066 FXSYS_memset8(pLineBuf, 0xff, m_Pitch); | 1074 FXSYS_memset8(pLineBuf, 0xff, m_Pitch); |
| 1067 return pLineBuf; | 1075 return pLineBuf; |
| 1068 } | 1076 } |
| 1069 if (m_bpc * m_nComponents == 1) { | 1077 if (bpc * m_nComponents == 1) { |
| 1070 if (m_bImageMask && m_bDefaultDecode) { | 1078 if (m_bImageMask && m_bDefaultDecode) { |
| 1071 for (FX_DWORD i = 0; i < src_pitch; i ++) { | 1079 for (FX_DWORD i = 0; i < src_pitch.ValueOrDie(); i++) { |
| 1072 m_pLineBuf[i] = ~pSrcLine[i]; | 1080 m_pLineBuf[i] = ~pSrcLine[i]; |
| 1073 } | 1081 } |
| 1074 } else if (m_bColorKey) { | 1082 } else if (m_bColorKey) { |
| 1075 FX_DWORD reset_argb, set_argb; | 1083 FX_DWORD reset_argb, set_argb; |
| 1076 reset_argb = m_pPalette ? m_pPalette[0] : 0xff000000; | 1084 reset_argb = m_pPalette ? m_pPalette[0] : 0xff000000; |
| 1077 set_argb = m_pPalette ? m_pPalette[1] : 0xffffffff; | 1085 set_argb = m_pPalette ? m_pPalette[1] : 0xffffffff; |
| 1078 if (m_pCompData[0].m_ColorKeyMin == 0) { | 1086 if (m_pCompData[0].m_ColorKeyMin == 0) { |
| 1079 reset_argb = 0; | 1087 reset_argb = 0; |
| 1080 } | 1088 } |
| 1081 if (m_pCompData[0].m_ColorKeyMax == 1) { | 1089 if (m_pCompData[0].m_ColorKeyMax == 1) { |
| 1082 set_argb = 0; | 1090 set_argb = 0; |
| 1083 } | 1091 } |
| 1084 set_argb = FXARGB_TODIB(set_argb); | 1092 set_argb = FXARGB_TODIB(set_argb); |
| 1085 reset_argb = FXARGB_TODIB(reset_argb); | 1093 reset_argb = FXARGB_TODIB(reset_argb); |
| 1086 FX_DWORD* dest_scan = (FX_DWORD*)m_pMaskedLine; | 1094 FX_DWORD* dest_scan = (FX_DWORD*)m_pMaskedLine; |
| 1087 for (int col = 0; col < m_Width; col ++) { | 1095 for (int col = 0; col < m_Width; col ++) { |
| 1088 if (pSrcLine[col / 8] & (1 << (7 - col % 8))) { | 1096 if (pSrcLine[col / 8] & (1 << (7 - col % 8))) { |
| 1089 *dest_scan = set_argb; | 1097 *dest_scan = set_argb; |
| 1090 } else { | 1098 } else { |
| 1091 *dest_scan = reset_argb; | 1099 *dest_scan = reset_argb; |
| 1092 } | 1100 } |
| 1093 dest_scan ++; | 1101 dest_scan ++; |
| 1094 } | 1102 } |
| 1095 return m_pMaskedLine; | 1103 return m_pMaskedLine; |
| 1096 } else { | 1104 } else { |
| 1097 FXSYS_memcpy32(m_pLineBuf, pSrcLine, src_pitch); | 1105 FXSYS_memcpy32(m_pLineBuf, pSrcLine, src_pitch.ValueOrDie()); |
| 1098 } | 1106 } |
| 1099 return m_pLineBuf; | 1107 return m_pLineBuf; |
| 1100 } | 1108 } |
| 1101 if (m_bpc * m_nComponents <= 8) { | 1109 if (bpc * m_nComponents <= 8) { |
| 1102 if (m_bpc == 8) { | 1110 if (bpc == 8) { |
| 1103 FXSYS_memcpy32(m_pLineBuf, pSrcLine, src_pitch); | 1111 FXSYS_memcpy32(m_pLineBuf, pSrcLine, src_pitch.ValueOrDie()); |
| 1104 } else { | 1112 } else { |
| 1105 int src_bit_pos = 0; | 1113 int src_bit_pos = 0; |
| 1106 for (int col = 0; col < m_Width; col ++) { | 1114 for (int col = 0; col < m_Width; col ++) { |
| 1107 int color_index = 0; | 1115 int color_index = 0; |
| 1108 for (FX_DWORD color = 0; color < m_nComponents; color ++) { | 1116 for (FX_DWORD color = 0; color < m_nComponents; color ++) { |
| 1109 int data = _GetBits8(pSrcLine, src_bit_pos, m_bpc); | 1117 int data = _GetBits8(pSrcLine, src_bit_pos, bpc); |
| 1110 color_index |= data << (color * m_bpc); | 1118 color_index |= data << (color * bpc); |
| 1111 src_bit_pos += m_bpc; | 1119 src_bit_pos += bpc; |
| 1112 } | 1120 } |
| 1113 m_pLineBuf[col] = color_index; | 1121 m_pLineBuf[col] = color_index; |
| 1114 } | 1122 } |
| 1115 } | 1123 } |
| 1116 if (m_bColorKey) { | 1124 if (m_bColorKey) { |
| 1117 FX_LPBYTE pDestPixel = m_pMaskedLine; | 1125 FX_LPBYTE pDestPixel = m_pMaskedLine; |
| 1118 FX_LPCBYTE pSrcPixel = m_pLineBuf; | 1126 FX_LPCBYTE pSrcPixel = m_pLineBuf; |
| 1119 for (int col = 0; col < m_Width; col ++) { | 1127 for (int col = 0; col < m_Width; col ++) { |
| 1120 FX_BYTE index = *pSrcPixel++; | 1128 FX_BYTE index = *pSrcPixel++; |
| 1121 if (m_pPalette) { | 1129 if (m_pPalette) { |
| 1122 *pDestPixel++ = FXARGB_B(m_pPalette[index]); | 1130 *pDestPixel++ = FXARGB_B(m_pPalette[index]); |
| 1123 *pDestPixel++ = FXARGB_G(m_pPalette[index]); | 1131 *pDestPixel++ = FXARGB_G(m_pPalette[index]); |
| 1124 *pDestPixel++ = FXARGB_R(m_pPalette[index]); | 1132 *pDestPixel++ = FXARGB_R(m_pPalette[index]); |
| 1125 } else { | 1133 } else { |
| 1126 *pDestPixel++ = index; | 1134 *pDestPixel++ = index; |
| 1127 *pDestPixel++ = index; | 1135 *pDestPixel++ = index; |
| 1128 *pDestPixel++ = index; | 1136 *pDestPixel++ = index; |
| 1129 } | 1137 } |
| 1130 *pDestPixel = (index < m_pCompData[0].m_ColorKeyMin || index > m _pCompData[0].m_ColorKeyMax) ? 0xff : 0; | 1138 *pDestPixel = (index < m_pCompData[0].m_ColorKeyMin || index > m _pCompData[0].m_ColorKeyMax) ? 0xff : 0; |
| 1131 pDestPixel ++ ; | 1139 pDestPixel ++ ; |
| 1132 } | 1140 } |
| 1133 return m_pMaskedLine; | 1141 return m_pMaskedLine; |
| 1134 } | 1142 } |
| 1135 return m_pLineBuf; | 1143 return m_pLineBuf; |
| 1136 } | 1144 } |
| 1137 if (m_bColorKey) { | 1145 if (m_bColorKey) { |
| 1138 if (m_nComponents == 3 && m_bpc == 8) { | 1146 if (m_nComponents == 3 && bpc == 8) { |
| 1139 FX_LPBYTE alpha_channel = m_pMaskedLine + 3; | 1147 FX_LPBYTE alpha_channel = m_pMaskedLine + 3; |
| 1140 for (int col = 0; col < m_Width; col ++) { | 1148 for (int col = 0; col < m_Width; col ++) { |
| 1141 FX_LPCBYTE pPixel = pSrcLine + col * 3; | 1149 FX_LPCBYTE pPixel = pSrcLine + col * 3; |
| 1142 alpha_channel[col * 4] = (pPixel[0] < m_pCompData[0].m_ColorKeyM in || | 1150 alpha_channel[col * 4] = (pPixel[0] < m_pCompData[0].m_ColorKeyM in || |
| 1143 pPixel[0] > m_pCompData[0].m_ColorKeyM ax || | 1151 pPixel[0] > m_pCompData[0].m_ColorKeyM ax || |
| 1144 pPixel[1] < m_pCompData[1].m_ColorKeyM in || pPixel[1] > m_pCompData[1].m_ColorKeyMax || | 1152 pPixel[1] < m_pCompData[1].m_ColorKeyM in || pPixel[1] > m_pCompData[1].m_ColorKeyMax || |
| 1145 pPixel[2] < m_pCompData[2].m_ColorKeyM in || pPixel[2] > m_pCompData[2].m_ColorKeyMax) ? 0xff : 0; | 1153 pPixel[2] < m_pCompData[2].m_ColorKeyM in || pPixel[2] > m_pCompData[2].m_ColorKeyMax) ? 0xff : 0; |
| 1146 } | 1154 } |
| 1147 } else { | 1155 } else { |
| 1148 FXSYS_memset8(m_pMaskedLine, 0xff, m_Pitch); | 1156 FXSYS_memset8(m_pMaskedLine, 0xff, m_Pitch); |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1526 if (!m_bCached) { | 1534 if (!m_bCached) { |
| 1527 if (m_pBitmap) { | 1535 if (m_pBitmap) { |
| 1528 delete m_pBitmap; | 1536 delete m_pBitmap; |
| 1529 m_pBitmap = NULL; | 1537 m_pBitmap = NULL; |
| 1530 } | 1538 } |
| 1531 if (m_pMask) { | 1539 if (m_pMask) { |
| 1532 delete m_pMask; | 1540 delete m_pMask; |
| 1533 } | 1541 } |
| 1534 } | 1542 } |
| 1535 } | 1543 } |
| OLD | NEW |