Orange: ImageWindow goodies

- options to show with alpha-over (checkered backdrop), only alpha (BW) and
  when available: the zbuffer.
  Note: it's icons in the header, I just re-used existing ones, no time now
  for fancy design. :)

Also: recoded the way alpha-only draws, also in renderwindow. Mucho faster!

Oh, and sampling the buffer with LMB now displays z values in float range
of 0.0 to 1.0. Note that we still save signed int in files for Z...
This commit is contained in:
2006-01-11 14:20:35 +00:00
parent 305fdec0eb
commit 1eee258449
7 changed files with 94 additions and 23 deletions

View File

@@ -312,6 +312,9 @@
#define B_SIMANOTHING 368
#define B_SIMACURVES 369
#define B_SIMARANGE 370
#define B_SIMA_USE_ALPHA 371
#define B_SIMA_SHOW_ALPHA 372
#define B_SIMA_SHOW_ZBUF 373
/* BUTS: 400 */
#define B_BUTSHOME 401

View File

@@ -467,6 +467,9 @@ typedef struct SpaceImaSel {
#define SI_PIXELSNAP 1024
#define SI_LSCM_LIVE 2048
#define SI_USE_ALPHA 4096
#define SI_SHOW_ALPHA 8192
#define SI_SHOW_ZBUF 16384
/* SpaceText flags (moved from DNA_text_types.h) */

View File

@@ -1099,6 +1099,38 @@ static void sima_draw_alpha_backdrop(SpaceImage *sima, float x1, float y1, float
}
}
static void sima_draw_alpha_pixels(float x1, float y1, int rectx, int recty, unsigned int *recti)
{
char *rect= (char *)recti;
/* swap bytes, so alpha is most significant one, then just draw it as luminance int */
glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
glaDrawPixelsSafe(x1, y1, rectx, recty, GL_UNSIGNED_INT, recti);
glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
}
static void sima_draw_zbuf_pixels(float x1, float y1, int rectx, int recty, int *recti)
{
if(recti==NULL)
return;
/* zbuffer values are signed, so we need to shift color range */
glPixelTransferf(GL_RED_SCALE, 0.5f);
glPixelTransferf(GL_GREEN_SCALE, 0.5f);
glPixelTransferf(GL_BLUE_SCALE, 0.5f);
glPixelTransferf(GL_RED_BIAS, 0.5f);
glPixelTransferf(GL_GREEN_BIAS, 0.5f);
glPixelTransferf(GL_BLUE_BIAS, 0.5f);
glaDrawPixelsSafe(x1, y1, rectx, recty, GL_INT, recti);
glPixelTransferf(GL_RED_SCALE, 1.0f);
glPixelTransferf(GL_GREEN_SCALE, 1.0f);
glPixelTransferf(GL_BLUE_SCALE, 1.0f);
glPixelTransferf(GL_RED_BIAS, 0.0f);
glPixelTransferf(GL_GREEN_BIAS, 0.0f);
glPixelTransferf(GL_BLUE_BIAS, 0.0f);
}
void drawimagespace(ScrArea *sa, void *spacedata)
{
@@ -1128,8 +1160,9 @@ void drawimagespace(ScrArea *sa, void *spacedata)
what_image(sima);
if(sima->image) {
if(sima->image->ibuf==0) {
if(sima->image->ibuf==NULL) {
load_image(sima->image, IB_rect, G.sce, G.scene->r.cfra);
scrarea_queue_headredraw(sa); /* update header for image options */
}
tag_image_time(sima->image);
ibuf= sima->image->ibuf;
@@ -1207,6 +1240,13 @@ void drawimagespace(ScrArea *sa, void *spacedata)
MEM_freeN(rect);
}
else {
if(sima->flag & SI_SHOW_ALPHA) {
sima_draw_alpha_pixels(x1, y1, ibuf->x, ibuf->y, ibuf->rect);
}
else if(sima->flag & SI_SHOW_ZBUF) {
sima_draw_zbuf_pixels(x1, y1, ibuf->x, ibuf->y, ibuf->zbuf);
}
else {
if(sima->flag & SI_USE_ALPHA) {
sima_draw_alpha_backdrop(sima, x1, y1, (float)ibuf->x, (float)ibuf->y);
@@ -1217,6 +1257,7 @@ void drawimagespace(ScrArea *sa, void *spacedata)
if(sima->flag & SI_USE_ALPHA)
glDisable(GL_BLEND);
}
}
if(Gip.current == IMAGEPAINT_CLONE) {
int w, h;

View File

@@ -1398,7 +1398,7 @@ int minmax_tface_uv(float *min, float *max)
return sel;
}
static void sima_show_info(int x, int y, char *cp, float *fp, unsigned int *zp)
static void sima_show_info(int x, int y, char *cp, float *fp, int *zp)
{
short ofs;
char str[256];
@@ -1409,7 +1409,7 @@ static void sima_show_info(int x, int y, char *cp, float *fp, unsigned int *zp)
if(fp)
ofs+= sprintf(str+ofs, "| R: %.3f G: %.3f B: %.3f A: %.3f ", fp[0], fp[1], fp[2], fp[3]);
if(zp)
ofs+= sprintf(str+ofs, "| Z: %x ", *zp);
ofs+= sprintf(str+ofs, "| Z: %.4f ", 0.5+0.5*( ((float)*zp)/(float)0x7fffffff));
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
@@ -1447,7 +1447,7 @@ void sima_sample_color(void)
if(fx>=0.0 && fy>=0.0 && fx<1.0 && fy<1.0) {
float *fp= NULL;
unsigned int *zp= NULL;
int *zp= NULL;
char *cp= NULL;
int x= (int) (fx*ibuf->x);

View File

@@ -343,6 +343,10 @@ void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int format, void
float *f_rect= (float *)rect;
glDrawPixels(draw_w, draw_h, GL_RGBA, GL_FLOAT, f_rect + (off_y*img_w + off_x)*4);
}
else if(format==GL_INT || format==GL_UNSIGNED_INT) {
int *i_rect= (int *)rect;
glDrawPixels(draw_w, draw_h, GL_LUMINANCE, format, i_rect + (off_y*img_w + off_x));
}
else {
unsigned char *uc_rect= (unsigned char *) rect;
glDrawPixels(draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, uc_rect + (off_y*img_w + off_x)*4);

View File

@@ -332,6 +332,21 @@ void do_image_buttons(unsigned short event)
}
}
break;
case B_SIMA_USE_ALPHA:
G.sima->flag &= ~(SI_SHOW_ALPHA|SI_SHOW_ZBUF);
scrarea_queue_winredraw(curarea);
scrarea_queue_headredraw(curarea);
break;
case B_SIMA_SHOW_ALPHA:
G.sima->flag &= ~(SI_USE_ALPHA|SI_SHOW_ZBUF);
scrarea_queue_winredraw(curarea);
scrarea_queue_headredraw(curarea);
break;
case B_SIMA_SHOW_ZBUF:
G.sima->flag &= ~(SI_SHOW_ALPHA|SI_USE_ALPHA);
scrarea_queue_winredraw(curarea);
scrarea_queue_headredraw(curarea);
break;
}
}
@@ -1166,8 +1181,19 @@ void image_buttons(void)
uiDefIconButBitS(block, TOG, SI_DRAWTOOL, B_SIMAGEPAINTTOOL, ICON_TPAINT_HLT, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Enables painting textures on the image with left mouse button");
xco+= XIC+8;
uiDefIconButBitS(block, TOG, SI_USE_ALPHA, B_REDR, ICON_TRANSP_HLT, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Draws image with alpha");
xco+= XIC+8;
uiBlockBeginAlign(block);
uiDefIconButBitS(block, TOG, SI_USE_ALPHA, B_SIMA_USE_ALPHA, ICON_TRANSP_HLT, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Draws image with alpha");
xco+= XIC;
uiDefIconButBitS(block, TOG, SI_SHOW_ALPHA, B_SIMA_SHOW_ALPHA, ICON_DOT, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Draws only alpha");
xco+= XIC;
if(G.sima->image->ibuf && G.sima->image->ibuf->zbuf) {
uiDefIconButBitS(block, TOG, SI_SHOW_ZBUF, B_SIMA_SHOW_ZBUF, ICON_SOLID, xco,0,XIC,YIC, &G.sima->flag, 0, 0, 0, 0, "Draws zbuffer values");
xco+= XIC;
}
else G.sima->flag &= ~SI_SHOW_ZBUF; /* no confusing display for non-zbuf images */
uiBlockEndAlign(block);
xco+= 8;
}
/* draw LOCK */

View File

@@ -326,16 +326,10 @@ static void renderwin_draw(RenderWin *rw, int just_clear)
} else {
glPixelZoom(rw->zoom, rw->zoom);
if(rw->flags & RW_FLAGS_ALPHA) {
char *rect= (char *)R.rectot;
glColorMask(1, 0, 0, 0);
glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, GL_UNSIGNED_BYTE, rect+3);
glColorMask(0, 1, 0, 0);
glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, GL_UNSIGNED_BYTE, rect+2);
glColorMask(0, 0, 1, 0);
glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, GL_UNSIGNED_BYTE, rect+1);
glColorMask(1, 1, 1, 1);
/* swap bytes, so alpha is most significant one, then just draw it as luminance int */
glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, GL_UNSIGNED_INT, R.rectot);
glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
}
else {
glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, GL_UNSIGNED_BYTE, R.rectot);