From b9ff5840a617ec836f2d09bb0f04d60e5c3b8f67 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 28 Dec 2011 13:29:33 +0000 Subject: Code refactoring: add unified image buffer functions for doing float => byte, byte => float, float => float, byte => byte conversions with profile, dither and predivide. Previously code for this was spread out too much. There should be no functional changes, this is so the predivide/table/dither patches can work correctly. --- source/blender/editors/render/render_internal.c | 57 ++++++------------------- source/blender/editors/render/render_opengl.c | 11 ++--- source/blender/editors/screen/glutil.c | 13 +++--- 3 files changed, 24 insertions(+), 57 deletions(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c index 8a580627da3..bff93fea067 100644 --- a/source/blender/editors/render/render_internal.c +++ b/source/blender/editors/render/render_internal.c @@ -76,10 +76,10 @@ /* called inside thread! */ void image_buffer_rect_update(Scene *scene, RenderResult *rr, ImBuf *ibuf, volatile rcti *renrect) { - float x1, y1, *rectf= NULL; + float *rectf= NULL; int ymin, ymax, xmin, xmax; - int rymin, rxmin, do_color_management; - char *rectc; + int rymin, rxmin, predivide, profile_from; + unsigned char *rectc; /* if renrect argument, we only refresh scanlines */ if(renrect) { @@ -136,50 +136,17 @@ void image_buffer_rect_update(Scene *scene, RenderResult *rr, ImBuf *ibuf, volat imb_addrectImBuf(ibuf); rectf+= 4*(rr->rectx*ymin + xmin); - rectc= (char *)(ibuf->rect + ibuf->x*rymin + rxmin); + rectc= (unsigned char*)(ibuf->rect + ibuf->x*rymin + rxmin); - do_color_management = (scene && (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT)); - - /* XXX make nice consistent functions for this */ - for(y1= 0; y1dither / 255.0f; - - /* XXX temp. because crop offset */ - if(rectc >= (char *)(ibuf->rect)) { - for(x1= 0; x1r.color_mgt_flag & R_COLOR_MANAGEMENT)) + profile_from= IB_PROFILE_LINEAR_RGB; + else + profile_from= IB_PROFILE_SRGB; + predivide= 0; - rectf += 4*rr->rectx; - rectc += 4*ibuf->x; - } + IMB_buffer_byte_from_float(rectc, rectf, + 4, ibuf->dither, IB_PROFILE_SRGB, profile_from, predivide, + xmax, ymax, ibuf->x, rr->rectx); } /* ****************************** render invoking ***************** */ diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c index 35b21c626ed..be4d54ae2e8 100644 --- a/source/blender/editors/render/render_opengl.c +++ b/source/blender/editors/render/render_opengl.c @@ -206,14 +206,11 @@ static void screen_opengl_render_apply(OGLRender *oglrender) * float buffer. */ if(oglrender->scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) { - float *rctf = rr->rectf; - int i; + int predivide= 0; /* no alpha */ - for (i = oglrender->sizex * oglrender->sizey; i > 0; i--, rctf+=4) { - rctf[0]= srgb_to_linearrgb(rctf[0]); - rctf[1]= srgb_to_linearrgb(rctf[1]); - rctf[2]= srgb_to_linearrgb(rctf[2]); - } + IMB_buffer_float_from_float(rr->rectf, rr->rectf, + 4, IB_PROFILE_LINEAR_RGB, IB_PROFILE_SRGB, predivide, + oglrender->sizex, oglrender->sizey, oglrender->sizex, oglrender->sizex); } RE_ReleaseResult(oglrender->re); diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index 0bba9838005..8f04940efd6 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -45,6 +45,9 @@ #include "BIF_gl.h" #include "BIF_glutil.h" +#include "IMB_imbuf.h" +#include "IMB_imbuf_types.h" + #ifndef GL_CLAMP_TO_EDGE #define GL_CLAMP_TO_EDGE 0x812F #endif @@ -563,17 +566,17 @@ void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, void * void glaDrawPixelsSafe_to32(float fx, float fy, int img_w, int img_h, int UNUSED(row_w), float *rectf, int do_gamma_correct) { unsigned char *rect32; + int profile_from= (do_gamma_correct)? IB_PROFILE_LINEAR_RGB: IB_PROFILE_SRGB; + int predivide= 0; /* copy imgw-imgh to a temporal 32 bits rect */ if(img_w<1 || img_h<1) return; rect32= MEM_mallocN(img_w*img_h*sizeof(int), "temp 32 bits"); - if (do_gamma_correct) { - floatbuf_to_srgb_byte(rectf, rect32, 0, img_w, 0, img_h, img_w); - } else { - floatbuf_to_byte(rectf, rect32, 0, img_w, 0, img_h, img_w); - } + IMB_buffer_byte_from_float(rect32, rectf, + 4, 0, IB_PROFILE_SRGB, profile_from, predivide, + img_w, img_h, img_w, img_w); glaDrawPixelsSafe(fx, fy, img_w, img_h, img_w, GL_RGBA, GL_UNSIGNED_BYTE, rect32); -- cgit v1.2.3