5751286 [rkeene@sledge /home/rkeene/devel/old/stereograph-0.16]$ cat -n stereograph.c
  1 /* Stereograph 0.16, 12/04/2000;
  2  * Copyright (c) 2000 by Fabian Januszewski <fabian.linux@januszewski.de>
  3  *
  4  * This program is free software; you can redistribute it and/or modify
  5  * it under the terms of the GNU General Public License as published by
  6  * the Free Software Foundation; either version 2 of the License, or
  7  * (at your option) any later version.
  8  *
  9  * This program is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12  * GNU General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU General Public License
 15  * along with this program; if not, write to the Free Software
 16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 17  */
 18 
 19 
 20 #include <stdio.h>
 21 #include <stdlib.h>
 22 
 23 #include "renderer.h"
 24 #include "gfxio.h"
 25 #include "stereograph.h"
 26 #include "globals.h"
 27 
 28 
 29 char *base_file_name;
 30 char *texture_file_name;
 31 char *stereo_file_name;
 32 
 33 /* interface to the renderer */
 34 struct PARAMS *pParam;
 35 struct GFX_DATA *pBase, *pTexture, *pStereo;
 36 
 37 
 38 void print_info(void) {
 39     printf("SYNOPSIS\n  stereograph [OPTIONS] -b [FILENAME] -t [FILENAME] [-o [FILENAME]]\n\n");
 40     printf("OPTIONS\n  -a anti-aliasing     -z zoom               (quality)\n  -d distance          -e eye shift        
	 (perspective)\n  -x texture insert x  -y texture insert y   (layout)\n  -r this flag enables anti-artefact feature
	(experimental)\n  -v you should know this flag :)\n\n");
 41 }
 42 
 43 int main (int argc, char **argv) {
 44 
 45     int last_error = 0;
 46 
 47     Get_GFX_Pointers(&pParam, &pBase, &pTexture, &pStereo);
 48 
 49     pParam->Zoom = 1;
 50     pParam->AA = 4;
 51     pParam->AAr = 0;
 52     pParam->Startx = 0;
 53     pParam->Starty = 0;
 54     pParam->Front = 1.0;
 55     pParam->Distance = 0.6;
 56     pParam->Eyeshift = 0.0;
 57 
 58     pBase->Data = NULL;
 59     pTexture->Data = NULL;
 60     pStereo->Data = NULL;
 61     base_file_name = NULL;
 62     texture_file_name = NULL;
 63     stereo_file_name = NULL;
 64 
 65     verbose = 0;
 66 
 67     parse_args(argc, argv);
 68 
 69     if(verbose) printf("Stereograph for linux Version %s\n", "0.16");
 70 
 71 
 72 
 73 
 74     if(base_file_name && texture_file_name) {
 75         if(verbose) printf("loading base '%s'...", base_file_name);
 76         if(!Read_Gfx_File(base_file_name, pBase)) {
 77             if(verbose) printf("loading texture '%s'...", texture_file_name);
 78             if(!Read_Gfx_File(texture_file_name, pTexture)) {
 79 
 80                 /* setting up renderer; */
 81                 if(verbose) printf("initializing renderer...");
 82                 if(!(last_error = Initialize_Renderer())) {
 83                     int y, s;
 84                     if(verbose) printf("success;\n");
 85                     if(verbose) printf("using parametres as follows (zadexy): %i %i %f %f %i %i;\n", pParam->Zoom,
	pParam->AA, pParam->Distance, pParam->Eyeshift, pParam->Startx, pParam->Starty);
 86                     if(verbose && pParam->AAr)
 87                         printf("experimental anti-artefacts feature enabled;\n");
 88                     if(verbose) printf("processing...");
 89 
 90                     for(y = 0, s = 0; (y < pBase->Height); y++) {
 91                         ProcessLine(y);
 92                         /* print simple status points (without refresh) */
 93                         for( ; verbose && (s < (58 * y / pBase->Height)); s++)
 94                             printf(".");
 95                     }
 96 
 97                     if(verbose) printf("completed;\n");
 98     
 99                     if(verbose) printf("writing stereogram to disk...");
100                     Write_Gfx_File(stereo_file_name, pStereo);
101                 } else {
102                     if(verbose)
103                         printf("FAILED;\n");
104                     else
105                         fprintf(stderr, "initializing renderer...FAILED;\n");
106                     switch (last_error) {
107                         case -1 :
108                             fprintf(stderr, "illegal parametre;\n\n");
109                             print_info();
110                             break;
111                         case -2 :
112                             fprintf(stderr, "width of texture file greater than the base;\nthis state is not
	processable;\n");
113                             break;
114                         case -3 :
115                             fprintf(stderr, "could not allocate memory.\n");
116                     }
117                     return -1;
118                 }
119                 Clear_Renderer();
120             }
121             free(pTexture->Data);
122         }
123         free(pBase->Data);
124     } else {
125         fprintf(stderr, "NOTIFY: must specify at least a base and a texture file!\n\n");
126         print_info();
127         return -1;
128     }
129     return 0;
130 }
131 
132 int parse_args (int argc, char **argv) {
133     int z;
134     for(z = 1; z < argc; z++)
135         if(argv[z][0] == '-')
136             switch(argv[z][1]) {
137                 case 'b' :
138                     base_file_name = argv[++z];
139                     break;
140                 case 't' :
141                     texture_file_name = argv[++z];
142                     break;
143                 case 'o' :
144                     stereo_file_name = argv[++z];
145                     break;
146                 case 'x' :
147                     pParam->Startx = atoi(argv[++z]);
148                     break;
149                 case 'y' :
150                     pParam->Starty = atoi(argv[++z]);
151                     break;
152                 case 'd' :
153                     pParam->Distance = (float) atof(argv[++z]);
154                     break;
155                 case 'e' :
156                     pParam->Eyeshift = (float) atof(argv[++z]);
157                     break;
158                 case 'a' :
159                     pParam->AA = atoi(argv[++z]);
160                     break;
161                 case 'z' :
162                     pParam->Zoom = atoi(argv[++z]);
163                     break;
164                 case 'r' :
165                     pParam->AAr = 1;
166                     break;
167                 case 'v' :
168                     verbose = 1;
169                     break;
170                 fprintf(stderr, "invalid argument '%c';\n", argv[z][1]);
171                 return -1;
172             }
173     return 0;
174 }

stereograph.c is the source file that contains main().
5751287 [rkeene@sledge /home/rkeene/devel/old/stereograph-0.16]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2000-04-12 11:50:43