Page 1 of 1

CloneImage() question

Posted: 2008-10-10T19:04:02-07:00
by rmabry
Veering off from a thread on the Users forum, I ran the following, which worked fine:

Code: Select all

imconvert 0001.jpg -write mpr:cap -size 600x600 xc:white -draw "image Darken 100,100 60,60 'mpr:cap'" -delete 0 test.png
Now for reasons not necessary to go into here, I have a bit of debug in the source, namely, the line

Code: Select all

  printf("CloneImage: filename = %s\n", image->filename); 
placed near the top of the CloneImage routine, just before the call

Code: Select all

  clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image)); 
Here is the output when I run the command-line mentioned at the top:

CloneImage: filename = cap
CloneImage: filename = cap
CloneImage: filename = cap
CloneImage: filename = cap
CloneImage: filename = cap
CloneImage: filename = cap
CloneImage: filename = cap


Seven calls to CloneImage() ???

If I use the simpler command,

Code: Select all

imconvert -size 600x600 xc:white -draw "image Darken 100,100 60,60 '0001.jpg'" test.png
then there seems to be two:

CloneImage: filename = 0001.jpg
CloneImage: filename = 0001.jpg


But why even two? What's going on that a curious pixel pusher should know?

Rick

Re: CloneImage() question

Posted: 2008-10-10T19:28:07-07:00
by magick
Cloning copies the image metadata but only increases the reference count for the pixel cache making cloning a relatively inexpensive operation. We clone when an image is pushed to the registry in case the original owner decides to destroy the original image object while it is still in the registry. Without cloning a user would need to synchronize the image destruction only after it is removed from the registry.

Re: CloneImage() question

Posted: 2010-06-11T03:32:13-07:00
by baibaichen
I have some questions
1 Does it mean the cloned image is Copy-on-write or only reference to pixle data which looks like a reference pointer?
2 what is meaning of "registry"? I assume

Thanks
Chang

Re: CloneImage() question

Posted: 2010-06-15T20:00:03-07:00
by anthony
baibaichen wrote:I have some questions
1 Does it mean the cloned image is Copy-on-write or only reference to pixle data which looks like a reference pointer?
2 what is meaning of "registry"? I assume
Clone is copy on write for the pixel data. Typically a complete re-write of the image data, after being processed by some operation coping from the data in the source image just cloned.

Registery is just a 'store' for images, I believe it is also used to hold patterns and internal images when they are needed. that way they get loaded once the first time they are used, and then comes from the store.
MPR just lets you store and retrieve images from the registry.

Actually you should also know that you can NOT replace an image once it is in the MPR store.
so modifying a mpc image and trying to write it back into the store under the same name does not
work. also once an image is in the registry store, you can not delete it from that store.

See Im Examples, MPR
http://www.imagemagick.org/Usage/files/#mpr

You may also be interested in MPC, which saves the inmemeory image into a file than can be 'paged' back into memory rather than 'read'
http://www.imagemagick.org/Usage/files/#mpc