📄 libmng_cms.c
字号:
{ sWhitepoint.x = (mng_float)pData->iGlobalWhitepointx / 100000; sWhitepoint.y = (mng_float)pData->iGlobalWhitepointy / 100000; sPrimaries.Red.x = (mng_float)pData->iGlobalPrimaryredx / 100000; sPrimaries.Red.y = (mng_float)pData->iGlobalPrimaryredy / 100000; sPrimaries.Green.x = (mng_float)pData->iGlobalPrimarygreenx / 100000; sPrimaries.Green.y = (mng_float)pData->iGlobalPrimarygreeny / 100000; sPrimaries.Blue.x = (mng_float)pData->iGlobalPrimarybluex / 100000; sPrimaries.Blue.y = (mng_float)pData->iGlobalPrimarybluey / 100000; } sWhitepoint.Y = /* Y component is always 1.0 */ sPrimaries.Red.Y = sPrimaries.Green.Y = sPrimaries.Blue.Y = 1.0; if (pBuf->bHasGAMA) /* get the gamma value */ dGamma = (mng_float)pBuf->iGamma / 100000; else dGamma = (mng_float)pData->iGlobalGamma / 100000;/* dGamma = pData->dViewgamma / (dGamma * pData->dDisplaygamma); ??? */ dGamma = pData->dViewgamma / dGamma; pGammatable [0] = /* and build the lookup tables */ pGammatable [1] = pGammatable [2] = cmsBuildGamma (256, dGamma);/* B001 start */ if (!pGammatable [0]) /* enough memory ? *//* B001 end */ MNG_ERRORL (pData, MNG_LCMS_NOMEM) /* create the profile */ hProf = cmsCreateRGBProfile (&sWhitepoint, &sPrimaries, pGammatable);/* B001 start */ cmsFreeGamma (pGammatable [0]); /* free the temporary gamma tables ? */ /* yes! but just the one! *//* B001 end */ pData->hProf1 = hProf; /* save for future use */ if (!hProf) /* handle error ? */ MNG_ERRORL (pData, MNG_LCMS_NOHANDLE) if (pData->bIsRGBA16) /* 16-bit intermediates ? */ hTrans = cmsCreateTransform (hProf, TYPE_RGBA_16_SE, pData->hProf2, TYPE_RGBA_16_SE, INTENT_PERCEPTUAL, MNG_CMS_FLAGS); else hTrans = cmsCreateTransform (hProf, TYPE_RGBA_8, pData->hProf2, TYPE_RGBA_8, INTENT_PERCEPTUAL, MNG_CMS_FLAGS); pData->hTrans = hTrans; /* save for future use */ if (!hTrans) /* handle error ? */ MNG_ERRORL (pData, MNG_LCMS_NOTRANS) /* load color-correction routine */ pData->fCorrectrow = (mng_fptr)correct_full_cms; return MNG_NOERROR; /* and done */ }#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_INIT_FULL_CMS, MNG_LC_END)#endif return init_gamma_only (pData); /* if we get here, we'll only do gamma */}#endif /* MNG_INCLUDE_LCMS *//* ************************************************************************** */#ifdef MNG_INCLUDE_LCMSmng_retcode init_full_cms_object (mng_datap pData){ mng_cmsprof hProf; mng_cmstrans hTrans; mng_imagedatap pBuf;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_INIT_FULL_CMS_OBJ, MNG_LC_START)#endif /* address the object-buffer */ pBuf = ((mng_imagep)pData->pRetrieveobj)->pImgbuf; if (pBuf->bHasICCP) { if (!pData->hProf2) /* output profile not defined ? */ { /* then assume sRGB !! */ pData->hProf2 = mnglcms_createsrgbprofile (); if (!pData->hProf2) /* handle error ? */ MNG_ERRORL (pData, MNG_LCMS_NOHANDLE) } /* generate a profile handle */ hProf = cmsOpenProfileFromMem (pBuf->pProfile, pBuf->iProfilesize); pData->hProf1 = hProf; /* save for future use */ if (!hProf) /* handle error ? */ MNG_ERRORL (pData, MNG_LCMS_NOHANDLE) if (pData->bIsRGBA16) /* 16-bit intermediates ? */ hTrans = cmsCreateTransform (hProf, TYPE_RGBA_16_SE, pData->hProf2, TYPE_RGBA_16_SE, INTENT_PERCEPTUAL, MNG_CMS_FLAGS); else hTrans = cmsCreateTransform (hProf, TYPE_RGBA_8, pData->hProf2, TYPE_RGBA_8, INTENT_PERCEPTUAL, MNG_CMS_FLAGS); pData->hTrans = hTrans; /* save for future use */ if (!hTrans) /* handle error ? */ MNG_ERRORL (pData, MNG_LCMS_NOTRANS) /* load color-correction routine */ pData->fCorrectrow = (mng_fptr)correct_full_cms; return MNG_NOERROR; /* and done */ } else if (pBuf->bHasSRGB) { if (pData->bIssRGB) /* sRGB system ? */ return MNG_NOERROR; /* no conversion required */ if (!pData->hProf3) /* sRGB profile not defined ? */ { /* then create it implicitly !! */ pData->hProf3 = mnglcms_createsrgbprofile (); if (!pData->hProf3) /* handle error ? */ MNG_ERRORL (pData, MNG_LCMS_NOHANDLE) } hProf = pData->hProf3; /* convert from sRGB profile */ if (pData->bIsRGBA16) /* 16-bit intermediates ? */ hTrans = cmsCreateTransform (hProf, TYPE_RGBA_16_SE, pData->hProf2, TYPE_RGBA_16_SE, pBuf->iRenderingintent, MNG_CMS_FLAGS); else hTrans = cmsCreateTransform (hProf, TYPE_RGBA_8, pData->hProf2, TYPE_RGBA_8, pBuf->iRenderingintent, MNG_CMS_FLAGS); pData->hTrans = hTrans; /* save for future use */ if (!hTrans) /* handle error ? */ MNG_ERRORL (pData, MNG_LCMS_NOTRANS) /* load color-correction routine */ pData->fCorrectrow = (mng_fptr)correct_full_cms; return MNG_NOERROR; /* and done */ } else if ((pBuf->bHasCHRM) && (pBuf->bHasGAMA) && (pBuf->iGamma > 0)) { mng_CIExyY sWhitepoint; mng_CIExyYTRIPLE sPrimaries; mng_gammatabp pGammatable[3]; mng_float dGamma; if (!pData->hProf2) /* output profile not defined ? */ { /* then assume sRGB !! */ pData->hProf2 = mnglcms_createsrgbprofile (); if (!pData->hProf2) /* handle error ? */ MNG_ERRORL (pData, MNG_LCMS_NOHANDLE) } sWhitepoint.x = (mng_float)pBuf->iWhitepointx / 100000; sWhitepoint.y = (mng_float)pBuf->iWhitepointy / 100000; sPrimaries.Red.x = (mng_float)pBuf->iPrimaryredx / 100000; sPrimaries.Red.y = (mng_float)pBuf->iPrimaryredy / 100000; sPrimaries.Green.x = (mng_float)pBuf->iPrimarygreenx / 100000; sPrimaries.Green.y = (mng_float)pBuf->iPrimarygreeny / 100000; sPrimaries.Blue.x = (mng_float)pBuf->iPrimarybluex / 100000; sPrimaries.Blue.y = (mng_float)pBuf->iPrimarybluey / 100000; sWhitepoint.Y = /* Y component is always 1.0 */ sPrimaries.Red.Y = sPrimaries.Green.Y = sPrimaries.Blue.Y = 1.0; dGamma = (mng_float)pBuf->iGamma / 100000;/* dGamma = pData->dViewgamma / (dGamma * pData->dDisplaygamma); ??? */ dGamma = pData->dViewgamma / dGamma; pGammatable [0] = /* and build the lookup tables */ pGammatable [1] = pGammatable [2] = cmsBuildGamma (256, dGamma);/* B001 start */ if (!pGammatable [0]) /* enough memory ? *//* B001 end */ MNG_ERRORL (pData, MNG_LCMS_NOMEM) /* create the profile */ hProf = cmsCreateRGBProfile (&sWhitepoint, &sPrimaries, pGammatable);/* B001 start */ cmsFreeGamma (pGammatable [0]); /* free the temporary gamma tables ? */ /* yes! but just the one! *//* B001 end */ pData->hProf1 = hProf; /* save for future use */ if (!hProf) /* handle error ? */ MNG_ERRORL (pData, MNG_LCMS_NOHANDLE) if (pData->bIsRGBA16) /* 16-bit intermediates ? */ hTrans = cmsCreateTransform (hProf, TYPE_RGBA_16_SE, pData->hProf2, TYPE_RGBA_16_SE, INTENT_PERCEPTUAL, MNG_CMS_FLAGS); else hTrans = cmsCreateTransform (hProf, TYPE_RGBA_8, pData->hProf2, TYPE_RGBA_8, INTENT_PERCEPTUAL, MNG_CMS_FLAGS); pData->hTrans = hTrans; /* save for future use */ if (!hTrans) /* handle error ? */ MNG_ERRORL (pData, MNG_LCMS_NOTRANS) /* load color-correction routine */ pData->fCorrectrow = (mng_fptr)correct_full_cms; return MNG_NOERROR; /* and done */ }#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_INIT_FULL_CMS_OBJ, MNG_LC_END)#endif /* if we get here, we'll only do gamma */ return init_gamma_only_object (pData);}#endif /* MNG_INCLUDE_LCMS *//* ************************************************************************** */#ifdef MNG_INCLUDE_LCMSmng_retcode correct_full_cms (mng_datap pData){#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_CORRECT_FULL_CMS, MNG_LC_START)#endif cmsDoTransform (pData->hTrans, pData->pRGBArow, pData->pRGBArow, pData->iRowsamples);#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_CORRECT_FULL_CMS, MNG_LC_END)#endif return MNG_NOERROR;}#endif /* MNG_INCLUDE_LCMS *//* ************************************************************************** */#if defined(MNG_GAMMA_ONLY) || defined(MNG_FULL_CMS)mng_retcode init_gamma_only (mng_datap pData){ mng_float dGamma; mng_imagep pImage = (mng_imagep)pData->pCurrentobj; mng_imagedatap pBuf;#ifdef MNG_SUPPORT_TRACE MNG_TRACE (pData, MNG_FN_INIT_GAMMA_ONLY, MNG_LC_START)#endif if (!pImage) /* no current object? then use object 0 */ pImage = (mng_imagep)pData->pObjzero; pBuf = pImage->pImgbuf; /* address the buffer */ if (pBuf->bHasSRGB) /* get the gamma value */ dGamma = 0.45455; else if (pBuf->bHasGAMA) dGamma = (mng_float)pBuf->iGamma / 100000; else if (pData->bHasglobalSRGB) dGamma = 0.45455; else if (pData->bHasglobalGAMA) dGamma = (mng_float)pData->iGlobalGamma / 100000; else dGamma = pData->dDfltimggamma; if (dGamma > 0) /* ignore gamma=0 */ { dGamma = pData->dViewgamma / (dGamma * pData->dDisplaygamma); if (dGamma != pData->dLastgamma) /* lookup table needs to be computed ? */ { mng_int32 iX; pData->aGammatab [0] = 0; for (iX = 1; iX <= 255; iX++) pData->aGammatab [iX] = (mng_uint8)(pow (iX / 255.0, dGamma) * 255 + 0.5); pData->dLastgamma = dGamma; /* keep for next time */ } /* load color-correction routine */ pData->fCorrectrow = (mng_fptr)correct_gamma_only; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -