CloneImage() question

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
User avatar
rmabry
Posts: 148
Joined: 2004-04-13T11:25:27-07:00

CloneImage() question

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: CloneImage() question

Post 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.
baibaichen
Posts: 11
Joined: 2010-03-23T20:32:14-07:00
Authentication code: 8675308

Re: CloneImage() question

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: CloneImage() question

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply