/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t W a n d V i e w E x c e p t i o n % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetWandViewException() returns the severity, reason, and description of any % error that occurs when utilizing a wand view. % % The format of the GetWandViewException method is: % % char *GetWandViewException(const WandView *wand_view, % ExceptionType *severity) % % A description of each parameter follows: % % o wand_view: the pixel wand_view. % % o severity: the severity of the error is returned here. % */ WandExport char *GetWandViewException(const WandView *wand_view, ExceptionType *severity) { char *description; assert(wand_view != (const WandView *) NULL); assert(wand_view->signature == WandSignature); if (wand_view->debug != MagickFalse) (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand_view->name); assert(severity != (ExceptionType *) NULL); *severity=wand_view->exception->severity; description=(char *) AcquireQuantumMemory(2UL*MaxTextExtent, sizeof(*description)); if (description == (char *) NULL) ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed", wand_view->name); *description='\0'; if (wand_view->exception->reason != (char *) NULL) (void) CopyMagickString(description,GetLocaleExceptionMessage( wand_view->exception->severity,wand_view->exception->reason), MaxTextExtent); if (wand_view->exception->description != (char *) NULL) { (void) ConcatenateMagickString(description," (",MaxTextExtent); (void) ConcatenateMagickString(description,GetLocaleExceptionMessage( wand_view->exception->severity,wand_view->exception->description), MaxTextExtent); (void) ConcatenateMagickString(description,")",MaxTextExtent); } return(description); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % M a g i c k G e t E x c e p t i o n % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % MagickGetException() returns the severity, reason, and description of any % error that occurs when using other methods in this API. % % The format of the MagickGetException method is: % % char *MagickGetException(const MagickWand *wand,ExceptionType *severity) % % A description of each parameter follows: % % o wand: the magick wand. % % o severity: the severity of the error is returned here. % */ WandExport char *MagickGetException(const MagickWand *wand, ExceptionType *severity) { char *description; assert(wand != (const MagickWand *) NULL); assert(wand->signature == WandSignature); if (wand->debug != MagickFalse) (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name); assert(severity != (ExceptionType *) NULL); *severity=wand->exception->severity; description=(char *) AcquireQuantumMemory(2UL*MaxTextExtent, sizeof(*description)); if (description == (char *) NULL) { (void) ThrowMagickException(wand->exception,GetMagickModule(),WandError, "MemoryAllocationFailed","`%s'",wand->name); return((char *) NULL); } *description='\0'; if (wand->exception->reason != (char *) NULL) (void) CopyMagickString(description,GetLocaleExceptionMessage( wand->exception->severity,wand->exception->reason),MaxTextExtent); if (wand->exception->description != (char *) NULL) { (void) ConcatenateMagickString(description," (",MaxTextExtent); (void) ConcatenateMagickString(description,GetLocaleExceptionMessage( wand->exception->severity,wand->exception->description),MaxTextExtent); (void) ConcatenateMagickString(description,")",MaxTextExtent); } return(description); }
MagickExport void MagickError(const ExceptionType error,const char *reason, const char *description) { if (error_handler != (ErrorHandler) NULL) (*error_handler)(error,GetLocaleExceptionMessage(error,reason), GetLocaleExceptionMessage(error,description)); }
/* * Static: handle_exception * Purpose: called when rm_check_exception determines that we need * to either issue a warning message or raise an exception. * This function allocates a bunch of stack so we don't call * it unless we have to. */ static void handle_exception(ExceptionInfo *exception, Image *imglist, ErrorRetention retention) { char reason[500]; char desc[500]; char msg[sizeof(reason)+sizeof(desc)+20]; memset(msg, 0, sizeof(msg)); // Handle simple warning if (exception->severity < ErrorException) { #if defined(HAVE_SNPRINTF) snprintf(msg, sizeof(msg)-1, "RMagick: %s%s%s", #else sprintf(msg, "RMagick: %.500s%s%.500s", #endif GetLocaleExceptionMessage(exception->severity, exception->reason), exception->description ? ": " : "", exception->description ? GetLocaleExceptionMessage(exception->severity, exception->description) : ""); msg[sizeof(msg)-1] = '\0'; rb_warning(msg); // Caller deletes ExceptionInfo... return; }
MagickExport void MagickWarning(const ExceptionType warning,const char *reason, const char *description) { if (warning_handler != (WarningHandler) NULL) (*warning_handler)(warning,GetLocaleExceptionMessage(warning,reason), GetLocaleExceptionMessage(warning,description)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t I m a g e V i e w E x c e p t i o n % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetImageViewException() returns the severity, reason, and description of any % error that occurs when utilizing a image view. % % The format of the GetImageViewException method is: % % char *GetImageViewException(const PixelImage *image_view, % ExceptionType *severity) % % A description of each parameter follows: % % o image_view: the pixel image_view. % % o severity: the severity of the error is returned here. % */ MagickExport char *GetImageViewException(const ImageView *image_view, ExceptionType *severity) { char *description; assert(image_view != (const ImageView *) NULL); assert(image_view->signature == MagickSignature); assert(severity != (ExceptionType *) NULL); *severity=image_view->exception->severity; description=(char *) AcquireQuantumMemory(2UL*MaxTextExtent, sizeof(*description)); if (description == (char *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); *description='\0'; if (image_view->exception->reason != (char *) NULL) (void) CopyMagickString(description,GetLocaleExceptionMessage( image_view->exception->severity,image_view->exception->reason), MaxTextExtent); if (image_view->exception->description != (char *) NULL) { (void) ConcatenateMagickString(description," (",MaxTextExtent); (void) ConcatenateMagickString(description,GetLocaleExceptionMessage( image_view->exception->severity,image_view->exception->description), MaxTextExtent); (void) ConcatenateMagickString(description,")",MaxTextExtent); } return(description); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % P i x e l G e t I t e r a t o r E x c e p t i o n % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % PixelGetIteratorException() returns the severity, reason, and description of % any error that occurs when using other methods in this API. % % The format of the PixelGetIteratorException method is: % % char *PixelGetIteratorException(const PixelIterator *iterator, % ExceptionType *severity) % % A description of each parameter follows: % % o iterator: the pixel iterator. % % o severity: the severity of the error is returned here. % */ WandExport char *PixelGetIteratorException(const PixelIterator *iterator, ExceptionType *severity) { char *description; assert(iterator != (const PixelIterator *) NULL); assert(iterator->signature == MagickWandSignature); if (iterator->debug != MagickFalse) (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",iterator->name); assert(severity != (ExceptionType *) NULL); *severity=iterator->exception->severity; description=(char *) AcquireQuantumMemory(2UL*MagickPathExtent, sizeof(*description)); if (description == (char *) NULL) ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed", iterator->name); *description='\0'; if (iterator->exception->reason != (char *) NULL) (void) CopyMagickString(description,GetLocaleExceptionMessage( iterator->exception->severity,iterator->exception->reason),MagickPathExtent); if (iterator->exception->description != (char *) NULL) { (void) ConcatenateMagickString(description," (",MagickPathExtent); (void) ConcatenateMagickString(description,GetLocaleExceptionMessage( iterator->exception->severity,iterator->exception->description), MagickPathExtent); (void) ConcatenateMagickString(description,")",MagickPathExtent); } return(description); }
MagickExport void _MagickFatalError(const ExceptionType error,const char *reason, const char *description) { if (fatal_error_handler != (ErrorHandler) NULL) (*fatal_error_handler)(error,GetLocaleExceptionMessage(error,reason), GetLocaleExceptionMessage(error,description)); errno=0; }
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; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % 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; }
MagickExport MagickBooleanType ThrowMagickExceptionList( ExceptionInfo *exception,const char *module,const char *function, const size_t line,const ExceptionType severity,const char *tag, const char *format,va_list operands) { char message[MaxTextExtent], path[MaxTextExtent], reason[MaxTextExtent]; const char *locale, *type; int n; MagickBooleanType status; size_t length; assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); locale=GetLocaleExceptionMessage(severity,tag); (void) CopyMagickString(reason,locale,MaxTextExtent); (void) ConcatenateMagickString(reason," ",MaxTextExtent); length=strlen(reason); #if defined(MAGICKCORE_HAVE_VSNPRINTF) n=vsnprintf(reason+length,MaxTextExtent-length,format,operands); #else n=vsprintf(reason+length,format,operands); #endif if (n < 0) reason[MaxTextExtent-1]='\0'; status=LogMagickEvent(ExceptionEvent,module,function,line,"%s",reason); GetPathComponent(module,TailPath,path); type="undefined"; if ((severity >= WarningException) && (severity < ErrorException)) type="warning"; if ((severity >= ErrorException) && (severity < FatalErrorException)) type="error"; if (severity >= FatalErrorException) type="fatal"; (void) FormatLocaleString(message,MaxTextExtent,"%s @ %s/%s/%s/%.20g",reason, type,path,function,(double) line); (void) ThrowException(exception,severity,message,(char *) NULL); return(status); }
/* * Extern: rm_fatal_error_handler * Purpose: called from ImageMagick for a fatal error */ void rm_fatal_error_handler(const ExceptionType severity, const char *reason, const char *description) { rb_raise(Class_FatalImageMagickError, GetLocaleExceptionMessage(severity, reason)); description = description; }
/*---------------------------------------------------------- * int_imfinfo: * interface for imfinfo function. * should provide type=imfinfo(name) at Scilab level * $Revision: 1.3 $ $Date: 2009-04-14 14:02:45 $ *----------------------------------------------------------*/ SipExport int int_imfinfo(char *fname) { /* Interface variables */ int mC, nC, lC, /* for name input arg */ mV, nV, lV, /* for "verbose" optional input arg */ mL=12, nL=1, lL, /* for list output arg */ mS=1, nS=12, mFileName, nFileName=1, mFileSize=1, nFileSize=1, mFormat, nFormat=1, mWidth=1, nWidth=1, mHeight=1, nHeight=1, mDepth=1, nDepth=1, mStorageType, nStorageType=1, mNumberOfColors=1, nNumberOfColors=1, mResolutionUnit, nResolutionUnit=1, mXResolution=1, nXResolution=1, mYResolution=1, nYResolution=1, pos, minlhs=1, maxlhs=1, minrhs=1, maxrhs=2, i; unsigned long int *lWidth, *lHeight, *lDepth, *lNumberOfColors, *lFileSize, fsize; char *lFileName, *lStorageType, *lFormat, *lResolutionUnit, *arg2; double *lXResolution, *lYResolution; static char *Str[]= { "type", "FileName", "FileSize", "Format", "Width", "Height", "Depth", "StorageType", "NumberOfColors", "ResolutionUnit", "XResolution", "YResolution" }; /* ImageMagick variables */ ExceptionInfo exception; Image *image; ImageInfo *image_info; CheckRhs(minrhs, maxrhs); CheckLhs(minlhs, maxlhs); /* Get name (#1) and "verbose" optional arg (#2)*/ GetRhsVar(1, "c", &mC, &nC, &lC); if (Rhs == 2) { GetRhsVar(2, "c", &mV, &nV, &lV); arg2 = (char *)calloc(strlen(cstk(lV))+1, sizeof(char)); if (!arg2) sip_error("unable to alloc memory"); strcpy(arg2,cstk(lV)); } InitializeMagick(NULL); GetExceptionInfo(&exception); image_info=CloneImageInfo((ImageInfo *) NULL); (void) strcpy(image_info->filename,cstk(lC)); image = PingImage(image_info, &exception); if (image == (Image *) NULL) { /* clean up */ if (Rhs==2) free(arg2); if(exception.reason != NULL) { char errmsg[50]; for (i=0; i<49; i++) errmsg[i]=' '; errmsg[49]='\0'; strncpy(errmsg,GetLocaleExceptionMessage(exception.severity,exception.reason),50); DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); DestroyMagick(); sip_error(errmsg); } DestroyImageInfo(image_info); DestroyExceptionInfo(&exception); DestroyMagick(); sip_error("unknown reason"); } pos =1; CreateVar(1, "t", &mL, &nL, &lL); CreateListVarFromPtr(1,pos++,"S", &mS, &nS, Str); lFileName = image->filename; mFileName = strlen(image->filename); CreateListVarFromPtr(1,pos++,"c", &mFileName, &nFileName, &lFileName); fsize = SizeBlob(image); lFileSize = &fsize; CreateListVarFromPtr(1,pos++,"i", &mFileSize, &nFileSize, &lFileSize); lFormat = image->magick; mFormat = strlen(image->magick); CreateListVarFromPtr(1,pos++,"c", &mFormat, &nFormat, &lFormat); lWidth = &(image->columns); CreateListVarFromPtr(1,pos++,"i", &mWidth, &nWidth, &lWidth); lHeight = &(image->rows); CreateListVarFromPtr(1,pos++,"i", &mHeight, &nHeight, &lHeight); lDepth = &(image->depth); CreateListVarFromPtr(1,pos++,"i", &mDepth, &nDepth, &lDepth); lStorageType = (image->storage_class == DirectClass)? "truecolor":"indexed"; mStorageType = strlen(lStorageType); CreateListVarFromPtr(1,pos++,"c", &mStorageType, &nStorageType, &lStorageType); lNumberOfColors = &(image->colors); CreateListVarFromPtr(1,pos++,"i", &mNumberOfColors, \ &nNumberOfColors, &lNumberOfColors); /* lComments = image->comments; mComments = strlen(image->comments); CreateListVarFromPtr(1,pos++,"c", &mComments, &nComments, &lComments); */ lResolutionUnit = (image->units == PixelsPerInchResolution)?"inch":"centimeter"; mResolutionUnit = strlen(lResolutionUnit); CreateListVarFromPtr(1,pos++,"c", &mResolutionUnit, \ &nResolutionUnit, &lResolutionUnit); lXResolution = &(image->x_resolution); CreateListVarFromPtr(1,pos++,"i", &mXResolution, &nXResolution, &lXResolution); lYResolution = &(image->y_resolution); CreateListVarFromPtr(1,pos++,"i", &mYResolution, &nYResolution, &lYResolution); if (Rhs==2) { if (strcmp(arg2,"verbose") != 0) sip_error("invalid 2nd argument"); sciprint(" FileName: %s\n\r", image->filename); sciprint(" FileSize: %d\n\r", fsize); sciprint(" Format: %s\n\r", image->magick); sciprint(" Width: %d\n\r", image->columns); sciprint(" Height: %d\n\r", image->rows); sciprint(" Depth: %d\n\r", image->depth); sciprint(" StorageType: %s\n\r", lStorageType); sciprint(" NumberOfColors: %d\n\r", image->colors); sciprint(" ResolutionUnit: %s\n\r", lResolutionUnit); sciprint(" XResolution: %f\n\r", image->x_resolution); sciprint(" YResolution: %f\n\r", image->y_resolution); free(arg2); } /* Terminate Imagemagick */ DestroyImageInfo(image_info); DestroyImage(image); DestroyExceptionInfo(&exception); DestroyMagick(); /* Return variables */ LhsVar(1) = 1; return true; }