bugfix [#23173] Blender crashes on selecting display color corrected image in image...
authorCampbell Barton <ideasman42@gmail.com>
Tue, 3 Aug 2010 23:59:42 +0000 (23:59 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 3 Aug 2010 23:59:42 +0000 (23:59 +0000)
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
source/blender/editors/space_image/image_draw.c
source/blender/imbuf/intern/allocimbuf.c

index 11801557c99944a9e769176606a283bb84310903..4b694ada7fb7a904ad17173f7ec75b4080510e98 100644 (file)
@@ -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
        }
 }
index 28616f085559ba3a3898ef6fc5a0e8386e968450..187e21a8702fb09d88675495c120e95dbe8e45fe 100644 (file)
@@ -215,7 +215,7 @@ static void draw_image_grid(ARegion *ar, float zoomx, float zoomy)
        glEnd();
 }
 
-static void sima_draw_alpha_backdrop(float x1, float y1, float xsize, float ysize, float zoomx, float zoomy)
+static void sima_draw_alpha_backdrop(float x1, float y1, float xsize, float ysize, float zoomx, float zoomy, unsigned char col1[3], unsigned char col2[3])
 {
        GLubyte checker_stipple[32*32/8] =
        {
@@ -229,9 +229,9 @@ static void sima_draw_alpha_backdrop(float x1, float y1, float xsize, float ysiz
                0,0,255,255,0,0,255,255,0,0,255,255,0,0,255,255, \
        };
        
-       glColor3ub(100, 100, 100);
+       glColor3ubv(col1);
        glRectf(x1, y1, x1 + zoomx*xsize, y1 + zoomy*ysize);
-       glColor3ub(160, 160, 160);
+       glColor3ubv(col2);
 
        glEnable(GL_POLYGON_STIPPLE);
        glPolygonStipple(checker_stipple);
@@ -271,11 +271,16 @@ static void sima_draw_alpha_pixelsf(float x1, float y1, int rectx, int recty, fl
 }
 
 #ifdef WITH_LCMS
-static void sima_draw_colorcorrected_pixels(float x1, float y1, ImBuf *ibuf)
+static int sima_draw_colorcorrected_pixels(float x1, float y1, ImBuf *ibuf)
 {
        colorcorrection_do_ibuf(ibuf, "MONOSCNR.ICM"); /* path is hardcoded here, find some place better */
-       
-       glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->crect);
+
+       if(ibuf->crect) {
+               glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->crect);
+               return 1;
+       }
+
+       return 0;
 }
 #endif
 
@@ -361,13 +366,17 @@ static void draw_image_buffer(SpaceImage *sima, ARegion *ar, Scene *scene, Image
        else if(sima->flag & SI_COLOR_CORRECTION) {
                image_verify_buffer_float(sima, ima, ibuf, color_manage);
                
-               sima_draw_colorcorrected_pixels(x, y, ibuf);
+               if(sima_draw_colorcorrected_pixels(x, y, ibuf)==0) {
+                       unsigned char col1[3]= {100, 0, 100}, col2[3]= {160, 0, 160}; /* pink says 'warning' in blender land */
+                       sima_draw_alpha_backdrop(x, y, ibuf->x, ibuf->y, zoomx, zoomy, col1, col2);
+               }
 
        }
 #endif
        else {
                if(sima->flag & SI_USE_ALPHA) {
-                       sima_draw_alpha_backdrop(x, y, ibuf->x, ibuf->y, zoomx, zoomy);
+                       unsigned char col1[3]= {100, 100, 100}, col2[3]= {160, 160, 160};
+                       sima_draw_alpha_backdrop(x, y, ibuf->x, ibuf->y, zoomx, zoomy, col1, col2);
 
                        glEnable(GL_BLEND);
                        glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
index 606913dd5906f27b1e684bf3196e1dd1feaaad8d..8e00c7c7cf1a78c29c70141daaeaf77428904e91 100644 (file)
@@ -77,7 +77,7 @@ void imb_freerectImBuf(ImBuf *ibuf)
 {
        if(ibuf==NULL) return;
        
-       if(ibuf->crect && ibuf->crect != ibuf->rect)
+       if(ibuf->crect)
                MEM_freeN(ibuf->crect);
 
        if(ibuf->rect && (ibuf->mall & IB_rect))