From 79fcb5f6fa61967517566100415972848edefd24 Mon Sep 17 00:00:00 2001 From: Wei Li Date: Thu, 10 Mar 2016 12:35:07 -0800 Subject: Change colorspace's number of components to be unsigned Also remove unnecessary casts. BUG=pdfium:29 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1783933002 . --- core/include/fpdfapi/fpdf_resource.h | 9 +++------ core/include/fxcodec/fx_codec.h | 5 +++-- core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp | 2 +- core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp | 2 +- core/src/fpdfapi/fpdf_page/pageint.h | 4 ++-- core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp | 4 ++-- core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp | 6 +++--- core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp | 2 +- core/src/fxcodec/codec/codec_int.h | 4 ++-- core/src/fxcodec/codec/fx_codec_icc.cpp | 14 +++++++++----- 10 files changed, 27 insertions(+), 25 deletions(-) diff --git a/core/include/fpdfapi/fpdf_resource.h b/core/include/fpdfapi/fpdf_resource.h index a5acc77762..f4dd6331de 100644 --- a/core/include/fpdfapi/fpdf_resource.h +++ b/core/include/fpdfapi/fpdf_resource.h @@ -435,7 +435,7 @@ class CPDF_ColorSpace { int GetBufSize() const; FX_FLOAT* CreateBuf(); void GetDefaultColor(FX_FLOAT* buf) const; - int CountComponents() const { return m_nComponents; } + FX_DWORD CountComponents() const { return m_nComponents; } int GetFamily() const { return m_Family; } virtual void GetDefaultValue(int iComponent, FX_FLOAT& value, @@ -485,7 +485,7 @@ class CPDF_ColorSpace { CPDF_Document* const m_pDocument; protected: - CPDF_ColorSpace(CPDF_Document* pDoc, int family, int nComponents) + CPDF_ColorSpace(CPDF_Document* pDoc, int family, FX_DWORD nComponents) : m_pDocument(pDoc), m_Family(family), m_nComponents(nComponents), @@ -511,11 +511,8 @@ class CPDF_ColorSpace { } int m_Family; - - int m_nComponents; - + FX_DWORD m_nComponents; CPDF_Array* m_pArray; - FX_DWORD m_dwStdConversion; }; class CPDF_Color { diff --git a/core/include/fxcodec/fx_codec.h b/core/include/fxcodec/fx_codec.h index 5c289c1a48..183783d86c 100644 --- a/core/include/fxcodec/fx_codec.h +++ b/core/include/fxcodec/fx_codec.h @@ -458,6 +458,7 @@ class ICodec_Jbig2Encoder { public: virtual ~ICodec_Jbig2Encoder() {} }; + class ICodec_IccModule { public: enum IccCS { @@ -504,14 +505,14 @@ class ICodec_IccModule { virtual void* CreateTransform_sRGB( const uint8_t* pProfileData, FX_DWORD dwProfileSize, - int32_t& nComponents, + FX_DWORD& nComponents, int32_t intent = 0, FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT) = 0; virtual void* CreateTransform_CMYK( const uint8_t* pSrcProfileData, FX_DWORD dwSrcProfileSize, - int32_t& nSrcComponents, + FX_DWORD& nSrcComponents, const uint8_t* pDstProfileData, FX_DWORD dwDstProfileSize, int32_t intent = 0, diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp index a43aff18cb..058cbe77d4 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_colors.cpp @@ -36,7 +36,7 @@ void sRGB_to_AdobeCMYK(FX_FLOAT R, } } -int ComponentsForFamily(int family) { +FX_DWORD ComponentsForFamily(int family) { if (family == PDFCS_DEVICERGB) return 3; if (family == PDFCS_DEVICEGRAY) diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp index f7c3f7d8d3..7e8b2e525b 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp @@ -173,7 +173,7 @@ FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, if (!m_nCoordBits || !m_nCompBits) { return FALSE; } - int nComps = pCS->CountComponents(); + FX_DWORD nComps = pCS->CountComponents(); if (nComps > 8) { return FALSE; } diff --git a/core/src/fpdfapi/fpdf_page/pageint.h b/core/src/fpdfapi/fpdf_page/pageint.h index 030e734edd..517c0a4055 100644 --- a/core/src/fpdfapi/fpdf_page/pageint.h +++ b/core/src/fpdfapi/fpdf_page/pageint.h @@ -396,12 +396,12 @@ class CPDF_IccProfile { public: CPDF_IccProfile(const uint8_t* pData, FX_DWORD dwSize); ~CPDF_IccProfile(); - int32_t GetComponents() const { return m_nSrcComponents; } + FX_DWORD GetComponents() const { return m_nSrcComponents; } FX_BOOL m_bsRGB; void* m_pTransform; private: - int32_t m_nSrcComponents; + FX_DWORD m_nSrcComponents; }; class CPDF_DeviceCS : public CPDF_ColorSpace { diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp index 0f9b88e638..3be74c5ce8 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp @@ -917,8 +917,8 @@ CFX_DIBitmap* CPDF_RenderStatus::LoadSMask(CPDF_Dictionary* pSMaskDict, if (pCS) { FX_FLOAT R, G, B; FX_DWORD comps = 8; - if (pCS->CountComponents() > static_cast(comps)) { - comps = (FX_DWORD)pCS->CountComponents(); + if (pCS->CountComponents() > comps) { + comps = pCS->CountComponents(); } CFX_FixedBufGrow float_array(comps); FX_FLOAT* pFloats = float_array; diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp index 709733c56f..72472ef8fb 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp @@ -709,7 +709,7 @@ void CPDF_DIBSource::LoadJpxBitmap() { FX_BOOL bSwapRGB = FALSE; if (m_pColorSpace) { - if (components != (FX_DWORD)m_pColorSpace->CountComponents()) + if (components != m_pColorSpace->CountComponents()) return; if (m_pColorSpace == CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB)) { @@ -776,7 +776,7 @@ CPDF_DIBSource* CPDF_DIBSource::LoadMask(FX_DWORD& MatteColor) { if (pSoftMask) { CPDF_Array* pMatte = pSoftMask->GetDict()->GetArrayBy("Matte"); if (pMatte && m_pColorSpace && - (FX_DWORD)m_pColorSpace->CountComponents() <= m_nComponents) { + m_pColorSpace->CountComponents() <= m_nComponents) { std::vector colors(m_nComponents); for (FX_DWORD i = 0; i < m_nComponents; i++) { colors[i] = pMatte->GetFloatAt(i); @@ -801,7 +801,7 @@ int CPDF_DIBSource::StratLoadMask() { if (m_pMaskStream) { CPDF_Array* pMatte = m_pMaskStream->GetDict()->GetArrayBy("Matte"); if (pMatte && m_pColorSpace && - (FX_DWORD)m_pColorSpace->CountComponents() <= m_nComponents) { + m_pColorSpace->CountComponents() <= m_nComponents) { FX_FLOAT R, G, B; std::vector colors(m_nComponents); for (FX_DWORD i = 0; i < m_nComponents; i++) { diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp index e4876a0d26..92e0ff4d12 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp @@ -832,7 +832,7 @@ void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern, CPDF_Array* pBackColor = pPattern->m_pShadingObj->GetDict()->GetArrayBy("Background"); if (pBackColor && - pBackColor->GetCount() >= (FX_DWORD)pColorSpace->CountComponents()) { + pBackColor->GetCount() >= pColorSpace->CountComponents()) { CFX_FixedBufGrow comps(pColorSpace->CountComponents()); for (int i = 0; i < pColorSpace->CountComponents(); i++) { comps[i] = pBackColor->GetNumberAt(i); diff --git a/core/src/fxcodec/codec/codec_int.h b/core/src/fxcodec/codec/codec_int.h index bde3daeaea..5c784adad6 100644 --- a/core/src/fxcodec/codec/codec_int.h +++ b/core/src/fxcodec/codec/codec_int.h @@ -287,13 +287,13 @@ class CCodec_IccModule : public ICodec_IccModule { void* CreateTransform_sRGB( const uint8_t* pProfileData, FX_DWORD dwProfileSize, - int32_t& nComponents, + FX_DWORD& nComponents, int32_t intent = 0, FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT) override; void* CreateTransform_CMYK( const uint8_t* pSrcProfileData, FX_DWORD dwSrcProfileSize, - int32_t& nSrcComponents, + FX_DWORD& nSrcComponents, const uint8_t* pDstProfileData, FX_DWORD dwDstProfileSize, int32_t intent = 0, diff --git a/core/src/fxcodec/codec/fx_codec_icc.cpp b/core/src/fxcodec/codec/fx_codec_icc.cpp index 297f392a30..ebec0b0a34 100644 --- a/core/src/fxcodec/codec/fx_codec_icc.cpp +++ b/core/src/fxcodec/codec/fx_codec_icc.cpp @@ -66,7 +66,8 @@ FX_BOOL CheckComponents(cmsColorSpaceSignature cs, } return TRUE; } -int32_t GetCSComponents(cmsColorSpaceSignature cs) { + +FX_DWORD GetCSComponents(cmsColorSpaceSignature cs) { FX_DWORD components; switch (cs) { case cmsSigLabData: @@ -87,9 +88,10 @@ int32_t GetCSComponents(cmsColorSpaceSignature cs) { } return components; } + void* IccLib_CreateTransform(const unsigned char* pSrcProfileData, FX_DWORD dwSrcProfileSize, - int32_t& nSrcComponents, + FX_DWORD& nSrcComponents, const unsigned char* pDstProfileData, FX_DWORD dwDstProfileSize, int32_t nDstComponents, @@ -169,7 +171,7 @@ void* IccLib_CreateTransform(const unsigned char* pSrcProfileData, } void* IccLib_CreateTransform_sRGB(const unsigned char* pProfileData, FX_DWORD dwProfileSize, - int32_t& nComponents, + FX_DWORD& nComponents, int32_t intent, FX_DWORD dwSrcFormat) { return IccLib_CreateTransform(pProfileData, dwProfileSize, nComponents, NULL, @@ -536,15 +538,16 @@ CCodec_IccModule::~CCodec_IccModule() { } void* CCodec_IccModule::CreateTransform_sRGB(const uint8_t* pProfileData, FX_DWORD dwProfileSize, - int32_t& nComponents, + FX_DWORD& nComponents, int32_t intent, FX_DWORD dwSrcFormat) { return IccLib_CreateTransform_sRGB(pProfileData, dwProfileSize, nComponents, intent, dwSrcFormat); } + void* CCodec_IccModule::CreateTransform_CMYK(const uint8_t* pSrcProfileData, FX_DWORD dwSrcProfileSize, - int32_t& nSrcComponents, + FX_DWORD& nSrcComponents, const uint8_t* pDstProfileData, FX_DWORD dwDstProfileSize, int32_t intent, @@ -554,6 +557,7 @@ void* CCodec_IccModule::CreateTransform_CMYK(const uint8_t* pSrcProfileData, pSrcProfileData, dwSrcProfileSize, nSrcComponents, pDstProfileData, dwDstProfileSize, 4, intent, dwSrcFormat, dwDstFormat); } + void CCodec_IccModule::DestroyTransform(void* pTransform) { IccLib_DestroyTransform(pTransform); } -- cgit v1.2.3