Chromium Code Reviews| Index: core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp |
| diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp |
| index 50041399e5639c1d1a759f7e56b38bebea22236b..21b0ff59f8af1f0922435bef21613f6a8d5cdd7f 100644 |
| --- a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp |
| +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp |
| @@ -496,10 +496,12 @@ FX_BOOL CPDF_DIBSource::LoadColorInfo(CPDF_Dictionary* pFormResources, CPDF_Dict |
| } |
| } |
| ValidateDictParam(); |
| + AllocCompData(); |
| + return TRUE; |
| +} |
| +void CPDF_DIBSource::AllocCompData() |
|
Tom Sepez
2014/09/03 16:59:11
maybe this is a bool so we can return FALSE if the
Tom Sepez
2014/09/03 16:59:11
nit: maybe AllocCompDataAndDecode().
Bo Xu
2014/09/03 18:10:15
I changed the function prototype to return m_pComp
Bo Xu
2014/09/03 18:10:15
Checked PDF reference, this struct contains decode
|
| +{ |
| m_pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents); |
|
Tom Sepez
2014/09/03 16:59:11
check return value for NULL?
Bo Xu
2014/09/03 18:10:16
Done.
|
| - if (m_bpc == 0) { |
| - return TRUE; |
| - } |
| int max_data = (1 << m_bpc) - 1; |
| CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode")); |
| if (pDecode) { |
| @@ -529,22 +531,22 @@ FX_BOOL CPDF_DIBSource::LoadColorInfo(CPDF_Dictionary* pFormResources, CPDF_Dict |
| if (!m_pDict->KeyExist(FX_BSTRC("SMask"))) { |
| CPDF_Object* pMask = m_pDict->GetElementValue(FX_BSTRC("Mask")); |
| if (pMask == NULL) { |
| - return TRUE; |
| + return; |
| } |
| if (pMask->GetType() == PDFOBJ_ARRAY) { |
| CPDF_Array* pArray = (CPDF_Array*)pMask; |
| - if (pArray->GetCount() >= m_nComponents * 2) |
| - for (FX_DWORD i = 0; i < m_nComponents * 2; i ++) { |
| - if (i % 2) { |
| - m_pCompData[i / 2].m_ColorKeyMax = pArray->GetInteger(i); |
| - } else { |
| - m_pCompData[i / 2].m_ColorKeyMin = pArray->GetInteger(i); |
| - } |
| + if (pArray->GetCount() >= m_nComponents * 2) { |
| + int min_num, max_num; |
|
Tom Sepez
2014/09/03 16:59:11
nit: these declarations can go inside the next lo
Bo Xu
2014/09/03 18:10:15
Done.
|
| + for (FX_DWORD i = 0; i < m_nComponents; i++) { |
| + min_num = pArray->GetInteger(i * 2); |
| + max_num = pArray->GetInteger(i * 2 + 1); |
| + m_pCompData[i].m_ColorKeyMin = FX_MAX(0, min_num); |
| + m_pCompData[i].m_ColorKeyMax = FX_MIN((1 << m_bpc) - 1, max_num); |
|
Tom Sepez
2014/09/03 16:59:11
I'd expect MIN to take two arguments?
Bo Xu
2014/09/03 18:10:15
I cleaned this a little bit.
|
| } |
| + } |
| m_bColorKey = TRUE; |
| } |
| } |
| - return TRUE; |
| } |
| ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size, int width, int height, |
| const CPDF_Dictionary* pParams); |
| @@ -572,7 +574,11 @@ int CPDF_DIBSource::CreateDecoder() |
| int comps, bpc; |
| ICodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModule(); |
| if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, comps, bpc, bTransform)) { |
| - m_nComponents = comps; |
| + if (m_nComponents != comps) { |
| + m_nComponents = comps; |
| + FX_Free(m_pCompData); |
| + AllocCompData(); |
| + } |
| m_bpc = bpc; |
| m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(src_data, src_size, m_Width, m_Height, |
| m_nComponents, bTransform); |
| @@ -1159,8 +1165,7 @@ FX_LPCBYTE CPDF_DIBSource::GetScanline(int line) const |
| FX_LPBYTE alpha_channel = m_pMaskedLine + 3; |
| for (int col = 0; col < m_Width; col ++) { |
| FX_LPCBYTE pPixel = pSrcLine + col * 3; |
| - alpha_channel[col * 4] = (pPixel[0] < m_pCompData[0].m_ColorKeyMin || |
| - pPixel[0] > m_pCompData[0].m_ColorKeyMax || |
| + alpha_channel[col * 4] = (pPixel[0] < m_pCompData[0].m_ColorKeyMin || pPixel[0] > m_pCompData[0].m_ColorKeyMax || |
| pPixel[1] < m_pCompData[1].m_ColorKeyMin || pPixel[1] > m_pCompData[1].m_ColorKeyMax || |
| pPixel[2] < m_pCompData[2].m_ColorKeyMin || pPixel[2] > m_pCompData[2].m_ColorKeyMax) ? 0xff : 0; |
| } |