"Fossies" - the Fresh Open Source Software Archive

Member "sip-0.12.1/src/mogrify_int.c" (19 Sep 2013, 64831 Bytes) of package /linux/privat/sip-0.12.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "mogrify_int.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 0.5.6_vs_0.12.1.

    1 /*
    2  * -------------------------------------------------------------------------
    3  * SIP - Scilab Image Processing toolbox
    4  * Copyright (C) 2002-2009  Ricardo Fabbri
    5  *
    6  * This program is free software; you can redistribute it and/or modify
    7  * it under the terms of the GNU General Public License as published by
    8  * the Free Software Foundation; either version 2 of the License, or
    9  * (at your option) any later version.
   10  * 
   11  * This program is distributed in the hope that it will be useful,
   12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  * GNU General Public License for more details.
   15  * 
   16  * You should have received a copy of the GNU General Public License
   17  * along with this program; if not, write to the Free Software
   18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   19  * -------------------------------------------------------------------------
   20  */ 
   21 #include <string.h>
   22 #include <stdio.h>
   23 #include <time.h>
   24 #include <sys/types.h>
   25 #include "sip_common.h"
   26 
   27 
   28 static bool
   29 check_argv_validity(ImageInfo *image_info, char **argv, int *argc, ExceptionInfo *exception);
   30 
   31 /*-----------------------------------------------------------------
   32  * [imout] = mogrify(im, argv);
   33  * [imout] = mogrify(imRGB, argv);
   34  * [imout,map] = mogrify(im, I, argv);
   35  *
   36  * Interface between imagemagick's MogrifyImage and scilab.
   37  * TODO
   38  *    - procedurize 2nd part (return Imagemagick -> Scilab)
   39  *    - upon return of an indexed image, will the user know how 
   40  *    many output variables there are? ImageMagick always returns 
   41  *    DirectClass after its operations??
   42  *    
   43  * $Revision: 1.4 $ $Date: 2009-03-29 21:34:48 $
   44  *-----------------------------------------------------------------*/
   45 SipExport int 
   46 mogrify_int(char *fname)
   47 {
   48    int   mogrify_check_args(char *fname),
   49          rim, cim, pim,
   50          rimout, cimout, 
   51          rargv, cargv,
   52          nv, argc, argtype,
   53          minlhs=1, maxlhs=2, minrhs=1, maxrhs=3;
   54    char **argv;
   55    bool stat; 
   56    double *pimout;
   57    HyperMat *Im;
   58 
   59    /* ImageMagick variables */
   60    ExceptionInfo  exception;
   61    Image          *image;
   62    ImageInfo      *image_info;
   63    PixelPacket    *pix;
   64 
   65 
   66    CheckRhs(minrhs,maxrhs); CheckLhs(minlhs,maxlhs);
   67    argtype = mogrify_check_args(fname);
   68    if (!argtype) // error messages were already issued
   69       return false; 
   70 
   71    /* --- Pass scilab structures to IM --- */
   72    
   73    InitializeMagick(NULL);
   74    GetExceptionInfo(&exception);
   75    image_info=CloneImageInfo((ImageInfo *) NULL);
   76    image=AllocateImage(image_info);
   77   
   78    nv = 1;
   79    switch (argtype) {
   80       case ARG_2D:
   81             GetRhsVar(nv++, "d", &rim, &cim, &pim);
   82             stat = sci_2D_double_matrix_to_magick(fname, pim, rim, cim, image, &pix);
   83             if (!stat) 
   84                return false;
   85             break;
   86       case ARG_3D:
   87             stat = sci_3D_double_hypermat_to_magick(fname,nv++,image,&pix); 
   88             if (!stat) 
   89                return false;
   90             break;
   91 
   92       case ARG_INDEX_MAP:
   93             stat = sci_index_map_to_magick(fname, nv, image, &pix);
   94             if (!stat) 
   95                return false;
   96             nv+=2;
   97             break;
   98 
   99       default:
  100             sip_error("invalid argument type");
  101    }
  102 
  103    /* --- Call ImageMagick's Mogrify --- */
  104 
  105    GetRhsVar(nv++, "S", &rargv, &cargv, &argv);  
  106    argc = rargv*cargv;
  107 
  108    stat = check_argv_validity(image_info, argv, &argc, &exception);
  109    if(!stat) {
  110       fprintf(stderr,"%s: ",fname);
  111       Scierror(999,"");
  112       sciprint("%s: ",fname);
  113       GetImageException(image,&exception);                                  
  114       if( (exception.reason != NULL)  ) {
  115          if (strcmp(exception.reason,"UnrecognizedOption") == 0) {
  116             sciprint("argv parameter %d unrecognized",argc);
  117             fprintf(stderr,"argv parameter %d unrecognized",argc);
  118          } else {
  119             fprintf(stderr,"%s (near argv parameter %d)",
  120                SipGetLocaleExceptionMessage(exception.severity,exception.reason),argc);
  121             sciprint("%s (near argv parameter %d)",
  122                SipGetLocaleExceptionMessage(exception.severity,exception.reason),argc);
  123          }
  124          if (exception.description != NULL)
  125             fprintf(stderr,": %s",
  126                SipGetLocaleExceptionMessage(exception.severity,exception.description));
  127             sciprint(": %s",
  128                SipGetLocaleExceptionMessage(exception.severity,exception.description));
  129          fprintf(stderr,".\n");
  130          sciprint(".\n\r");
  131       } else {
  132          fprintf(stderr,"unknown reason (near argv parameter %d).\n",argc);
  133          sciprint("unknown reason (near argv parameter %d).\n\r",argc);
  134       }
  135 
  136       /* clean up */
  137       DestroyImageInfo(image_info);
  138       DestroyImage(image);
  139       DestroyExceptionInfo(&exception);
  140       DestroyMagick();
  141       return false;
  142    }
  143 
  144 #ifdef SIP_HAVE_MogrifyImage_5args
  145    stat = MogrifyImage(image_info, argc, argv, &image,&exception);
  146 #else
  147    stat = MogrifyImage(image_info, argc, argv, &image);
  148    GetImageException(image,&exception);
  149 #endif
  150    if(!stat || exception.severity != UndefinedException) 
  151       SIP_MAGICK_ERROR;
  152 
  153    FreeRhsSVar(argv);
  154 
  155    /* --- Return image to SciLab --- */
  156 
  157 
  158    rimout  = image->rows; cimout = image->columns;
  159 
  160    pix = GetImagePixels(image,0,0,cimout,rimout);
  161    if(!pix)
  162       SIP_MAGICK_ERROR;
  163 
  164    switch(image->storage_class) {
  165       case DirectClass:
  166          if ( IsMonochromeImage(image, &exception) ) {
  167             stat = magick_binary_image_to_double_array(fname,pix,&pimout, rimout, cimout);
  168             if (!stat) return false;
  169             CreateVarFromPtr(nv, "d",&rimout,&cimout,&pimout);  
  170             LhsVar(1) = nv++;
  171             free(pimout);
  172          } else if ( IsGrayImage(image,&exception) ) {
  173             stat = magick_grayscale_image_to_double_array(fname,pix,&pimout, rimout, cimout);
  174             if (!stat) return false;
  175             CreateVarFromPtr(nv, "d",&rimout,&cimout,&pimout);  
  176             LhsVar(1) = nv++;
  177             free(pimout);
  178          } else {
  179             stat= magick_truecolor_image_to_double_hypermat(fname,pix,&Im,rimout,cimout);
  180             if (!stat) return false;
  181             CreateHMat(nv,Im);
  182             LhsVar(1) = nv++;
  183             free_sci_tru_img(&Im);
  184          }
  185          break;
  186      case PseudoClass: 
  187          stat= magick_index_map_to_sci_dbl(fname,image,nv);
  188          if (!stat) return false;
  189          LhsVar(1) = nv;
  190          LhsVar(2) = nv+1;
  191          break;
  192      default: 
  193         sip_error("unknown color class");
  194         break;
  195    }
  196 
  197 
  198    /* Terminate Imagemagick */
  199    DestroyImageInfo(image_info);
  200    DestroyImage(image);
  201    DestroyExceptionInfo(&exception);
  202    DestroyMagick();
  203    return true;
  204 }
  205 
  206 /*-----------------------------------------------------------
  207  * check_args:                                                
  208  *    Certify the correctness of the number and type of
  209  *    arguments. 
  210  *    The returning code indicates the sematic type of the
  211  *    argument (non-zero), or invalid argument (zero)
  212  *    - @@@ I guess this function could be less pedantic
  213  *-----------------------------------------------------------*/
  214 int 
  215 mogrify_check_args(char *fname)
  216 {
  217 
  218    if (Rhs == 2) {  // mogrify(image, string)
  219       if (VarType(2) != STRING)
  220          sip_error("argument 2 must be a string");
  221       switch (VarType(1)) {
  222          case USUALMATRIX: return ARG_2D; 
  223          case HYPERMATRIX: return ARG_3D; 
  224          default: 
  225             sip_error("argument 1 must be matrix or RGB hypermatrix.");
  226       }
  227    } 
  228 
  229    /* Rhs == 3  --> mogrify(image,map,string) */
  230    if(VarType(3) != STRING) 
  231       sip_error("argument 3 must be a string");
  232    if((VarType(1) != USUALMATRIX) || (VarType(2) != USUALMATRIX))
  233       sip_error("first two arguments must be arrays");
  234 
  235    return ARG_INDEX_MAP;
  236 }
  237 
  238 bool
  239 check_argv_validity(ImageInfo *image_info, char **argv, int *pargc, ExceptionInfo *exception)
  240 {
  241 #define ThrowMogrifyException(code,reason,description) \
  242 { \
  243   (void) ThrowException(exception,code,reason,description); \
  244   *pargc = i+1; \
  245   return false; \
  246 }
  247    int i, argc=*pargc;
  248    unsigned global_colormap;
  249    long x;
  250    char *option, *format;
  251 
  252    for (i=0; i < argc; ++i) {
  253       option = argv[i];
  254       switch (option[1])
  255       {
  256         case 'a':
  257         {
  258           if (LocaleCompare("affine",option+1) == 0)
  259             {
  260               if (*option == '-')
  261                 {
  262                   i++;
  263                   if ((i == argc) || !IsGeometry(argv[i]))
  264                     ThrowMogrifyException(OptionError,"MissingMatrix",option);
  265                 }
  266               break;
  267             }
  268           if (LocaleCompare("antialias",option+1) == 0)
  269             {
  270               image_info->antialias=(*option == '-');
  271               break;
  272             }
  273           /*
  274           if (LocaleCompare("authenticate",option+1) == 0)
  275             {
  276               (void) CloneString(&image_info->authenticate,(char *) NULL);
  277               if (*option == '-')
  278                 {
  279                   i++;
  280                   if (i == argc)
  281                     ThrowMogrifyException(OptionError,"MissingPassword",option);
  282                   (void) CloneString(&image_info->authenticate,argv[i]);
  283                 }
  284               break;
  285             }
  286             */
  287           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
  288         }
  289         case 'b':
  290         {
  291           if (LocaleCompare("background",option+1) == 0)
  292             {
  293               if (*option == '-')
  294                 {
  295                   i++;
  296                   if (i == argc)
  297                     ThrowMogrifyException(OptionError,"MissingBackgroundColor",
  298                       option);
  299                   (void) SIP_QueryColorDatabase(argv[i],&image_info->background_color,
  300                     exception);
  301                 }
  302               break;
  303             }
  304           if (LocaleCompare("black-threshold",option+1) == 0)
  305             {
  306               if (*option == '-')
  307                 {
  308                   i++;
  309                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
  310                     ThrowMogrifyException(OptionError,"MissingThreshold",option);
  311                 }
  312               break;
  313             }
  314           if (LocaleCompare("blue-primary",option+1) == 0)
  315             {
  316               if (*option == '-')
  317                 {
  318                   i++;
  319                   if ((i == argc) || !IsGeometry(argv[i]))
  320                     ThrowMogrifyException(OptionError,"MissingPoint",option);
  321                 }
  322               break;
  323             }
  324           if (LocaleCompare("blur",option+1) == 0)
  325             {
  326               i++;
  327               if ((i == argc) || !IsGeometry(argv[i]))
  328                 ThrowMogrifyException(OptionError,"MissingGeometry",option);
  329               break;
  330             }
  331           if (LocaleCompare("border",option+1) == 0)
  332             {
  333               if (*option == '-')
  334                 {
  335                   i++;
  336                   if ((i == argc) || !IsGeometry(argv[i]))
  337                     ThrowMogrifyException(OptionError,"MissingGeometry",option);
  338                 }
  339               break;
  340             }
  341           if (LocaleCompare("bordercolor",option+1) == 0)
  342             {
  343               if (*option == '-')
  344                 {
  345                   i++;
  346                   if (i == argc)
  347                     ThrowMogrifyException(OptionError,"MissingBorderColor",
  348                       option);
  349                   (void) SIP_QueryColorDatabase(argv[i],&image_info->border_color,
  350                     exception);
  351                 }
  352               break;
  353             }
  354           if (LocaleCompare("box",option+1) == 0)
  355             {
  356               if (*option == '-')
  357                 {
  358                   i++;
  359                   if (i == argc)
  360                     ThrowMogrifyException(OptionError,"MissingColors",option);
  361                 }
  362               break;
  363             }
  364           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
  365         }
  366         case 'c':
  367         {
  368            /*
  369           if (LocaleCompare("cache",option+1) == 0)
  370             {
  371               if (*option == '-')
  372                 {
  373                   i++;
  374                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
  375                     ThrowMogrifyException(OptionError,"MissingThreshold",option);
  376                   SetMagickResourceLimit(MemoryResource,atol(argv[i]));
  377                   SetMagickResourceLimit(MapResource,2*atol(argv[i]));
  378                 }
  379               break;
  380             }
  381             */
  382           if (LocaleCompare("channel",option+1) == 0)
  383             {
  384               if (*option == '-')
  385                 {
  386                   ChannelType
  387                     channel;
  388 
  389                   i++;
  390                   if (i == argc)
  391                     ThrowMogrifyException(OptionError,"MissingType",option);
  392                   option=argv[i];
  393                   channel=UndefinedChannel;
  394                  if (LocaleCompare("Red",option) == 0)
  395                    channel=RedChannel;
  396                  if (LocaleCompare("Cyan",option) == 0)
  397                    channel=CyanChannel;
  398                  if (LocaleCompare("Green",option) == 0)
  399                    channel=GreenChannel;
  400                  if (LocaleCompare("Magenta",option) == 0)
  401                    channel=MagentaChannel;
  402                  if (LocaleCompare("Blue",option) == 0)
  403                    channel=BlueChannel;
  404                  if (LocaleCompare("Yellow",option) == 0)
  405                    channel=YellowChannel;
  406                  if (LocaleCompare("Opacity",option) == 0)
  407                    channel=OpacityChannel;
  408                  if (LocaleCompare("Black",option) == 0)
  409                    channel=BlackChannel;
  410                  if (LocaleCompare("Matte",option) == 0)
  411                    channel=MatteChannel;
  412                   if (channel == UndefinedChannel)
  413                     ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
  414                       option);
  415                 }
  416               break;
  417             }
  418           if (LocaleCompare("charcoal",option+1) == 0)
  419             {
  420               if (*option == '-')
  421                 {
  422                   i++;
  423                   if ((i == argc) || !IsGeometry(argv[i]))
  424                     ThrowMogrifyException(OptionError,"MissingPaintRadius",
  425                       option);
  426                 }
  427               break;
  428             }
  429           if (LocaleCompare("chop",option+1) == 0)
  430             {
  431               if (*option == '-')
  432                 {
  433                   i++;
  434                   if ((i == argc) || !IsGeometry(argv[i]))
  435                     ThrowMogrifyException(OptionError,"MissingGeometry",option);
  436                 }
  437               break;
  438             }
  439           if (LocaleCompare("colorize",option+1) == 0)
  440             {
  441               if (*option == '-')
  442                 {
  443                   i++;
  444                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
  445                     ThrowMogrifyException(OptionError,"MissingColorizeValue",
  446                       option);
  447                 }
  448               break;
  449             }
  450           if (LocaleCompare("colors",option+1) == 0)
  451             {
  452               if (*option == '-')
  453                 {
  454                   i++;
  455                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
  456                     ThrowMogrifyException(OptionError,"MissingColors",option);
  457                 }
  458               break;
  459             }
  460           if (LocaleCompare("colorspace",option+1) == 0)
  461             {
  462               if (*option == '-')
  463                 {
  464                   i++;
  465                   if (i == argc)
  466                     ThrowMogrifyException(OptionError,"MissingType",option);
  467                   option=argv[i];
  468                   image_info->colorspace=UndefinedColorspace;
  469                   if (LocaleCompare("cmyk",option) == 0)
  470                     image_info->colorspace=CMYKColorspace;
  471                   if (LocaleCompare("gray",option) == 0)
  472                     image_info->colorspace=GRAYColorspace;
  473 #ifdef SIP_HAVE_HSLCOLORSPACE
  474                   if (LocaleCompare("hsl",option) == 0)
  475                     image_info->colorspace=HSLColorspace;
  476 #endif
  477 #ifdef SIP_HAVE_HWBCOLORSPACE
  478                   if (LocaleCompare("hwb",option) == 0)
  479                     image_info->colorspace=HWBColorspace;
  480 #endif
  481                   if (LocaleCompare("ohta",option) == 0)
  482                     image_info->colorspace=OHTAColorspace;
  483                   if (LocaleCompare("rgb",option) == 0)
  484                     image_info->colorspace=RGBColorspace;
  485                   if (LocaleCompare("srgb",option) == 0)
  486                     image_info->colorspace=sRGBColorspace;
  487                   if (LocaleCompare("transparent",option) == 0)
  488                     image_info->colorspace=TransparentColorspace;
  489                   if (LocaleCompare("xyz",option) == 0)
  490                     image_info->colorspace=XYZColorspace;
  491                   if (LocaleCompare("ycbcr",option) == 0)
  492                     image_info->colorspace=YCbCrColorspace;
  493                   if (LocaleCompare("ycc",option) == 0)
  494                     image_info->colorspace=YCCColorspace;
  495                   if (LocaleCompare("yiq",option) == 0)
  496                     image_info->colorspace=YIQColorspace;
  497                   if (LocaleCompare("ypbpr",option) == 0)
  498                     image_info->colorspace=YPbPrColorspace;
  499                   if (LocaleCompare("yuv",option) == 0)
  500                     image_info->colorspace=YUVColorspace;
  501                   if (image_info->colorspace == UndefinedColorspace)
  502                     ThrowMogrifyException(OptionError,"UnrecognizedColorspace",option);
  503                 }
  504               break;
  505             }
  506           if (LocaleCompare("comment",option+1) == 0)
  507             {
  508               if (*option == '-')
  509                 {
  510                   i++;
  511                   if (i == argc)
  512                     ThrowMogrifyException(OptionError,"MissingComment",option);
  513                 }
  514               break;
  515             }
  516           if (LocaleCompare("contrast",option+1) == 0)
  517             break;
  518           if (LocaleCompare("convolve",option+1) == 0)
  519             {
  520               if (*option == '-')
  521                 {
  522                   i++;
  523                   if ((i == (argc-1)) || !IsGeometry(argv[i]))
  524                     ThrowMogrifyException(OptionError,"MissingCoefficients",
  525                       option);
  526                 }
  527               break;
  528             }
  529           if (LocaleCompare("crop",option+1) == 0)
  530             {
  531               if (*option == '-')
  532                 {
  533                   i++;
  534                   if ((i == argc) || !IsGeometry(argv[i]))
  535                     ThrowMogrifyException(OptionError,"MissingGeometry",option);
  536                 }
  537               break;
  538             }
  539           if (LocaleCompare("cycle",option+1) == 0)
  540             {
  541               if (*option == '-')
  542                 {
  543                   i++;
  544                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
  545                     ThrowMogrifyException(OptionError,"MissingCycleAmount",
  546                       option);
  547                 }
  548               break;
  549             }
  550           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
  551         }
  552         case 'd':
  553         {
  554            /*
  555           if (LocaleCompare("debug",option+1) == 0)
  556             {
  557               (void) SetLogEventMask("None");
  558               if (*option == '-')
  559                 {
  560                   i++;
  561                   if (i == argc)
  562                     ThrowMogrifyException(OptionError,"MissingEventMask",option);
  563                   (void) SetLogEventMask(argv[i]);
  564                 }
  565               break;
  566             }
  567             */
  568           if (LocaleCompare("delay",option+1) == 0)
  569             {
  570               if (*option == '-')
  571                 {
  572                   i++;
  573                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
  574                     ThrowMogrifyException(OptionError,"MissingDelay",option);
  575                 }
  576               break;
  577             }
  578           if (LocaleCompare("density",option+1) == 0)
  579             {
  580               (void) CloneString(&image_info->density,(char *) NULL);
  581               if (*option == '-')
  582                 {
  583                   i++;
  584                   if ((i == argc) || !IsGeometry(argv[i]))
  585                     ThrowMogrifyException(OptionError,"MissingGeometry",option);
  586                   (void) CloneString(&image_info->density,argv[i]);
  587                 }
  588               break;
  589             }
  590           if (LocaleCompare("depth",option+1) == 0)
  591             {
  592               image_info->depth=QuantumDepth;
  593               if (*option == '-')
  594                 {
  595                   i++;
  596                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
  597                     ThrowMogrifyException(OptionError,"MissingImageDepth",option);
  598                   image_info->depth=atol(argv[i]);
  599                 }
  600               break;
  601             }
  602           if (LocaleCompare("despeckle",option+1) == 0)
  603             break;
  604           if (LocaleCompare("display",option+1) == 0)
  605             {
  606               (void) CloneString(&image_info->server_name,(char *) NULL);
  607               if (*option == '-')
  608                 {
  609                   i++;
  610                   if (i == argc)
  611                     ThrowMogrifyException(OptionError,"MissingServerName",option);
  612                   (void) CloneString(&image_info->server_name,argv[i]);
  613                 }
  614               break;
  615             }
  616           if (LocaleCompare("dispose",option+1) == 0)
  617             {
  618               if (*option == '-')
  619                 {
  620                   i++;
  621                   if (i == argc)
  622                     ThrowMogrifyException(OptionError,"MissingDisposeMethod",
  623                       option);
  624                   if ((LocaleCompare("0",option) != 0) &&
  625                       (LocaleCompare("1",option) != 0) &&
  626                       (LocaleCompare("2",option) != 0) &&
  627                       (LocaleCompare("3",option) != 0) &&
  628                       (LocaleCompare("Undefined",option) != 0) &&
  629                       (LocaleCompare("None",option) != 0) &&
  630                       (LocaleCompare("Background",option) != 0) &&
  631                       (LocaleCompare("Previous",option) != 0))
  632                     ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
  633                       option);
  634                 }
  635               break;
  636             }
  637           if (LocaleCompare("dither",option+1) == 0)
  638             {
  639               image_info->dither=(*option == '-');
  640               break;
  641             }
  642           if (LocaleCompare("draw",option+1) == 0)
  643             {
  644               if (*option == '-')
  645                 {
  646                   i++;
  647                   if (i == argc)
  648                     ThrowMogrifyException(OptionError,"MissingDrawingPrimitive",
  649                       option);
  650                 }
  651               break;
  652             }
  653           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
  654         }
  655         case 'e':
  656         {
  657           if (LocaleCompare("edge",option+1) == 0)
  658             {
  659               if (*option == '-')
  660                 {
  661                   i++;
  662                   if ((i == argc) || !IsGeometry(argv[i]))
  663                     ThrowMogrifyException(OptionError,"MissingPaintRadius",
  664                       option);
  665                 }
  666               break;
  667             }
  668           if (LocaleCompare("emboss",option+1) == 0)
  669             {
  670               if (*option == '-')
  671                 {
  672                   i++;
  673                   if ((i == argc) || !IsGeometry(argv[i]))
  674                     ThrowMogrifyException(OptionError,"MissingEmbossRadius",
  675                       option);
  676                 }
  677               break;
  678             }
  679           if (LocaleCompare("encoding",option+1) == 0)
  680             {
  681               if (*option == '-')
  682                 {
  683                   i++;
  684                   if (i == argc)
  685                     ThrowMogrifyException(OptionError,"MissingEncodingType",
  686                       option);
  687                 }
  688               break;
  689             }
  690           if (LocaleCompare("enhance",option+1) == 0)
  691             break;
  692           if (LocaleCompare("equalize",option+1) == 0)
  693             break;
  694           /* Removed to remain backward-compatible to 5.5.1
  695           if (LocaleCompare("extract",option+1) == 0)
  696             {
  697               (void) CloneString(&image_info->extract,(char *) NULL);
  698               if (*option == '-')
  699                 {
  700                   i++;
  701                   if ((i == argc) || !IsGeometry(argv[i]))
  702                     ThrowMogrifyException(OptionError,"MissingGeometry",option);
  703                   (void) CloneString(&image_info->extract,argv[i]);
  704                 }
  705               break;
  706             }
  707          */
  708           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
  709         }
  710         case 'f':
  711         {
  712           if (LocaleCompare("fill",option+1) == 0)
  713             {
  714               (void) SIP_QueryColorDatabase("none",&image_info->pen,exception);
  715               if (*option == '-')
  716                 {
  717                   i++;
  718                   if (i == argc)
  719                     ThrowMogrifyException(OptionError,"MissingFillColor",option);
  720                   (void) SIP_QueryColorDatabase(argv[i],&image_info->pen,exception);
  721                 }
  722               break;
  723             }
  724           if (LocaleCompare("filter",option+1) == 0)
  725             {
  726               if (*option == '-')
  727                 {
  728                   FilterTypes
  729                     filter;
  730 
  731                   i++;
  732                   if (i == argc)
  733                     ThrowMogrifyException(OptionError,"MissingType",option);
  734                   option=argv[i];
  735                   filter=UndefinedFilter;
  736                   if (LocaleCompare("Point",option) == 0)
  737                     filter=PointFilter;
  738                   if (LocaleCompare("Box",option) == 0)
  739                     filter=BoxFilter;
  740                   if (LocaleCompare("Triangle",option) == 0)
  741                     filter=TriangleFilter;
  742                   if (LocaleCompare("Hermite",option) == 0)
  743                     filter=HermiteFilter;
  744                   if (LocaleCompare("Hanning",option) == 0)
  745                     filter=HanningFilter;
  746                   if (LocaleCompare("Hamming",option) == 0)
  747                     filter=HammingFilter;
  748                   if (LocaleCompare("Blackman",option) == 0)
  749                     filter=BlackmanFilter;
  750                   if (LocaleCompare("Gaussian",option) == 0)
  751                     filter=GaussianFilter;
  752                   if (LocaleCompare("Quadratic",option) == 0)
  753                     filter=QuadraticFilter;
  754                   if (LocaleCompare("Cubic",option) == 0)
  755                     filter=CubicFilter;
  756                   if (LocaleCompare("Catrom",option) == 0)
  757                     filter=CatromFilter;
  758                   if (LocaleCompare("Mitchell",option) == 0)
  759                     filter=MitchellFilter;
  760                   if (LocaleCompare("Lanczos",option) == 0)
  761                     filter=LanczosFilter;
  762                   if (LocaleCompare("Bessel",option) == 0)
  763                     filter=BesselFilter;
  764                   if (LocaleCompare("Sinc",option) == 0)
  765                     filter=SincFilter;
  766                   if (filter == UndefinedFilter)
  767                     ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
  768                       option);
  769                 }
  770               break;
  771             }
  772           if (LocaleCompare("flip",option+1) == 0)
  773             break;
  774           if (LocaleCompare("flop",option+1) == 0)
  775             break;
  776           if (LocaleCompare("font",option+1) == 0)
  777             {
  778               (void) CloneString(&image_info->font,(char *) NULL);
  779               if (*option == '-')
  780                 {
  781                   i++;
  782                   if (i == argc)
  783                     ThrowMogrifyException(OptionError,"MissingFontName",
  784                       option);
  785                   (void) CloneString(&image_info->font,argv[i]);
  786                 }
  787               break;
  788             }
  789           if (LocaleCompare("format",option+1) == 0)
  790             {
  791               (void) CloneString(&format,(char *) NULL);
  792               if (*option == '-')
  793                 {
  794                   i++;
  795                   if (i == argc)
  796                     ThrowMogrifyException(OptionError,"MissingImageType",option);
  797                   (void) CloneString(&format,argv[i]);
  798                   (void) strncpy(image_info->filename,format,MaxTextExtent-1);
  799                   (void) strcat(image_info->filename,":");
  800                   (void) SetImageInfo(image_info,false,exception);
  801                   if (*image_info->magick == '\0')
  802                     ThrowMogrifyException(OptionError,
  803                       "UnrecognizedImageFormat",format);
  804                 }
  805               break;
  806             }
  807           if (LocaleCompare("frame",option+1) == 0)
  808             {
  809               if (*option == '-')
  810                 {
  811                   i++;
  812                   if ((i == argc) || !IsGeometry(argv[i]))
  813                     ThrowMogrifyException(OptionError,"MissingGeometry",
  814                       option);
  815                 }
  816               break;
  817             }
  818           if (LocaleCompare("fuzz",option+1) == 0)
  819             {
  820               image_info->fuzz=0.0;
  821               if (*option == '-')
  822                 {
  823                   i++;
  824                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
  825                     ThrowMogrifyException(OptionError,"MissingDistance",option);
  826 #ifdef SIP_HAVE_StringToDouble
  827                   image_info->fuzz=StringToDouble(argv[i],MaxRGB);
  828 #else
  829                   // To make it link against Ubuntu 11.04's seemingly broken 
  830                   // ImageMagick:
  831                   fprintf(stderr,"Option -fuzz %s temporarily hardcoded to 0.0 in your system due to broken ImageMagick libs\n", argv[i]);
  832 #endif
  833                 }
  834               break;
  835             }
  836           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
  837         }
  838         case 'g':
  839         {
  840           if (LocaleCompare("gamma",option+1) == 0)
  841             {
  842               i++;
  843               if ((i == argc) || !IsGeometry(argv[i]))
  844                 ThrowMogrifyException(OptionError,"MissingImageGamma",option);
  845               break;
  846             }
  847           if (LocaleCompare("gaussian",option+1) == 0)
  848             {
  849               i++;
  850               if ((i == argc) || !IsGeometry(argv[i]))
  851                 ThrowMogrifyException(OptionError,"MissingGeometry",option);
  852               break;
  853             }
  854           if (LocaleCompare("geometry",option+1) == 0)
  855             {
  856               if (*option == '-')
  857                 {
  858                   i++;
  859                   if ((i == argc) || !IsGeometry(argv[i]))
  860                     ThrowMogrifyException(OptionError,"MissingGeometry",option);
  861                 }
  862               break;
  863             }
  864           if (LocaleCompare("gravity",option+1) == 0)
  865             {
  866               GravityType
  867                 gravity;
  868 
  869               gravity=(GravityType) ForgetGravity;
  870               if (*option == '-')
  871                 {
  872                   i++;
  873                   if (i == argc)
  874                     ThrowMogrifyException(OptionError,"MissingType",option);
  875                   option=argv[i];
  876                   if (LocaleCompare("NorthWest",option) == 0)
  877                     gravity=(GravityType) NorthWestGravity;
  878                   if (LocaleCompare("North",option) == 0)
  879                     gravity=(GravityType) NorthGravity;
  880                   if (LocaleCompare("NorthEast",option) == 0)
  881                     gravity=(GravityType) NorthEastGravity;
  882                   if (LocaleCompare("West",option) == 0)
  883                     gravity=(GravityType) WestGravity;
  884                   if (LocaleCompare("Center",option) == 0)
  885                     gravity=(GravityType) CenterGravity;
  886                   if (LocaleCompare("East",option) == 0)
  887                     gravity=(GravityType) EastGravity;
  888                   if (LocaleCompare("SouthWest",option) == 0)
  889                     gravity=(GravityType) SouthWestGravity;
  890                   if (LocaleCompare("South",option) == 0)
  891                     gravity=(GravityType) SouthGravity;
  892                   if (LocaleCompare("SouthEast",option) == 0)
  893                     gravity=(GravityType) SouthEastGravity;
  894                   if (gravity == (GravityType) ForgetGravity)
  895                     ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
  896                       option);
  897                 }
  898               break;
  899             }
  900           if (LocaleCompare("green-primary",option+1) == 0)
  901             {
  902               if (*option == '-')
  903                 {
  904                   i++;
  905                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
  906                     ThrowMogrifyException(OptionError,"MissingPoint",option);
  907                 }
  908               break;
  909             }
  910           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
  911         }
  912         case 'h':
  913         {
  914           if (LocaleCompare("help",option+1) == 0)
  915             break;
  916           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
  917         }
  918         case 'i':
  919         {
  920           if (LocaleCompare("implode",option+1) == 0)
  921             {
  922               if (*option == '-')
  923                 {
  924                   i++;
  925                   if ((i == argc) || !IsGeometry(argv[i]))
  926                     ThrowMogrifyException(OptionError,"MissingImplodeAmount",
  927                       option);
  928                 }
  929               break;
  930             }
  931           if (LocaleCompare("interlace",option+1) == 0)
  932             {
  933               image_info->interlace=NoInterlace;
  934               if (*option == '-')
  935                 {
  936                   i++;
  937                   if (i == argc)
  938                     ThrowMogrifyException(OptionError,"MissingType",option);
  939                   option=argv[i];
  940                   image_info->interlace=UndefinedInterlace;
  941                   if (LocaleCompare("None",option) == 0)
  942                     image_info->interlace=NoInterlace;
  943                   if (LocaleCompare("Line",option) == 0)
  944                     image_info->interlace=LineInterlace;
  945                   if (LocaleCompare("Plane",option) == 0)
  946                     image_info->interlace=PlaneInterlace;
  947                   if (LocaleCompare("Partition",option) == 0)
  948                     image_info->interlace=PartitionInterlace;
  949                   if (image_info->interlace == UndefinedInterlace)
  950                     ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
  951                       option);
  952                 }
  953               break;
  954             }
  955           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
  956         }
  957         case 'l':
  958         {
  959           if (LocaleCompare("label",option+1) == 0)
  960             {
  961               if (*option == '-')
  962                 {
  963                   i++;
  964                   if (i == argc)
  965                     ThrowMogrifyException(OptionError,"MissingImageLabel",
  966                       option);
  967                 }
  968               break;
  969             }
  970           if (LocaleCompare("lat",option+1) == 0)
  971             {
  972               if (*option == '-')
  973                 {
  974                   i++;
  975                   if ((i == argc) || !IsGeometry(argv[i]))
  976                     ThrowMogrifyException(OptionError,"MissingGeometry",option);
  977                 }
  978               break;
  979             }
  980           if (LocaleCompare("level",option+1) == 0)
  981             {
  982               i++;
  983               if ((i == argc) || !sscanf(argv[i],"%ld",&x))
  984                 ThrowMogrifyException(OptionError,"MissingImageLevel",option);
  985               break;
  986             }
  987           if (LocaleCompare("linewidth",option+1) == 0)
  988             {
  989               if (*option == '-')
  990                 {
  991                   i++;
  992                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
  993                     ThrowMogrifyException(OptionError,"MissingPointsize",option);
  994                 }
  995               break;
  996             }
  997           /*
  998           if (LocaleCompare("limit",option+1) == 0)
  999             {
 1000               if (*option == '-')
 1001                 {
 1002                   char
 1003                     *type;
 1004 
 1005                   i++;
 1006                   if (i == argc)
 1007                     ThrowMogrifyException(OptionError,"MissingResourceType",
 1008                       option);
 1009                   type=argv[i];
 1010                   i++;
 1011                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
 1012                     ThrowMogrifyException(OptionError,"MissingResourceLimit",
 1013                       option);
 1014                   if (LocaleCompare("disk",type) == 0)
 1015                     SetMagickResourceLimit(DiskResource,atol(argv[i]));
 1016                   else
 1017                     if (LocaleCompare("map",type) == 0)
 1018                       SetMagickResourceLimit(MapResource,atol(argv[i]));
 1019                     else
 1020                       if (LocaleCompare("memory",type) == 0)
 1021                         SetMagickResourceLimit(MemoryResource,atol(argv[i]));
 1022                       else
 1023                         ThrowMogrifyException(OptionError,
 1024                           "UnrecognizedResourceType",type);
 1025                 }
 1026               break;
 1027             }
 1028             */
 1029           if (LocaleCompare("list",option+1) == 0)
 1030             {
 1031               if (*option == '-')
 1032                 {
 1033                   i++;
 1034                   if (i == argc)
 1035                     ThrowMogrifyException(OptionError,"MissingListName",
 1036                       option);
 1037                   option=argv[i];
 1038                   switch (*option)
 1039                   {
 1040                     case 'C':
 1041                     case 'c':
 1042                     {
 1043                       if (LocaleCompare("Color",option) == 0)
 1044                         {
 1045                           (void) ListColorInfo((FILE *) NULL,exception);
 1046                           break;
 1047                         }
 1048                       ThrowMogrifyException(OptionError,"UnrecognizedListType",
 1049                         option)
 1050                     }
 1051                     case 'D':
 1052                     case 'd':
 1053                     {
 1054                       if (LocaleCompare("Delegate",option) == 0)
 1055                         {
 1056                           (void) ListDelegateInfo((FILE *) NULL,exception);
 1057                           break;
 1058                         }
 1059                       ThrowMogrifyException(OptionError,"UnrecognizedListType",
 1060                         option)
 1061                     }
 1062                     case 'F':
 1063                     case 'f':
 1064                     {
 1065                       if (LocaleCompare("Format",option) == 0)
 1066                         {
 1067                           (void) ListMagickInfo((FILE *) NULL,exception);
 1068                           break;
 1069                         }
 1070                       ThrowMogrifyException(OptionError,"UnrecognizedListType",
 1071                         option)
 1072                     }
 1073                     case 'M':
 1074                     case 'm':
 1075                     {
 1076                       if (LocaleCompare("Magic",option) == 0)
 1077                         {
 1078                           (void) ListMagicInfo((FILE *) NULL,exception);
 1079                           break;
 1080                         }
 1081                       ThrowMogrifyException(OptionError,"UnrecognizedListType",
 1082                         option)
 1083                     }
 1084                     /* Removed for compatibility with 5.5.1
 1085                     case 'R':
 1086                     case 'r':
 1087                     {
 1088                       if (LocaleCompare("Resource",option) == 0)
 1089                         {
 1090                           (void) ListMagickResourceInfo((FILE *) NULL,exception);
 1091                           break;
 1092                         }
 1093                       ThrowMogrifyException(OptionError,"UnrecognizedListType",
 1094                         option)
 1095                     }
 1096                     */
 1097                     case 'T':
 1098                     case 't':
 1099                     {
 1100                       if (LocaleCompare("Type",option) == 0)
 1101                         {
 1102                           (void) ListTypeInfo((FILE *) NULL,exception);
 1103                           break;
 1104                         }
 1105                       ThrowMogrifyException(OptionError,"UnrecognizedListType",
 1106                         option)
 1107                     }
 1108                     default:
 1109                       ThrowMogrifyException(OptionError,"UnrecognizedListType",
 1110                         option)
 1111                   }
 1112                   return true;
 1113                 }
 1114               break;
 1115             }
 1116           /* Removed for compat. with 5.5.1
 1117           if (LocaleCompare("log",option+1) == 0)
 1118             {
 1119               if (*option == '-')
 1120                 {
 1121                   i++;
 1122                   if (i == argc)
 1123                     ThrowMogrifyException(OptionError,"MissingLogFormat",option);
 1124                   (void) SetLogFormat(argv[i]);
 1125                 }
 1126               break;
 1127             }
 1128             */
 1129           if (LocaleCompare("loop",option+1) == 0)
 1130             {
 1131               if (*option == '-')
 1132                 {
 1133                   i++;
 1134                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
 1135                     ThrowMogrifyException(OptionError,"MissingIterations",option);
 1136                 }
 1137               break;
 1138             }
 1139           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
 1140         }
 1141         case 'm':
 1142         {
 1143           if (LocaleCompare("map",option+1) == 0)
 1144             {
 1145               global_colormap=(*option == '+');
 1146               if (*option == '-')
 1147                 {
 1148                   i++;
 1149                   if (i == argc)
 1150                     ThrowMogrifyException(OptionError,"MissingFilename",option);
 1151                 }
 1152               break;
 1153             }
 1154           if (LocaleCompare("mask",option+1) == 0)
 1155             {
 1156               if (*option == '-')
 1157                 {
 1158                   i++;
 1159                   if (i == argc)
 1160                     ThrowMogrifyException(OptionError,"MissingFilename",option);
 1161                 }
 1162               break;
 1163             }
 1164           if (LocaleCompare("matte",option+1) == 0)
 1165             break;
 1166           if (LocaleCompare("mattecolor",option+1) == 0)
 1167             {
 1168               if (*option == '-')
 1169                 {
 1170                   i++;
 1171                   if (i == argc)
 1172                     ThrowMogrifyException(OptionError,"MissingMatteColor",option);
 1173                   (void) SIP_QueryColorDatabase(argv[i],&image_info->matte_color,
 1174                     exception);
 1175                 }
 1176               break;
 1177             }
 1178           if (LocaleCompare("modulate",option+1) == 0)
 1179             {
 1180               if (*option == '-')
 1181                 {
 1182                   i++;
 1183                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
 1184                     ThrowMogrifyException(OptionError,"MissingImageGamma",option);
 1185                 }
 1186               break;
 1187             }
 1188           if (LocaleCompare("median",option+1) == 0)
 1189             {
 1190               if (*option == '-')
 1191                 {
 1192                   i++;
 1193                   if ((i == argc) || !IsGeometry(argv[i]))
 1194                     ThrowMogrifyException(OptionError,"MissingPaintRadius",
 1195                       option);
 1196                 }
 1197               break;
 1198             }
 1199           if (LocaleCompare("monochrome",option+1) == 0)
 1200             {
 1201               image_info->monochrome=(*option == '-');
 1202               break;
 1203             }
 1204           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
 1205         }
 1206         case 'n':
 1207         {
 1208           if (LocaleCompare("negate",option+1) == 0)
 1209             break;
 1210           if (LocaleCompare("noise",option+1) == 0)
 1211             {
 1212               if (*option == '-')
 1213                 {
 1214                   i++;
 1215                   if ((i == argc) || !IsGeometry(argv[i]))
 1216                     ThrowMogrifyException(OptionError,"MissingImageGamma",option);
 1217                 }
 1218               if (*option == '+')
 1219                 {
 1220                   i++;
 1221                   if (i == argc)
 1222                     ThrowMogrifyException(OptionError,"MissingType",option);
 1223                   option=argv[i];
 1224                   if ((LocaleCompare("Uniform",option) != 0) &&
 1225                       (LocaleCompare("Gaussian",option) != 0) &&
 1226                       (LocaleCompare("Multiplicative",option) != 0) &&
 1227                       (LocaleCompare("Impulse",option) != 0) &&
 1228                       (LocaleCompare("Laplacian",option) != 0) &&
 1229                       (LocaleCompare("Poisson",option) != 0))
 1230                     ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
 1231                       option);
 1232                 }
 1233               break;
 1234             }
 1235           if (LocaleCompare("noop",option+1) == 0)
 1236             break;
 1237           if (LocaleCompare("normalize",option+1) == 0)
 1238             break;
 1239           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
 1240         }
 1241         case 'o':
 1242         {
 1243           if (LocaleCompare("opaque",option+1) == 0)
 1244             {
 1245               if (*option == '-')
 1246                 {
 1247                   i++;
 1248                   if (i == argc)
 1249                     ThrowMogrifyException(OptionError,"MissingOpaqueColor",
 1250                       option);
 1251                 }
 1252               break;
 1253             }
 1254           if (LocaleCompare("ordered-dither",option+1) == 0)
 1255             {
 1256               if (*option == '-')
 1257                 {
 1258                   i++;
 1259                   if (i == argc)
 1260                     ThrowMogrifyException(OptionError,"MissingType",option);
 1261                   i++;
 1262                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
 1263                     ThrowMogrifyException(OptionError,"MissingOrder",option);
 1264                 }
 1265               break;
 1266             }
 1267           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
 1268         }
 1269         case 'p':
 1270         {
 1271           if (LocaleCompare("paint",option+1) == 0)
 1272             {
 1273               if (*option == '-')
 1274                 {
 1275                   i++;
 1276                   if ((i == argc) || !IsGeometry(argv[i]))
 1277                     ThrowMogrifyException(OptionError,"MissingPaintRadius",
 1278                       option);
 1279                 }
 1280               break;
 1281             }
 1282           if (LocaleCompare("pointsize",option+1) == 0)
 1283             {
 1284               image_info->pointsize=12;
 1285               if (*option == '-')
 1286                 {
 1287                   i++;
 1288                   if ((i == argc) || !IsGeometry(argv[i]))
 1289                     ThrowMogrifyException(OptionError,"MissingPointsize",option);
 1290                   image_info->pointsize=atof(argv[i]);
 1291                 }
 1292               break;
 1293             }
 1294           if (LocaleCompare("profile",option+1) == 0)
 1295             {
 1296               i++;
 1297               if (i == argc)
 1298                 ThrowMogrifyException(OptionError,"MissingProfile",option);
 1299               break;
 1300             }
 1301           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
 1302         }
 1303         case 'q':
 1304         {
 1305           if (LocaleCompare("quality",option+1) == 0)
 1306             {
 1307               image_info->quality=SIP_MAGICK_DEFAULT_COMPRESSION_QUALITY;
 1308               if (*option == '-')
 1309                 {
 1310                   i++;
 1311                   if ((i == argc) || !IsGeometry(argv[i]))
 1312                     ThrowMogrifyException(OptionError,"MissingCompressionQuality",
 1313                       option);
 1314                   image_info->quality=atol(argv[i]);
 1315                 }
 1316               break;
 1317             }
 1318           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
 1319         }
 1320         case 'r':
 1321         {
 1322           if (LocaleCompare("raise",option+1) == 0)
 1323             {
 1324               i++;
 1325               if ((i == argc) || !IsGeometry(argv[i]))
 1326                 ThrowMogrifyException(OptionError,"MissingBevelWidth",option);
 1327               break;
 1328             }
 1329           if (LocaleCompare("random-threshold",option+1) == 0)
 1330             {
 1331               if (*option == '-')
 1332                 {
 1333                   i++;
 1334                   if (i == argc)
 1335                     ThrowMogrifyException(OptionError,"MissingType",option);
 1336                   i++;
 1337                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
 1338                     ThrowMogrifyException(OptionError,"MissingThreshold",option);
 1339                 }
 1340               break;
 1341             }
 1342           if (LocaleCompare("red-primary",option+1) == 0)
 1343             {
 1344               if (*option == '-')
 1345                 {
 1346                   i++;
 1347                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
 1348                     ThrowMogrifyException(OptionError,"MissingPoint",option);
 1349                 }
 1350               break;
 1351             }
 1352           if (LocaleCompare("region",option+1) == 0)
 1353             {
 1354               if (*option == '-')
 1355                 {
 1356                   i++;
 1357                   if ((i == argc) || !IsGeometry(argv[i]))
 1358                     ThrowMogrifyException(OptionError,"MissingGeometry",option);
 1359                 }
 1360               break;
 1361             }
 1362           if (LocaleCompare("render",option+1) == 0)
 1363             break;
 1364           if (LocaleCompare("resample",option+1) == 0)
 1365             {
 1366               if (*option == '-')
 1367                 {
 1368                   i++;
 1369                   if ((i == (argc-1)) || !IsGeometry(argv[i]))
 1370                     ThrowMogrifyException(OptionError,"MissingGeometry",option);
 1371                 }
 1372               break;
 1373             }
 1374           if (LocaleCompare("resize",option+1) == 0)
 1375             {
 1376               if (*option == '-')
 1377                 {
 1378                   i++;
 1379                   if ((i == argc) || !IsGeometry(argv[i]))
 1380                     ThrowMogrifyException(OptionError,"MissingGeometry",option);
 1381                 }
 1382               break;
 1383             }
 1384           if (LocaleCompare("roll",option+1) == 0)
 1385             {
 1386               if (*option == '-')
 1387                 {
 1388                   i++;
 1389                   if ((i == argc) || !IsGeometry(argv[i]))
 1390                     ThrowMogrifyException(OptionError,"MissingGeometry",option);
 1391                 }
 1392               break;
 1393             }
 1394           if (LocaleCompare("rotate",option+1) == 0)
 1395             {
 1396               i++;
 1397               if ((i == argc) || !IsGeometry(argv[i]))
 1398                 ThrowMogrifyException(OptionError,"MissingImageRotation",option);
 1399               break;
 1400             }
 1401           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
 1402         }
 1403         case 's':
 1404         {
 1405           if (LocaleCompare("sample",option+1) == 0)
 1406             {
 1407               if (*option == '-')
 1408                 {
 1409                   i++;
 1410                   if ((i == argc) || !IsGeometry(argv[i]))
 1411                     ThrowMogrifyException(OptionError,"MissingGeometry",option);
 1412                 }
 1413               break;
 1414             }
 1415           /*
 1416           if (LocaleCompare("sampling-factor",option+1) == 0)
 1417             {
 1418               (void) CloneString(&image_info->sampling_factor,(char *) NULL);
 1419               if (*option == '-')
 1420                 {
 1421                   i++;
 1422                   if ((i == argc) || !IsGeometry(argv[i]))
 1423                     ThrowMogrifyException(OptionError,"MissingGeometry",option);
 1424                   (void) CloneString(&image_info->sampling_factor,argv[i]);
 1425                 }
 1426               break;
 1427             }
 1428             */
 1429           if (LocaleCompare("scale",option+1) == 0)
 1430             {
 1431               if (*option == '-')
 1432                 {
 1433                   i++;
 1434                   if ((i == argc) || !IsGeometry(argv[i]))
 1435                     ThrowMogrifyException(OptionError,"MissingGeometry",option);
 1436                 }
 1437               break;
 1438             }
 1439           if (LocaleCompare("scene",option+1) == 0)
 1440             {
 1441               if (*option == '-')
 1442                 {
 1443                   i++;
 1444                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
 1445                     ThrowMogrifyException(OptionError,"MissingImageScene",
 1446                       option);
 1447                 }
 1448               break;
 1449             }
 1450           /* Removed for backward compat. with 5.5.1
 1451           if (LocaleCompare("seed",option+1) == 0)
 1452             {
 1453               unsigned long
 1454                 seed;
 1455 
 1456               if (*option == '-')
 1457                 {
 1458                   i++;
 1459                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
 1460                     ThrowMogrifyException(OptionError,"MissingImageGamma",option);
 1461                 }
 1462               seed=atol(argv[i]);
 1463               DistillRandomEvent((unsigned char *) &seed,sizeof(unsigned long));
 1464               break;
 1465             }
 1466             */
 1467           if (LocaleCompare("segment",option+1) == 0)
 1468             {
 1469               if (*option == '-')
 1470                 {
 1471                   i++;
 1472                   if ((i == argc) || !IsGeometry(argv[i]))
 1473                     ThrowMogrifyException(OptionError,"MissingThreshold",option);
 1474                 }
 1475               break;
 1476             }
 1477           if (LocaleCompare("shade",option+1) == 0)
 1478             {
 1479               i++;
 1480               if ((i == argc) || !IsGeometry(argv[i]))
 1481                 ThrowMogrifyException(OptionError,"MissingAzimuth",option);
 1482               break;
 1483             }
 1484           if (LocaleCompare("sharpen",option+1) == 0)
 1485             {
 1486               i++;
 1487               if ((i == argc) || !IsGeometry(argv[i]))
 1488                 ThrowMogrifyException(OptionError,"MissingGeometry",option);
 1489               break;
 1490             }
 1491           if (LocaleCompare("shave",option+1) == 0)
 1492             {
 1493               if (*option == '-')
 1494                 {
 1495                   i++;
 1496                   if ((i == argc) || !IsGeometry(argv[i]))
 1497                     ThrowMogrifyException(OptionError,"MissingGeometry",option);
 1498                 }
 1499               break;
 1500             }
 1501           if (LocaleCompare("shear",option+1) == 0)
 1502             {
 1503               i++;
 1504               if ((i == argc) || !IsGeometry(argv[i]))
 1505                 ThrowMogrifyException(OptionError,"MissingGeometry",option);
 1506               break;
 1507             }
 1508           if (LocaleCompare("size",option+1) == 0)
 1509             {
 1510               (void) CloneString(&image_info->size,(char *) NULL);
 1511               if (*option == '-')
 1512                 {
 1513                   i++;
 1514                   if ((i == argc) || !IsGeometry(argv[i]))
 1515                     ThrowMogrifyException(OptionError,"MissingGeometry",option);
 1516                   (void) CloneString(&image_info->size,argv[i]);
 1517                 }
 1518               break;
 1519             }
 1520           if (LocaleCompare("solarize",option+1) == 0)
 1521             {
 1522               if (*option == '-')
 1523                 {
 1524                   i++;
 1525                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
 1526                     ThrowMogrifyException(OptionError,"MissingThreshold",
 1527                       option);
 1528                 }
 1529               break;
 1530             }
 1531           if (LocaleCompare("spread",option+1) == 0)
 1532             {
 1533               if (*option == '-')
 1534                 {
 1535                   i++;
 1536                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
 1537                     ThrowMogrifyException(OptionError,"MissingAmount",option);
 1538                 }
 1539               break;
 1540             }
 1541           if (LocaleCompare("stroke",option+1) == 0)
 1542             {
 1543               if (*option == '-')
 1544                 {
 1545                   i++;
 1546                   if (i == argc)
 1547                     ThrowMogrifyException(OptionError,"MissingColors",option);
 1548                 }
 1549               break;
 1550             }
 1551           if (LocaleCompare("strokewidth",option+1) == 0)
 1552             {
 1553               if (*option == '-')
 1554                 {
 1555                   i++;
 1556                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
 1557                     ThrowMogrifyException(OptionError,"MissingPointsize",option);
 1558                 }
 1559               break;
 1560             }
 1561           if (LocaleCompare("swirl",option+1) == 0)
 1562             {
 1563               if (*option == '-')
 1564                 {
 1565                   i++;
 1566                   if ((i == argc) || !IsGeometry(argv[i]))
 1567                     ThrowMogrifyException(OptionError,"MissingImageRotation",
 1568                       option);
 1569                 }
 1570               break;
 1571             }
 1572           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
 1573         }
 1574         case 't':
 1575         {
 1576           if (LocaleCompare("texture",option+1) == 0)
 1577             {
 1578               (void) CloneString(&image_info->texture,(char *) NULL);
 1579               if (*option == '-')
 1580                 {
 1581                   i++;
 1582                   if (i == argc)
 1583                     ThrowMogrifyException(OptionError,"MissingFilename",
 1584                       option);
 1585                   (void) CloneString(&image_info->texture,argv[i]);
 1586                 }
 1587               break;
 1588             }
 1589           if (LocaleCompare("threshold",option+1) == 0)
 1590             {
 1591               if (*option == '-')
 1592                 {
 1593                   i++;
 1594                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
 1595                     ThrowMogrifyException(OptionError,"MissingThreshold",option);
 1596                 }
 1597               break;
 1598             }
 1599           if (LocaleCompare("thumbnail",option+1) == 0)
 1600             {
 1601               if (*option == '-')
 1602                 {
 1603                   i++;
 1604                   if ((i == argc) || !IsGeometry(argv[i]))
 1605                     ThrowMogrifyException(OptionError,"MissingGeometry",option);
 1606                 }
 1607               break;
 1608             }
 1609           if (LocaleCompare("transparent",option+1) == 0)
 1610             {
 1611               if (*option == '-')
 1612                 {
 1613                   i++;
 1614                   if (i == argc)
 1615                     ThrowMogrifyException(OptionError,"MissingTransparentColor",
 1616                       option);
 1617                 }
 1618               break;
 1619             }
 1620           if (LocaleCompare("treedepth",option+1) == 0)
 1621             {
 1622               if (*option == '-')
 1623                 {
 1624                   i++;
 1625                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
 1626                     ThrowMogrifyException(OptionError,"MissingTreeDepth",
 1627                       option);
 1628                 }
 1629               break;
 1630             }
 1631           if (LocaleCompare("trim",option+1) == 0)
 1632             break;
 1633           if (LocaleCompare("type",option+1) == 0)
 1634             {
 1635               image_info->type=UndefinedType;
 1636               if (*option == '-')
 1637                 {
 1638                   i++;
 1639                   if (i == argc)
 1640                     ThrowMogrifyException(OptionError,"MissingType",option);
 1641                   option=argv[i];
 1642                   if (LocaleCompare("Bilevel",option) == 0)
 1643                     image_info->type=BilevelType;
 1644                   if (LocaleCompare("Grayscale",option) == 0)
 1645                     image_info->type=GrayscaleType;
 1646                   if (LocaleCompare("GrayscaleMatte",option) == 0)
 1647                     image_info->type=GrayscaleMatteType;
 1648                   if (LocaleCompare("Palette",option) == 0)
 1649                     image_info->type=PaletteType;
 1650                   if (LocaleCompare("PaletteMatte",option) == 0)
 1651                     image_info->type=PaletteMatteType;
 1652                   if (LocaleCompare("TrueColor",option) == 0)
 1653                     image_info->type=TrueColorType;
 1654                   if (LocaleCompare("TrueColorMatte",option) == 0)
 1655                     image_info->type=TrueColorMatteType;
 1656                   if (LocaleCompare("ColorSeparation",option) == 0)
 1657                     image_info->type=ColorSeparationType;
 1658                   if (LocaleCompare("ColorSeparationMatte",option) == 0)
 1659                     image_info->type=ColorSeparationMatteType;
 1660                   if (LocaleCompare("Optimize",option) == 0)
 1661                     image_info->type=OptimizeType;
 1662                   if (image_info->type == UndefinedType)
 1663                     ThrowMogrifyException(OptionError,"UnrecognizedImageType",
 1664                       option);
 1665                 }
 1666               break;
 1667             }
 1668           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
 1669         }
 1670         case 'u':
 1671         {
 1672           if (LocaleCompare("undercolor",option+1) == 0)
 1673             {
 1674               if (*option == '-')
 1675                 {
 1676                   i++;
 1677                   if (i == argc)
 1678                     ThrowMogrifyException(OptionError,"MissingColors",option);
 1679                 }
 1680               break;
 1681             }
 1682           if (LocaleCompare("units",option+1) == 0)
 1683             {
 1684               image_info->units=UndefinedResolution;
 1685               if (*option == '-')
 1686                 {
 1687                   i++;
 1688                   if (i == argc)
 1689                     ThrowMogrifyException(OptionError,"MissingType",option);
 1690                   option=argv[i];
 1691                   image_info->units=UndefinedResolution;
 1692                   if (LocaleCompare("PixelsPerInch",option) == 0)
 1693                     image_info->units=PixelsPerInchResolution;
 1694                   if (LocaleCompare("PixelsPerCentimeter",option) == 0)
 1695                     image_info->units=PixelsPerCentimeterResolution;
 1696                 }
 1697               break;
 1698             }
 1699           if (LocaleCompare("unsharp",option+1) == 0)
 1700             {
 1701               i++;
 1702               if ((i == argc) || !IsGeometry(argv[i]))
 1703                 ThrowMogrifyException(OptionError,"MissingGeometry",option);
 1704               break;
 1705             }
 1706           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
 1707         }
 1708         case 'v':
 1709         {
 1710           if (LocaleCompare("verbose",option+1) == 0)
 1711             {
 1712               image_info->verbose=(*option == '-');
 1713               break;
 1714             }
 1715           if (LocaleCompare("verbose",option+1) == 0)
 1716             break;
 1717           if (LocaleCompare("view",option+1) == 0)
 1718             {
 1719               (void) CloneString(&image_info->view,(char *) NULL);
 1720               if (*option == '-')
 1721                 {
 1722                   i++;
 1723                   if (i == argc)
 1724                     ThrowMogrifyException(OptionError,"MissingViewTransform",
 1725                       option);
 1726                   (void) CloneString(&image_info->view,argv[i]);
 1727                 }
 1728               break;
 1729             }
 1730 #ifdef SIP_HAVE_VIRTUAL_PIXEL
 1731           if (LocaleCompare("virtual-pixel",option+1) == 0)
 1732             {
 1733               if (*option == '-')
 1734                 {
 1735                   VirtualPixelMethod
 1736                     virtual_pixel_method;
 1737 
 1738                   i++;
 1739                   if (i == argc)
 1740                     ThrowMogrifyException(OptionError,
 1741                       "MissingVirtualPixelMethod",option);
 1742                   option=argv[i];
 1743                   virtual_pixel_method=UndefinedVirtualPixelMethod;
 1744                   if (LocaleCompare("Constant",option) == 0)
 1745                     virtual_pixel_method=ConstantVirtualPixelMethod;
 1746                   if (LocaleCompare("Edge",option) == 0)
 1747                     virtual_pixel_method=EdgeVirtualPixelMethod;
 1748                   if (LocaleCompare("Mirror",option) == 0)
 1749                     virtual_pixel_method=MirrorVirtualPixelMethod;
 1750                   if (LocaleCompare("Tile",option) == 0)
 1751                     virtual_pixel_method=TileVirtualPixelMethod;
 1752                   if (virtual_pixel_method == UndefinedVirtualPixelMethod)
 1753                     ThrowMogrifyException(OptionError,
 1754                       "UnrecognizedVirtualPixelMethod",option);
 1755                 }
 1756               break;
 1757             }
 1758 #endif
 1759           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
 1760         }
 1761         case 'w':
 1762         {
 1763           if (LocaleCompare("wave",option+1) == 0)
 1764             {
 1765               i++;
 1766               if ((i == argc) || !IsGeometry(argv[i]))
 1767                 ThrowMogrifyException(OptionError,"MissingAmplitude",option);
 1768               break;
 1769             }
 1770           if (LocaleCompare("white-point",option+1) == 0)
 1771             {
 1772               if (*option == '-')
 1773                 {
 1774                   i++;
 1775                   if ((i == argc) || !IsGeometry(argv[i]))
 1776                     ThrowMogrifyException(OptionError,"MissingPoint",option);
 1777                 }
 1778               break;
 1779             }
 1780           if (LocaleCompare("white-threshold",option+1) == 0)
 1781             {
 1782               if (*option == '-')
 1783                 {
 1784                   i++;
 1785                   if ((i == argc) || !sscanf(argv[i],"%ld",&x))
 1786                     ThrowMogrifyException(OptionError,"MissingThreshold",option);
 1787                 }
 1788               break;
 1789             }
 1790           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
 1791         }
 1792         case '?':
 1793           break;
 1794         default:
 1795           ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
 1796       }
 1797    }
 1798 
 1799    return true;
 1800 }