progress monitor ios

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
gameover
Posts: 3
Joined: 2013-01-03T04:23:12-07:00
Authentication code: 6789

progress monitor ios

Post by gameover »

Hi all,

I am successfully using image magick on ios with all the commands I need.
I have converted the command lines used on our server into a ConvertImageCommand and everything work well.
I have added the -monitor as an argument to the command so I can see every tiny progress on my image (loading, resizing, cropping, etc)

However, I would like to display a progress bar to inform the user on the progress of the image process.
I am looking for a very simple example on how to use the progress monitor function...

Code: Select all

SetImageProgressMonitor(Image *,const MagickProgressMonitor,void *),
SetImageInfoProgressMonitor(ImageInfo *,const MagickProgressMonitor,void *);
Can somebody help me ?

Thanks
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: progress monitor ios

Post by magick »

Take a look @ wand/mogrify.c, magick/display.c, and magick/montage.c. These source modules all have calls to a progress monitor which you can use as a basis for your own custom progress monitor.
gameover
Posts: 3
Joined: 2013-01-03T04:23:12-07:00
Authentication code: 6789

Re: progress monitor ios

Post by gameover »

Thanks for your answer but I have already read these files and I do not know how to use the code (I do not use any Image but only file path)

I would like to monitor the progress of the following command line:

Code: Select all

convert \( \( -size 700x495 xc:black -virtual-pixel Transparent \( \( imgSource.jpg -resize x180 -gravity Center -crop 125x180+0+0 +repage \) -matte +distort Perspective '0,0 312,34 0,180 308,209 125,180 436,251 125,0 431,112'  \) \( \( imgSource.jpg -resize x180 -gravity Center -crop 125x180+0+0 +repage \) -matte +distort Perspective '0,0 219,116 0,180 211,247 125,180 308,209 125,0 312,34 ' \) -layers merge +repage imgDest.jpg -compose dst-in -composite \) \) imgSaved.png
I transform this this command line into char **argv to use the method

Code: Select all

ConvertImageCommand(AcquireImageInfo(), nbArgs, argv, NULL, AcquireExceptionInfo());
I do not know how track the progress of the "ConvertImageCommand" method.

Is there an example somewhere which shows how to proceed ?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: progress monitor ios

Post by magick »

If you want to use the default progress monitor which writes progress to stdout, simply add -monitor to your argv[] array. If you want a custom moniter, call SetImageInfoProgressMonitor() before ConvertImageCommand(). You can pass any data you want as the final parameter and access it with your custom monitor method. The method has this signature:
  • MagickBooleanType MonitorProgress(const char *text,const MagickOffsetType offset,const MagickSizeType extent,void *client_data)
It is called by ImageMagick periodically. Progress is measured by the offset end extent value (e.g. 35 out of 100). The text tells the what operation is in progress (e.g. resizing). You can halt progress by returning MagickFalse or continue progress by returning MagickTrue.
gameover
Posts: 3
Joined: 2013-01-03T04:23:12-07:00
Authentication code: 6789

Re: progress monitor ios

Post by gameover »

Hi,

Thank you very much for your help. I achieved the setup of the monitor.

However, I would like to know if there is a simple way to define the number of operations which will be proceed (monitored) before the execution of the command line.
For example, the command "convert imgSource.jpg -blur 0x2.5 -paint 5 imgSaved.jpg" execute 4 operations : Load, Blur, OilPaint and Save.
But the command "convert ((-size 765x523 xc:black -virtual-pixel Transparent (( imgSource.jpg -resize x358 -gravity center -crop 277x358+0+0 +repage ) -matte +distort Perspective 0,0 180,163 0,358 230,522 277,358 469,431 277,0 455,134 ) -layers merge +repage imgBackground.jpg -compose dst-in -composite ) ) imgSaved.png" execute only 3 operations.

Also, for the others who have the same issue, here is my code:

Code: Select all

- (void)ExecuteCommand {
    /*
     command is an array which contains all the elements of the ImageMagick command.
     example:
     command (
     convert,
     imgSource.jpg,
     "-blur",
     "0x2.5",
     "-paint",
     5,
     imgSaved.jpg
     )
     */
    
    ImageInfo *imageInfo = AcquireImageInfo();
    int nbArgs = command.count;
    char **argv = (char **)malloc((nbArgs + 1) * sizeof(char*));
    
    for (unsigned i = 0; i < nbArgs; i++)
    {
        NSString *argString = [command objectAtIndex:i];
        argv[i] = strdup([argString UTF8String]);
    }
    
    argv[nbArgs] = NULL;
    
    progress_monitor_method = SetImageInfoProgressMonitor(imageInfo, &MonitorProgress, self);
    ConvertImageCommand(imageInfo, nbArgs, argv, NULL, AcquireExceptionInfo());
    
    if (argv != NULL)
    {
        for (unsigned index = 0; argv[index] != NULL; index++) {
            free(argv[index]);
        }
        free(argv);
    }
}

MagickBooleanType MonitorProgress(const char *text,const MagickOffsetType offset,const MagickSizeType extent,void *client_data) {
    IM_TestViewController *IMVC = client_data;
    float prog = offset;
    float tot = extent;
    NSNumber *value = [NSNumber numberWithFloat:prog/tot];
    [IMVC performSelectorInBackground:@selector(updateProgressBar:) withObject:value] ;
    NSLog(@"Action : %@ %lld on %lld", [NSString stringWithCString:text encoding:NSUTF8StringEncoding], offset, extent);
    return MagickTrue;
}

- (void)updateProgressBar:(NSNumber *)value {
    self.progressBar.progress = [value floatValue];
}
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: progress monitor ios

Post by magick »

Almost any operation that reads or updates image pixels calls the progress monitor but ImageMagick does not maintain state with the progress monitor other than what is passed to the monitor method-- the operation, the relative offset, and the extent of the offset (e.g. resizing scanline 0 of 100, resizing scanline 1 of 100, ... resizing scanline 99 of 100).
Post Reply