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

Ryakiotakis Antonis kalast at gmail.com
Fri May 27 19:59:49 CEST 2011


Revision: 36953
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36953
Author:   psy-fi
Date:     2011-05-27 17:59:48 +0000 (Fri, 27 May 2011)
Log Message:
-----------
GSOC 2011 - onion branch

--Color correction fix series no.3--

After brief discussion on irc and ML
reverting changes to byte path.
For now color correct behavior will be used only
for float textures and only for brush colors, not brush texture images. 

also fixed loading for color corrected high-res float textures. Now results when painting between the two should be consistent.
There's still a speed issue, this time with the image editor. I have an idea about this though, coming in the next commit :).

brush texture images are considered to be in sRGB space, 
however they are not yet converted to linear rgb due to precision
considerations.This will be further tested until a decision is made.
GLSL mode may also show incorrect results(tests needed);

Also, it looks like non-sRGB images are not color corrected before
drawn on the GUI (for example noise textures)

coming soon, optimization for byte texture painting path + user preference for high res texture loading.

Modified Paths:
--------------
    branches/soc-2011-onion/source/blender/blenkernel/intern/brush.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_image.c
    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/blenkernel/intern/brush.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/intern/brush.c	2011-05-27 16:20:49 UTC (rev 36952)
+++ branches/soc-2011-onion/source/blender/blenkernel/intern/brush.c	2011-05-27 17:59:48 UTC (rev 36953)
@@ -571,9 +571,9 @@
 		}
 	}
 	else {
-		crgb[0]= FTOCHAR(srgb_to_linearrgb(brush->rgb[0]));
-		crgb[1]= FTOCHAR(srgb_to_linearrgb(brush->rgb[1]));
-		crgb[2]= FTOCHAR(srgb_to_linearrgb(brush->rgb[2]));
+		crgb[0]= brush->rgb[0];
+		crgb[1]= brush->rgb[1];
+		crgb[2]= brush->rgb[2];
 
 		for (y=0; y < ibuf->y; y++) {
 			dst = (char*)ibuf->rect + y*rowbytes;
@@ -601,9 +601,9 @@
 					dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
 
 					brush_sample_tex(brush, xy, rgba, 0);
-					dst[0] = FTOCHAR(rgba[0]*srgb_to_linearrgb(brush->rgb[0]));
-					dst[1] = FTOCHAR(rgba[1]*srgb_to_linearrgb(brush->rgb[1]));
-					dst[2] = FTOCHAR(rgba[2]*srgb_to_linearrgb(brush->rgb[2]));
+					dst[0] = FTOCHAR(rgba[0]*brush->rgb[0]);
+					dst[1] = FTOCHAR(rgba[1]*brush->rgb[1]);
+					dst[2] = FTOCHAR(rgba[2]*brush->rgb[2]);
 					dst[3] = FTOCHAR(rgba[3]*alpha*brush_curve_strength_clamp(brush, dist, radius));
 				} else {
 					dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);

Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_image.c	2011-05-27 16:20:49 UTC (rev 36952)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_image.c	2011-05-27 17:59:48 UTC (rev 36953)
@@ -3674,9 +3674,9 @@
 	
 	if (ps->is_texbrush) {
 		/*rgba already holds a texture result here from higher level function*/
-		rgba_ub[0] = FTOCHAR(rgba[0] * srgb_to_linearrgb(ps->brush->rgb[0]));
-		rgba_ub[1] = FTOCHAR(rgba[1] * srgb_to_linearrgb(ps->brush->rgb[1]));
-		rgba_ub[2] = FTOCHAR(rgba[2] * srgb_to_linearrgb(ps->brush->rgb[2]));
+		rgba_ub[0] = FTOCHAR(rgba[0] * ps->brush->rgb[0]);
+		rgba_ub[1] = FTOCHAR(rgba[1] * ps->brush->rgb[1]);
+		rgba_ub[2] = FTOCHAR(rgba[2] * ps->brush->rgb[2]);
 		rgba_ub[3] = FTOCHAR(rgba[3]);
 	}
 	else {

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-27 16:20:49 UTC (rev 36952)
+++ branches/soc-2011-onion/source/blender/gpu/intern/gpu_draw.c	2011-05-27 17:59:48 UTC (rev 36953)
@@ -409,12 +409,11 @@
 	int rectw, recth, tpx=0, tpy=0, y;
 	unsigned int *rectrow, *tilerectrow;
 	unsigned int *tilerect= NULL, *scalerect= NULL, *rect= NULL;
+	float *frect = NULL, *fscalerect = NULL;
 	short texwindx, texwindy, texwinsx, texwinsy;
-	/*OpenGL internal format, used to set float or high precision integer formats*/
-	unsigned int openGLinternalFormat = GL_RGBA; 
-	/*image format is blender's internal format*/
-	unsigned int imageFormat = GL_UNSIGNED_BYTE;
-
+	/*flag to determine whether high resolution format is used*/
+	int useHighPrecisionTex = FALSE;
+	
 	/* initialize tile mode and number of repeats */
 	GTS.ima = ima;
 	GTS.tilemode= (ima && (ima->tpageflag & (IMA_TILES|IMA_TWINANIM)));
@@ -464,14 +463,17 @@
 		return 0;
 
 	if (ibuf->rect_float){
-		/* ensure we have a char buffer too if high precision not suported by hardware*/
-		if(ibuf->rect==NULL){
+		/*replace with user preference when ready :)*/
+		if(1)
+		{
+			/*Use high precision textures. This is relatively harmless because OpenGL gives us
+			a high precision format only if it is available*/
+			useHighPrecisionTex = TRUE;
+		}
+		else if(ibuf->rect==NULL){
 			IMB_rect_from_float(ibuf);
 		}
-		/*Use high precision textures. This is relatively harmless because OpenGL gives us
-		a high precision format only if it is available*/
-		openGLinternalFormat = GL_RGBA16;
-		imageFormat = GL_FLOAT;
+
 	}
 		
 	/* currently, tpage refresh is used by ima sequences */
@@ -517,10 +519,18 @@
 			tpx= ibuf->x;
 			tpy= ibuf->y;
 			rect= ibuf->rect;
+			if(useHighPrecisionTex){
+				/*We also need a color corrected float image*/
+				frect = MEM_mallocN(ibuf->x*ibuf->y*sizeof(float)*4, "floar_buf_col_cor");
+				IMB_float_color_corrected_from_float_rect(ibuf, frect);
+			}
 		}
 	}
 
 	if(*bind != 0) {
+		if(frect)
+			MEM_freeN(frect);
+
 		/* enable opengl drawing with textures */
 		glBindTexture(GL_TEXTURE_2D, *bind);
 		return *bind;
@@ -549,9 +559,20 @@
 		rectw= smaller_pow2_limit(rectw);
 		recth= smaller_pow2_limit(recth);
 		
-		scalerect= MEM_mallocN(rectw*recth*sizeof(*scalerect), "scalerect");
-		gluScaleImage(GL_RGBA, tpx, tpy, imageFormat, rect, rectw, recth, imageFormat, scalerect);
-		rect= scalerect;
+		if(useHighPrecisionTex)
+		{
+			fscalerect= MEM_mallocN(rectw*recth*sizeof(float)*4, "fscalerect");
+			gluScaleImage(GL_RGBA, tpx, tpy, GL_FLOAT, frect, rectw, recth, GL_FLOAT, fscalerect);
+			MEM_freeN(frect);
+			frect = fscalerect;
+			fscalerect = NULL;
+		}
+		else
+		{
+			scalerect= MEM_mallocN(rectw*recth*sizeof(*scalerect), "scalerect");
+			gluScaleImage(GL_RGBA, tpx, tpy, GL_UNSIGNED_BYTE, rect, rectw, recth, GL_UNSIGNED_BYTE, scalerect);
+			rect= scalerect;
+		}
 	}
 
 	/* create image */
@@ -559,18 +580,18 @@
 	glBindTexture( GL_TEXTURE_2D, *bind);
 
 	if (!(gpu_get_mipmap() && mipmap)) {
-		if(imageFormat == GL_FLOAT)
-			glTexImage2D(GL_TEXTURE_2D, 0,  openGLinternalFormat,  rectw, recth, 0, GL_RGBA, imageFormat, ibuf->rect_float);			
+		if(useHighPrecisionTex)
+			glTexImage2D(GL_TEXTURE_2D, 0,  GL_RGBA16,  rectw, recth, 0, GL_RGBA, GL_FLOAT, frect);			
 		else
-			glTexImage2D(GL_TEXTURE_2D, 0,  openGLinternalFormat,  rectw, recth, 0, GL_RGBA, imageFormat, rect);
+			glTexImage2D(GL_TEXTURE_2D, 0,  GL_RGBA,  rectw, recth, 0, GL_RGBA, GL_UNSIGNED_BYTE, rect);
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
 	}
 	else {
-		if(imageFormat == GL_FLOAT)
-			gluBuild2DMipmaps(GL_TEXTURE_2D, openGLinternalFormat, rectw, recth, GL_RGBA, imageFormat, ibuf->rect_float);
+		if(useHighPrecisionTex)
+			gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA16, rectw, recth, GL_RGBA, GL_FLOAT, frect);
 		else
-			gluBuild2DMipmaps(GL_TEXTURE_2D, openGLinternalFormat, rectw, recth, GL_RGBA, imageFormat, rect);
+			gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, rectw, recth, GL_RGBA, GL_UNSIGNED_BYTE, rect);
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
 
@@ -585,7 +606,10 @@
 		MEM_freeN(tilerect);
 	if (scalerect)
 		MEM_freeN(scalerect);
-
+	if (fscalerect)
+		MEM_freeN(fscalerect);
+	if(frect)
+		MEM_freeN(frect);
 	return *bind;
 }
 
@@ -710,7 +734,7 @@
 			if(ibuf->rect==NULL) {
 				IMB_rect_from_float(ibuf);
 			}
-            else {
+			else {
             	/*Do partial drawing. 'buffer' holds only the changed part. 
             	This approach is better since:
             	a)we avoid sending the whole
@@ -727,7 +751,7 @@
 				if(ima->tpageflag & IMA_MIPMAP_COMPLETE)
 					ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
 				return;
-            }
+			}
 		}
 		
 		glBindTexture(GL_TEXTURE_2D, ima->bindcode);

Modified: branches/soc-2011-onion/source/blender/imbuf/IMB_imbuf.h
===================================================================
--- branches/soc-2011-onion/source/blender/imbuf/IMB_imbuf.h	2011-05-27 16:20:49 UTC (rev 36952)
+++ branches/soc-2011-onion/source/blender/imbuf/IMB_imbuf.h	2011-05-27 17:59:48 UTC (rev 36953)
@@ -323,9 +323,11 @@
 
 /*create char buffer, color corrected if necessary, for ImBufs that lack one*/ 
 void IMB_rect_from_float(struct ImBuf *ibuf);
-/*create char buffer for part of the image, color corrected if necessary, for ImBufs that lack one.
+/*create char buffer for part of the image, color corrected if necessary,
 Changed part will be stored in buffer. This is expected to bu used for texure painting updates*/ 
 void IMB_partial_rect_from_float(struct ImBuf *ibuf, float *buffer, int x, int y, int w, int h);
+/*Create a new float buffer containing color corrected colors from an Imbuf*/
+void IMB_float_color_corrected_from_float_rect(struct ImBuf *ibuf, float *buffer);
 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-27 16:20:49 UTC (rev 36952)
+++ branches/soc-2011-onion/source/blender/imbuf/intern/divers.c	2011-05-27 17:59:48 UTC (rev 36953)
@@ -235,8 +235,8 @@
 			for (j = 0; j < h; j++){
 				bufferIndex = buffer + w*j*4;
 				dstBytePxl = init_dstBytePxl + (ibuf->x*(y + j) + x)*4;
-				srcFloatPxl = init_srcFloatPxl + (ibuf->x*(y + j) + x)*4;
-				for(i = 0;  i < w; i++, dstBytePxl+=4, srcFloatPxl+=4, bufferIndex+=4) {
+				srcFloatPxl = init_srcFloatPxl + (ibuf->x*(y + j) + x);
+				for(i = 0;  i < w; i++, dstBytePxl+=4, srcFloatPxl++, bufferIndex+=4) {
 					dstBytePxl[1]= dstBytePxl[2]= dstBytePxl[3]= dstBytePxl[0] = FTOCHAR(srcFloatPxl[0]);
 					bufferIndex[0] = bufferIndex[1] = bufferIndex[2] = bufferIndex[3] = srcFloatPxl[0];
 				}
@@ -247,8 +247,8 @@
 			for (j = 0; j < h; j++){
 				bufferIndex = buffer + w*j*4;
 				dstBytePxl = init_dstBytePxl + (ibuf->x*(y + j) + x)*4;
-				srcFloatPxl = init_srcFloatPxl + (ibuf->x*(y + j) + x)*4;
-				for(i = 0;  i < w; i++, dstBytePxl+=4, srcFloatPxl+=4, bufferIndex += 4) {
+				srcFloatPxl = init_srcFloatPxl + (ibuf->x*(y + j) + x)*3;
+				for(i = 0;  i < w; i++, dstBytePxl+=4, srcFloatPxl+=3, bufferIndex += 4) {
 
 					bufferIndex[0]= linearrgb_to_srgb(srcFloatPxl[0]);
 					bufferIndex[1]= linearrgb_to_srgb(srcFloatPxl[1]);
@@ -307,16 +307,16 @@
 			for (j = 0; j < h; j++){
 				bufferIndex = buffer + w*j*4;
 				dstBytePxl = init_dstBytePxl + (ibuf->x*(y + j) + x)*4;
-				srcFloatPxl = init_srcFloatPxl + (ibuf->x*(y + j) + x)*4;
-				for(i = 0;  i < w; i++, dstBytePxl+=4, srcFloatPxl+=4, bufferIndex+=4) {
+				srcFloatPxl = init_srcFloatPxl + (ibuf->x*(y + j) + x)*3;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list