Page 1 of 1

Bug in ColorFloodfillImage in 6.3.2

Posted: 2007-01-21T15:20:26-07:00
by rmagick
The C program below uses ColorFloodfillImage with the FilltoBorderMethod to fill with an image. It produces the expected image when built with "ImageMagick 6.2.9 10/19/06 Q16"
Image

When built with "ImageMagick 6.3.2 01/19/07 Q16" it produces the following image:
Image

Please let me know if you need more information.

Code: Select all

/*
gcc `Magick-config --cflags --cppflags` texturefilltoborder.c `Magick-config --ldflags --libs` -o texturefilltoborder
*/
#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, *rose;
  ImageInfo *image_info;
  PixelPacket black;
  DrawInfo *draw;
  ExceptionInfo exception;
  const char * const primitives =
	"fill transparent\n"
	"stroke black\n"
	"stroke-width 2\n"
	"circle 100,100,180,100\n"
	"fill plum1\n"
	"stroke transparent\n"
	"circle 60,100,40,100\n"
	"circle 140,100,120,100\n"
	"circle 100,60,100,40\n"
	"circle 100,140,100,120\n"
	;

  InitializeMagick("TextureFillToBorderTest");

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

  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);
  }

  //DisplayImages(image_info, image);

  DestroyImageInfo(image_info);

  image_info=CloneImageInfo((ImageInfo *) NULL);
  strcpy(image_info->filename, "rose:");

  SetImageInfoFile(image_info, NULL);

  GetExceptionInfo(&exception);

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

  draw->fill_pattern = rose;
  draw->fill.red = MaxRGB;
  draw->fill.green = MaxRGB;
  draw->fill.blue = MaxRGB;
  draw->fill.opacity = OpaqueOpacity;

  black.red = 0;
  black.green = 0;
  black.blue = 0;
  black.opacity = OpaqueOpacity;

  ColorFloodfillImage(image, draw, black, 100, 100, FillToBorderMethod);
  if (image->exception.severity != UndefinedException)
  {
  	printf("%s: %s", image->exception.reason, image->exception.description);
	exit(1);
  }

  //memset(image_info->filename, 0, sizeof(image_info->filename));
  //DisplayImages(image_info,image);
  strcpy(image_info->filename, "texturefilltoborder.jpg");
  strcpy(image->filename, image_info->filename);
  WriteImage(image_info, image);

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

  return 0;
}
[/code]

Posted: 2007-01-21T17:18:09-07:00
by anthony
Bug was picked up in IM examples and has been fixed in the current alpha test release. The beta of this fix may already be available.

Posted: 2007-01-21T17:42:55-07:00
by rmagick
Good deal! Thanks!

Posted: 2007-01-21T18:39:08-07:00
by magick
The problem is fixed in ImageMagick-6.3.2-1 Beta. It will be available by tommorrow. In the mean-time you can call
  • (void) SetImageVirtualPixelMethod(draw->fill_pattern,TileVirtualPixelMethod);

Posted: 2007-01-22T17:41:54-07:00
by rmagick
I built all the RMagick samples with the beta and everything worked perfectly. Thanks!