bool draw_forest(enum tree_state * forest, size_t width, size_t height) { static uint32_t counter = 0; bool ret = false; MagickCoreGenesis(NULL,MagickTrue); { uint8_t * pixels = malloc( width * height * sizeof(uint8_t) * 4); // channel count forest_to_intensity(forest, pixels, width * height); const char name[128]; sprintf((char *)name, "out_%04d.gif", counter); ExceptionInfo * exception = AcquireExceptionInfo(); Image * image = ConstituteImage(width,height,"RGBP",CharPixel,pixels,exception); ImageInfo * info = AcquireImageInfo(); strncpy(image->filename, name, sizeof(image->filename)); ret = WriteImage(info, image); DestroyImage(image); DestroyExceptionInfo(exception); DestroyImageInfo(info); free(pixels); } counter++; MagickCoreTerminus(); return ret; }
static int CompareMain(int argc,char **argv) { char *metadata; const char *option; ExceptionInfo *exception; ImageInfo *image_info; MagickBooleanType dissimilar, status; MagickCoreGenesis(*argv,MagickTrue); exception=AcquireExceptionInfo(); image_info=AcquireImageInfo(); metadata=(char *) NULL; status=MagickCommandGenesis(image_info,CompareImageCommand,argc,argv, &metadata,exception); if (metadata != (char *) NULL) metadata=DestroyString(metadata); option=GetImageOption(image_info,"compare:dissimilar"); dissimilar=IsMagickTrue(option); image_info=DestroyImageInfo(image_info); exception=DestroyExceptionInfo(exception); MagickCoreTerminus(); if (dissimilar != MagickFalse) return(1); return(status != MagickFalse ? 0 : 2); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % N e w M a g i c k W a n d % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % NewMagickWand() returns a wand required for all other methods in the API. % A fatal exception is thrown if there is not enough memory to allocate the % wand. Use DestroyMagickWand() to dispose of the wand when it is no longer % needed. % % The format of the NewMagickWand method is: % % MagickWand *NewMagickWand(void) % */ WandExport MagickWand *NewMagickWand(void) { const char *quantum; MagickWand *wand; size_t depth; depth=MAGICKCORE_QUANTUM_DEPTH; quantum=GetMagickQuantumDepth(&depth); if (depth != MAGICKCORE_QUANTUM_DEPTH) ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum); wand=(MagickWand *) AcquireMagickMemory(sizeof(*wand)); if (wand == (MagickWand *) NULL) ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed", GetExceptionMessage(errno)); (void) ResetMagickMemory(wand,0,sizeof(*wand)); wand->id=AcquireWandId(); (void) FormatLocaleString(wand->name,MaxTextExtent,"%s-%.20g",MagickWandId, (double) wand->id); wand->images=NewImageList(); wand->image_info=AcquireImageInfo(); wand->exception=AcquireExceptionInfo(); wand->debug=IsEventLogging(); if (wand->debug != MagickFalse) (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name); wand->signature=WandSignature; return(wand); }
static int IdentifyMain(int argc,char **argv) { char *metadata; ExceptionInfo *exception; ImageInfo *image_info; MagickBooleanType status; MagickCoreGenesis(*argv,MagickTrue); exception=AcquireExceptionInfo(); image_info=AcquireImageInfo(); metadata=(char *) NULL; status=MagickCommandGenesis(image_info,IdentifyImageCommand,argc,argv, &metadata,exception); if (metadata != (char *) NULL) metadata=DestroyString(metadata); image_info=DestroyImageInfo(image_info); exception=DestroyExceptionInfo(exception); MagickCoreTerminus(); return(status != MagickFalse ? 0 : 1); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % M a i n % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % */ int main(int argc,char **argv) { char *option, *text; ExceptionInfo *exception; ImageInfo *image_info; MagickBooleanType regard_warnings, status; register long i; MagickCoreGenesis(*argv,MagickTrue); exception=AcquireExceptionInfo(); regard_warnings=MagickFalse; for (i=1; i < (long) argc; i++) { option=argv[i]; if ((strlen(option) == 1) || ((*option != '-') && (*option != '+'))) continue; if (LocaleCompare("debug",option+1) == 0) (void) SetLogEventMask(argv[++i]); if (LocaleCompare("regard-warnings",option+1) == 0) regard_warnings=MagickTrue; } image_info=AcquireImageInfo(); text=(char *) NULL; status=CompareImageCommand(image_info,argc,argv,&text,exception); if ((status == MagickFalse) || (exception->severity != UndefinedException)) { if ((exception->severity < ErrorException) && (regard_warnings == MagickFalse)) status=MagickTrue; CatchException(exception); } if (text != (char *) NULL) { (void) fputs(text,stdout); (void) fputc('\n',stdout); text=DestroyString(text); } image_info=DestroyImageInfo(image_info); exception=DestroyExceptionInfo(exception); MagickCoreTerminus(); return(status == MagickFalse ? 1 : 0); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % C l e a r M a g i c k W a n d % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ClearMagickWand() clears resources associated with the wand, leaving the % wand blank, and ready to be used for a new set of images. % % The format of the ClearMagickWand method is: % % void ClearMagickWand(MagickWand *wand) % % A description of each parameter follows: % % o wand: the magick wand. % */ WandExport void ClearMagickWand(MagickWand *wand) { assert(wand != (MagickWand *) NULL); assert(wand->signature == WandSignature); if (wand->debug != MagickFalse) (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name); wand->image_info=DestroyImageInfo(wand->image_info); wand->images=DestroyImageList(wand->images); wand->image_info=AcquireImageInfo(); wand->insert_before=MagickFalse; wand->image_pending=MagickFalse; ClearMagickException(wand->exception); wand->debug=IsEventLogging(); }
MagickExport Image *MontageImages(const Image *images, const MontageInfo *montage_info,ExceptionInfo *exception) { Image *montage_image; ImageInfo *image_info; image_info=AcquireImageInfo(); montage_image=MontageImageList(image_info,montage_info,images,exception); image_info=DestroyImageInfo(image_info); return(montage_image); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % M a i n % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % */ int main(int argc,char **argv) { ExceptionInfo *exception; ImageInfo *image_info; MagickBooleanType status; MagickCoreGenesis(*argv,MagickTrue); exception=AcquireExceptionInfo(); image_info=AcquireImageInfo(); status=MagickCommandGenesis(image_info,MogrifyImageCommand,argc,argv, (char **) NULL,exception); image_info=DestroyImageInfo(image_info); exception=DestroyExceptionInfo(exception); MagickCoreTerminus(); return(status); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % N e w M a g i c k W a n d % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % NewMagickWand() returns a wand required for all other methods in the API. % % The format of the NewMagickWand method is: % % MagickWand *NewMagickWand(void) % */ WandExport MagickWand *NewMagickWand(void) { const char *quantum; MagickWand *wand; unsigned long depth; depth=QuantumDepth; quantum=GetMagickQuantumDepth(&depth); if (depth != QuantumDepth) ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum); wand=(MagickWand *) AcquireMagickMemory(sizeof(*wand)); if (wand == (MagickWand *) NULL) { char *message; message=GetExceptionMessage(errno); ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed", message); message=DestroyString(message); } (void) ResetMagickMemory(wand,0,sizeof(*wand)); wand->id=AcquireWandId(); (void) FormatMagickString(wand->name,MaxTextExtent,"%s-%lu",MagickWandId, wand->id); wand->exception=AcquireExceptionInfo(); wand->image_info=AcquireImageInfo(); wand->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL); wand->images=NewImageList(); wand->debug=IsEventLogging(); if (wand->debug != MagickFalse) (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name); wand->signature=WandSignature; return(wand); }
static void _dispatch_magick_cmd(INTERNAL_FUNCTION_PARAMETERS, MagickCommand cmd, char *command) { zval *arr, **entry; HashPosition pos; int argc, i, k = -1; char *argv[32], **argvp; zval tval[32], *tvalp; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &arr) == FAILURE) { return; } /* Build command args */ argc = zend_hash_num_elements(Z_ARRVAL_P(arr)) + 1; if (argc > 32) { argvp = (char **) ecalloc(argc, sizeof(char *)); tvalp = (zval *) ecalloc(argc, sizeof(zval)); } else { argvp = argv; tvalp = tval; } argvp[0] = command; for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos), i = 1; zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **)&entry, &pos) == SUCCESS; zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos), ++i ) { if (Z_TYPE_PP(entry) == IS_ARRAY || Z_TYPE_PP(entry) == IS_OBJECT) { continue; } if (Z_TYPE_PP(entry) == IS_STRING) { argvp[i] = Z_STRVAL_PP(entry); } else { tvalp[++k] = **entry; zval_copy_ctor(&tvalp[k]); convert_to_string(&tvalp[k]); argvp[i] = Z_STRVAL(tvalp[k]); } } /* Imagick processes */ { MagickBooleanType result; ImageInfo *ii; ExceptionInfo *ei; char *metadata = NULL; ii = AcquireImageInfo(); ei = AcquireExceptionInfo(); result = (cmd)(ii, argc, argvp, &metadata, ei); if (ei->reason) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ei->reason); } if (metadata) { RETVAL_STRING(metadata, 1); } else { RETVAL_BOOL(result); } if (metadata) { DestroyString(metadata); } DestroyImageInfo(ii); DestroyExceptionInfo(ei); } /* Release resources */ while (k != -1) { zval_dtor(&tvalp[k--]); } if (argvp != argv) { efree(argvp); efree(tvalp); } }
void printImageProperties( std::string path ) { try { Image *image; ImageInfo *image_info; // Read a file into image object image_info = AcquireImageInfo(); GetImageInfo( image_info ); strcpy( image_info -> filename, path.c_str() ); ExceptionInfo* exceptionsInfo = AcquireExceptionInfo(); GetExceptionInfo( exceptionsInfo ); image = ReadImage( image_info, exceptionsInfo ); std::string imageType; switch( image->type ) { case UndefinedType : imageType = "Undefined type of image"; break; case BilevelType : imageType = "Bilevel image"; break; case GrayscaleType : imageType = "Grayscale image"; break; case GrayscaleMatteType : imageType = "Grayscale image with opacity"; break; case PaletteType : imageType = "Indexed color image"; break; case PaletteMatteType : imageType = "Indexed color image with opacity"; break; case TrueColorType : imageType = "Truecolor image"; break; case TrueColorMatteType : imageType = "Truecolor image with opacity"; break; case ColorSeparationType : imageType = "Cyan/Yellow/Magenta/Black (CYMK) image"; break; case ColorSeparationMatteType : imageType = "Cyan/Yellow/Magenta/Black (CYMK) image with opacity"; break; case OptimizeType : imageType = "Optimize image"; break; case 11 : imageType = "Indexed bilevel image with opacity"; break; // PaletteBilevelMatteType } std::string resolutionType; switch( image->units ) { case UndefinedResolution : resolutionType = " [unknown units]"; break; case PixelsPerInchResolution : resolutionType = " [dpi]"; break; case PixelsPerCentimeterResolution : resolutionType = " [pixels/cm]"; break; } std::string colorSpaceType; switch( image->colorspace ) { case UndefinedColorspace : colorSpaceType = "unknown color space"; break; case RGBColorspace : colorSpaceType = "RGB"; break; case GRAYColorspace : colorSpaceType = "Gray"; break; case TransparentColorspace : colorSpaceType = "Transparent"; break; case OHTAColorspace : colorSpaceType = "OHTA"; break; case XYZColorspace : colorSpaceType = "XYZ"; break; case YCbCrColorspace : colorSpaceType = "Y Cb Cr"; break; case YCCColorspace : colorSpaceType = "YCC"; break; case YIQColorspace : colorSpaceType = "YIQ"; break; case YPbPrColorspace : colorSpaceType = "Y Pb Pr"; break; case YUVColorspace : colorSpaceType = "YUV"; break; case CMYKColorspace : colorSpaceType = "CMYK"; break; case sRGBColorspace : colorSpaceType = "sRGB"; break; case LabColorspace : colorSpaceType = "Lab"; break; case 14 : colorSpaceType = "HSB"; break; // HSBColorspace case HSLColorspace : colorSpaceType = "HSL"; break; case HWBColorspace : colorSpaceType = "HWB"; break; case Rec601LumaColorspace : colorSpaceType = "Rec601 Luma"; break; case 18 : colorSpaceType = "Rec601 Y Cb Cr"; break; // Rec601YCbCrColorspace case Rec709LumaColorspace : colorSpaceType = "Rec709 Luma"; break; case 20 : colorSpaceType = "Rec709 Y Cb Cr"; break; // Rec709YCbCrColorspace case LogColorspace : colorSpaceType = "Log"; break; case 22 : colorSpaceType = "CMY"; break; // CMYColorspace } std::string interlaceType; switch( image->interlace ) { case UndefinedInterlace : interlaceType = "undefined"; break; case NoInterlace : interlaceType = "no interlacing"; break; case LineInterlace : interlaceType = "line interlacing"; break; case PlaneInterlace : interlaceType = "plane interlacing"; break; case PartitionInterlace : interlaceType = "partition interlacing"; break; case 5 : interlaceType = "GIF interlacing"; break; // GIFInterlace case 6 : interlaceType = "Jpeg interlacing"; break; // JPEGInterlace case 7 : interlaceType = "PNG interlacing"; break; // PNGInterlace } TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "width" << image->columns ); TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "height" << image->rows ); TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "bit-depth" << image->depth << " bits" ); TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "compression quality" << image->quality ); TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "image type" << imageType ); TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "" ); TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "x resolution" << image->x_resolution << resolutionType ); TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "y resolution" << image->y_resolution << resolutionType ); TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "interlacing" << interlaceType ); TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "" ); //TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "format" << image->format() ); TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "channels" << colorSpaceType << ( GetImageAlphaChannel(image)==MagickTrue ? std::string("A") : "" ) ); TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "color space" << colorSpaceType ); TUTTLE_COUT( std::setw(FIRST_COLUMN_WIDTH) << "gamma" << image->gamma ); TUTTLE_COUT( "" ); } catch( ... ) { TUTTLE_COUT( "Caught exception" << "\n" ); } }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G l o b E x p r e s s i o n % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GlobExpression() returns MagickTrue if the expression matches the pattern. % % The format of the GlobExpression function is: % % MagickBooleanType GlobExpression(const char *expression, % const char *pattern,const MagickBooleanType case_insensitive) % % A description of each parameter follows: % % o expression: Specifies a pointer to a text string containing a file name. % % o pattern: Specifies a pointer to a text string containing a pattern. % % o case_insensitive: set to MagickTrue to ignore the case when matching % an expression. % */ MagickExport MagickBooleanType GlobExpression(const char *expression, const char *pattern,const MagickBooleanType case_insensitive) { MagickBooleanType done, match; register const char *p; /* Return on empty pattern or '*'. */ if (pattern == (char *) NULL) return(MagickTrue); if (GetUTFCode(pattern) == 0) return(MagickTrue); if (LocaleCompare(pattern,"*") == 0) return(MagickTrue); p=pattern+strlen(pattern)-1; if ((GetUTFCode(p) == ']') && (strchr(pattern,'[') != (char *) NULL)) { ExceptionInfo *exception; ImageInfo *image_info; /* Determine if pattern is a scene, i.e. img0001.pcd[2]. */ image_info=AcquireImageInfo(); (void) CopyMagickString(image_info->filename,pattern,MaxTextExtent); exception=AcquireExceptionInfo(); (void) SetImageInfo(image_info,MagickTrue,exception); exception=DestroyExceptionInfo(exception); if (LocaleCompare(image_info->filename,pattern) != 0) { image_info=DestroyImageInfo(image_info); return(MagickFalse); } image_info=DestroyImageInfo(image_info); } /* Evaluate glob expression. */ done=MagickFalse; while ((GetUTFCode(pattern) != 0) && (done == MagickFalse)) { if (GetUTFCode(expression) == 0) if ((GetUTFCode(pattern) != '{') && (GetUTFCode(pattern) != '*')) break; switch (GetUTFCode(pattern)) { case '\\': { pattern+=GetUTFOctets(pattern); if (GetUTFCode(pattern) != 0) pattern+=GetUTFOctets(pattern); break; } case '*': { MagickBooleanType status; status=MagickFalse; pattern+=GetUTFOctets(pattern); while ((GetUTFCode(expression) != 0) && (status == MagickFalse)) { status=GlobExpression(expression,pattern,case_insensitive); expression+=GetUTFOctets(expression); } if (status != MagickFalse) { while (GetUTFCode(expression) != 0) expression+=GetUTFOctets(expression); while (GetUTFCode(pattern) != 0) pattern+=GetUTFOctets(pattern); } break; } case '[': { long c; pattern+=GetUTFOctets(pattern); for ( ; ; ) { if ((GetUTFCode(pattern) == 0) || (GetUTFCode(pattern) == ']')) { done=MagickTrue; break; } if (GetUTFCode(pattern) == '\\') { pattern+=GetUTFOctets(pattern); if (GetUTFCode(pattern) == 0) { done=MagickTrue; break; } } if (GetUTFCode(pattern+GetUTFOctets(pattern)) == '-') { c=GetUTFCode(pattern); pattern+=GetUTFOctets(pattern); pattern+=GetUTFOctets(pattern); if (GetUTFCode(pattern) == ']') { done=MagickTrue; break; } if (GetUTFCode(pattern) == '\\') { pattern+=GetUTFOctets(pattern); if (GetUTFCode(pattern) == 0) { done=MagickTrue; break; } } if ((GetUTFCode(expression) < c) || (GetUTFCode(expression) > GetUTFCode(pattern))) { pattern+=GetUTFOctets(pattern); continue; } } else if (GetUTFCode(pattern) != GetUTFCode(expression)) { pattern+=GetUTFOctets(pattern); continue; } pattern+=GetUTFOctets(pattern); while ((GetUTFCode(pattern) != ']') && (GetUTFCode(pattern) != 0)) { if ((GetUTFCode(pattern) == '\\') && (GetUTFCode(pattern+GetUTFOctets(pattern)) > 0)) pattern+=GetUTFOctets(pattern); pattern+=GetUTFOctets(pattern); } if (GetUTFCode(pattern) != 0) { pattern+=GetUTFOctets(pattern); expression+=GetUTFOctets(expression); } break; } break; } case '?': { pattern+=GetUTFOctets(pattern); expression+=GetUTFOctets(expression); break; } case '{': { register const char *p; pattern+=GetUTFOctets(pattern); while ((GetUTFCode(pattern) != '}') && (GetUTFCode(pattern) != 0)) { p=expression; match=MagickTrue; while ((GetUTFCode(p) != 0) && (GetUTFCode(pattern) != 0) && (GetUTFCode(pattern) != ',') && (GetUTFCode(pattern) != '}') && (match != MagickFalse)) { if (GetUTFCode(pattern) == '\\') pattern+=GetUTFOctets(pattern); match=(GetUTFCode(pattern) == GetUTFCode(p)) ? MagickTrue : MagickFalse; p+=GetUTFOctets(p); pattern+=GetUTFOctets(pattern); } if (GetUTFCode(pattern) == 0) { match=MagickFalse; done=MagickTrue; break; } else if (match != MagickFalse) { expression=p; while ((GetUTFCode(pattern) != '}') && (GetUTFCode(pattern) != 0)) { pattern+=GetUTFOctets(pattern); if (GetUTFCode(pattern) == '\\') { pattern+=GetUTFOctets(pattern); if (GetUTFCode(pattern) == '}') pattern+=GetUTFOctets(pattern); } } } else { while ((GetUTFCode(pattern) != '}') && (GetUTFCode(pattern) != ',') && (GetUTFCode(pattern) != 0)) { pattern+=GetUTFOctets(pattern); if (GetUTFCode(pattern) == '\\') { pattern+=GetUTFOctets(pattern); if ((GetUTFCode(pattern) == '}') || (GetUTFCode(pattern) == ',')) pattern+=GetUTFOctets(pattern); } } } if (GetUTFCode(pattern) != 0) pattern+=GetUTFOctets(pattern); } break; } default: { if (case_insensitive != MagickFalse) { if (tolower((int) GetUTFCode(expression)) != tolower((int) GetUTFCode(pattern))) { done=MagickTrue; break; } } else if (GetUTFCode(expression) != GetUTFCode(pattern)) { done=MagickTrue; break; } expression+=GetUTFOctets(expression); pattern+=GetUTFOctets(pattern); } } } while (GetUTFCode(pattern) == '*') pattern+=GetUTFOctets(pattern); match=(GetUTFCode(expression) == 0) && (GetUTFCode(pattern) == 0) ? MagickTrue : MagickFalse; return(match); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % M a i n % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % */ int main(int argc,char **argv) { char *option; double elapsed_time, user_time; ExceptionInfo *exception; ImageInfo *image_info; MagickBooleanType regard_warnings, status; register long i; TimerInfo timer; unsigned long iterations; MagickCoreGenesis(*argv,MagickTrue); exception=AcquireExceptionInfo(); iterations=1; status=MagickFalse; regard_warnings=MagickFalse; for (i=1; i < (long) (argc-1); i++) { option=argv[i]; if ((strlen(option) == 1) || ((*option != '-') && (*option != '+'))) continue; if (LocaleCompare("bench",option+1) == 0) iterations=(unsigned long) atol(argv[++i]); if (LocaleCompare("debug",option+1) == 0) (void) SetLogEventMask(argv[++i]); if (LocaleCompare("regard-warnings",option+1) == 0) regard_warnings=MagickTrue; } GetTimerInfo(&timer); for (i=0; i < (long) iterations; i++) { image_info=AcquireImageInfo(); status=ConvertImageCommand(image_info,argc,argv,(char **) NULL,exception); if (exception->severity != UndefinedException) { if ((exception->severity > ErrorException) || (regard_warnings != MagickFalse)) status=MagickTrue; CatchException(exception); } image_info=DestroyImageInfo(image_info); } if (iterations > 1) { elapsed_time=GetElapsedTime(&timer); user_time=GetUserTime(&timer); (void) fprintf(stderr,"Performance: %lui %gips %0.3fu %ld:%02ld\n", iterations,1.0*iterations/elapsed_time,user_time,(long) (elapsed_time/60.0+0.5),(long) ceil(fmod(elapsed_time,60.0))); } exception=DestroyExceptionInfo(exception); MagickCoreTerminus(); return(status == MagickFalse ? 0 : 1); }
int main(int argc,char **argv) { #define DestroyValidate() \ { \ timer=DestroyTimerInfo(timer); \ image_info=DestroyImageInfo(image_info); \ exception=DestroyExceptionInfo(exception); \ } #define ThrowValidateException(asperity,tag,option) \ { \ (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \ option); \ CatchException(exception); \ DestroyValidate(); \ return(MagickFalse); \ } char output_filename[MaxTextExtent], reference_filename[MaxTextExtent], *option; double elapsed_time, user_time; ExceptionInfo *exception; Image *reference_image; ImageInfo *image_info; MagickBooleanType regard_warnings, status; register long i; TimerInfo *timer; unsigned long fail, iterations, tests; ValidateType type; /* Validate the ImageMagick image processing suite. */ MagickCoreGenesis(*argv,MagickFalse); iterations=1; status=MagickFalse; type=AllValidate; regard_warnings=MagickFalse; exception=AcquireExceptionInfo(); image_info=AcquireImageInfo(); (void) CopyMagickString(image_info->filename,ReferenceFilename,MaxTextExtent); timer=AcquireTimerInfo(); GetTimerInfo(timer); for (i=1; i < (long) argc; i++) { option=argv[i]; if (IsMagickOption(option) == MagickFalse) { (void) CopyMagickString(image_info->filename,option,MaxTextExtent); continue; } switch (*(option+1)) { case 'b': { if (LocaleCompare("bench",option+1) == 0) { iterations=(unsigned long) atol(argv[++i]); break; } ThrowValidateException(OptionError,"UnrecognizedOption",option) } case 'd': { if (LocaleCompare("debug",option+1) == 0) { (void) SetLogEventMask(argv[++i]); break; } ThrowValidateException(OptionError,"UnrecognizedOption",option) } case 'h': { if (LocaleCompare("help",option+1) == 0) { (void) ValidateUsage(); return(0); } ThrowValidateException(OptionError,"UnrecognizedOption",option) } case 'l': { if (LocaleCompare("log",option+1) == 0) { if (*option != '+') (void) SetLogFormat(argv[i+1]); break; } ThrowValidateException(OptionError,"UnrecognizedOption",option) } case 'r': { if (LocaleCompare("regard-warnings",option+1) == 0) { regard_warnings=MagickTrue; break; } ThrowValidateException(OptionError,"UnrecognizedOption",option) } case 'v': { if (LocaleCompare("validate",option+1) == 0) { long validate; if (*option == '+') break; i++; if (i == (long) argc) ThrowValidateException(OptionError,"MissingArgument",option); validate=ParseMagickOption(MagickValidateOptions,MagickFalse, argv[i]); if (validate < 0) ThrowValidateException(OptionError,"UnrecognizedValidateType", argv[i]); type=(ValidateType) validate; break; } if ((LocaleCompare("version",option+1) == 0) || (LocaleCompare("-version",option+1) == 0)) { (void) fprintf(stdout,"Version: %s\n", GetMagickVersion((unsigned long *) NULL)); (void) fprintf(stdout,"Copyright: %s\n\n",GetMagickCopyright()); return(0); } ThrowValidateException(OptionError,"UnrecognizedOption",option) } default: ThrowValidateException(OptionError,"UnrecognizedOption",option) } } reference_image=ReadImage(image_info,exception); tests=0; fail=0; if (reference_image == (Image *) NULL) fail++; else { if (LocaleCompare(image_info->filename,ReferenceFilename) == 0) (void) CopyMagickString(reference_image->magick,ReferenceImageFormat, MaxTextExtent); (void) AcquireUniqueFilename(reference_filename); (void) AcquireUniqueFilename(output_filename); (void) CopyMagickString(reference_image->filename,reference_filename, MaxTextExtent); status=WriteImage(image_info,reference_image); InheritException(exception,&reference_image->exception); reference_image=DestroyImage(reference_image); if (status == MagickFalse) fail++; else { (void) fprintf(stdout,"Version: %s\n", GetMagickVersion((unsigned long *) NULL)); (void) fprintf(stdout,"Copyright: %s\n\n", GetMagickCopyright()); (void) fprintf(stdout,"ImageMagick Validation Suite (%s)\n\n", MagickOptionToMnemonic(MagickValidateOptions,(long) type)); if ((type & CompareValidate) != 0) tests+=ValidateCompareCommand(image_info,reference_filename, output_filename,&fail,exception); if ((type & CompositeValidate) != 0) tests+=ValidateCompositeCommand(image_info,reference_filename, output_filename,&fail,exception); if ((type & ConvertValidate) != 0) tests+=ValidateConvertCommand(image_info,reference_filename, output_filename,&fail,exception); if ((type & FormatsInMemoryValidate) != 0) tests+=ValidateImageFormatsInMemory(image_info,reference_filename, output_filename,&fail,exception); if ((type & FormatsOnDiskValidate) != 0) tests+=ValidateImageFormatsOnDisk(image_info,reference_filename, output_filename,&fail,exception); if ((type & IdentifyValidate) != 0) tests+=ValidateIdentifyCommand(image_info,reference_filename, output_filename,&fail,exception); if ((type & ImportExportValidate) != 0) tests+=ValidateImportExportPixels(image_info,reference_filename, output_filename,&fail,exception); if ((type & MontageValidate) != 0) tests+=ValidateMontageCommand(image_info,reference_filename, output_filename,&fail,exception); if ((type & StreamValidate) != 0) tests+=ValidateStreamCommand(image_info,reference_filename, output_filename,&fail,exception); (void) fprintf(stdout,"validation suite: %lu tests; %lu passed; " "%lu failed.\n",tests,tests-fail,fail); } (void) RelinquishUniqueFileResource(output_filename); (void) RelinquishUniqueFileResource(reference_filename); } if (exception->severity != UndefinedException) CatchException(exception); if (iterations > 1) { elapsed_time=GetElapsedTime(timer); user_time=GetUserTime(timer); (void) fprintf(stderr,"Performance: %lui %gips %0.3fu %ld:%02ld\n", iterations,1.0*iterations/elapsed_time,user_time,(long) (elapsed_time/60.0+0.5),(long) ceil(fmod(elapsed_time,60.0))); } DestroyValidate(); MagickCoreTerminus(); return(fail == 0 ? 0 : 1); }
int main(int argc,char **argv) { #define ThrowImageException(image) \ { \ \ CatchException(exception); \ if (contrast_image != (Image *) NULL) \ contrast_image=DestroyImage(contrast_image); \ exit(-1); \ } #define ThrowViewException(view) \ { \ char \ *description; \ \ ExceptionType \ severity; \ \ description=GetImageViewException(view,&severity); \ (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \ description=(char *) MagickRelinquishMemory(description); \ exit(-1); \ } ExceptionInfo *exception; Image *contrast_image; ImageInfo *image_info; ImageView *contrast_view; MagickBooleanType status; if (argc != 3) { (void) fprintf(stdout,"Usage: %s image sigmoidal-image\n",argv[0]); exit(0); } /* Read an image. */ MagickCoreGenesis(*argv,MagickTrue); image_info=AcquireImageInfo(); (void) CopyMagickString(image_info->filename,argv[1],MaxTextExtent); exception=AcquireExceptionInfo(); contrast_image=ReadImage(image_info,exception); if (contrast_image == (Image *) NULL) ThrowImageException(contrast_image); /* Sigmoidal non-linearity contrast control. */ contrast_view=NewImageView(contrast_image); if (contrast_view == (ImageView *) NULL) ThrowImageException(contrast_image); status=UpdateImageViewIterator(contrast_view,SigmoidalContrast,(void *) NULL); if (status == MagickFalse) ThrowImageException(contrast_image); contrast_view=DestroyImageView(contrast_view); /* Write the image then destroy it. */ status=WriteImages(image_info,contrast_image,argv[2],exception); if (status == MagickFalse) ThrowImageException(contrast_image); contrast_image=DestroyImage(contrast_image); exception=DestroyExceptionInfo(exception); image_info=DestroyImageInfo(image_info); MagickCoreTerminus(); return(0); }
static int MagickMain(int argc,char **argv) { #define MagickCommandSize(name,use_metadata,command) \ { (name), sizeof(name)-1, (use_metadata), (command) } typedef struct _CommandInfo { const char *client_name; size_t extent; MagickBooleanType use_metadata; MagickCommand command; } CommandInfo; const CommandInfo MagickCommands[] = { MagickCommandSize("magick", MagickFalse, MagickImageCommand), MagickCommandSize("convert", MagickFalse, ConvertImageCommand), MagickCommandSize("composite", MagickFalse, CompositeImageCommand), MagickCommandSize("identify", MagickTrue, IdentifyImageCommand), MagickCommandSize("animate", MagickFalse, AnimateImageCommand), MagickCommandSize("compare", MagickTrue, CompareImagesCommand), MagickCommandSize("conjure", MagickFalse, ConjureImageCommand), MagickCommandSize("display", MagickFalse, DisplayImageCommand), MagickCommandSize("import", MagickFalse, ImportImageCommand), MagickCommandSize("mogrify", MagickFalse, MogrifyImageCommand), MagickCommandSize("montage", MagickFalse, MontageImageCommand), MagickCommandSize("stream", MagickFalse, StreamImageCommand) }; char client_name[MagickPathExtent], *metadata; ExceptionInfo *exception; ImageInfo *image_info; int exit_code, offset; MagickBooleanType status; register ssize_t i; size_t number_commands; MagickCoreGenesis(*argv,MagickTrue); exception=AcquireExceptionInfo(); image_info=AcquireImageInfo(); GetPathComponent(argv[0],TailPath,client_name); number_commands=sizeof(MagickCommands)/sizeof(MagickCommands[0]); for (i=0; i < (ssize_t) number_commands; i++) { offset=LocaleNCompare(MagickCommands[i].client_name,client_name, MagickCommands[i].extent); if (offset == 0) break; } i%=(number_commands); if ((i == 0) && (argc > 1)) { for (i=1; i < (ssize_t) number_commands; i++) { offset=LocaleCompare(MagickCommands[i].client_name,argv[1]); if (offset == 0) { argc--; argv++; break; } } i%=number_commands; } metadata=(char *) NULL; status=MagickCommandGenesis(image_info,MagickCommands[i].command,argc,argv, MagickCommands[i].use_metadata ? &metadata : (char **) NULL,exception); if (metadata != (char *) NULL) { (void) fputs(metadata,stdout); metadata=DestroyString(metadata); } if (MagickCommands[i].command != CompareImagesCommand) exit_code=status != MagickFalse ? 0 : 1; else { if (status == MagickFalse) exit_code=2; else { const char *option; option=GetImageOption(image_info,"compare:dissimilar"); exit_code=IsStringTrue(option) ? 1 : 0; } } image_info=DestroyImageInfo(image_info); exception=DestroyExceptionInfo(exception); MagickCoreTerminus(); return(exit_code); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + A c q u i r e W a n d C L I % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireMagickCLI() creates a new CLI wand (an expanded form of Magick % Wand). The given image_info and exception is included as is if provided. % % Use DestroyMagickCLI() to dispose of the CLI wand when it is no longer % needed. % % The format of the NewMagickWand method is: % % MagickCLI *AcquireMagickCLI(ImageInfo *image_info, % ExceptionInfo *exception) % */ WandExport MagickCLI *AcquireMagickCLI(ImageInfo *image_info, ExceptionInfo *exception) { MagickCLI *cli_wand; /* precaution - as per NewMagickWand() */ { size_t depth = MAGICKCORE_QUANTUM_DEPTH; const char *quantum = GetMagickQuantumDepth(&depth); if (depth != MAGICKCORE_QUANTUM_DEPTH) ThrowWandFatalException(WandError,"QuantumDepthMismatch",quantum); } /* allocate memory for MgaickCLI */ cli_wand=(MagickCLI *) AcquireMagickMemory(sizeof(*cli_wand)); if (cli_wand == (MagickCLI *) NULL) { ThrowWandFatalException(ResourceLimitFatalError,"MemoryAllocationFailed", GetExceptionMessage(errno)); return((MagickCLI *)NULL); } /* Initialize Wand Part of MagickCLI FUTURE: this is a repeat of code from NewMagickWand() However some parts may be given fro man external source! */ cli_wand->wand.id=AcquireWandId(); (void) FormatLocaleString(cli_wand->wand.name,MaxTextExtent, "%s-%.20g","MagickWandCLI", (double) cli_wand->wand.id); cli_wand->wand.images=NewImageList(); if ( image_info == (ImageInfo *)NULL) cli_wand->wand.image_info=AcquireImageInfo(); else cli_wand->wand.image_info=image_info; if ( exception == (ExceptionInfo *)NULL) cli_wand->wand.exception=AcquireExceptionInfo(); else cli_wand->wand.exception=exception; cli_wand->wand.debug=IsEventLogging(); cli_wand->wand.signature=WandSignature; /* Initialize CLI Part of MagickCLI */ cli_wand->draw_info=CloneDrawInfo(cli_wand->wand.image_info,(DrawInfo *) NULL); cli_wand->quantize_info=AcquireQuantizeInfo(cli_wand->wand.image_info); cli_wand->process_flags=MagickCommandOptionFlags; /* assume "magick" CLI */ cli_wand->command=(const OptionInfo *)NULL; /* no option at this time */ cli_wand->image_list_stack=(Stack *)NULL; cli_wand->image_info_stack=(Stack *)NULL; /* default exception location... EG: sprintf(locaiton, filename, line, column); */ cli_wand->location="from \"%s\""; /* location format using arguments: */ /* filename, line, column */ cli_wand->filename="unknown"; /* script filename, unknown source */ cli_wand->line=0; /* line from script OR CLI argument */ cli_wand->column=0; /* column from script */ cli_wand->signature=WandSignature; if (IfMagickTrue(cli_wand->wand.debug)) (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",cli_wand->wand.name); return(cli_wand); }