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 ) ...@@ -256,7 +256,7 @@ char *parti_stereo( const char *ster )
static char rslt[28]; static char rslt[28];
static enum Gv_Stereo stereotype = GV_MONO; static enum Gv_Stereo stereotype = GV_MONO;
static int quadmode = -1; 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; int smode = -1;
if(stereotype == GV_MONO) { if(stereotype == GV_MONO) {
...@@ -540,7 +540,7 @@ float parti_pickrange( char *newrange ) { ...@@ -540,7 +540,7 @@ float parti_pickrange( char *newrange ) {
return ppui.pickrange; 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; if(str==NULL || suf==NULL) return 0;
int len = strlen(str); int len = strlen(str);
int suflen = strlen(suf); int suflen = strlen(suf);
...@@ -730,7 +730,7 @@ static int snappng( char *outfname, int xsize, int ysize, char *rgbbuf ) ...@@ -730,7 +730,7 @@ static int snappng( char *outfname, int xsize, int ysize, char *rgbbuf )
int parti_snapshot( char *snapinfo ) int parti_snapshot( char *snapinfo )
{ {
char tfcmd[10240], *tftail; char tfcmd1[10240], tfcmd2[10240], *tftail;
int fail; int fail;
enum imtype { AS_PNG, AS_JPEG, AS_OTHER } astype = AS_OTHER; enum imtype { AS_PNG, AS_JPEG, AS_OTHER } astype = AS_OTHER;
...@@ -754,30 +754,30 @@ int parti_snapshot( char *snapinfo ) ...@@ -754,30 +754,30 @@ int parti_snapshot( char *snapinfo )
} }
if(ppui.snapfmt[0] == '|' || endswith(ppui.snapfmt, ".ppm")) { if(ppui.snapfmt[0] == '|' || endswith(ppui.snapfmt, ".ppm")) {
tfcmd[0] = '\0'; tfcmd1[0] = '\0';
#ifdef HAVE_PNG_H #ifdef HAVE_PNG_H
} else if(endswith(ppui.snapfmt, ".png")) { } else if(endswith(ppui.snapfmt, ".png")) {
/* use built-in libpng writer if available */ /* use built-in libpng writer if available */
astype = AS_PNG; astype = AS_PNG;
tfcmd[0] = '\0'; tfcmd1[0] = '\0';
#endif #endif
#ifdef HAVE_JPEGLIB_H #ifdef HAVE_JPEGLIB_H
} else if(endswith(ppui.snapfmt, ".jpeg") || endswith(ppui.snapfmt, ".jpg")) { } else if(endswith(ppui.snapfmt, ".jpeg") || endswith(ppui.snapfmt, ".jpg")) {
/* use built-in libjpeg writer if available */ /* use built-in libjpeg writer if available */
astype = AS_JPEG; astype = AS_JPEG;
tfcmd[0] = '\0'; tfcmd1[0] = '\0';
#endif #endif
#if unix #if unix
} else if(endswith(ppui.snapfmt, ".ppm.gz")) { } else if(endswith(ppui.snapfmt, ".ppm.gz")) {
strcpy(tfcmd, gzprefix); strcpy(tfcmd1, gzprefix);
#endif #endif
} else { } else {
strcpy(tfcmd, prefix); strcpy(tfcmd1, prefix);
} }
tftail = tfcmd+strlen(tfcmd); tftail = tfcmd1+strlen(tfcmd1);
sprintf(tftail, ppui.snapfmt, ppui.snapfno); sprintf(tftail, ppui.snapfmt, ppui.snapfno);
if(!ppui.view || !ppui.view->visible_r()) { if(!ppui.view || !ppui.view->visible_r()) {
msg("snapshot: no visible graphics window?"); msg("snapshot: no visible graphics window?");
...@@ -785,81 +785,111 @@ int parti_snapshot( char *snapinfo ) ...@@ -785,81 +785,111 @@ int parti_snapshot( char *snapinfo )
} }
Fl_Widget *pa; 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 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(); int y, h = ppui.view->h(), w = ppui.view->w();
char *buf = (char *)malloc(w*h*3); char *buf = (char *)malloc(w*h*3);
if(!ppui.view->snapshot( 0, 0, w, h, buf )) {
free(buf);
msg("snapshot: couldn't read from graphics window?");
return -2;
}
switch(astype) { for(int eye = 0; eye < (snapstereo ? 2 : 1); eye++) {
case AS_PNG: 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?");
fail = -2;
break;
}
switch(astype) {
case AS_PNG:
#ifdef HAVE_PNG_H #ifdef HAVE_PNG_H
fail = snappng( tfcmd, w, h, buf ); fail = snappng( tfcmd, w, h, buf );
#endif #endif
break; break;
#ifdef HAVE_JPEGLIB_H #ifdef HAVE_JPEGLIB_H
case AS_JPEG: case AS_JPEG:
fail = snapjpeg( tfcmd, w, h, buf ); fail = snapjpeg( tfcmd, w, h, buf );
break; break;
#endif #endif
default: default:
/* write ppm stream/file */ /* write ppm stream/file */
FILE *p; FILE *p;
#if unix #if unix
void (*oldpipe)(int) = 0; void (*oldpipe)(int) = 0;
int popened = tfcmd[0] == '|'; int popened = tfcmd[0] == '|';
if(popened) { if(popened) {
oldpipe = signal(SIGPIPE, SIG_IGN); oldpipe = signal(SIGPIPE, SIG_IGN);
p = popen(tfcmd+1, "w"); p = popen(tfcmd+1, "w");
} else { } else {
p = fopen(tfcmd, "wb"); p = fopen(tfcmd, "wb");
} }
fprintf(p, "P6\n%d %d\n255\n", w, h); fprintf(p, "P6\n%d %d\n255\n", w, h);
for(y = h; --y >= 0 && fwrite(&buf[w*3*y], w*3, 1, p) > 0; ) for(y = h; --y >= 0 && fwrite(&buf[w*3*y], w*3, 1, p) > 0; )
; ;
fflush(p); fflush(p);
fail = ferror(p) || y >= 0; fail = ferror(p) || y >= 0;
if(popened) { if(popened) {
pclose(p); pclose(p);
signal(SIGPIPE, oldpipe); signal(SIGPIPE, oldpipe);
} }
else else
fclose(p); fclose(p);
#else /* win32 */ #else /* win32 */
p = fopen(tfcmd, "wb"); p = fopen(tfcmd, "wb");
fprintf(p, "P6\n%d %d\n255\n", w, h); fprintf(p, "P6\n%d %d\n255\n", w, h);
for(y = h; --y >= 0 && fwrite(&buf[w*3*y], w*3, 1, p) > 0; ) for(y = h; --y >= 0 && fwrite(&buf[w*3*y], w*3, 1, p) > 0; )
; ;
fflush(p); fflush(p);
fail = ferror(p) || y >= 0; fail = ferror(p) || y >= 0;
fclose(p); fclose(p);
#endif #endif
/* end of "write ppm" case */ /* end of "write ppm" case */
break; break;
}
if(fail) {
msg("snapshot: Error writing to %s", tfcmd);
break;
}
} }
free(buf); free(buf);
if(snapstereo) // restore changed stereo setting
ppui.view->stereo( stereowas );
if(fail) { if(snapinfo) {
msg("snapshot: Error writing to %s", tfcmd); if(fail)
return -1; 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);
} }
if(snapinfo)
sprintf(snapinfo, "%.1000s [%dx%d]", tftail, w, h); return fail ? -1 : ppui.snapfno++;
return ppui.snapfno++;
} }
const char *parti_get_alias( struct stuff *st ) { const char *parti_get_alias( struct stuff *st ) {
...@@ -1129,7 +1159,7 @@ int parti_select_subcam( int index ) ...@@ -1129,7 +1159,7 @@ int parti_select_subcam( int index )
return 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(paramsp) paramsp[0] = '\0';
if(index == 0 || index > ppui.scroom) return ""; 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