From 49370765189d67d4c65750d9bdff12bc369bcf8f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 3 Aug 2010 23:59:42 +0000 Subject: bugfix [#23173] Blender crashes on selecting display color corrected image in image editor notes, - Use our own callback which doesnt exit() blender. - Hard coded 'MONOSCNR.ICM' is bad, should this be a user preference or stored per image? - imb->crect was being set to imb->rect in some cases, disable this because its possible 'rect' gets reallocated and crect becomes freed memory. - when crect cant be created draw pink checkers, so users dont get confused if color correction isnt working. (previously would draw the uncorrected image, if it didnt crash) --- source/blender/blenkernel/intern/colortools.c | 61 ++++++++++++++++++--------- 1 file changed, 40 insertions(+), 21 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index 11801557c99..4b694ada7fb 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -782,34 +782,53 @@ void curvemapping_evaluate_premulRGBF(CurveMapping *cumap, float *vecout, const vecout[2]= curvemap_evaluateF(cumap->cm+2, fac); } + +#ifdef WITH_LCMS +/* basic error handler, if we dont do this blender will exit */ +static int ErrorReportingFunction(int ErrorCode, const char *ErrorText) +{ + fprintf(stderr, "%s:%d\n", ErrorText, ErrorCode); + return 1; +} +#endif + void colorcorrection_do_ibuf(ImBuf *ibuf, const char *profile) { +#ifdef WITH_LCMS if (ibuf->crect == NULL) { -#ifdef WITH_LCMS - cmsHPROFILE imageProfile, proofingProfile; - cmsHTRANSFORM hTransform; + cmsHPROFILE proofingProfile; - ibuf->crect = MEM_mallocN(ibuf->x*ibuf->y*sizeof(int), "imbuf crect"); - - imageProfile = cmsCreate_sRGBProfile(); - proofingProfile = cmsOpenProfileFromFile(profile, "r"); + /* TODO, move to initialization area of code */ + //cmsSetLogErrorHandler(ErrorReportingFunction); + cmsSetErrorHandler(ErrorReportingFunction); + /* will return NULL if the file isn't fount */ + proofingProfile = cmsOpenProfileFromFile(profile, "r"); + cmsErrorAction(LCMS_ERROR_SHOW); - - hTransform = cmsCreateProofingTransform(imageProfile, TYPE_RGBA_8, imageProfile, TYPE_RGBA_8, - proofingProfile, - INTENT_ABSOLUTE_COLORIMETRIC, - INTENT_ABSOLUTE_COLORIMETRIC, - cmsFLAGS_SOFTPROOFING); - - cmsDoTransform(hTransform, ibuf->rect, ibuf->crect, ibuf->x * ibuf->y); - - cmsDeleteTransform(hTransform); - cmsCloseProfile(imageProfile); - cmsCloseProfile(proofingProfile); -#else - ibuf->crect = ibuf->rect; + + if(proofingProfile) { + cmsHPROFILE imageProfile; + cmsHTRANSFORM hTransform; + + ibuf->crect = MEM_mallocN(ibuf->x*ibuf->y*sizeof(int), "imbuf crect"); + + imageProfile = cmsCreate_sRGBProfile(); + + + hTransform = cmsCreateProofingTransform(imageProfile, TYPE_RGBA_8, imageProfile, TYPE_RGBA_8, + proofingProfile, + INTENT_ABSOLUTE_COLORIMETRIC, + INTENT_ABSOLUTE_COLORIMETRIC, + cmsFLAGS_SOFTPROOFING); + + cmsDoTransform(hTransform, ibuf->rect, ibuf->crect, ibuf->x * ibuf->y); + + cmsDeleteTransform(hTransform); + cmsCloseProfile(imageProfile); + cmsCloseProfile(proofingProfile); + } #endif } } -- cgit v1.2.3