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
diff options
context:
space:
mode:
authorKeir Mierle <mierle@gmail.com>2011-12-04 08:33:06 +0400
committerKeir Mierle <mierle@gmail.com>2011-12-04 08:33:06 +0400
commit50d440504ca611c4a1cb9219e7b64c70e077b0a5 (patch)
treea638e96872faf00497a6c6d44796b8b926cd57a0 /source/blender/editors/interface
parent8e01cfa04592ebcfea13a4b47862c67d7114bb81 (diff)
Switch the tracker preview area to use bilinear filtering instead of nearest
neighbour. This makes it easier to align tracks.
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r--source/blender/editors/interface/interface_draw.c113
1 files changed, 68 insertions, 45 deletions
diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c
index da94fd9237a..ad8885e3394 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -1471,33 +1471,12 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect
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++) {
- int pixel= scaleibuf->x*y + x;
- int orig_pixel= ibuf->x*(int)(((float)y)/zoomy) + (int)(((float)x)/zoomx);
- char *rrgb= (char*)scaleibuf->rect + pixel*4;
- char *orig_rrgb= (char*)ibuf->rect + orig_pixel*4;
- rrgb[0]= orig_rrgb[0];
- rrgb[1]= orig_rrgb[1];
- rrgb[2]= orig_rrgb[2];
- rrgb[3]= orig_rrgb[3];
- }
- }
-
- 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;
@@ -1505,12 +1484,20 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc
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);
@@ -1520,30 +1507,66 @@ 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;
+ int a;
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]);
-
- zoomx= (rect.xmax-rect.xmin) / (scopes->track_preview->x-2.0f);
- zoomy= (rect.ymax-rect.ymin) / (scopes->track_preview->y-2.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;
-
- 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);
+ 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);
+
+ /* 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);
+
+ /* this matrix is reused below to draw the crosshair */
+ glPushMatrix();
- IMB_freeImBuf(drawibuf);
+ /* 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);
+
+ /* 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);
@@ -1555,14 +1578,14 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc
}
glBegin(GL_LINES);
- glVertex2f(-10.0f, 0.0f);
- glVertex2f(10.0f, 0.0f);
- glVertex2f(0.0f, -10.0f);
- glVertex2f(0.0f, 10.0f);
+ glVertex2f(-0.10f, 0.0f);
+ glVertex2f( 0.10f, 0.0f);
+ glVertex2f( 0.0f, -0.10f);
+ glVertex2f( 0.0f, 0.10f);
glEnd();
}
-
glDisable(GL_LINE_STIPPLE);
+
glPopMatrix();
ok= 1;
@@ -1577,7 +1600,7 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc
/* outline, scale gripper */
draw_scope_end(&rect, scissor);
- glDisable(GL_BLEND);
+ glPopAttrib();
}
/* ****************************************************** */