forked from bartvdbraak/blender
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)
This commit is contained in:
parent
a72047b197
commit
4937076518
@ -782,20 +782,40 @@ 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;
|
||||
cmsHPROFILE proofingProfile;
|
||||
|
||||
/* 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);
|
||||
|
||||
if(proofingProfile) {
|
||||
cmsHPROFILE imageProfile;
|
||||
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,
|
||||
@ -808,8 +828,7 @@ void colorcorrection_do_ibuf(ImBuf *ibuf, const char *profile)
|
||||
cmsDeleteTransform(hTransform);
|
||||
cmsCloseProfile(imageProfile);
|
||||
cmsCloseProfile(proofingProfile);
|
||||
#else
|
||||
ibuf->crect = ibuf->rect;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -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 */
|
||||
|
||||
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);
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user