diff --git a/source/blender/blenlib/BLI_arithb.h b/source/blender/blenlib/BLI_arithb.h index 5b4e380f88e..9ed23bc32b6 100644 --- a/source/blender/blenlib/BLI_arithb.h +++ b/source/blender/blenlib/BLI_arithb.h @@ -96,7 +96,7 @@ float CalcNormFloat4(float *v1, float *v2, float *v3, float *v4, float *n); void CalcNormLong(int *v1, int *v2, int *v3, float *n); /* CalcNormShort: is ook uitprodukt - (translates as 'is also out/cross product') */ void CalcNormShort(short *v1, short *v2, short *v3, float *n); - +float power_of_2(float val); /** * @section Euler conversion routines diff --git a/source/blender/blenlib/intern/arithb.c b/source/blender/blenlib/intern/arithb.c index 19a8d4f5152..48a149f4b3a 100644 --- a/source/blender/blenlib/intern/arithb.c +++ b/source/blender/blenlib/intern/arithb.c @@ -4345,3 +4345,8 @@ void tangent_from_uv(float *uv1, float *uv2, float *uv3, float *co1, float *co2, if ((ct[0]*n[0] + ct[1]*n[1] + ct[2]*n[2]) < 0.0f) VecMulf(tang, -1.0f); } + +/* used for zoom values*/ +float power_of_2(float val) { + return pow(2, ceil(log(val) / log(2))); +} diff --git a/source/blender/include/BIF_drawseq.h b/source/blender/include/BIF_drawseq.h index 17311ab1489..462075cdf3d 100644 --- a/source/blender/include/BIF_drawseq.h +++ b/source/blender/include/BIF_drawseq.h @@ -39,5 +39,7 @@ void set_special_seq_update(int val); void seq_viewmove(SpaceSeq *sseq); void seq_reset_imageofs(SpaceSeq *sseq); +void seq_viewzoom(unsigned short event, int invert); +void seq_home(void); #endif diff --git a/source/blender/src/drawimage.c b/source/blender/src/drawimage.c index 6d1cd244b84..09ba518565f 100644 --- a/source/blender/src/drawimage.c +++ b/source/blender/src/drawimage.c @@ -2349,17 +2349,6 @@ void drawimagespace(ScrArea *sa, void *spacedata) sa->win_swap= WIN_BACK_OK; } -static void image_zoom_power_of_two(void) -{ - /* Make zoom a power of 2 */ - - G.sima->zoom = 1 / G.sima->zoom; - G.sima->zoom = log(G.sima->zoom) / log(2); - G.sima->zoom = ceil(G.sima->zoom); - G.sima->zoom = pow(2, G.sima->zoom); - G.sima->zoom = 1 / G.sima->zoom; -} - static void image_zoom_set_factor(float zoomfac) { SpaceImage *sima= curarea->spacedata.first; @@ -2503,8 +2492,10 @@ void image_home(void) imgheight = 256; } else { - imgwidth = ibuf->x; - imgheight = ibuf->y; + float xuser_asp, yuser_asp; + image_pixel_aspect(G.sima->image, &xuser_asp, &yuser_asp); + imgwidth = ibuf->x * xuser_asp; + imgheight = ibuf->y * yuser_asp; } /* Check if the image will fit in the image with zoom==1 */ @@ -2515,9 +2506,7 @@ void image_home(void) /* Find the zoom value that will fit the image in the image space */ zoomX = ((float)width) / ((float)imgwidth); zoomY = ((float)height) / ((float)imgheight); - G.sima->zoom= MIN2(zoomX, zoomY); - - image_zoom_power_of_two(); + G.sima->zoom = 1.0f / power_of_2(1/ MIN2(zoomX, zoomY) ); } else { G.sima->zoom= 1.0f; diff --git a/source/blender/src/drawseq.c b/source/blender/src/drawseq.c index fb97a369dd8..5e8e1783540 100644 --- a/source/blender/src/drawseq.c +++ b/source/blender/src/drawseq.c @@ -913,6 +913,64 @@ void seq_reset_imageofs(SpaceSeq *sseq) sseq->xof = sseq->yof = sseq->zoom = 0; } +void seq_home(void) +{ + SpaceSeq *sseq= curarea->spacedata.first; + + if (!sseq->mainb) { + G.v2d->cur= G.v2d->tot; + test_view2d(G.v2d, curarea->winx, curarea->winy); + view2d_do_locks(curarea, V2D_LOCK_COPY); + } else { + float zoomX, zoomY; + int width, height, imgwidth, imgheight; + + width = curarea->winx; + height = curarea->winy; + + seq_reset_imageofs(sseq); + + imgwidth= (G.scene->r.size*G.scene->r.xsch)/100; + imgheight= (G.scene->r.size*G.scene->r.ysch)/100; + + /* Apply aspect, dosnt need to be that accurate */ + imgwidth= (int)(imgwidth * ((float)G.scene->r.xasp / (float)G.scene->r.yasp)); + + if (((imgwidth >= width) || (imgheight >= height)) && + ((width > 0) && (height > 0))) { + + /* Find the zoom value that will fit the image in the image space */ + zoomX = ((float)width) / ((float)imgwidth); + zoomY = ((float)height) / ((float)imgheight); + sseq->zoom= (zoomX < zoomY) ? zoomX : zoomY; + + sseq->zoom = 1.0f / power_of_2(1/ MIN2(zoomX, zoomY) ); + } + else { + sseq->zoom= 1.0f; + } + } + scrarea_queue_winredraw(curarea); +} + +void seq_viewzoom(unsigned short event, int invert) +{ + SpaceSeq *sseq= curarea->spacedata.first; + + if(event==PAD1) + sseq->zoom= 1.0; + else if(event==PAD2) + sseq->zoom= (invert)? 2.0: 0.5; + else if(event==PAD4) + sseq->zoom= (invert)? 4.0: 0.25; + else if(event==PAD8) + sseq->zoom= (invert)? 8.0: 0.125; + + /* ensure pixel exact locations for draw */ + sseq->xof= (int)sseq->xof; + sseq->yof= (int)sseq->yof; +} + void seq_viewmove(SpaceSeq *sseq) { ScrArea *sa; diff --git a/source/blender/src/header_seq.c b/source/blender/src/header_seq.c index b3d9ff8d563..393830a61cf 100644 --- a/source/blender/src/header_seq.c +++ b/source/blender/src/header_seq.c @@ -75,13 +75,13 @@ static void do_seq_viewmenu(void *arg, int event) switch(event) { case 1: /* Play Back Animation */ - play_anim(0); - break; + play_anim(0); + break; case 2: /* Play Back Animation in All */ - play_anim(1); - break; + play_anim(1); + break; case 3: - do_seq_buttons(B_SEQHOME); + seq_home(); break; case 4: if(last_seq) { @@ -450,7 +450,7 @@ static void do_seq_editmenu(void *arg, int event) seq_mute_sel(0); break; case 22: - seq_mute_sel(-1); + seq_mute_sel(0); break; case 23: seq_cut(CFRA, 0); @@ -620,21 +620,13 @@ static uiBlock *seq_markermenu(void *arg_unused) void do_seq_buttons(short event) { Editing *ed; - SpaceSeq *sseq= curarea->spacedata.first; ed= G.scene->ed; if(ed==0) return; switch(event) { - case B_SEQHOME: - if(sseq->mainb) - seq_reset_imageofs(sseq); - else { - G.v2d->cur= G.v2d->tot; - test_view2d(G.v2d, curarea->winx, curarea->winy); - view2d_do_locks(curarea, V2D_LOCK_COPY); - } - scrarea_queue_winredraw(curarea); + case B_HOME: + seq_home(); break; case B_SEQCLEAR: free_imbuf_seq(); diff --git a/source/blender/src/space.c b/source/blender/src/space.c index 751cad1029d..d815f708799 100644 --- a/source/blender/src/space.c +++ b/source/blender/src/space.c @@ -4909,7 +4909,7 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt) break; case HOMEKEY: if((G.qual==0)) - do_seq_buttons(B_SEQHOME); + seq_home(); break; case PADPERIOD: if(last_seq) { @@ -5073,7 +5073,11 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt) del_seq(); } break; - } + case PAD1: case PAD2: case PAD4: case PAD8: + seq_viewzoom(event, (G.qual & LR_SHIFTKEY)==0); + doredraw= 1; + break; + } } if(doredraw) scrarea_queue_winredraw(curarea);