Ejemplo n.º 1
0
static MagickBooleanType SigmoidalContrast(ImageView *contrast_view,
  const ssize_t y,const int id,void *context)
{
#define QuantumScale  ((MagickRealType) 1.0/(MagickRealType) QuantumRange)
#define SigmoidalContrast(x) \
  (QuantumRange*(1.0/(1+exp(10.0*(0.5-QuantumScale*x)))-0.0066928509)*1.0092503)

  RectangleInfo
    extent;

  register IndexPacket
    *indexes;

  register PixelPacket
    *pixels;

  register ssize_t
    x;

  extent=GetImageViewExtent(contrast_view);
  pixels=GetImageViewAuthenticPixels(contrast_view);
  for (x=0; x < (ssize_t) (extent.width-extent.height); x++)
  {
    pixels[x].red=RoundToQuantum(SigmoidalContrast(pixels[x].red));
    pixels[x].green=RoundToQuantum(SigmoidalContrast(pixels[x].green));
    pixels[x].blue=RoundToQuantum(SigmoidalContrast(pixels[x].blue));
    pixels[x].opacity=RoundToQuantum(SigmoidalContrast(pixels[x].opacity));
  }
  indexes=GetImageViewAuthenticIndexes(contrast_view);
  if (indexes != (IndexPacket *) NULL)
    for (x=0; x < (ssize_t) (extent.width-extent.height); x++)
      indexes[x]=(IndexPacket) RoundToQuantum(SigmoidalContrast(indexes[x]));
  return(MagickTrue);
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
	printf("Hello World\n");
#define QuantumScale ((MagickRealType) 1.0/(MagickRealType) QuantumRange)
#define SigmoidalContrast(x) (QuantumRange*(1.0/(1+exp(10.0*(0.5-QuantumScale*x)))-0.0066928509)*1.0092503)

#define ThrowWandException(wand)\
	{\
		char *description;\
		ExceptionType\
		severity;\
		\
		description=MagickGetException(wand,&severity);\
		(void)fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description);\
		exit(-1);\
	}
	long y;
	MagickBooleanType status;
	MagickPixelPacket pixel;
	MagickWand *contrast_wand, *image_wand;
	PixelIterator *contrast_iterator,*iterator;
	PixelWand **contrast_pixels, **pixels;
	register long x;
	unsigned long width;

	if (argc != 3)
	{
		(void)fprintf(stdout,"Usage: %s image sigmoidal-image\n",argv[0]);
		exit(0);
	}

	/*
	   Read an Image
	   */

	MagickWandGenesis();
	image_wand = NewMagickWand();
	status = MagickReadImage(image_wand,argv[1]);
	if(status == MagickFalse)
		ThrowWandException(image_wand);
	contrast_wand = CloneMagickWand(image_wand);
	/*
	   Sigmoidal non-linearity contrast control.
	   */

	iterator = NewPixelIterator(image_wand);
	contrast_iterator=NewPixelIterator(contrast_wand);

	if((iterator == (PixelIterator*)NULL) || (contrast_iterator == (PixelIterator*)NULL))
		ThrowWandException(image_wand);

	for(y=0; y<(long)MagickGetImageHeight(image_wand); y++)
	{
		pixels = PixelGetNextIteratorRow(iterator,&width);
		contrast_pixels = PixelGetNextIteratorRow(contrast_iterator,&width);
		if((pixels==(PixelWand**)NULL) || (contrast_pixels == (PixelWand**)NULL))
			break;

		for(x = 0; x<(long)width; x++)
		{
			PixelGetMagickColor(pixels[x],&pixel);
			pixel.red = SigmoidalContrast(pixel.red);
			pixel.green = SigmoidalContrast(pixel.green);
			pixel.blue = SigmoidalContrast(pixel.blue);
			pixel.index = SigmoidalContrast(pixel.index);
			PixelSetMagickColor(contrast_pixels[x],&pixel);
		}
		(void)PixelSyncIterator(contrast_iterator);
	}
	if(y < (long)MagickGetImageHeight(image_wand))
		ThrowWandException(image_wand);
	contrast_iterator = DestroyPixelIterator(contrast_iterator);
	iterator = DestroyPixelIterator(iterator);
	image_wand=DestroyMagickWand(image_wand);

	status = MagickWriteImages(contrast_wand,argv[2],MagickTrue);
	if(status == MagickFalse)
		ThrowWandException(image_wand);
	contrast_wand = DestroyMagickWand(contrast_wand);
	MagickWandTerminus();
	return 0;
}