diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-12-30 18:17:11 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-12-30 18:17:11 +0400 |
commit | d7d856a23de2b6751a46632130f941a71377d134 (patch) | |
tree | 67662eadc78a4145eba4f0a9e04655cb1adb9edb /source/blender/editors/render | |
parent | 424e09a2cec805aa67824385c16a1d267fb1022b (diff) |
Color management: add "Color Unpremultiply" option for images and render settings.
For premultiplied alpha images, this makes any color space conversion for the image
or render output work on color without alpha multiplied in.
This is typically useful to avoid fringing when the image was or will be composited
over a light background. If the image will be composited over a black background on
the other hand, leaving this option off will give correct results.
In an ideal world, there should never be any color space conversion on images with
alpha, since it's undefined what to do then, but in practice it's useful to have
this option.
Patch by Troy Sobotka, with changes by me.
Diffstat (limited to 'source/blender/editors/render')
-rw-r--r-- | source/blender/editors/render/render_internal.c | 9 | ||||
-rw-r--r-- | source/blender/editors/render/render_preview.c | 27 |
2 files changed, 30 insertions, 6 deletions
diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c index bff93fea067..e4597d6afc3 100644 --- a/source/blender/editors/render/render_internal.c +++ b/source/blender/editors/render/render_internal.c @@ -138,11 +138,14 @@ void image_buffer_rect_update(Scene *scene, RenderResult *rr, ImBuf *ibuf, volat rectf+= 4*(rr->rectx*ymin + xmin); rectc= (unsigned char*)(ibuf->rect + ibuf->x*rymin + rxmin); - if(scene && (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT)) + if(scene && (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT)) { profile_from= IB_PROFILE_LINEAR_RGB; - else + predivide= (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT_PREDIVIDE); + } + else { profile_from= IB_PROFILE_SRGB; - predivide= 0; + predivide= 0; + } IMB_buffer_byte_from_float(rectc, rectf, 4, ibuf->dither, IB_PROFILE_SRGB, profile_from, predivide, diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index feff1e05d60..86328ca2a64 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -460,12 +460,15 @@ static int ed_preview_draw_rect(ScrArea *sa, Scene *sce, ID *id, int split, int Render *re; RenderResult rres; char name[32]; - int do_gamma_correct=0; + int do_gamma_correct=0, do_predivide=0; int offx=0, newx= rect->xmax-rect->xmin, newy= rect->ymax-rect->ymin; if (id && GS(id->name) != ID_TE) { /* exception: don't color manage texture previews - show the raw values */ - if (sce) do_gamma_correct = sce->r.color_mgt_flag & R_COLOR_MANAGEMENT; + if (sce) { + do_gamma_correct = sce->r.color_mgt_flag & R_COLOR_MANAGEMENT; + do_predivide = sce->r.color_mgt_flag & R_COLOR_MANAGEMENT_PREDIVIDE; + } } if(!split || first) sprintf(name, "Preview %p", (void *)sa); @@ -488,10 +491,28 @@ static int ed_preview_draw_rect(ScrArea *sa, Scene *sce, ID *id, int split, int if(rres.rectf) { if(ABS(rres.rectx-newx)<2 && ABS(rres.recty-newy)<2) { + newrect->xmax= MAX2(newrect->xmax, rect->xmin + rres.rectx + offx); newrect->ymax= MAX2(newrect->ymax, rect->ymin + rres.recty); - glaDrawPixelsSafe_to32(rect->xmin+offx, rect->ymin, rres.rectx, rres.recty, rres.rectx, rres.rectf, do_gamma_correct); + if(rres.rectx && rres.recty) { + /* temporary conversion to byte for drawing */ + float fx= rect->xmin + offx; + float fy= rect->ymin; + int profile_from= (do_gamma_correct)? IB_PROFILE_LINEAR_RGB: IB_PROFILE_SRGB; + int dither= 0; + unsigned char *rect_byte; + + rect_byte= MEM_mallocN(rres.rectx*rres.recty*sizeof(int), "ed_preview_draw_rect"); + + IMB_buffer_byte_from_float(rect_byte, rres.rectf, + 4, dither, IB_PROFILE_SRGB, profile_from, do_predivide, + rres.rectx, rres.recty, rres.rectx, rres.rectx); + + glaDrawPixelsSafe(fx, fy, rres.rectx, rres.recty, rres.rectx, GL_RGBA, GL_UNSIGNED_BYTE, rect_byte); + + MEM_freeN(rect_byte); + } RE_ReleaseResultImage(re); return 1; |