Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

SnapshotDisplayDevice.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2019 The Board of Trustees of the           
00004  *cr                        University of Illinois                       
00005  *cr                         All Rights Reserved                        
00006  *cr                                                                   
00007  ***************************************************************************/
00008 /***************************************************************************
00009  * RCS INFORMATION:
00010  *
00011  *      $RCSfile: SnapshotDisplayDevice.C,v $
00012  *      $Author: johns $        $Locker:  $             $State: Exp $
00013  *      $Revision: 1.49 $       $Date: 2020/02/26 07:21:45 $
00014  *
00015  ***************************************************************************/
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include "ImageIO.h"
00028 #include "SnapshotDisplayDevice.h"
00029 #include "Inform.h"
00030 #include "utilities.h"
00031 #include "config.h"
00032 
00033 #if defined(_MSC_VER) || defined(WIN32)
00034 #define DEF_SNAPSHOT_FILENAME "vmdscene.bmp"
00035 #else
00036 #define DEF_SNAPSHOT_FILENAME "vmdscene.tga"
00037 #endif
00038 
00039 SnapshotDisplayDevice::SnapshotDisplayDevice(DisplayDevice *d) 
00040 : FileRenderer("snapshot", "Snapshot (VMD OpenGL window)", DEF_SNAPSHOT_FILENAME, DEF_VMDIMAGEVIEWER) {
00041   display = d; 
00042   // override default command line if environment variable set
00043   const char *envtxt = getenv("VMDIMAGEVIEWER");
00044   if (envtxt) {
00045     delete [] defaultCommandLine;
00046     defaultCommandLine = stringdup(envtxt);
00047     set_exec_string(envtxt); // change current exec command as well
00048   }
00049 }
00050 
00051 int SnapshotDisplayDevice::open_file(const char *filename) {
00052   if ((outfile = fopen(filename, "wb")) == NULL) {
00053     msgErr << "Could not open file " << filename
00054            << " in current directory for writing!" << sendmsg;
00055     return FALSE;
00056   }
00057   my_filename = stringdup(filename);
00058   isOpened = TRUE;
00059   return TRUE;
00060 }
00061 
00062 static int checkfileextension(const char * s, const char * extension) {
00063   int sz, extsz; 
00064   sz = strlen(s);
00065   extsz = strlen(extension); 
00066 
00067   if (extsz > sz)
00068     return 0;
00069 
00070   if (!strupncmp(s + (sz - extsz), extension, extsz)) {
00071     return 1;
00072   }
00073 
00074   return 0;
00075 }
00076 
00077 
00078 // construct the exec string, then system() it
00079 // pretty easy, eh?
00080 void SnapshotDisplayDevice::close_file(void) {
00081   int xs=0, ys=0;
00082   unsigned char * img;
00083 
00084   img = display->readpixels_rgb3u(xs, ys);
00085 
00086   // write the image to a file on disk
00087   if (checkfileextension(my_filename, ".bmp")) {
00088     vmd_writebmp(outfile, img, xs, ys);
00089 #if defined(VMDLIBPNG)
00090   } else if (checkfileextension(my_filename, ".png")) {
00091     vmd_writepng(outfile, img, xs, ys);
00092 #endif
00093   } else if (checkfileextension(my_filename, ".ppm")) {
00094     vmd_writeppm(outfile, img, xs, ys);
00095   } else if (checkfileextension(my_filename, ".rgb")) {
00096     vmd_writergb(outfile, img, xs, ys);
00097   } else if (checkfileextension(my_filename, ".tga")) {
00098     vmd_writetga(outfile, img, xs, ys);
00099   } else {
00100 #if defined(_MSC_VER) || defined(WIN32)
00101     msgErr << "Unrecognized image file extension, writing Windows Bitmap file." 
00102            << sendmsg;
00103     vmd_writebmp(outfile, img, xs, ys);
00104 #else
00105     msgErr << "Unrecognized image file extension, writing Targa file." 
00106            << sendmsg;
00107     vmd_writetga(outfile, img, xs, ys);
00108 #endif
00109   }
00110 
00111   free(img); // free img memory block
00112   fclose(outfile);
00113   outfile = NULL;
00114   delete [] my_filename;
00115   my_filename = NULL;
00116   isOpened = FALSE;
00117 }
00118 

Generated on Mon Apr 22 04:27:34 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002