void ScImgDataLoader_GMagick::loadEmbeddedProfile(const QString& fn, int /*page*/)
{
	initGraphicsMagick();
	m_embeddedProfile.resize(0);
	m_profileComponents = 0;
	if (!QFile::exists(fn)) return;

	ExceptionInfo exception;
	GetExceptionInfo(&exception);
	ImageInfo *image_info = CloneImageInfo(0);
	strcpy(image_info->filename, fn.toUtf8().data());
	image_info->units = PixelsPerInchResolution;
	Image *image = ReadImage(image_info, &exception);
	if (exception.severity != UndefinedException)
		CatchException(&exception);
	if (!image) {
		qCritical() << "Failed to read image" << fn;
		return;
	}

	size_t length = 0;
	const unsigned char *src = GetImageProfile(image, "ICM", &length);
	char *dest = m_embeddedProfile.data();

	if (image->colorspace == CMYKColorspace) {
		m_profileComponents = 4;
	} else if (image->colorspace == RGBColorspace) {
		m_profileComponents = 3;
	}

	m_embeddedProfile.resize(length);
	memcpy(dest, src, length);
}
bool ScImgDataLoader_GMagick::preloadAlphaChannel(const QString& fn, int /*page*/, int res, bool& hasAlpha)
{
	initGraphicsMagick();
	initialize();
	hasAlpha = false;

	if (!QFile::exists(fn))
		return false;

	ExceptionInfo exception;
	GetExceptionInfo(&exception);
	ImageInfo *image_info = CloneImageInfo(0);
	strcpy(image_info->filename, fn.toUtf8().data());
	image_info->units = PixelsPerInchResolution;
	Image *image = PingImage(image_info, &exception);
	if (exception.severity != UndefinedException)
		CatchException(&exception);
	if (!image) {
		qCritical() << "Failed to read image" << fn;
		return false;
	}

	hasAlpha = image->matte;
	if (!hasAlpha) return true;
	return loadPicture(fn, 0, 0, false);
}
示例#3
0
文件: exmagick.c 项目: Xerpa/exmagick
static
ERL_NIF_TERM exmagick_init_handle (ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
  ERL_NIF_TERM result;

  EXM_INIT;
  ErlNifResourceType *type = (ErlNifResourceType *) enif_priv_data(env);
  exm_resource_t *resource = enif_alloc_resource(type, sizeof(exm_resource_t));
  if (resource == NULL)
  { EXM_FAIL(ehandler, "enif_alloc_resource"); }

  /* initializes exception to default values (badly named function) */
  GetExceptionInfo(&resource->e_info);

  resource->image  = NULL;
  resource->i_info = CloneImageInfo(0);
  if (resource->i_info == NULL)
  { EXM_FAIL(ehandler, "CloneImageInfo"); }

  result = enif_make_resource(env, (void *) resource);
  enif_release_resource(resource);
  return(enif_make_tuple2(env, enif_make_atom(env, "ok"), result));

ehandler:
  if (resource != NULL)
  {
    if (resource->i_info != NULL)
    { DestroyImageInfo(resource->i_info); }
    enif_release_resource(resource);
  }
  return(enif_make_tuple2(env, enif_make_atom(env, "error"), exmagick_make_utf8str(env, errmsg)));
}
示例#4
0
文件: rminfo.c 项目: AzkaarAli/leihs
/*
    Method:     Info#format=
    Purpose:    Set the image encoding format
*/
VALUE
Info_format_eq(VALUE self, VALUE magick)
{
    Info *info;
    const MagickInfo *m;
    char *mgk;
    ExceptionInfo exception;

    Data_Get_Struct(self, Info, info);

    GetExceptionInfo(&exception);

    mgk = StringValuePtr(magick);
    m = GetMagickInfo(mgk, &exception);
    CHECK_EXCEPTION()
    (void) DestroyExceptionInfo(&exception);

    if (!m)
    {
        rb_raise(rb_eArgError, "unknown format: %s", mgk);
    }

    strncpy(info->magick, m->name, MaxTextExtent-1);
    return self;
}
/* auto orient image */
ngx_int_t 
gm_auto_orient_image(ngx_http_request_t *r, void *option, Image **image)
{
    ExceptionInfo                      exception;

    Image                             *orient_image = NULL;

    dd("starting auto orient");

    GetExceptionInfo(&exception);
    orient_image=AutoOrientImage(*image,(*image)->orientation, &exception);

    if (orient_image == (Image *) NULL) {
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                "gm filter: auto orient image failed, "
                "severity: \"%O\" "
                "reason: \"%s\", description: \"%s\"",
                exception.severity, exception.reason, exception.description);

        DestroyExceptionInfo(&exception);

        return NGX_ERROR;
    }

    DestroyImage(*image);
    *image = orient_image;
    DestroyExceptionInfo(&exception);

    return NGX_OK;
}
void    appendImageBytesToRaw(int fd, char * file) {
    Image *img = get_image_from_path(file);

    unsigned char   *pixel_map = NULL;
    size_t pixel_map_size = img->columns * img->rows * sizeof(*pixel_map);
    pixel_map = malloc(pixel_map_size);
    unsigned int    x = 0;
    unsigned int    y = 0;
    int             width = (int)img->columns;
    int             height = (int)img->rows;
    PixelPacket     *px;
    ExceptionInfo	exception;

    GetExceptionInfo(&exception);

    px = GetImagePixels(img, 0, 0, img->columns, img->rows);

    while (y < height) {
        x = 0;
        while (x < width) {
            pixel_map[(width * y) + x] = (char)px[(width * y) + x].green;
            x++;
        }
        y++;
    }
    write(fd, pixel_map, pixel_map_size);
    free(pixel_map);
    DestroyImage(img);

}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   N e w M a g i c k W a n d                                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  NewMagickWand() returns a wand required for all other methods in the API.
%
%  The format of the NewMagickWand method is:
%
%      MagickWand *NewMagickWand(void)
%
*/
WandExport MagickWand *NewMagickWand(void)
{
  const char
    *quantum;

  MagickWand
    *wand;

  unsigned long
    depth;

  depth=QuantumDepth;
  quantum=GetMagickQuantumDepth(&depth);
  if (depth != QuantumDepth)
    ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum);
  wand=(MagickWand *) AcquireMagickMemory(sizeof(*wand));
  if (wand == (MagickWand *) NULL)
    ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
      strerror(errno));
  (void) ResetMagickMemory(wand,0,sizeof(*wand));
  wand->id=AcquireWandId();
  (void) FormatMagickString(wand->name,MaxTextExtent,"%s-%lu",MagickWandId,
    wand->id);
  GetExceptionInfo(&wand->exception);
  wand->image_info=CloneImageInfo((ImageInfo *) NULL);
  wand->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
  wand->images=NewImageList();
  wand->debug=IsEventLogging();
  if (wand->debug != MagickFalse)
    (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
  wand->signature=MagickSignature;
  return(wand);
}
示例#8
0
int main ( int argc, char **argv )
{
  Image *canvas = (Image *)NULL;
  char outfile[MaxTextExtent];
  int rows, columns = 0;
  char size[MaxTextExtent];
  ImageInfo *image_info;
  ExceptionInfo exception;

  if ( argc != 2 )
    {
      (void) printf ( "Usage: %s filename\n", argv[0] );
      exit( 1 );
    }

  outfile[MaxTextExtent-1]='\0';
  (void) strncpy( outfile, argv[1], MaxTextExtent-1 );

  if (LocaleNCompare("drawtest",argv[0],7) == 0)
    InitializeMagick((char *) NULL);
  else
    InitializeMagick(*argv);

  /*
   * Create canvas image
   */
  columns=596;
  rows=842;
  image_info=CloneImageInfo((ImageInfo*)NULL);
  GetExceptionInfo( &exception );
  FormatString(size, "%dx%d", columns, rows);
  (void) CloneString(&image_info->size, size);
  (void) strcpy( image_info->filename, "xc:white");
  canvas = ReadImage ( image_info, &exception );
  if (exception.severity != UndefinedException)
    CatchException(&exception);
  if ( canvas == (Image *)NULL )
    {
      (void) printf ( "Failed to read canvas image %s\n", image_info->filename );
      exit(1);
    }

  /*
   * Scribble on image
   */
  ScribbleImage( canvas );

  /*
   * Save image to file
   */
  canvas->filename[MaxTextExtent-1]='\0';
  (void) strncpy( canvas->filename, outfile, MaxTextExtent-1);
  (void) WriteImage ( image_info, canvas );

  DestroyExceptionInfo( &exception );
  DestroyImage( canvas );
  DestroyImageInfo( image_info );
  DestroyMagick();
  return 0;
}
Image::Image( uint32 width, uint32 height,
              const char* map, 
              StorageType storage,
              const void* pixels ) throw (GSystem::Exception):
   m_image( NULL ) {

   // initialize exception
   ExceptionInfo exception;
   GetExceptionInfo( &exception );

   m_image = ConstituteImage( width, height, map, storage,
                              pixels, &exception );
   if ( m_image == NULL ) {
      MC2String exceptionString = "Reason: ";
      exceptionString += exception.reason;
      exceptionString += "Description: ";
      exceptionString += exception.description;

      DestroyExceptionInfo( &exception );

      throw GSystem::Exception( "[ImageMagick]" + exceptionString );
   }
   DestroyExceptionInfo( &exception );

   GetQuantizeInfo(&m_quantizeInfo);
}
示例#10
0
/*
    Method:     ImageList#fx(expression[, channel...])
*/
VALUE
ImageList_fx(int argc, VALUE *argv, VALUE self)
{
    Image *images, *new_image;
    char *expression;
    ChannelType channels;
    ExceptionInfo exception;


    channels = extract_channels(&argc, argv);

    // There must be exactly 1 remaining argument.
    if (argc == 0)
    {
        rb_raise(rb_eArgError, "wrong number of arguments (0 for 1 or more)");
    }
    else if (argc > 1)
    {
        raise_ChannelType_error(argv[argc-1]);
    }

    expression = StringValuePtr(argv[0]);

    images = images_from_imagelist(self);
    GetExceptionInfo(&exception);
    new_image = FxImageChannel(images, channels, expression, &exception);
    rm_split(images);
    rm_check_exception(&exception, new_image, DestroyOnError);
    (void) DestroyExceptionInfo(&exception);

    rm_ensure_result(new_image);

    return rm_image_new(new_image);
}
pair< unsigned char*, int >
Image::getBuffer() {
   size_t size = 0;
   ::ImageInfo info;
   GetImageInfo( &info );
   ExceptionInfo exception;
   GetExceptionInfo( &exception );

   unsigned char* blob = ImageToBlob( &info, m_image, &size,
                                      &exception );
   if ( blob == NULL ) {
      MC2String exceptionString = "Reason: ";
      exceptionString += exception.reason;
      exceptionString += "Description: ";
      exceptionString += exception.description;

      DestroyExceptionInfo( &exception );

      throw GSystem::Exception( "[ImageMagick]" + exceptionString );
   }

   DestroyExceptionInfo( &exception );

   return make_pair( blob, size );
}
示例#12
0
/*
    Method:     ImageList#morph(number_images)
    Purpose:    requires a minimum of two images. The first image is
                transformed into the second by a number of intervening images
                as specified by "number_images".
    Returns:    a new Image with the images array set to the morph sequence.
                @scenes = 0
*/
VALUE
ImageList_morph(VALUE self, VALUE nimages)
{
    Image *images, *new_images;
    ExceptionInfo exception;
    long number_images;


    // Use a signed long so we can test for a negative argument.
    number_images = NUM2LONG(nimages);
    if (number_images <= 0)
    {
        rb_raise(rb_eArgError, "number of intervening images must be > 0");
    }

    GetExceptionInfo(&exception);
    images = images_from_imagelist(self);
    new_images = MorphImages(images, (unsigned long)number_images, &exception);
    rm_split(images);
    rm_check_exception(&exception, new_images, DestroyOnError);
    (void) DestroyExceptionInfo(&exception);

    rm_ensure_result(new_images);

    return rm_imagelist_from_images(new_images);
}
示例#13
0
文件: rminfo.c 项目: AzkaarAli/leihs
/*
    Static:     set_color_option
    Purpose:    Set a color name as the value of the specified option
    Note:       Call QueryColorDatabase to validate color name
*/
static VALUE set_color_option(VALUE self, const char *option, VALUE color)
{
    Info *info;
    char *name;
    PixelPacket pp;
    ExceptionInfo exception;
    MagickBooleanType okay;

    Data_Get_Struct(self, Info, info);

    if (NIL_P(color))
    {
        (void) RemoveImageOption(info, option);
    }
    else
    {
        GetExceptionInfo(&exception);
        name = StringValuePtr(color);
        okay = QueryColorDatabase(name, &pp, &exception);
        (void) DestroyExceptionInfo(&exception);
        if (!okay)
        {
            rb_raise(rb_eArgError, "invalid color name `%s'", name);
        }

        (void) RemoveImageOption(info, option);
        (void) SetImageOption(info, option, name);
    }

    return self;
}
示例#14
0
Image		*get_image_from_path(char *path)
{
    ImageInfo	*image_info;
    Image		*img = NULL;
    ExceptionInfo	exception;
    
    GetExceptionInfo(&exception);
    if ((image_info = CloneImageInfo((ImageInfo *)NULL)) == NULL) {
        CatchException(&exception);
        DestroyImageInfo(image_info);
        DestroyImage(img);
        return (NULL);
    }
    
    strcpy(image_info->filename, path);
    
    if ((img = ReadImage(image_info, &exception)) == NULL)
    {
        CatchException(&exception);
        DestroyImageInfo(image_info);
        DestroyImage(img);
        return (NULL);
    }
    DestroyImageInfo(image_info);
    return (img);
}
示例#15
0
Image       *get_threshold_image(Image *img, c_threshold *c)
{
    Image       *threshold_img;
    int         size_x, size_y;
    int         i = 0;
    int         j = 0;
    char        *string_img = malloc(img->rows * img->columns * sizeof(*string_img));
    char        *temp_string_img;
    PixelPacket	*px;
    ExceptionInfo	exception;
    
    GetExceptionInfo(&exception);

    px = GetImagePixels(img, 0, 0, img->columns, img->rows);
    size_x = (int)img->columns;
    size_y = (int)img->rows;
    
    while (i < size_y) {
        j=0;
        while (j < size_x) {
            string_img[(size_x * i) + j] = (char)px[(size_x * i) + j].green;
            j++;
        }
        i++;
    }
    temp_string_img = otsu_th(size_x, size_y, string_img, c);
    
    threshold_img = ConstituteImage(size_x, size_y, "I", CharPixel, temp_string_img, &exception);
    free(temp_string_img);
    free(string_img);

    DestroyImage(img);
    SyncImagePixels(threshold_img);
    return (threshold_img);
}
示例#16
0
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   C l o n e M a g i c k W a n d                                             %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  CloneMagickWand() makes an exact copy of the specified wand.
%
%  The format of the CloneMagickWand method is:
%
%      MagickWand *CloneMagickWand(const MagickWand *wand)
%
%  A description of each parameter follows:
%
%    o wand: The magick wand.
%
%
*/
WandExport MagickWand *CloneMagickWand(const MagickWand *wand)
{
  MagickWand
    *clone_wand;

  assert(wand != (MagickWand *) NULL);
  assert(wand->signature == MagickSignature);
  if (wand->debug != MagickFalse)
    (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
  clone_wand=(MagickWand *) AcquireMagickMemory(sizeof(*clone_wand));
  if (clone_wand == (MagickWand *) NULL)
    ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
      strerror(errno));
  (void) ResetMagickMemory(clone_wand,0,sizeof(*clone_wand));
  clone_wand->id=AcquireWandId();
  (void) FormatMagickString(clone_wand->name,MaxTextExtent,"MagickWand-%lu",
    clone_wand->id);
  GetExceptionInfo(&clone_wand->exception);
  InheritException(&clone_wand->exception,&wand->exception);
  clone_wand->image_info=CloneImageInfo(wand->image_info);
  clone_wand->quantize_info=CloneQuantizeInfo(wand->quantize_info);
  clone_wand->images=CloneImageList(wand->images,&clone_wand->exception);
  clone_wand->debug=IsEventLogging();
  if (clone_wand->debug != MagickFalse)
    (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",clone_wand->name);
  clone_wand->signature=MagickSignature;
  return(clone_wand);
}
示例#17
0
Image   *crop_masked_final_image(Image *org_img, Image *mask_img)
{
    unsigned int    x = 0;
    unsigned int    y = 0;
    int             width = (int)org_img->columns;
    int             height = (int)org_img->rows;
    PixelPacket     *px;
    PixelPacket     *mask_px;
    ExceptionInfo	exception;
    
    GetExceptionInfo(&exception);
    
    px = GetImagePixels(org_img, 0, 0, org_img->columns, org_img->rows);
    mask_px = GetImagePixels(mask_img, 0, 0, mask_img->columns, mask_img->rows);
    
    while (y < height) {
        x = 0;
        while (x < width) {
            if (mask_px[(width * y) + x].red == WHITE) {
                px[(width * y) + x].green = px[(width * y) + x].blue = px[(width * y) + x].red = BLACK;
            }
            x++;
        }
        y++;
    }
    DestroyImage(mask_img);
    return (org_img);
}
示例#18
0
void CheckStatus(int status)
{
    if (status)
    {
        std::runtime_error error(GetExceptionInfo());
        throw error;
    }
}
示例#19
0
Image       *deconstruction(Image *img){
    ExceptionInfo	exception;
    GetExceptionInfo(&exception);
    
    DeconstructImages(img, &exception);
    SyncImagePixels(img);
    return (img);
}
示例#20
0
int
install_input_magick_readers(void)
{
#if (MagickLibVersion < 0x0534)
#define AT_MAGICK_SET_INFO(X) X = GetMagickInfo(NULL)
#else  /* (MagickLibVersion < 0x0534) */
#define AT_MAGICK_SET_INFO(X)			\
  do {						\
    X = GetMagickInfo(NULL, &exception);	\
    if (X && !X->next)				\
      X = GetMagickInfo("*", &exception);	\
  } while (0)
#endif	/* (MagickLibVersion < 0x0534) */

#if (MagickLibVersion < 0x0537)
#define AT_MAGICK_SUFFIX_FIELD_NAME tag
#else  /* (MagickLibVersion < 0x0537) */
#define AT_MAGICK_SUFFIX_FIELD_NAME name
#endif	/* (MagickLibVersion < 0x0537) */

#if (MagickLibVersion < 0x0538)
#define AT_MAGICK_INITIALIZER()     MagickIncarnate("")
#else  /* (MagickLibVersion < 0x0538) */
#define AT_MAGICK_INITIALIZER()           MagickCoreGenesis("",MagickFalse);
#endif	/* (MagickLibVersion < 0x0538) */


#if (MagickLibVersion < 0x0540)
#define AT_MAGICK_INFO_TYPE_MODIFIER     const
#else  /* (MagickLibVersion < 0x0540) */
#define AT_MAGICK_INFO_TYPE_MODIFIER 
#endif	/* (MagickLibVersion < 0x0540)*/

  {
    ExceptionInfo exception;

    AT_MAGICK_INFO_TYPE_MODIFIER const MagickInfo *info, *magickinfo;
    AT_MAGICK_INITIALIZER() ;

    GetExceptionInfo(&exception);

    AT_MAGICK_SET_INFO(info);
    magickinfo = info;

    while (info)
      {
	if (info->AT_MAGICK_SUFFIX_FIELD_NAME && info->description)
	  at_input_add_handler_full(info->AT_MAGICK_SUFFIX_FIELD_NAME,
				    info->description,
				    input_magick_reader,
				    0,
				    info->AT_MAGICK_SUFFIX_FIELD_NAME,
				    NULL);
	info = info->next ;
      }
  }
  return 0;
}
bool ScImgDataLoader_GMagick::readCMYK(Image *input, RawImage *output, int width, int height)
{
	/* Mapping:
		red:     cyan
		green:   magenta
		blue:    yellow
		opacity: black
		index:   alpha
	*/
	//Copied from GraphicsMagick header and modified
	#define GetCyanSample(p) (p.red)
	#define GetMagentaSample(p) (p.green)
	#define GetYellowSample(p) (p.blue)
	#define GetCMYKBlackSample(p) (p.opacity)
	#define GetAlphaSample(p) (p)

	bool hasAlpha = input->matte;

	if (!output->create(width, height, hasAlpha ? 5 : 4)) return false;

	ExceptionInfo exception;
	GetExceptionInfo(&exception);
	const PixelPacket *pixels = AcquireImagePixels(input, 0, 0, width, height, &exception);
	if (exception.severity != UndefinedException)
		CatchException(&exception);
	if (!pixels) {
		qCritical() << QObject::tr("Could not get pixel data!");
		return false;
	}

    const IndexPacket *alpha = 0;
    if (hasAlpha) {
        alpha = AccessImmutableIndexes(input);
        if (!alpha) {
            qCritical() << QObject::tr("Could not get alpha channel data!");
            return false;
        }
    }

	unsigned char *buffer = output->bits();
	if (!buffer) {
	   qCritical() << QObject::tr("Could not allocate output buffer!");
	   return false;
    }

	int i;
	for (i = 0; i < width*height; i++) {
		*buffer++ = ScaleQuantumToChar(GetCyanSample(pixels[i]));
		*buffer++ = ScaleQuantumToChar(GetMagentaSample(pixels[i]));
		*buffer++ = ScaleQuantumToChar(GetYellowSample(pixels[i]));
		*buffer++ = ScaleQuantumToChar(GetCMYKBlackSample(pixels[i]));
		if (hasAlpha) {
			*buffer++ = 255 - ScaleQuantumToChar(GetAlphaSample(alpha[i]));
		}
	}
	return true;
}
示例#22
0
/*
    Method:     ImageList#composite_layers
    Purpose:    Equivalent to convert's -layers composite option
    Notes:      see mogrify.c
*/
VALUE
ImageList_composite_layers(int argc, VALUE *argv, VALUE self)
{
#if defined(HAVE_COMPOSITELAYERS)
    volatile VALUE source_images;
    Image *dest, *source, *new_images;
    RectangleInfo geometry;
    CompositeOperator operator = OverCompositeOp;
    ExceptionInfo exception;

    switch (argc)
    {
        case 2:
            VALUE_TO_ENUM(argv[1], operator, CompositeOperator);
        case 1:
            source_images = argv[0];
            break;
        default:
            rb_raise(rb_eArgError, "wrong number of arguments (expected 1 or 2, got %d)", argc);
            break;
    }

    // Convert ImageLists to image sequences.
    dest = images_from_imagelist(self);
    new_images = clone_imagelist(dest);
    rm_split(dest);

    source = images_from_imagelist(source_images);

    SetGeometry(new_images,&geometry);
    (void) ParseAbsoluteGeometry(new_images->geometry, &geometry);

    geometry.width  = source->page.width != 0 ? source->page.width : source->columns;
    geometry.height = source->page.height != 0 ? source->page.height : source->rows;
    GravityAdjustGeometry(new_images->page.width  != 0 ? new_images->page.width  : new_images->columns
                        , new_images->page.height != 0 ? new_images->page.height : new_images->rows
                        , new_images->gravity, &geometry);

    GetExceptionInfo(&exception);
    CompositeLayers(new_images, operator, source, geometry.x, geometry.y, &exception);
    rm_split(source);
    rm_check_exception(&exception, new_images, DestroyOnError);
    (void) DestroyExceptionInfo(&exception);

    return rm_imagelist_from_images(new_images);

#else

    self = self;
    argc = argc;
    argv = argv;
    rm_not_implemented();
    return (VALUE)0;

#endif
}
示例#23
0
/*----------------------------------------------------------------------- */
SEXP
lib_writeImages (SEXP x, SEXP files, SEXP quality) {
    int nz, nfiles, i;
    Image * images, * image;
    ImageInfo *image_info;
    ExceptionInfo exception;

    /* basic checks */
    validImage(x,0);

    images = sexp2Magick (x);
    nz = GetImageListLength(images);
 
    nfiles = LENGTH (files);
    if ( nfiles != 1 && nfiles != nz)
        error ( "number of files must be 1, or equal to the size of the image stack" );
    
    if ( images == NULL || GetImageListLength (images) < 1 )
        error ( "cannot write an empty image" );
    GetExceptionInfo (&exception);
    image_info = CloneImageInfo ( (ImageInfo *)NULL );
    /* set attributes in image_info*/
    image_info->compression = images->compression;
    image_info->quality = (unsigned int) INTEGER (quality)[0];
    if ( nfiles == 1 ) {
    /* save into a single file, TIFF, GIF, or automatically add file suffixes */
        strcpy (image_info->filename, CHAR(STRING_ELT(files, 0)) );
        /* we want to overwrite the feature imported from SEXP image */
        strcpy (images->filename, image_info->filename);
        WriteImages(image_info, images, CHAR(STRING_ELT(files, 0)), &exception);
        CatchException (&exception);
    }
    else {
    /* save each frame into a separate file */
        for ( i = 0; i < nz; i++ ) {
            image = GetImageFromList (images, i);
            if ( image == NULL || GetImageListLength (image) < 1 ) {
                warning ( "cannot write an empty image, skipping" );
                continue;
            }
            strcpy (image_info->filename, CHAR(STRING_ELT(files, i)));
            /* we want to overwrite the feature imported from SEXP image */
            strcpy (image->filename, image_info->filename);
            WriteImage (image_info, image);
            CatchException (&image->exception);
            // WriteImages(image_info, image, CHAR(STRING_ELT(files, i)), &exception);
            // CatchException (&exception);

        }
    }

    image_info = DestroyImageInfo (image_info);
    images = DestroyImageList (images);
    DestroyExceptionInfo(&exception);
    return R_NilValue;
}
示例#24
0
Image   *get_blur_maked(Image *img, c_image *c)
{
    Image           *maked_img;
    static  unsigned short    color = 0;
    unsigned int    x = 0;
    unsigned int    y = 0;
    unsigned char   *pixel_map = malloc(img->columns * img->rows * sizeof(*pixel_map));
    
    c->label_map = malloc(img->columns * img->rows * sizeof(*c->label_map));
    
    int             width = (int)img->columns;
    int             height = (int)img->rows;
    
    PixelPacket     *px;
    ExceptionInfo	exception;
    
    GetExceptionInfo(&exception);
    
    px = GetImagePixels(img, 0, 0, img->columns, img->rows);
    
    while (y < height) {
        x = 0;
        while (x < width) {
            pixel_map[(width * y) + x] = (char)px[(width * y) + x].green;
            x++;
        }
        y++;
    }
    y = 0;
    
    while (y < height){
        x = 0;
        while (x < width){
            if (pixel_map[(width * y) + x] != WHITE){
                c->label_map[(width * y) + x] = 1;
                pixel_map[(width * y) + x] = get_neighborpixcel(pixel_map, x, y, width, height, color, c);
            }
            else{
                c->label_map[(width * y) + x] = 0;
            }
            if(color >= 255){
                color = 0;
            }
            x++;
        }
        y++;
     }
    maked_img = ConstituteImage(width, height, "I", CharPixel, pixel_map, &exception);
    
    free(c->label_map);
    free(pixel_map);
    DestroyImage(img);
    SyncImagePixels(maked_img);
    
    return (maked_img);
}
示例#25
0
Image       *reduce_noice(Image *img){
    Image *new_img = NULL;
    ExceptionInfo	exception;
    GetExceptionInfo(&exception);
    
    new_img = ReduceNoiseImage(img, 1, &exception);
    DestroyImage(img);
    SyncImagePixels(new_img);
    return (new_img);
}
示例#26
0
Image       *rotate_image(Image *img, int degrees){
    Image           *retated_img = NULL;
    ExceptionInfo	exception;
    GetExceptionInfo(&exception);
    
    retated_img = RotateImage(img, degrees, &exception);
    DestroyImage(img);
    SyncImagePixels(retated_img);
    return (retated_img);
}
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;
}
示例#28
0
Image		*get_blue_channe_image(Image *img)
{
  unsigned int	i = 0;
  unsigned int	j = 0;
  PixelPacket	*px_original;
  PixelPacket	*px_new;
  Image		*new_img;
  ExceptionInfo	exception;
  ImageInfo	*new_img_info;

  GetExceptionInfo(&exception);
  if ((new_img_info = CloneImageInfo((ImageInfo *)NULL)) == NULL) {
    CatchException(&exception);
    DestroyImageInfo(new_img_info);
    return (NULL);
  }

  new_img_info->colorspace = RGBColorspace;
  new_img = AllocateImage(new_img_info);
  new_img->rows = img->rows;
  new_img->columns = img->columns;

  if ((px_original = GetImagePixelsEx(img, 0, 0, img->columns, img->rows, &exception)) == NULL)
    {
      DestroyImage(new_img);
      CatchException(&exception);
      return (NULL);
    }

  if ((px_new = SetImagePixelsEx(new_img, 0, 0, new_img->columns, new_img->rows, &exception)) == NULL)
    {
      DestroyImage(new_img);
      CatchException(&exception);
      return (NULL);
    }

  while (i < img->rows)
    {
      j = 0;
      while (j < img->columns)
	{
	  px_new[(new_img->columns * i) + j].red = 0;
	  px_new[(new_img->columns * i) + j].blue = px_original[(img->columns * i) + j].blue;
	  px_new[(new_img->columns * i) + j].green = 0;
	  j++;
	}
      i++;
    }
  SyncImagePixels(new_img);

  DestroyImageInfo(new_img_info);

  return (new_img);
}
示例#29
0
Image       *edge_image(Image *img)
{
    Image           *new_image = NULL;
    ExceptionInfo	exception;
    
    GetExceptionInfo(&exception);
    new_image = EdgeImage(img, 5, &exception);
    DestroyImage(img);
    SyncImagePixels(new_image);
    return (new_image);
}
示例#30
0
Image       *unsharp_mask_image(Image *img, double sigma, double amount)
{
    //double radius = img->columns > img->rows ? img->rows : img->columns;
    Image *new_img = NULL;
    ExceptionInfo	exception;
    GetExceptionInfo(&exception);
     
    new_img = UnsharpMaskImage(img, 0, sigma, amount, 0.03, &exception);
    DestroyImage(img);
    return (new_img);
}