Ticket #76: size.patch
File size.patch, 6.8 KB (added by , 5 years ago) |
---|
-
src/const.h
commit 2639dec30113b75c3365d307482ea72c4ec19c96 Author: boomlinde <linde.philip@gmail.com> Date: Mon May 14 19:46:19 2018 +0200 Add -size commandline argument diff --git a/src/const.h b/src/const.h index 3c4358b..ca24622 100644
a b enum ERROR_CODES 167 167 ERROR_MEMORY, ///< Out of memory 168 168 ERROR_COMMAND_LINE, ///< Error in command-line arguments (syntax, or couldn't find the file to open) 169 169 ERROR_FORBIDDEN_MODE, ///< Graphics mode requested is not supported 170 ERROR_FORBIDDEN_SIZE, ///< Image size requested is not supported 170 171 ERROR_SAVING_CFG, ///< Error while writing gfx2.cfg 171 172 ERROR_MISSING_DIRECTORY, ///< Unable to return to the original "current directory" on program exit 172 173 ERROR_INI_CORRUPTED, ///< File gfx2.ini couldn't be parsed -
src/main.c
diff --git a/src/main.c b/src/main.c index 9e65d5e..8b87c82 100644
a b 94 94 95 95 extern char Program_version[]; // generated in pversion.c 96 96 97 static int setsize_width; 98 static int setsize_height; 99 97 100 //--- Affichage de la syntaxe, et de la liste des modes vidéos disponibles --- 98 101 void Display_syntax(void) 99 102 { 100 103 int mode_index; 101 104 printf("Syntax: grafx2 [<arguments>] [<picture1>] [<picture2>]\n\n"); 102 105 printf("<arguments> can be:]\n"); 103 printf("\t-? -h -H -help for this help screen\n"); 104 printf("\t-wide to emulate a video mode with wide pixels (2x1)\n"); 105 printf("\t-tall to emulate a video mode with tall pixels (1x2)\n"); 106 printf("\t-double to emulate a video mode with double pixels (2x2)\n"); 107 printf("\t-wide2 to emulate a video mode with double wide pixels (4x2)\n"); 108 printf("\t-tall2 to emulate a video mode with double tall pixels (2x4)\n"); 109 printf("\t-triple to emulate a video mode with triple pixels (3x3)\n"); 110 printf("\t-quadruple to emulate a video mode with quadruple pixels (4x4)\n"); 111 printf("\t-rgb n to reduce RGB precision (2 to 256, 256=max precision)\n"); 112 printf("\t-gamma n to adjust Gamma correction (1 to 30, 10=no correction)\n"); 113 printf("\t-skin <filename> to use an alternate file with the menu graphics\n"); 114 printf("\t-mode <videomode> to set a video mode\n"); 106 printf("\t-? -h -H -help for this help screen\n"); 107 printf("\t-wide to emulate a video mode with wide pixels (2x1)\n"); 108 printf("\t-tall to emulate a video mode with tall pixels (1x2)\n"); 109 printf("\t-double to emulate a video mode with double pixels (2x2)\n"); 110 printf("\t-wide2 to emulate a video mode with double wide pixels (4x2)\n"); 111 printf("\t-tall2 to emulate a video mode with double tall pixels (2x4)\n"); 112 printf("\t-triple to emulate a video mode with triple pixels (3x3)\n"); 113 printf("\t-quadruple to emulate a video mode with quadruple pixels (4x4)\n"); 114 printf("\t-rgb n to reduce RGB precision (2 to 256, 256=max precision)\n"); 115 printf("\t-gamma n to adjust Gamma correction (1 to 30, 10=no correction)\n"); 116 printf("\t-skin <filename> to use an alternate file with the menu graphics\n"); 117 printf("\t-mode <videomode> to set a video mode\n"); 118 printf("\t-size <resolution> to set the image size\n"); 115 119 printf("Arguments can be prefixed either by / - or --\n"); 116 120 printf("They can also be abbreviated.\n\n"); 117 121 printf("Available video modes:\n\n"); … … void Error_function(int error_code, const char *filename, int line_number, const 179 183 printf("enabled mode, then enter the resolution menu and enable the mode you want.\n"); 180 184 printf("Check also if the 'Default_video_mode' parameter in gfx2.ini is correct.\n"); 181 185 break; 186 case ERROR_FORBIDDEN_SIZE : printf("Error: The image dimensions all have to be in the range 1-9999!\n"); 187 break; 182 188 case ERROR_COMMAND_LINE : printf("Error: Invalid parameter or file not found.\n\n"); 183 189 Display_syntax(); 184 190 break; … … enum CMD_PARAMS 217 223 CMDPARAM_PIXELRATIO_WIDE2, 218 224 CMDPARAM_RGB, 219 225 CMDPARAM_GAMMA, 220 CMDPARAM_SKIN 226 CMDPARAM_SKIN, 227 CMDPARAM_SIZE 221 228 }; 222 229 223 230 struct { … … struct { 239 246 {"wide2", CMDPARAM_PIXELRATIO_WIDE2}, 240 247 {"rgb", CMDPARAM_RGB}, 241 248 {"gamma", CMDPARAM_GAMMA}, 242 {"skin", CMDPARAM_SKIN} 249 {"skin", CMDPARAM_SKIN}, 250 {"size", CMDPARAM_SIZE}, 243 251 }; 244 252 245 253 #define ARRAY_SIZE(x) (int)(sizeof(x) / sizeof(x[0])) … … int Analyze_command_line(int argc, char * argv[], char *main_filename, char *mai 261 269 char *s = argv[index]; 262 270 int is_switch = ((strchr(s,'/') == s) || (strchr(s,'-') == s) || (strstr(s,"--") == s)); 263 271 int tmpi; 272 char *tmpcp; 264 273 int paramtype = -1; 265 274 if (is_switch) 266 275 { … … int Analyze_command_line(int argc, char * argv[], char *main_filename, char *mai 404 413 exit(0); 405 414 } 406 415 break; 416 case CMDPARAM_SIZE: 417 index++; 418 if (index<argc) 419 { 420 setsize_width = atoi(argv[index]); 421 tmpcp = strchr(argv[index], 'x'); 422 if (tmpcp == NULL) 423 tmpcp = strchr(argv[index], 'X'); 424 if (tmpcp == NULL) 425 { 426 Error(ERROR_COMMAND_LINE); 427 Display_syntax(); 428 exit(0); 429 } 430 setsize_height = atoi(++tmpcp); 431 if (setsize_height < 1 || setsize_height > 9999 || 432 setsize_width < 1 || setsize_width > 9999) 433 { 434 Error(ERROR_FORBIDDEN_SIZE); 435 Display_syntax(); 436 exit(0); 437 } 438 } 439 else 440 { 441 Error(ERROR_COMMAND_LINE); 442 Display_syntax(); 443 exit(0); 444 } 445 break; 407 446 default: 408 447 // Si ce n'est pas un paramètre, c'est le nom du fichier à ouvrir 409 448 if (file_in_command_line > 1) … … int Init_program(int argc,char * argv[]) 818 857 // Nettoyage de l'écran virtuel (les autres recevront celui-ci par copie) 819 858 memset(Main_screen,0,Main.image_width*Main.image_height); 820 859 860 // If image size was specified on command line, set that now 861 if (setsize_width != 0 && setsize_height != 0) 862 { 863 Main.image_width=setsize_width; 864 Main.image_height=setsize_height; 865 Spare.image_width=setsize_width; 866 Spare.image_height=setsize_height; 867 } 868 821 869 // Now that the backup system is there, we can store the gradients. 822 870 memcpy(Main.backups->Pages->Gradients->Range, initial_gradients.Range, sizeof(initial_gradients.Range)); 823 871 memcpy(Spare.backups->Pages->Gradients->Range, initial_gradients.Range, sizeof(initial_gradients.Range));