Ticket #76: size.patch

File size.patch, 6.8 KB (added by Philip Linde, 2 years ago)

Patch implementing -size commandline parameter

  • 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 
    167167  ERROR_MEMORY,            ///< Out of memory
    168168  ERROR_COMMAND_LINE,      ///< Error in command-line arguments (syntax, or couldn't find the file to open)
    169169  ERROR_FORBIDDEN_MODE,    ///< Graphics mode requested is not supported
     170  ERROR_FORBIDDEN_SIZE,    ///< Image size requested is not supported
    170171  ERROR_SAVING_CFG,        ///< Error while writing gfx2.cfg
    171172  ERROR_MISSING_DIRECTORY, ///< Unable to return to the original "current directory" on program exit
    172173  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  
    9494
    9595extern char Program_version[]; // generated in pversion.c
    9696
     97static int setsize_width;
     98static int setsize_height;
     99
    97100//--- Affichage de la syntaxe, et de la liste des modes vidéos disponibles ---
    98101void Display_syntax(void)
    99102{
    100103  int mode_index;
    101104  printf("Syntax: grafx2 [<arguments>] [<picture1>] [<picture2>]\n\n");
    102105  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");
    115119  printf("Arguments can be prefixed either by / - or --\n");
    116120  printf("They can also be abbreviated.\n\n");
    117121  printf("Available video modes:\n\n");
    void Error_function(int error_code, const char *filename, int line_number, const 
    179183                                       printf("enabled mode, then enter the resolution menu and enable the mode you want.\n");
    180184                                       printf("Check also if the 'Default_video_mode' parameter in gfx2.ini is correct.\n");
    181185                                       break;
     186      case ERROR_FORBIDDEN_SIZE      : printf("Error: The image dimensions all have to be in the range 1-9999!\n");
     187                                       break;
    182188      case ERROR_COMMAND_LINE     : printf("Error: Invalid parameter or file not found.\n\n");
    183189                                       Display_syntax();
    184190                                       break;
    enum CMD_PARAMS 
    217223    CMDPARAM_PIXELRATIO_WIDE2,
    218224    CMDPARAM_RGB,
    219225    CMDPARAM_GAMMA,
    220     CMDPARAM_SKIN
     226    CMDPARAM_SKIN,
     227    CMDPARAM_SIZE
    221228};
    222229
    223230struct {
    struct { 
    239246    {"wide2", CMDPARAM_PIXELRATIO_WIDE2},
    240247    {"rgb", CMDPARAM_RGB},
    241248    {"gamma", CMDPARAM_GAMMA},
    242     {"skin", CMDPARAM_SKIN}
     249    {"skin", CMDPARAM_SKIN},
     250    {"size", CMDPARAM_SIZE},
    243251};
    244252
    245253#define ARRAY_SIZE(x) (int)(sizeof(x) / sizeof(x[0]))
    int Analyze_command_line(int argc, char * argv[], char *main_filename, char *mai 
    261269    char *s = argv[index];
    262270    int is_switch = ((strchr(s,'/') == s) || (strchr(s,'-') == s) || (strstr(s,"--") == s));
    263271    int tmpi;
     272    char *tmpcp;
    264273    int paramtype = -1;
    265274    if (is_switch)
    266275    {
    int Analyze_command_line(int argc, char * argv[], char *main_filename, char *mai 
    404413          exit(0);
    405414        }
    406415        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;
    407446      default:
    408447        // Si ce n'est pas un paramètre, c'est le nom du fichier à ouvrir
    409448        if (file_in_command_line > 1)
    int Init_program(int argc,char * argv[]) 
    818857  // Nettoyage de l'écran virtuel (les autres recevront celui-ci par copie)
    819858  memset(Main_screen,0,Main.image_width*Main.image_height);
    820859
     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
    821869  // Now that the backup system is there, we can store the gradients.
    822870  memcpy(Main.backups->Pages->Gradients->Range, initial_gradients.Range, sizeof(initial_gradients.Range));
    823871  memcpy(Spare.backups->Pages->Gradients->Range, initial_gradients.Range, sizeof(initial_gradients.Range));