[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12097] trunk/blender/source/blender: image display option for viewing non square pixels (x/ y aspect for each image) - useful when editing UV coords with textures that have been resized to values that run fast in openGL (256/512/1024) but have lost their original aspect ratio, especially useful when rotating UV's.

Campbell Barton cbarton at metavr.com
Fri Sep 21 00:38:06 CEST 2007


Revision: 12097
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12097
Author:   campbellbarton
Date:     2007-09-21 00:38:04 +0200 (Fri, 21 Sep 2007)

Log Message:
-----------
image display option for viewing non square pixels (x/y aspect for each image) - useful when editing UV coords with textures that have been resized to values that run fast in openGL (256/512/1024) but have lost their original aspect ratio, especially useful when rotating UV's.
Bumped the subversion to 2, so the default aspect is set to 1:1.

Made "Repeat Image" option time image drawing and bail out early if its taking too long. (quater of a sec max) this could be avoided if the texture was drawn on a quad, but that wouldnt support other image draw options.
This is a good short term solution because it was possibly to lock up blender if you zoomed out a long way then enabled "Repeat Image".

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_blender.h
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/include/BIF_editsima.h
    trunk/blender/source/blender/makesdna/DNA_image_types.h
    trunk/blender/source/blender/src/drawimage.c
    trunk/blender/source/blender/src/editsima.c

Modified: trunk/blender/source/blender/blenkernel/BKE_blender.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_blender.h	2007-09-20 05:56:57 UTC (rev 12096)
+++ trunk/blender/source/blender/blenkernel/BKE_blender.h	2007-09-20 22:38:04 UTC (rev 12097)
@@ -44,7 +44,7 @@
 struct MemFile;
 
 #define BLENDER_VERSION			245
-#define BLENDER_SUBVERSION		1
+#define BLENDER_SUBVERSION		2
 
 #define BLENDER_MINVERSION		240
 #define BLENDER_MINSUBVERSION	0

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2007-09-20 05:56:57 UTC (rev 12096)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2007-09-20 22:38:04 UTC (rev 12097)
@@ -6751,6 +6751,14 @@
 		
 	}
 
+	if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 2)) {
+		Image *ima;	
+		/* initialize 1:1 Aspect */
+		for(ima= main->image.first; ima; ima= ima->id.next) {
+			ima->aspx = ima->aspy = 1.0f;				
+		}
+	}
+
 	/* WATCH IT!!!: pointers from libdata have not been converted yet here! */
 	/* WATCH IT 2!: Userdef struct init has to be in src/usiblender.c! */
 

Modified: trunk/blender/source/blender/include/BIF_editsima.h
===================================================================
--- trunk/blender/source/blender/include/BIF_editsima.h	2007-09-20 05:56:57 UTC (rev 12096)
+++ trunk/blender/source/blender/include/BIF_editsima.h	2007-09-20 22:38:04 UTC (rev 12097)
@@ -80,6 +80,7 @@
 void mouseco_to_curtile(void);
 void mouse_select_sima(void);
 void snap_menu_sima(void);
+void aspect_sima(struct SpaceImage *sima, float *x, float *y);
 
 void select_invert_tface_uv(void);
 void select_swap_tface_uv(void);

Modified: trunk/blender/source/blender/makesdna/DNA_image_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_image_types.h	2007-09-20 05:56:57 UTC (rev 12096)
+++ trunk/blender/source/blender/makesdna/DNA_image_types.h	2007-09-20 22:38:04 UTC (rev 12097)
@@ -90,6 +90,9 @@
 	
 	short gen_x, gen_y, gen_type;	/* for generated images */
 	
+	/* display aspect - for UV editing images resized for faster openGL display */
+	float aspx, aspy;
+	
 /*#ifdef WITH_VERSE*/
 	void *vnode;		/* pointer at verse bitmap node */
 /*#endif*/

Modified: trunk/blender/source/blender/src/drawimage.c
===================================================================
--- trunk/blender/source/blender/src/drawimage.c	2007-09-20 05:56:57 UTC (rev 12096)
+++ trunk/blender/source/blender/src/drawimage.c	2007-09-20 22:38:04 UTC (rev 12097)
@@ -108,6 +108,8 @@
 #include "RE_pipeline.h"
 #include "BMF_Api.h"
 
+#include "PIL_time.h"
+
 /* Modules used */
 #include "mydevice.h"
 #include "blendef.h"
@@ -190,10 +192,12 @@
 	if(image_preview_active(curarea, &xim, &yim));
 	else if(sima->image) {
 		ImBuf *ibuf= BKE_image_get_ibuf(sima->image, &sima->iuser);
+		float xuser_asp, yuser_asp;
 		
+		aspect_sima(sima, &xuser_asp, &yuser_asp);
 		if(ibuf) {
-			xim= ibuf->x;
-			yim= ibuf->y;
+			xim= ibuf->x * xuser_asp;
+			yim= ibuf->y * yuser_asp;
 		}
 		else if( sima->image->type==IMA_TYPE_R_RESULT ) {
 			/* not very important, just nice */
@@ -401,14 +405,14 @@
 	mval[1]= y;
 }
 
-static void drawcursor_sima(void)
+static void drawcursor_sima(float xuser_asp, float yuser_asp)
 {
 	int wi, hi;
 	float w, h;
 	
 	transform_width_height_tface_uv(&wi, &hi);
-	w = (((float)wi)/256.0f)*G.sima->zoom;
-	h = (((float)hi)/256.0f)*G.sima->zoom;
+	w = (((float)wi)/256.0f)*G.sima->zoom * xuser_asp;
+	h = (((float)hi)/256.0f)*G.sima->zoom * yuser_asp;
 	
 	cpack(0xFFFFFF);
 	glTranslatef(G.v2d->cursor[0], G.v2d->cursor[1], 0.0f);  
@@ -645,12 +649,7 @@
 			}
 		}
 	}
-	bglEnd();
-
-	
-	/* Draw the cursor here, this should be in its own function really but it relys on the previous calls to set the view matrix */
-	drawcursor_sima();
-	
+	bglEnd();	
 	glPointSize(1.0);
 }
 
@@ -676,7 +675,7 @@
 	return rectmain;
 }
 
-static void draw_image_transform(ImBuf *ibuf)
+static void draw_image_transform(ImBuf *ibuf, float xuser_asp, float yuser_asp)
 {
 	if(G.moving) {
 		float aspx, aspy, center[3];
@@ -687,10 +686,9 @@
 			aspx= aspy= 1.0;
 		}
 		else {
-			aspx= 256.0/ibuf->x;
-			aspy= 256.0/ibuf->y;
+			aspx= (256.0/ibuf->x) * xuser_asp;
+			aspy= (256.0/ibuf->y) * yuser_asp;
 		}
-
 		BIF_getPropCenter(center);
 
 		/* scale and translate the circle into place and draw it */
@@ -926,10 +924,9 @@
 		}
 		
 		uiBlockBeginAlign(block);
-		uiDefButF(block, NUM, B_CURSOR_IMAGE, "Cursor X:",	165, 40, 145, 19, &ocent[0], -10*imx, 10.0*imx, step, digits, "");
-		uiDefButF(block, NUM, B_CURSOR_IMAGE, "Cursor Y:",	165, 20, 145, 19, &ocent[1], -10*imy, 10.0*imy, step, digits, "");
+		uiDefButF(block, NUM, B_CURSOR_IMAGE, "Cursor X:",	165, 60, 145, 19, &ocent[0], -10*imx, 10.0*imx, step, digits, "");
+		uiDefButF(block, NUM, B_CURSOR_IMAGE, "Cursor Y:",	165, 40, 145, 19, &ocent[1], -10*imy, 10.0*imy, step, digits, "");
 		uiBlockEndAlign(block);
-	
 	}
 	else {	// apply event
 		if (G.sima->flag & SI_COORDFLOATS) {
@@ -1034,7 +1031,7 @@
 		uiBlockBeginAlign(block);
 		uiDefButBitS(block, TOG, IMA_CLAMP_U, B_SIMA3DVIEWDRAW, "ClampX",	160,100,70,19, &G.sima->image->tpageflag, 0, 0, 0, 0, "Disable texture repeating horizontaly");
 		uiDefButBitS(block, TOG, IMA_CLAMP_V, B_SIMA3DVIEWDRAW, "ClampY",	230,100,70,19, &G.sima->image->tpageflag, 0, 0, 0, 0, "Disable texture repeating vertically");
-		uiBlockEndAlign(block);		
+		uiBlockEndAlign(block);
 	}
 }
 
@@ -1064,9 +1061,18 @@
 	if(uiNewPanel(curarea, block, "View Properties", "Image", 10, 10, 318, 204)==0)
 		return;
 	
-	uiDefButBitI(block, TOG, SI_COORDFLOATS, B_REDR, "Normalized Coords",	10,100,140,19, &G.sima->flag, 0, 0, 0, 0, "Display coords from 0.0 to 1.0 rather then in pixels");
-	uiDefButBitI(block, TOG, SI_DRAW_TILE, B_REDR, "Repeat Image",	10,80,140,19, &G.sima->flag, 0, 0, 0, 0, "Repeat/Tile the image display");
 	
+	uiDefButBitI(block, TOG, SI_DRAW_TILE, B_REDR, "Repeat Image",	10,100,140,19, &G.sima->flag, 0, 0, 0, 0, "Repeat/Tile the image display");
+	uiDefButBitI(block, TOG, SI_COORDFLOATS, B_REDR, "Normalized Coords",	165,100,140,19, &G.sima->flag, 0, 0, 0, 0, "Display coords from 0.0 to 1.0 rather then in pixels");
+	
+	
+	if (G.sima->image) {
+		uiDefBut(block, LABEL, B_NOP, "Image Display...",		10,80,140,19, 0, 0, 0, 0, 0, "");
+		uiBlockBeginAlign(block);
+		uiDefButF(block, NUM, B_REDR, "AspX:", 10,60,140,19, &G.sima->image->aspx, 0.1, 5000.0, 100, 0, "X Display Aspect for this image, does not affect renderingm 0 disables.");
+		uiDefButF(block, NUM, B_REDR, "AspY:", 10,40,140,19, &G.sima->image->aspy, 0.1, 5000.0, 100, 0, "X Display Aspect for this image, does not affect rendering 0 disables.");
+		uiBlockEndAlign(block);
+	}
 	//image_editvertex_buts(block);
 	image_editcursor_buts(block);
 }
@@ -1680,7 +1686,7 @@
 	unsigned int *rect;
 	float x1, y1;
 	short sx, sy, dx, dy, show_render= 0, show_viewer= 0;
-	
+	float xuser_asp, yuser_asp;
 		/* If derived data is used then make sure that object
 		 * is up-to-date... might not be the case because updates
 		 * are normally done in drawview and could get here before
@@ -1704,6 +1710,8 @@
 	}
 	what_image(sima);
 	
+	aspect_sima(sima, &xuser_asp, &yuser_asp);
+	
 	if(sima->image) {
 		
 		/* UGLY hack? until now iusers worked fine... but for flipbook viewer we need this */
@@ -1720,8 +1728,10 @@
 	
 	if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL)) {
 		imagespace_grid(sima);
-		if(show_viewer==0)
+		if(show_viewer==0) {
 			draw_tfaces();
+			drawcursor_sima(xuser_asp, yuser_asp);
+		}
 	}
 	else {
 		float xim, yim, xoffs=0.0f, yoffs= 0.0f;
@@ -1736,7 +1746,7 @@
 			glLoadIdentity();
 		}
 		else {
-			xim= ibuf->x; yim= ibuf->y;
+			xim= ibuf->x * xuser_asp; yim= ibuf->y * yuser_asp;
 		}
 		
 		/* calc location */
@@ -1757,7 +1767,7 @@
 		}
 		else glaDefine2DArea(&sa->winrct);
 		
-		glPixelZoom((float)sima->zoom, (float)sima->zoom);
+		glPixelZoom(sima->zoom * xuser_asp, sima->zoom * yuser_asp);
 				
 		if(sima->flag & SI_EDITTILE) {
 			/* create char buffer from float if needed */
@@ -1822,15 +1832,23 @@
 			else {
 				float x1_rep, y1_rep;
 				int x_rep, y_rep;
+				double time_current;
+				short loop_draw_ok = 0;
 				
-				/* Loop for drawing repeating images */
+				if (sima->flag & SI_DRAW_TILE) {
+					loop_draw_ok= 1;
+				}
+				
+				time_current = PIL_check_seconds_timer();
+				
 				for (x_rep= ((int)G.v2d->cur.xmin)-1; x_rep < G.v2d->cur.xmax; x_rep++) {
-					x1_rep=x1+  (x_rep* ibuf->x * sima->zoom);
+					x1_rep=x1+  ((x_rep* ibuf->x * sima->zoom)  *xuser_asp);
 					for (y_rep= ((int)G.v2d->cur.ymin)-1; y_rep < G.v2d->cur.ymax; y_rep++) {
-						y1_rep=y1+  (y_rep * ibuf->y *sima->zoom);
+						y1_rep=y1+  ((y_rep * ibuf->y *sima->zoom)  *yuser_asp);
+				
 				/* end repeating image loop */
 						
-						if((sima->flag & SI_DRAW_TILE)==0) {
+						if(!loop_draw_ok) {
 							y1_rep = y1;
 							x1_rep = x1;
 						}
@@ -1883,15 +1901,19 @@
 							if(sima->flag & SI_USE_ALPHA)
 								glDisable(GL_BLEND);
 						}
-				
+						
 						/* only draw once */
-						if((sima->flag & SI_DRAW_TILE)==0) {
-							x_rep = G.v2d->cur.xmax+1;
-							y_rep = G.v2d->cur.ymax+1;
+						if(!loop_draw_ok) {
+							break; /* only draw once */
+						} else if ((PIL_check_seconds_timer() - time_current) > 0.25) {
+							loop_draw_ok = 0;
+							break;
 						}
 				
 				/* tile draw loop */
 					}
+					/* only draw once */
+					if(!loop_draw_ok) break;
 				}
 				/* tile draw loop */
 				
@@ -1924,6 +1946,7 @@
 			
 			if(show_viewer==0) { 
 				draw_tfaces();
+				drawcursor_sima(xuser_asp, yuser_asp);
 			}
 		}
 
@@ -1932,7 +1955,7 @@
 		calc_image_view(sima, 'f');	/* float */
 	}
 
-	draw_image_transform(ibuf);
+	draw_image_transform(ibuf, xuser_asp, yuser_asp);
 
 	mywinset(sa->win);	/* restore scissor after gla call... */
 	myortho2(-0.375, sa->winx-0.375, -0.375, sa->winy-0.375);

Modified: trunk/blender/source/blender/src/editsima.c
===================================================================
--- trunk/blender/source/blender/src/editsima.c	2007-09-20 05:56:57 UTC (rev 12096)
+++ trunk/blender/source/blender/src/editsima.c	2007-09-20 22:38:04 UTC (rev 12097)
@@ -216,10 +216,13 @@
 void transform_aspect_ratio_tface_uv(float *aspx, float *aspy)
 {
 	int w, h;
-

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list