/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d I m a g e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadImages() reads one or more images and returns them as an image list. % % The format of the ReadImage method is: % % Image *ReadImages(const ImageInfo *image_info,ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: the image info. % % o exception: return any errors or warnings in this structure. % */ MagickExport Image *ReadImages(const ImageInfo *image_info, ExceptionInfo *exception) { char filename[MaxTextExtent]; Image *image, *images; ImageInfo *read_info; /* Read image list from a file. */ assert(image_info != (ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); (void) InterpretImageFilename(image_info,(Image *) NULL,image_info->filename, (int) image_info->scene,filename); if (LocaleCompare(filename,image_info->filename) != 0) { ExceptionInfo *sans; ssize_t extent, scene; /* Images of the form image-%d.png[1-5]. */ read_info=CloneImageInfo(image_info); sans=AcquireExceptionInfo(); (void) SetImageInfo(read_info,0,sans); sans=DestroyExceptionInfo(sans); (void) CopyMagickString(filename,read_info->filename,MaxTextExtent); images=NewImageList(); extent=(ssize_t) (read_info->scene+read_info->number_scenes); for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++) { (void) InterpretImageFilename(image_info,(Image *) NULL,filename,(int) scene,read_info->filename); image=ReadImage(read_info,exception); if (image == (Image *) NULL) continue; AppendImageToList(&images,image); } read_info=DestroyImageInfo(read_info); return(images); } return(ReadImage(image_info,exception)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % N e w P i x e l I t e r a t o r % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % NewPixelIterator() returns a new pixel iterator. % % The format of the NewPixelIterator method is: % % PixelIterator *NewPixelIterator(MagickWand *wand) % % A description of each parameter follows: % % o wand: the magick wand. % */ WandExport PixelIterator *NewPixelIterator(MagickWand *wand) { const char *quantum; ExceptionInfo *exception; Image *image; PixelIterator *iterator; size_t depth; CacheView *view; depth=MAGICKCORE_QUANTUM_DEPTH; quantum=GetMagickQuantumDepth(&depth); if (depth != MAGICKCORE_QUANTUM_DEPTH) ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum); assert(wand != (MagickWand *) NULL); image=GetImageFromMagickWand(wand); if (image == (Image *) NULL) return((PixelIterator *) NULL); exception=AcquireExceptionInfo(); view=AcquireVirtualCacheView(image,exception); if (view == (CacheView *) NULL) return((PixelIterator *) NULL); iterator=(PixelIterator *) AcquireMagickMemory(sizeof(*iterator)); if (iterator == (PixelIterator *) NULL) ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed", GetExceptionMessage(errno)); (void) ResetMagickMemory(iterator,0,sizeof(*iterator)); iterator->id=AcquireWandId(); (void) FormatLocaleString(iterator->name,MaxTextExtent,"%s-%.20g", PixelIteratorId,(double) iterator->id); iterator->exception=exception; iterator->view=view; SetGeometry(image,&iterator->region); iterator->region.width=image->columns; iterator->region.height=image->rows; iterator->region.x=0; iterator->region.y=0; iterator->pixel_wands=NewPixelWands(iterator->region.width); iterator->y=0; iterator->debug=IsEventLogging(); if (iterator->debug != MagickFalse) (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name); iterator->signature=WandSignature; return(iterator); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % N e w P i x e l R e g i o n I t e r a t o r % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % NewPixelRegionIterator() returns a new pixel iterator. % % The format of the NewPixelRegionIterator method is: % % PixelIterator NewPixelRegionIterator(MagickWand *wand,const long x, % const long y,const unsigned long width,const unsigned long height) % % A description of each parameter follows: % % o wand: the magick wand. % % o x,y,columns,rows: These values define the perimeter of a region of % pixels. % */ WandExport PixelIterator *NewPixelRegionIterator(MagickWand *wand,const long x, const long y,const unsigned long width,const unsigned long height) { const char *quantum; Image *image; PixelIterator *iterator; unsigned long depth; CacheView *view; assert(wand != (MagickWand *) NULL); depth=MAGICKCORE_QUANTUM_DEPTH; quantum=GetMagickQuantumDepth(&depth); if (depth != MAGICKCORE_QUANTUM_DEPTH) ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum); if ((width == 0) || (width == 0)) ThrowWandFatalException(WandError,"ZeroRegionSize",quantum); image=GetImageFromMagickWand(wand); if (image == (Image *) NULL) return((PixelIterator *) NULL); view=AcquireCacheView(image); if (view == (CacheView *) NULL) return((PixelIterator *) NULL); iterator=(PixelIterator *) AcquireMagickMemory(sizeof(*iterator)); if (iterator == (PixelIterator *) NULL) ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed", wand->name); (void) ResetMagickMemory(iterator,0,sizeof(*iterator)); iterator->id=AcquireWandId(); (void) FormatMagickString(iterator->name,MaxTextExtent,"%s-%lu", PixelIteratorId,iterator->id); iterator->exception=AcquireExceptionInfo(); iterator->view=view; SetGeometry(image,&iterator->region); iterator->region.width=width; iterator->region.height=height; iterator->region.x=x; iterator->region.y=y; iterator->pixel_wands=NewPixelWands(iterator->region.width); iterator->y=0; iterator->debug=IsEventLogging(); if (iterator->debug != MagickFalse) (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name); iterator->signature=WandSignature; return(iterator); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % M a i n % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % */ int main(int argc,char **argv) { char *option, *text; ExceptionInfo *exception; ImageInfo *image_info; MagickBooleanType regard_warnings, status; register long i; MagickCoreGenesis(*argv,MagickTrue); exception=AcquireExceptionInfo(); regard_warnings=MagickFalse; for (i=1; i < (long) argc; i++) { option=argv[i]; if ((strlen(option) == 1) || ((*option != '-') && (*option != '+'))) continue; if (LocaleCompare("debug",option+1) == 0) (void) SetLogEventMask(argv[++i]); if (LocaleCompare("regard-warnings",option+1) == 0) regard_warnings=MagickTrue; } image_info=AcquireImageInfo(); text=(char *) NULL; status=CompareImageCommand(image_info,argc,argv,&text,exception); if ((status == MagickFalse) || (exception->severity != UndefinedException)) { if ((exception->severity < ErrorException) && (regard_warnings == MagickFalse)) status=MagickTrue; CatchException(exception); } if (text != (char *) NULL) { (void) fputs(text,stdout); (void) fputc('\n',stdout); text=DestroyString(text); } image_info=DestroyImageInfo(image_info); exception=DestroyExceptionInfo(exception); MagickCoreTerminus(); return(status == MagickFalse ? 1 : 0); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e n e r a t e S e c r e t K e y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GenerateSecretKey() returns WizardTrue if a key is generated and successfully % added to the secret key ring. % % The format of the GenerateSecretKey method is: % % WizardBooleanType GenerateSecretKey(SecretInfo *secret_info, % ExceptionInfo *exception) % % A description of each parameter follows: % % o secret_info: The secret info. % % o exception: Return any errors or warnings in this structure. % */ WizardExport WizardBooleanType GenerateSecretKey(SecretInfo *secret_info, ExceptionInfo *exception) { ExceptionInfo *sans; WizardBooleanType status; StringInfo *key, *phrase; (void) LogWizardEvent(TraceEvent,GetWizardModule(),"..."); WizardAssert(AuthenticateDomain,secret_info != (SecretInfo *) NULL); WizardAssert(AuthenticateDomain,secret_info->signature == WizardSignature); WizardAssert(AuthenticateDomain,exception != (ExceptionInfo *) NULL); if (secret_info->passphrase == (char *) NULL) phrase=GetPassphrase(exception); else phrase=FileToStringInfo(secret_info->passphrase,~0,exception); if (phrase == (StringInfo *) NULL) return(WizardFalse); sans=AcquireExceptionInfo(); do { if (secret_info->key != (StringInfo *) NULL) secret_info->key=DestroyStringInfo(secret_info->key); secret_info->key=GetRandomKey(secret_info->random_info, secret_info->key_length/8); ConstructHMAC(secret_info->hmac_info,phrase,secret_info->key); if (secret_info->id != (StringInfo *) NULL) secret_info->id=DestroyStringInfo(secret_info->id); secret_info->id=CloneStringInfo(GetHMACDigest(secret_info->hmac_info)); SetKeyringId(secret_info->keyring_info,secret_info->id); status=ExportKeyringKey(secret_info->keyring_info,sans); } while (status != WizardFalse); sans=DestroyExceptionInfo(sans); SetKeyringKey(secret_info->keyring_info,secret_info->key); SetKeyringNonce(secret_info->keyring_info,secret_info->nonce); SetCipherKey(secret_info->cipher_info,phrase); SetCipherNonce(secret_info->cipher_info,GetKeyringNonce( secret_info->keyring_info)); key=CloneStringInfo(GetKeyringKey(secret_info->keyring_info)); (void) EncipherCipher(secret_info->cipher_info,key); SetKeyringKey(secret_info->keyring_info,key); status=ImportKeyringKey(secret_info->keyring_info,exception); phrase=DestroyStringInfo(phrase); key=DestroyStringInfo(key); return(WizardTrue); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % I s R i g h t s A u t h o r i z e d % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % IsRightsAuthorized() returns MagickTrue if the policy authorizes the % requested rights for the specified domain. % % The format of the IsRightsAuthorized method is: % % MagickBooleanType IsRightsAuthorized(const PolicyDomain domain, % const PolicyRights rights,const char *pattern) % % A description of each parameter follows: % % o domain: the policy domain. % % o rights: the policy rights. % % o pattern: the coder, delegate, filter, or path pattern. % */ MagickExport MagickBooleanType IsRightsAuthorized(const PolicyDomain domain, const PolicyRights rights,const char *pattern) { const PolicyInfo *policy_info; ExceptionInfo *exception; MagickBooleanType authorized; register PolicyInfo *p; (void) LogMagickEvent(PolicyEvent,GetMagickModule(), "Domain: %s; rights=%s; pattern=\"%s\" ...", CommandOptionToMnemonic(MagickPolicyDomainOptions,domain), CommandOptionToMnemonic(MagickPolicyRightsOptions,rights),pattern); exception=AcquireExceptionInfo(); policy_info=GetPolicyInfo("*",exception); exception=DestroyExceptionInfo(exception); if (policy_info == (PolicyInfo *) NULL) return(MagickTrue); authorized=MagickTrue; LockSemaphoreInfo(policy_semaphore); ResetLinkedListIterator(policy_list); p=(PolicyInfo *) GetNextValueInLinkedList(policy_list); while ((p != (PolicyInfo *) NULL) && (authorized != MagickFalse)) { if ((p->domain == domain) && (GlobExpression(pattern,p->pattern,MagickFalse) != MagickFalse)) { if (((rights & ReadPolicyRights) != 0) && ((p->rights & ReadPolicyRights) == 0)) authorized=MagickFalse; if (((rights & WritePolicyRights) != 0) && ((p->rights & WritePolicyRights) == 0)) authorized=MagickFalse; if (((rights & ExecutePolicyRights) != 0) && ((p->rights & ExecutePolicyRights) == 0)) authorized=MagickFalse; } p=(PolicyInfo *) GetNextValueInLinkedList(policy_list); } UnlockSemaphoreInfo(policy_semaphore); return(authorized); }
/** * Convert a color name to a PixelPacket * * No Ruby usage (internal function) * * @param color the PixelPacket to modify * @param name_arg the coor name * @throw ArgumentError */ static void Color_Name_to_PixelPacket(PixelPacket *color, VALUE name_arg) { MagickBooleanType okay; char *name; ExceptionInfo *exception; exception = AcquireExceptionInfo(); name = StringValuePtr(name_arg); okay = QueryColorDatabase(name, color, exception); (void) DestroyExceptionInfo(exception); if (!okay) { rb_raise(rb_eArgError, "invalid color name %s", name); } }
/** * Equivalent to convert's -layers composite option. * * Ruby usage: * - @verbatim ImageList#composite_layers(images) @endverbatim * - @verbatim ImageList#composite_layers(images,operator) @endverbatim * * Notes: * - Default operator is OverCompositeOp * * @param argc number of input arguments * @param argv array of input arguments * @param self this object * @return a new imagelist * @see mogrify.c in ImageMagick */ VALUE ImageList_composite_layers(int argc, VALUE *argv, VALUE self) { 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); exception = AcquireExceptionInfo(); CompositeLayers(new_images, operator, source, geometry.x, geometry.y, exception); rm_split(source); rm_check_exception(exception, new_images, DestroyOnError); (void) DestroyExceptionInfo(exception); RB_GC_GUARD(source_images); return rm_imagelist_from_images(new_images); }
/** * Compare each image with the next in a sequence and returns the maximum * bounding region of any pixel differences it discovers. * * Ruby usage: * - @verbatim ImageList#deconstruct @endverbatim * * @param self this object * @return a new imagelist */ VALUE ImageList_deconstruct(VALUE self) { Image *new_images, *images; ExceptionInfo *exception; images = images_from_imagelist(self); exception = AcquireExceptionInfo(); new_images = DeconstructImages(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); }
/** * Call MontageImages. * * Ruby usage: * - @verbatim ImageList#montage <{parm block}> @endverbatim * * Notes: * - Creates Montage object, yields to block if present in Montage object's * scope. * * @param self this object * @return a new image list */ VALUE ImageList_montage(VALUE self) { VALUE montage_obj; Montage *montage; Image *new_images, *images; ExceptionInfo *exception; // Create a new instance of the Magick::Montage class montage_obj = rm_montage_new(); if (rb_block_given_p()) { // Run the block in the instance's context, allowing the app to modify the // object's attributes. (void) rb_obj_instance_eval(0, NULL, montage_obj); } Data_Get_Struct(montage_obj, Montage, montage); images = images_from_imagelist(self); // If app specified a non-default composition operator, use it for all images. if (montage->compose != UndefinedCompositeOp) { Image *i; for (i = images; i; i = GetNextImageInList(i)) { i->compose = montage->compose; } } exception = AcquireExceptionInfo(); // MontageImage can return more than one image. new_images = MontageImages(images, montage->info, exception); rm_split(images); rm_check_exception(exception, new_images, DestroyOnError); (void) DestroyExceptionInfo(exception); rm_ensure_result(new_images); RB_GC_GUARD(montage_obj); return rm_imagelist_from_images(new_images); }
/** * Call CoalesceImages. * * Ruby usage: * - @verbatim ImageList#coalesce @endverbatim * * Notes: * - Respects the delay, matte, and start_loop fields in each image. * * @param self this object * @return a new Image with the coalesced image sequence return stored in the * images array */ VALUE ImageList_coalesce(VALUE self) { Image *images, *new_images; ExceptionInfo *exception; // Convert the image array to an image sequence. images = images_from_imagelist(self); exception = AcquireExceptionInfo(); new_images = CoalesceImages(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); }
/** * Undo the image_to_str, above. * * No Ruby usage (internal function) * * Notes: * - Returns NULL if the argument is Qnil * * @param str the Ruby string to convert * @return Image represented by str * @see image_to_str */ static Image *str_to_image(VALUE str) { Image *image = NULL; Info *info; ExceptionInfo *exception; if (str != Qnil) { info = CloneImageInfo(NULL); exception = AcquireExceptionInfo(); image = BlobToImage(info, RSTRING_PTR(str), RSTRING_LEN(str), exception); DestroyImageInfo(info); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); } return image; }
int ImageWrite( struct ImageLibrary *im, Image *img, File *rootDev, const char *path ) { FHandler *fh = rootDev->f_FSys; File *rfp = (File *)fh->FileOpen( rootDev, path, "wb" ); if( rfp != NULL ) { char *buffer = NULL; size_t length = 0; ExceptionInfo *ei=AcquireExceptionInfo(); ImageInfo *ii=CloneImageInfo((ImageInfo *) NULL); buffer = ImageToBlob( ii, img, &length, ei ); if( buffer == NULL ) { ERROR("Cannot image to data\n"); DestroyExceptionInfo( ei ); DestroyImageInfo( ii ); fh->FileClose( rootDev, rfp ); return 2; } else { fh->FileWrite( rfp, buffer, length ); } DestroyExceptionInfo( ei ); DestroyImageInfo( ii ); fh->FileClose( rootDev, rfp ); } else { ERROR("Cannot open file: %s to write\n", path ); return 1; } return 0; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % C l o n e I m a g e V i e w % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % CloneImageView() makes a copy of the specified image view. % % The format of the CloneImageView method is: % % ImageView *CloneImageView(const ImageView *image_view) % % A description of each parameter follows: % % o image_view: the image view. % */ MagickExport ImageView *CloneImageView(const ImageView *image_view) { ImageView *clone_view; assert(image_view != (ImageView *) NULL); assert(image_view->signature == MagickSignature); clone_view=(ImageView *) AcquireMagickMemory(sizeof(*clone_view)); if (clone_view == (ImageView *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); (void) ResetMagickMemory(clone_view,0,sizeof(*clone_view)); clone_view->description=ConstantString(image_view->description); clone_view->extent=image_view->extent; clone_view->view=CloneCacheView(image_view->view); clone_view->exception=AcquireExceptionInfo(); InheritException(clone_view->exception,image_view->exception); clone_view->debug=image_view->debug; clone_view->signature=MagickSignature; return(clone_view); }
/* We use BlobToImage to load input as an image, if successful destroy image. */ extern "C" int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size) { Image *image; ImageInfo image_info; ExceptionInfo *exception; GetImageInfo(&image_info); exception = AcquireExceptionInfo(); image = BlobToImage(&image_info, data, size, exception); if (exception->severity != UndefinedException){ //CatchException(exception); } if(image != (Image *) NULL){ DestroyImage(image); } DestroyExceptionInfo(exception); return 0; }
/** * Clone a list of images, handle errors. * * No Ruby usage (internal function) * * @param images the images * @return a new array of images */ static Image * clone_imagelist(Image *images) { Image *new_imagelist = NULL, *image, *clone; ExceptionInfo *exception; exception = AcquireExceptionInfo(); image = GetFirstImageInList(images); while (image) { clone = CloneImage(image, 0, 0, MagickTrue, exception); rm_check_exception(exception, new_imagelist, DestroyOnError); AppendImageToList(&new_imagelist, clone); image = GetNextImageInList(image); } (void) DestroyExceptionInfo(exception); return new_imagelist; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % M a i n % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % */ int main(int argc,char **argv) { ExceptionInfo *exception; ImageInfo *image_info; MagickBooleanType status; MagickCoreGenesis(*argv,MagickTrue); exception=AcquireExceptionInfo(); image_info=AcquireImageInfo(); status=MagickCommandGenesis(image_info,MogrifyImageCommand,argc,argv, (char **) NULL,exception); image_info=DestroyImageInfo(image_info); exception=DestroyExceptionInfo(exception); MagickCoreTerminus(); return(status); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t L o c a l e M e s s a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetLocaleMessage() returns a message in the current locale that matches the % supplied tag. % % The format of the GetLocaleMessage method is: % % const char *GetLocaleMessage(const char *tag) % % A description of each parameter follows: % % o tag: Return a message that matches this tag in the current locale. % */ MagickExport const char *GetLocaleMessage(const char *tag) { char name[MaxTextExtent]; const LocaleInfo *locale_info; ExceptionInfo *exception; if ((tag == (const char *) NULL) || (*tag == '\0')) return(tag); exception=AcquireExceptionInfo(); (void) FormatMagickString(name,MaxTextExtent,"%s/",tag); locale_info=GetLocaleInfo_(name,exception); exception=DestroyExceptionInfo(exception); if (locale_info != (const LocaleInfo *) NULL) return(locale_info->message); return(tag); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % 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) { char *message; message=GetExceptionMessage(errno); ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed", message); message=DestroyString(message); } (void) ResetMagickMemory(wand,0,sizeof(*wand)); wand->id=AcquireWandId(); (void) FormatMagickString(wand->name,MaxTextExtent,"%s-%lu",MagickWandId, wand->id); wand->exception=AcquireExceptionInfo(); wand->image_info=AcquireImageInfo(); 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=WandSignature; return(wand); }
int main (int argc, char **argv) { if (argc != 5) { printf ("Usage: %s image_file scheme_file key_file layout_type\n", argv[0]); return (0); } char *ifile_name = argv[1]; char *ofile_name = argv[2]; char *key_name = argv[3]; SM_LayoutType layout_type = (SM_LayoutType)atoi(argv[4]); MagickWandGenesis(); ExceptionInfo *exception = AcquireExceptionInfo(); MagickWand *image = NewMagickWand(); // Read an image. printf("Proceeding file %s\n", ifile_name); MagickReadImage(image, ifile_name); SM_SchemeGenerator *generator = SM_CrossStitchSchemeGenerator_New(); SM_Scheme *scheme_base = SM_SchemeGenerator_GenerateScheme(generator, image); MagickWand *scheme = SM_CrossStitch_Color_Draw(scheme_base, layout_type); scheme_base->cell_info.square->width *= 2; MagickWand *key = SM_CrossStitch_Key_Draw(scheme_base, layout_type); MagickWriteImage(scheme, ofile_name); MagickWriteImage(key, key_name); SM_SchemeGenerator_Delete(generator); SM_Scheme_Delete(scheme_base); DestroyMagickWand(image); DestroyMagickWand(scheme); exception = DestroyExceptionInfo(exception); MagickWandTerminus(); printf("Done!\n"); return (0); }
Image *ImageRead( struct ImageLibrary *im, File *rootDev, const char *path ) { Image *img = NULL; FHandler *fh = rootDev->f_FSys; File *rfp = (File *)fh->FileOpen( rootDev, path, "rb" ); if( rfp != NULL ) { BufString *bs = BufStringNew( ); char buffer[ 20048 ]; int len = 0; while( ( len = fh->FileRead( rfp, buffer, 20048 ) ) > 0 ) { BufStringAddSize( bs, buffer, len ); } ExceptionInfo *ei=AcquireExceptionInfo(); ImageInfo *ii=CloneImageInfo((ImageInfo *) NULL); img = BlobToImage( ii, bs->bs_Buffer, bs->bs_Size, ei ); if( img == NULL ) { ERROR("Cannot convert file data to image\n"); } DestroyExceptionInfo( ei ); DestroyImageInfo( ii ); BufStringDelete( bs ); fh->FileClose( rootDev, rfp ); } else { ERROR("Cannot open file: %s to read\n", path ); } }
int FResizeImage( struct ImageLibrary *im, Image **image, int w, int h ) { if( image != NULL ) { ExceptionInfo *ei=AcquireExceptionInfo(); ///filters are in resamples.h Image* newImage = ResizeImage( *image, w, h, LanczosFilter, 1.0, ei ); if( newImage != NULL ) { DeleteImage( *image ); *image = newImage; } DestroyExceptionInfo( ei ); } else { ERROR("Cannot resize empty image\n"); } return 0; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t C o n f i g u r e O p t i o n % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetConfigureOption() returns the value associated with the configure option. % % The format of the GetConfigureOption method is: % % char *GetConfigureOption(const char *option) % % A description of each parameter follows: % % o configure_info: The configure info. % */ MagickExport char *GetConfigureOption(const char *option) { const char *value; const ConfigureInfo *configure_info; ExceptionInfo *exception; assert(option != (const char *) NULL); (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",option); exception=AcquireExceptionInfo(); configure_info=GetConfigureInfo(option,exception); exception=DestroyExceptionInfo(exception); if (configure_info == (ConfigureInfo *) NULL) return((char *) NULL); value=GetConfigureValue(configure_info); if ((value == (const char *) NULL) || (*value == '\0')) return((char *) NULL); return(ConstantString(value)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % N e w I m a g e V i e w % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % NewImageView() returns a image view required for all other methods in the % Image View API. % % The format of the NewImageView method is: % % ImageView *NewImageView(MagickCore *wand,ExceptionInfo *exception) % % A description of each parameter follows: % % o image: the image. % % o exception: return any errors or warnings in this structure. % */ MagickExport ImageView *NewImageView(Image *image,ExceptionInfo *exception) { ImageView *image_view; assert(image != (Image *) NULL); assert(image->signature == MagickSignature); image_view=(ImageView *) AcquireMagickMemory(sizeof(*image_view)); if (image_view == (ImageView *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); (void) ResetMagickMemory(image_view,0,sizeof(*image_view)); image_view->description=ConstantString("ImageView"); image_view->image=image; image_view->view=AcquireVirtualCacheView(image_view->image,exception); image_view->extent.width=image->columns; image_view->extent.height=image->rows; image_view->extent.x=0; image_view->extent.y=0; image_view->exception=AcquireExceptionInfo(); image_view->debug=IsEventLogging(); image_view->signature=MagickSignature; return(image_view); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + M a g i c k T o M i m e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % MagickToMime() returns the officially registered (or de facto) MIME % media-type corresponding to a magick string. If there is no registered % media-type, then the string "image/x-magick" (all lower case) is returned. % The returned string must be deallocated by the user. % % The format of the MagickToMime method is: % % char *MagickToMime(const char *magick) % % A description of each parameter follows. % % o magick: ImageMagick format specification "magick" tag. % */ MagickExport char *MagickToMime(const char *magick) { char filename[MagickPathExtent], media[MagickPathExtent]; const MimeInfo *mime_info; ExceptionInfo *exception; (void) FormatLocaleString(filename,MagickPathExtent,"file.%s",magick); LocaleLower(filename); exception=AcquireExceptionInfo(); mime_info=GetMimeInfo(filename,(unsigned char *) " ",1,exception); exception=DestroyExceptionInfo(exception); if (mime_info != (const MimeInfo *) NULL) return(ConstantString(GetMimeType(mime_info))); (void) FormatLocaleString(media,MagickPathExtent,"image/x-%s",magick); LocaleLower(media+8); return(ConstantString(media)); }
/** * Merge all the images into a single image. * * Ruby usage: * - @verbatim ImageList#mosaic @endverbatim * * @param self this object * @return the new image */ VALUE ImageList_mosaic(VALUE self) { Image *images, *new_image; ExceptionInfo *exception; exception = AcquireExceptionInfo(); images = images_from_imagelist(self); #if defined(HAVE_ENUM_MOSAICLAYER) new_image = MergeImageLayers(images, MosaicLayer, exception); #else new_image = MosaicImages(images, exception); #endif rm_split(images); rm_check_exception(exception, new_image, DestroyOnError); (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t P o l i c y V a l u e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetPolicyValue() returns the value associated with the named policy. % % The format of the GetPolicyValue method is: % % char *GetPolicyValue(const char *name) % % A description of each parameter follows: % % o policy_info: The policy info. % */ MagickExport char *GetPolicyValue(const char *name) { const char *value; const PolicyInfo *policy_info; ExceptionInfo *exception; assert(name != (const char *) NULL); (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name); exception=AcquireExceptionInfo(); policy_info=GetPolicyInfo(name,exception); exception=DestroyExceptionInfo(exception); if (policy_info == (PolicyInfo *) NULL) return((char *) NULL); value=policy_info->value; if ((value == (const char *) NULL) || (*value == '\0')) return((char *) NULL); return(ConstantString(value)); }
void* magickminify(void* src, ssize_t src_len, ssize_t* dst_len){ Image *image, *resize; ImageInfo image_info; ExceptionInfo *exception; size_t len; void *ans; GetImageInfo(&image_info); exception = AcquireExceptionInfo(); image = BlobToImage(&image_info, src, src_len, exception); if (exception->severity != UndefinedException) CatchException(exception); if (image == (Image *) NULL) { printf("image not obtained by BlobToImage.\n"); exit(1); } resize = MinifyImage(image, exception); if (exception->severity != UndefinedException) CatchException(exception); if (resize == (Image *) NULL) exit(1); ans = ImageToBlob(&image_info, resize, &len, exception); if(dst_len != NULL) *dst_len = len; DestroyImage(image); DestroyImage(resize); DestroyExceptionInfo(exception); return ans; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % M a g i c k Q u e r y C o n f i g u r e O p t i o n % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % MagickQueryConfigureOption() returns the value associated with the specified % configure option. % % The format of the MagickQueryConfigureOption function is: % % char *MagickQueryConfigureOption(const char *option) % % A description of each parameter follows: % % o option: the option name. % */ WandExport char *MagickQueryConfigureOption(const char *option) { char *value; const ConfigureInfo **configure_info; ExceptionInfo *exception; size_t number_options; exception=AcquireExceptionInfo(); configure_info=GetConfigureInfoList(option,&number_options,exception); exception=DestroyExceptionInfo(exception); if (configure_info == (const ConfigureInfo **) NULL) return((char *) NULL); value=AcquireString(configure_info[0]->value); configure_info=(const ConfigureInfo **) RelinquishMagickMemory((void *) configure_info); return(value); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % N e w W a n d V i e w E x t e n t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % NewWandViewExtent() returns a wand view required for all other methods % in the Wand View API. % % The format of the NewWandViewExtent method is: % % WandView *NewWandViewExtent(MagickWand *wand,const ssize_t x, % const ssize_t y,const size_t width,const size_t height) % % A description of each parameter follows: % % o wand: the magick wand. % % o x,y,columns,rows: These values define the perimeter of a extent of % pixel_wands view. % */ WandExport WandView *NewWandViewExtent(MagickWand *wand,const ssize_t x, const ssize_t y,const size_t width,const size_t height) { ExceptionInfo *exception; WandView *wand_view; assert(wand != (MagickWand *) NULL); assert(wand->signature == WandSignature); wand_view=(WandView *) AcquireMagickMemory(sizeof(*wand_view)); if (wand_view == (WandView *) NULL) ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed", GetExceptionMessage(errno)); (void) ResetMagickMemory(wand_view,0,sizeof(*wand_view)); wand_view->id=AcquireWandId(); (void) FormatLocaleString(wand_view->name,MaxTextExtent,"%s-%.20g", WandViewId,(double) wand_view->id); wand_view->description=ConstantString("WandView"); exception=AcquireExceptionInfo(); wand_view->view=AcquireVirtualCacheView(wand_view->wand->images,exception); wand_view->wand=wand; wand_view->extent.width=width; wand_view->extent.height=height; wand_view->extent.x=x; wand_view->extent.y=y; wand_view->exception=exception; wand_view->pixel_wands=AcquirePixelsThreadSet(wand_view->extent.width); if (wand_view->pixel_wands == (PixelWand ***) NULL) ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed", GetExceptionMessage(errno)); wand_view->debug=IsEventLogging(); wand_view->signature=WandSignature; return(wand_view); }