From b9dbc296c59e91df014757130b4e584c7fb6c74d Mon Sep 17 00:00:00 2001 From: dirk Date: Sun, 26 Jul 2015 09:50:00 +0000 Subject: [PATCH] Removed IsMagickTrue, IsMagickFalse, IsMagickNot. Fixed memory leak in operation.c. --- MagickCore/color.c | 74 +++++++++++++++++++-------------------- MagickCore/delegate.c | 70 ++++++++++++++++++------------------ MagickCore/display.c | 37 +++++++++++--------- MagickCore/hashmap.c | 17 +++++---- MagickCore/magick-type.h | 10 ------ MagickCore/methods.h | 1 - MagickCore/option.c | 4 +-- MagickCore/property.c | 26 +++++++------- MagickCore/token.h | 3 -- MagickWand/magick-cli.c | 2 +- MagickWand/magick-image.c | 12 ++++--- MagickWand/operation.c | 52 ++++++++++++++------------- MagickWand/wandcli.c | 10 +++--- 13 files changed, 163 insertions(+), 155 deletions(-) diff --git a/MagickCore/color.c b/MagickCore/color.c index dd6a395a1..05a26c87d 100644 --- a/MagickCore/color.c +++ b/MagickCore/color.c @@ -1303,8 +1303,8 @@ MagickExport const ColorInfo **GetColorInfoList(const char *pattern, p=(const ColorInfo *) GetNextValueInLinkedList(color_cache); for (i=0; p != (const ColorInfo *) NULL; ) { - if (IsMagickFalse(p->stealth) && - IsMagickTrue(GlobExpression(p->name,pattern,MagickFalse))) + if ((p->stealth == MagickFalse) && + (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) colors[i++]=p; p=(const ColorInfo *) GetNextValueInLinkedList(color_cache); } @@ -1396,8 +1396,8 @@ MagickExport char **GetColorList(const char *pattern, p=(const ColorInfo *) GetNextValueInLinkedList(color_cache); for (i=0; p != (const ColorInfo *) NULL; ) { - if (IsMagickFalse(p->stealth) && - IsMagickTrue(GlobExpression(p->name,pattern,MagickFalse))) + if ((p->stealth == MagickFalse) && + (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) colors[i++]=ConstantString(p->name); p=(const ColorInfo *) GetNextValueInLinkedList(color_cache); } @@ -1437,6 +1437,29 @@ MagickExport char **GetColorList(const char *pattern, % */ +static inline MagickBooleanType IsSVGCompliant(const PixelInfo *pixel) +{ +#define SVGCompliant(component) ((double) \ + ScaleCharToQuantum(ScaleQuantumToChar(ClampToQuantum(component)))) + + /* + SVG requires color depths > 8 expressed as percentages. + */ + if (fabs(SVGCompliant(pixel->red)-pixel->red) >= MagickEpsilon) + return(MagickFalse); + if (fabs(SVGCompliant(pixel->green)-pixel->green) >= MagickEpsilon) + return(MagickFalse); + if (fabs(SVGCompliant(pixel->blue)-pixel->blue) >= MagickEpsilon) + return(MagickFalse); + if ((pixel->colorspace == CMYKColorspace) && + (fabs(SVGCompliant(pixel->black)-pixel->black) >= MagickEpsilon)) + return(MagickFalse); + if ((pixel->alpha_trait != UndefinedPixelTrait) && + (fabs(SVGCompliant(pixel->alpha)-pixel->alpha) >= MagickEpsilon)) + return(MagickFalse); + return(MagickTrue); +} + static void ConcatentateHexColorComponent(const PixelInfo *pixel, const PixelChannel channel,char *tuple) { @@ -1534,32 +1557,8 @@ MagickExport void GetColorTuple(const PixelInfo *pixel, Convert pixel to rgb() or cmyk() color. */ color=(*pixel); - if (color.depth > 8) - { -#define SVGCompliant(component) ((double) \ - ScaleCharToQuantum(ScaleQuantumToChar(ClampToQuantum(component)))) - - MagickStatusType - status; - - /* - SVG requires color depths > 8 expressed as percentages. - */ - status=IsMagickTrue(fabs((double) (color.red- - SVGCompliant(color.red))) < MagickEpsilon); - status&=IsMagickTrue(fabs((double) (color.green- - SVGCompliant(color.green))) < MagickEpsilon); - status&=IsMagickTrue(fabs((double) (color.blue- - SVGCompliant(color.blue))) < MagickEpsilon); - if (color.colorspace == CMYKColorspace) - status&=IsMagickTrue(fabs((double) (color.black- - SVGCompliant(color.black))) < MagickEpsilon); - if (color.alpha_trait != UndefinedPixelTrait) - status&=IsMagickTrue(fabs((double) (color.alpha- - SVGCompliant(color.alpha))) < MagickEpsilon); - if (IfMagickTrue(status)) - color.depth=8; - } + if (color.depth > 8 && IsSVGCompliant(pixel) != MagickFalse) + color.depth=8; (void) ConcatenateMagickString(tuple,CommandOptionToMnemonic( MagickColorspaceOptions,(ssize_t) color.colorspace),MagickPathExtent); if (color.alpha_trait != UndefinedPixelTrait) @@ -1745,7 +1744,7 @@ MagickExport MagickBooleanType IsEquivalentImage(const Image *image, assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); - if (IfMagickTrue(image->debug)) + if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(target_image != (Image *) NULL); assert(target_image->signature == MagickCoreSignature); @@ -1774,7 +1773,7 @@ MagickExport MagickBooleanType IsEquivalentImage(const Image *image, if (q == (const Quantum *) NULL) break; GetPixelInfoPixel(image,q,&target); - if (IfMagickFalse(IsFuzzyEquivalencePixelInfo(&pixel,&target))) + if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse) break; } if (i < (ssize_t) target_image->columns) @@ -1792,7 +1791,7 @@ MagickExport MagickBooleanType IsEquivalentImage(const Image *image, proceed=SetImageProgress(image,SearchImageText,(MagickOffsetType) y, image->rows); - if( IfMagickFalse(proceed) ) + if (proceed == MagickFalse) status=MagickFalse; } } @@ -1800,9 +1799,9 @@ MagickExport MagickBooleanType IsEquivalentImage(const Image *image, image_view=DestroyCacheView(image_view); *x_offset=x; *y_offset=y; - if (IfMagickFalse(status)) + if (status == MagickFalse) return(status); - return(IsMagickTrue(y < (ssize_t) image->rows)); + return(y < (ssize_t) image->rows ? MagickTrue : MagickFalse); } /* @@ -2570,8 +2569,9 @@ MagickExport MagickBooleanType QueryColorname( if ( pixel.depth > 16 ) pixel.depth=16; } - GetColorTuple(&pixel,IsMagickTrue(compliance != SVGCompliance),name); - if (IfMagickFalse(IssRGBColorspace(pixel.colorspace))) + GetColorTuple(&pixel,compliance != SVGCompliance ? MagickTrue : MagickFalse, + name); + if (IssRGBColorspace(pixel.colorspace) == MagickFalse) return(MagickFalse); alpha=color->alpha_trait != UndefinedPixelTrait ? color->alpha : OpaqueAlpha; (void) GetColorInfo("*",exception); diff --git a/MagickCore/delegate.c b/MagickCore/delegate.c index 7f47f2245..0663077af 100644 --- a/MagickCore/delegate.c +++ b/MagickCore/delegate.c @@ -1099,7 +1099,7 @@ static MagickBooleanType CopyDelegateFile(const char *source, (void) close(destination_file); (void) close(source_file); buffer=(unsigned char *) RelinquishMagickMemory(buffer); - return(IsMagickTrue(i!=0)); + return(i != 0 ? MagickTrue : MagickFalse); } MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info, @@ -1135,32 +1135,32 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info, (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); rights=ExecutePolicyRights; - if( IfMagickFalse(IsRightsAuthorized(DelegatePolicyDomain,rights,decode)) ) + if (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse) { errno=EPERM; (void) ThrowMagickException(exception,GetMagickModule(),PolicyError, "NotAuthorized","`%s'",decode); return(MagickFalse); } - if( IfMagickFalse(IsRightsAuthorized(DelegatePolicyDomain,rights,encode)) ) + if (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse) { errno=EPERM; (void) ThrowMagickException(exception,GetMagickModule(),PolicyError, "NotAuthorized","`%s'",encode); return(MagickFalse); } - temporary=IsMagickTrue(*image->filename == '\0'); - if( IfMagickTrue(temporary) ) - if( IfMagickFalse(AcquireUniqueFilename(image->filename)) ) - { - ThrowFileException(exception,FileOpenError, - "UnableToCreateTemporaryFile",image->filename); - return(MagickFalse); - } + temporary=*image->filename == '\0' ? MagickTrue : MagickFalse; + if ((temporary != MagickFalse) && (AcquireUniqueFilename(image->filename) == + MagickFalse)) + { + ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile", + image->filename); + return(MagickFalse); + } delegate_info=GetDelegateInfo(decode,encode,exception); if (delegate_info == (DelegateInfo *) NULL) { - if( IfMagickTrue(temporary) ) + if (temporary != MagickFalse) (void) RelinquishUniqueFileResource(image->filename); (void) ThrowMagickException(exception,GetMagickModule(),DelegateError, "NoTagFound","`%s'",decode ? decode : encode); @@ -1168,9 +1168,9 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info, } if (*image_info->filename == '\0') { - if( IfMagickFalse(AcquireUniqueFilename(image_info->filename)) ) + if (AcquireUniqueFilename(image_info->filename) == MagickFalse) { - if( IfMagickTrue(temporary) ) + if (temporary != MagickFalse) (void) RelinquishUniqueFileResource(image->filename); ThrowFileException(exception,FileOpenError, "UnableToCreateTemporaryFile",image_info->filename); @@ -1195,13 +1195,13 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info, /* Delegate requires a particular image format. */ - if( IfMagickFalse(AcquireUniqueFilename(image_info->unique)) ) + if (AcquireUniqueFilename(image_info->unique) == MagickFalse) { ThrowFileException(exception,FileOpenError, "UnableToCreateTemporaryFile",image_info->unique); return(MagickFalse); } - if( IfMagickFalse(AcquireUniqueFilename(image_info->zero)) ) + if (AcquireUniqueFilename(image_info->zero) == MagickFalse) { (void) RelinquishUniqueFileResource(image_info->unique); ThrowFileException(exception,FileOpenError, @@ -1214,7 +1214,7 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info, { (void) RelinquishUniqueFileResource(image_info->unique); (void) RelinquishUniqueFileResource(image_info->zero); - if( IfMagickTrue(temporary) ) + if (temporary != MagickFalse) (void) RelinquishUniqueFileResource(image->filename); (void) ThrowMagickException(exception,GetMagickModule(), DelegateError,"DelegateFailed","`%s'",decode ? decode : encode); @@ -1240,18 +1240,18 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info, (void) FormatLocaleString(p->filename,MagickPathExtent,"%s:%s", delegate_info->decode,clone_info->filename); status=WriteImage(clone_info,p,exception); - if( IfMagickFalse(status) ) + if (status == MagickFalse) { (void) RelinquishUniqueFileResource(image_info->unique); (void) RelinquishUniqueFileResource(image_info->zero); - if( IfMagickTrue(temporary) ) + if (temporary != MagickFalse) (void) RelinquishUniqueFileResource(image->filename); clone_info=DestroyImageInfo(clone_info); (void) ThrowMagickException(exception,GetMagickModule(), DelegateError,"DelegateFailed","`%s'",decode ? decode : encode); return(MagickFalse); } - if( IfMagickTrue(clone_info->adjoin) ) + if (clone_info->adjoin != MagickFalse) break; } (void) RelinquishUniqueFileResource(image_info->unique); @@ -1272,19 +1272,20 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info, return(MagickFalse); } command=(char *) NULL; - status=MagickFalse; - (void) CopyMagickString(output_filename,image_info->filename,MagickPathExtent); + status=MagickTrue; + (void) CopyMagickString(output_filename,image_info->filename, + MagickPathExtent); (void) CopyMagickString(input_filename,image->filename,MagickPathExtent); for (i=0; commands[i] != (char *) NULL; i++) { - status=AcquireUniqueSymbolicLink(output_filename,image_info->filename); - if( IfMagickFalse(AcquireUniqueFilename(image_info->unique)) ) + (void) AcquireUniqueSymbolicLink(output_filename,image_info->filename); + if (AcquireUniqueFilename(image_info->unique) == MagickFalse) { ThrowFileException(exception,FileOpenError, "UnableToCreateTemporaryFile",image_info->unique); break; } - if( IfMagickFalse(AcquireUniqueFilename(image_info->zero)) ) + if (AcquireUniqueFilename(image_info->zero) == MagickFalse) { (void) RelinquishUniqueFileResource(image_info->unique); ThrowFileException(exception,FileOpenError, @@ -1294,23 +1295,24 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info, if (LocaleCompare(decode,"SCAN") != 0) { status=AcquireUniqueSymbolicLink(input_filename,image->filename); - if( IfMagickFalse(status) ) + if (status == MagickFalse) { ThrowFileException(exception,FileOpenError, "UnableToCreateTemporaryFile",input_filename); break; } } - status=MagickFalse; + status=MagickTrue; command=InterpretImageProperties(image_info,image,commands[i],exception); if (command != (char *) NULL) { /* Execute delegate. */ - status=IsMagickTrue(ExternalDelegateCommand(delegate_info->spawn, - image_info->verbose,command,(char *) NULL,exception) != 0); - if (IfMagickTrue(delegate_info->spawn)) + if (ExternalDelegateCommand(delegate_info->spawn,image_info->verbose, + command,(char *) NULL,exception) != 0) + status=MagickFalse; + if (delegate_info->spawn != MagickFalse) { ssize_t count; @@ -1331,13 +1333,13 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info, } if (CopyDelegateFile(image_info->filename,output_filename,MagickTrue) == MagickFalse) (void) RelinquishUniqueFileResource(output_filename); - if( IfMagickTrue(image_info->temporary) ) + if (image_info->temporary != MagickFalse) (void) RelinquishUniqueFileResource(image_info->filename); (void) RelinquishUniqueFileResource(image_info->unique); (void) RelinquishUniqueFileResource(image_info->zero); (void) RelinquishUniqueFileResource(image_info->filename); (void) RelinquishUniqueFileResource(image->filename); - if( IfMagickTrue(status) ) + if (status == MagickFalse) { (void) ThrowMagickException(exception,GetMagickModule(),DelegateError, "DelegateFailed","`%s'",commands[i]); @@ -1353,9 +1355,9 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info, for ( ; commands[i] != (char *) NULL; i++) commands[i]=DestroyString(commands[i]); commands=(char **) RelinquishMagickMemory(commands); - if( IfMagickTrue(temporary) ) + if (temporary != MagickFalse) (void) RelinquishUniqueFileResource(image->filename); - return(IsMagickFalse(status)); + return(status); } /* diff --git a/MagickCore/display.c b/MagickCore/display.c index 07ea459bf..7f3bf7aef 100644 --- a/MagickCore/display.c +++ b/MagickCore/display.c @@ -1767,7 +1767,7 @@ MagickExport MagickBooleanType RemoteDisplayCommand(const ImageInfo *image_info, (void) XSetErrorHandler(XError); status=XRemoteCommand(display,window,filename); (void) XCloseDisplay(display); - return(IsMagickTrue(status)); + return(status != 0 ? MagickTrue : MagickFalse); } /* @@ -2811,7 +2811,7 @@ static MagickBooleanType XBackgroundImage(Display *display, XCheckRefreshWindows(display,windows); background_resources=(*resource_info); background_resources.window_id=window_id; - background_resources.backdrop=IsMagickTrue(status); + background_resources.backdrop=status != 0 ? MagickTrue : MagickFalse; status=XDisplayBackgroundImage(display,&background_resources,*image, exception); if (IfMagickTrue(status)) @@ -3827,7 +3827,7 @@ static MagickBooleanType XColorEditImage(Display *display, AllCompliance,&draw_info->fill,exception); (void) FloodfillPaintImage(*image,draw_info,&target, (ssize_t)x_offset,(ssize_t)y_offset, - IsMagickFalse(method == FloodfillMethod),exception); + method != FloodfillMethod ? MagickTrue : MagickFalse,exception); draw_info=DestroyDrawInfo(draw_info); break; } @@ -4527,7 +4527,7 @@ static MagickBooleanType XConfigureImage(Display *display, (void) XReconfigureWMWindow(display,windows->icon.id,windows->icon.screen, (unsigned int) (CWWidth | CWHeight),&window_changes); XSetCursorState(display,windows,MagickFalse); - return(IsMagickTrue(status)); + return(status != 0 ? MagickTrue : MagickFalse); } /* @@ -6328,7 +6328,7 @@ static MagickBooleanType XDrawEditImage(Display *display, } XSetCursorState(display,windows,MagickFalse); coordinate_info=(XPoint *) RelinquishMagickMemory(coordinate_info); - return(IsMagickTrue(status)); + return(status != 0 ? MagickTrue : MagickFalse); } /* @@ -8404,7 +8404,7 @@ static Image *XMagickCommand(Display *display,XResourceInfo *resource_info, flags=ParseGeometry(geometry,&geometry_info); if ((flags & SigmaValue) == 0) geometry_info.sigma=1.0; - shade_image=ShadeImage(*image,IsMagickTrue(status), + shade_image=ShadeImage(*image,status != 0 ? MagickTrue : MagickFalse, geometry_info.rho,geometry_info.sigma,exception); if (shade_image != (Image *) NULL) { @@ -10165,7 +10165,7 @@ static MagickBooleanType XMatteEditImage(Display *display, channel_mask=SetImageChannelMask(*image,AlphaChannel); (void) FloodfillPaintImage(*image,draw_info,&target,(ssize_t) x_offset,(ssize_t) y_offset, - IsMagickFalse(method == FloodfillMethod),exception); + method != FloodfillMethod ? MagickTrue : MagickFalse,exception); (void) SetPixelChannelMask(*image,channel_mask); draw_info=DestroyDrawInfo(draw_info); break; @@ -11017,7 +11017,7 @@ static MagickBooleanType XPrintImage(Display *display, print_image=DestroyImage(print_image); image_info=DestroyImageInfo(image_info); XSetCursorState(display,windows,MagickFalse); - return(IsMagickTrue(status)); + return(status != 0 ? MagickTrue : MagickFalse); } /* @@ -12640,7 +12640,7 @@ static MagickBooleanType XSaveImage(Display *display, save_image=DestroyImage(save_image); image_info=DestroyImageInfo(image_info); XSetCursorState(display,windows,MagickFalse); - return(IsMagickTrue(status)); + return(status != 0 ? MagickTrue : MagickFalse); } /* @@ -13663,8 +13663,8 @@ static Image *XVisualDirectoryImage(Display *display, /* Read each image and convert them to a tile. */ - backdrop=IsMagickTrue( (windows->visual_info->klass == TrueColor) || - (windows->visual_info->klass == DirectColor) ); + backdrop=((windows->visual_info->klass == TrueColor) || + (windows->visual_info->klass == DirectColor)) ? MagickTrue : MagickFalse; read_info=CloneImageInfo(resource_info->image_info); (void) SetImageOption(read_info,"jpeg:size","120x120"); (void) CloneString(&read_info->size,DefaultTileGeometry); @@ -14018,7 +14018,7 @@ MagickExport MagickBooleanType XDisplayBackgroundImage(Display *display, delay=1000*image->delay/MagickMax(image->ticks_per_second,1L); XDelay(display,delay == 0UL ? 10UL : delay); (void) XSync(display,MagickFalse); - return(IsMagickTrue(window_info.id == root_window)); + return(window_info.id == root_window ? MagickTrue : MagickFalse); } /* @@ -15121,10 +15121,15 @@ MagickExport Image *XDisplayImage(Display *display,XResourceInfo *resource_info, } timestamp=time((time_t *) NULL); (void) XNextEvent(display,&event); - if (IfMagickFalse(windows->image.stasis) ) - windows->image.stasis=IsMagickTrue((time((time_t *) NULL)-timestamp) > 0); - if (IfMagickFalse(windows->magnify.stasis) ) - windows->magnify.stasis=IsMagickTrue((time((time_t *) NULL)-timestamp) > 0); + if ((windows->image.stasis == MagickFalse) || + (windows->magnify.stasis == MagickFalse)) + { + if ((time((time_t *) NULL)-timestamp) > 0) + { + windows->image.stasis=MagickTrue; + windows->magnify.stasis=MagickTrue; + } + } if (event.xany.window == windows->command.id) { /* diff --git a/MagickCore/hashmap.c b/MagickCore/hashmap.c index d0abfff8f..19e81c8c3 100644 --- a/MagickCore/hashmap.c +++ b/MagickCore/hashmap.c @@ -263,7 +263,7 @@ MagickExport MagickBooleanType CompareHashmapString(const void *target, p=(const char *) target; q=(const char *) source; - return(IsMagickTrue(LocaleCompare(p,q))); + return(LocaleCompare(p,q) == 0 ? MagickTrue : MagickFalse); } /* @@ -294,9 +294,14 @@ MagickExport MagickBooleanType CompareHashmapString(const void *target, */ MagickExport MagickBooleanType CompareHashmapStringInfo(const void *target, const void *source) -{ - return(IsMagickTrue(LocaleCompare((const char *)target, - (const char *)source))); +{ + const StringInfo + *p, + *q; + + p=(const StringInfo *) target; + q=(const StringInfo *) source; + return(CompareStringInfo(p,q) == 0 ? MagickTrue : MagickFalse); } /* @@ -1171,7 +1176,7 @@ MagickExport MagickBooleanType IsHashmapEmpty(const HashmapInfo *hashmap_info) { assert(hashmap_info != (HashmapInfo *) NULL); assert(hashmap_info->signature == MagickCoreSignature); - return(IsMagickTrue(hashmap_info->entries == 0)); + return(hashmap_info->entries == 0 ? MagickTrue : MagickFalse); } /* @@ -1201,7 +1206,7 @@ MagickExport MagickBooleanType IsLinkedListEmpty( { assert(list_info != (LinkedListInfo *) NULL); assert(list_info->signature == MagickCoreSignature); - return(IsMagickTrue(list_info->elements == 0)); + return(list_info->elements == 0 ? MagickTrue : MagickFalse); } /* diff --git a/MagickCore/magick-type.h b/MagickCore/magick-type.h index 20de3bfc6..3e1cb76bb 100644 --- a/MagickCore/magick-type.h +++ b/MagickCore/magick-type.h @@ -157,25 +157,15 @@ typedef enum IfMagickTrue() converts MagickBooleanType to C integer Boolean IfMagickFalse() Not the MagickBooleanType to C integer Boolean - - IsMagickTrue() converts a C integer boolean to a MagickBooleanType - IsMagickFalse() converts and is also a MagickBooleanType 'not' operation - */ #if 1 /* Fast C typing method assumes MagickBooleanType match 0,1 values */ # define IfMagickTrue(v) ((int)(v)) # define IfMagickFalse(v) (!(int)(v)) -# define IsMagickTrue(v) ((MagickBooleanType)((int)(v)!=0)) -# define IsMagickFalse(v) ((MagickBooleanType)(!(int)(v))) -# define IsMagickNot(v) ((MagickBooleanType)(!(int)(v))) #else /* Do not depend MagickBooleanType's values */ # define IfMagickTrue(v) ((v) != MagickFalse) # define IfMagickFalse(v) ((v) == MagickFalse) -# define IsMagickTrue(v) ((v)?MagickTrue:MagickFalse) -# define IsMagickFalse(v) ((v)?MagickFalse:MagickTrue) -# define IsMagickNot(v) (IfMagickTrue(v)?MagickFalse:MagickTrue) #endif /* diff --git a/MagickCore/methods.h b/MagickCore/methods.h index d64afd316..6b3341aef 100644 --- a/MagickCore/methods.h +++ b/MagickCore/methods.h @@ -667,7 +667,6 @@ extern "C" { #define IsMagickConflict PrependMagickMethod(IsMagickConflict) #define IsMagickInstantiated PrependMagickMethod(IsMagickInstantiated) #define IsCommandOption PrependMagickMethod(IsCommandOption) -#define IsMagickTrue PrependMagickMethod(IsMagickTrue) #define IsImageMonochrome PrependMagickMethod(IsImageMonochrome) #define IsEquivalentAlpha PrependMagickMethod(IsEquivalentAlpha) #define IsImageOpaque PrependMagickMethod(IsImageOpaque) diff --git a/MagickCore/option.c b/MagickCore/option.c index 20e2cded6..6815d7613 100644 --- a/MagickCore/option.c +++ b/MagickCore/option.c @@ -2283,8 +2283,8 @@ MagickExport MagickBooleanType IsCommandOption(const char *option) if ((*option != '-') && (*option != '+')) return(MagickFalse); if (strlen(option) == 1) - return(IsMagickTrue((*option == '{') || (*option == '}') || - (*option == '[') || (*option == ']') )); + return(((*option == '{') || (*option == '}') || (*option == '[') || + (*option == ']')) ? MagickTrue : MagickFalse); option++; if (*option == '-') return(MagickTrue); diff --git a/MagickCore/property.c b/MagickCore/property.c index 1307a3a67..50c78bb69 100644 --- a/MagickCore/property.c +++ b/MagickCore/property.c @@ -3265,7 +3265,7 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info, interpret_text=AcquireString(embed_text); /* new string with extra space */ extent=MagickPathExtent; /* allocated space in string */ number=MagickFalse; /* is last char a number? */ - for (q=interpret_text; *p!='\0'; number=IsMagickTrue(isdigit(*p)),p++) + for (q=interpret_text; *p!='\0'; number=isdigit(*p) ? MagickTrue : MagickFalse,p++) { *q='\0'; ExtendInterpretText(MagickPathExtent); @@ -3333,7 +3333,7 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info, *string; /* But only if not preceeded by a number! */ - if ( IfMagickTrue(number) ) { + if (number != MagickFalse) { *q++='%'; /* do NOT substitute the percent */ p--; /* back up one */ continue; @@ -3433,7 +3433,7 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info, status=FxEvaluateChannelExpression(fx_info,IntensityPixelChannel,0,0, &value,exception); fx_info=DestroyFxInfo(fx_info); - if( IfMagickTrue(status) ) + if (status != MagickFalse) { char result[MagickPathExtent]; @@ -3485,7 +3485,7 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info, &value,exception); pixel.alpha=(double) QuantumRange*value; fx_info=DestroyFxInfo(fx_info); - if( IfMagickTrue(status) ) + if (status != MagickFalse) { char name[MagickPathExtent]; @@ -3504,11 +3504,11 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info, OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern); continue; /* else no image to retrieve artifact */ } - if( IfMagickTrue(IsGlob(pattern+7)) ) + if (IsGlob(pattern+7) != MagickFalse) { ResetImageOptionIterator(image_info); while ((key=GetNextImageOption(image_info)) != (const char *) NULL) - if( IfMagickTrue(GlobExpression(key,pattern+7,MagickTrue)) ) + if (GlobExpression(key,pattern+7,MagickTrue) != MagickFalse) { string=GetImageOption(image_info,key); if (string != (const char *) NULL) @@ -3531,11 +3531,11 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info, OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern); continue; /* else no image to retrieve artifact */ } - if( IfMagickTrue(IsGlob(pattern+9)) ) + if (IsGlob(pattern+9) != MagickFalse) { ResetImageArtifactIterator(image); while ((key=GetNextImageArtifact(image)) != (const char *) NULL) - if( IfMagickTrue(GlobExpression(key,pattern+9,MagickTrue)) ) + if (GlobExpression(key,pattern+9,MagickTrue) != MagickFalse) { string=GetImageArtifact(image,key); if (string != (const char *) NULL) @@ -3558,11 +3558,11 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info, OptionWarning,"NoImageForProperty","\"%%[%s]\"",pattern); continue; /* else no image to retrieve artifact */ } - if( IfMagickTrue(IsGlob(pattern+9)) ) + if (IsGlob(pattern+9) != MagickFalse) { ResetImagePropertyIterator(image); while ((key=GetNextImageProperty(image)) != (const char *) NULL) - if( IfMagickTrue(GlobExpression(key,pattern,MagickTrue)) ) + if (GlobExpression(key,pattern,MagickTrue) != MagickFalse) { string=GetImageProperty(image,key,exception); if (string != (const char *) NULL) @@ -3581,7 +3581,7 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info, This handles attributes, properties, and profiles such as %[exif:...] Note the profile properties may also include a glob expansion pattern. */ - if ( image != (Image *) NULL ) + if (image != (Image *) NULL) { string=GetImageProperty(image,pattern,exception); if (string != (const char *) NULL) @@ -3598,13 +3598,13 @@ MagickExport char *InterpretImageProperties(ImageInfo *image_info, Handle property 'glob' patterns Such as: %[*] %[user:array_??] %[filename:e*] */ - if( IfMagickTrue(IsGlob(pattern)) ) + if (IsGlob(pattern) != MagickFalse) { if (image == (Image *) NULL) continue; /* else no image to retrieve proprty - no list */ ResetImagePropertyIterator(image); while ((key=GetNextImageProperty(image)) != (const char *) NULL) - if( IfMagickTrue(GlobExpression(key,pattern,MagickTrue)) ) + if (GlobExpression(key,pattern,MagickTrue) != MagickFalse) { string=GetImageProperty(image,key,exception); if (string != (const char *) NULL) diff --git a/MagickCore/token.h b/MagickCore/token.h index 776ce49ef..43a05a84c 100644 --- a/MagickCore/token.h +++ b/MagickCore/token.h @@ -35,9 +35,6 @@ extern MagickExport int extern MagickExport MagickBooleanType GlobExpression(const char *,const char *,const MagickBooleanType); -/* Deprecated Function equivelent */ -/* #define IsMagickTrue(v) IsStringTrue(v) */ - extern MagickExport TokenInfo *AcquireTokenInfo(void), *DestroyTokenInfo(TokenInfo *); diff --git a/MagickWand/magick-cli.c b/MagickWand/magick-cli.c index 6dfbf4ab1..036b08537 100644 --- a/MagickWand/magick-cli.c +++ b/MagickWand/magick-cli.c @@ -838,5 +838,5 @@ Magick_Command_Exit: cli_wand->wand.exception = (ExceptionInfo *) NULL; cli_wand=DestroyMagickCLI(cli_wand); - return(IsMagickTrue(exception->severity < ErrorException)); + return(exception->severity < ErrorException ? MagickTrue : MagickFalse); } diff --git a/MagickWand/magick-image.c b/MagickWand/magick-image.c index 3480e4a69..522ac3b45 100644 --- a/MagickWand/magick-image.c +++ b/MagickWand/magick-image.c @@ -10003,10 +10003,14 @@ WandExport MagickBooleanType MagickSetImageMatte(MagickWand *wand, (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name); if (wand->images == (Image *) NULL) ThrowWandException(WandError,"ContainsNoImages",wand->name); - if ((wand->images->alpha_trait == UndefinedPixelTrait) && IsMagickTrue(matte)) - (void) SetImageAlpha(wand->images,OpaqueAlpha,wand->exception); - wand->images->alpha_trait=matte != MagickFalse ? BlendPixelTrait : - UndefinedPixelTrait; + if (matte == MagickFalse) + wand->images->alpha_trait=UndefinedPixelTrait; + else + { + if (wand->images->alpha_trait == UndefinedPixelTrait) + (void) SetImageAlpha(wand->images,OpaqueAlpha,wand->exception); + wand->images->alpha_trait=BlendPixelTrait; + } return(MagickTrue); } diff --git a/MagickWand/operation.c b/MagickWand/operation.c index 8156af1e7..3589f6498 100644 --- a/MagickWand/operation.c +++ b/MagickWand/operation.c @@ -237,14 +237,15 @@ static Image *SparseColorOption(const Image *image, x++; /* floating point argument */ } /* control points and color values */ - error = IsMagickTrue( x % (2+number_colors) ); + if ((x % (2+number_colors)) != 0) + { + (void) ThrowMagickException(exception,GetMagickModule(),OptionError, + "InvalidArgument","'%s': %s", "sparse-color", + "Invalid number of Arguments"); + return( (Image *) NULL); + } + error=MagickFalse; number_arguments=x; - if ( IfMagickTrue(error) ) { - (void) ThrowMagickException(exception,GetMagickModule(), - OptionError, "InvalidArgument", "'%s': %s", "sparse-color", - "Invalid number of Arguments"); - return( (Image *) NULL); - } /* Allocate and fill in the floating point arguments */ sparse_arguments=(double *) AcquireQuantumMemory(number_arguments, @@ -266,7 +267,7 @@ static Image *SparseColorOption(const Image *image, (void) ThrowMagickException(exception,GetMagickModule(), OptionError, "InvalidArgument", "'%s': %s", "sparse-color", "Color found, instead of X-coord"); - error = MagickTrue; + error=MagickTrue; break; } sparse_arguments[x++]=StringToDouble(token,(char **) NULL); @@ -277,7 +278,7 @@ static Image *SparseColorOption(const Image *image, (void) ThrowMagickException(exception,GetMagickModule(), OptionError, "InvalidArgument", "'%s': %s", "sparse-color", "Color found, instead of Y-coord"); - error = MagickTrue; + error=MagickTrue; break; } sparse_arguments[x++]=StringToDouble(token,(char **) NULL); @@ -348,15 +349,18 @@ static Image *SparseColorOption(const Image *image, } } } - if ( number_arguments != x && !error ) { - (void) ThrowMagickException(exception,GetMagickModule(),OptionError, - "InvalidArgument","'%s': %s","sparse-color","Argument Parsing Error"); - sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments); - return( (Image *) NULL); - } - if ( error ) - return( (Image *) NULL); - + if (error != MagickFalse) + { + sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments); + return((Image *) NULL); + } + if (number_arguments != x) + { + sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments); + (void) ThrowMagickException(exception,GetMagickModule(),OptionError, + "InvalidArgument","'%s': %s","sparse-color","Argument Parsing Error"); + return((Image *) NULL); + } /* Call the Sparse Color Interpolation function with the parsed arguments */ sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments, exception); @@ -417,8 +421,8 @@ WandPrivate void CLISettingOptionInfo(MagickCLI *cli_wand, #define _draw_info (cli_wand->draw_info) #define _quantize_info (cli_wand->quantize_info) #define IfSetOption (*option=='-') -#define ArgBoolean IsMagickTrue(IfSetOption) -#define ArgBooleanNot IsMagickFalse(IfSetOption) +#define ArgBoolean IfSetOption ? MagickTrue : MagickFalse +#define ArgBooleanNot IfSetOption ? MagickFalse : MagickTrue #define ArgBooleanString (IfSetOption?"true":"false") #define ArgOption(def) (IfSetOption?arg1:(const char *)(def)) @@ -692,7 +696,7 @@ WandPrivate void CLISettingOptionInfo(MagickCLI *cli_wand, /* DefineImageOption() equals SetImageOption() but with '=' */ if (IfSetOption) (void) DefineImageOption(_image_info,arg1); - else if (IsMagickFalse(DeleteImageOption(_image_info,arg1))) + else if (DeleteImageOption(_image_info,arg1) == MagickFalse) CLIWandExceptArgBreak(OptionError,"NoSuchOption",option,arg1); break; } @@ -1694,8 +1698,8 @@ static MagickBooleanType CLISimpleOperatorImage(MagickCLI *cli_wand, #define _option_type ((CommandOptionFlags) cli_wand->command->flags) #define IfNormalOp (*option=='-') #define IfPlusOp (*option!='-') -#define IsNormalOp IsMagickTrue(IfNormalOp) -#define IsPlusOp IsMagickFalse(IfNormalOp) +#define IsNormalOp IfNormalOp ? MagickTrue : MagickFalse +#define IsPlusOp IfNormalOp ? MagickFalse : MagickTrue assert(cli_wand != (MagickCLI *) NULL); assert(cli_wand->signature == MagickWandSignature); @@ -3671,7 +3675,7 @@ WandPrivate MagickBooleanType CLIListOperatorImages(MagickCLI *cli_wand, #define _option_type ((CommandOptionFlags) cli_wand->command->flags) #define IfNormalOp (*option=='-') #define IfPlusOp (*option!='-') -#define IsNormalOp IsMagickTrue(IfNormalOp) +#define IsNormalOp IfNormalOp ? MagickTrue : MagickFalse assert(cli_wand != (MagickCLI *) NULL); assert(cli_wand->signature == MagickWandSignature); diff --git a/MagickWand/wandcli.c b/MagickWand/wandcli.c index 3d8d1b47c..86e1a9be3 100644 --- a/MagickWand/wandcli.c +++ b/MagickWand/wandcli.c @@ -232,22 +232,24 @@ WandExport MagickCLI *DestroyMagickCLI(MagickCLI *cli_wand) % */ WandExport MagickBooleanType CLICatchException(MagickCLI *cli_wand, - const MagickBooleanType all_exceptions ) + const MagickBooleanType all_exceptions) { MagickBooleanType status; + assert(cli_wand != (MagickCLI *) NULL); assert(cli_wand->signature == MagickWandSignature); assert(cli_wand->wand.signature == MagickWandSignature); - if (IfMagickTrue(cli_wand->wand.debug)) + if (cli_wand->wand.debug != MagickFalse) (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",cli_wand->wand.name); // FUTURE: '-regard_warning' should make this more sensitive. // Note pipelined options may like more control over this level - status = IsMagickTrue(cli_wand->wand.exception->severity > ErrorException); + status=cli_wand->wand.exception->severity > ErrorException ? MagickTrue : + MagickFalse; - if ( IfMagickFalse(status) || IfMagickTrue(all_exceptions) ) + if ((status == MagickFalse) || (all_exceptions != MagickFalse)) CatchException(cli_wand->wand.exception); /* output and clear exceptions */ return(status); -- 2.40.0