[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42407] branches/soc-2011-tomato/source/ blender/editors/interface/interface_draw.c: Use own bilinear interpolation function for preview widget sampling

Sergey Sharybin sergey.vfx at gmail.com
Sun Dec 4 17:07:55 CET 2011


Revision: 42407
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42407
Author:   nazgul
Date:     2011-12-04 16:07:50 +0000 (Sun, 04 Dec 2011)
Log Message:
-----------
Use own bilinear interpolation function for preview widget sampling

Solves issue with image clamping, but issue with dark edge is still present

Modified Paths:
--------------
    branches/soc-2011-tomato/source/blender/editors/interface/interface_draw.c

Modified: branches/soc-2011-tomato/source/blender/editors/interface/interface_draw.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/interface/interface_draw.c	2011-12-04 15:49:14 UTC (rev 42406)
+++ branches/soc-2011-tomato/source/blender/editors/interface/interface_draw.c	2011-12-04 16:07:50 UTC (rev 42407)
@@ -1471,12 +1471,27 @@
 	fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
 }
 
+static ImBuf *scale_trackpreview_ibuf(ImBuf *ibuf, float zoomx, float zoomy)
+{
+	ImBuf *scaleibuf;
+	int x, y, w= ibuf->x*zoomx, h= ibuf->y*zoomy;
+
+	scaleibuf= IMB_allocImBuf(w, h, 32, IB_rect);
+
+	for(y= 0; y<scaleibuf->y; y++) {
+		for (x= 0; x<scaleibuf->x; x++) {
+			bilinear_interpolation(ibuf, scaleibuf, ((float)x)/zoomx, ((float)y)/zoomy, x, y);
+		}
+	}
+
+	return scaleibuf;
+}
+
 void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti)
 {
 	rctf rect;
 	int ok= 0;
 	GLint scissor[4];
-	int preview_width, preview_height;
 	MovieClipScopes *scopes = (MovieClipScopes *)but->poin;
 
 	rect.xmin = (float)recti->xmin+1;
@@ -1484,20 +1499,12 @@
 	rect.ymin = (float)recti->ymin+SCOPE_RESIZE_PAD+2;
 	rect.ymax = (float)recti->ymax-1;
 
-	preview_width = rect.xmax - rect.xmin;
-	preview_height = rect.ymax - rect.ymin;
-
-	glPushAttrib(GL_ALL_ATTRIB_BITS);
-
 	glEnable(GL_BLEND);
 	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
 
 	/* need scissor test, preview image can draw outside of boundary */
 	glGetIntegerv(GL_VIEWPORT, scissor);
-	glScissor(ar->winrct.xmin + (rect.xmin-1),
-	          ar->winrct.ymin+(rect.ymin-1),
-	          (rect.xmax+1)-(rect.xmin-1),
-	          (rect.ymax+1)-(rect.ymin-1));
+	glScissor(ar->winrct.xmin + (rect.xmin-1), ar->winrct.ymin+(rect.ymin-1), (rect.xmax+1)-(rect.xmin-1), (rect.ymax+1)-(rect.ymin-1));
 
 	if(scopes->track_disabled) {
 		glColor4f(0.7f, 0.3f, 0.3f, 0.3f);
@@ -1507,66 +1514,30 @@
 		ok= 1;
 	}
 	else if(scopes->track_preview) {
-		int a;
+		int a, off_x, off_y;
+		float zoomx, zoomy;
 		ImBuf *drawibuf;
-		GLuint preview_texture;
-		float pattern_width, pattern_height;
 
-		pattern_width = scopes->track_preview->x;
-		pattern_height = scopes->track_preview->y;
-
 		glPushMatrix();
 
 		/* draw content of pattern area */
-		glScissor(ar->winrct.xmin + rect.xmin,
-		          ar->winrct.ymin + rect.ymin,
-		          scissor[2],
-		          scissor[3]);
+		glScissor(ar->winrct.xmin+rect.xmin, ar->winrct.ymin+rect.ymin, scissor[2], scissor[3]);
 
-		/* make a texture from the pattern */
-		/* TODO(keir): add a switch for bilinear filtering or not. */
-		glGenTextures(1, &preview_texture);
-		glBindTexture(GL_TEXTURE_2D, preview_texture);
-		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
-		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
-		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
-		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
-		             scopes->track_preview->x,
-		             scopes->track_preview->y,
-		             0, GL_RGBA, GL_UNSIGNED_BYTE,
-		             scopes->track_preview->rect);
-		glEnable(GL_TEXTURE_2D);
+		zoomx= (rect.xmax-rect.xmin) / (scopes->track_preview->x-2.0f);
+		zoomy= (rect.ymax-rect.ymin) / (scopes->track_preview->y-2.0f);
 
-		/* reposition so the preview area goes from -0.5 to 0.5 on x and y. */
-		glTranslatef((rect.xmin + rect.xmax) / 2.0f,
-		             (rect.ymin + rect.ymax) / 2.0f, 0.0f);
-		glScalef(preview_width, preview_height, 1.0f);
+		off_x= ((int)scopes->track_pos[0]-scopes->track_pos[0]-0.5f)*zoomx;
+		off_y= ((int)scopes->track_pos[1]-scopes->track_pos[1]-0.5f)*zoomy;
 
-		/* this matrix is reused below to draw the crosshair */
-		glPushMatrix();
+		drawibuf= scale_trackpreview_ibuf(scopes->track_preview, zoomx, zoomy);
+		glaDrawPixelsSafe(off_x+rect.xmin, off_y+rect.ymin, rect.xmax-rect.xmin+1.f-off_x, rect.ymax-rect.ymin+1.f-off_y, drawibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, drawibuf->rect);
 
-		/* make scale match the pattern and apply the subpixel marker translation. */
-		glScalef(1.0f / pattern_width,
-		         1.0f / pattern_width, 1.0f);
-		glTranslatef(-scopes->track_pos[0],
-		             -scopes->track_pos[1], 0.f);
-		glScalef(pattern_width, pattern_height, 1.0f);
+		IMB_freeImBuf(drawibuf);
 
-		/* draw the pattern over the preview area. */
-		glBegin(GL_QUADS);
-		glTexCoord2f(0.0f,0.0f); glVertex2f(0.0f, 0.0f);
-		glTexCoord2f(1.0f,0.0f); glVertex2f(1.0f, 0.0f);
-		glTexCoord2f(1.0f,1.0f); glVertex2f(1.0f, 1.0f);
-		glTexCoord2f(0.0f,1.0f); glVertex2f(0.0f, 1.0f);
-		glEnd();
+		/* draw cross for pizel position */
+		glTranslatef(off_x+rect.xmin+scopes->track_pos[0]*zoomx, off_y+rect.ymin+scopes->track_pos[1]*zoomy, 0.f);
+		glScissor(ar->winrct.xmin + rect.xmin, ar->winrct.ymin+rect.ymin, rect.xmax-rect.xmin, rect.ymax-rect.ymin);
 
-		glDeleteTextures(1, &preview_texture);
-		glPopMatrix();
-
-		/* draw the crosshair */
 		for(a= 0; a< 2; a++) {
 			if(a==1) {
 				glLineStipple(3, 0xaaaa);
@@ -1578,14 +1549,14 @@
 			}
 
 			glBegin(GL_LINES);
-				glVertex2f(-0.10f,  0.0f);
-				glVertex2f( 0.10f,  0.0f);
-				glVertex2f( 0.0f,  -0.10f);
-				glVertex2f( 0.0f,   0.10f);
+				glVertex2f(-10.0f, 0.0f);
+				glVertex2f(10.0f, 0.0f);
+				glVertex2f(0.0f, -10.0f);
+				glVertex2f(0.0f, 10.0f);
 			glEnd();
 		}
-		glDisable(GL_LINE_STIPPLE);
 
+		glDisable(GL_LINE_STIPPLE);
 		glPopMatrix();
 
 		ok= 1;
@@ -1600,7 +1571,7 @@
 	/* outline, scale gripper */
 	draw_scope_end(&rect, scissor);
 
-	glPopAttrib();
+	glDisable(GL_BLEND);
 }
 
 /* ****************************************************** */




More information about the Bf-blender-cvs mailing list