From a12159b17085796e2b72d2b49e850092e0b4e8b7 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 15 Mar 2017 13:26:37 -0700 Subject: Refactor some CPDF_ColorSpace code. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I1e30d68dae3bf70cf3c426f6126d593b7f1c3ba4 Reviewed-on: https://pdfium-review.googlesource.com/2991 Commit-Queue: Lei Zhang Reviewed-by: Nicolás Peña --- core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp | 2 +- core/fpdfapi/page/cpdf_color.cpp | 14 +- core/fpdfapi/page/cpdf_color.h | 2 +- core/fpdfapi/page/cpdf_colorspace.cpp | 564 +++++++++++++----------- core/fpdfapi/page/cpdf_colorspace.h | 20 +- core/fpdfapi/page/cpdf_colorstate.cpp | 18 +- core/fpdfapi/page/cpdf_devicecs_unittest.cpp | 26 +- core/fpdfapi/page/cpdf_meshstream.cpp | 6 +- core/fpdfapi/page/cpdf_streamparser.cpp | 2 +- core/fpdfapi/page/fpdf_page_colors.cpp | 47 +- core/fpdfapi/page/fpdf_page_func.cpp | 10 +- core/fpdfapi/page/pageint.h | 21 +- core/fpdfapi/parser/cpdf_security_handler.cpp | 2 +- core/fpdfapi/parser/fpdf_parser_decode.cpp | 10 +- core/fpdfapi/render/cpdf_dibsource.cpp | 28 +- core/fpdfapi/render/cpdf_docrenderdata.cpp | 4 +- core/fpdfapi/render/cpdf_renderstatus.cpp | 30 +- core/fxcodec/codec/ccodec_iccmodule.h | 2 +- core/fxcodec/codec/fx_codec_flate.cpp | 13 +- core/fxcodec/codec/fx_codec_icc.cpp | 26 +- core/fxcrt/fx_basic_gcc.cpp | 9 +- core/fxcrt/fx_xml_parser.cpp | 2 +- xfa/fde/css/cfde_csssyntaxparser.cpp | 4 +- 23 files changed, 458 insertions(+), 404 deletions(-) diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp index 20af9b7c2e..98e96255c6 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp @@ -37,7 +37,7 @@ bool GetColor(const CPDF_Color* pColor, float* rgb) { int intRGB[3]; if (!pColor || pColor->GetColorSpace() != CPDF_ColorSpace::GetStockCS(PDFCS_DEVICERGB) || - !pColor->GetRGB(intRGB[0], intRGB[1], intRGB[2])) { + !pColor->GetRGB(&intRGB[0], &intRGB[1], &intRGB[2])) { return false; } rgb[0] = intRGB[0] / 255.0f; diff --git a/core/fpdfapi/page/cpdf_color.cpp b/core/fpdfapi/page/cpdf_color.cpp index b191b24808..46771513f4 100644 --- a/core/fpdfapi/page/cpdf_color.cpp +++ b/core/fpdfapi/page/cpdf_color.cpp @@ -132,17 +132,19 @@ void CPDF_Color::Copy(const CPDF_Color* pSrc) { } } -bool CPDF_Color::GetRGB(int& R, int& G, int& B) const { +bool CPDF_Color::GetRGB(int* R, int* G, int* B) const { if (!m_pCS || !m_pBuffer) return false; - float r = 0.0f, g = 0.0f, b = 0.0f; - if (!m_pCS->GetRGB(m_pBuffer, r, g, b)) + float r = 0.0f; + float g = 0.0f; + float b = 0.0f; + if (!m_pCS->GetRGB(m_pBuffer, &r, &g, &b)) return false; - R = (int32_t)(r * 255 + 0.5f); - G = (int32_t)(g * 255 + 0.5f); - B = (int32_t)(b * 255 + 0.5f); + *R = static_cast(r * 255 + 0.5f); + *G = static_cast(g * 255 + 0.5f); + *B = static_cast(b * 255 + 0.5f); return true; } diff --git a/core/fpdfapi/page/cpdf_color.h b/core/fpdfapi/page/cpdf_color.h index 9b6eff85a3..67c5063326 100644 --- a/core/fpdfapi/page/cpdf_color.h +++ b/core/fpdfapi/page/cpdf_color.h @@ -26,7 +26,7 @@ class CPDF_Color { void SetValue(float* comp); void SetValue(CPDF_Pattern* pPattern, float* comp, int ncomps); - bool GetRGB(int& R, int& G, int& B) const; + bool GetRGB(int* R, int* G, int* B) const; CPDF_Pattern* GetPattern() const; const CPDF_ColorSpace* GetColorSpace() const { return m_pCS; } diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp index a88edb1828..7a85284ca7 100644 --- a/core/fpdfapi/page/cpdf_colorspace.cpp +++ b/core/fpdfapi/page/cpdf_colorspace.cpp @@ -6,6 +6,7 @@ #include "core/fpdfapi/page/cpdf_colorspace.h" +#include #include #include @@ -62,18 +63,18 @@ const uint8_t g_sRGBSamples2[] = { class CPDF_CalGray : public CPDF_ColorSpace { public: explicit CPDF_CalGray(CPDF_Document* pDoc); + ~CPDF_CalGray() override {} + // CPDF_ColorSpace: bool v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override; - - bool GetRGB(float* pBuf, float& R, float& G, float& B) const override; + bool GetRGB(float* pBuf, float* R, float* G, float* B) const override; bool SetRGB(float* pBuf, float R, float G, float B) const override; - void TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, int image_width, int image_height, - bool bTransMask = false) const override; + bool bTransMask) const override; private: float m_WhitePoint[3]; @@ -84,10 +85,11 @@ class CPDF_CalGray : public CPDF_ColorSpace { class CPDF_CalRGB : public CPDF_ColorSpace { public: explicit CPDF_CalRGB(CPDF_Document* pDoc); + ~CPDF_CalRGB() override {} bool v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override; - bool GetRGB(float* pBuf, float& R, float& G, float& B) const override; + bool GetRGB(float* pBuf, float* R, float* G, float* B) const override; bool SetRGB(float* pBuf, float R, float G, float B) const override; void TranslateImageLine(uint8_t* pDestBuf, @@ -95,7 +97,7 @@ class CPDF_CalRGB : public CPDF_ColorSpace { int pixels, int image_width, int image_height, - bool bTransMask = false) const override; + bool bTransMask) const override; float m_WhitePoint[3]; float m_BlackPoint[3]; @@ -108,22 +110,22 @@ class CPDF_CalRGB : public CPDF_ColorSpace { class CPDF_LabCS : public CPDF_ColorSpace { public: explicit CPDF_LabCS(CPDF_Document* pDoc); + ~CPDF_LabCS() override {} bool v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override; void GetDefaultValue(int iComponent, - float& value, - float& min, - float& max) const override; - bool GetRGB(float* pBuf, float& R, float& G, float& B) const override; - bool SetRGB(float* pBuf, float R, float G, float B) const override; + float* value, + float* min, + float* max) const override; + bool GetRGB(float* pBuf, float* R, float* G, float* B) const override; void TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, int image_width, int image_height, - bool bTransMask = false) const override; + bool bTransMask) const override; float m_WhitePoint[3]; float m_BlackPoint[3]; @@ -135,24 +137,30 @@ class CPDF_ICCBasedCS : public CPDF_ColorSpace { explicit CPDF_ICCBasedCS(CPDF_Document* pDoc); ~CPDF_ICCBasedCS() override; + // CPDF_ColorSpace: bool v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override; - - bool GetRGB(float* pBuf, float& R, float& G, float& B) const override; - bool SetRGB(float* pBuf, float R, float G, float B) const override; - + bool GetRGB(float* pBuf, float* R, float* G, float* B) const override; bool v_GetCMYK(float* pBuf, - float& c, - float& m, - float& y, - float& k) const override; - + float* c, + float* m, + float* y, + float* k) const override; void EnableStdConversion(bool bEnabled) override; void TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, int image_width, int image_height, - bool bTransMask = false) const override; + bool bTransMask) const override; + + bool IsSRGB() const { return m_pProfile->m_bsRGB; } + + private: + // If no valid ICC profile or using sRGB, try looking for an alternate. + bool FindAlternateProfile(CPDF_Document* pDoc, CPDF_Dictionary* pDict); + + void UseStockAlternateProfile(); + void PopulateRanges(CPDF_Dictionary* pDict); CFX_MaybeOwned m_pAlterCS; CPDF_IccProfile* m_pProfile; @@ -167,7 +175,7 @@ class CPDF_IndexedCS : public CPDF_ColorSpace { bool v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override; - bool GetRGB(float* pBuf, float& R, float& G, float& B) const override; + bool GetRGB(float* pBuf, float* R, float* G, float* B) const override; CPDF_ColorSpace* GetBaseCS() const override; void EnableStdConversion(bool bEnabled) override; @@ -187,11 +195,11 @@ class CPDF_SeparationCS : public CPDF_ColorSpace { // CPDF_ColorSpace: void GetDefaultValue(int iComponent, - float& value, - float& min, - float& max) const override; + float* value, + float* min, + float* max) const override; bool v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override; - bool GetRGB(float* pBuf, float& R, float& G, float& B) const override; + bool GetRGB(float* pBuf, float* R, float* G, float* B) const override; void EnableStdConversion(bool bEnabled) override; std::unique_ptr m_pAltCS; @@ -206,11 +214,11 @@ class CPDF_DeviceNCS : public CPDF_ColorSpace { // CPDF_ColorSpace: void GetDefaultValue(int iComponent, - float& value, - float& min, - float& max) const override; + float* value, + float* min, + float* max) const override; bool v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override; - bool GetRGB(float* pBuf, float& R, float& G, float& B) const override; + bool GetRGB(float* pBuf, float* R, float* G, float* B) const override; void EnableStdConversion(bool bEnabled) override; std::unique_ptr m_pAltCS; @@ -218,40 +226,32 @@ class CPDF_DeviceNCS : public CPDF_ColorSpace { }; float RGB_Conversion(float colorComponent) { - if (colorComponent > 1) - colorComponent = 1; - if (colorComponent < 0) - colorComponent = 0; - - int scale = (int)(colorComponent * 1023); - if (scale < 0) - scale = 0; + colorComponent = std::min(std::max(colorComponent, 0.0f), 1.0f); + int scale = std::max(static_cast(colorComponent * 1023), 0); if (scale < 192) - colorComponent = (g_sRGBSamples1[scale] / 255.0f); - else - colorComponent = (g_sRGBSamples2[scale / 4 - 48] / 255.0f); - return colorComponent; + return g_sRGBSamples1[scale] / 255.0f; + return g_sRGBSamples2[scale / 4 - 48] / 255.0f; } -void XYZ_to_sRGB(float X, float Y, float Z, float& R, float& G, float& B) { +void XYZ_to_sRGB(float X, float Y, float Z, float* R, float* G, float* B) { float R1 = 3.2410f * X - 1.5374f * Y - 0.4986f * Z; float G1 = -0.9692f * X + 1.8760f * Y + 0.0416f * Z; float B1 = 0.0556f * X - 0.2040f * Y + 1.0570f * Z; - R = RGB_Conversion(R1); - G = RGB_Conversion(G1); - B = RGB_Conversion(B1); + *R = RGB_Conversion(R1); + *G = RGB_Conversion(G1); + *B = RGB_Conversion(B1); } void XYZ_to_sRGB_WhitePoint(float X, float Y, float Z, - float& R, - float& G, - float& B, float Xw, float Yw, - float Zw) { + float Zw, + float* R, + float* G, + float* B) { // The following RGB_xyz is based on // sRGB value {Rx,Ry}={0.64, 0.33}, {Gx,Gy}={0.30, 0.60}, {Bx,By}={0.15, 0.06} @@ -269,9 +269,9 @@ void XYZ_to_sRGB_WhitePoint(float X, CFX_Matrix_3by3 M = RGB_xyz.Multiply(RGB_SUM_XYZ_DIAG); CFX_Vector_3by1 RGB = M.Inverse().TransformVector(XYZ); - R = RGB_Conversion(RGB.a); - G = RGB_Conversion(RGB.b); - B = RGB_Conversion(RGB.c); + *R = RGB_Conversion(RGB.a); + *G = RGB_Conversion(RGB.b); + *B = RGB_Conversion(RGB.c); } } // namespace @@ -331,26 +331,34 @@ std::unique_ptr CPDF_ColorSpace::Load(CPDF_Document* pDoc, return std::unique_ptr(ColorspaceFromName(familyname)); std::unique_ptr pCS; - uint32_t id = familyname.GetID(); - if (id == FXBSTR_ID('C', 'a', 'l', 'G')) { - pCS.reset(new CPDF_CalGray(pDoc)); - } else if (id == FXBSTR_ID('C', 'a', 'l', 'R')) { - pCS.reset(new CPDF_CalRGB(pDoc)); - } else if (id == FXBSTR_ID('L', 'a', 'b', 0)) { - pCS.reset(new CPDF_LabCS(pDoc)); - } else if (id == FXBSTR_ID('I', 'C', 'C', 'B')) { - pCS.reset(new CPDF_ICCBasedCS(pDoc)); - } else if (id == FXBSTR_ID('I', 'n', 'd', 'e') || - id == FXBSTR_ID('I', 0, 0, 0)) { - pCS.reset(new CPDF_IndexedCS(pDoc)); - } else if (id == FXBSTR_ID('S', 'e', 'p', 'a')) { - pCS.reset(new CPDF_SeparationCS(pDoc)); - } else if (id == FXBSTR_ID('D', 'e', 'v', 'i')) { - pCS.reset(new CPDF_DeviceNCS(pDoc)); - } else if (id == FXBSTR_ID('P', 'a', 't', 't')) { - pCS.reset(new CPDF_PatternCS(pDoc)); - } else { - return nullptr; + switch (familyname.GetID()) { + case FXBSTR_ID('C', 'a', 'l', 'G'): + pCS.reset(new CPDF_CalGray(pDoc)); + break; + case FXBSTR_ID('C', 'a', 'l', 'R'): + pCS.reset(new CPDF_CalRGB(pDoc)); + break; + case FXBSTR_ID('L', 'a', 'b', 0): + pCS.reset(new CPDF_LabCS(pDoc)); + break; + case FXBSTR_ID('I', 'C', 'C', 'B'): + pCS.reset(new CPDF_ICCBasedCS(pDoc)); + break; + case FXBSTR_ID('I', 'n', 'd', 'e'): + case FXBSTR_ID('I', 0, 0, 0): + pCS.reset(new CPDF_IndexedCS(pDoc)); + break; + case FXBSTR_ID('S', 'e', 'p', 'a'): + pCS.reset(new CPDF_SeparationCS(pDoc)); + break; + case FXBSTR_ID('D', 'e', 'v', 'i'): + pCS.reset(new CPDF_DeviceNCS(pDoc)); + break; + case FXBSTR_ID('P', 'a', 't', 't'): + pCS.reset(new CPDF_PatternCS(pDoc)); + break; + default: + return nullptr; } pCS->m_pArray = pArray; if (!pCS->v_Load(pDoc, pArray)) @@ -383,14 +391,14 @@ float* CPDF_ColorSpace::CreateBuf() { } bool CPDF_ColorSpace::sRGB() const { - if (m_Family == PDFCS_DEVICERGB) { + if (m_Family == PDFCS_DEVICERGB) return true; - } - if (m_Family != PDFCS_ICCBASED) { + + if (m_Family != PDFCS_ICCBASED) return false; - } - CPDF_ICCBasedCS* pCS = (CPDF_ICCBasedCS*)this; - return pCS->m_pProfile->m_bsRGB; + + const CPDF_ICCBasedCS* pCS = static_cast(this); + return pCS->IsSRGB(); } bool CPDF_ColorSpace::SetRGB(float* pBuf, float R, float G, float B) const { @@ -398,18 +406,20 @@ bool CPDF_ColorSpace::SetRGB(float* pBuf, float R, float G, float B) const { } bool CPDF_ColorSpace::GetCMYK(float* pBuf, - float& c, - float& m, - float& y, - float& k) const { - if (v_GetCMYK(pBuf, c, m, y, k)) { + float* c, + float* m, + float* y, + float* k) const { + if (v_GetCMYK(pBuf, c, m, y, k)) return true; - } - float R, G, B; - if (!GetRGB(pBuf, R, G, B)) { + + float R; + float G; + float B; + if (!GetRGB(pBuf, &R, &G, &B)) return false; - } - sRGB_to_AdobeCMYK(R, G, B, c, m, y, k); + + sRGB_to_AdobeCMYK(R, G, B, *c, *m, *y, *k); return true; } @@ -418,22 +428,24 @@ bool CPDF_ColorSpace::SetCMYK(float* pBuf, float m, float y, float k) const { - if (v_SetCMYK(pBuf, c, m, y, k)) { + if (v_SetCMYK(pBuf, c, m, y, k)) return true; - } - float R, G, B; + + float R; + float G; + float B; AdobeCMYK_to_sRGB(c, m, y, k, R, G, B); return SetRGB(pBuf, R, G, B); } void CPDF_ColorSpace::GetDefaultColor(float* buf) const { - if (!buf || m_Family == PDFCS_PATTERN) { + if (!buf || m_Family == PDFCS_PATTERN) return; - } - float min, max; - for (uint32_t i = 0; i < m_nComponents; i++) { - GetDefaultValue(i, buf[i], min, max); - } + + float min; + float max; + for (uint32_t i = 0; i < m_nComponents; i++) + GetDefaultValue(i, &buf[i], &min, &max); } uint32_t CPDF_ColorSpace::CountComponents() const { @@ -441,12 +453,12 @@ uint32_t CPDF_ColorSpace::CountComponents() const { } void CPDF_ColorSpace::GetDefaultValue(int iComponent, - float& value, - float& min, - float& max) const { - value = 0; - min = 0; - max = 1.0f; + float* value, + float* min, + float* max) const { + *value = 0.0f; + *min = 0.0f; + *max = 1.0f; } void CPDF_ColorSpace::TranslateImageLine(uint8_t* dest_buf, @@ -457,18 +469,17 @@ void CPDF_ColorSpace::TranslateImageLine(uint8_t* dest_buf, bool bTransMask) const { CFX_FixedBufGrow srcbuf(m_nComponents); float* src = srcbuf; - float R, G, B; + float R; + float G; + float B; + const int divisor = m_Family != PDFCS_INDEXED ? 255 : 1; for (int i = 0; i < pixels; i++) { for (uint32_t j = 0; j < m_nComponents; j++) - if (m_Family == PDFCS_INDEXED) { - src[j] = (float)(*src_buf++); - } else { - src[j] = (float)(*src_buf++) / 255; - } - GetRGB(src, R, G, B); - *dest_buf++ = (int32_t)(B * 255); - *dest_buf++ = (int32_t)(G * 255); - *dest_buf++ = (int32_t)(R * 255); + src[j] = static_cast(*src_buf++) / divisor; + GetRGB(src, &R, &G, &B); + *dest_buf++ = static_cast(B * 255); + *dest_buf++ = static_cast(G * 255); + *dest_buf++ = static_cast(R * 255); } } @@ -499,10 +510,10 @@ bool CPDF_ColorSpace::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { } bool CPDF_ColorSpace::v_GetCMYK(float* pBuf, - float& c, - float& m, - float& y, - float& k) const { + float* c, + float* m, + float* y, + float* k) const { return false; } @@ -537,8 +548,10 @@ bool CPDF_CalGray::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { return true; } -bool CPDF_CalGray::GetRGB(float* pBuf, float& R, float& G, float& B) const { - R = G = B = *pBuf; +bool CPDF_CalGray::GetRGB(float* pBuf, float* R, float* G, float* B) const { + *R = *pBuf; + *G = *pBuf; + *B = *pBuf; return true; } @@ -600,7 +613,7 @@ bool CPDF_CalRGB::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { return true; } -bool CPDF_CalRGB::GetRGB(float* pBuf, float& R, float& G, float& B) const { +bool CPDF_CalRGB::GetRGB(float* pBuf, float* R, float* G, float* B) const { float A_ = pBuf[0]; float B_ = pBuf[1]; float C_ = pBuf[2]; @@ -622,8 +635,8 @@ bool CPDF_CalRGB::GetRGB(float* pBuf, float& R, float& G, float& B) const { Y = B_; Z = C_; } - XYZ_to_sRGB_WhitePoint(X, Y, Z, R, G, B, m_WhitePoint[0], m_WhitePoint[1], - m_WhitePoint[2]); + XYZ_to_sRGB_WhitePoint(X, Y, Z, m_WhitePoint[0], m_WhitePoint[1], + m_WhitePoint[2], R, G, B); return true; } @@ -646,10 +659,10 @@ void CPDF_CalRGB::TranslateImageLine(uint8_t* pDestBuf, float G; float B; for (int i = 0; i < pixels; i++) { - Cal[0] = ((float)pSrcBuf[2]) / 255; - Cal[1] = ((float)pSrcBuf[1]) / 255; - Cal[2] = ((float)pSrcBuf[0]) / 255; - GetRGB(Cal, R, G, B); + Cal[0] = static_cast(pSrcBuf[2]) / 255; + Cal[1] = static_cast(pSrcBuf[1]) / 255; + Cal[2] = static_cast(pSrcBuf[0]) / 255; + GetRGB(Cal, &R, &G, &B); pDestBuf[0] = FXSYS_round(B * 255); pDestBuf[1] = FXSYS_round(G * 255); pDestBuf[2] = FXSYS_round(R * 255); @@ -664,21 +677,18 @@ CPDF_LabCS::CPDF_LabCS(CPDF_Document* pDoc) : CPDF_ColorSpace(pDoc, PDFCS_LAB, 3) {} void CPDF_LabCS::GetDefaultValue(int iComponent, - float& value, - float& min, - float& max) const { + float* value, + float* min, + float* max) const { ASSERT(iComponent < 3); - value = 0; if (iComponent == 0) { - min = 0; - max = 100 * 1.0f; + *min = 0.0f; + *max = 100 * 1.0f; + *value = 0.0f; } else { - min = m_Ranges[iComponent * 2 - 2]; - max = m_Ranges[iComponent * 2 - 1]; - if (value < min) - value = min; - else if (value > max) - value = max; + *min = m_Ranges[iComponent * 2 - 2]; + *max = m_Ranges[iComponent * 2 - 1]; + *value = std::min(std::max(0.0f, *min), *max); } } @@ -704,14 +714,16 @@ bool CPDF_LabCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { return true; } -bool CPDF_LabCS::GetRGB(float* pBuf, float& R, float& G, float& B) const { +bool CPDF_LabCS::GetRGB(float* pBuf, float* R, float* G, float* B) const { float Lstar = pBuf[0]; float astar = pBuf[1]; float bstar = pBuf[2]; float M = (Lstar + 16.0f) / 116.0f; float L = M + astar / 500.0f; float N = M - bstar / 200.0f; - float X, Y, Z; + float X; + float Y; + float Z; if (L < 0.2069f) X = 0.957f * 0.12842f * (L - 0.1379f); else @@ -731,10 +743,6 @@ bool CPDF_LabCS::GetRGB(float* pBuf, float& R, float& G, float& B) const { return true; } -bool CPDF_LabCS::SetRGB(float* pBuf, float R, float G, float B) const { - return false; -} - void CPDF_LabCS::TranslateImageLine(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels, @@ -743,14 +751,16 @@ void CPDF_LabCS::TranslateImageLine(uint8_t* pDestBuf, bool bTransMask) const { for (int i = 0; i < pixels; i++) { float lab[3]; - float R, G, B; + float R; + float G; + float B; lab[0] = (pSrcBuf[0] * 100 / 255.0f); lab[1] = (float)(pSrcBuf[1] - 128); lab[2] = (float)(pSrcBuf[2] - 128); - GetRGB(lab, R, G, B); - pDestBuf[0] = (int32_t)(B * 255); - pDestBuf[1] = (int32_t)(G * 255); - pDestBuf[2] = (int32_t)(R * 255); + GetRGB(lab, &R, &G, &B); + pDestBuf[0] = static_cast(B * 255); + pDestBuf[1] = static_cast(G * 255); + pDestBuf[2] = static_cast(R * 255); pDestBuf += 3; pSrcBuf += 3; } @@ -781,58 +791,18 @@ bool CPDF_ICCBasedCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { // Try using the |nComponents| from ICC profile m_nComponents = m_pProfile->GetComponents(); CPDF_Dictionary* pDict = pStream->GetDict(); - if (!m_pProfile->m_pTransform) { // No valid ICC profile or using sRGB - CPDF_Object* pAlterCSObj = - pDict ? pDict->GetDirectObjectFor("Alternate") : nullptr; - if (pAlterCSObj) { - std::unique_ptr pAlterCS = - CPDF_ColorSpace::Load(pDoc, pAlterCSObj); - if (pAlterCS) { - if (m_nComponents == 0) { // NO valid ICC profile - if (pAlterCS->CountComponents() > 0) { // Use Alternative colorspace - m_nComponents = pAlterCS->CountComponents(); - m_pAlterCS = std::move(pAlterCS); - } else { // No valid alternative colorspace - int32_t nDictComponents = pDict ? pDict->GetIntegerFor("N") : 0; - if (nDictComponents != 1 && nDictComponents != 3 && - nDictComponents != 4) { - return false; - } - m_nComponents = nDictComponents; - } - } else { // Using sRGB - if (pAlterCS->CountComponents() == m_nComponents) - m_pAlterCS = std::move(pAlterCS); - } - } - } - if (!m_pAlterCS) { - if (m_nComponents == 1) - m_pAlterCS = GetStockCS(PDFCS_DEVICEGRAY); - else if (m_nComponents == 3) - m_pAlterCS = GetStockCS(PDFCS_DEVICERGB); - else if (m_nComponents == 4) - m_pAlterCS = GetStockCS(PDFCS_DEVICECMYK); - } - } - CPDF_Array* pRanges = pDict->GetArrayFor("Range"); - m_pRanges = FX_Alloc2D(float, m_nComponents, 2); - for (uint32_t i = 0; i < m_nComponents * 2; i++) { - if (pRanges) - m_pRanges[i] = pRanges->GetNumberAt(i); - else if (i % 2) - m_pRanges[i] = 1.0f; - else - m_pRanges[i] = 0; - } + if (!m_pProfile->m_pTransform && !FindAlternateProfile(pDoc, pDict)) + return false; + + PopulateRanges(pDict); return true; } -bool CPDF_ICCBasedCS::GetRGB(float* pBuf, float& R, float& G, float& B) const { +bool CPDF_ICCBasedCS::GetRGB(float* pBuf, float* R, float* G, float* B) const { if (m_pProfile && m_pProfile->m_bsRGB) { - R = pBuf[0]; - G = pBuf[1]; - B = pBuf[2]; + *R = pBuf[0]; + *G = pBuf[1]; + *B = pBuf[2]; return true; } CCodec_IccModule* pIccModule = CPDF_ModuleMgr::Get()->GetIccModule(); @@ -840,36 +810,32 @@ bool CPDF_ICCBasedCS::GetRGB(float* pBuf, float& R, float& G, float& B) const { if (m_pAlterCS) return m_pAlterCS->GetRGB(pBuf, R, G, B); - R = 0.0f; - G = 0.0f; - B = 0.0f; + *R = 0.0f; + *G = 0.0f; + *B = 0.0f; return true; } float rgb[3]; pIccModule->SetComponents(m_nComponents); pIccModule->Translate(m_pProfile->m_pTransform, pBuf, rgb); - R = rgb[0]; - G = rgb[1]; - B = rgb[2]; + *R = rgb[0]; + *G = rgb[1]; + *B = rgb[2]; return true; } -bool CPDF_ICCBasedCS::SetRGB(float* pBuf, float R, float G, float B) const { - return false; -} - bool CPDF_ICCBasedCS::v_GetCMYK(float* pBuf, - float& c, - float& m, - float& y, - float& k) const { + float* c, + float* m, + float* y, + float* k) const { if (m_nComponents != 4) return false; - c = pBuf[0]; - m = pBuf[1]; - y = pBuf[2]; - k = pBuf[3]; + *c = pBuf[0]; + *m = pBuf[1]; + *y = pBuf[2]; + *k = pBuf[3]; return true; } @@ -927,7 +893,73 @@ void CPDF_ICCBasedCS::TranslateImageLine(uint8_t* pDestBuf, } } else if (m_pAlterCS) { m_pAlterCS->TranslateImageLine(pDestBuf, pSrcBuf, pixels, image_width, - image_height); + image_height, false); + } +} + +bool CPDF_ICCBasedCS::FindAlternateProfile(CPDF_Document* pDoc, + CPDF_Dictionary* pDict) { + CPDF_Object* pAlterCSObj = + pDict ? pDict->GetDirectObjectFor("Alternate") : nullptr; + if (!pAlterCSObj) { + UseStockAlternateProfile(); + return true; + } + + auto pAlterCS = CPDF_ColorSpace::Load(pDoc, pAlterCSObj); + if (!pAlterCS) { + UseStockAlternateProfile(); + return true; + } + + if (m_nComponents) { + ASSERT(IsSRGB()); // Using sRGB case. + if (pAlterCS->CountComponents() == m_nComponents) + m_pAlterCS = std::move(pAlterCS); + else + UseStockAlternateProfile(); + return true; + } + + // NO valid ICC profile + if (pAlterCS->CountComponents() > 0) { + // Use Alternative colorspace + m_nComponents = pAlterCS->CountComponents(); + m_pAlterCS = std::move(pAlterCS); + return true; + } + + int32_t nDictComponents = pDict ? pDict->GetIntegerFor("N") : 0; + if (nDictComponents == 1 || nDictComponents == 3 || nDictComponents == 4) { + m_nComponents = nDictComponents; + UseStockAlternateProfile(); + return true; + } + + // No valid alternative colorspace + return false; +} + +void CPDF_ICCBasedCS::UseStockAlternateProfile() { + ASSERT(!m_pAlterCS); + if (m_nComponents == 1) + m_pAlterCS = GetStockCS(PDFCS_DEVICEGRAY); + else if (m_nComponents == 3) + m_pAlterCS = GetStockCS(PDFCS_DEVICERGB); + else if (m_nComponents == 4) + m_pAlterCS = GetStockCS(PDFCS_DEVICECMYK); +} + +void CPDF_ICCBasedCS::PopulateRanges(CPDF_Dictionary* pDict) { + CPDF_Array* pRanges = pDict->GetArrayFor("Range"); + m_pRanges = FX_Alloc2D(float, m_nComponents, 2); + for (uint32_t i = 0; i < m_nComponents * 2; i++) { + if (pRanges) + m_pRanges[i] = pRanges->GetNumberAt(i); + else if (i % 2) + m_pRanges[i] = 1.0f; + else + m_pRanges[i] = 0.0f; } } @@ -946,25 +978,25 @@ CPDF_IndexedCS::~CPDF_IndexedCS() { } bool CPDF_IndexedCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { - if (pArray->GetCount() < 4) { + if (pArray->GetCount() < 4) return false; - } + CPDF_Object* pBaseObj = pArray->GetDirectObjectAt(1); - if (pBaseObj == m_pArray) { + if (pBaseObj == m_pArray) return false; - } + CPDF_DocPageData* pDocPageData = pDoc->GetPageData(); m_pBaseCS = pDocPageData->GetColorSpace(pBaseObj, nullptr); - if (!m_pBaseCS) { + if (!m_pBaseCS) return false; - } + m_pCountedBaseCS = pDocPageData->FindColorSpacePtr(m_pBaseCS->GetArray()); m_nBaseComponents = m_pBaseCS->CountComponents(); m_pCompMinMax = FX_Alloc2D(float, m_nBaseComponents, 2); float defvalue; for (int i = 0; i < m_nBaseComponents; i++) { - m_pBaseCS->GetDefaultValue(i, defvalue, m_pCompMinMax[i * 2], - m_pCompMinMax[i * 2 + 1]); + m_pBaseCS->GetDefaultValue(i, &defvalue, &m_pCompMinMax[i * 2], + &m_pCompMinMax[i * 2 + 1]); m_pCompMinMax[i * 2 + 1] -= m_pCompMinMax[i * 2]; } m_MaxIndex = pArray->GetIntegerAt(2); @@ -983,11 +1015,11 @@ bool CPDF_IndexedCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { return true; } -bool CPDF_IndexedCS::GetRGB(float* pBuf, float& R, float& G, float& B) const { - int index = (int32_t)(*pBuf); - if (index < 0 || index > m_MaxIndex) { +bool CPDF_IndexedCS::GetRGB(float* pBuf, float* R, float* G, float* B) const { + int index = static_cast(*pBuf); + if (index < 0 || index > m_MaxIndex) return false; - } + if (m_nBaseComponents) { if (index == INT_MAX || (index + 1) > INT_MAX / m_nBaseComponents || (index + 1) * m_nBaseComponents > (int)m_Table.GetLength()) { @@ -1012,9 +1044,8 @@ CPDF_ColorSpace* CPDF_IndexedCS::GetBaseCS() const { void CPDF_IndexedCS::EnableStdConversion(bool bEnabled) { CPDF_ColorSpace::EnableStdConversion(bEnabled); - if (m_pBaseCS) { + if (m_pBaseCS) m_pBaseCS->EnableStdConversion(bEnabled); - } } CPDF_PatternCS::CPDF_PatternCS(CPDF_Document* pDoc) @@ -1031,35 +1062,34 @@ CPDF_PatternCS::~CPDF_PatternCS() { bool CPDF_PatternCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { CPDF_Object* pBaseCS = pArray->GetDirectObjectAt(1); - if (pBaseCS == m_pArray) { + if (pBaseCS == m_pArray) return false; - } + CPDF_DocPageData* pDocPageData = pDoc->GetPageData(); m_pBaseCS = pDocPageData->GetColorSpace(pBaseCS, nullptr); - if (m_pBaseCS) { - if (m_pBaseCS->GetFamily() == PDFCS_PATTERN) { - return false; - } - m_pCountedBaseCS = pDocPageData->FindColorSpacePtr(m_pBaseCS->GetArray()); - m_nComponents = m_pBaseCS->CountComponents() + 1; - if (m_pBaseCS->CountComponents() > MAX_PATTERN_COLORCOMPS) { - return false; - } - } else { + if (!m_pBaseCS) { m_nComponents = 1; + return true; } - return true; + + if (m_pBaseCS->GetFamily() == PDFCS_PATTERN) + return false; + + m_pCountedBaseCS = pDocPageData->FindColorSpacePtr(m_pBaseCS->GetArray()); + m_nComponents = m_pBaseCS->CountComponents() + 1; + return m_pBaseCS->CountComponents() <= MAX_PATTERN_COLORCOMPS; } -bool CPDF_PatternCS::GetRGB(float* pBuf, float& R, float& G, float& B) const { +bool CPDF_PatternCS::GetRGB(float* pBuf, float* R, float* G, float* B) const { if (m_pBaseCS) { ASSERT(m_pBaseCS->GetFamily() != PDFCS_PATTERN); PatternValue* pvalue = (PatternValue*)pBuf; - if (m_pBaseCS->GetRGB(pvalue->m_Comps, R, G, B)) { + if (m_pBaseCS->GetRGB(pvalue->m_Comps, R, G, B)) return true; - } } - R = G = B = 0.75f; + *R = 0.75f; + *G = 0.75f; + *B = 0.75f; return false; } @@ -1073,12 +1103,12 @@ CPDF_SeparationCS::CPDF_SeparationCS(CPDF_Document* pDoc) CPDF_SeparationCS::~CPDF_SeparationCS() {} void CPDF_SeparationCS::GetDefaultValue(int iComponent, - float& value, - float& min, - float& max) const { - value = 1.0f; - min = 0; - max = 1.0f; + float* value, + float* min, + float* max) const { + *value = 1.0f; + *min = 0; + *max = 1.0f; } bool CPDF_SeparationCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { @@ -1107,9 +1137,9 @@ bool CPDF_SeparationCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { } bool CPDF_SeparationCS::GetRGB(float* pBuf, - float& R, - float& G, - float& B) const { + float* R, + float* G, + float* B) const { if (m_Type == None) return false; @@ -1126,7 +1156,7 @@ bool CPDF_SeparationCS::GetRGB(float* pBuf, CFX_FixedBufGrow results(m_pFunc->CountOutputs()); int nresults = 0; - m_pFunc->Call(pBuf, 1, results, nresults); + m_pFunc->Call(pBuf, 1, results, &nresults); if (nresults == 0) return false; @@ -1151,12 +1181,12 @@ CPDF_DeviceNCS::CPDF_DeviceNCS(CPDF_Document* pDoc) CPDF_DeviceNCS::~CPDF_DeviceNCS() {} void CPDF_DeviceNCS::GetDefaultValue(int iComponent, - float& value, - float& min, - float& max) const { - value = 1.0f; - min = 0; - max = 1.0f; + float* value, + float* min, + float* max) const { + *value = 1.0f; + *min = 0; + *max = 1.0f; } bool CPDF_DeviceNCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { @@ -1177,13 +1207,13 @@ bool CPDF_DeviceNCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) { return m_pFunc->CountOutputs() >= m_pAltCS->CountComponents(); } -bool CPDF_DeviceNCS::GetRGB(float* pBuf, float& R, float& G, float& B) const { +bool CPDF_DeviceNCS::GetRGB(float* pBuf, float* R, float* G, float* B) const { if (!m_pFunc) return false; CFX_FixedBufGrow results(m_pFunc->CountOutputs()); int nresults = 0; - m_pFunc->Call(pBuf, m_nComponents, results, nresults); + m_pFunc->Call(pBuf, m_nComponents, results, &nresults); if (nresults == 0) return false; diff --git a/core/fpdfapi/page/cpdf_colorspace.h b/core/fpdfapi/page/cpdf_colorspace.h index e3c369e5ce..76072d1260 100644 --- a/core/fpdfapi/page/cpdf_colorspace.h +++ b/core/fpdfapi/page/cpdf_colorspace.h @@ -43,15 +43,15 @@ class CPDF_ColorSpace { uint32_t CountComponents() const; int GetFamily() const { return m_Family; } virtual void GetDefaultValue(int iComponent, - float& value, - float& min, - float& max) const; + float* value, + float* min, + float* max) const; bool sRGB() const; - virtual bool GetRGB(float* pBuf, float& R, float& G, float& B) const = 0; + virtual bool GetRGB(float* pBuf, float* R, float* G, float* B) const = 0; virtual bool SetRGB(float* pBuf, float R, float G, float B) const; - bool GetCMYK(float* pBuf, float& c, float& m, float& y, float& k) const; + bool GetCMYK(float* pBuf, float* c, float* m, float* y, float* k) const; bool SetCMYK(float* pBuf, float c, float m, float y, float k) const; virtual void TranslateImageLine(uint8_t* dest_buf, @@ -59,7 +59,7 @@ class CPDF_ColorSpace { int pixels, int image_width, int image_height, - bool bTransMask = false) const; + bool bTransMask) const; CPDF_Array*& GetArray() { return m_pArray; } virtual CPDF_ColorSpace* GetBaseCS() const; @@ -74,10 +74,10 @@ class CPDF_ColorSpace { virtual bool v_Load(CPDF_Document* pDoc, CPDF_Array* pArray); virtual bool v_GetCMYK(float* pBuf, - float& c, - float& m, - float& y, - float& k) const; + float* c, + float* m, + float* y, + float* k) const; virtual bool v_SetCMYK(float* pBuf, float c, float m, float y, float k) const; int m_Family; diff --git a/core/fpdfapi/page/cpdf_colorstate.cpp b/core/fpdfapi/page/cpdf_colorstate.cpp index 8ab182acc6..693fcf1a93 100644 --- a/core/fpdfapi/page/cpdf_colorstate.cpp +++ b/core/fpdfapi/page/cpdf_colorstate.cpp @@ -88,15 +88,17 @@ void CPDF_ColorState::SetFillPattern(CPDF_Pattern* pPattern, uint32_t nValues) { ColorData* pData = m_Ref.GetPrivateCopy(); pData->m_FillColor.SetValue(pPattern, pValue, nValues); - int R, G, B; - bool ret = pData->m_FillColor.GetRGB(R, G, B); + int R; + int G; + int B; + bool ret = pData->m_FillColor.GetRGB(&R, &G, &B); if (CPDF_TilingPattern* pTilingPattern = pPattern->AsTilingPattern()) { if (!ret && pTilingPattern->colored()) { pData->m_FillRGB = 0x00BFBFBF; return; } } - pData->m_FillRGB = ret ? FXSYS_RGB(R, G, B) : (uint32_t)-1; + pData->m_FillRGB = ret ? FXSYS_RGB(R, G, B) : 0xFFFFFFFF; } void CPDF_ColorState::SetStrokePattern(CPDF_Pattern* pPattern, @@ -104,8 +106,10 @@ void CPDF_ColorState::SetStrokePattern(CPDF_Pattern* pPattern, uint32_t nValues) { ColorData* pData = m_Ref.GetPrivateCopy(); pData->m_StrokeColor.SetValue(pPattern, pValue, nValues); - int R, G, B; - bool ret = pData->m_StrokeColor.GetRGB(R, G, B); + int R; + int G; + int B; + bool ret = pData->m_StrokeColor.GetRGB(&R, &G, &B); if (CPDF_TilingPattern* pTilingPattern = pPattern->AsTilingPattern()) { if (!ret && pTilingPattern->colored()) { pData->m_StrokeRGB = 0x00BFBFBF; @@ -113,7 +117,7 @@ void CPDF_ColorState::SetStrokePattern(CPDF_Pattern* pPattern, } } pData->m_StrokeRGB = - pData->m_StrokeColor.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (uint32_t)-1; + pData->m_StrokeColor.GetRGB(&R, &G, &B) ? FXSYS_RGB(R, G, B) : 0xFFFFFFFF; } void CPDF_ColorState::SetColor(CPDF_Color& color, @@ -133,7 +137,7 @@ void CPDF_ColorState::SetColor(CPDF_Color& color, int R; int G; int B; - rgb = color.GetRGB(R, G, B) ? FXSYS_RGB(R, G, B) : (uint32_t)-1; + rgb = color.GetRGB(&R, &G, &B) ? FXSYS_RGB(R, G, B) : 0xFFFFFFFF; } CPDF_ColorState::ColorData::ColorData() : m_FillRGB(0), m_StrokeRGB(0) {} diff --git a/core/fpdfapi/page/cpdf_devicecs_unittest.cpp b/core/fpdfapi/page/cpdf_devicecs_unittest.cpp index b1b30094aa..6edc8ff9f9 100644 --- a/core/fpdfapi/page/cpdf_devicecs_unittest.cpp +++ b/core/fpdfapi/page/cpdf_devicecs_unittest.cpp @@ -15,36 +15,36 @@ TEST(CPDF_DeviceCSTest, GetRGBFromGray) { // Test normal values. For gray, only first value from buf should be used. float buf[3] = {0.43f, 0.11f, 0.34f}; - ASSERT_TRUE(deviceGray.GetRGB(buf, R, G, B)); + ASSERT_TRUE(deviceGray.GetRGB(buf, &R, &G, &B)); EXPECT_EQ(0.43f, R); EXPECT_EQ(0.43f, G); EXPECT_EQ(0.43f, B); buf[0] = 0.872f; - ASSERT_TRUE(deviceGray.GetRGB(buf, R, G, B)); + ASSERT_TRUE(deviceGray.GetRGB(buf, &R, &G, &B)); EXPECT_EQ(0.872f, R); EXPECT_EQ(0.872f, G); EXPECT_EQ(0.872f, B); // Test boundary values buf[0] = {0.0f}; - ASSERT_TRUE(deviceGray.GetRGB(buf, R, G, B)); + ASSERT_TRUE(deviceGray.GetRGB(buf, &R, &G, &B)); EXPECT_EQ(0.0f, R); EXPECT_EQ(0.0f, G); EXPECT_EQ(0.0f, B); buf[0] = 1.0f; - ASSERT_TRUE(deviceGray.GetRGB(buf, R, G, B)); + ASSERT_TRUE(deviceGray.GetRGB(buf, &R, &G, &B)); EXPECT_EQ(1.0f, R); EXPECT_EQ(1.0f, G); EXPECT_EQ(1.0f, B); // Test out of range values buf[0] = -0.01f; - ASSERT_TRUE(deviceGray.GetRGB(buf, R, G, B)); + ASSERT_TRUE(deviceGray.GetRGB(buf, &R, &G, &B)); EXPECT_EQ(0.0f, R); EXPECT_EQ(0.0f, G); EXPECT_EQ(0.0f, B); buf[0] = 12.5f; - ASSERT_TRUE(deviceGray.GetRGB(buf, R, G, B)); + ASSERT_TRUE(deviceGray.GetRGB(buf, &R, &G, &B)); EXPECT_EQ(1.0f, R); EXPECT_EQ(1.0f, G); EXPECT_EQ(1.0f, B); @@ -58,14 +58,14 @@ TEST(CPDF_DeviceCSTest, GetRGBFromRGB) { // Test normal values float buf[3] = {0.13f, 1.0f, 0.652f}; - ASSERT_TRUE(deviceRGB.GetRGB(buf, R, G, B)); + ASSERT_TRUE(deviceRGB.GetRGB(buf, &R, &G, &B)); EXPECT_EQ(0.13f, R); EXPECT_EQ(1.0f, G); EXPECT_EQ(0.652f, B); buf[0] = 0.0f; buf[1] = 0.52f; buf[2] = 0.78f; - ASSERT_TRUE(deviceRGB.GetRGB(buf, R, G, B)); + ASSERT_TRUE(deviceRGB.GetRGB(buf, &R, &G, &B)); EXPECT_EQ(0.0f, R); EXPECT_EQ(0.52f, G); EXPECT_EQ(0.78f, B); @@ -73,7 +73,7 @@ TEST(CPDF_DeviceCSTest, GetRGBFromRGB) { // Test out of range values buf[0] = -10.5f; buf[1] = 100.0f; - ASSERT_TRUE(deviceRGB.GetRGB(buf, R, G, B)); + ASSERT_TRUE(deviceRGB.GetRGB(buf, &R, &G, &B)); EXPECT_EQ(0.0f, R); EXPECT_EQ(1.0f, G); EXPECT_EQ(0.78f, B); @@ -88,19 +88,19 @@ TEST(CPDF_DeviceCSTest, GetRGBFromCMYK) { float eps = 1e-6f; // Test normal values float buf[4] = {0.6f, 0.5f, 0.3f, 0.9f}; - ASSERT_TRUE(deviceCMYK.GetRGB(buf, R, G, B)); + ASSERT_TRUE(deviceCMYK.GetRGB(buf, &R, &G, &B)); EXPECT_TRUE(std::abs(0.0627451f - R) < eps); EXPECT_TRUE(std::abs(0.0627451f - G) < eps); EXPECT_TRUE(std::abs(0.105882f - B) < eps); buf[0] = 0.15f; buf[2] = 0.0f; - ASSERT_TRUE(deviceCMYK.GetRGB(buf, R, G, B)); + ASSERT_TRUE(deviceCMYK.GetRGB(buf, &R, &G, &B)); EXPECT_TRUE(std::abs(0.2f - R) < eps); EXPECT_TRUE(std::abs(0.0862745f - G) < eps); EXPECT_TRUE(std::abs(0.164706f - B) < eps); buf[2] = 1.0f; buf[3] = 0.0f; - ASSERT_TRUE(deviceCMYK.GetRGB(buf, R, G, B)); + ASSERT_TRUE(deviceCMYK.GetRGB(buf, &R, &G, &B)); EXPECT_TRUE(std::abs(0.850980f - R) < eps); EXPECT_TRUE(std::abs(0.552941f - G) < eps); EXPECT_TRUE(std::abs(0.156863f - B) < eps); @@ -108,7 +108,7 @@ TEST(CPDF_DeviceCSTest, GetRGBFromCMYK) { // Test out of range values buf[2] = 1.5f; buf[3] = -0.6f; - ASSERT_TRUE(deviceCMYK.GetRGB(buf, R, G, B)); + ASSERT_TRUE(deviceCMYK.GetRGB(buf, &R, &G, &B)); EXPECT_TRUE(std::abs(0.850980f - R) < eps); EXPECT_TRUE(std::abs(0.552941f - G) < eps); EXPECT_TRUE(std::abs(0.156863f - B) < eps); diff --git a/core/fpdfapi/page/cpdf_meshstream.cpp b/core/fpdfapi/page/cpdf_meshstream.cpp index 6450d14904..c0074f84cc 100644 --- a/core/fpdfapi/page/cpdf_meshstream.cpp +++ b/core/fpdfapi/page/cpdf_meshstream.cpp @@ -205,7 +205,7 @@ std::tuple CPDF_MeshStream::ReadColor() { float g; float b; if (m_funcs.empty()) { - m_pCS->GetRGB(color_value, r, g, b); + m_pCS->GetRGB(color_value, &r, &g, &b); return std::tuple(r, g, b); } @@ -214,10 +214,10 @@ std::tuple CPDF_MeshStream::ReadColor() { int nResults; for (const auto& func : m_funcs) { if (func && func->CountOutputs() <= kMaxComponents) - func->Call(color_value, 1, result, nResults); + func->Call(color_value, 1, result, &nResults); } - m_pCS->GetRGB(result, r, g, b); + m_pCS->GetRGB(result, &r, &g, &b); return std::tuple(r, g, b); } diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp index 978617ee8d..f3a04fb117 100644 --- a/core/fpdfapi/page/cpdf_streamparser.cpp +++ b/core/fpdfapi/page/cpdf_streamparser.cpp @@ -94,7 +94,7 @@ uint32_t PDF_DecodeInlineStream(const uint8_t* src_buf, return RunLengthDecode(src_buf, limit, dest_buf, dest_size); dest_size = 0; dest_buf = 0; - return (uint32_t)-1; + return 0xFFFFFFFF; } } // namespace diff --git a/core/fpdfapi/page/fpdf_page_colors.cpp b/core/fpdfapi/page/fpdf_page_colors.cpp index 8964a18cdb..061aae807a 100644 --- a/core/fpdfapi/page/fpdf_page_colors.cpp +++ b/core/fpdfapi/page/fpdf_page_colors.cpp @@ -73,49 +73,50 @@ CPDF_DeviceCS::CPDF_DeviceCS(CPDF_Document* pDoc, int family) family == PDFCS_DEVICECMYK); } -bool CPDF_DeviceCS::GetRGB(float* pBuf, float& R, float& G, float& B) const { +CPDF_DeviceCS::~CPDF_DeviceCS() {} + +bool CPDF_DeviceCS::GetRGB(float* pBuf, float* R, float* G, float* B) const { switch (m_Family) { case PDFCS_DEVICEGRAY: - R = NormalizeChannel(*pBuf); - G = R; - B = R; - break; + *R = NormalizeChannel(*pBuf); + *G = *R; + *B = *R; + return true; case PDFCS_DEVICERGB: - R = NormalizeChannel(pBuf[0]); - G = NormalizeChannel(pBuf[1]); - B = NormalizeChannel(pBuf[2]); - break; + *R = NormalizeChannel(pBuf[0]); + *G = NormalizeChannel(pBuf[1]); + *B = NormalizeChannel(pBuf[2]); + return true; case PDFCS_DEVICECMYK: if (m_dwStdConversion) { float k = pBuf[3]; - R = 1.0f - std::min(1.0f, pBuf[0] + k); - G = 1.0f - std::min(1.0f, pBuf[1] + k); - B = 1.0f - std::min(1.0f, pBuf[2] + k); + *R = 1.0f - std::min(1.0f, pBuf[0] + k); + *G = 1.0f - std::min(1.0f, pBuf[1] + k); + *B = 1.0f - std::min(1.0f, pBuf[2] + k); } else { AdobeCMYK_to_sRGB(NormalizeChannel(pBuf[0]), NormalizeChannel(pBuf[1]), NormalizeChannel(pBuf[2]), NormalizeChannel(pBuf[3]), - R, G, B); + *R, *G, *B); } - break; + return true; default: ASSERT(false); return false; } - return true; } bool CPDF_DeviceCS::v_GetCMYK(float* pBuf, - float& c, - float& m, - float& y, - float& k) const { + float* c, + float* m, + float* y, + float* k) const { if (m_Family != PDFCS_DEVICECMYK) return false; - c = pBuf[0]; - m = pBuf[1]; - y = pBuf[2]; - k = pBuf[3]; + *c = pBuf[0]; + *m = pBuf[1]; + *y = pBuf[2]; + *k = pBuf[3]; return true; } diff --git a/core/fpdfapi/page/fpdf_page_func.cpp b/core/fpdfapi/page/fpdf_page_func.cpp index 32142d89c3..94695daca2 100644 --- a/core/fpdfapi/page/fpdf_page_func.cpp +++ b/core/fpdfapi/page/fpdf_page_func.cpp @@ -717,7 +717,7 @@ bool CPDF_StitchFunc::v_Call(float* inputs, float* outputs) const { input = PDF_Interpolate(input, m_pBounds[i], m_pBounds[i + 1], m_pEncode[i * 2], m_pEncode[i * 2 + 1]); int nresults; - m_pSubFunctions[i]->Call(&input, kRequiredNumInputs, outputs, nresults); + m_pSubFunctions[i]->Call(&input, kRequiredNumInputs, outputs, &nresults); return true; } @@ -810,11 +810,11 @@ bool CPDF_Function::Init(CPDF_Object* pObj) { bool CPDF_Function::Call(float* inputs, uint32_t ninputs, float* results, - int& nresults) const { - if (m_nInputs != ninputs) { + int* nresults) const { + if (m_nInputs != ninputs) return false; - } - nresults = m_nOutputs; + + *nresults = m_nOutputs; for (uint32_t i = 0; i < m_nInputs; i++) { if (inputs[i] < m_pDomains[i * 2]) inputs[i] = m_pDomains[i * 2]; diff --git a/core/fpdfapi/page/pageint.h b/core/fpdfapi/page/pageint.h index 88e9c15ff2..0737c2ed6e 100644 --- a/core/fpdfapi/page/pageint.h +++ b/core/fpdfapi/page/pageint.h @@ -33,10 +33,11 @@ class CPDF_Function { static Type IntegerToFunctionType(int iType); virtual ~CPDF_Function(); + bool Call(float* inputs, uint32_t ninputs, float* results, - int& nresults) const; + int* nresults) const; uint32_t CountInputs() const { return m_nInputs; } uint32_t CountOutputs() const { return m_nOutputs; } float GetDomain(int i) const { return m_pDomains[i]; } @@ -148,14 +149,16 @@ class CPDF_IccProfile { class CPDF_DeviceCS : public CPDF_ColorSpace { public: CPDF_DeviceCS(CPDF_Document* pDoc, int family); + ~CPDF_DeviceCS() override; - bool GetRGB(float* pBuf, float& R, float& G, float& B) const override; + // CPDF_ColorSpace: + bool GetRGB(float* pBuf, float* R, float* G, float* B) const override; bool SetRGB(float* pBuf, float R, float G, float B) const override; bool v_GetCMYK(float* pBuf, - float& c, - float& m, - float& y, - float& k) const override; + float* c, + float* m, + float* y, + float* k) const override; bool v_SetCMYK(float* pBuf, float c, float m, @@ -166,15 +169,17 @@ class CPDF_DeviceCS : public CPDF_ColorSpace { int pixels, int image_width, int image_height, - bool bTransMask = false) const override; + bool bTransMask) const override; }; class CPDF_PatternCS : public CPDF_ColorSpace { public: explicit CPDF_PatternCS(CPDF_Document* pDoc); ~CPDF_PatternCS() override; + + // CPDF_ColorSpace: bool v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) override; - bool GetRGB(float* pBuf, float& R, float& G, float& B) const override; + bool GetRGB(float* pBuf, float* R, float* G, float* B) const override; CPDF_ColorSpace* GetBaseCS() const override; private: diff --git a/core/fpdfapi/parser/cpdf_security_handler.cpp b/core/fpdfapi/parser/cpdf_security_handler.cpp index 61834fca13..cfc51350d9 100644 --- a/core/fpdfapi/parser/cpdf_security_handler.cpp +++ b/core/fpdfapi/parser/cpdf_security_handler.cpp @@ -52,7 +52,7 @@ void CalcEncryptKey(CPDF_Dictionary* pEncrypt, } if (!bIgnoreMeta && revision >= 3 && !pEncrypt->GetIntegerFor("EncryptMetadata", 1)) { - uint32_t tag = (uint32_t)-1; + uint32_t tag = 0xFFFFFFFF; CRYPT_MD5Update(&md5, (uint8_t*)&tag, 4); } uint8_t digest[16]; diff --git a/core/fpdfapi/parser/fpdf_parser_decode.cpp b/core/fpdfapi/parser/fpdf_parser_decode.cpp index 98bb4eedf5..af1f452afd 100644 --- a/core/fpdfapi/parser/fpdf_parser_decode.cpp +++ b/core/fpdfapi/parser/fpdf_parser_decode.cpp @@ -101,9 +101,9 @@ uint32_t A85Decode(const uint8_t* src_buf, // Count the space needed to contain non-zero characters. The encoding ratio // of Ascii85 is 4:5. uint32_t space_for_non_zeroes = (pos - zcount) / 5 * 4 + 4; - if (zcount > (UINT_MAX - space_for_non_zeroes) / 4) { - return (uint32_t)-1; - } + if (zcount > (UINT_MAX - space_for_non_zeroes) / 4) + return 0xFFFFFFFF; + dest_buf = FX_Alloc(uint8_t, zcount * 4 + space_for_non_zeroes); size_t state = 0; uint32_t res = 0; @@ -315,7 +315,7 @@ uint32_t FPDFAPI_FlateOrLZWDecode(bool bLZW, BitsPerComponent = pParams->GetIntegerFor("BitsPerComponent", 8); Columns = pParams->GetIntegerFor("Columns", 1); if (!CheckFlateDecodeParams(Colors, BitsPerComponent, Columns)) - return (uint32_t)-1; + return 0xFFFFFFFF; } return CPDF_ModuleMgr::Get()->GetFlateModule()->FlateOrLZWDecode( bLZW, src_buf, src_size, bEarlyChange, predictor, Colors, @@ -358,7 +358,7 @@ bool PDF_DataDecode(const uint8_t* src_buf, CFX_ByteString decoder = DecoderArray[i].first; CPDF_Dictionary* pParam = ToDictionary(DecoderArray[i].second); uint8_t* new_buf = nullptr; - uint32_t new_size = (uint32_t)-1; + uint32_t new_size = 0xFFFFFFFF; int offset = -1; if (decoder == "FlateDecode" || decoder == "Fl") { if (bImageAcc && i == nSize - 1) { diff --git a/core/fpdfapi/render/cpdf_dibsource.cpp b/core/fpdfapi/render/cpdf_dibsource.cpp index 403866300d..341327b5e9 100644 --- a/core/fpdfapi/render/cpdf_dibsource.cpp +++ b/core/fpdfapi/render/cpdf_dibsource.cpp @@ -457,7 +457,7 @@ DIB_COMP_DATA* CPDF_DIBSource::GetDecodeAndMaskArray(bool& bDefaultDecode, float def_value; float def_min; float def_max; - m_pColorSpace->GetDefaultValue(i, def_value, def_min, def_max); + m_pColorSpace->GetDefaultValue(i, &def_value, &def_min, &def_max); if (m_Family == PDFCS_INDEXED) { def_max = max_data; } @@ -468,8 +468,8 @@ DIB_COMP_DATA* CPDF_DIBSource::GetDecodeAndMaskArray(bool& bDefaultDecode, } else { for (uint32_t i = 0; i < m_nComponents; i++) { float def_value; - m_pColorSpace->GetDefaultValue(i, def_value, pCompData[i].m_DecodeMin, - pCompData[i].m_DecodeStep); + m_pColorSpace->GetDefaultValue(i, &def_value, &pCompData[i].m_DecodeMin, + &pCompData[i].m_DecodeStep); if (m_Family == PDFCS_INDEXED) { pCompData[i].m_DecodeStep = max_data; } @@ -701,10 +701,10 @@ int CPDF_DIBSource::StratLoadMask() { m_pColorSpace->CountComponents() <= m_nComponents) { float R, G, B; std::vector colors(m_nComponents); - for (uint32_t i = 0; i < m_nComponents; i++) { + for (uint32_t i = 0; i < m_nComponents; i++) colors[i] = pMatte->GetFloatAt(i); - } - m_pColorSpace->GetRGB(colors.data(), R, G, B); + + m_pColorSpace->GetRGB(colors.data(), &R, &G, &B); m_MatteColor = FXARGB_MAKE(0, FXSYS_round(R * 255), FXSYS_round(G * 255), FXSYS_round(B * 255)); } @@ -779,13 +779,13 @@ void CPDF_DIBSource::LoadPalette() { color_values[0] = m_pCompData[0].m_DecodeMin; color_values[1] = color_values[2] = color_values[0]; float R = 0.0f, G = 0.0f, B = 0.0f; - m_pColorSpace->GetRGB(color_values, R, G, B); + m_pColorSpace->GetRGB(color_values, &R, &G, &B); FX_ARGB argb0 = ArgbEncode(255, FXSYS_round(R * 255), FXSYS_round(G * 255), FXSYS_round(B * 255)); color_values[0] += m_pCompData[0].m_DecodeStep; color_values[1] += m_pCompData[0].m_DecodeStep; color_values[2] += m_pCompData[0].m_DecodeStep; - m_pColorSpace->GetRGB(color_values, R, G, B); + m_pColorSpace->GetRGB(color_values, &R, &G, &B); FX_ARGB argb1 = ArgbEncode(255, FXSYS_round(R * 255), FXSYS_round(G * 255), FXSYS_round(B * 255)); if (argb0 != 0xFF000000 || argb1 != 0xFFFFFFFF) { @@ -816,9 +816,9 @@ void CPDF_DIBSource::LoadPalette() { for (int k = 0; k < nComponents; k++) { temp_buf[k] = *color_value; } - m_pColorSpace->GetRGB(temp_buf.data(), R, G, B); + m_pColorSpace->GetRGB(temp_buf.data(), &R, &G, &B); } else { - m_pColorSpace->GetRGB(color_value, R, G, B); + m_pColorSpace->GetRGB(color_value, &R, &G, &B); } SetPaletteArgb(i, ArgbEncode(255, FXSYS_round(R * 255), FXSYS_round(G * 255), FXSYS_round(B * 255))); @@ -935,7 +935,7 @@ void CPDF_DIBSource::TranslateScanline24bpp(uint8_t* dest_scan, G = (1.0f - color_values[1]) * k; B = (1.0f - color_values[2]) * k; } else { - m_pColorSpace->GetRGB(color_values, R, G, B); + m_pColorSpace->GetRGB(color_values, &R, &G, &B); } R = ClampValue(R, 1.0f); G = ClampValue(G, 1.0f); @@ -961,7 +961,7 @@ void CPDF_DIBSource::TranslateScanline24bpp(uint8_t* dest_scan, G = (1.0f - color_values[1]) * k; B = (1.0f - color_values[2]) * k; } else { - m_pColorSpace->GetRGB(color_values, R, G, B); + m_pColorSpace->GetRGB(color_values, &R, &G, &B); } R = ClampValue(R, 1.0f); G = ClampValue(G, 1.0f); @@ -1183,12 +1183,12 @@ void CPDF_DIBSource::DownSampleScanline1Bit(int orig_Bpp, bool bFlipX, int clip_left, int clip_width) const { - uint32_t set_argb = (uint32_t)-1; + uint32_t set_argb = 0xFFFFFFFF; uint32_t reset_argb = 0; if (m_bImageMask) { if (m_bDefaultDecode) { set_argb = 0; - reset_argb = (uint32_t)-1; + reset_argb = 0xFFFFFFFF; } } else if (m_bColorKey) { reset_argb = m_pPalette ? m_pPalette.get()[0] : 0xFF000000; diff --git a/core/fpdfapi/render/cpdf_docrenderdata.cpp b/core/fpdfapi/render/cpdf_docrenderdata.cpp index a6488c64d8..1c430e8f0f 100644 --- a/core/fpdfapi/render/cpdf_docrenderdata.cpp +++ b/core/fpdfapi/render/cpdf_docrenderdata.cpp @@ -117,7 +117,7 @@ CPDF_TransferFunc* CPDF_DocRenderData::GetTransferFunc(CPDF_Object* pObj) { input = (float)v / 255.0f; if (bUniTransfer) { if (pFuncs[0] && pFuncs[0]->CountOutputs() <= kMaxOutputs) - pFuncs[0]->Call(&input, 1, output, noutput); + pFuncs[0]->Call(&input, 1, output, &noutput); int o = FXSYS_round(output[0] * 255); if (o != v) bIdentity = false; @@ -130,7 +130,7 @@ CPDF_TransferFunc* CPDF_DocRenderData::GetTransferFunc(CPDF_Object* pObj) { pTransfer->m_Samples[i * 256 + v] = v; continue; } - pFuncs[i]->Call(&input, 1, output, noutput); + pFuncs[i]->Call(&input, 1, output, &noutput); int o = FXSYS_round(output[0] * 255); if (o != v) bIdentity = false; diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp index 28c7166013..17576fc1f3 100644 --- a/core/fpdfapi/render/cpdf_renderstatus.cpp +++ b/core/fpdfapi/render/cpdf_renderstatus.cpp @@ -145,12 +145,14 @@ void DrawAxialShading(CFX_DIBitmap* pBitmap, for (const auto& func : funcs) { if (func) { int nresults = 0; - if (func->Call(&input, 1, pResults + offset, nresults)) + if (func->Call(&input, 1, pResults + offset, &nresults)) offset += nresults; } } - float R = 0.0f, G = 0.0f, B = 0.0f; - pCS->GetRGB(pResults, R, G, B); + float R = 0.0f; + float G = 0.0f; + float B = 0.0f; + pCS->GetRGB(pResults, &R, &G, &B); rgb_array[i] = FXARGB_TODIB(FXARGB_MAKE(alpha, FXSYS_round(R * 255), FXSYS_round(G * 255), FXSYS_round(B * 255))); @@ -226,12 +228,14 @@ void DrawRadialShading(CFX_DIBitmap* pBitmap, for (const auto& func : funcs) { if (func) { int nresults; - if (func->Call(&input, 1, pResults + offset, nresults)) + if (func->Call(&input, 1, pResults + offset, &nresults)) offset += nresults; } } - float R = 0.0f, G = 0.0f, B = 0.0f; - pCS->GetRGB(pResults, R, G, B); + float R = 0.0f; + float G = 0.0f; + float B = 0.0f; + pCS->GetRGB(pResults, &R, &G, &B); rgb_array[i] = FXARGB_TODIB(FXARGB_MAKE(alpha, FXSYS_round(R * 255), FXSYS_round(G * 255), FXSYS_round(B * 255))); @@ -355,7 +359,7 @@ void DrawFuncShading(CFX_DIBitmap* pBitmap, for (const auto& func : funcs) { if (func) { int nresults; - if (func->Call(input, 2, pResults + offset, nresults)) + if (func->Call(input, 2, pResults + offset, &nresults)) offset += nresults; } } @@ -363,7 +367,7 @@ void DrawFuncShading(CFX_DIBitmap* pBitmap, float R = 0.0f; float G = 0.0f; float B = 0.0f; - pCS->GetRGB(pResults, R, G, B); + pCS->GetRGB(pResults, &R, &G, &B); dib_buf[column] = FXARGB_TODIB(FXARGB_MAKE( alpha, (int32_t)(R * 255), (int32_t)(G * 255), (int32_t)(B * 255))); } @@ -2041,8 +2045,10 @@ void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern, CFX_FixedBufGrow comps(pColorSpace->CountComponents()); for (uint32_t i = 0; i < pColorSpace->CountComponents(); i++) comps[i] = pBackColor->GetNumberAt(i); - float R = 0.0f, G = 0.0f, B = 0.0f; - pColorSpace->GetRGB(comps, R, G, B); + float R = 0.0f; + float G = 0.0f; + float B = 0.0f; + pColorSpace->GetRGB(comps, &R, &G, &B); background = ArgbEncode(255, (int32_t)(R * 255), (int32_t)(G * 255), (int32_t)(B * 255)); } @@ -2585,7 +2591,7 @@ std::unique_ptr CPDF_RenderStatus::LoadSMask( for (size_t i = 0; i < count; i++) { pFloats[i] = pBC->GetNumberAt(i); } - pCS->GetRGB(pFloats, R, G, B); + pCS->GetRGB(pFloats, &R, &G, &B); back_color = 0xff000000 | ((int32_t)(R * 255) << 16) | ((int32_t)(G * 255) << 8) | (int32_t)(B * 255); m_pContext->GetDocument()->GetPageData()->ReleaseColorSpace(pCSObj); @@ -2621,7 +2627,7 @@ std::unique_ptr CPDF_RenderStatus::LoadSMask( for (int i = 0; i < 256; i++) { float input = (float)i / 255.0f; int nresult; - pFunc->Call(&input, 1, results, nresult); + pFunc->Call(&input, 1, results, &nresult); transfers[i] = FXSYS_round(results[0] * 255); } } else { diff --git a/core/fxcodec/codec/ccodec_iccmodule.h b/core/fxcodec/codec/ccodec_iccmodule.h index c568a9b3c2..08878acc98 100644 --- a/core/fxcodec/codec/ccodec_iccmodule.h +++ b/core/fxcodec/codec/ccodec_iccmodule.h @@ -22,7 +22,7 @@ class CCodec_IccModule { int32_t intent = 0, uint32_t dwSrcFormat = Icc_FORMAT_DEFAULT); void DestroyTransform(void* pTransform); - void Translate(void* pTransform, float* pSrcValues, float* pDestValues); + void Translate(void* pTransform, const float* pSrcValues, float* pDestValues); void TranslateScanline(void* pTransform, uint8_t* pDest, const uint8_t* pSrc, diff --git a/core/fxcodec/codec/fx_codec_flate.cpp b/core/fxcodec/codec/fx_codec_flate.cpp index 2ba505d059..f908908062 100644 --- a/core/fxcodec/codec/fx_codec_flate.cpp +++ b/core/fxcodec/codec/fx_codec_flate.cpp @@ -161,7 +161,7 @@ int CLZWDecoder::Decode(uint8_t* dest_buf, m_pOutput = dest_buf; m_Early = bEarlyChange ? 1 : 0; m_nCodes = 0; - uint32_t old_code = (uint32_t)-1; + uint32_t old_code = 0xFFFFFFFF; uint8_t last_char = 0; while (1) { if (m_InPos + m_CodeLen > src_size * 8) { @@ -193,20 +193,19 @@ int CLZWDecoder::Decode(uint8_t* dest_buf, } m_OutPos++; last_char = (uint8_t)code; - if (old_code != (uint32_t)-1) { + if (old_code != 0xFFFFFFFF) AddCode(old_code, last_char); - } old_code = code; } else if (code == 256) { m_CodeLen = 9; m_nCodes = 0; - old_code = (uint32_t)-1; + old_code = 0xFFFFFFFF; } else if (code == 257) { break; } else { - if (old_code == (uint32_t)-1) { + if (old_code == 0xFFFFFFFF) return 2; - } + m_StackLen = 0; if (code >= m_nCodes + 258) { if (m_StackLen < sizeof(m_DecodeStack)) { @@ -824,7 +823,7 @@ uint32_t CCodec_FlateModule::FlateOrLZWDecode(bool bLZW, if (bLZW) { { std::unique_ptr decoder(new CLZWDecoder); - dest_size = (uint32_t)-1; + dest_size = 0xFFFFFFFF; offset = src_size; int err = decoder->Decode(nullptr, dest_size, src_buf, offset, bEarlyChange); diff --git a/core/fxcodec/codec/fx_codec_icc.cpp b/core/fxcodec/codec/fx_codec_icc.cpp index 4f701aaed3..b143dcc0c9 100644 --- a/core/fxcodec/codec/fx_codec_icc.cpp +++ b/core/fxcodec/codec/fx_codec_icc.cpp @@ -154,33 +154,32 @@ void IccLib_DestroyTransform(void* pTransform) { cmsDeleteTransform(((CLcmsCmm*)pTransform)->m_hTransform); delete (CLcmsCmm*)pTransform; } + void IccLib_Translate(void* pTransform, uint32_t nSrcComponents, - float* pSrcValues, + const float* pSrcValues, float* pDestValues) { - if (!pTransform) { + if (!pTransform) return; - } + CLcmsCmm* p = (CLcmsCmm*)pTransform; uint8_t output[4]; if (p->m_bLab) { CFX_FixedBufGrow inputs(nSrcComponents); double* input = inputs; - for (uint32_t i = 0; i < nSrcComponents; i++) { + for (uint32_t i = 0; i < nSrcComponents; i++) input[i] = pSrcValues[i]; - } cmsDoTransform(p->m_hTransform, input, output, 1); } else { CFX_FixedBufGrow inputs(nSrcComponents); uint8_t* input = inputs; for (uint32_t i = 0; i < nSrcComponents; i++) { - if (pSrcValues[i] > 1.0f) { + if (pSrcValues[i] > 1.0f) input[i] = 255; - } else if (pSrcValues[i] < 0) { + else if (pSrcValues[i] < 0) input[i] = 0; - } else { - input[i] = (int)(pSrcValues[i] * 255.0f); - } + else + input[i] = static_cast(pSrcValues[i] * 255.0f); } cmsDoTransform(p->m_hTransform, input, output, 1); } @@ -201,6 +200,7 @@ void IccLib_Translate(void* pTransform, break; } } + void IccLib_TranslateImage(void* pTransform, unsigned char* pDest, const unsigned char* pSrc, @@ -225,17 +225,20 @@ void* CCodec_IccModule::CreateTransform_sRGB(const uint8_t* pProfileData, void CCodec_IccModule::DestroyTransform(void* pTransform) { IccLib_DestroyTransform(pTransform); } + void CCodec_IccModule::Translate(void* pTransform, - float* pSrcValues, + const float* pSrcValues, float* pDestValues) { IccLib_Translate(pTransform, m_nComponents, pSrcValues, pDestValues); } + void CCodec_IccModule::TranslateScanline(void* pTransform, uint8_t* pDest, const uint8_t* pSrc, int32_t pixels) { IccLib_TranslateImage(pTransform, pDest, pSrc, pixels); } + const uint8_t g_CMYKSamples[81 * 81 * 3] = { 255, 255, 255, 225, 226, 228, 199, 200, 202, 173, 174, 178, 147, 149, 152, 123, 125, 128, 99, 99, 102, 69, 70, 71, 34, 30, 31, 255, 253, 229, @@ -1551,6 +1554,7 @@ const uint8_t g_CMYKSamples[81 * 81 * 3] = { 33, 28, 32, 22, 19, 23, 11, 6, 10, 1, 0, 0, 0, 0, 0, 0, 0, 0, }; + void AdobeCMYK_to_sRGB1(uint8_t c, uint8_t m, uint8_t y, diff --git a/core/fxcrt/fx_basic_gcc.cpp b/core/fxcrt/fx_basic_gcc.cpp index 4960dc8432..e041065b32 100644 --- a/core/fxcrt/fx_basic_gcc.cpp +++ b/core/fxcrt/fx_basic_gcc.cpp @@ -110,20 +110,23 @@ extern "C" { int FXSYS_GetACP() { return 0; } + uint32_t FXSYS_GetFullPathName(const char* filename, uint32_t buflen, char* buf, char** filepart) { int srclen = FXSYS_strlen(filename); - if (!buf || (int)buflen < srclen + 1) { + if (!buf || (int)buflen < srclen + 1) return srclen + 1; - } + FXSYS_strcpy(buf, filename); return srclen; } + uint32_t FXSYS_GetModuleFileName(void* hModule, char* buf, uint32_t bufsize) { - return (uint32_t)-1; + return 0xFFFFFFFF; } + #ifdef __cplusplus } #endif diff --git a/core/fxcrt/fx_xml_parser.cpp b/core/fxcrt/fx_xml_parser.cpp index 25024a1b2d..da4815bfd9 100644 --- a/core/fxcrt/fx_xml_parser.cpp +++ b/core/fxcrt/fx_xml_parser.cpp @@ -869,7 +869,7 @@ uint32_t CXML_Element::FindElement(CXML_Element* pChild) const { } ++index; } - return (uint32_t)-1; + return 0xFFFFFFFF; } bool CXML_AttrItem::Matches(const CFX_ByteString& space, diff --git a/xfa/fde/css/cfde_csssyntaxparser.cpp b/xfa/fde/css/cfde_csssyntaxparser.cpp index fada76b6b1..9c45422ebb 100644 --- a/xfa/fde/css/cfde_csssyntaxparser.cpp +++ b/xfa/fde/css/cfde_csssyntaxparser.cpp @@ -23,7 +23,7 @@ bool IsSelectorStart(wchar_t wch) { CFDE_CSSSyntaxParser::CFDE_CSSSyntaxParser() : m_iTextDataLen(0), - m_dwCheck((uint32_t)-1), + m_dwCheck(0xFFFFFFFF), m_eMode(FDE_CSSSyntaxMode::RuleSet), m_eStatus(FDE_CSSSyntaxStatus::None) {} @@ -47,7 +47,7 @@ void CFDE_CSSSyntaxParser::Reset(bool bOnlyDeclaration) { m_TextPlane.Reset(); m_TextData.Reset(); m_iTextDataLen = 0; - m_dwCheck = (uint32_t)-1; + m_dwCheck = 0xFFFFFFFF; m_eStatus = FDE_CSSSyntaxStatus::None; m_eMode = bOnlyDeclaration ? FDE_CSSSyntaxMode::PropertyName : FDE_CSSSyntaxMode::RuleSet; -- cgit v1.2.3