[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36844] branches/soc-2011-onion/source/ blender: GSOC-2011

Ryakiotakis Antonis kalast at gmail.com
Mon May 23 21:58:34 CEST 2011


Revision: 36844
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36844
Author:   psy-fi
Date:     2011-05-23 19:58:33 +0000 (Mon, 23 May 2011)
Log Message:
-----------
GSOC-2011

texture paint speed enhancements.

Correct bug with float texture painting and enable partial drawing to skip converting the whole float texture to char.

Modified Paths:
--------------
    branches/soc-2011-onion/source/blender/gpu/intern/gpu_draw.c
    branches/soc-2011-onion/source/blender/imbuf/IMB_imbuf.h
    branches/soc-2011-onion/source/blender/imbuf/intern/divers.c

Modified: branches/soc-2011-onion/source/blender/gpu/intern/gpu_draw.c
===================================================================
--- branches/soc-2011-onion/source/blender/gpu/intern/gpu_draw.c	2011-05-23 17:26:50 UTC (rev 36843)
+++ branches/soc-2011-onion/source/blender/gpu/intern/gpu_draw.c	2011-05-23 19:58:33 UTC (rev 36844)
@@ -687,9 +687,15 @@
 		glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skip_pixels);
 		glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skip_rows);
 
-		if ((ibuf->rect==NULL) && ibuf->rect_float)
-			IMB_rect_from_float(ibuf);
-
+		if (ibuf->rect_float){
+			if(ibuf->rect==NULL) {
+				IMB_rect_from_float(ibuf);
+			}
+            else {
+				IMB_partial_rect_from_float(ibuf, x, y, w, h);
+            }
+		}
+		
 		glBindTexture(GL_TEXTURE_2D, ima->bindcode);
 
 		glPixelStorei(GL_UNPACK_ROW_LENGTH, ibuf->x);

Modified: branches/soc-2011-onion/source/blender/imbuf/IMB_imbuf.h
===================================================================
--- branches/soc-2011-onion/source/blender/imbuf/IMB_imbuf.h	2011-05-23 17:26:50 UTC (rev 36843)
+++ branches/soc-2011-onion/source/blender/imbuf/IMB_imbuf.h	2011-05-23 19:58:33 UTC (rev 36844)
@@ -321,6 +321,7 @@
 void IMB_de_interlace(struct ImBuf *ibuf);
 void IMB_interlace(struct ImBuf *ibuf);
 void IMB_rect_from_float(struct ImBuf *ibuf);
+void IMB_partial_rect_from_float(struct ImBuf *ibuf, int x, int y, int w, int h);
 void IMB_float_from_rect(struct ImBuf *ibuf);
 void IMB_float_from_rect_simple(struct ImBuf *ibuf); /* no profile conversion */
 /* note, check that the conversion exists, only some are supported */

Modified: branches/soc-2011-onion/source/blender/imbuf/intern/divers.c
===================================================================
--- branches/soc-2011-onion/source/blender/imbuf/intern/divers.c	2011-05-23 17:26:50 UTC (rev 36843)
+++ branches/soc-2011-onion/source/blender/imbuf/intern/divers.c	2011-05-23 19:58:33 UTC (rev 36844)
@@ -197,6 +197,147 @@
 	ibuf->userflags &= ~IB_RECT_INVALID;
 }
 
+ 
+
+/* assume converting from linear float to sRGB byte for part of the texture*/
+void IMB_partial_rect_from_float(struct ImBuf *ibuf, int x, int y, int w, int h)
+{
+	/* quick method to convert floatbuf to byte */
+	float *tof, *init_tof = (float *)ibuf->rect_float;
+//	int do_dither = ibuf->dither != 0.f;
+	float dither= ibuf->dither / 255.0f;
+	float srgb[4];
+	int i, j, channels= ibuf->channels;
+	short profile= ibuf->profile;
+	unsigned char *to, *init_to = (unsigned char *) ibuf->rect;
+
+	/*
+		if called -only- from GPU_paint_update_image this test will never fail
+		but leaving it here for better or worse
+	*/
+	if(init_tof==NULL) return;
+	if(init_to==NULL) {
+		imb_addrectImBuf(ibuf);
+		init_to = (unsigned char *) ibuf->rect;
+	}
+	if(channels==1) {
+			for (j = 0; j < h; j++){
+				to = init_to + (ibuf->x*(y + j) + x)*4;
+				tof = init_tof + (ibuf->x*(y + j) + x)*4;
+				for(i = 0;  i < w; i++, to+=4, tof+=4) {
+					to[1]= to[2]= to[3]= to[0] = FTOCHAR(tof[0]);
+				}
+			}
+	}
+	else if (profile == IB_PROFILE_LINEAR_RGB) {
+		if(channels == 3) {
+			for (j = 0; j < h; j++){
+				to = init_to + (ibuf->x*(y + j) + x)*4;
+				tof = init_tof + (ibuf->x*(y + j) + x)*4;
+				for(i = 0;  i < w; i++, to+=4, tof+=4) {
+
+					srgb[0]= linearrgb_to_srgb(tof[0]);
+					srgb[1]= linearrgb_to_srgb(tof[1]);
+					srgb[2]= linearrgb_to_srgb(tof[2]);
+
+					to[0] = FTOCHAR(srgb[0]);
+					to[1] = FTOCHAR(srgb[1]);
+					to[2] = FTOCHAR(srgb[2]);
+					to[3] = 255;
+				}
+			}
+		}
+		else if (channels == 4) {
+			if (dither != 0.f) {
+				for (j = 0; j < h; j++){
+					to = init_to + (ibuf->x*(y + j) + x)*4;
+					tof = init_tof + (ibuf->x*(y + j) + x)*4;
+					for(i = 0;  i < w; i++, to+=4, tof+=4) {
+						const float d = (BLI_frand()-0.5f)*dither;
+
+						srgb[0]= d + linearrgb_to_srgb(tof[0]);
+						srgb[1]= d + linearrgb_to_srgb(tof[1]);
+						srgb[2]= d + linearrgb_to_srgb(tof[2]);
+						srgb[3]= d + tof[3];
+
+						to[0] = FTOCHAR(srgb[0]);
+						to[1] = FTOCHAR(srgb[1]);
+						to[2] = FTOCHAR(srgb[2]);
+						to[3] = FTOCHAR(srgb[3]);
+					}
+				}
+			} else {
+				for (j = 0; j < h; j++){
+					to = init_to + (ibuf->x*(y + j) + x)*4;
+					tof = init_tof + (ibuf->x*(y + j) + x)*4;
+					for(i = 0;  i < w; i++, to+=4, tof+=4) {
+						srgb[0]= linearrgb_to_srgb(tof[0]);
+						srgb[1]= linearrgb_to_srgb(tof[1]);
+						srgb[2]= linearrgb_to_srgb(tof[2]);
+						srgb[3]= tof[3];
+
+						to[0] = FTOCHAR(srgb[0]);
+						to[1] = FTOCHAR(srgb[1]);
+						to[2] = FTOCHAR(srgb[2]);
+						to[3] = FTOCHAR(srgb[3]);
+					}
+				}
+			}
+		}
+	}
+	else if(ELEM(profile, IB_PROFILE_NONE, IB_PROFILE_SRGB)) {
+		if(channels==3) {
+			for (j = 0; j < h; j++){
+				to = init_to + (ibuf->x*(y + j) + x)*4;
+				tof = init_tof + (ibuf->x*(y + j) + x)*4;
+				for(i = 0;  i < w; i++, to+=4, tof+=4) {
+					to[0] = FTOCHAR(tof[0]);
+					to[1] = FTOCHAR(tof[1]);
+					to[2] = FTOCHAR(tof[2]);
+					to[3] = 255;
+				}
+		}
+		}
+		else {
+			if (dither != 0.f) {
+				for (j = 0; j < h; j++){
+					to = init_to + (ibuf->x*(y + j) + x)*4;
+					tof = init_tof + (ibuf->x*(y + j) + x)*4;
+					for(i = 0;  i < w; i++, to+=4, tof+=4) {
+						const float d = (BLI_frand()-0.5f)*dither;
+						float col[4];
+
+						col[0]= d + tof[0];
+						col[1]= d + tof[1];
+						col[2]= d + tof[2];
+						col[3]= d + tof[3];
+
+						to[0] = FTOCHAR(col[0]);
+						to[1] = FTOCHAR(col[1]);
+						to[2] = FTOCHAR(col[2]);
+						to[3] = FTOCHAR(col[3]);
+					}
+				}
+			} else {
+				for (j = 0; j < h; j++){
+					to = init_to + (ibuf->x*(y + j) + x)*4;
+					tof = init_tof + (ibuf->x*(y + j) + x)*4;
+					for(i = 0;  i < w; i++, to+=4, tof+=4) {
+						to[0] = FTOCHAR(tof[0]);
+						to[1] = FTOCHAR(tof[1]);
+						to[2] = FTOCHAR(tof[2]);
+						to[3] = FTOCHAR(tof[3]);
+					}
+				}
+			}
+		}
+	}
+	/* ensure user flag is reset */
+	ibuf->userflags &= ~IB_RECT_INVALID;
+}
+
+
+
 static void imb_float_from_rect_nonlinear(struct ImBuf *ibuf, float *fbuf)
 {
 	float *tof = fbuf;




More information about the Bf-blender-cvs mailing list