Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2007-09-21 02:38:04 +0400
committerCampbell Barton <ideasman42@gmail.com>2007-09-21 02:38:04 +0400
commit9dcf337e93e02300e66739bb647031c94551a10d (patch)
tree9394007b5355c3f26c4c259ef9cc3a014013104d /source
parentd3a8bcc435f9bfb1ff0d12d0e3f588a1fa8d19e0 (diff)
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".
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_blender.h2
-rw-r--r--source/blender/blenloader/intern/readfile.c9
-rw-r--r--source/blender/include/BIF_editsima.h2
-rw-r--r--source/blender/makesdna/DNA_image_types.h3
-rw-r--r--source/blender/src/drawimage.c91
-rw-r--r--source/blender/src/editsima.c25
6 files changed, 93 insertions, 39 deletions
diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h
index 6bddd9de932..0a202dfadc3 100644
--- a/source/blender/blenkernel/BKE_blender.h
+++ b/source/blender/blenkernel/BKE_blender.h
@@ -44,7 +44,7 @@ struct ListBase;
struct MemFile;
#define BLENDER_VERSION 245
-#define BLENDER_SUBVERSION 1
+#define BLENDER_SUBVERSION 2
#define BLENDER_MINVERSION 240
#define BLENDER_MINSUBVERSION 0
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 6b4444e0311..444deba0e97 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6514,7 +6514,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
if(main->versionfile <= 244) {
Scene *sce;
- Material *ma;
bScreen *sc;
Object *ob;
Lamp *la;
@@ -6751,6 +6750,14 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
}
+ 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! */
diff --git a/source/blender/include/BIF_editsima.h b/source/blender/include/BIF_editsima.h
index 7192c20b3e4..1df3c85d53e 100644
--- a/source/blender/include/BIF_editsima.h
+++ b/source/blender/include/BIF_editsima.h
@@ -32,6 +32,7 @@
struct Mesh;
struct EditMesh;
+struct SpaceImage;
/* id can be from 0 to 3 */
#define TF_PIN_MASK(id) (TF_PIN1 << id)
@@ -80,6 +81,7 @@ void borderselect_sima(short whichuvs);
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);
diff --git a/source/blender/makesdna/DNA_image_types.h b/source/blender/makesdna/DNA_image_types.h
index 694279d4605..8a5a7ce4a4c 100644
--- a/source/blender/makesdna/DNA_image_types.h
+++ b/source/blender/makesdna/DNA_image_types.h
@@ -90,6 +90,9 @@ typedef struct Image {
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*/
diff --git a/source/blender/src/drawimage.c b/source/blender/src/drawimage.c
index 5387d0fca6e..dd55515abe0 100644
--- a/source/blender/src/drawimage.c
+++ b/source/blender/src/drawimage.c
@@ -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 @@ void calc_image_view(SpaceImage *sima, char mode)
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 @@ void uvco_to_areaco_noclip(float *vec, int *mval)
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 @@ void draw_tfaces(void)
}
}
}
- 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 @@ static unsigned int *get_part_from_ibuf(ImBuf *ibuf, short startx, short starty,
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 @@ static void draw_image_transform(ImBuf *ibuf)
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 @@ void image_editcursor_buts(uiBlock *block)
}
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 @@ static void image_panel_game_properties(short cntrl) // IMAGE_HANDLER_GAME_PROPE
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 @@ static void image_panel_view_properties(short cntrl) // IMAGE_HANDLER_VIEW_PROPE
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 @@ void drawimagespace(ScrArea *sa, void *spacedata)
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 @@ void drawimagespace(ScrArea *sa, void *spacedata)
}
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 @@ void drawimagespace(ScrArea *sa, void *spacedata)
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 @@ void drawimagespace(ScrArea *sa, void *spacedata)
glLoadIdentity();
}
else {
- xim= ibuf->x; yim= ibuf->y;
+ xim= ibuf->x * xuser_asp; yim= ibuf->y * yuser_asp;
}
/* calc location */
@@ -1757,7 +1767,7 @@ void drawimagespace(ScrArea *sa, void *spacedata)
}
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 @@ void drawimagespace(ScrArea *sa, void *spacedata)
else {
float x1_rep, y1_rep;
int x_rep, y_rep;
+ double time_current;
+ short loop_draw_ok = 0;
+
+ if (sima->flag & SI_DRAW_TILE) {
+ loop_draw_ok= 1;
+ }
+
+ time_current = PIL_check_seconds_timer();
- /* Loop for drawing repeating images */
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 @@ void drawimagespace(ScrArea *sa, void *spacedata)
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 @@ void drawimagespace(ScrArea *sa, void *spacedata)
if(show_viewer==0) {
draw_tfaces();
+ drawcursor_sima(xuser_asp, yuser_asp);
}
}
@@ -1932,7 +1955,7 @@ void drawimagespace(ScrArea *sa, void *spacedata)
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);
diff --git a/source/blender/src/editsima.c b/source/blender/src/editsima.c
index 8d17599dd86..d0e8f11b1c2 100644
--- a/source/blender/src/editsima.c
+++ b/source/blender/src/editsima.c
@@ -216,10 +216,13 @@ void be_square_tface_uv(EditMesh *em)
void transform_aspect_ratio_tface_uv(float *aspx, float *aspy)
{
int w, h;
-
+ float xuser_asp, yuser_asp;
+
+ aspect_sima(G.sima, &xuser_asp, &yuser_asp);
+
transform_width_height_tface_uv(&w, &h);
- *aspx= (float)w/256.0f;
- *aspy= (float)h/256.0f;
+ *aspx= (float)w/256.0f * xuser_asp;
+ *aspy= (float)h/256.0f * yuser_asp;
}
void transform_width_height_tface_uv(int *width, int *height)
@@ -1990,3 +1993,19 @@ void BIF_image_update_frame(void)
}
}
+void aspect_sima(SpaceImage *sima, float *x, float *y)
+{
+ *x = *y = 1.0;
+
+ if( (sima->image == 0) ||
+ (sima->image->type == IMA_TYPE_R_RESULT) ||
+ (sima->image->type == IMA_TYPE_COMPOSITE) ||
+ (sima->image->tpageflag & IMA_TILES) ||
+ (sima->image->aspx==0.0 || sima->image->aspy==0.0)
+ ) {
+ return;
+ }
+
+ /* x is always 1 */
+ *y = sima->image->aspy / sima->image->aspx;
+}