summaryrefslogtreecommitdiff
path: root/core/src/fxcodec
diff options
context:
space:
mode:
authorBo Xu <bo_xu@foxitsoftware.com>2014-08-25 13:45:17 -0700
committerBo Xu <bo_xu@foxitsoftware.com>2014-08-25 13:45:17 -0700
commit1dfbe601cfd9e1b5edb14d18d6a76c7e6d44d45f (patch)
treeff37d23fe15138daa474b4d55d0297a38e2b806d /core/src/fxcodec
parent187483a29f08416583bacd772eb77172d8ad06f3 (diff)
downloadpdfium-1dfbe601cfd9e1b5edb14d18d6a76c7e6d44d45f.tar.xz
Use number of components from ICC profile and alternate color space
BUG=406806 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/503883002
Diffstat (limited to 'core/src/fxcodec')
-rw-r--r--core/src/fxcodec/codec/codec_int.h6
-rw-r--r--core/src/fxcodec/codec/fx_codec_icc.cpp53
2 files changed, 42 insertions, 17 deletions
diff --git a/core/src/fxcodec/codec/codec_int.h b/core/src/fxcodec/codec/codec_int.h
index 47f2c8e1fe..78672e62ee 100644
--- a/core/src/fxcodec/codec/codec_int.h
+++ b/core/src/fxcodec/codec/codec_int.h
@@ -162,10 +162,10 @@ public:
FX_DWORD dwPrfIntent = Icc_INTENT_ABSOLUTE_COLORIMETRIC,
FX_DWORD dwPrfFlag = Icc_FLAGS_SOFTPROOFING
);
- virtual FX_LPVOID CreateTransform_sRGB(FX_LPCBYTE pProfileData, unsigned int dwProfileSize, int nComponents, int intent = 0,
+ virtual FX_LPVOID CreateTransform_sRGB(FX_LPCBYTE pProfileData, FX_DWORD dwProfileSize, FX_INT32& nComponents, FX_INT32 intent = 0,
FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT);
- virtual FX_LPVOID CreateTransform_CMYK(FX_LPCBYTE pSrcProfileData, unsigned int dwSrcProfileSize, int nSrcComponents,
- FX_LPCBYTE pDstProfileData, unsigned int dwDstProfileSize, int intent = 0,
+ virtual FX_LPVOID CreateTransform_CMYK(FX_LPCBYTE pSrcProfileData, FX_DWORD dwSrcProfileSize, FX_INT32& nSrcComponents,
+ FX_LPCBYTE pDstProfileData, FX_DWORD dwDstProfileSize, FX_INT32 intent = 0,
FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT,
FX_DWORD dwDstFormat = Icc_FORMAT_DEFAULT
);
diff --git a/core/src/fxcodec/codec/fx_codec_icc.cpp b/core/src/fxcodec/codec/fx_codec_icc.cpp
index b10d9c4868..6bdc225adf 100644
--- a/core/src/fxcodec/codec/fx_codec_icc.cpp
+++ b/core/src/fxcodec/codec/fx_codec_icc.cpp
@@ -7,6 +7,12 @@
#include "../../../include/fxcodec/fx_codec.h"
#include "codec_int.h"
#include "../lcms2/include/fx_lcms2.h"
+const FX_DWORD N_COMPONENT_LAB = 3;
+const FX_DWORD N_COMPONENT_GRAY = 1;
+const FX_DWORD N_COMPONENT_RGB = 3;
+const FX_DWORD N_COMPONENT_CMYK = 4;
+const FX_DWORD N_COMPONENT_DEFAULT = 3;
+
FX_BOOL MD5ComputeID( FX_LPCVOID buf, FX_DWORD dwSize, FX_BYTE ID[16] )
{
return cmsMD5computeIDExt(buf, dwSize, ID);
@@ -59,14 +65,37 @@ FX_BOOL CheckComponents(cmsColorSpaceSignature cs, int nComponents, FX_BOOL bDst
}
return TRUE;
}
-void* IccLib_CreateTransform(const unsigned char* pSrcProfileData, unsigned int dwSrcProfileSize, int nSrcComponents,
- const unsigned char* pDstProfileData, unsigned int dwDstProfileSize, int nDstComponents,
+FX_INT32 GetCSComponents(cmsColorSpaceSignature cs)
+{
+ FX_DWORD components;
+ switch (cs) {
+ case cmsSigLabData:
+ components = N_COMPONENT_LAB;
+ break;
+ case cmsSigGrayData:
+ components = N_COMPONENT_GRAY;
+ break;
+ case cmsSigRgbData:
+ components = N_COMPONENT_RGB;
+ break;
+ case cmsSigCmykData:
+ components = N_COMPONENT_CMYK;
+ break;
+ default:
+ components = N_COMPONENT_DEFAULT;
+ break;
+ }
+ return components;
+}
+void* IccLib_CreateTransform(const unsigned char* pSrcProfileData, FX_DWORD dwSrcProfileSize, FX_INT32& nSrcComponents,
+ const unsigned char* pDstProfileData, FX_DWORD dwDstProfileSize, FX_INT32 nDstComponents,
int intent, FX_DWORD dwSrcFormat = Icc_FORMAT_DEFAULT, FX_DWORD dwDstFormat = Icc_FORMAT_DEFAULT)
{
cmsHPROFILE srcProfile = NULL;
cmsHPROFILE dstProfile = NULL;
cmsHTRANSFORM hTransform = NULL;
CLcmsCmm* pCmm = NULL;
+ nSrcComponents = 0;
srcProfile = cmsOpenProfileFromMem((void*)pSrcProfileData, dwSrcProfileSize);
if (srcProfile == NULL) {
return NULL;
@@ -83,11 +112,7 @@ void* IccLib_CreateTransform(const unsigned char* pSrcProfileData, unsigned int
int srcFormat;
FX_BOOL bLab = FALSE;
cmsColorSpaceSignature srcCS = cmsGetColorSpace(srcProfile);
- if (!CheckComponents(srcCS, nSrcComponents, FALSE)) {
- cmsCloseProfile(srcProfile);
- cmsCloseProfile(dstProfile);
- return NULL;
- }
+ nSrcComponents = GetCSComponents(srcCS);
if (srcCS == cmsSigLabData) {
srcFormat = COLORSPACE_SH(PT_Lab) | CHANNELS_SH(nSrcComponents) | BYTES_SH(0);
bLab = TRUE;
@@ -135,7 +160,7 @@ void* IccLib_CreateTransform(const unsigned char* pSrcProfileData, unsigned int
cmsCloseProfile(dstProfile);
return pCmm;
}
-void* IccLib_CreateTransform_sRGB(const unsigned char* pProfileData, unsigned int dwProfileSize, int nComponents, int intent, FX_DWORD dwSrcFormat)
+void* IccLib_CreateTransform_sRGB(const unsigned char* pProfileData, FX_DWORD dwProfileSize, FX_INT32& nComponents, FX_INT32 intent, FX_DWORD dwSrcFormat)
{
return IccLib_CreateTransform(pProfileData, dwProfileSize, nComponents, NULL, 0, 3, intent, dwSrcFormat);
}
@@ -192,7 +217,7 @@ void IccLib_Translate(void* pTransform, FX_DWORD nSrcComponents, FX_FLOAT* pSrcV
break;
}
}
-void IccLib_TranslateImage(void* pTransform, unsigned char* pDest, const unsigned char* pSrc, int pixels)
+void IccLib_TranslateImage(void* pTransform, unsigned char* pDest, const unsigned char* pSrc, FX_INT32 pixels)
{
cmsDoTransform(((CLcmsCmm*)pTransform)->m_hTransform, (void*)pSrc, pDest, pixels);
}
@@ -242,7 +267,7 @@ ICodec_IccModule::IccCS GetProfileCSFromHandle(FX_LPVOID pProfile)
return ICodec_IccModule::IccCS_Unknown;
}
}
-ICodec_IccModule::IccCS CCodec_IccModule::GetProfileCS(FX_LPCBYTE pProfileData, unsigned int dwProfileSize)
+ICodec_IccModule::IccCS CCodec_IccModule::GetProfileCS(FX_LPCBYTE pProfileData, FX_DWORD dwProfileSize)
{
ICodec_IccModule::IccCS cs;
cmsHPROFILE hProfile = cmsOpenProfileFromMem((void*)pProfileData, dwProfileSize);
@@ -517,12 +542,12 @@ CCodec_IccModule::~CCodec_IccModule()
}
}
}
-void* CCodec_IccModule::CreateTransform_sRGB(FX_LPCBYTE pProfileData, unsigned int dwProfileSize, int nComponents, int intent, FX_DWORD dwSrcFormat)
+void* CCodec_IccModule::CreateTransform_sRGB(FX_LPCBYTE pProfileData, FX_DWORD dwProfileSize, FX_INT32& nComponents, FX_INT32 intent, FX_DWORD dwSrcFormat)
{
return IccLib_CreateTransform_sRGB(pProfileData, dwProfileSize, nComponents, intent, dwSrcFormat);
}
-void* CCodec_IccModule::CreateTransform_CMYK(FX_LPCBYTE pSrcProfileData, unsigned int dwSrcProfileSize, int nSrcComponents,
- FX_LPCBYTE pDstProfileData, unsigned int dwDstProfileSize, int intent,
+void* CCodec_IccModule::CreateTransform_CMYK(FX_LPCBYTE pSrcProfileData, FX_DWORD dwSrcProfileSize, FX_INT32& nSrcComponents,
+ FX_LPCBYTE pDstProfileData, FX_DWORD dwDstProfileSize, FX_INT32 intent,
FX_DWORD dwSrcFormat , FX_DWORD dwDstFormat)
{
return IccLib_CreateTransform(pSrcProfileData, dwSrcProfileSize, nSrcComponents,
@@ -536,7 +561,7 @@ void CCodec_IccModule::Translate(void* pTransform, FX_FLOAT* pSrcValues, FX_FLOA
{
IccLib_Translate(pTransform, m_nComponents, pSrcValues, pDestValues);
}
-void CCodec_IccModule::TranslateScanline(void* pTransform, FX_LPBYTE pDest, FX_LPCBYTE pSrc, int pixels)
+void CCodec_IccModule::TranslateScanline(void* pTransform, FX_LPBYTE pDest, FX_LPCBYTE pSrc, FX_INT32 pixels)
{
IccLib_TranslateImage(pTransform, pDest, pSrc, pixels);
}