/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % W r i t e M P R I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % WriteMPRImage() writes an image into the Magick Persistent Registry % image as a blob from memory. It allocates the memory necessary for the % new Image structure and returns a pointer to the new image. % % The format of the WriteMPRImage method is: % % MagickBooleanType WriteMPRImage(const ImageInfo *image_info,Image *image) % % A description of each parameter follows. % % o image_info: the image info. % % o image: The image. % */ static MagickBooleanType WriteMPRImage(const ImageInfo *image_info,Image *image) { MagickBooleanType status; assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); status=SetImageRegistry(ImageRegistryType,image->filename,image, &image->exception); return(status); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % D e f i n e I m a g e R e g i s t r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DefineImageRegistry() associates a key/value pair with the image registry. % % The format of the DefineImageRegistry method is: % % MagickBooleanType DefineImageRegistry(const RegistryType type, % const char *option,ExceptionInfo *exception) % % A description of each parameter follows: % % o type: the type. % % o option: the option. % % o exception: the exception. % */ MagickExport MagickBooleanType DefineImageRegistry(const RegistryType type, const char *option,ExceptionInfo *exception) { char key[MaxTextExtent], value[MaxTextExtent]; register char *p; assert(option != (const char *) NULL); (void) CopyMagickString(key,option,MaxTextExtent); for (p=key; *p != '\0'; p++) if (*p == '=') break; *value='\0'; if (*p == '=') (void) CopyMagickString(value,p+1,MaxTextExtent); *p='\0'; return(SetImageRegistry(type,key,value,exception)); }
/* External: write_temp_image Purpose: Write a temporary copy of the image to the IM registry Returns: the "filename" of the registered image Notes: The `temp_name' argument must point to an char array of size MaxTextExtent. */ void rm_write_temp_image(Image *image, char *temp_name) { #define TMPNAM_CLASS_VAR "@@_tmpnam_" MagickBooleanType okay; ExceptionInfo exception; volatile VALUE id_value; int id; GetExceptionInfo(&exception); // 'id' is always the value of its previous use if (rb_cvar_defined(Module_Magick, rb_intern(TMPNAM_CLASS_VAR)) == Qtrue) { id_value = rb_cv_get(Module_Magick, TMPNAM_CLASS_VAR); id = FIX2INT(id_value); } else { id = 0; rb_cv_set(Module_Magick, TMPNAM_CLASS_VAR, INT2FIX(id)); } id += 1; rb_cv_set(Module_Magick, TMPNAM_CLASS_VAR, INT2FIX(id)); sprintf(temp_name, "mpri:%d", id); // Omit "mpri:" from filename to form the key okay = SetImageRegistry(ImageRegistryType, temp_name+5, image, &exception); CHECK_EXCEPTION() DestroyExceptionInfo(&exception); if (!okay) { rb_raise(rb_eRuntimeError, "SetImageRegistry failed."); } }