/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % 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 name: The name of the policy. % */ 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)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % 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); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e g i s t e r P A N G O I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RegisterPANGOImage() adds attributes for the Pango Markup Language format to % the list of supported formats. The attributes include the image format % tag, a method to read and/or write the format, whether the format % supports the saving of more than one frame to the same file or blob, % whether the format supports native in-memory I/O, and a brief % description of the format. % % The format of the RegisterPANGOImage method is: % % size_t RegisterPANGOImage(void) % */ ModuleExport size_t RegisterPANGOImage(void) { char version[MagickPathExtent]; MagickInfo *entry; *version='\0'; #if defined(PANGO_VERSION_STRING) (void) FormatLocaleString(version,MagickPathExtent,"Pangocairo %s", PANGO_VERSION_STRING); #endif entry=AcquireMagickInfo("PANGO","PANGO","Pango Markup Language"); #if defined(MAGICKCORE_PANGOCAIRO_DELEGATE) entry->decoder=(DecodeImageHandler *) ReadPANGOImage; #endif if (*version != '\0') entry->version=ConstantString(version); entry->flags^=CoderAdjoinFlag; (void) RegisterMagickInfo(entry); return(MagickImageCoderSignature); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % 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); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % C l o n e W a n d V i e w % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % CloneWandView() makes a copy of the specified wand view. % % The format of the CloneWandView method is: % % WandView *CloneWandView(const WandView *wand_view) % % A description of each parameter follows: % % o wand_view: the wand view. % */ WandExport WandView *CloneWandView(const WandView *wand_view) { WandView *clone_view; register ssize_t i; assert(wand_view != (WandView *) NULL); assert(wand_view->signature == WandSignature); if (wand_view->debug != MagickFalse) (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand_view->name); clone_view=(WandView *) AcquireMagickMemory(sizeof(*clone_view)); if (clone_view == (WandView *) NULL) ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed", wand_view->name); (void) ResetMagickMemory(clone_view,0,sizeof(*clone_view)); clone_view->id=AcquireWandId(); (void) FormatLocaleString(clone_view->name,MaxTextExtent,"%s-%.20g", WandViewId,(double) clone_view->id); clone_view->description=ConstantString(wand_view->description); clone_view->image=CloneImage(wand_view->image,0,0,MagickTrue, wand_view->exception); clone_view->view=CloneCacheView(wand_view->view); clone_view->extent=wand_view->extent; clone_view->exception=AcquireExceptionInfo(); InheritException(clone_view->exception,wand_view->exception); for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++) clone_view->pixel_wands[i]=ClonePixelWands((const PixelWand **) wand_view->pixel_wands[i],wand_view->extent.width); clone_view->debug=wand_view->debug; if (clone_view->debug != MagickFalse) (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",clone_view->name); clone_view->signature=WandSignature; return(clone_view); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e g i s t e r C A L S I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RegisterCALSImage() adds attributes for the CALS Raster Group 1 image file % image format to the list of supported formats. The attributes include the % image format tag, a method to read and/or write the format, whether the % format supports the saving of more than one frame to the same file or blob, % whether the format supports native in-memory I/O, and a brief description % of the format. % % The format of the RegisterCALSImage method is: % % size_t RegisterCALSImage(void) % */ ModuleExport size_t RegisterCALSImage(void) { MagickInfo *entry; static const char *CALSDescription= { "Continuous Acquisition and Life-cycle Support Type 1" }, *CALSNote= { "Specified in MIL-R-28002 and MIL-PRF-28002" }; entry=SetMagickInfo("CAL"); entry->decoder=(DecodeImageHandler *) ReadCALSImage; #if defined(MAGICKCORE_TIFF_DELEGATE) entry->encoder=(EncodeImageHandler *) WriteCALSImage; #endif entry->adjoin=MagickFalse; entry->magick=(IsImageFormatHandler *) IsCALS; entry->description=ConstantString(CALSDescription); entry->note=ConstantString(CALSNote); entry->module=ConstantString("CALS"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("CALS"); entry->decoder=(DecodeImageHandler *) ReadCALSImage; #if defined(MAGICKCORE_TIFF_DELEGATE) entry->encoder=(EncodeImageHandler *) WriteCALSImage; #endif entry->adjoin=MagickFalse; entry->magick=(IsImageFormatHandler *) IsCALS; entry->description=ConstantString(CALSDescription); entry->note=ConstantString(CALSNote); entry->module=ConstantString("CALS"); (void) RegisterMagickInfo(entry); return(MagickImageCoderSignature); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e g i s t e r E P T I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RegisterEPTImage() adds attributes for the EPT image format to % the list of supported formats. The attributes include the image format % tag, a method to read and/or write the format, whether the format % supports the saving of more than one frame to the same file or blob, % whether the format supports native in-memory I/O, and a brief % description of the format. % % The format of the RegisterEPTImage method is: % % size_t RegisterEPTImage(void) % */ ModuleExport size_t RegisterEPTImage(void) { MagickInfo *entry; entry=SetMagickInfo("EPT"); entry->decoder=(DecodeImageHandler *) ReadEPTImage; entry->encoder=(EncodeImageHandler *) WriteEPTImage; entry->magick=(IsImageFormatHandler *) IsEPT; entry->seekable_stream=MagickTrue; entry->adjoin=MagickFalse; entry->blob_support=MagickFalse; entry->description=ConstantString( "Encapsulated PostScript with TIFF preview"); entry->module=ConstantString("EPT"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("EPT2"); entry->decoder=(DecodeImageHandler *) ReadEPTImage; entry->encoder=(EncodeImageHandler *) WriteEPTImage; entry->magick=(IsImageFormatHandler *) IsEPT; entry->adjoin=MagickFalse; entry->seekable_stream=MagickTrue; entry->blob_support=MagickFalse; entry->description=ConstantString( "Encapsulated PostScript Level II with TIFF preview"); entry->module=ConstantString("EPT"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("EPT3"); entry->decoder=(DecodeImageHandler *) ReadEPTImage; entry->encoder=(EncodeImageHandler *) WriteEPTImage; entry->magick=(IsImageFormatHandler *) IsEPT; entry->seekable_stream=MagickTrue; entry->blob_support=MagickFalse; entry->description=ConstantString( "Encapsulated PostScript Level III with TIFF preview"); entry->module=ConstantString("EPT"); (void) RegisterMagickInfo(entry); return(MagickImageCoderSignature); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e g i s t e r P S 2 I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RegisterPS2Image() adds properties for the PS2 image format to % the list of supported formats. The properties include the image format % tag, a method to read and/or write the format, whether the format % supports the saving of more than one frame to the same file or blob, % whether the format supports native in-memory I/O, and a brief % description of the format. % % The format of the RegisterPS2Image method is: % % size_t RegisterPS2Image(void) % */ ModuleExport size_t RegisterPS2Image(void) { MagickInfo *entry; entry=SetMagickInfo("EPS2"); entry->encoder=(EncodeImageHandler *) WritePS2Image; entry->adjoin=MagickFalse; entry->seekable_stream=MagickTrue; entry->description=ConstantString("Level II Encapsulated PostScript"); entry->mime_type=ConstantString("application/postscript"); entry->module=ConstantString("PS2"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("PS2"); entry->encoder=(EncodeImageHandler *) WritePS2Image; entry->seekable_stream=MagickTrue; entry->description=ConstantString("Level II PostScript"); entry->mime_type=ConstantString("application/postscript"); entry->module=ConstantString("PS2"); (void) RegisterMagickInfo(entry); return(MagickImageCoderSignature); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t C o n f i g u r e P a t h s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetConfigurePaths() returns any Magick configuration paths associated % with the specified filename. % % The format of the GetConfigurePaths method is: % % LinkedListInfo *GetConfigurePaths(const char *filename, % ExceptionInfo *exception) % % A description of each parameter follows: % % o filename: the configure file name. % % o exception: return any errors or warnings in this structure. % */ MagickExport LinkedListInfo *GetConfigurePaths(const char *filename, ExceptionInfo *exception) { #define RegistryKey "ConfigurePath" #define MagickCoreDLL "CORE_RL_magick_.dll" #define MagickCoreDebugDLL "CORE_DB_magick_.dll" char path[MaxTextExtent]; LinkedListInfo *paths; assert(filename != (const char *) NULL); (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename); assert(exception != (ExceptionInfo *) NULL); (void) CopyMagickString(path,filename,MaxTextExtent); paths=NewLinkedList(0); { char *configure_path; /* Search $MAGICK_CONFIGURE_PATH. */ configure_path=GetEnvironmentValue("MAGICK_CONFIGURE_PATH"); if (configure_path != (char *) NULL) { register char *p, *q; for (p=configure_path-1; p != (char *) NULL; ) { (void) CopyMagickString(path,p+1,MaxTextExtent); q=strchr(path,DirectoryListSeparator); if (q != (char *) NULL) *q='\0'; q=path+strlen(path)-1; if ((q >= path) && (*q != *DirectorySeparator)) (void) ConcatenateMagickString(path,DirectorySeparator, MaxTextExtent); (void) AppendValueToLinkedList(paths,ConstantString(path)); p=strchr(p+1,DirectoryListSeparator); } configure_path=DestroyString(configure_path); } } #if defined(MAGICKCORE_INSTALLED_SUPPORT) #if defined(MAGICKCORE_SHARE_PATH) (void) AppendValueToLinkedList(paths,ConstantString(MAGICKCORE_SHARE_PATH)); #endif #if defined(MAGICKCORE_SHAREARCH_PATH) (void) AppendValueToLinkedList(paths,ConstantString( MAGICKCORE_SHAREARCH_PATH)); #endif #if defined(MAGICKCORE_CONFIGURE_PATH) (void) AppendValueToLinkedList(paths,ConstantString( MAGICKCORE_CONFIGURE_PATH)); #endif #if defined(MAGICKCORE_DOCUMENTATION_PATH) (void) AppendValueToLinkedList(paths,ConstantString( MAGICKCORE_DOCUMENTATION_PATH)); #endif #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !(defined(MAGICKCORE_CONFIGURE_PATH) || defined(MAGICKCORE_SHARE_PATH)) { unsigned char *key_value; /* Locate file via registry key. */ key_value=NTRegistryKeyLookup(RegistryKey); if (key_value != (unsigned char *) NULL) { (void) FormatLocaleString(path,MaxTextExtent,"%s%s",(char *) key_value, DirectorySeparator); (void) AppendValueToLinkedList(paths,ConstantString(path)); key_value=(unsigned char *) RelinquishMagickMemory(key_value); } } #endif #else { char *home; /* Search under MAGICK_HOME. */ home=GetEnvironmentValue("MAGICK_HOME"); if (home != (char *) NULL) { #if !defined(MAGICKCORE_POSIX_SUPPORT) (void) FormatLocaleString(path,MaxTextExtent,"%s%s",home, DirectorySeparator); (void) AppendValueToLinkedList(paths,ConstantString(path)); #else (void) FormatLocaleString(path,MaxTextExtent,"%s/etc/%s/",home, MAGICKCORE_CONFIGURE_RELATIVE_PATH); (void) AppendValueToLinkedList(paths,ConstantString(path)); (void) FormatLocaleString(path,MaxTextExtent,"%s/share/%s/",home, MAGICKCORE_SHARE_RELATIVE_PATH); (void) AppendValueToLinkedList(paths,ConstantString(path)); #endif home=DestroyString(home); } } if (*GetClientPath() != '\0') { #if !defined(MAGICKCORE_POSIX_SUPPORT) (void) FormatLocaleString(path,MaxTextExtent,"%s%s",GetClientPath(), DirectorySeparator); (void) AppendValueToLinkedList(paths,ConstantString(path)); #else char prefix[MaxTextExtent]; /* Search based on executable directory if directory is known. */ (void) CopyMagickString(prefix,GetClientPath(),MaxTextExtent); ChopPathComponents(prefix,1); (void) FormatLocaleString(path,MaxTextExtent,"%s/etc/%s/",prefix, MAGICKCORE_CONFIGURE_RELATIVE_PATH); (void) AppendValueToLinkedList(paths,ConstantString(path)); (void) FormatLocaleString(path,MaxTextExtent,"%s/share/%s/",prefix, MAGICKCORE_SHARE_RELATIVE_PATH); (void) AppendValueToLinkedList(paths,ConstantString(path)); #endif } /* Search current directory. */ (void) AppendValueToLinkedList(paths,ConstantString("")); #endif { char *home; home=GetEnvironmentValue("HOME"); if (home == (char *) NULL) home=GetEnvironmentValue("USERPROFILE"); if (home != (char *) NULL) { /* Search $HOME/.magick. */ (void) FormatLocaleString(path,MaxTextExtent,"%s%s.magick%s",home, DirectorySeparator,DirectorySeparator); (void) AppendValueToLinkedList(paths,ConstantString(path)); home=DestroyString(home); } } #if defined(MAGICKCORE_WINDOWS_SUPPORT) { char module_path[MaxTextExtent]; if ((NTGetModulePath(MagickCoreDLL,module_path) != MagickFalse) || (NTGetModulePath(MagickCoreDebugDLL,module_path) != MagickFalse)) { unsigned char *key_value; /* Search module path. */ (void) FormatLocaleString(path,MaxTextExtent,"%s%s",module_path, DirectorySeparator); key_value=NTRegistryKeyLookup(RegistryKey); if (key_value == (unsigned char *) NULL) (void) AppendValueToLinkedList(paths,ConstantString(path)); else key_value=(unsigned char *) RelinquishMagickMemory(key_value); } if (NTGetModulePath("Magick.dll",module_path) != MagickFalse) { /* Search PerlMagick module path. */ (void) FormatLocaleString(path,MaxTextExtent,"%s%s",module_path, DirectorySeparator); (void) AppendValueToLinkedList(paths,ConstantString(path)); (void) FormatLocaleString(path,MaxTextExtent,"%s%s",module_path, "\\inc\\lib\\auto\\Image\\Magick\\"); (void) AppendValueToLinkedList(paths,ConstantString(path)); } } #endif return(paths); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + L o a d C o n f i g u r e L i s t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % LoadConfigureList() loads the configure configuration file which provides a % mapping between configure attributes and a configure name. % % The format of the LoadConfigureList method is: % % MagickBooleanType LoadConfigureList(const char *xml,const char *filename, % const size_t depth,ExceptionInfo *exception) % % A description of each parameter follows: % % o xml: The configure list in XML format. % % o filename: The configure list filename. % % o depth: depth of <include /> statements. % % o exception: return any errors or warnings in this structure. % */ static MagickBooleanType LoadConfigureList(const char *xml,const char *filename, const size_t depth,ExceptionInfo *exception) { char keyword[MaxTextExtent], *token; ConfigureInfo *configure_info; const char *q; MagickBooleanType status; /* Load the configure map file. */ (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), "Loading configure file \"%s\" ...",filename); if (configure_list == (LinkedListInfo *) NULL) { configure_list=NewLinkedList(0); if (configure_list == (LinkedListInfo *) NULL) { ThrowFileException(exception,ResourceLimitError, "MemoryAllocationFailed",filename); return(MagickFalse); } } status=MagickTrue; configure_info=(ConfigureInfo *) NULL; token=AcquireString((char *) xml); for (q=(char *) xml; *q != '\0'; ) { /* Interpret XML. */ GetMagickToken(q,&q,token); if (*token == '\0') break; (void) CopyMagickString(keyword,token,MaxTextExtent); if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0) { /* Doctype element. */ while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0')) GetMagickToken(q,&q,token); continue; } if (LocaleNCompare(keyword,"<!--",4) == 0) { /* Comment element. */ while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0')) GetMagickToken(q,&q,token); continue; } if (LocaleCompare(keyword,"<include") == 0) { /* Include element. */ while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0')) { (void) CopyMagickString(keyword,token,MaxTextExtent); GetMagickToken(q,&q,token); if (*token != '=') continue; GetMagickToken(q,&q,token); if (LocaleCompare(keyword,"file") == 0) { if (depth > 200) (void) ThrowMagickException(exception,GetMagickModule(), ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token); else { char path[MaxTextExtent], *xml; GetPathComponent(filename,HeadPath,path); if (*path != '\0') (void) ConcatenateMagickString(path,DirectorySeparator, MaxTextExtent); if (*token == *DirectorySeparator) (void) CopyMagickString(path,token,MaxTextExtent); else (void) ConcatenateMagickString(path,token,MaxTextExtent); xml=FileToString(path,~0,exception); if (xml != (char *) NULL) { status=LoadConfigureList(xml,path,depth+1,exception); xml=(char *) RelinquishMagickMemory(xml); } } } } continue; } if (LocaleCompare(keyword,"<configure") == 0) { /* Configure element. */ configure_info=(ConfigureInfo *) AcquireMagickMemory( sizeof(*configure_info)); if (configure_info == (ConfigureInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); (void) ResetMagickMemory(configure_info,0,sizeof(*configure_info)); configure_info->path=ConstantString(filename); configure_info->exempt=MagickFalse; configure_info->signature=MagickSignature; continue; } if (configure_info == (ConfigureInfo *) NULL) continue; if (LocaleCompare(keyword,"/>") == 0) { status=AppendValueToLinkedList(configure_list,configure_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'", configure_info->name); configure_info=(ConfigureInfo *) NULL; } /* Parse configure element. */ GetMagickToken(q,(const char **) NULL,token); if (*token != '=') continue; GetMagickToken(q,&q,token); GetMagickToken(q,&q,token); switch (*keyword) { case 'N': case 'n': { if (LocaleCompare((char *) keyword,"name") == 0) { configure_info->name=ConstantString(token); break; } break; } case 'S': case 's': { if (LocaleCompare((char *) keyword,"stealth") == 0) { configure_info->stealth=IsMagickTrue(token); break; } break; } case 'V': case 'v': { if (LocaleCompare((char *) keyword,"value") == 0) { configure_info->value=ConstantString(token); break; } break; } default: break; } } token=(char *) RelinquishMagickMemory(token); return(status); }
MagickExport MagickBooleanType SetImageRegistry(const RegistryType type, const char *key,const void *value,ExceptionInfo *exception) { MagickBooleanType status; RegistryInfo *registry_info; void *clone_value; if (IsEventLogging() != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",key); clone_value=(void *) NULL; switch (type) { case StringRegistryType: default: { const char *string; string=(const char *) value; clone_value=(void *) ConstantString(string); break; } case ImageRegistryType: { const Image *image; image=(const Image *) value; if (image->signature != MagickSignature) { (void) ThrowMagickException(exception,GetMagickModule(),RegistryError, "UnableToSetRegistry","%s",key); return(MagickFalse); } clone_value=(void *) CloneImageList(image,exception); break; } case ImageInfoRegistryType: { const ImageInfo *image_info; image_info=(const ImageInfo *) value; if (image_info->signature != MagickSignature) { (void) ThrowMagickException(exception,GetMagickModule(),RegistryError, "UnableToSetRegistry","%s",key); return(MagickFalse); } clone_value=(void *) CloneImageInfo(image_info); break; } } if (clone_value == (void *) NULL) return(MagickFalse); registry_info=(RegistryInfo *) AcquireMagickMemory(sizeof(*registry_info)); if (registry_info == (RegistryInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); (void) ResetMagickMemory(registry_info,0,sizeof(*registry_info)); registry_info->type=type; registry_info->value=clone_value; registry_info->signature=MagickSignature; if ((registry == (SplayTreeInfo *) NULL) && (instantiate_registry == MagickFalse)) { if (registry_semaphore == (SemaphoreInfo *) NULL) AcquireSemaphoreInfo(®istry_semaphore); LockSemaphoreInfo(registry_semaphore); if ((registry == (SplayTreeInfo *) NULL) && (instantiate_registry == MagickFalse)) { registry=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, DestroyRegistryNode); instantiate_registry=MagickTrue; } UnlockSemaphoreInfo(registry_semaphore); } status=AddValueToSplayTree(registry,ConstantString(key),registry_info); return(status); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t I m a g e R e g i s t r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetImageRegistry() returns a value associated with an image registry key. % % The format of the GetImageRegistry method is: % % void *GetImageRegistry(const RegistryType type,const char *key, % ExceptionInfo *exception) % % A description of each parameter follows: % % o type: the type. % % o key: the key. % % o exception: the exception. % */ MagickExport void *GetImageRegistry(const RegistryType type,const char *key, ExceptionInfo *exception) { void *value; RegistryInfo *registry_info; if (IsEventLogging() != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",key); if (registry == (void *) NULL) return((void *) NULL); registry_info=(RegistryInfo *) GetValueFromSplayTree(registry,key); if (registry_info == (void *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(),RegistryError, "UnableToGetRegistryID","`%s'",key); return((void *) NULL); } value=(void *) NULL; switch (type) { case ImageRegistryType: { if (type == registry_info->type) value=(void *) CloneImageList((Image *) registry_info->value,exception); break; } case ImageInfoRegistryType: { if (type == registry_info->type) value=(void *) CloneImageInfo((ImageInfo *) registry_info->value); break; } case StringRegistryType: { switch (registry_info->type) { case ImageRegistryType: { value=(Image *) ConstantString(((Image *) registry_info->value)->filename); break; } case ImageInfoRegistryType: { value=(Image *) ConstantString(((ImageInfo *) registry_info->value)->filename); break; } case StringRegistryType: { value=(void *) ConstantString((char *) registry_info->value); break; } default: break; } break; } default: break; } return(value); }
static SplayTreeInfo *AcquireCoderCache(const char *filename, ExceptionInfo *exception) { const StringInfo *option; LinkedListInfo *options; MagickStatusType status; register ssize_t i; SplayTreeInfo *coder_cache; /* Load external coder map. */ coder_cache=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, DestroyCoderNode); if (coder_cache == (SplayTreeInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); status=MagickTrue; options=GetConfigureOptions(filename,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); while (option != (const StringInfo *) NULL) { status&=LoadCoderCache(coder_cache,(const char *) GetStringInfoDatum(option),GetStringInfoPath(option),0,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); } options=DestroyConfigureOptions(options); /* Load built-in coder map. */ for (i=0; i < (ssize_t) (sizeof(CoderMap)/sizeof(*CoderMap)); i++) { CoderInfo *coder_info; register const CoderMapInfo *p; p=CoderMap+i; coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info)); if (coder_info == (CoderInfo *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name); continue; } (void) ResetMagickMemory(coder_info,0,sizeof(*coder_info)); coder_info->path=(char *) "[built-in]"; coder_info->magick=(char *) p->magick; coder_info->name=(char *) p->name; coder_info->exempt=MagickTrue; coder_info->signature=MagickCoreSignature; status&=AddValueToSplayTree(coder_cache,ConstantString(coder_info->magick), coder_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",coder_info->name); } return(coder_cache); }
static MagickBooleanType LoadTypeList(const char *xml,const char *filename, const size_t depth,ExceptionInfo *exception) { char font_path[MaxTextExtent], keyword[MaxTextExtent], *token; const char *q; MagickBooleanType status; TypeInfo *type_info; /* Load the type map file. */ (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), "Loading type configure file \"%s\" ...",filename); if (xml == (const char *) NULL) return(MagickFalse); if (type_list == (SplayTreeInfo *) NULL) { type_list=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL, DestroyTypeNode); if (type_list == (SplayTreeInfo *) NULL) { ThrowFileException(exception,ResourceLimitError, "MemoryAllocationFailed",filename); return(MagickFalse); } } status=MagickTrue; type_info=(TypeInfo *) NULL; token=AcquireString(xml); #if defined(MAGICKCORE_WINDOWS_SUPPORT) /* Determine the Ghostscript font path. */ *font_path='\0'; if (NTGhostscriptFonts(font_path,MaxTextExtent-2)) (void) ConcatenateMagickString(font_path,DirectorySeparator,MaxTextExtent); #endif for (q=(char *) xml; *q != '\0'; ) { /* Interpret XML. */ GetMagickToken(q,&q,token); if (*token == '\0') break; (void) CopyMagickString(keyword,token,MaxTextExtent); if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0) { /* Doctype element. */ while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0')) GetMagickToken(q,&q,token); continue; } if (LocaleNCompare(keyword,"<!--",4) == 0) { /* Comment element. */ while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0')) GetMagickToken(q,&q,token); continue; } if (LocaleCompare(keyword,"<include") == 0) { /* Include element. */ while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0')) { (void) CopyMagickString(keyword,token,MaxTextExtent); GetMagickToken(q,&q,token); if (*token != '=') continue; GetMagickToken(q,&q,token); if (LocaleCompare(keyword,"file") == 0) { if (depth > 200) (void) ThrowMagickException(exception,GetMagickModule(), ConfigureError,"IncludeNodeNestedTooDeeply","`%s'",token); else { char path[MaxTextExtent], *xml; ExceptionInfo *sans_exception; *path='\0'; GetPathComponent(filename,HeadPath,path); if (*path != '\0') (void) ConcatenateMagickString(path,DirectorySeparator, MaxTextExtent); if (*token == *DirectorySeparator) (void) CopyMagickString(path,token,MaxTextExtent); else (void) ConcatenateMagickString(path,token,MaxTextExtent); sans_exception=AcquireExceptionInfo(); xml=FileToString(path,~0UL,sans_exception); sans_exception=DestroyExceptionInfo(sans_exception); if (xml != (char *) NULL) { status=LoadTypeList(xml,path,depth+1,exception); xml=(char *) RelinquishMagickMemory(xml); } } } } continue; } if (LocaleCompare(keyword,"<type") == 0) { /* Type element. */ type_info=(TypeInfo *) AcquireMagickMemory(sizeof(*type_info)); if (type_info == (TypeInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); (void) ResetMagickMemory(type_info,0,sizeof(*type_info)); type_info->path=ConstantString(filename); type_info->signature=MagickSignature; continue; } if (type_info == (TypeInfo *) NULL) continue; if (LocaleCompare(keyword,"/>") == 0) { status=AddValueToSplayTree(type_list,type_info->name,type_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",type_info->name); type_info=(TypeInfo *) NULL; } GetMagickToken(q,(const char **) NULL,token); if (*token != '=') continue; GetMagickToken(q,&q,token); GetMagickToken(q,&q,token); switch (*keyword) { case 'E': case 'e': { if (LocaleCompare((char *) keyword,"encoding") == 0) { type_info->encoding=ConstantString(token); break; } break; } case 'F': case 'f': { if (LocaleCompare((char *) keyword,"face") == 0) { type_info->face=StringToUnsignedLong(token); break; } if (LocaleCompare((char *) keyword,"family") == 0) { type_info->family=ConstantString(token); break; } if (LocaleCompare((char *) keyword,"format") == 0) { type_info->format=ConstantString(token); break; } if (LocaleCompare((char *) keyword,"foundry") == 0) { type_info->foundry=ConstantString(token); break; } if (LocaleCompare((char *) keyword,"fullname") == 0) { type_info->description=ConstantString(token); break; } break; } case 'G': case 'g': { if (LocaleCompare((char *) keyword,"glyphs") == 0) { char *path; path=ConstantString(token); #if defined(MAGICKCORE_WINDOWS_SUPPORT) if (strchr(path,'@') != (char *) NULL) SubstituteString(&path,"@ghostscript_font_path@",font_path); #endif if (IsPathAccessible(path) == MagickFalse) { /* Relative path. */ path=DestroyString(path); GetPathComponent(filename,HeadPath,font_path); (void) ConcatenateMagickString(font_path,DirectorySeparator, MaxTextExtent); (void) ConcatenateMagickString(font_path,token,MaxTextExtent); path=ConstantString(font_path); if (IsPathAccessible(path) == MagickFalse) { path=DestroyString(path); path=ConstantString(token); } } type_info->glyphs=path; break; } break; } case 'M': case 'm': { if (LocaleCompare((char *) keyword,"metrics") == 0) { char *path; path=ConstantString(token); #if defined(MAGICKCORE_WINDOWS_SUPPORT) if (strchr(path,'@') != (char *) NULL) SubstituteString(&path,"@ghostscript_font_path@",font_path); #endif if (IsPathAccessible(path) == MagickFalse) { /* Relative path. */ path=DestroyString(path); GetPathComponent(filename,HeadPath,font_path); (void) ConcatenateMagickString(font_path,DirectorySeparator, MaxTextExtent); (void) ConcatenateMagickString(font_path,token,MaxTextExtent); path=ConstantString(font_path); } type_info->metrics=path; break; } break; } case 'N': case 'n': { if (LocaleCompare((char *) keyword,"name") == 0) { type_info->name=ConstantString(token); break; } break; } case 'S': case 's': { if (LocaleCompare((char *) keyword,"stealth") == 0) { type_info->stealth=IsStringTrue(token); break; } if (LocaleCompare((char *) keyword,"stretch") == 0) { type_info->stretch=(StretchType) ParseCommandOption( MagickStretchOptions,MagickFalse,token); break; } if (LocaleCompare((char *) keyword,"style") == 0) { type_info->style=(StyleType) ParseCommandOption(MagickStyleOptions, MagickFalse,token); break; } break; } case 'W': case 'w': { if (LocaleCompare((char *) keyword,"weight") == 0) { type_info->weight=StringToUnsignedLong(token); if (LocaleCompare(token,"bold") == 0) type_info->weight=700; if (LocaleCompare(token,"normal") == 0) type_info->weight=400; break; } break; } default: break; } } token=(char *) RelinquishMagickMemory(token); return(status); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d V I D I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadVIDImage reads one of more images and creates a Visual Image % Directory file. It allocates the memory necessary for the new Image % structure and returns a pointer to the new image. % % The format of the ReadVIDImage method is: % % Image *ReadVIDImage(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. % */ static Image *ReadVIDImage(const ImageInfo *image_info,ExceptionInfo *exception) { #define ClientName "montage" char **filelist, *label; Image *image, *images, *montage_image, *next_image, *thumbnail_image; ImageInfo *read_info; int number_files; MagickBooleanType status; MontageInfo *montage_info; RectangleInfo geometry; register ssize_t i; /* Expand the filename. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AcquireImage(image_info); filelist=(char **) AcquireAlignedMemory(1,sizeof(*filelist)); if (filelist == (char **) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); filelist[0]=ConstantString(image_info->filename); number_files=1; status=ExpandFilenames(&number_files,&filelist); if ((status == MagickFalse) || (number_files == 0)) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); image=DestroyImage(image); /* Read each image and convert them to a tile. */ images=NewImageList(); read_info=CloneImageInfo(image_info); SetImageInfoBlob(read_info,(void *) NULL,0); (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL, (void *) NULL); if (read_info->size == (char *) NULL) (void) CloneString(&read_info->size,DefaultTileGeometry); for (i=0; i < (ssize_t) number_files; i++) { if (image_info->debug != MagickFalse) (void) LogMagickEvent(CoderEvent,GetMagickModule(),"name: %s", filelist[i]); (void) CopyMagickString(read_info->filename,filelist[i],MaxTextExtent); filelist[i]=DestroyString(filelist[i]); *read_info->magick='\0'; next_image=ReadImage(read_info,exception); CatchException(exception); if (next_image == (Image *) NULL) break; label=InterpretImageProperties(image_info,next_image,DefaultTileLabel); (void) SetImageProperty(next_image,"label",label); label=DestroyString(label); if (image_info->debug != MagickFalse) (void) LogMagickEvent(CoderEvent,GetMagickModule(), "geometry: %.20gx%.20g",(double) next_image->columns,(double) next_image->rows); SetGeometry(next_image,&geometry); (void) ParseMetaGeometry(read_info->size,&geometry.x,&geometry.y, &geometry.width,&geometry.height); thumbnail_image=ThumbnailImage(next_image,geometry.width,geometry.height, exception); if (thumbnail_image != (Image *) NULL) { next_image=DestroyImage(next_image); next_image=thumbnail_image; } if (image_info->debug != MagickFalse) (void) LogMagickEvent(CoderEvent,GetMagickModule(), "thumbnail geometry: %.20gx%.20g",(double) next_image->columns,(double) next_image->rows); AppendImageToList(&images,next_image); status=SetImageProgress(images,LoadImagesTag,i,number_files); if (status == MagickFalse) break; } read_info=DestroyImageInfo(read_info); filelist=(char **) RelinquishMagickMemory(filelist); if (images == (Image *) NULL) ThrowReaderException(CorruptImageError, "ImageFileDoesNotContainAnyImageData"); /* Create the visual image directory. */ montage_info=CloneMontageInfo(image_info,(MontageInfo *) NULL); if (image_info->debug != MagickFalse) (void) LogMagickEvent(CoderEvent,GetMagickModule(),"creating montage"); montage_image=MontageImageList(image_info,montage_info, GetFirstImageInList(images),exception); montage_info=DestroyMontageInfo(montage_info); images=DestroyImageList(images); return(montage_image); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d L A B E L I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadLABELImage() reads a LABEL image file and returns it. It % allocates the memory necessary for the new Image structure and returns a % pointer to the new image. % % The format of the ReadLABELImage method is: % % Image *ReadLABELImage(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. % */ static Image *ReadLABELImage(const ImageInfo *image_info, ExceptionInfo *exception) { char geometry[MaxTextExtent], *property; const char *label; DrawInfo *draw_info; Image *image; MagickBooleanType status; TypeMetric metrics; size_t height, width; /* Initialize Image structure. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AcquireImage(image_info); (void) ResetImagePage(image,"0x0+0+0"); property=InterpretImageProperties(image_info,image,image_info->filename); (void) SetImageProperty(image,"label",property); property=DestroyString(property); label=GetImageProperty(image,"label"); draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL); draw_info->text=ConstantString(label); if (((image->columns != 0) || (image->rows != 0)) && (image_info->pointsize == 0.0)) { /* Fit label to canvas size. */ status=GetMultilineTypeMetrics(image,draw_info,&metrics); for ( ; status != MagickFalse; draw_info->pointsize*=2.0) { width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5); height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5); if (((image->columns != 0) && (width > (image->columns+1))) || ((image->rows != 0) && (height > (image->rows+1)))) break; status=GetMultilineTypeMetrics(image,draw_info,&metrics); } for ( ; status != MagickFalse; draw_info->pointsize--) { width=(size_t) floor(metrics.width+draw_info->stroke_width+0.5); height=(size_t) floor(metrics.height+draw_info->stroke_width+0.5); if ((image->columns != 0) && (width <= (image->columns+1)) && ((image->rows == 0) || (height <= (image->rows+1)))) break; if ((image->rows != 0) && (height <= (image->rows+1)) && ((image->columns == 0) || (width <= (image->columns+1)))) break; if (draw_info->pointsize < 2.0) break; status=GetMultilineTypeMetrics(image,draw_info,&metrics); } } status=GetMultilineTypeMetrics(image,draw_info,&metrics); if (status == MagickFalse) { InheritException(exception,&image->exception); image=DestroyImageList(image); return((Image *) NULL); } if (image->columns == 0) image->columns=(size_t) (metrics.width+draw_info->stroke_width+1.5); if (image->columns == 0) image->columns=(size_t) (draw_info->pointsize+ draw_info->stroke_width+1.5); if (draw_info->gravity == UndefinedGravity) { (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g", -metrics.bounds.x1+draw_info->stroke_width/2.0,metrics.ascent+ draw_info->stroke_width/2.0); draw_info->geometry=AcquireString(geometry); } if (image->rows == 0) image->rows=(size_t) floor(metrics.height+draw_info->stroke_width+0.5); if (image->rows == 0) image->rows=(size_t) floor(draw_info->pointsize+draw_info->stroke_width+ 0.5); if (SetImageBackgroundColor(image) == MagickFalse) { InheritException(exception,&image->exception); image=DestroyImageList(image); return((Image *) NULL); } (void) AnnotateImage(image,draw_info); if (image_info->pointsize == 0.0) { char pointsize[MaxTextExtent]; (void) FormatLocaleString(pointsize,MaxTextExtent,"%.20g", draw_info->pointsize); (void) SetImageProperty(image,"label:pointsize",pointsize); } draw_info=DestroyDrawInfo(draw_info); return(GetFirstImageInList(image)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d C A P T I O N I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadCAPTIONImage() reads a CAPTION image file and returns it. It % allocates the memory necessary for the new Image structure and returns a % pointer to the new image. % % The format of the ReadCAPTIONImage method is: % % Image *ReadCAPTIONImage(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. % */ static Image *ReadCAPTIONImage(const ImageInfo *image_info, ExceptionInfo *exception) { char *caption, geometry[MaxTextExtent], *property; const char *gravity; DrawInfo *draw_info; Image *image; MagickBooleanType status; register long i; TypeMetric metrics; unsigned long height, width; /* Initialize Image structure. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AcquireImage(image_info); if (image->columns == 0) ThrowReaderException(OptionError,"MustSpecifyImageSize"); (void) ResetImagePage(image,"0x0+0+0"); /* Format caption. */ property=InterpretImageProperties(image_info,image,image_info->filename); (void) SetImageProperty(image,"caption",property); property=DestroyString(property); caption=ConstantString(GetImageProperty(image,"caption")); draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL); draw_info->text=ConstantString(caption); gravity=GetImageOption(image_info,"gravity"); if (gravity != (char *) NULL) draw_info->gravity=(GravityType) ParseMagickOption(MagickGravityOptions, MagickFalse,gravity); if ((*caption != '\0') && (image->rows != 0) && (image_info->pointsize == 0.0)) { char *text; /* Scale text to fit bounding box. */ for ( ; ; ) { text=AcquireString(caption); i=FormatMagickCaption(image,draw_info,&metrics,&text); (void) CloneString(&draw_info->text,text); text=DestroyString(text); (void) FormatMagickString(geometry,MaxTextExtent,"%+g%+g", -metrics.bounds.x1,metrics.ascent); if (draw_info->gravity == UndefinedGravity) (void) CloneString(&draw_info->geometry,geometry); status=GetMultilineTypeMetrics(image,draw_info,&metrics); width=(unsigned long) floor(metrics.width+draw_info->stroke_width+0.5); height=(unsigned long) floor(metrics.height+draw_info->stroke_width+ 0.5); if ((width > (image->columns+1)) || (height > (image->rows+1))) break; draw_info->pointsize*=2.0; } draw_info->pointsize/=2.0; for ( ; ; ) { text=AcquireString(caption); i=FormatMagickCaption(image,draw_info,&metrics,&text); (void) CloneString(&draw_info->text,text); text=DestroyString(text); (void) FormatMagickString(geometry,MaxTextExtent,"%+g%+g", -metrics.bounds.x1,metrics.ascent); if (draw_info->gravity == UndefinedGravity) (void) CloneString(&draw_info->geometry,geometry); status=GetMultilineTypeMetrics(image,draw_info,&metrics); width=(unsigned long) floor(metrics.width+draw_info->stroke_width+0.5); height=(unsigned long) floor(metrics.height+draw_info->stroke_width+ 0.5); if ((width > (image->columns+1)) || (height > (image->rows+1))) break; draw_info->pointsize++; } draw_info->pointsize--; } i=FormatMagickCaption(image,draw_info,&metrics,&caption); if (image->rows == 0) image->rows=(unsigned long) ((i+1)*(metrics.ascent-metrics.descent+ draw_info->stroke_width)+0.5); if (image->rows == 0) image->rows=(unsigned long) ((i+1)*draw_info->pointsize+ draw_info->stroke_width+0.5); if (SetImageBackgroundColor(image) == MagickFalse) { InheritException(exception,&image->exception); image=DestroyImageList(image); return((Image *) NULL); } /* Draw caption. */ (void) CloneString(&draw_info->text,caption); status=GetMultilineTypeMetrics(image,draw_info,&metrics); if (draw_info->gravity != UndefinedGravity) image->page.x=(long) (metrics.bounds.x1-draw_info->stroke_width/2.0); else { (void) FormatMagickString(geometry,MaxTextExtent,"%+g%+g", -metrics.bounds.x1+draw_info->stroke_width/2.0,metrics.ascent+ draw_info->stroke_width/2.0); (void) CloneString(&draw_info->geometry,geometry); } (void) AnnotateImage(image,draw_info); draw_info=DestroyDrawInfo(draw_info); caption=DestroyString(caption); return(GetFirstImageInList(image)); }
MagickExport int AcquireUniqueFileResource(char *path) { #if !defined(O_NOFOLLOW) #define O_NOFOLLOW 0 #endif #if !defined(TMP_MAX) # define TMP_MAX 238328 #endif int c, file; register char *p; register ssize_t i; static const char portable_filename[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"; StringInfo *key; unsigned char *datum; assert(path != (char *) NULL); (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s",path); if (random_info == (RandomInfo *) NULL) random_info=AcquireRandomInfo(); file=(-1); for (i=0; i < (ssize_t) TMP_MAX; i++) { /* Get temporary pathname. */ (void) GetPathTemplate(path); key=GetRandomKey(random_info,2); p=path+strlen(path)-8; datum=GetStringInfoDatum(key); for (i=0; i < (ssize_t) GetStringInfoLength(key); i++) { c=(int) (datum[i] & 0x3f); *p++=portable_filename[c]; } key=DestroyStringInfo(key); #if defined(MAGICKCORE_HAVE_MKSTEMP) file=mkstemp(path); #if defined(__OS2__) setmode(file,O_BINARY); #endif if (file != -1) break; #endif key=GetRandomKey(random_info,6); p=path+strlen(path)-6; datum=GetStringInfoDatum(key); for (i=0; i < (ssize_t) GetStringInfoLength(key); i++) { c=(int) (datum[i] & 0x3f); *p++=portable_filename[c]; } key=DestroyStringInfo(key); file=open_utf8(path,O_RDWR | O_CREAT | O_EXCL | O_BINARY | O_NOFOLLOW,S_MODE); if ((file >= 0) || (errno != EEXIST)) break; } (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s",path); if (file == -1) return(file); if (resource_semaphore == (SemaphoreInfo *) NULL) AcquireSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); if (temporary_resources == (SplayTreeInfo *) NULL) temporary_resources=NewSplayTree(CompareSplayTreeString, DestroyTemporaryResources,(void *(*)(void *)) NULL); UnlockSemaphoreInfo(resource_semaphore); (void) AddValueToSplayTree(temporary_resources,ConstantString(path), (const void *) NULL); return(file); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + L o a d M a g i c L i s t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % LoadMagicCache() loads the magic configurations which provides a mapping % between magic attributes and a magic name. % % The format of the LoadMagicCache method is: % % MagickBooleanType LoadMagicCache(LinkedListInfo *magic_cache, % const char *xml,const char *filename,const size_t depth, % ExceptionInfo *exception) % % A description of each parameter follows: % % o xml: The magic list in XML format. % % o filename: The magic list filename. % % o depth: depth of <include /> statements. % % o exception: return any errors or warnings in this structure. % */ static MagickBooleanType LoadMagicCache(LinkedListInfo *magic_cache, const char *xml,const char *filename,const size_t depth, ExceptionInfo *exception) { char keyword[MaxTextExtent], *token; const char *q; MagicInfo *magic_info; MagickStatusType status; /* Load the magic map file. */ (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), "Loading magic configure file \"%s\" ...",filename); if (xml == (char *) NULL) return(MagickFalse); status=MagickTrue; magic_info=(MagicInfo *) NULL; token=AcquireString(xml); for (q=(char *) xml; *q != '\0'; ) { /* Interpret XML. */ GetMagickToken(q,&q,token); if (*token == '\0') break; (void) CopyMagickString(keyword,token,MaxTextExtent); if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0) { /* Doctype element. */ while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0')) GetMagickToken(q,&q,token); continue; } if (LocaleNCompare(keyword,"<!--",4) == 0) { /* Comment element. */ while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0')) GetMagickToken(q,&q,token); continue; } if (LocaleCompare(keyword,"<include") == 0) { /* Include element. */ while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0')) { (void) CopyMagickString(keyword,token,MaxTextExtent); GetMagickToken(q,&q,token); if (*token != '=') continue; GetMagickToken(q,&q,token); if (LocaleCompare(keyword,"file") == 0) { if (depth > 200) (void) ThrowMagickException(exception,GetMagickModule(), ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token); else { char path[MaxTextExtent], *xml; GetPathComponent(filename,HeadPath,path); if (*path != '\0') (void) ConcatenateMagickString(path,DirectorySeparator, MaxTextExtent); if (*token == *DirectorySeparator) (void) CopyMagickString(path,token,MaxTextExtent); else (void) ConcatenateMagickString(path,token,MaxTextExtent); xml=FileToXML(path,~0UL); if (xml != (char *) NULL) { status&=LoadMagicCache(magic_cache,xml,path,depth+1, exception); xml=(char *) RelinquishMagickMemory(xml); } } } } continue; } if (LocaleCompare(keyword,"<magic") == 0) { /* Magic element. */ magic_info=(MagicInfo *) AcquireMagickMemory(sizeof(*magic_info)); if (magic_info == (MagicInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); (void) ResetMagickMemory(magic_info,0,sizeof(*magic_info)); magic_info->path=ConstantString(filename); magic_info->exempt=MagickFalse; magic_info->signature=MagickSignature; continue; } if (magic_info == (MagicInfo *) NULL) continue; if (LocaleCompare(keyword,"/>") == 0) { status=AppendValueToLinkedList(magic_cache,magic_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'", magic_info->name); magic_info=(MagicInfo *) NULL; continue; } GetMagickToken(q,(const char **) NULL,token); if (*token != '=') continue; GetMagickToken(q,&q,token); GetMagickToken(q,&q,token); switch (*keyword) { case 'N': case 'n': { if (LocaleCompare((char *) keyword,"name") == 0) { magic_info->name=ConstantString(token); break; } break; } case 'O': case 'o': { if (LocaleCompare((char *) keyword,"offset") == 0) { magic_info->offset=(MagickOffsetType) StringToLong(token); break; } break; } case 'S': case 's': { if (LocaleCompare((char *) keyword,"stealth") == 0) { magic_info->stealth=IsMagickTrue(token); break; } break; } case 'T': case 't': { if (LocaleCompare((char *) keyword,"target") == 0) { char *p; register unsigned char *q; size_t length; length=strlen(token); magic_info->target=ConstantString(token); magic_info->magic=(unsigned char *) ConstantString(token); q=magic_info->magic; for (p=magic_info->target; *p != '\0'; ) { if (*p == '\\') { p++; if (isdigit((int) ((unsigned char) *p)) != 0) { char *end; *q++=(unsigned char) strtol(p,&end,8); p+=(end-p); magic_info->length++; continue; } switch (*p) { case 'b': *q='\b'; break; case 'f': *q='\f'; break; case 'n': *q='\n'; break; case 'r': *q='\r'; break; case 't': *q='\t'; break; case 'v': *q='\v'; break; case 'a': *q='a'; break; case '?': *q='\?'; break; default: *q=(unsigned char) (*p); break; } p++; q++; magic_info->length++; continue; } else if (LocaleNCompare(p,"&",5) == 0) (void) CopyMagickString(p+1,p+5,length-magic_info->length); *q++=(unsigned char) (*p++); magic_info->length++; } break; } break; } default: break; } } token=(char *) RelinquishMagickMemory(token); return(status != 0 ? MagickTrue : MagickFalse); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d D N G I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadDNGImage() reads an binary file in the Digital Negative format and % returns it. It allocates the memory necessary for the new Image structure % and returns a pointer to the new image. % % The format of the ReadDNGImage method is: % % Image *ReadDNGImage(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. % */ static Image *ReadDNGImage(const ImageInfo *image_info,ExceptionInfo *exception) { ExceptionInfo *sans_exception; Image *image; ImageInfo *read_info; MagickBooleanType status; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AcquireImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } (void) CloseBlob(image); (void) DestroyImageList(image); /* Convert DNG to PPM with delegate. */ image=AcquireImage(image_info); read_info=CloneImageInfo(image_info); (void) InvokeDelegate(read_info,image,"dng:decode",(char *) NULL,exception); image=DestroyImage(image); (void) FormatMagickString(read_info->filename,MaxTextExtent,"%s.png", read_info->unique); sans_exception=AcquireExceptionInfo(); image=ReadImage(read_info,sans_exception); sans_exception=DestroyExceptionInfo(sans_exception); if (image == (Image *) NULL) { (void) FormatMagickString(read_info->filename,MaxTextExtent,"%s.ppm", read_info->unique); image=ReadImage(read_info,exception); } (void) RelinquishUniqueFileResource(read_info->filename); if (image != (Image *) NULL) { char filename[MaxTextExtent], *xml; ExceptionInfo *sans; (void) CopyMagickString(image->magick,read_info->magick,MaxTextExtent); (void) FormatMagickString(filename,MaxTextExtent,"%s.ufraw", read_info->unique); sans=AcquireExceptionInfo(); xml=FileToString(filename,MaxTextExtent,sans); (void) RelinquishUniqueFileResource(filename); if (xml != (char *) NULL) { XMLTreeInfo *ufraw; /* Inject */ ufraw=NewXMLTree(xml,sans); if (ufraw != (XMLTreeInfo *) NULL) { char *content, property[MaxTextExtent]; const char *tag; XMLTreeInfo *next; if (image->properties == (void *) NULL) ((Image *) image)->properties=NewSplayTree( CompareSplayTreeString,RelinquishMagickMemory, RelinquishMagickMemory); next=GetXMLTreeChild(ufraw,(const char *) NULL); while (next != (XMLTreeInfo *) NULL) { tag=GetXMLTreeTag(next); if (tag == (char *) NULL) tag="unknown"; (void) FormatMagickString(property,MaxTextExtent,"dng:%s",tag); content=ConstantString(GetXMLTreeContent(next)); StripString(content); if ((LocaleCompare(tag,"log") != 0) && (LocaleCompare(tag,"InputFilename") != 0) && (LocaleCompare(tag,"OutputFilename") != 0) && (LocaleCompare(tag,"OutputType") != 0) && (strlen(content) != 0)) (void) AddValueToSplayTree((SplayTreeInfo *) ((Image *) image)->properties,ConstantString(property), content); next=GetXMLTreeSibling(next); } ufraw=DestroyXMLTree(ufraw); } xml=DestroyString(xml); } sans=DestroyExceptionInfo(sans); } read_info=DestroyImageInfo(read_info); return(image); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e g i s t e r D N G I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RegisterDNGImage() adds attributes for the DNG image format to % the list of supported formats. The attributes include the image format % tag, a method to read and/or write the format, whether the format % supports the saving of more than one frame to the same file or blob, % whether the format supports native in-memory I/O, and a brief % description of the format. % % The format of the RegisterDNGImage method is: % % unsigned long RegisterDNGImage(void) % */ ModuleExport unsigned long RegisterDNGImage(void) { MagickInfo *entry; entry=SetMagickInfo("ARW"); entry->decoder=(DecodeImageHandler *) ReadDNGImage; entry->blob_support=MagickFalse; entry->seekable_stream=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Sony Alpha Raw Image Format"); entry->module=ConstantString("DNG"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("DNG"); entry->decoder=(DecodeImageHandler *) ReadDNGImage; entry->blob_support=MagickFalse; entry->seekable_stream=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Digital Negative"); entry->module=ConstantString("DNG"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("CR2"); entry->decoder=(DecodeImageHandler *) ReadDNGImage; entry->blob_support=MagickFalse; entry->seekable_stream=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Canon Digital Camera Raw Image Format"); entry->module=ConstantString("DNG"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("CRW"); entry->decoder=(DecodeImageHandler *) ReadDNGImage; entry->blob_support=MagickFalse; entry->seekable_stream=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Canon Digital Camera Raw Image Format"); entry->module=ConstantString("DNG"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("DCR"); entry->decoder=(DecodeImageHandler *) ReadDNGImage; entry->blob_support=MagickFalse; entry->seekable_stream=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Kodak Digital Camera Raw Image File"); entry->module=ConstantString("DNG"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("ERF"); entry->decoder=(DecodeImageHandler *) ReadDNGImage; entry->blob_support=MagickFalse; entry->seekable_stream=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Epson RAW Format"); entry->module=ConstantString("DNG"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("KDC"); entry->decoder=(DecodeImageHandler *) ReadDNGImage; entry->blob_support=MagickFalse; entry->seekable_stream=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Kodak Digital Camera Raw Image Format"); entry->module=ConstantString("DNG"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("K25"); entry->decoder=(DecodeImageHandler *) ReadDNGImage; entry->blob_support=MagickFalse; entry->seekable_stream=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Kodak Digital Camera Raw Image Format"); entry->module=ConstantString("DNG"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("MRW"); entry->decoder=(DecodeImageHandler *) ReadDNGImage; entry->blob_support=MagickFalse; entry->seekable_stream=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Sony (Minolta) Raw Image File"); entry->module=ConstantString("DNG"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("NEF"); entry->decoder=(DecodeImageHandler *) ReadDNGImage; entry->blob_support=MagickFalse; entry->seekable_stream=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Nikon Digital SLR Camera Raw Image File"); entry->module=ConstantString("DNG"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("ORF"); entry->decoder=(DecodeImageHandler *) ReadDNGImage; entry->blob_support=MagickFalse; entry->seekable_stream=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Olympus Digital Camera Raw Image File"); entry->module=ConstantString("DNG"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("PEF"); entry->decoder=(DecodeImageHandler *) ReadDNGImage; entry->blob_support=MagickFalse; entry->seekable_stream=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Pentax Electronic File"); entry->module=ConstantString("DNG"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("RAF"); entry->decoder=(DecodeImageHandler *) ReadDNGImage; entry->blob_support=MagickFalse; entry->seekable_stream=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Fuji CCD-RAW Graphic File"); entry->module=ConstantString("DNG"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("SRF"); entry->decoder=(DecodeImageHandler *) ReadDNGImage; entry->blob_support=MagickFalse; entry->seekable_stream=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Sony Raw Format"); entry->module=ConstantString("DNG"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("SR2"); entry->decoder=(DecodeImageHandler *) ReadDNGImage; entry->blob_support=MagickFalse; entry->seekable_stream=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Sony Raw Format 2"); entry->module=ConstantString("DNG"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("X3F"); entry->decoder=(DecodeImageHandler *) ReadDNGImage; entry->blob_support=MagickFalse; entry->seekable_stream=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Sigma Camera RAW Picture File"); entry->module=ConstantString("DNG"); (void) RegisterMagickInfo(entry); return(MagickImageCoderSignature); }
static Image *ReadXPMImage(const ImageInfo *image_info,ExceptionInfo *exception) { char *grey, key[MaxTextExtent], target[MaxTextExtent], *xpm_buffer; Image *image; MagickBooleanType active, status; register char *next, *p, *q; register IndexPacket *indexes; register ssize_t x; register PixelPacket *r; size_t length; SplayTreeInfo *xpm_colors; ssize_t count, j, y; unsigned long colors, columns, rows, width; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AcquireImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } /* Read XPM file. */ length=MaxTextExtent; xpm_buffer=(char *) AcquireQuantumMemory((size_t) length,sizeof(*xpm_buffer)); if (xpm_buffer == (char *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); *xpm_buffer='\0'; p=xpm_buffer; while (ReadBlobString(image,p) != (char *) NULL) { if ((*p == '#') && ((p == xpm_buffer) || (*(p-1) == '\n'))) continue; if ((*p == '}') && (*(p+1) == ';')) break; p+=strlen(p); if ((size_t) (p-xpm_buffer+MaxTextExtent) < length) continue; length<<=1; xpm_buffer=(char *) ResizeQuantumMemory(xpm_buffer,length+MaxTextExtent, sizeof(*xpm_buffer)); if (xpm_buffer == (char *) NULL) break; p=xpm_buffer+strlen(xpm_buffer); } if (xpm_buffer == (char *) NULL) ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); /* Remove comments. */ count=0; width=0; for (p=xpm_buffer; *p != '\0'; p++) { if (*p != '"') continue; count=(ssize_t) sscanf(p+1,"%lu %lu %lu %lu",&columns,&rows,&colors,&width); image->columns=columns; image->rows=rows; image->colors=colors; if (count == 4) break; } if ((count != 4) || (width > 10) || (image->columns == 0) || (image->rows == 0) || (image->colors == 0)) { xpm_buffer=DestroyString(xpm_buffer); ThrowReaderException(CorruptImageError,"ImproperImageHeader"); } /* Remove unquoted characters. */ active=MagickFalse; q=xpm_buffer; while (*p != '\0') { if (*p++ == '"') { if (active != MagickFalse) *q++='\n'; active=active != MagickFalse ? MagickFalse : MagickTrue; } if (active != MagickFalse) *q++=(*p); } *q='\0'; /* Initialize image structure. */ xpm_colors=NewSplayTree(CompareXPMColor,RelinquishMagickMemory, (void *(*)(void *)) NULL); if (AcquireImageColormap(image,image->colors) == MagickFalse) { xpm_buffer=DestroyString(xpm_buffer); ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); } /* Read image colormap. */ image->depth=1; next=NextXPMLine(xpm_buffer); for (j=0; (j < (ssize_t) image->colors) && (next != (char *) NULL); j++) { MagickPixelPacket pixel; p=next; next=NextXPMLine(p); (void) CopyXPMColor(key,p,MagickMin((size_t) width,MaxTextExtent-1)); status=AddValueToSplayTree(xpm_colors,ConstantString(key),(void *) j); /* Parse color. */ (void) CopyMagickString(target,"gray",MaxTextExtent); q=ParseXPMColor(p+width,MagickTrue); if (q != (char *) NULL) { while ((isspace((int) ((unsigned char) *q)) == 0) && (*q != '\0')) q++; if ((next-q) < 0) break; if (next != (char *) NULL) (void) CopyXPMColor(target,q,MagickMin((size_t) (next-q), MaxTextExtent-1)); else (void) CopyMagickString(target,q,MaxTextExtent); q=ParseXPMColor(target,MagickFalse); if (q != (char *) NULL) *q='\0'; } StripString(target); grey=strstr(target,"grey"); if (grey != (char *) NULL) grey[2]='a'; if (LocaleCompare(target,"none") == 0) { image->storage_class=DirectClass; image->matte=MagickTrue; } status=QueryColorCompliance(target,XPMCompliance,&image->colormap[j], exception); if (status == MagickFalse) break; (void) QueryMagickColorCompliance(target,XPMCompliance,&pixel,exception); if (image->depth < pixel.depth) image->depth=pixel.depth; } if (j < (ssize_t) image->colors) { xpm_colors=DestroySplayTree(xpm_colors); xpm_buffer=DestroyString(xpm_buffer); ThrowReaderException(CorruptImageError,"CorruptImage"); } j=0; if (image_info->ping == MagickFalse) { /* Read image pixels. */ status=SetImageExtent(image,image->columns,image->rows); if (status == MagickFalse) { InheritException(exception,&image->exception); return(DestroyImageList(image)); } for (y=0; y < (ssize_t) image->rows; y++) { p=NextXPMLine(p); if (p == (char *) NULL) break; r=QueueAuthenticPixels(image,0,y,image->columns,1,exception); if (r == (PixelPacket *) NULL) break; indexes=GetAuthenticIndexQueue(image); for (x=0; x < (ssize_t) image->columns; x++) { ssize_t count=CopyXPMColor(key,p,MagickMin(width,MaxTextExtent-1)); if (count != (ssize_t) width) break; j=(ssize_t) GetValueFromSplayTree(xpm_colors,key); if (image->storage_class == PseudoClass) SetPixelIndex(indexes+x,j); *r=image->colormap[j]; p+=count; r++; } if (x < (ssize_t) image->columns) break; if (SyncAuthenticPixels(image,exception) == MagickFalse) break; } if (y < (ssize_t) image->rows) { xpm_colors=DestroySplayTree(xpm_colors); xpm_buffer=DestroyString(xpm_buffer); ThrowReaderException(CorruptImageError,"NotEnoughPixelData"); } } /* Relinquish resources. */ xpm_colors=DestroySplayTree(xpm_colors); xpm_buffer=DestroyString(xpm_buffer); (void) CloseBlob(image); return(GetFirstImageInList(image)); }
MagickExport MagickBooleanType LoadFontConfigFonts(SplayTreeInfo *type_list, ExceptionInfo *exception) { #if !defined(FC_FULLNAME) #define FC_FULLNAME "fullname" #endif char extension[MaxTextExtent], name[MaxTextExtent]; FcChar8 *family, *file, *fullname, *style; FcConfig *font_config; FcFontSet *font_set; FcObjectSet *object_set; FcPattern *pattern; FcResult status; int slant, width, weight; register ssize_t i; TypeInfo *type_info; /* Load system fonts. */ (void) exception; font_config=FcInitLoadConfigAndFonts(); if (font_config == (FcConfig *) NULL) return(MagickFalse); font_set=(FcFontSet *) NULL; object_set=FcObjectSetBuild(FC_FULLNAME,FC_FAMILY,FC_STYLE,FC_SLANT, FC_WIDTH,FC_WEIGHT,FC_FILE,(char *) NULL); if (object_set != (FcObjectSet *) NULL) { pattern=FcPatternCreate(); if (pattern != (FcPattern *) NULL) { font_set=FcFontList(0,pattern,object_set); FcPatternDestroy(pattern); } FcObjectSetDestroy(object_set); } if (font_set == (FcFontSet *) NULL) { FcConfigDestroy(font_config); return(MagickFalse); } for (i=0; i < (ssize_t) font_set->nfont; i++) { status=FcPatternGetString(font_set->fonts[i],FC_FAMILY,0,&family); if (status != FcResultMatch) continue; status=FcPatternGetString(font_set->fonts[i],FC_FILE,0,&file); if (status != FcResultMatch) continue; *extension='\0'; GetPathComponent((const char *) file,ExtensionPath,extension); if ((*extension != '\0') && (LocaleCompare(extension,"gz") == 0)) continue; type_info=(TypeInfo *) AcquireMagickMemory(sizeof(*type_info)); if (type_info == (TypeInfo *) NULL) continue; (void) ResetMagickMemory(type_info,0,sizeof(*type_info)); type_info->path=ConstantString("System Fonts"); type_info->signature=MagickSignature; (void) CopyMagickString(name,"Unknown",MaxTextExtent); status=FcPatternGetString(font_set->fonts[i],FC_FULLNAME,0,&fullname); if ((status == FcResultMatch) && (fullname != (FcChar8 *) NULL)) (void) CopyMagickString(name,(const char *) fullname,MaxTextExtent); else { if (family != (FcChar8 *) NULL) (void) CopyMagickString(name,(const char *) family,MaxTextExtent); status=FcPatternGetString(font_set->fonts[i],FC_STYLE,0,&style); if ((status == FcResultMatch) && (style != (FcChar8 *) NULL) && (LocaleCompare((const char *) style,"Regular") != 0)) { (void) ConcatenateMagickString(name," ",MaxTextExtent); (void) ConcatenateMagickString(name,(const char *) style, MaxTextExtent); } } type_info->name=ConstantString(name); (void) SubstituteString(&type_info->name," ","-"); type_info->family=ConstantString((const char *) family); status=FcPatternGetInteger(font_set->fonts[i],FC_SLANT,0,&slant); type_info->style=NormalStyle; if (slant == FC_SLANT_ITALIC) type_info->style=ItalicStyle; if (slant == FC_SLANT_OBLIQUE) type_info->style=ObliqueStyle; status=FcPatternGetInteger(font_set->fonts[i],FC_WIDTH,0,&width); type_info->stretch=NormalStretch; if (width >= FC_WIDTH_ULTRACONDENSED) type_info->stretch=UltraCondensedStretch; if (width >= FC_WIDTH_EXTRACONDENSED) type_info->stretch=ExtraCondensedStretch; if (width >= FC_WIDTH_CONDENSED) type_info->stretch=CondensedStretch; if (width >= FC_WIDTH_SEMICONDENSED) type_info->stretch=SemiCondensedStretch; if (width >= FC_WIDTH_NORMAL) type_info->stretch=NormalStretch; if (width >= FC_WIDTH_SEMIEXPANDED) type_info->stretch=SemiExpandedStretch; if (width >= FC_WIDTH_EXPANDED) type_info->stretch=ExpandedStretch; if (width >= FC_WIDTH_EXTRAEXPANDED) type_info->stretch=ExtraExpandedStretch; if (width >= FC_WIDTH_ULTRAEXPANDED) type_info->stretch=UltraExpandedStretch; type_info->weight=400; status=FcPatternGetInteger(font_set->fonts[i],FC_WEIGHT,0,&weight); if (weight >= FC_WEIGHT_THIN) type_info->weight=100; if (weight >= FC_WEIGHT_EXTRALIGHT) type_info->weight=200; if (weight >= FC_WEIGHT_LIGHT) type_info->weight=300; if (weight >= FC_WEIGHT_NORMAL) type_info->weight=400; if (weight >= FC_WEIGHT_MEDIUM) type_info->weight=500; if (weight >= FC_WEIGHT_DEMIBOLD) type_info->weight=600; if (weight >= FC_WEIGHT_BOLD) type_info->weight=700; if (weight >= FC_WEIGHT_EXTRABOLD) type_info->weight=800; if (weight >= FC_WEIGHT_BLACK) type_info->weight=900; type_info->glyphs=ConstantString((const char *) file); (void) AddValueToSplayTree(type_list,type_info->name,type_info); } FcFontSetDestroy(font_set); FcConfigDestroy(font_config); return(MagickTrue); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % N T A c q u i r e T y p e C a c h e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % NTAcquireTypeCache() loads a Windows TrueType fonts. % % The format of the NTAcquireTypeCache method is: % % MagickBooleanType NTAcquireTypeCache(SplayTreeInfo *type_cache) % % A description of each parameter follows: % % o type_cache: A linked list of fonts. % */ MagickExport MagickBooleanType NTAcquireTypeCache(SplayTreeInfo *type_cache, ExceptionInfo *exception) { HKEY reg_key = (HKEY) INVALID_HANDLE_VALUE; LONG res; int list_entries = 0; char buffer[MaxTextExtent], system_root[MaxTextExtent], font_root[MaxTextExtent]; DWORD type, system_root_length; MagickBooleanType status; /* Try to find the right Windows*\CurrentVersion key, the SystemRoot and then the Fonts key */ res = RegOpenKeyExA (HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, ®_key); if (res == ERROR_SUCCESS) { system_root_length=sizeof(system_root)-1; res = RegQueryValueExA(reg_key,"SystemRoot",NULL, &type, (BYTE*) system_root, &system_root_length); } if (res != ERROR_SUCCESS) { res = RegOpenKeyExA (HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", 0, KEY_READ, ®_key); if (res == ERROR_SUCCESS) { system_root_length=sizeof(system_root)-1; res = RegQueryValueExA(reg_key,"SystemRoot",NULL, &type, (BYTE*)system_root, &system_root_length); } } if (res == ERROR_SUCCESS) res = RegOpenKeyExA (reg_key, "Fonts",0, KEY_READ, ®_key); if (res != ERROR_SUCCESS) return(MagickFalse); *font_root='\0'; (void) CopyMagickString(buffer,system_root,MaxTextExtent); (void) ConcatenateMagickString(buffer,"\\fonts\\arial.ttf",MaxTextExtent); if (IsPathAccessible(buffer) != MagickFalse) { (void) CopyMagickString(font_root,system_root,MaxTextExtent); (void) ConcatenateMagickString(font_root,"\\fonts\\",MaxTextExtent); } else { (void) CopyMagickString(font_root,system_root,MaxTextExtent); (void) ConcatenateMagickString(font_root,"\\",MaxTextExtent); } { TypeInfo *type_info; DWORD registry_index = 0, type, value_data_size, value_name_length; char value_data[MaxTextExtent], value_name[MaxTextExtent]; res = ERROR_SUCCESS; while (res != ERROR_NO_MORE_ITEMS) { char *family_extent, token[MaxTextExtent], *pos, *q; value_name_length = sizeof(value_name) - 1; value_data_size = sizeof(value_data) - 1; res=RegEnumValueA(reg_key,registry_index,value_name,&value_name_length, 0,&type,(BYTE *) value_data,&value_data_size); registry_index++; if (res != ERROR_SUCCESS) continue; if ((pos=strstr(value_name," (TrueType)")) == (char*) NULL) continue; *pos='\0'; /* Remove (TrueType) from string */ type_info=(TypeInfo *) AcquireMagickMemory(sizeof(*type_info)); if (type_info == (TypeInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); (void) ResetMagickMemory(type_info,0,sizeof(TypeInfo)); type_info->path=ConstantString("Windows Fonts"); type_info->signature=MagickSignature; (void) CopyMagickString(buffer,value_name,MaxTextExtent); /* name */ for (pos=buffer; *pos != 0; pos++) if (*pos == ' ') *pos='-'; type_info->name=ConstantString(buffer); type_info->description=ConstantString(value_name); /* fullname */ type_info->format=ConstantString("truetype"); /* format */ if (strchr(value_data,'\\') != (char *) NULL) /* glyphs */ (void) CopyMagickString(buffer,value_data,MaxTextExtent); else { (void) CopyMagickString(buffer,font_root,MaxTextExtent); (void) ConcatenateMagickString(buffer,value_data,MaxTextExtent); } LocaleLower(buffer); type_info->glyphs=ConstantString(buffer); type_info->stretch=NormalStretch; type_info->style=NormalStyle; type_info->weight=400; /* Some fonts are known to require special encodings. */ if ( (LocaleCompare(type_info->name, "Symbol") == 0 ) || (LocaleCompare(type_info->name, "Wingdings") == 0 ) || (LocaleCompare(type_info->name, "Wingdings-2") == 0 ) || (LocaleCompare(type_info->name, "Wingdings-3") == 0 ) ) type_info->encoding=ConstantString("AppleRoman"); family_extent=value_name; for (q=value_name; *q != '\0'; ) { GetMagickToken(q,(const char **) &q,token); if (*token == '\0') break; if (LocaleCompare(token,"Italic") == 0) { type_info->style=ItalicStyle; } else if (LocaleCompare(token,"Oblique") == 0) { type_info->style=ObliqueStyle; } else if (LocaleCompare(token,"Bold") == 0) { type_info->weight=700; } else if (LocaleCompare(token,"Thin") == 0) { type_info->weight=100; } else if ( (LocaleCompare(token,"ExtraLight") == 0) || (LocaleCompare(token,"UltraLight") == 0) ) { type_info->weight=200; } else if (LocaleCompare(token,"Light") == 0) { type_info->weight=300; } else if ( (LocaleCompare(token,"Normal") == 0) || (LocaleCompare(token,"Regular") == 0) ) { type_info->weight=400; } else if (LocaleCompare(token,"Medium") == 0) { type_info->weight=500; } else if ( (LocaleCompare(token,"SemiBold") == 0) || (LocaleCompare(token,"DemiBold") == 0) ) { type_info->weight=600; } else if ( (LocaleCompare(token,"ExtraBold") == 0) || (LocaleCompare(token,"UltraBold") == 0) ) { type_info->weight=800; } else if ( (LocaleCompare(token,"Heavy") == 0) || (LocaleCompare(token,"Black") == 0) ) { type_info->weight=900; } else if (LocaleCompare(token,"Condensed") == 0) { type_info->stretch = CondensedStretch; } else if (LocaleCompare(token,"Expanded") == 0) { type_info->stretch = ExpandedStretch; } else if (LocaleCompare(token,"ExtraCondensed") == 0) { type_info->stretch = ExtraCondensedStretch; } else if (LocaleCompare(token,"ExtraExpanded") == 0) { type_info->stretch = ExtraExpandedStretch; } else if (LocaleCompare(token,"SemiCondensed") == 0) { type_info->stretch = SemiCondensedStretch; } else if (LocaleCompare(token,"SemiExpanded") == 0) { type_info->stretch = SemiExpandedStretch; } else if (LocaleCompare(token,"UltraCondensed") == 0) { type_info->stretch = UltraCondensedStretch; } else if (LocaleCompare(token,"UltraExpanded") == 0) { type_info->stretch = UltraExpandedStretch; } else { family_extent=q; } } (void) CopyMagickString(buffer,value_name,family_extent-value_name+1); StripString(buffer); type_info->family=ConstantString(buffer); list_entries++; status=AddValueToSplayTree(type_cache,ConstantString(type_info->name), type_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",type_info->name); } } RegCloseKey(reg_key); return(MagickTrue); }
static Image *ReadFITSImage(const ImageInfo *image_info, ExceptionInfo *exception) { typedef struct _FITSInfo { MagickBooleanType extend, simple; int bits_per_pixel, columns, rows, number_axes, number_planes; double min_data, max_data, zero, scale; EndianType endian; } FITSInfo; char *comment, keyword[9], property[MaxTextExtent], value[73]; double pixel, scale; FITSInfo fits_info; Image *image; int c; MagickBooleanType status; MagickSizeType number_pixels; register ssize_t i, x; register PixelPacket *q; ssize_t count, scene, y; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); image=AcquireImage(image_info); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } /* Initialize image header. */ (void) ResetMagickMemory(&fits_info,0,sizeof(fits_info)); fits_info.extend=MagickFalse; fits_info.simple=MagickFalse; fits_info.bits_per_pixel=8; fits_info.columns=1; fits_info.rows=1; fits_info.rows=1; fits_info.number_planes=1; fits_info.min_data=0.0; fits_info.max_data=0.0; fits_info.zero=0.0; fits_info.scale=1.0; fits_info.endian=MSBEndian; /* Decode image header. */ for (comment=(char *) NULL; EOFBlob(image) == MagickFalse; ) { for ( ; EOFBlob(image) == MagickFalse; ) { register char *p; count=ReadBlob(image,8,(unsigned char *) keyword); if (count != 8) break; for (i=0; i < 8; i++) { if (isspace((int) ((unsigned char) keyword[i])) != 0) break; keyword[i]=tolower((int) ((unsigned char) keyword[i])); } keyword[i]='\0'; count=ReadBlob(image,72,(unsigned char *) value); if (count != 72) break; value[72]='\0'; p=value; if (*p == '=') { p+=2; while (isspace((int) ((unsigned char) *p)) != 0) p++; } if (LocaleCompare(keyword,"end") == 0) break; if (LocaleCompare(keyword,"extend") == 0) fits_info.extend=(*p == 'T') || (*p == 't') ? MagickTrue : MagickFalse; if (LocaleCompare(keyword,"simple") == 0) fits_info.simple=(*p == 'T') || (*p == 't') ? MagickTrue : MagickFalse; if (LocaleCompare(keyword,"bitpix") == 0) fits_info.bits_per_pixel=StringToLong(p); if (LocaleCompare(keyword,"naxis") == 0) fits_info.number_axes=StringToLong(p); if (LocaleCompare(keyword,"naxis1") == 0) fits_info.columns=StringToLong(p); if (LocaleCompare(keyword,"naxis2") == 0) fits_info.rows=StringToLong(p); if (LocaleCompare(keyword,"naxis3") == 0) fits_info.number_planes=StringToLong(p); if (LocaleCompare(keyword,"datamax") == 0) fits_info.max_data=InterpretLocaleValue(p,(char **) NULL); if (LocaleCompare(keyword,"datamin") == 0) fits_info.min_data=InterpretLocaleValue(p,(char **) NULL); if (LocaleCompare(keyword,"bzero") == 0) fits_info.zero=InterpretLocaleValue(p,(char **) NULL); if (LocaleCompare(keyword,"bscale") == 0) fits_info.scale=InterpretLocaleValue(p,(char **) NULL); if (LocaleCompare(keyword,"comment") == 0) { if (comment == (char *) NULL) comment=ConstantString(p); else (void) ConcatenateString(&comment,p); } if (LocaleCompare(keyword,"xendian") == 0) { if (LocaleNCompare(p,"big",3) == 0) fits_info.endian=MSBEndian; else fits_info.endian=LSBEndian; } (void) FormatLocaleString(property,MaxTextExtent,"fits:%s",keyword); (void) SetImageProperty(image,property,p); } c=0; while (((TellBlob(image) % FITSBlocksize) != 0) && (c != EOF)) c=ReadBlobByte(image); if (fits_info.extend == MagickFalse) break; number_pixels=(MagickSizeType) fits_info.columns*fits_info.rows; if ((fits_info.simple != MagickFalse) && (fits_info.number_axes >= 1) && (fits_info.number_axes <= 4) && (number_pixels != 0)) break; } /* Verify that required image information is defined. */ if (comment != (char *) NULL) { (void) SetImageProperty(image,"comment",comment); comment=DestroyString(comment); } if (EOFBlob(image) != MagickFalse) ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", image->filename); number_pixels=(MagickSizeType) fits_info.columns*fits_info.rows; if ((fits_info.simple == MagickFalse) || (fits_info.number_axes < 1) || (fits_info.number_axes > 4) || (number_pixels == 0)) ThrowReaderException(CorruptImageError,"ImageTypeNotSupported"); for (scene=0; scene < (ssize_t) fits_info.number_planes; scene++) { image->columns=(size_t) fits_info.columns; image->rows=(size_t) fits_info.rows; image->depth=(size_t) (fits_info.bits_per_pixel < 0 ? -1 : 1)* fits_info.bits_per_pixel; image->endian=fits_info.endian; image->scene=(size_t) scene; if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) if (image->scene >= (image_info->scene+image_info->number_scenes-1)) break; /* Initialize image structure. */ if ((fits_info.min_data != 0.0) || (fits_info.max_data != 0.0)) { if ((fits_info.bits_per_pixel != 0) && (fits_info.max_data == 0.0)) fits_info.max_data=GetFITSPixelRange((size_t) fits_info.bits_per_pixel); } else GetFITSPixelExtrema(image,fits_info.bits_per_pixel,&fits_info.min_data, &fits_info.max_data); /* Convert FITS pixels to pixel packets. */ scale=(double) QuantumRange/(fits_info.scale*(fits_info.max_data- fits_info.min_data)+fits_info.zero); for (y=(ssize_t) image->rows-1; y >= 0; y--) { q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); if (q == (PixelPacket *) NULL) break; for (x=0; x < (ssize_t) image->columns; x++) { pixel=GetFITSPixel(image,fits_info.bits_per_pixel); SetPixelRed(q,ClampToQuantum(scale*(fits_info.scale*(pixel- fits_info.min_data)+fits_info.zero))); SetPixelGreen(q,GetPixelRed(q)); SetPixelBlue(q,GetPixelRed(q)); q++; } if (SyncAuthenticPixels(image,exception) == MagickFalse) break; if (image->previous == (Image *) NULL) { status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, image->rows); if (status == MagickFalse) break; } } if (EOFBlob(image) != MagickFalse) { ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile", image->filename); break; } /* Proceed to next image. */ if (image_info->number_scenes != 0) if (image->scene >= (image_info->scene+image_info->number_scenes-1)) break; if (scene < (ssize_t) (fits_info.number_planes-1)) { /* Allocate next image structure. */ AcquireNextImage(image_info,image); if (GetNextImageInList(image) == (Image *) NULL) { image=DestroyImageList(image); return((Image *) NULL); } image=SyncNextImageInList(image); status=SetImageProgress(image,LoadImagesTag,TellBlob(image), GetBlobSize(image)); if (status == MagickFalse) break; } } (void) CloseBlob(image); return(GetFirstImageInList(image)); }
static MagickBooleanType GetPathTemplate(char *path) { char *directory; ExceptionInfo *exception; MagickBooleanType status; register char *p; struct stat attributes; (void) CopyMagickString(path,"magick-XXXXXXXX",MaxTextExtent); exception=AcquireExceptionInfo(); directory=(char *) GetImageRegistry(StringRegistryType,"temporary-path", exception); exception=DestroyExceptionInfo(exception); if (directory == (char *) NULL) directory=GetEnvironmentValue("MAGICK_TEMPORARY_PATH"); if (directory == (char *) NULL) directory=GetEnvironmentValue("MAGICK_TMPDIR"); if (directory == (char *) NULL) directory=GetPolicyValue("temporary-path"); if (directory == (char *) NULL) directory=GetEnvironmentValue("TMPDIR"); #if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__OS2__) if (directory == (char *) NULL) directory=GetEnvironmentValue("TMP"); if (directory == (char *) NULL) directory=GetEnvironmentValue("TEMP"); #endif #if defined(__VMS) if (directory == (char *) NULL) directory=GetEnvironmentValue("MTMPDIR"); #endif #if defined(P_tmpdir) if (directory == (char *) NULL) directory=ConstantString(P_tmpdir); #endif if (directory == (char *) NULL) return(MagickTrue); if (strlen(directory) > (MaxTextExtent-15)) { directory=DestroyString(directory); return(MagickTrue); } status=GetPathAttributes(directory,&attributes); if ((status == MagickFalse) || !S_ISDIR(attributes.st_mode)) { directory=DestroyString(directory); return(MagickTrue); } if (directory[strlen(directory)-1] == *DirectorySeparator) (void) FormatLocaleString(path,MaxTextExtent,"%smagick-XXXXXXXX",directory); else (void) FormatLocaleString(path,MaxTextExtent,"%s%smagick-XXXXXXXX", directory,DirectorySeparator); directory=DestroyString(directory); if (*DirectorySeparator != '/') for (p=path; *p != '\0'; p++) if (*p == *DirectorySeparator) *p='/'; return(MagickTrue); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e g i s t e r R G B I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RegisterRGBImage() adds attributes for the RGB or RGBA image format to % the list of supported formats. The attributes include the image format % tag, a method to read and/or write the format, whether the format % supports the saving of more than one frame to the same file or blob, % whether the format supports native in-memory I/O, and a brief % description of the format. % % The format of the RegisterRGBImage method is: % % unsigned long RegisterRGBImage(void) % */ ModuleExport unsigned long RegisterRGBImage(void) { MagickInfo *entry; entry=SetMagickInfo("RGB"); entry->decoder=(DecodeImageHandler *) ReadRGBImage; entry->encoder=(EncodeImageHandler *) WriteRGBImage; entry->raw=MagickTrue; entry->endian_support=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Raw red, green, and blue samples"); entry->module=ConstantString("RGB"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("RBG"); entry->decoder=(DecodeImageHandler *) ReadRGBImage; entry->encoder=(EncodeImageHandler *) WriteRGBImage; entry->raw=MagickTrue; entry->endian_support=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Raw red, blue, and green samples"); entry->module=ConstantString("RGB"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("GRB"); entry->decoder=(DecodeImageHandler *) ReadRGBImage; entry->encoder=(EncodeImageHandler *) WriteRGBImage; entry->raw=MagickTrue; entry->endian_support=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Raw green, red, and blue samples"); entry->module=ConstantString("RGB"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("GBR"); entry->decoder=(DecodeImageHandler *) ReadRGBImage; entry->encoder=(EncodeImageHandler *) WriteRGBImage; entry->raw=MagickTrue; entry->endian_support=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Raw green, blue, and red samples"); entry->module=ConstantString("RGB"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("BRG"); entry->decoder=(DecodeImageHandler *) ReadRGBImage; entry->encoder=(EncodeImageHandler *) WriteRGBImage; entry->raw=MagickTrue; entry->endian_support=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Raw blue, red, and green samples"); entry->module=ConstantString("RGB"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("BGR"); entry->decoder=(DecodeImageHandler *) ReadRGBImage; entry->encoder=(EncodeImageHandler *) WriteRGBImage; entry->raw=MagickTrue; entry->endian_support=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Raw blue, green, and red samples"); entry->module=ConstantString("RGB"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("RGBA"); entry->decoder=(DecodeImageHandler *) ReadRGBImage; entry->encoder=(EncodeImageHandler *) WriteRGBImage; entry->raw=MagickTrue; entry->endian_support=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Raw red, green, blue, and alpha samples"); entry->module=ConstantString("RGB"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("RGBO"); entry->decoder=(DecodeImageHandler *) ReadRGBImage; entry->encoder=(EncodeImageHandler *) WriteRGBImage; entry->raw=MagickTrue; entry->endian_support=MagickTrue; entry->format_type=ExplicitFormatType; entry->description=ConstantString("Raw red, green, blue, and opacity " "samples"); entry->module=ConstantString("RGB"); (void) RegisterMagickInfo(entry); return(MagickImageCoderSignature); }
static MagickBooleanType LoadCoderList(const char *xml,const char *filename, const unsigned long depth,ExceptionInfo *exception) { char keyword[MaxTextExtent], *q, *token; CoderInfo *coder_info = (CoderInfo *) NULL; MagickBooleanType status; /* Load the coder map file. */ (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), "Loading coder file \"%s\" ...",filename); if (xml == (const char *) NULL) return(MagickFalse); if (coder_list == (SplayTreeInfo *) NULL) { coder_list=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, DestroyCoderNode); if (coder_list == (SplayTreeInfo *) NULL) { ThrowFileException(exception,ResourceLimitError, "MemoryAllocationFailed",filename); return(MagickFalse); } } status=MagickTrue; token=AcquireString(xml); for (q=(char *) xml; *q != '\0'; ) { /* Interpret XML. */ GetMagickToken(q,&q,token); if (*token == '\0') break; (void) CopyMagickString(keyword,token,MaxTextExtent); if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0) { /* Doctype element. */ while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0')) GetMagickToken(q,&q,token); continue; } if (LocaleNCompare(keyword,"<!--",4) == 0) { /* Comment element. */ while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0')) GetMagickToken(q,&q,token); continue; } if (LocaleCompare(keyword,"<include") == 0) { /* Include element. */ while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0')) { (void) CopyMagickString(keyword,token,MaxTextExtent); GetMagickToken(q,&q,token); if (*token != '=') continue; GetMagickToken(q,&q,token); if (LocaleCompare(keyword,"file") == 0) { if (depth > 200) (void) ThrowMagickException(exception,GetMagickModule(), ConfigureError,"IncludeNodeNestedTooDeeply","`%s'",token); else { char path[MaxTextExtent], *xml; GetPathComponent(filename,HeadPath,path); if (*path != '\0') (void) ConcatenateMagickString(path,DirectorySeparator, MaxTextExtent); (void) ConcatenateMagickString(path,token,MaxTextExtent); xml=FileToString(path,~0,exception); if (LoadCoderList(xml,path,depth+1,exception) == MagickFalse) status=MagickFalse; xml=(char *) RelinquishMagickMemory(xml); } } } continue; } if (LocaleCompare(keyword,"<coder") == 0) { /* Allocate memory for the coder list. */ coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info)); if (coder_info == (CoderInfo *) NULL) ThrowMagickFatalException(ResourceLimitFatalError, "MemoryAllocationFailed",filename); (void) ResetMagickMemory(coder_info,0,sizeof(*coder_info)); coder_info->path=ConstantString(AcquireString(filename)); coder_info->signature=MagickSignature; continue; } if (coder_info == (CoderInfo *) NULL) continue; if (LocaleCompare(keyword,"/>") == 0) { status=AddValueToSplayTree(coder_list, ConstantString(AcquireString(coder_info->magick)),coder_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'", coder_info->magick); coder_info=(CoderInfo *) NULL; } GetMagickToken(q,(char **) NULL,token); if (*token != '=') continue; GetMagickToken(q,&q,token); GetMagickToken(q,&q,token); switch (*keyword) { case 'M': case 'm': { if (LocaleCompare((char *) keyword,"magick") == 0) { coder_info->magick=ConstantString(AcquireString(token)); break; } break; } case 'N': case 'n': { if (LocaleCompare((char *) keyword,"name") == 0) { coder_info->name=ConstantString(AcquireString(token)); break; } break; } case 'S': case 's': { if (LocaleCompare((char *) keyword,"stealth") == 0) { coder_info->stealth=(MagickBooleanType) (LocaleCompare(token,"True") == 0); break; } break; } default: break; } } token=(char *) RelinquishMagickMemory(token); if (coder_list == (SplayTreeInfo *) NULL) return(MagickFalse); return(status); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e g i s t e r X T R N I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RegisterXTRNImage() adds attributes for the XTRN image format to % the list of supported formats. The attributes include the image format % tag, a method to read and/or write the format, whether the format % supports the saving of more than one frame to the same file or blob, % whether the format supports native in-memory I/O, and a brief % description of the format. % % The format of the RegisterXTRNImage method is: % % RegisterXTRNImage(void) % */ ModuleExport void RegisterXTRNImage(void) { MagickInfo *entry; entry=SetMagickInfo("XTRNFILE"); entry->decoder=ReadXTRNImage; entry->encoder=WriteXTRNImage; entry->adjoin=MagickFalse; entry->stealth=MagickTrue; entry->description=ConstantString("External transfer of a file"); entry->module=ConstantString("XTRN"); RegisterMagickInfo(entry); entry=SetMagickInfo("XTRNIMAGE"); entry->decoder=ReadXTRNImage; entry->encoder=WriteXTRNImage; entry->adjoin=MagickFalse; entry->stealth=MagickTrue; entry->description=ConstantString("External transfer of a image in memory"); entry->module=ConstantString("XTRN"); RegisterMagickInfo(entry); entry=SetMagickInfo("XTRNBLOB"); entry->decoder=ReadXTRNImage; entry->encoder=WriteXTRNImage; entry->adjoin=MagickFalse; entry->stealth=MagickTrue; entry->description=ConstantString("IExternal transfer of a blob in memory"); entry->module=ConstantString("XTRN"); RegisterMagickInfo(entry); entry=SetMagickInfo("XTRNSTREAM"); entry->decoder=ReadXTRNImage; entry->encoder=WriteXTRNImage; entry->adjoin=MagickFalse; entry->stealth=MagickTrue; entry->description=ConstantString("External transfer via a streaming interface"); entry->module=ConstantString("XTRN"); RegisterMagickInfo(entry); entry=SetMagickInfo("XTRNARRAY"); entry->decoder=ReadXTRNImage; entry->encoder=WriteXTRNImage; entry->adjoin=MagickFalse; entry->stealth=MagickTrue; entry->description=ConstantString("External transfer via a smart array interface"); entry->module=ConstantString("XTRN"); RegisterMagickInfo(entry); entry=SetMagickInfo("XTRNBSTR"); entry->decoder=ReadXTRNImage; entry->encoder=WriteXTRNImage; entry->adjoin=MagickFalse; entry->stealth=MagickTrue; entry->description=ConstantString("External transfer via a smart array interface"); entry->module=ConstantString("XTRN"); RegisterMagickInfo(entry); }