Lost frames after clonning

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
opilarium
Posts: 7
Joined: 2014-09-23T08:21:27-07:00
Authentication code: 6789

Lost frames after clonning

Post by opilarium »

I've found some wierd logic in clonning function of image:

Code: Select all

Image *CloneImage(...)
{
...
  if (detach == MagickFalse)
    clone_image->blob=ReferenceBlob(image->blob);
  else
    {
      clone_image->next=NewImageList();
      clone_image->previous=NewImageList();
      clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
    }
That means if an image has multiple pages they will be lost.
I think it's serious bug.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Lost frames after clonning

Post by magick »

Images are typically in a list and maintains its position in the list with the next and previous pointers. CloneImage() is behaving properly in that it typically makes a copy that is standalone to remove it from the list (i.e. an orphan), while leaving the original image in the list. You can set the detach parameter to ensure the clone maintains its position in list. Given that, what exactly is the bug you are reporting?
opilarium
Posts: 7
Joined: 2014-09-23T08:21:27-07:00
Authentication code: 6789

Re: Lost frames after clonning

Post by opilarium »

I serialize an image using write method.

Code: Select all

// Write image to in-memory BLOB
void Magick::Image::write ( Blob *blob_ )
{
  modifyImage();
As listed above write invokes modifyImage.

Code: Select all

void Magick::Image::modifyImage( void )
{
  ...
  replaceImage( CloneImage( image(),
                            0, // columns
                            0, // rows
                            MagickTrue, // orphan
                            &exceptionInfo) );
  ...
}
If the image has it's copy previous and next pages will be lost.

Code: Select all

Magick::Image img1; // has 2 pages
Magick::Image img2( img1 ); // has 2 pages. img2 has ImageRef of img1

Magick::Blob blob;
img2.write( &blob ); // img2 has been detached and now has 1 page!
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Lost frames after clonning

Post by dlemstra »

Magick::Image is always a single image. Take a look at the code that reads the image.

Code: Select all

void Magick::Image::read(MagickCore::Image *image,
  MagickCore::ExceptionInfo *exceptionInfo)
{
  ...
  // Destroy any extra image frames
  next=image->next;
  image->next=(MagickCore::Image *) NULL;
  next->previous=(MagickCore::Image *) NULL;
  DestroyImageList(next);
}
You should use the readImages method from STL.h if you want to read more than one frame.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
opilarium
Posts: 7
Joined: 2014-09-23T08:21:27-07:00
Authentication code: 6789

Re: Lost frames after clonning

Post by opilarium »

Magick::Image is always a single image.
Well. Than how does it work with multipage tiff file?

Code: Select all

Magick::Blob blob( buffer.get(), file_size );
img.read( blob );
img has multiple pages.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Lost frames after clonning

Post by dlemstra »

What do you mean by 'img has multiple pages?'. It will only contain the first page.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
opilarium
Posts: 7
Joined: 2014-09-23T08:21:27-07:00
Authentication code: 6789

Re: Lost frames after clonning

Post by opilarium »

I mean img has properly working img.next image. But I only have one.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Lost frames after clonning

Post by dlemstra »

Are you using the latest version of ImageMagick?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
opilarium
Posts: 7
Joined: 2014-09-23T08:21:27-07:00
Authentication code: 6789

Re: Lost frames after clonning

Post by opilarium »

No. 6.8.3. Is that an issue?
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Lost frames after clonning

Post by dlemstra »

I am asking that because this might be something that was fixed in a later version. The image() property of an img should be NULL.

Code: Select all

Magick::Blob blob( buffer.get(), file_size );
img.read( blob );
if (img.image()->next == NULL) // This should be true...  
A Magick:Image instance should always contain a single image. It should be considered a bug if it contains more then one image.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Post Reply