IM v6 CLI process handling notes... --- While processing the command line Parts of the command line ( argc, argv ) will be passed to various routines to be processed. The image stack is just a array of image and image_info pointers. In the main loop k = current stack of images being processed, 0 = lowest level j = command line option up to which we have processed. i = command line option we are parsing (look ahead for images to read) The j,k variables are handled by macros found in mogrify-private.h ----- Image Processing Levels... Low level option processing... MogrifyImageInfo() Handle settings that modify the global image_info structure There may be no images defined when called. No images are passed. MogrifyImageList() Handle settings MogrifyImageInfo(), and then each multi-image Sequence Operators seen (generally one only) MogrifyImage() Apply a single image operators against the pointed to single image. Also handles -region modify limitations. This is why regions only work until the next non-simple operator or a +region MorgifyImages() if NOT 'post' MogrifyImageList() to handle multi-image sequence operators for each image MogrifyImage() break if that image was last done if 'post' MogrifyImageList() to handle multi-image sequence operators ---- Macros shared in mogrify-private.h -- This is the heart of the processing AppendImageStack(images) Add these images to the current stack PushImageStack() handle '(' creating a net image list with clone of image_info PopImageStack() handle ')' to append any images left to previous stack and respect_parenthesis handling of image_info FinalizeImageSettings(image_info,image,advance) calls FireImageStack() to update various settings saving them into the global image_info structure FireImageStack(postfix,advance,fire) This is the main work horse of Convert and Mogrify go thru all options in argv from j to i calling MogrifyImageInfo(...) if no images are present or calling MogrifyImages(...) if images present and 'fire' is true The 'advance' is used so the options can be fired twice. Once to just set settings until at least one image has been read in. and a second time immediatally after image has been read in. 'postfix' is passed into MogrifyImages to determine when the Multi-Image Sequence Operators in the options are to be applied (before or after) the simple operations. ---- MogrifyImageCommand() Mogrify read one image then fires the whole list against that one image. The 'output' filename is modified as it id processed. read one image FireImageStack (only one option sequence is allowed) write image ConvertImageCommand() For each long sequence of options found... FireImageStack The sequence determined based on the Multi-Image Sequence Operators which are specifically listed in "MagickImageListOptions". convert -list ImageList Note this list does not determine if an option is processed by MogrifyImageList, only that the 'image list loop' of MogrifyImages should stop processing immediatally (post) after such an option. Almost all the above routines processes all the options given skipping any options not needed at that moment using the argument counts provided by "CommandOptions". This is why a variable number of args are currently not permitted. Special and duplicated handling of operations being executed is due to legacy handling requirements, complex as that is. The function is also performed the final write of the image at end. Convert reads images during argument handling. MagickCommandGenesis() (in mogrify.c) Wrapper around the XXXXImageCommand() for special CLI commands Basically handles very very special options... -bench -concurrent -debug -duration and -regard-warnings global options, which can appear anywhere on command line. (and then ignored by all other option handlers above) -bench for example will run the command 'iterations' times. ------------ In "magick/option.c" is the CommandOptions[] array which contains all the options and the number of arguments that follow. It is this number of arguments, that makes the current techniques work as they do, as it allows the routines about to 'skip over' elements in the argv array that are not relevent to there specific processing. For a command stream processor, we will need a to expand this returned value to include a 'type of option' flags that will separate the options into something that can determine which of the above functions should be called, and posibily if the argument should have percent escapes processed. Note a 'stream' processor will have no way of knowing if the next argument is the final 'write' argument. As such the new command will need to use some type of -write "..." to perform that final write. It will also need to understand argument space separation and quoting and some type of comment method (up until newline). It should also be able to parse a command into a 'processing sequence' rather than exectuting the option immediatally. ------------