cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % SSSSS TTTTT RRRR EEEEE AAA M M % |
| 7 | % SS T R R E A A MM MM % |
| 8 | % SSS T RRRR EEE AAAAA M M M % |
| 9 | % SS T R R E A A M M % |
| 10 | % SSSSS T R R EEEEE A A M M % |
| 11 | % % |
| 12 | % % |
| 13 | % Stream Image to a Raw Image Format % |
| 14 | % % |
| 15 | % Software Design % |
cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
Cristy | 7ce65e7 | 2015-12-12 18:03:16 -0500 | [diff] [blame] | 20 | % Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % Stream is a lightweight tool to stream one or more pixel components of the |
| 37 | % image or portion of the image to your choice of storage formats. It writes |
| 38 | % the pixel components as they are read from the input image a row at a time |
| 39 | % making stream desirable when working with large images or when you require |
| 40 | % raw pixel components. |
| 41 | % |
| 42 | */ |
| 43 | |
| 44 | /* |
| 45 | Include declarations. |
| 46 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 47 | #include "MagickWand/studio.h" |
| 48 | #include "MagickWand/MagickWand.h" |
| 49 | #include "MagickWand/mogrify-private.h" |
| 50 | #include "MagickCore/stream-private.h" |
cristy | 196372d | 2011-11-05 00:07:32 +0000 | [diff] [blame] | 51 | #include "MagickCore/string-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 52 | |
| 53 | /* |
| 54 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 55 | % % |
| 56 | % % |
| 57 | % % |
| 58 | % S t r e a m I m a g e C o m m a n d % |
| 59 | % % |
| 60 | % % |
| 61 | % % |
| 62 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 63 | % |
| 64 | % StreamImageCommand() is a lightweight method designed to extract pixels |
| 65 | % from large image files to a raw format using a minimum of system resources. |
| 66 | % The entire image or any regular portion of the image can be extracted. |
| 67 | % |
| 68 | % The format of the StreamImageCommand method is: |
| 69 | % |
| 70 | % MagickBooleanType StreamImageCommand(ImageInfo *image_info,int argc, |
| 71 | % char **argv,char **metadata,ExceptionInfo *exception) |
| 72 | % |
| 73 | % A description of each parameter follows: |
| 74 | % |
| 75 | % o image_info: the image info. |
| 76 | % |
| 77 | % o argc: the number of elements in the argument vector. |
| 78 | % |
| 79 | % o argv: A text array containing the command line arguments. |
| 80 | % |
| 81 | % o metadata: any metadata is returned here. |
| 82 | % |
| 83 | % o exception: return any errors or warnings in this structure. |
| 84 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 85 | */ |
| 86 | |
| 87 | static MagickBooleanType StreamUsage(void) |
| 88 | { |
| 89 | const char |
| 90 | **p; |
| 91 | |
| 92 | static const char |
| 93 | *miscellaneous[]= |
| 94 | { |
cristy | 17ada02 | 2014-11-07 22:12:23 +0000 | [diff] [blame] | 95 | "-channel mask set the image channel mask", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 96 | "-debug events display copious debugging information", |
| 97 | "-help print program options", |
| 98 | "-list type print a list of supported option arguments", |
| 99 | "-log format format of debugging information", |
| 100 | "-version print version information", |
| 101 | (char *) NULL |
| 102 | }, |
| 103 | *settings[]= |
| 104 | { |
| 105 | "-authenticate password", |
| 106 | " decipher image with this password", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 107 | "-colorspace type alternate image colorspace", |
| 108 | "-compress type type of pixel compression when writing the image", |
| 109 | "-define format:option", |
| 110 | " define one or more image format options", |
| 111 | "-density geometry horizontal and vertical density of the image", |
| 112 | "-depth value image depth", |
| 113 | "-extract geometry extract area from image", |
| 114 | "-identify identify the format and characteristics of the image", |
| 115 | "-interlace type type of image interlacing scheme", |
| 116 | "-interpolate method pixel color interpolation method", |
| 117 | "-limit type value pixel cache resource limit", |
| 118 | "-map components one or more pixel components", |
| 119 | "-monitor monitor progress", |
| 120 | "-quantize colorspace reduce colors in this colorspace", |
| 121 | "-quiet suppress all warning messages", |
| 122 | "-regard-warnings pay attention to warning messages", |
| 123 | "-respect-parentheses settings remain in effect until parenthesis boundary", |
| 124 | "-sampling-factor geometry", |
| 125 | " horizontal and vertical sampling factor", |
| 126 | "-seed value seed a new sequence of pseudo-random numbers", |
| 127 | "-set attribute value set an image attribute", |
| 128 | "-size geometry width and height of image", |
| 129 | "-storage-type type pixel storage type", |
cristy | d9a2919 | 2010-10-16 16:49:53 +0000 | [diff] [blame] | 130 | "-synchronize synchronize image to storage device", |
| 131 | "-taint declare the image as modified", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 132 | "-transparent-color color", |
| 133 | " transparent color", |
| 134 | "-verbose print detailed information about the image", |
| 135 | "-virtual-pixel method", |
| 136 | " virtual pixel access method", |
| 137 | (char *) NULL |
| 138 | }; |
| 139 | |
cristy | 4f7a613 | 2012-12-23 00:35:19 +0000 | [diff] [blame] | 140 | ListMagickVersion(stdout); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 141 | (void) printf("Usage: %s [options ...] input-image raw-image\n", |
| 142 | GetClientName()); |
| 143 | (void) printf("\nImage Settings:\n"); |
| 144 | for (p=settings; *p != (char *) NULL; p++) |
| 145 | (void) printf(" %s\n",*p); |
| 146 | (void) printf("\nMiscellaneous Options:\n"); |
| 147 | for (p=miscellaneous; *p != (char *) NULL; p++) |
| 148 | (void) printf(" %s\n",*p); |
| 149 | (void) printf( |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 150 | "\nBy default, the image format of 'file' is determined by its magic\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 151 | (void) printf( |
| 152 | "number. To specify a particular image format, precede the filename\n"); |
| 153 | (void) printf( |
| 154 | "with an image format name and a colon (i.e. ps:image) or specify the\n"); |
| 155 | (void) printf( |
| 156 | "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n"); |
| 157 | (void) printf("'-' for standard input or output.\n"); |
| 158 | return(MagickFalse); |
| 159 | } |
| 160 | |
| 161 | WandExport MagickBooleanType StreamImageCommand(ImageInfo *image_info, |
| 162 | int argc,char **argv,char **metadata,ExceptionInfo *exception) |
| 163 | { |
| 164 | #define DestroyStream() \ |
| 165 | { \ |
| 166 | DestroyImageStack(); \ |
| 167 | stream_info=DestroyStreamInfo(stream_info); \ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 168 | for (i=0; i < (ssize_t) argc; i++) \ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 169 | argv[i]=DestroyString(argv[i]); \ |
| 170 | argv=(char **) RelinquishMagickMemory(argv); \ |
| 171 | } |
| 172 | #define ThrowStreamException(asperity,tag,option) \ |
| 173 | { \ |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 174 | (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 175 | option); \ |
| 176 | DestroyStream(); \ |
| 177 | return(MagickFalse); \ |
| 178 | } |
| 179 | #define ThrowStreamInvalidArgumentException(option,argument) \ |
| 180 | { \ |
| 181 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \ |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 182 | "InvalidArgument","'%s': %s",option,argument); \ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 183 | DestroyStream(); \ |
| 184 | return(MagickFalse); \ |
| 185 | } |
| 186 | |
| 187 | char |
| 188 | *filename, |
| 189 | *option; |
| 190 | |
| 191 | const char |
| 192 | *format; |
| 193 | |
| 194 | Image |
| 195 | *image; |
| 196 | |
| 197 | ImageStack |
| 198 | image_stack[MaxImageStackDepth+1]; |
| 199 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 200 | MagickBooleanType |
| 201 | fire, |
cristy | ebbcfea | 2011-02-25 02:43:54 +0000 | [diff] [blame] | 202 | pend, |
| 203 | respect_parenthesis; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 204 | |
| 205 | MagickStatusType |
| 206 | status; |
| 207 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 208 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 209 | i; |
| 210 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 211 | ssize_t |
| 212 | j, |
| 213 | k; |
| 214 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 215 | StreamInfo |
| 216 | *stream_info; |
| 217 | |
| 218 | /* |
| 219 | Set defaults. |
| 220 | */ |
| 221 | assert(image_info != (ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 222 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 223 | if (image_info->debug != MagickFalse) |
| 224 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 225 | assert(exception != (ExceptionInfo *) NULL); |
| 226 | (void) metadata; |
| 227 | if (argc == 2) |
| 228 | { |
| 229 | option=argv[1]; |
| 230 | if ((LocaleCompare("version",option+1) == 0) || |
| 231 | (LocaleCompare("-version",option+1) == 0)) |
| 232 | { |
cristy | 4f7a613 | 2012-12-23 00:35:19 +0000 | [diff] [blame] | 233 | ListMagickVersion(stdout); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 234 | return(MagickFalse); |
| 235 | } |
| 236 | } |
| 237 | if (argc < 3) |
cristy | 13e61a1 | 2010-02-04 20:19:00 +0000 | [diff] [blame] | 238 | return(StreamUsage()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 239 | format="%w,%h,%m"; |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 240 | (void) format; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 241 | j=1; |
| 242 | k=0; |
| 243 | NewImageStack(); |
| 244 | option=(char *) NULL; |
| 245 | pend=MagickFalse; |
cristy | ebbcfea | 2011-02-25 02:43:54 +0000 | [diff] [blame] | 246 | respect_parenthesis=MagickFalse; |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 247 | stream_info=AcquireStreamInfo(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 248 | status=MagickTrue; |
| 249 | /* |
| 250 | Stream an image. |
| 251 | */ |
| 252 | ReadCommandlLine(argc,&argv); |
| 253 | status=ExpandFilenames(&argc,&argv); |
| 254 | if (status == MagickFalse) |
| 255 | ThrowStreamException(ResourceLimitError,"MemoryAllocationFailed", |
| 256 | GetExceptionMessage(errno)); |
| 257 | status=OpenStream(image_info,stream_info,argv[argc-1],exception); |
| 258 | if (status == MagickFalse) |
| 259 | { |
| 260 | DestroyStream(); |
| 261 | return(MagickFalse); |
| 262 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 263 | for (i=1; i < (ssize_t) (argc-1); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 264 | { |
| 265 | option=argv[i]; |
| 266 | if (LocaleCompare(option,"(") == 0) |
| 267 | { |
| 268 | FireImageStack(MagickFalse,MagickTrue,pend); |
| 269 | if (k == MaxImageStackDepth) |
| 270 | ThrowStreamException(OptionError,"ParenthesisNestedTooDeeply",option); |
| 271 | PushImageStack(); |
| 272 | continue; |
| 273 | } |
| 274 | if (LocaleCompare(option,")") == 0) |
| 275 | { |
| 276 | FireImageStack(MagickFalse,MagickTrue,MagickTrue); |
| 277 | if (k == 0) |
| 278 | ThrowStreamException(OptionError,"UnableToParseExpression",option); |
| 279 | PopImageStack(); |
| 280 | continue; |
| 281 | } |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 282 | if (IsCommandOption(option) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 283 | { |
| 284 | Image |
| 285 | *images; |
| 286 | |
| 287 | /* |
| 288 | Stream input image. |
| 289 | */ |
| 290 | FireImageStack(MagickFalse,MagickFalse,pend); |
| 291 | filename=argv[i]; |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 292 | if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 293 | filename=argv[++i]; |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 294 | (void) CopyMagickString(image_info->filename,filename,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 295 | images=StreamImage(image_info,stream_info,exception); |
| 296 | status&=(images != (Image *) NULL) && |
| 297 | (exception->severity < ErrorException); |
| 298 | if (images == (Image *) NULL) |
| 299 | continue; |
| 300 | AppendImageStack(images); |
| 301 | continue; |
| 302 | } |
| 303 | pend=image != (Image *) NULL ? MagickTrue : MagickFalse; |
| 304 | switch (*(option+1)) |
| 305 | { |
| 306 | case 'a': |
| 307 | { |
| 308 | if (LocaleCompare("authenticate",option+1) == 0) |
| 309 | { |
| 310 | if (*option == '+') |
| 311 | break; |
| 312 | i++; |
cristy | e81f552 | 2014-05-07 01:25:59 +0000 | [diff] [blame] | 313 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 314 | ThrowStreamException(OptionError,"MissingArgument",option); |
| 315 | break; |
| 316 | } |
| 317 | ThrowStreamException(OptionError,"UnrecognizedOption",option) |
| 318 | } |
| 319 | case 'c': |
| 320 | { |
| 321 | if (LocaleCompare("cache",option+1) == 0) |
| 322 | { |
| 323 | if (*option == '+') |
| 324 | break; |
| 325 | i++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 326 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 327 | ThrowStreamException(OptionError,"MissingArgument",option); |
| 328 | if (IsGeometry(argv[i]) == MagickFalse) |
| 329 | ThrowStreamInvalidArgumentException(option,argv[i]); |
| 330 | break; |
| 331 | } |
| 332 | if (LocaleCompare("channel",option+1) == 0) |
| 333 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 334 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 335 | channel; |
| 336 | |
| 337 | if (*option == '+') |
| 338 | break; |
| 339 | i++; |
cristy | e81f552 | 2014-05-07 01:25:59 +0000 | [diff] [blame] | 340 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 341 | ThrowStreamException(OptionError,"MissingArgument",option); |
| 342 | channel=ParseChannelOption(argv[i]); |
| 343 | if (channel < 0) |
| 344 | ThrowStreamException(OptionError,"UnrecognizedChannelType", |
| 345 | argv[i]); |
| 346 | break; |
| 347 | } |
| 348 | if (LocaleCompare("colorspace",option+1) == 0) |
| 349 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 350 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 351 | colorspace; |
| 352 | |
| 353 | if (*option == '+') |
| 354 | break; |
| 355 | i++; |
cristy | e81f552 | 2014-05-07 01:25:59 +0000 | [diff] [blame] | 356 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 357 | ThrowStreamException(OptionError,"MissingArgument",option); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 358 | colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 359 | argv[i]); |
| 360 | if (colorspace < 0) |
| 361 | ThrowStreamException(OptionError,"UnrecognizedColorspace", |
| 362 | argv[i]); |
| 363 | break; |
| 364 | } |
| 365 | if (LocaleCompare("compress",option+1) == 0) |
| 366 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 367 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 368 | compress; |
| 369 | |
| 370 | if (*option == '+') |
| 371 | break; |
| 372 | i++; |
cristy | e81f552 | 2014-05-07 01:25:59 +0000 | [diff] [blame] | 373 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 374 | ThrowStreamException(OptionError,"MissingArgument",option); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 375 | compress=ParseCommandOption(MagickCompressOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 376 | argv[i]); |
| 377 | if (compress < 0) |
| 378 | ThrowStreamException(OptionError,"UnrecognizedImageCompression", |
| 379 | argv[i]); |
| 380 | break; |
| 381 | } |
cristy | 2287975 | 2009-10-25 23:55:40 +0000 | [diff] [blame] | 382 | if (LocaleCompare("concurrent",option+1) == 0) |
| 383 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 384 | ThrowStreamException(OptionError,"UnrecognizedOption",option) |
| 385 | } |
| 386 | case 'd': |
| 387 | { |
| 388 | if (LocaleCompare("debug",option+1) == 0) |
| 389 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 390 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 391 | event; |
| 392 | |
| 393 | if (*option == '+') |
| 394 | break; |
| 395 | i++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 396 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 397 | ThrowStreamException(OptionError,"MissingArgument",option); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 398 | event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 399 | if (event < 0) |
| 400 | ThrowStreamException(OptionError,"UnrecognizedEventType",argv[i]); |
| 401 | (void) SetLogEventMask(argv[i]); |
| 402 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 403 | } |
| 404 | if (LocaleCompare("define",option+1) == 0) |
| 405 | { |
| 406 | i++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 407 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 408 | ThrowStreamException(OptionError,"MissingArgument",option); |
| 409 | if (*option == '+') |
| 410 | { |
| 411 | const char |
| 412 | *define; |
| 413 | |
| 414 | define=GetImageOption(image_info,argv[i]); |
| 415 | if (define == (const char *) NULL) |
| 416 | ThrowStreamException(OptionError,"NoSuchOption",argv[i]); |
| 417 | break; |
| 418 | } |
| 419 | break; |
| 420 | } |
| 421 | if (LocaleCompare("density",option+1) == 0) |
| 422 | { |
| 423 | if (*option == '+') |
| 424 | break; |
| 425 | i++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 426 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 427 | ThrowStreamException(OptionError,"MissingArgument",option); |
| 428 | if (IsGeometry(argv[i]) == MagickFalse) |
| 429 | ThrowStreamInvalidArgumentException(option,argv[i]); |
| 430 | break; |
| 431 | } |
| 432 | if (LocaleCompare("depth",option+1) == 0) |
| 433 | { |
| 434 | if (*option == '+') |
| 435 | break; |
| 436 | i++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 437 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 438 | ThrowStreamException(OptionError,"MissingArgument",option); |
| 439 | if (IsGeometry(argv[i]) == MagickFalse) |
| 440 | ThrowStreamInvalidArgumentException(option,argv[i]); |
| 441 | break; |
| 442 | } |
cristy | 2287975 | 2009-10-25 23:55:40 +0000 | [diff] [blame] | 443 | if (LocaleCompare("duration",option+1) == 0) |
| 444 | { |
| 445 | if (*option == '+') |
| 446 | break; |
| 447 | i++; |
cristy | e81f552 | 2014-05-07 01:25:59 +0000 | [diff] [blame] | 448 | if (i == (ssize_t) argc) |
cristy | 2287975 | 2009-10-25 23:55:40 +0000 | [diff] [blame] | 449 | ThrowStreamException(OptionError,"MissingArgument",option); |
| 450 | if (IsGeometry(argv[i]) == MagickFalse) |
| 451 | ThrowStreamInvalidArgumentException(option,argv[i]); |
| 452 | break; |
| 453 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 454 | ThrowStreamException(OptionError,"UnrecognizedOption",option) |
| 455 | } |
| 456 | case 'e': |
| 457 | { |
| 458 | if (LocaleCompare("extract",option+1) == 0) |
| 459 | { |
| 460 | if (*option == '+') |
| 461 | break; |
| 462 | i++; |
cristy | e81f552 | 2014-05-07 01:25:59 +0000 | [diff] [blame] | 463 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 464 | ThrowStreamException(OptionError,"MissingArgument",option); |
| 465 | if (IsGeometry(argv[i]) == MagickFalse) |
| 466 | ThrowStreamInvalidArgumentException(option,argv[i]); |
| 467 | break; |
| 468 | } |
| 469 | ThrowStreamException(OptionError,"UnrecognizedOption",option) |
| 470 | } |
| 471 | case 'h': |
| 472 | { |
| 473 | if ((LocaleCompare("help",option+1) == 0) || |
| 474 | (LocaleCompare("-help",option+1) == 0)) |
| 475 | return(StreamUsage()); |
| 476 | ThrowStreamException(OptionError,"UnrecognizedOption",option) |
| 477 | } |
| 478 | case 'i': |
| 479 | { |
| 480 | if (LocaleCompare("identify",option+1) == 0) |
| 481 | break; |
| 482 | if (LocaleCompare("interlace",option+1) == 0) |
| 483 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 484 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 485 | interlace; |
| 486 | |
| 487 | if (*option == '+') |
| 488 | break; |
| 489 | i++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 490 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 491 | ThrowStreamException(OptionError,"MissingArgument",option); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 492 | interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 493 | argv[i]); |
| 494 | if (interlace < 0) |
| 495 | ThrowStreamException(OptionError,"UnrecognizedInterlaceType", |
| 496 | argv[i]); |
| 497 | break; |
| 498 | } |
| 499 | if (LocaleCompare("interpolate",option+1) == 0) |
| 500 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 501 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 502 | interpolate; |
| 503 | |
| 504 | if (*option == '+') |
| 505 | break; |
| 506 | i++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 507 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 508 | ThrowStreamException(OptionError,"MissingArgument",option); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 509 | interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 510 | argv[i]); |
| 511 | if (interpolate < 0) |
| 512 | ThrowStreamException(OptionError,"UnrecognizedInterpolateMethod", |
| 513 | argv[i]); |
| 514 | break; |
| 515 | } |
| 516 | ThrowStreamException(OptionError,"UnrecognizedOption",option) |
| 517 | } |
| 518 | case 'l': |
| 519 | { |
| 520 | if (LocaleCompare("limit",option+1) == 0) |
| 521 | { |
| 522 | char |
| 523 | *p; |
| 524 | |
| 525 | double |
| 526 | value; |
| 527 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 528 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 529 | resource; |
| 530 | |
| 531 | if (*option == '+') |
| 532 | break; |
| 533 | i++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 534 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 535 | ThrowStreamException(OptionError,"MissingArgument",option); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 536 | resource=ParseCommandOption(MagickResourceOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 537 | argv[i]); |
| 538 | if (resource < 0) |
| 539 | ThrowStreamException(OptionError,"UnrecognizedResourceType", |
| 540 | argv[i]); |
| 541 | i++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 542 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 543 | ThrowStreamException(OptionError,"MissingArgument",option); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 544 | value=StringToDouble(argv[i],&p); |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 545 | (void) value; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 546 | if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0)) |
| 547 | ThrowStreamInvalidArgumentException(option,argv[i]); |
| 548 | break; |
| 549 | } |
| 550 | if (LocaleCompare("list",option+1) == 0) |
| 551 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 552 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 553 | list; |
| 554 | |
| 555 | if (*option == '+') |
| 556 | break; |
| 557 | i++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 558 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 559 | ThrowStreamException(OptionError,"MissingArgument",option); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 560 | list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 561 | if (list < 0) |
| 562 | ThrowStreamException(OptionError,"UnrecognizedListType",argv[i]); |
cristy | aeb2cbc | 2010-05-07 13:28:58 +0000 | [diff] [blame] | 563 | status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 564 | argv+j,exception); |
| 565 | DestroyStream(); |
cristy | 32ce239 | 2014-09-24 19:08:53 +0000 | [diff] [blame] | 566 | return(status == 0 ? MagickTrue : MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 567 | } |
| 568 | if (LocaleCompare("log",option+1) == 0) |
| 569 | { |
| 570 | if (*option == '+') |
| 571 | break; |
| 572 | i++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 573 | if ((i == (ssize_t) argc) || (strchr(argv[i],'%') == (char *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 574 | ThrowStreamException(OptionError,"MissingArgument",option); |
| 575 | break; |
| 576 | } |
| 577 | ThrowStreamException(OptionError,"UnrecognizedOption",option) |
| 578 | } |
| 579 | case 'm': |
| 580 | { |
| 581 | if (LocaleCompare("map",option+1) == 0) |
| 582 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 583 | (void) CopyMagickString(argv[i]+1,"san",MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 584 | if (*option == '+') |
| 585 | break; |
| 586 | i++; |
| 587 | SetStreamInfoMap(stream_info,argv[i]); |
| 588 | break; |
| 589 | } |
| 590 | if (LocaleCompare("monitor",option+1) == 0) |
| 591 | break; |
| 592 | ThrowStreamException(OptionError,"UnrecognizedOption",option) |
| 593 | } |
| 594 | case 'q': |
| 595 | { |
| 596 | if (LocaleCompare("quantize",option+1) == 0) |
| 597 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 598 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 599 | colorspace; |
| 600 | |
| 601 | if (*option == '+') |
| 602 | break; |
| 603 | i++; |
cristy | e81f552 | 2014-05-07 01:25:59 +0000 | [diff] [blame] | 604 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 605 | ThrowStreamException(OptionError,"MissingArgument",option); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 606 | colorspace=ParseCommandOption(MagickColorspaceOptions, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 607 | MagickFalse,argv[i]); |
| 608 | if (colorspace < 0) |
| 609 | ThrowStreamException(OptionError,"UnrecognizedColorspace", |
| 610 | argv[i]); |
| 611 | break; |
| 612 | } |
| 613 | if (LocaleCompare("quiet",option+1) == 0) |
| 614 | break; |
| 615 | ThrowStreamException(OptionError,"UnrecognizedOption",option) |
| 616 | } |
| 617 | case 'r': |
| 618 | { |
| 619 | if (LocaleCompare("regard-warnings",option+1) == 0) |
| 620 | break; |
| 621 | if (LocaleNCompare("respect-parentheses",option+1,17) == 0) |
| 622 | { |
| 623 | respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse; |
| 624 | break; |
| 625 | } |
| 626 | ThrowStreamException(OptionError,"UnrecognizedOption",option) |
| 627 | } |
| 628 | case 's': |
| 629 | { |
| 630 | if (LocaleCompare("sampling-factor",option+1) == 0) |
| 631 | { |
| 632 | if (*option == '+') |
| 633 | break; |
| 634 | i++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 635 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 636 | ThrowStreamException(OptionError,"MissingArgument",option); |
| 637 | if (IsGeometry(argv[i]) == MagickFalse) |
| 638 | ThrowStreamInvalidArgumentException(option,argv[i]); |
| 639 | break; |
| 640 | } |
| 641 | if (LocaleCompare("seed",option+1) == 0) |
| 642 | { |
| 643 | if (*option == '+') |
| 644 | break; |
| 645 | i++; |
cristy | e81f552 | 2014-05-07 01:25:59 +0000 | [diff] [blame] | 646 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 647 | ThrowStreamException(OptionError,"MissingArgument",option); |
| 648 | if (IsGeometry(argv[i]) == MagickFalse) |
| 649 | ThrowStreamInvalidArgumentException(option,argv[i]); |
| 650 | break; |
| 651 | } |
| 652 | if (LocaleCompare("set",option+1) == 0) |
| 653 | { |
| 654 | i++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 655 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 656 | ThrowStreamException(OptionError,"MissingArgument",option); |
| 657 | if (*option == '+') |
| 658 | break; |
| 659 | i++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 660 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 661 | ThrowStreamException(OptionError,"MissingArgument",option); |
| 662 | break; |
| 663 | } |
| 664 | if (LocaleCompare("size",option+1) == 0) |
| 665 | { |
| 666 | if (*option == '+') |
| 667 | break; |
| 668 | i++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 669 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 670 | ThrowStreamException(OptionError,"MissingArgument",option); |
| 671 | if (IsGeometry(argv[i]) == MagickFalse) |
| 672 | ThrowStreamInvalidArgumentException(option,argv[i]); |
| 673 | break; |
| 674 | } |
| 675 | if (LocaleCompare("storage-type",option+1) == 0) |
| 676 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 677 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 678 | type; |
| 679 | |
| 680 | if (*option == '+') |
| 681 | break; |
| 682 | i++; |
cristy | e81f552 | 2014-05-07 01:25:59 +0000 | [diff] [blame] | 683 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 684 | ThrowStreamException(OptionError,"MissingArgument",option); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 685 | type=ParseCommandOption(MagickStorageOptions,MagickFalse,argv[i]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 686 | if (type < 0) |
| 687 | ThrowStreamException(OptionError,"UnrecognizedStorageType", |
| 688 | argv[i]); |
| 689 | SetStreamInfoStorageType(stream_info,(StorageType) type); |
| 690 | break; |
| 691 | } |
cristy | d9a2919 | 2010-10-16 16:49:53 +0000 | [diff] [blame] | 692 | if (LocaleCompare("synchronize",option+1) == 0) |
| 693 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 694 | ThrowStreamException(OptionError,"UnrecognizedOption",option) |
| 695 | } |
| 696 | case 't': |
| 697 | { |
cristy | d9a2919 | 2010-10-16 16:49:53 +0000 | [diff] [blame] | 698 | if (LocaleCompare("taint",option+1) == 0) |
| 699 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 700 | if (LocaleCompare("transparent-color",option+1) == 0) |
| 701 | { |
| 702 | if (*option == '+') |
| 703 | break; |
| 704 | i++; |
cristy | e81f552 | 2014-05-07 01:25:59 +0000 | [diff] [blame] | 705 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 706 | ThrowStreamException(OptionError,"MissingArgument",option); |
| 707 | break; |
| 708 | } |
| 709 | ThrowStreamException(OptionError,"UnrecognizedOption",option) |
| 710 | } |
| 711 | case 'v': |
| 712 | { |
| 713 | if (LocaleCompare("verbose",option+1) == 0) |
| 714 | break; |
| 715 | if ((LocaleCompare("version",option+1) == 0) || |
| 716 | (LocaleCompare("-version",option+1) == 0)) |
| 717 | { |
cristy | 4f7a613 | 2012-12-23 00:35:19 +0000 | [diff] [blame] | 718 | ListMagickVersion(stdout); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 719 | break; |
| 720 | } |
| 721 | if (LocaleCompare("virtual-pixel",option+1) == 0) |
| 722 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 723 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 724 | method; |
| 725 | |
| 726 | if (*option == '+') |
| 727 | break; |
| 728 | i++; |
cristy | e81f552 | 2014-05-07 01:25:59 +0000 | [diff] [blame] | 729 | if (i == (ssize_t) argc) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 730 | ThrowStreamException(OptionError,"MissingArgument",option); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 731 | method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 732 | argv[i]); |
| 733 | if (method < 0) |
cristy | 0696de1 | 2013-05-26 19:22:40 +0000 | [diff] [blame] | 734 | ThrowStreamException(OptionError,"UnrecognizedVirtualPixelMethod", |
| 735 | argv[i]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 736 | break; |
| 737 | } |
| 738 | ThrowStreamException(OptionError,"UnrecognizedOption",option) |
| 739 | } |
| 740 | case '?': |
| 741 | break; |
| 742 | default: |
| 743 | ThrowStreamException(OptionError,"UnrecognizedOption",option) |
| 744 | } |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 745 | fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) & |
| 746 | FireOptionFlag) == 0 ? MagickFalse : MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 747 | if (fire != MagickFalse) |
| 748 | FireImageStack(MagickFalse,MagickTrue,MagickTrue); |
| 749 | } |
| 750 | if (k != 0) |
| 751 | ThrowStreamException(OptionError,"UnbalancedParenthesis",argv[i]); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 752 | if (i-- != (ssize_t) (argc-1)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 753 | ThrowStreamException(OptionError,"MissingAnImageFilename",argv[i]); |
| 754 | if (image == (Image *) NULL) |
| 755 | ThrowStreamException(OptionError,"MissingAnImageFilename",argv[i]); |
| 756 | FinalizeImageSettings(image_info,image,MagickTrue); |
cristy | 94f2007 | 2009-09-12 02:12:36 +0000 | [diff] [blame] | 757 | if (image == (Image *) NULL) |
| 758 | ThrowStreamException(OptionError,"MissingAnImageFilename",argv[i]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 759 | DestroyStream(); |
| 760 | return(status != 0 ? MagickTrue : MagickFalse); |
| 761 | } |