Color proofing support with lcms (http://www.littlecms.com/).
[blender.git] / source / blender / blenkernel / intern / colortools.c
index 1bc34aea9a135896dab31ad276db682ba8a10372..e8716aba296fb3b47f51cfeacb68d57f27678336 100644 (file)
 #include <stdlib.h>
 #include <float.h>
 
+#ifdef WITH_LCMS
+#include <lcms.h>
+#endif
+
 #include "MEM_guardedalloc.h"
 
 #include "DNA_color_types.h"
@@ -650,6 +654,38 @@ void curvemapping_evaluate_premulRGBF(CurveMapping *cumap, float *vecout, const
        vecout[2]= curvemap_evaluateF(cumap->cm+2, fac);
 }
 
+void colorcorrection_do_ibuf(ImBuf *ibuf, const char *profile)
+{
+       if (ibuf->crect == NULL)
+       {
+#ifdef WITH_LCMS
+               cmsHPROFILE imageProfile, proofingProfile;
+               cmsHTRANSFORM hTransform;
+               
+               ibuf->crect = MEM_mallocN(ibuf->x*ibuf->y*sizeof(int), "imbuf crect");
+
+               imageProfile  = cmsCreate_sRGBProfile();
+               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;
+#endif
+       }
+}
+
 
 void curvemapping_do_ibuf(CurveMapping *cumap, ImBuf *ibuf)
 {