Commit b13421fa authored by slevy's avatar slevy
Browse files

parti_snapshot(): if the pattern includes '@', emit a stereo pair of images,...

parti_snapshot(): if the pattern includes '@', emit a stereo pair of images, replacing @ with L and R.
parent 7749ea07
......@@ -256,7 +256,7 @@ char *parti_stereo( const char *ster )
static char rslt[28];
static enum Gv_Stereo stereotype = GV_MONO;
static int quadmode = -1;
static char *sternames[] = { "mono", "redcyan", "crosseyed", "glasses", "left", "right" };
static const char *sternames[] = { "mono", "redcyan", "crosseyed", "glasses", "left", "right" };
int smode = -1;
if(stereotype == GV_MONO) {
......@@ -540,7 +540,7 @@ float parti_pickrange( char *newrange ) {
return ppui.pickrange;
}
static int endswith(char *str, char *suf) {
static int endswith(const char *str, const char *suf) {
if(str==NULL || suf==NULL) return 0;
int len = strlen(str);
int suflen = strlen(suf);
......@@ -730,7 +730,7 @@ static int snappng( char *outfname, int xsize, int ysize, char *rgbbuf )
int parti_snapshot( char *snapinfo )
{
char tfcmd[10240], *tftail;
char tfcmd1[10240], tfcmd2[10240], *tftail;
int fail;
enum imtype { AS_PNG, AS_JPEG, AS_OTHER } astype = AS_OTHER;
......@@ -754,30 +754,30 @@ int parti_snapshot( char *snapinfo )
}
if(ppui.snapfmt[0] == '|' || endswith(ppui.snapfmt, ".ppm")) {
tfcmd[0] = '\0';
tfcmd1[0] = '\0';
#ifdef HAVE_PNG_H
} else if(endswith(ppui.snapfmt, ".png")) {
/* use built-in libpng writer if available */
astype = AS_PNG;
tfcmd[0] = '\0';
tfcmd1[0] = '\0';
#endif
#ifdef HAVE_JPEGLIB_H
} else if(endswith(ppui.snapfmt, ".jpeg") || endswith(ppui.snapfmt, ".jpg")) {
/* use built-in libjpeg writer if available */
astype = AS_JPEG;
tfcmd[0] = '\0';
tfcmd1[0] = '\0';
#endif
#if unix
} else if(endswith(ppui.snapfmt, ".ppm.gz")) {
strcpy(tfcmd, gzprefix);
strcpy(tfcmd1, gzprefix);
#endif
} else {
strcpy(tfcmd, prefix);
strcpy(tfcmd1, prefix);
}
tftail = tfcmd+strlen(tfcmd);
tftail = tfcmd1+strlen(tfcmd1);
sprintf(tftail, ppui.snapfmt, ppui.snapfno);
if(!ppui.view || !ppui.view->visible_r()) {
msg("snapshot: no visible graphics window?");
......@@ -785,17 +785,36 @@ int parti_snapshot( char *snapinfo )
}
Fl_Widget *pa;
for(pa = ppui.view; pa->parent(); pa = pa->parent()) ;
for(pa = ppui.view; pa->parent(); pa = pa->parent())
;
pa->show(); // raise window
// Ensure window's image is up-to-date
parti_update();
bool snapstereo = (strchr(tfcmd1, '@') != NULL);
enum Gv_Stereo stereowas = ppui.view->stereo();
char *tfcmd = snapstereo ? tfcmd2 : tfcmd1;
int y, h = ppui.view->h(), w = ppui.view->w();
char *buf = (char *)malloc(w*h*3);
for(int eye = 0; eye < (snapstereo ? 2 : 1); eye++) {
char eyech = 'L';
if(snapstereo) {
ppui.view->stereo( eye==0 ? GV_LEFTEYE : GV_RIGHTEYE );
strcpy(tfcmd, tfcmd1);
// replace all instances of "@" with "L" or "R"
char eyech = eye==0 ? 'L' : 'R';
for(char *s = tfcmd; (s = strchr(s, '@')) != NULL; s++)
*s = eyech;
}
// Ensure window's image is up-to-date
parti_update();
if(!ppui.view->snapshot( 0, 0, w, h, buf )) {
free(buf);
msg("snapshot: couldn't read from graphics window?");
return -2;
fail = -2;
break;
}
switch(astype) {
......@@ -850,16 +869,27 @@ int parti_snapshot( char *snapinfo )
/* end of "write ppm" case */
break;
}
free(buf);
if(fail) {
msg("snapshot: Error writing to %s", tfcmd);
return -1;
break;
}
}
if(snapinfo)
free(buf);
if(snapstereo) // restore changed stereo setting
ppui.view->stereo( stereowas );
if(snapinfo) {
if(fail)
sprintf(snapinfo, "failed snapping %.900s", tftail);
else if(snapstereo)
sprintf(snapinfo, "%.1000s [%dx%d] @ => stereo L,R", tftail, w, h);
else
sprintf(snapinfo, "%.1000s [%dx%d]", tftail, w, h);
return ppui.snapfno++;
}
return fail ? -1 : ppui.snapfno++;
}
const char *parti_get_alias( struct stuff *st ) {
......@@ -1129,7 +1159,7 @@ int parti_select_subcam( int index )
return index;
}
char *parti_get_subcam( int index, char *paramsp )
const char *parti_get_subcam( int index, char *paramsp )
{
if(paramsp) paramsp[0] = '\0';
if(index == 0 || index > ppui.scroom) return "";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment