/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t M o n t a g e I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetMontageInfo() initializes montage_info to default values. % % The format of the GetMontageInfo method is: % % void GetMontageInfo(const ImageInfo *image_info, % MontageInfo *montage_info) % % A description of each parameter follows: % % o image_info: a structure of type ImageInfo. % % o montage_info: Specifies a pointer to a MontageInfo structure. % */ MagickExport void GetMontageInfo(const ImageInfo *image_info, MontageInfo *montage_info) { assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickCoreSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(montage_info != (MontageInfo *) NULL); (void) ResetMagickMemory(montage_info,0,sizeof(*montage_info)); (void) CopyMagickString(montage_info->filename,image_info->filename, MagickPathExtent); montage_info->geometry=AcquireString(DefaultTileGeometry); if (image_info->font != (char *) NULL) montage_info->font=AcquireString(image_info->font); montage_info->gravity=CenterGravity; montage_info->pointsize=image_info->pointsize; montage_info->fill.alpha=OpaqueAlpha; montage_info->stroke.alpha=(Quantum) TransparentAlpha; montage_info->matte_color=image_info->matte_color; montage_info->background_color=image_info->background_color; montage_info->border_color=image_info->border_color; montage_info->debug=IsEventLogging(); montage_info->signature=MagickCoreSignature; }
/* * Class: magick_ImageInfo * Method: setImageOption * Signature: (Ljava/lang/String;Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_magick_ImageInfo_setImageOption (JNIEnv *env, jobject self, jstring option, jstring value) { ImageInfo *info = NULL; const char *cstr1 = NULL; const char *cstr2 = NULL; info = (ImageInfo *) getHandle(env, self, "imageInfoHandle", NULL); if (info == NULL) { throwMagickException(env, "Unable to retrieve handle"); return; } cstr1 = (*env)->GetStringUTFChars(env, option, 0); if (cstr1 == NULL) { throwMagickException(env, "Unable to retrieve Java string chars"); return; } cstr2 = (*env)->GetStringUTFChars(env, value, 0); if (cstr2 == NULL) { throwMagickException(env, "Unable to retrieve Java string chars"); return; } SetImageOption(info, (char *)AcquireString(cstr1), (char *)AcquireString(cstr2)); (*env)->ReleaseStringUTFChars(env, option, cstr1); (*env)->ReleaseStringUTFChars(env, value, cstr2); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e g i s t e r F A X I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RegisterFAXImage() adds attributes for the FAX 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 RegisterFAXImage method is: % % RegisterFAXImage(void) % */ ModuleExport void RegisterFAXImage(void) { MagickInfo *entry; static const char *Note= { "See TIFF format. Note that FAX machines use non-square pixels which\n" "are 1.5 times wider than they are tall but computer displays use\n" "square pixels. FAX images may appear to be narrow unless they are\n" "explicitly resized using a resize specification of \"150x100%\"." }; entry=SetMagickInfo("FAX"); entry->decoder=(DecoderHandler *) ReadFAXImage; entry->encoder=(EncoderHandler *) WriteFAXImage; entry->magick=(MagickHandler *) IsFAX; entry->description=AcquireString("Group 3 FAX"); entry->note=AcquireString(Note); entry->module=AcquireString("FAX"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("G3"); entry->decoder=(DecoderHandler *) ReadFAXImage; entry->encoder=(EncoderHandler *) WriteFAXImage; entry->magick=(MagickHandler *) IsFAX; entry->adjoin=MagickFalse; entry->description=AcquireString("Group 3 FAX"); entry->module=AcquireString("FAX"); (void) RegisterMagickInfo(entry); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e g i s t e r S T E G A N O I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RegisterSTEGANOImage() adds attributes for the STEGANO 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 RegisterSTEGANOImage method is: % % RegisterSTEGANOImage(void) % */ ModuleExport void RegisterSTEGANOImage(void) { MagickInfo *entry; entry=SetMagickInfo("STEGANO"); entry->decoder=(DecoderHandler *) ReadSTEGANOImage; entry->description=AcquireString("Steganographic image"); entry->module=AcquireString("STEGANO"); (void) RegisterMagickInfo(entry); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e g i s t e r C I P I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RegisterCIPImage() adds attributes for the CIP IP phone 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 RegisterCIPImage method is: % % RegisterCIPImage(void) % */ ModuleExport void RegisterCIPImage(void) { MagickInfo *entry; entry=SetMagickInfo("CIP"); entry->encoder=(EncoderHandler *) WriteCIPImage; entry->adjoin=MagickFalse; entry->description=AcquireString("Cisco IP phone image format"); entry->module=AcquireString("CIP"); (void) RegisterMagickInfo(entry); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e g i s t e r T I L E I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RegisterTILEImage() adds attributes for the TILE 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 RegisterTILEImage method is: % % RegisterTILEImage(void) % */ ModuleExport void RegisterTILEImage(void) { MagickInfo *entry; entry=SetMagickInfo("TILE"); entry->decoder=(DecoderHandler *) ReadTILEImage; entry->raw=MagickTrue; entry->endian_support=MagickTrue; entry->description=AcquireString("Tile image with a texture"); entry->module=AcquireString("TILE"); (void) RegisterMagickInfo(entry); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e g i s t e r M V G I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RegisterMVGImage() adds attributes for the MVG 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 RegisterMVGImage method is: % % RegisterMVGImage(void) % */ ModuleExport void RegisterMVGImage(void) { MagickInfo *entry; entry=SetMagickInfo("MVG"); entry->decoder=(DecoderHandler *) ReadMVGImage; entry->encoder=(EncoderHandler *) WriteMVGImage; entry->magick=(MagickHandler *) IsMVG; entry->adjoin=MagickFalse; entry->seekable_stream=MagickTrue; entry->description=AcquireString("Magick Vector Graphics"); entry->module=AcquireString("MVG"); (void) RegisterMagickInfo(entry); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e g i s t e r P L A S M A I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RegisterPLASMAImage() adds attributes for the Plasma 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 RegisterPLASMAImage method is: % % RegisterPLASMAImage(void) % */ ModuleExport void RegisterPLASMAImage(void) { MagickInfo *entry; entry=SetMagickInfo("PLASMA"); entry->decoder=(DecoderHandler *) ReadPlasmaImage; entry->adjoin=MagickFalse; entry->description=AcquireString("Plasma fractal image"); entry->module=AcquireString("PLASMA"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("FRACTAL"); entry->decoder=(DecoderHandler *) ReadPlasmaImage; entry->adjoin=MagickFalse; entry->description=AcquireString("Plasma fractal image"); entry->module=AcquireString("PLASMA"); (void) RegisterMagickInfo(entry); }
/* * Set a attribute in a generic handle to string. * * Input: * env Java VM environment * attribVar points to a C string so as to set the value * jstr Java string for which to set the attrib * * Output: * attribVar points to a new C string with content from jstr */ void setHandleAttribute(JNIEnv *env, char **attribVar, jstring jstr) { const char *cstr = NULL; if (*attribVar != NULL) { // RelinquishMagickMemory((void**)attribVar); } cstr = (*env)->GetStringUTFChars(env, jstr, 0); *attribVar = (char *) AcquireString(cstr); (*env)->ReleaseStringUTFChars(env, jstr, cstr); }
MagickExport void ThrowException(ExceptionInfo *exception, const ExceptionType severity,const char *reason,const char *description) { assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); exception->severity=(ExceptionType) severity; MagickFreeMemory(exception->reason); if (reason) exception->reason= AcquireString(GetLocaleExceptionMessage(severity,reason)); MagickFreeMemory(exception->description); if (description) exception->description= AcquireString(GetLocaleExceptionMessage(severity,description)); exception->error_number=errno; MagickFreeMemory(exception->module); MagickFreeMemory(exception->function); exception->line=0UL; exception->signature=0UL; return; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e g i s t e r M P E G I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RegisterMPEGImage() adds attributes for the MPEG 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 RegisterMPEGImage method is: % % RegisterMPEGImage(void) % */ ModuleExport void RegisterMPEGImage(void) { MagickInfo *entry; entry=SetMagickInfo("MPEG"); entry->decoder=(DecoderHandler *) ReadMPEGImage; entry->encoder=(EncoderHandler *) WriteMPEGImage; entry->magick=(MagickHandler *) IsMPEG; entry->blob_support=MagickFalse; entry->description=AcquireString("MPEG Video Stream"); entry->module=AcquireString("MPEG"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("MPG"); entry->decoder=(DecoderHandler *) ReadMPEGImage; entry->encoder=(EncoderHandler *) WriteMPEGImage; entry->magick=(MagickHandler *) IsMPEG; entry->blob_support=MagickFalse; entry->description=AcquireString("MPEG Video Stream"); entry->module=AcquireString("MPEG"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("M2V"); entry->decoder=(DecoderHandler *) ReadMPEGImage; entry->encoder=(EncoderHandler *) WriteMPEGImage; entry->magick=(MagickHandler *) IsMPEG; entry->blob_support=MagickFalse; entry->description=AcquireString("MPEG Video Stream"); entry->module=AcquireString("MPEG"); (void) RegisterMagickInfo(entry); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e g i s t e r R G B I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RegisterRGBImage() adds attributes for the RGB 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: % % RegisterRGBImage(void) % */ ModuleExport void RegisterRGBImage(void) { MagickInfo *entry; entry=SetMagickInfo("RGB"); entry->decoder=(DecoderHandler *) ReadRGBImage; entry->encoder=(EncoderHandler *) WriteRGBImage; entry->raw=MagickTrue; entry->endian_support=MagickTrue; entry->description=AcquireString("Raw red, green, and blue samples"); entry->module=AcquireString("RGB"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("RGBA"); entry->decoder=(DecoderHandler *) ReadRGBImage; entry->encoder=(EncoderHandler *) WriteRGBImage; entry->raw=MagickTrue; entry->endian_support=MagickTrue; entry->description=AcquireString("Raw red, green, blue, and alpha samples"); entry->module=AcquireString("RGB"); (void) RegisterMagickInfo(entry); entry=SetMagickInfo("RGBO"); entry->decoder=(DecoderHandler *) ReadRGBImage; entry->encoder=(EncoderHandler *) WriteRGBImage; entry->raw=MagickTrue; entry->endian_support=MagickTrue; entry->description=AcquireString("Raw red, green, blue, and opacity samples"); entry->module=AcquireString("RGB"); (void) RegisterMagickInfo(entry); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % T h r o w L o g g e d E x c e p t i o n % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ThrowLoggedException() throws an exception with the specified severity code, % reason, optional description, source filename, function name, and line % number. If logging is enabled, the exception is also logged. % % The format of the ThrowLoggedException method is: % % void ThrowLoggedException(ExceptionInfo *exception, % const ExceptionType severity,const char *reason, % const char *description,const char *module, % const char *function,const unsigned long line % % A description of each parameter follows: % % o exception: The exception. % % o severity: The severity of the exception. % % o reason: The reason of the exception. % % o description: The exception description. % % o filename: The source module filename. % % o function: The function name. % % o line: The line number of the source module. % % */ MagickExport void ThrowLoggedException(ExceptionInfo *exception, const ExceptionType severity,const char *reason,const char *description, const char *module,const char *function,const unsigned long line) { assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); exception->severity=(ExceptionType) severity; MagickFreeMemory(exception->reason); if (reason) exception->reason= AcquireString(GetLocaleExceptionMessage(severity,reason)); MagickFreeMemory(exception->description); if (description) exception->description= AcquireString(GetLocaleExceptionMessage(severity,description)); exception->error_number=errno; MagickFreeMemory(exception->module); if (module) exception->module=AcquireString(module); MagickFreeMemory(exception->function); if (function) exception->function=AcquireString(function); exception->line=line; if (exception->reason) { if (exception->description) (void) LogMagickEvent(severity,module,function,line,"%.1024s (%.1024s)", exception->reason,exception->description ); else (void) LogMagickEvent(severity,module,function,line,"%.1024s", exception->reason); } else { (void) LogMagickEvent(severity,module,function,line, "exception contains no reason!"); } return; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % C o p y E x c e p t i o n % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % CopyException() copies exception data from one ExceptionInfo structure % to another. % % The format of the CopyException method is: % % void CopyException(ExceptionInfo *copy, const ExceptionInfo *original) % % A description of each parameter follows: % % o copy: The exception to copy to. % % o original: The exception to copy from. % */ MagickExport void CopyException(ExceptionInfo *copy, const ExceptionInfo *original) { assert(copy != (ExceptionInfo *) NULL); assert(copy->signature == MagickSignature); assert(original != (ExceptionInfo *) NULL); assert(original->signature == MagickSignature); copy->severity=original->severity; MagickFreeMemory(copy->reason); if (original->reason) copy->reason=AcquireString(original->reason); MagickFreeMemory(copy->description); if (original->description) copy->description=AcquireString(original->description); copy->error_number=original->error_number; MagickFreeMemory(copy->module); if (original->module) copy->module=AcquireString(original->module); MagickFreeMemory(copy->function); if (original->function) copy->function=AcquireString(original->function); copy->line=original->line; return; }
static bool HHVM_METHOD(ImagickDraw, setResolution, double x, double y) { auto wand = getDrawingWandResource(Object{this_}); std::ostringstream density; density << x << "x" << y; auto drawInfo = PeekDrawingWand(wand->getWand()); drawInfo->density = AcquireString(density.str().c_str()); auto drawWand = DrawAllocateWand(drawInfo, nullptr); if (drawWand == nullptr) { IMAGICKDRAW_THROW("Failed to allocate new DrawingWand structure"); } setWandResource(s_ImagickDraw, Object{this_}, drawWand); return true; }
/* * Retrieve the string value of the specified field. * * Input: * env Java VM environment. * obj Java object for which the value is to be retrieved. * fieldName name of the field to be retrieved. * fieldID if non-null, points to field ID. 0 to request retrieval. * * Output: * fieldID if non-null, will contain the field ID. * * Return: * The string value requested. The caller is responsible for * deallocating this string. */ char* getStringFieldValue(JNIEnv *env, jobject obj, const char *fieldName, jfieldID *fieldID) { jclass objClass = 0; jfieldID objFieldID = 0; jobject stringObj = 0; char *stringVal = NULL; char *stringCpy = NULL; if (fieldID == NULL) { objClass = (*env)->GetObjectClass(env, obj); if (objClass == 0) { return NULL; } objFieldID = (*env)->GetFieldID(env, objClass, fieldName, "Ljava/lang/String;"); } else if (*fieldID == 0) { objClass = (*env)->GetObjectClass(env, obj); if (objClass == 0) { return NULL; } objFieldID = *fieldID = (*env)->GetFieldID(env, objClass, fieldName, "Ljava/lang/String;"); } else { objFieldID = *fieldID; } if (objFieldID == 0) { return NULL; } stringObj = (*env)->GetObjectField(env, obj, objFieldID); if (stringObj == NULL) { return NULL; } stringVal = (char *) (*env)->GetStringUTFChars(env, stringObj, 0); stringCpy = (char *) AcquireString(stringVal); (*env)->ReleaseStringUTFChars(env, stringObj, stringVal); return stringCpy; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % M a g i c k Q u e r y C o n f i g u r e O p t i o n % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % MagickQueryConfigureOption() returns the value associated with the specified % configure option. % % The format of the MagickQueryConfigureOption function is: % % char *MagickQueryConfigureOption(const char *option) % % A description of each parameter follows: % % o option: the option name. % */ WandExport char *MagickQueryConfigureOption(const char *option) { char *value; const ConfigureInfo **configure_info; ExceptionInfo *exception; size_t number_options; exception=AcquireExceptionInfo(); configure_info=GetConfigureInfoList(option,&number_options,exception); exception=DestroyExceptionInfo(exception); if (configure_info == (const ConfigureInfo **) NULL) return((char *) NULL); value=AcquireString(configure_info[0]->value); configure_info=(const ConfigureInfo **) RelinquishMagickMemory((void *) configure_info); return(value); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % C l o n e M o n t a g e I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % CloneMontageInfo() makes a copy of the given montage info structure. If % NULL is specified, a new image info structure is created initialized to % default values. % % The format of the CloneMontageInfo method is: % % MontageInfo *CloneMontageInfo(const ImageInfo *image_info, % const MontageInfo *montage_info) % % A description of each parameter follows: % % o image_info: the image info. % % o montage_info: the montage info. % */ MagickExport MontageInfo *CloneMontageInfo(const ImageInfo *image_info, const MontageInfo *montage_info) { MontageInfo *clone_info; clone_info=(MontageInfo *) AcquireMagickMemory(sizeof(*clone_info)); if (clone_info == (MontageInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); GetMontageInfo(image_info,clone_info); if (montage_info == (MontageInfo *) NULL) return(clone_info); if (montage_info->geometry != (char *) NULL) clone_info->geometry=AcquireString(montage_info->geometry); if (montage_info->tile != (char *) NULL) clone_info->tile=AcquireString(montage_info->tile); if (montage_info->title != (char *) NULL) clone_info->title=AcquireString(montage_info->title); if (montage_info->frame != (char *) NULL) clone_info->frame=AcquireString(montage_info->frame); if (montage_info->texture != (char *) NULL) clone_info->texture=AcquireString(montage_info->texture); if (montage_info->font != (char *) NULL) clone_info->font=AcquireString(montage_info->font); clone_info->pointsize=montage_info->pointsize; clone_info->border_width=montage_info->border_width; clone_info->shadow=montage_info->shadow; clone_info->fill=montage_info->fill; clone_info->stroke=montage_info->stroke; clone_info->background_color=montage_info->background_color; clone_info->border_color=montage_info->border_color; clone_info->matte_color=montage_info->matte_color; clone_info->gravity=montage_info->gravity; (void) CopyMagickString(clone_info->filename,montage_info->filename, MagickPathExtent); clone_info->debug=IsEventLogging(); return(clone_info); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + 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); }
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); }
int main(int argc, char **argv) { char *xml; const char *acronym, *data_type, *description, *endian, *mask, *mime_type, *offset, *pattern, *priority, *match_type, *value; ExceptionInfo *exception; size_t length; static char *doc_type = { "<!DOCTYPE mimemap [\n" " <!ELEMENT mimemap (mime+)>\n" " <!ELEMENT mime (#PCDATA)>\n" " <!ATTLIST mime type CDATA #REQUIRED>\n" " <!ATTLIST mime acronym CDATA #IMPLIED>\n" " <!ATTLIST mime description CDATA #IMPLIED>\n" " <!ATTLIST mime pattern CDATA #IMPLIED>\n" " <!ATTLIST mime offset CDATA #IMPLIED>\n" " <!ATTLIST mime data-type (string|byte|short|ssize_t) #IMPLIED>\n" " <!ATTLIST mime endian (lsb|msb) #IMPLIED>\n" " <!ATTLIST mime magic CDATA #IMPLIED>\n" " <!ATTLIST mime mask CDATA #IMPLIED>\n" " <!ATTLIST mime priority CDATA #IMPLIED>\n" "]>" }; XMLTreeInfo *comment, *expanded_acronym, *glob, *magic, *match, *type, *xml_info; if (argc != 2) return(fprintf(stderr,"usage: %s xml-file\n", argv[0])); exception=AcquireExceptionInfo(); xml=(char *) FileToBlob(argv[1],~0UL,&length,exception); if (xml == (char *) NULL) return(fprintf(stderr,"%s: unable to read file\n",argv[1])); xml_info=NewXMLTree(xml,exception); xml=(char *) RelinquishWizardMemory(xml); if (xml_info == (XMLTreeInfo *) NULL) return(fprintf(stderr,"%s: unable to parse xml-file\n",argv[1])); (void) printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); (void) printf("%s\n",doc_type); (void) printf("<mimemap>\n"); type=GetXMLTreeChild(xml_info,"mime-type"); while (type != (XMLTreeInfo *) NULL) { mime_type=GetXMLTreeAttribute(type,"type"); acronym=(const char *) NULL; expanded_acronym=GetXMLTreeChild(type,"acronym"); if (expanded_acronym != (XMLTreeInfo *) NULL) acronym=GetXMLTreeContent(expanded_acronym); expanded_acronym=GetXMLTreeChild(type,"expanded-acronym"); description=(const char *) NULL; comment=GetXMLTreeChild(type,"comment"); if (comment != (XMLTreeInfo *) NULL) description=GetXMLTreeContent(comment); if (expanded_acronym != (XMLTreeInfo *) NULL) description=GetXMLTreeContent(expanded_acronym); magic=GetXMLTreeChild(type,"magic"); priority=(char *) NULL; match=(XMLTreeInfo *) NULL; if (magic != (XMLTreeInfo *) NULL) { priority=GetXMLTreeAttribute(magic,"priority"); match=GetXMLTreeChild(magic,"match"); } while (match != (XMLTreeInfo *) NULL) { value=(char *) NULL; match_type=(char *) NULL; mask=(char *) NULL; offset=(char *) NULL; if (match != (XMLTreeInfo *) NULL) { value=GetXMLTreeAttribute(match,"value"); match_type=GetXMLTreeAttribute(match,"type"); offset=GetXMLTreeAttribute(match,"offset"); mask=GetXMLTreeAttribute(match,"mask"); } (void) printf(" <mime"); if (mime_type != (const char *) NULL) (void) printf(" type=\"%s\"",mime_type); if (description != (const char *) NULL) (void) printf(" description=\"%s\"",description); if (match_type != (const char *) NULL) { data_type="string"; endian="undefined"; if (strncmp(match_type,"little",6) == 0) endian="LSB"; if (strncmp(match_type,"big",3) == 0) endian="MSB"; if (strcmp(match_type,"byte") == 0) data_type="byte"; if (strcmp(match_type+strlen(match_type)-2,"16") == 0) data_type="short"; if (strcmp(match_type+strlen(match_type)-2,"32") == 0) data_type="ssize_t"; (void) printf(" data-type=\"%s\"",data_type); if (strcmp(endian,"undefined") != 0) (void) printf(" endian=\"%s\"",endian); } if (offset != (const char *) NULL) (void) printf(" offset=\"%s\"",offset); if (mask != (const char *) NULL) (void) printf(" mask=\"%s\"",mask); if (value != (const char *) NULL) { char *magic; magic=AcquireString(value); SubstituteString(&magic,"<","<"); SubstituteString(&magic,">",">"); SubstituteString(&magic,"\"","""); (void) printf(" magic=\"%s\"",magic); magic=(char *) RelinquishWizardMemory(magic); } if (priority != (const char *) NULL) (void) printf(" priority=\"%s\"",priority); (void) printf(" />\n"); match=GetNextXMLTreeTag(match); } glob=GetXMLTreeChild(type,"glob"); while (glob != (XMLTreeInfo *) NULL) { pattern=GetXMLTreeAttribute(glob,"pattern"); value=(char *) NULL; if (match) value=GetXMLTreeAttribute(match,"value"); (void) printf(" <mime"); if (mime_type != (const char *) NULL) (void) printf(" type=\"%s\"",mime_type); if (acronym != (const char *) NULL) (void) printf(" acronym=\"%s\"",acronym); if (description != (const char *) NULL) (void) printf(" description=\"%s\"",description); (void) printf(" priority=\"100\""); if (pattern != (const char *) NULL) (void) printf(" pattern=\"%s\"",pattern); (void) printf(" />\n"); glob=GetNextXMLTreeTag(glob); } type=GetNextXMLTreeTag(type); } (void) printf("</mimemap>\n"); xml=XMLTreeInfoToXML(xml_info); (void) fprintf(stderr,"%s\n",xml); xml=(char *) RelinquishWizardMemory(xml); DestroyXMLTree(xml_info); exception=DestroyExceptionInfo(exception); return(0); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % 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)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t P a g e G e o m e t r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetPageGeometry() replaces any page mneumonic with the equivalent size in % picas. % % The format of the GetPageGeometry method is: % % char *GetPageGeometry(const char *page_geometry) % % A description of each parameter follows. % % o page_geometry: Specifies a pointer to an array of characters. % The string is either a Postscript page name (e.g. A4) or a postscript % page geometry (e.g. 612x792+36+36). % */ MagickExport char *GetPageGeometry(const char *page_geometry) { static const char *PageSizes[][2]= { { "4x6", "288x432" }, { "5x7", "360x504" }, { "7x9", "504x648" }, { "8x10", "576x720" }, { "9x11", "648x792" }, { "9x12", "648x864" }, { "10x13", "720x936" }, { "10x14", "720x1008" }, { "11x17", "792x1224" }, { "a0", "2384x3370" }, { "a1", "1684x2384" }, { "a10", "73x105" }, { "a2", "1191x1684" }, { "a3", "842x1191" }, { "a4", "595x842" }, { "a4smaLL", "595x842" }, { "a5", "420x595" }, { "a6", "297x420" }, { "a7", "210x297" }, { "a8", "148x210" }, { "a9", "105x148" }, { "archa", "648x864" }, { "archb", "864x1296" }, { "archC", "1296x1728" }, { "archd", "1728x2592" }, { "arche", "2592x3456" }, { "b0", "2920x4127" }, { "b1", "2064x2920" }, { "b10", "91x127" }, { "b2", "1460x2064" }, { "b3", "1032x1460" }, { "b4", "729x1032" }, { "b5", "516x729" }, { "b6", "363x516" }, { "b7", "258x363" }, { "b8", "181x258" }, { "b9", "127x181" }, { "c0", "2599x3676" }, { "c1", "1837x2599" }, { "c2", "1298x1837" }, { "c3", "918x1296" }, { "c4", "649x918" }, { "c5", "459x649" }, { "c6", "323x459" }, { "c7", "230x323" }, { "executive", "540x720" }, { "flsa", "612x936" }, { "flse", "612x936" }, { "folio", "612x936" }, { "halfletter", "396x612" }, { "isob0", "2835x4008" }, { "isob1", "2004x2835" }, { "isob10", "88x125" }, { "isob2", "1417x2004" }, { "isob3", "1001x1417" }, { "isob4", "709x1001" }, { "isob5", "499x709" }, { "isob6", "354x499" }, { "isob7", "249x354" }, { "isob8", "176x249" }, { "isob9", "125x176" }, { "jisb0", "1030x1456" }, { "jisb1", "728x1030" }, { "jisb2", "515x728" }, { "jisb3", "364x515" }, { "jisb4", "257x364" }, { "jisb5", "182x257" }, { "jisb6", "128x182" }, { "ledger", "1224x792" }, { "legal", "612x1008" }, { "letter", "612x792" }, { "lettersmaLL", "612x792" }, { "quarto", "610x780" }, { "statement", "396x612" }, { "tabloid", "792x1224" }, { (char *) NULL, (char *) NULL } }; char *page; register ssize_t i; assert(page_geometry != (char *) NULL); (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",page_geometry); page=AcquireString(page_geometry); for (i=0; *PageSizes[i] != (char *) NULL; i++) if (LocaleNCompare(PageSizes[i][0],page,strlen(PageSizes[i][0])) == 0) { RectangleInfo geometry; MagickStatusType flags; /* Replace mneumonic with the equivalent size in dots-per-inch. */ (void) CopyMagickString(page,PageSizes[i][1],MaxTextExtent); (void) ConcatenateMagickString(page,page_geometry+ strlen(PageSizes[i][0]),MaxTextExtent); flags=GetGeometry(page,&geometry.x,&geometry.y,&geometry.width, &geometry.height); if ((flags & GreaterValue) == 0) (void) ConcatenateMagickString(page,">",MaxTextExtent); break; } return(page); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + 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); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % W r i t e U I L I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Procedure WriteUILImage() writes an image to a file in the X-Motif UIL table % format. % % The format of the WriteUILImage method is: % % MagickBooleanType WriteUILImage(const ImageInfo *image_info, % Image *image,ExceptionInfo *exception) % % A description of each parameter follows. % % o image_info: the image info. % % o image: The image. % % o exception: return any errors or warnings in this structure. % */ static MagickBooleanType WriteUILImage(const ImageInfo *image_info,Image *image, ExceptionInfo *exception) { #define MaxCixels 92 char basename[MagickPathExtent], buffer[MagickPathExtent], name[MagickPathExtent], *symbol; int j; MagickBooleanType status, transparent; MagickSizeType number_pixels; PixelInfo pixel; register const Quantum *p; register ssize_t i, x; size_t characters_per_pixel, colors; ssize_t k, y; static const char Cixel[MaxCixels+1] = " .XoO+@#$%&*=-;:>,<1234567890qwertyuipasdfghjk" "lzxcvbnmMNBVCZASDFGHJKLPIUYTREWQ!~^/()_`'][{}|"; /* Open output image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickCoreSignature); assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickCoreSignature); status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); if (status == MagickFalse) return(status); (void) TransformImageColorspace(image,sRGBColorspace,exception); transparent=MagickFalse; i=0; p=(const Quantum *) NULL; if (image->storage_class == PseudoClass) colors=image->colors; else { unsigned char *matte_image; /* Convert DirectClass to PseudoClass image. */ matte_image=(unsigned char *) NULL; if (image->alpha_trait != UndefinedPixelTrait) { /* Map all the transparent pixels. */ number_pixels=(MagickSizeType) image->columns*image->rows; if (number_pixels != ((MagickSizeType) (size_t) number_pixels)) ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); matte_image=(unsigned char *) AcquireQuantumMemory(image->columns, image->rows*sizeof(*matte_image)); if (matte_image == (unsigned char *) NULL) ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); for (y=0; y < (ssize_t) image->rows; y++) { p=GetVirtualPixels(image,0,y,image->columns,1,exception); if (p == (const Quantum *) NULL) break; for (x=0; x < (ssize_t) image->columns; x++) { matte_image[i]=(unsigned char) (GetPixelAlpha(image,p) == (Quantum) TransparentAlpha ? 1 : 0); if (matte_image[i] != 0) transparent=MagickTrue; i++; p+=GetPixelChannels(image); } } } (void) SetImageType(image,PaletteType,exception); colors=image->colors; if (transparent != MagickFalse) { register Quantum *q; colors++; for (y=0; y < (ssize_t) image->rows; y++) { q=GetAuthenticPixels(image,0,y,image->columns,1,exception); if (q == (Quantum *) NULL) break; for (x=0; x < (ssize_t) image->columns; x++) { if (matte_image[i] != 0) SetPixelIndex(image,(Quantum) image->colors,q); q+=GetPixelChannels(image); } } } if (matte_image != (unsigned char *) NULL) matte_image=(unsigned char *) RelinquishMagickMemory(matte_image); } /* Compute the character per pixel. */ characters_per_pixel=1; for (k=MaxCixels; (ssize_t) colors > k; k*=MaxCixels) characters_per_pixel++; /* UIL header. */ symbol=AcquireString(""); (void) WriteBlobString(image,"/* UIL */\n"); GetPathComponent(image->filename,BasePath,basename); (void) FormatLocaleString(buffer,MagickPathExtent, "value\n %s_ct : color_table(\n",basename); (void) WriteBlobString(image,buffer); GetPixelInfo(image,&pixel); for (i=0; i < (ssize_t) colors; i++) { /* Define UIL color. */ pixel=image->colormap[i]; pixel.colorspace=sRGBColorspace; pixel.depth=8; pixel.alpha=(double) OpaqueAlpha; GetColorTuple(&pixel,MagickTrue,name); if (transparent != MagickFalse) if (i == (ssize_t) (colors-1)) (void) CopyMagickString(name,"None",MagickPathExtent); /* Write UIL color. */ k=i % MaxCixels; symbol[0]=Cixel[k]; for (j=1; j < (int) characters_per_pixel; j++) { k=((i-k)/MaxCixels) % MaxCixels; symbol[j]=Cixel[k]; } symbol[j]='\0'; (void) SubstituteString(&symbol,"'","''"); if (LocaleCompare(name,"None") == 0) (void) FormatLocaleString(buffer,MagickPathExtent, " background color = '%s'",symbol); else (void) FormatLocaleString(buffer,MagickPathExtent, " color('%s',%s) = '%s'",name, GetPixelInfoIntensity(image,image->colormap+i) < (QuantumRange/2.0) ? "background" : "foreground",symbol); (void) WriteBlobString(image,buffer); (void) FormatLocaleString(buffer,MagickPathExtent,"%s", (i == (ssize_t) (colors-1) ? ");\n" : ",\n")); (void) WriteBlobString(image,buffer); } /* Define UIL pixels. */ GetPathComponent(image->filename,BasePath,basename); (void) FormatLocaleString(buffer,MagickPathExtent, " %s_icon : icon(color_table = %s_ct,\n",basename,basename); (void) WriteBlobString(image,buffer); for (y=0; y < (ssize_t) image->rows; y++) { p=GetVirtualPixels(image,0,y,image->columns,1,exception); if (p == (const Quantum *) NULL) break; (void) WriteBlobString(image," \""); for (x=0; x < (ssize_t) image->columns; x++) { k=((ssize_t) GetPixelIndex(image,p) % MaxCixels); symbol[0]=Cixel[k]; for (j=1; j < (int) characters_per_pixel; j++) { k=(((int) GetPixelIndex(image,p)-k)/MaxCixels) % MaxCixels; symbol[j]=Cixel[k]; } symbol[j]='\0'; (void) CopyMagickString(buffer,symbol,MagickPathExtent); (void) WriteBlobString(image,buffer); p+=GetPixelChannels(image); } (void) FormatLocaleString(buffer,MagickPathExtent,"\"%s\n", (y == (ssize_t) (image->rows-1) ? ");" : ",")); (void) WriteBlobString(image,buffer); status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, image->rows); if (status == MagickFalse) break; } symbol=DestroyString(symbol); (void) CloseBlob(image); return(MagickTrue); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + L o a d M i m e C a c h e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % LoadMimeCache() loads the mime configurations which provides a mapping % between mime attributes and a mime name. % % The format of the LoadMimeCache method is: % % MagickBooleanType LoadMimeCache(LinkedListInfo *cache,const char *xml, % const char *filename,const size_t depth,ExceptionInfo *exception) % % A description of each parameter follows: % % o xml: The mime list in XML format. % % o filename: The mime list filename. % % o depth: depth of <include /> statements. % % o exception: return any errors or warnings in this structure. % */ static MagickBooleanType LoadMimeCache(LinkedListInfo *cache,const char *xml, const char *filename,const size_t depth,ExceptionInfo *exception) { const char *attribute; MimeInfo *mime_info = (MimeInfo *) NULL; MagickStatusType status; XMLTreeInfo *mime, *mime_map, *include; /* Load the mime map file. */ (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), "Loading mime map \"%s\" ...",filename); if (xml == (const char *) NULL) return(MagickFalse); mime_map=NewXMLTree(xml,exception); if (mime_map == (XMLTreeInfo *) NULL) return(MagickFalse); status=MagickTrue; include=GetXMLTreeChild(mime_map,"include"); while (include != (XMLTreeInfo *) NULL) { /* Process include element. */ attribute=GetXMLTreeAttribute(include,"file"); if (attribute != (const char *) NULL) { if (depth > 200) (void) ThrowMagickException(exception,GetMagickModule(), ConfigureError,"IncludeElementNestedTooDeeply","`%s'",filename); else { char path[MagickPathExtent], *file_xml; GetPathComponent(filename,HeadPath,path); if (*path != '\0') (void) ConcatenateMagickString(path,DirectorySeparator, MagickPathExtent); if (*attribute == *DirectorySeparator) (void) CopyMagickString(path,attribute,MagickPathExtent); else (void) ConcatenateMagickString(path,attribute,MagickPathExtent); file_xml=FileToXML(path,~0UL); if (file_xml != (char *) NULL) { status&=LoadMimeCache(cache,file_xml,path,depth+1,exception); file_xml=DestroyString(file_xml); } } } include=GetNextXMLTreeTag(include); } mime=GetXMLTreeChild(mime_map,"mime"); while (mime != (XMLTreeInfo *) NULL) { /* Process mime element. */ mime_info=(MimeInfo *) AcquireCriticalMemory(sizeof(*mime_info)); (void) ResetMagickMemory(mime_info,0,sizeof(*mime_info)); mime_info->path=ConstantString(filename); mime_info->signature=MagickCoreSignature; attribute=GetXMLTreeAttribute(mime,"data-type"); if (attribute != (const char *) NULL) mime_info->data_type=(DataType) ParseCommandOption(MagickDataTypeOptions, MagickTrue,attribute); attribute=GetXMLTreeAttribute(mime,"description"); if (attribute != (const char *) NULL) mime_info->description=ConstantString(attribute); attribute=GetXMLTreeAttribute(mime,"endian"); if (attribute != (const char *) NULL) mime_info->endian=(EndianType) ParseCommandOption(MagickEndianOptions, MagickTrue,attribute); attribute=GetXMLTreeAttribute(mime,"magic"); if (attribute != (const char *) NULL) { char *token; const char *p; register unsigned char *q; token=AcquireString(attribute); (void) SubstituteString((char **) &token,"<","<"); (void) SubstituteString((char **) &token,"&","&"); (void) SubstituteString((char **) &token,""","\""); mime_info->magic=(unsigned char *) AcquireString(token); q=mime_info->magic; for (p=token; *p != '\0'; ) { if (*p == '\\') { p++; if (isdigit((int) ((unsigned char) *p)) != 0) { char *end; *q++=(unsigned char) strtol(p,&end,8); p+=(end-p); mime_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++; mime_info->length++; continue; } *q++=(unsigned char) (*p++); mime_info->length++; } token=DestroyString(token); if (mime_info->data_type != StringData) mime_info->value=(ssize_t) strtoul((char *) mime_info->magic, (char **) NULL,0); } attribute=GetXMLTreeAttribute(mime,"mask"); if (attribute != (const char *) NULL) mime_info->mask=(ssize_t) strtoul(attribute,(char **) NULL,0); attribute=GetXMLTreeAttribute(mime,"offset"); if (attribute != (const char *) NULL) { char *c; mime_info->offset=(MagickOffsetType) strtol(attribute,&c,0); if (*c == ':') mime_info->extent=(size_t) strtol(c+1,(char **) NULL,0); } attribute=GetXMLTreeAttribute(mime,"pattern"); if (attribute != (const char *) NULL) mime_info->pattern=ConstantString(attribute); attribute=GetXMLTreeAttribute(mime,"priority"); if (attribute != (const char *) NULL) mime_info->priority=(ssize_t) strtol(attribute,(char **) NULL,0); attribute=GetXMLTreeAttribute(mime,"stealth"); if (attribute != (const char *) NULL) mime_info->stealth=IsStringTrue(attribute); attribute=GetXMLTreeAttribute(mime,"type"); if (attribute != (const char *) NULL) mime_info->type=ConstantString(attribute); status=AppendValueToLinkedList(cache,mime_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",filename); mime=GetNextXMLTreeTag(mime); } mime_map=DestroyXMLTree(mime_map); return(status != 0 ? MagickTrue : MagickFalse); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d I N L I N E I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadINLINEImage() reads base64-encoded inlines images. % % The format of the ReadINLINEImage method is: % % Image *ReadINLINEImage(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 *ReadINLINEImage(const ImageInfo *image_info, ExceptionInfo *exception) { Image *image; MagickBooleanType status; register size_t i; size_t quantum; ssize_t count; unsigned char *inline_image; /* Open image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickCoreSignature); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickCoreSignature); if (LocaleCompare(image_info->magick,"DATA") == 0) { char *filename; Image *data_image; filename=AcquireString("data:"); (void) ConcatenateMagickString(filename,image_info->filename, MagickPathExtent); data_image=ReadInlineImage(image_info,filename,exception); filename=DestroyString(filename); return(data_image); } image=AcquireImage(image_info,exception); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } quantum=MagickMin((size_t) GetBlobSize(image),MagickMaxBufferExtent); if (quantum == 0) quantum=MagickMaxBufferExtent; inline_image=(unsigned char *) AcquireQuantumMemory(quantum, sizeof(*inline_image)); count=0; for (i=0; inline_image != (unsigned char *) NULL; i+=count) { count=(ssize_t) ReadBlob(image,quantum,inline_image+i); if (count <= 0) { count=0; if (errno != EINTR) break; } if (~((size_t) i) < (quantum+1)) { inline_image=(unsigned char *) RelinquishMagickMemory(inline_image); break; } inline_image=(unsigned char *) ResizeQuantumMemory(inline_image,i+count+ quantum+1,sizeof(*inline_image)); } if (inline_image == (unsigned char *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); return((Image *) NULL); } inline_image[i+count]='\0'; image=DestroyImageList(image); image=ReadInlineImage(image_info,(char *) inline_image,exception); inline_image=(unsigned char *) RelinquishMagickMemory(inline_image); return(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)); }
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 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, *text; const char *gravity, *option; DrawInfo *draw_info; Image *image; MagickBooleanType split, status; register ssize_t i; size_t height, width; TypeMetric metrics; /* 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"); /* Format caption. */ option=GetImageOption(image_info,"filename"); if (option == (const char *) NULL) property=InterpretImageProperties(image_info,image,image_info->filename); else if (LocaleNCompare(option,"caption:",8) == 0) property=InterpretImageProperties(image_info,image,option+8); else property=InterpretImageProperties(image_info,image,option); (void) SetImageProperty(image,"caption",property); property=DestroyString(property); caption=ConstantString(GetImageProperty(image,"caption")); draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL); (void) CloneString(&draw_info->text,caption); gravity=GetImageOption(image_info,"gravity"); if (gravity != (char *) NULL) draw_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions, MagickFalse,gravity); split=MagickFalse; status=MagickTrue; if (image->columns == 0) { text=AcquireString(caption); i=FormatMagickCaption(image,draw_info,split,&metrics,&text); (void) CloneString(&draw_info->text,text); text=DestroyString(text); (void) FormatLocaleString(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=(size_t) floor(metrics.width+draw_info->stroke_width+0.5); image->columns=width; } if (image->rows == 0) { split=MagickTrue; text=AcquireString(caption); i=FormatMagickCaption(image,draw_info,split,&metrics,&text); (void) CloneString(&draw_info->text,text); text=DestroyString(text); (void) FormatLocaleString(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); image->rows=(size_t) ((i+1)*(metrics.ascent-metrics.descent+ draw_info->interline_spacing+draw_info->stroke_width)+0.5); } if (status != MagickFalse) status=SetImageExtent(image,image->columns,image->rows); if (status == MagickFalse) { draw_info=DestroyDrawInfo(draw_info); InheritException(exception,&image->exception); return(DestroyImageList(image)); } if (SetImageBackgroundColor(image) == MagickFalse) { draw_info=DestroyDrawInfo(draw_info); InheritException(exception,&image->exception); image=DestroyImageList(image); return((Image *) NULL); } if (fabs(image_info->pointsize) < MagickEpsilon) { double high, low; /* Auto fit text into bounding box. */ for ( ; ; draw_info->pointsize*=2.0) { text=AcquireString(caption); i=FormatMagickCaption(image,draw_info,split,&metrics,&text); (void) CloneString(&draw_info->text,text); text=DestroyString(text); (void) FormatLocaleString(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); (void) status; 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) && (image->rows != 0)) { if ((width >= image->columns) && (height >= image->rows)) break; } else if (((image->columns != 0) && (width >= image->columns)) || ((image->rows != 0) && (height >= image->rows))) break; } high=draw_info->pointsize; for (low=1.0; (high-low) > 0.5; ) { draw_info->pointsize=(low+high)/2.0; text=AcquireString(caption); i=FormatMagickCaption(image,draw_info,split,&metrics,&text); (void) CloneString(&draw_info->text,text); text=DestroyString(text); (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g", -metrics.bounds.x1,metrics.ascent); if (draw_info->gravity == UndefinedGravity) (void) CloneString(&draw_info->geometry,geometry); (void) GetMultilineTypeMetrics(image,draw_info,&metrics); 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) && (image->rows != 0)) { if ((width < image->columns) && (height < image->rows)) low=draw_info->pointsize+0.5; else high=draw_info->pointsize-0.5; } else if (((image->columns != 0) && (width < image->columns)) || ((image->rows != 0) && (height < image->rows))) low=draw_info->pointsize+0.5; else high=draw_info->pointsize-0.5; } draw_info->pointsize=(low+high)/2.0-0.5; } /* Draw caption. */ i=FormatMagickCaption(image,draw_info,split,&metrics,&caption); (void) CloneString(&draw_info->text,caption); (void) FormatLocaleString(geometry,MaxTextExtent,"%+g%+g",MagickMax( draw_info->direction == RightToLeftDirection ? image->columns- metrics.bounds.x2 : -metrics.bounds.x1,0.0),draw_info->gravity == UndefinedGravity ? metrics.ascent : 0.0); draw_info->geometry=AcquireString(geometry); status=AnnotateImage(image,draw_info); if (image_info->pointsize == 0.0) { char pointsize[MaxTextExtent]; (void) FormatLocaleString(pointsize,MaxTextExtent,"%.20g", draw_info->pointsize); (void) SetImageProperty(image,"caption:pointsize",pointsize); } draw_info=DestroyDrawInfo(draw_info); caption=DestroyString(caption); if (status == MagickFalse) { image=DestroyImageList(image); return((Image *) NULL); } return(GetFirstImageInList(image)); }