Ejemplo n.º 1
0
//==============================================================
void f0r_update(f0r_instance_t instance, double time, const uint32_t* inframe, uint32_t* outframe)
{
  Tinstance *in;
  in=(Tinstance*)instance;
  ExceptionInfo *exception;
  /* Generamos la excepción */
  exception = AcquireExceptionInfo();
  /* Transformamos el mapa de imagen de entrada para imagemagick */
  Image *im = ConstituteImage(in->size.width, in->size.height, "RGBA", CharPixel, inframe, exception);

  if (in->preview) 
    {
      minify(&im, (int)in->preview, exception);
    }
  /* Generamos la imagen de salida */
  Image *out = MotionBlurImage(im, in->radius, in->deviation, in->angle, exception);
  if (in->preview) 
    {
      magnify(&out, (int)in->preview, exception);
    }
  /* Volvemos a coger el contenido de la imagen para frei0r */
  ExportImagePixels(out, 0, 0, in->size.width, in->size.height, "RGBA", CharPixel,  outframe, exception);

  /* Liberamos memoria */
  exception = DestroyExceptionInfo(exception);
  im = DestroyImage(im);
  out = DestroyImage(out);
}
Ejemplo n.º 2
0
MAGICK_NET_EXPORT unsigned short *PixelCollection_ToShortArray(const CacheView *instance, const size_t x, const size_t y, const size_t width, const size_t height, const char *mapping, ExceptionInfo **exception)
{
  ExportStart(unsigned short);
  result = AcquireMagickMemory(length);
  MAGICK_NET_GET_EXCEPTION;
  ExportImagePixels(GetCacheViewImage(instance), x, y, width, height, mapping, ShortPixel, result, exceptionInfo);
  MAGICK_NET_SET_EXCEPTION;
  return result;
}
Ejemplo n.º 3
0
struct fp_img *fpi_im_resize(struct fp_img *img, unsigned int factor)
{
	Image *mimg;
	Image *resized;
	ExceptionInfo exception;
	MagickBooleanType ret;
	int new_width = img->width * factor;
	int new_height = img->height * factor;
	struct fp_img *newimg;

	/* It is possible to implement resizing using a simple algorithm, however
	 * we use ImageMagick because it applies some kind of smoothing to the
	 * result, which improves matching performances in my experiments. */

	if (!IsMagickInstantiated())
		InitializeMagick(NULL);
	
	GetExceptionInfo(&exception);
	mimg = ConstituteImage(img->width, img->height, "I", CharPixel, img->data,
		&exception);

	GetExceptionInfo(&exception);
	resized = ResizeImage(mimg, new_width, new_height, 0, 1.0, &exception);

	newimg = fpi_img_new(new_width * new_height);
	newimg->width = new_width;
	newimg->height = new_height;
	newimg->flags = img->flags;

	GetExceptionInfo(&exception);
	ret = ExportImagePixels(resized, 0, 0, new_width, new_height, "I",
		CharPixel, newimg->data, &exception);
	if (ret != MagickTrue) {
		fp_err("export failed");
		return NULL;
	}

	DestroyImage(mimg);
	DestroyImage(resized);

	return newimg;
}
Ejemplo n.º 4
0
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   V a l i d a t e I m p o r t E x p o r t P i x e l s                       %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  ValidateImportExportPixels() validates the pixel import and export methods.
%  It returns the number of validation tests that passed and failed.
%
%  The format of the ValidateImportExportPixels method is:
%
%      unsigned long ValidateImportExportPixels(ImageInfo *image_info,
%        const char *reference_filename,const char *output_filename,
%        unsigned long *fail,ExceptionInfo *exception)
%
%  A description of each parameter follows:
%
%    o image_info: the image info.
%
%    o reference_filename: the reference image filename.
%
%    o output_filename: the output image filename.
%
%    o fail: return the number of validation tests that pass.
%
%    o exception: return any errors or warnings in this structure.
%
*/
static unsigned long ValidateImportExportPixels(ImageInfo *image_info,
  const char *reference_filename,const char *output_filename,
  unsigned long *fail,ExceptionInfo *exception)
{
  double
    distortion;

  Image
    *difference_image,
    *reference_image,
    *reconstruct_image;

  MagickBooleanType
    status;

  register long
    i,
    j;

  size_t
    length;

  unsigned char
    *pixels;

  unsigned long
    test;

  (void) output_filename;
  test=0;
  (void) fprintf(stdout,"validate the import and export of image pixels:\n");
  for (i=0; reference_map[i] != (char *) NULL; i++)
  {
    for (j=0; reference_storage[j].type != UndefinedPixel; j++)
    {
      /*
        Generate reference image.
      */
      CatchException(exception);
      (void) fprintf(stdout,"  test %lu: %s/%s",test++,
        reference_map[i],MagickOptionToMnemonic(MagickStorageOptions,
        reference_storage[j].type));
      (void) CopyMagickString(image_info->filename,reference_filename,
        MaxTextExtent);
      reference_image=ReadImage(image_info,exception);
      if (reference_image == (Image *) NULL)
        {
          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
          (*fail)++;
          continue;
        }
      if (LocaleNCompare(reference_map[i],"cmy",3) == 0)
        (void) TransformImageColorspace(reference_image,CMYKColorspace);
      length=strlen(reference_map[i])*reference_image->columns*
        reference_image->rows*reference_storage[j].quantum;
      pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
      if (pixels == (unsigned char *) NULL)
        {
          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
          (*fail)++;
          reference_image=DestroyImage(reference_image);
          continue;
        }
      (void) ResetMagickMemory(pixels,0,length*sizeof(*pixels));
      status=ExportImagePixels(reference_image,0,0,reference_image->columns,
        reference_image->rows,reference_map[i],reference_storage[j].type,pixels,
        exception);
      if (status == MagickFalse)
        {
          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
          (*fail)++;
          pixels=(unsigned char *) RelinquishMagickMemory(pixels);
          reference_image=DestroyImage(reference_image);
          continue;
        }
      (void) SetImageBackgroundColor(reference_image);
      status=ImportImagePixels(reference_image,0,0,reference_image->columns,
        reference_image->rows,reference_map[i],reference_storage[j].type,
        pixels);
      InheritException(exception,&reference_image->exception);
      if (status == MagickFalse)
        {
          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
          (*fail)++;
           pixels=(unsigned char *) RelinquishMagickMemory(pixels);
          reference_image=DestroyImage(reference_image);
          continue;
        }
      /*
        Read reconstruct image.
      */
      reconstruct_image=AcquireImage(image_info);
      (void) SetImageColorspace(reconstruct_image,reference_image->colorspace);
      (void) SetImageExtent(reconstruct_image,reference_image->columns,
        reference_image->rows);
      (void) SetImageBackgroundColor(reconstruct_image);
      status=ImportImagePixels(reconstruct_image,0,0,reconstruct_image->columns,
        reconstruct_image->rows,reference_map[i],reference_storage[j].type,
        pixels);
      InheritException(exception,&reconstruct_image->exception);
      pixels=(unsigned char *) RelinquishMagickMemory(pixels);
      if (status == MagickFalse)
        {
          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
          (*fail)++;
          reference_image=DestroyImage(reference_image);
          continue;
        }
      /*
        Compare reference to reconstruct image.
      */
      difference_image=CompareImageChannels(reference_image,reconstruct_image,
        AllChannels,MeanSquaredErrorMetric,&distortion,exception);
      reconstruct_image=DestroyImage(reconstruct_image);
      reference_image=DestroyImage(reference_image);
      if (difference_image == (Image *) NULL)
        {
          (void) fprintf(stdout,"... fail @ %s/%s/%lu.\n",GetMagickModule());
          (*fail)++;
          continue;
        }
      difference_image=DestroyImage(difference_image);
      if ((distortion/QuantumRange) > 0.0)
        {
          (void) fprintf(stdout,"... fail (with distortion %g).\n",distortion/
            QuantumRange);
          (*fail)++;
          continue;
        }
      (void) fprintf(stdout,"... pass.\n");
    }
  }
  (void) fprintf(stdout,"  summary: %lu subtests; %lu passed; %lu failed.\n",
    test,test-(*fail),*fail);
  return(test);
}
Ejemplo n.º 5
0
void ExportRGBA(Image *image, size_t w, size_t h, void *pixels, ExceptionInfo *e) {
	ExportImagePixels(image, 0, 0, w, h, "RGBA", CharPixel, pixels, e);
}