Camera tracking: more accurate track preview widget

- Added 1px extra margin to deal with bicubic interpolation nicely
- Code should be a bit more clear now
This commit is contained in:
2012-01-04 15:25:43 +00:00
parent 49cf3c76a9
commit a4604c457d
3 changed files with 44 additions and 28 deletions

View File

@@ -860,7 +860,9 @@ void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClip
undist_marker.pos[1]/= height*aspy;
}
tmpibuf= BKE_tracking_get_pattern_imbuf(ibuf, track, &undist_marker, 1, 1, scopes->track_pos, NULL);
/* NOTE: margin should be kept in sync with value from ui_draw_but_TRACKPREVIEW */
tmpibuf= BKE_tracking_get_pattern_imbuf(ibuf, track, &undist_marker, 2 /* margin */,
1 /* anchor */, scopes->track_pos, NULL);
if(tmpibuf->rect_float)
IMB_rect_from_float(tmpibuf);

View File

@@ -999,17 +999,24 @@ static ImBuf *get_area_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTracki
if(anchored)
add_v2_v2(mpos, track->offset);
if(pos)
zero_v2(pos);
x= mpos[0]*ibuf->x;
y= mpos[1]*ibuf->y;
x1= x-(int)(-min[0]*ibuf->x);
y1= y-(int)(-min[1]*ibuf->y);
x2= x+(int)(max[0]*ibuf->x);
y2= y+(int)(max[1]*ibuf->y);
w= (max[0]-min[0])*ibuf->x;
h= (max[1]-min[1])*ibuf->y;
w= w|1;
h= h|1;
x1= x-(int)(w/2.0f);
y1= y-(int)(h/2.0f);
x2= x+(int)(w/2.0f);
y2= y+(int)(h/2.0f);
/* dimensions should be odd */
w= (x2-x1)|1;
h= (y2-y1)|1;
tmpibuf= IMB_allocImBuf(w+margin*2, h+margin*2, 32, IB_rect);
IMB_rectcpy(tmpibuf, ibuf, 0, 0, x1-margin, y1-margin, w+margin*2, h+margin*2);
@@ -1023,13 +1030,17 @@ static ImBuf *get_area_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTracki
origin[1]= y1-margin;
}
if ((track->flag & TRACK_PREVIEW_GRAYSCALE) ||
(track->flag & TRACK_DISABLE_RED) ||
(track->flag & TRACK_DISABLE_GREEN) ||
(track->flag & TRACK_DISABLE_BLUE) ) {
if((track->flag & TRACK_PREVIEW_GRAYSCALE) ||
(track->flag & TRACK_DISABLE_RED) ||
(track->flag & TRACK_DISABLE_GREEN) ||
(track->flag & TRACK_DISABLE_BLUE))
{
disable_imbuf_channels(tmpibuf, track, 1 /* grayscale */);
}
tmpibuf->ftype= PNG;
IMB_saveiff(tmpibuf, "/tmp/1.png", IB_rect);
return tmpibuf;
}

View File

@@ -1465,21 +1465,16 @@ static ImBuf *scale_trackpreview_ibuf(ImBuf *ibuf, float zoomx, float zoomy)
{
ImBuf *scaleibuf;
int x, y, w= ibuf->x*zoomx, h= ibuf->y*zoomy;
const float max_x= ibuf->x-1.0f;
const float max_y= ibuf->y-1.0f;
const float scalex= 1.0f/zoomx;
const float scaley= 1.0f/zoomy;
scaleibuf= IMB_allocImBuf(w, h, 32, IB_rect);
for(y= 0; y<scaleibuf->y; y++) {
for (x= 0; x<scaleibuf->x; x++) {
for(y= 0; y<h; y++) {
for (x= 0; x<w; x++) {
float src_x= scalex*x;
float src_y= scaley*y;
CLAMP(src_x, 0, max_x);
CLAMP(src_y, 0, max_y);
bicubic_interpolation(ibuf, scaleibuf, src_x, src_y, x, y);
}
}
@@ -1514,28 +1509,36 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc
ok= 1;
}
else if(scopes->track_preview) {
int a, off_x, off_y;
float zoomx, zoomy;
/* additional margin around image */
/* NOTE: should be kept in sync with value from BKE_movieclip_update_scopes */
const int margin= 2;
float zoomx, zoomy, track_pos[2], off_x, off_y;
int a;
ImBuf *drawibuf;
glPushMatrix();
track_pos[0]= scopes->track_pos[0]-margin;
track_pos[1]= scopes->track_pos[1]-margin;
/* draw content of pattern area */
glScissor(ar->winrct.xmin+rect.xmin, ar->winrct.ymin+rect.ymin, scissor[2], scissor[3]);
zoomx= (rect.xmax-rect.xmin) / (scopes->track_preview->x-2.0f);
zoomy= (rect.ymax-rect.ymin) / (scopes->track_preview->y-2.0f);
zoomx= (rect.xmax-rect.xmin) / (scopes->track_preview->x-2*margin);
zoomy= (rect.ymax-rect.ymin) / (scopes->track_preview->y-2*margin);
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;
off_x= ((int)track_pos[0]-track_pos[0]+0.5)*zoomx;
off_y= ((int)track_pos[1]-track_pos[1]+0.5)*zoomy;
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);
glaDrawPixelsSafe(off_x+rect.xmin-zoomx*(margin-0.5f), off_y+rect.ymin-zoomy*(margin-0.5f),
rect.xmax-rect.xmin+2+(int)(zoomx*(margin-0.5f)-off_x),
rect.ymax-rect.ymin+2+(int)(zoomy*(margin-0.5f)-off_y),
drawibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, drawibuf->rect);
IMB_freeImBuf(drawibuf);
/* 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);
glTranslatef(off_x+rect.xmin+track_pos[0]*zoomx, off_y+rect.ymin+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);
for(a= 0; a< 2; a++) {