Page 1 of 1

QuantizeImage never terminates - ImageMagick 6.3.5-2

Posted: 2007-07-24T15:27:44-07:00
by rmagick
The following C program appears to trigger an endless loop in QuantizeImage called from WriteImage. I'm running ImageMagick 6.3.5 07/19/07 Q16 on Mandriva 2006.0.

Please let me know if you need any more information.

Code: Select all

/*
gcc `Magick-config --cflags --cppflags` mattefilltoborder.c `Magick-config --ldflags --libs` -o mattefilltoborder
*/
#include <stdio.h>
#include <time.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <magick/api.h>


int main(int argc,char **argv)
{
  Image *image, *plasma;
  ImageInfo *image_info;
  unsigned int okay;
  PixelPacket border_color = {0};
  PixelPacket white = {MaxRGB, MaxRGB, MaxRGB, OpaqueOpacity};
  DrawInfo *draw;
  ExceptionInfo exception;
  const char * const primitives =
	"stroke-width 2\n"
	"stroke black\n"
	"fill white\n"
	"roundrectangle 0,0,199,199,8,8\n"
	"fill black\n"
	"circle 100,45,100,25\n"
	"circle 45,100,25,100\n"
	"circle 100,155,100,175\n"
	"circle 155,100,175,100\n"
	;

  InitializeMagick("MatteFillToBorderTest");

  image_info=CloneImageInfo((ImageInfo *) NULL);
  image_info->size = AcquireMemory(sizeof("200x200"));
  strcpy(image_info->size, "200x200");
  image_info->background_color = white;

  image=AllocateImage(image_info);
  if (image == (Image *) NULL)
    MagickError(ResourceLimitError,"Unable to display image",
      "Memory allocation failed");

  SetImage(image, OpaqueOpacity);

  draw = CloneDrawInfo(image_info, NULL);
  CloneString(&(draw->primitive), primitives);
  DrawImage(image, draw);
  if (image->exception.severity != UndefinedException)
  {
  	printf("%s: %s", image->exception.reason, image->exception.description);
	exit(1);
  }

  strcpy(image_info->filename, "plasma:fractal");

  GetExceptionInfo(&exception);
  plasma = ReadImage(image_info, &exception);
  if (image->exception.severity != UndefinedException)
  {
  	printf("%s: %s", exception.reason, exception.description);
	exit(1);
  }

  okay = MatteFloodfillImage(image, border_color, TransparentOpacity, 100, 100, FillToBorderMethod);
  printf("MatteFloodfillImage returned %s\n", okay ? "`okay'" : "`not okay'");
  //DisplayImages(image_info,image);

  okay = CompositeImage(plasma, OverCompositeOp, image, 0, 0);
  printf("CompositeImage returned %s\n", okay ? "`okay'" : "`not okay'");

  strcpy(plasma->filename, "mattefilltoborder.gif");
  WriteImage(image_info, plasma);

  /*
    Free resources.
  */
  DestroyExceptionInfo(&exception);
  DestroyDrawInfo(draw);
  DestroyImage(image);
  DestroyImageInfo(image_info);
  DestroyMagick();

  return 0;
}

Re: QuantizeImage never terminates - ImageMagick 6.3.5-2

Posted: 2007-07-24T17:52:28-07:00
by magick
The color reduction would eventually terminate. On our fast processor it takes 32 seconds. The problem relates to the new color reduction algorithm that takes associated alpha into consideration. If you set
  • plasma->matte=MagickFalse
before you call WriteImage() it takes less than 2 seconds to produce the GIF. We patched ImageMagick 6.3.5-4 Beta (available tomorrow) to reduce the oct-tree depth from 6 to 5 and the process completes in 3 seconds.

Re: QuantizeImage never terminates - ImageMagick 6.3.5-2

Posted: 2007-07-24T18:33:23-07:00
by rmagick
Thanks for your help! I'll change the test.