Use FormatImageProperty() instead of SetImageProperty() where appropriate

This commit is contained in:
Cristy
2020-03-23 20:10:18 -04:00
parent 96bc8865d5
commit 8a36f4e418
10 changed files with 101 additions and 154 deletions
+7 -17
View File
@@ -9032,8 +9032,7 @@ static Image *XMagickCommand(Display *display,XResourceInfo *resource_info,
case ShowPreviewCommand:
{
char
**previews,
value[MagickPathExtent];
**previews;
Image
*preview_image;
@@ -9063,9 +9062,8 @@ static Image *XMagickCommand(Display *display,XResourceInfo *resource_info,
XCheckRefreshWindows(display,windows);
preview=(PreviewType) ParseCommandOption(MagickPreviewOptions,
MagickFalse,preview_type);
(void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
(void) FormatImageProperty(*image,"group","%.20g",(double)
windows->image.id);
(void) SetImageProperty(*image,"group",value,exception);
(void) DeleteImageProperty(*image,"label");
(void) SetImageProperty(*image,"label","Preview",exception);
preview_image=PreviewImage(*image,preview,exception);
@@ -9086,9 +9084,6 @@ static Image *XMagickCommand(Display *display,XResourceInfo *resource_info,
}
case ShowHistogramCommand:
{
char
value[MagickPathExtent];
Image
*histogram_image;
@@ -9097,10 +9092,9 @@ static Image *XMagickCommand(Display *display,XResourceInfo *resource_info,
*/
XSetCursorState(display,windows,MagickTrue);
XCheckRefreshWindows(display,windows);
(void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
windows->image.id);
(void) SetImageProperty(*image,"group",value,exception);
(void) DeleteImageProperty(*image,"label");
(void) FormatImageProperty(*image,"group","%.20g",(double)
windows->image.id);
(void) SetImageProperty(*image,"label","Histogram",exception);
(void) AcquireUniqueFilename(filename);
(void) FormatLocaleString((*image)->filename,MagickPathExtent,
@@ -9124,9 +9118,6 @@ static Image *XMagickCommand(Display *display,XResourceInfo *resource_info,
}
case ShowMatteCommand:
{
char
value[MagickPathExtent];
Image
*matte_image;
@@ -9141,9 +9132,8 @@ static Image *XMagickCommand(Display *display,XResourceInfo *resource_info,
*/
XSetCursorState(display,windows,MagickTrue);
XCheckRefreshWindows(display,windows);
(void) FormatLocaleString(value,MaxTextExtent,"%.20g",(double)
(void) FormatImageProperty(*image,"group","%.20g",(double)
windows->image.id);
(void) SetImageProperty(*image,"group",value,exception);
(void) DeleteImageProperty(*image,"label");
(void) SetImageProperty(*image,"label","Matte",exception);
(void) AcquireUniqueFilename(filename);
@@ -9155,8 +9145,8 @@ static Image *XMagickCommand(Display *display,XResourceInfo *resource_info,
(void) RelinquishUniqueFileResource(filename);
if (matte_image == (Image *) NULL)
break;
(void) FormatLocaleString(matte_image->filename,MagickPathExtent,"show:%s",
filename);
(void) FormatLocaleString(matte_image->filename,MagickPathExtent,
"show:%s",filename);
status=WriteImage(image_info,matte_image,exception);
matte_image=DestroyImage(matte_image);
if (status == MagickFalse)
+8 -17
View File
@@ -4585,11 +4585,8 @@ MagickExport Image *ThumbnailImage(const Image *image,const size_t columns,
GetPathComponent(image->magick_filename,TailPath,filename);
(void) CopyMagickString(value,filename,MagickPathExtent);
if ( GetPathAttributes(image->filename,&attributes) != MagickFalse )
{
(void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
attributes.st_mtime);
(void) SetImageProperty(thumbnail_image,"Thumb::MTime",value,exception);
}
(void) FormatImageProperty(thumbnail_image,"Thumb::MTime","%.20g",(double)
attributes.st_mtime);
(void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
attributes.st_mtime);
(void) FormatMagickSize(GetBlobSize(image),MagickFalse,"B",MagickPathExtent,
@@ -4600,17 +4597,11 @@ MagickExport Image *ThumbnailImage(const Image *image,const size_t columns,
(void) SetImageProperty(thumbnail_image,"Thumb::Mimetype",value,exception);
(void) SetImageProperty(thumbnail_image,"software",MagickAuthoritativeURL,
exception);
(void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
image->magick_columns);
(void) SetImageProperty(thumbnail_image,"Thumb::Image::Width",value,
exception);
(void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
image->magick_rows);
(void) SetImageProperty(thumbnail_image,"Thumb::Image::Height",value,
exception);
(void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
GetImageListLength(image));
(void) SetImageProperty(thumbnail_image,"Thumb::Document::Pages",value,
exception);
(void) FormatImageProperty(thumbnail_image,"Thumb::Image::Width","%.20g",
(double) image->magick_columns);
(void) FormatImageProperty(thumbnail_image,"Thumb::Image::Height","%.20g",
(double) image->magick_rows);
(void) FormatImageProperty(thumbnail_image,"Thumb::Document::Pages","%.20g",
(double) GetImageListLength(image));
return(thumbnail_image);
}
+55 -52
View File
@@ -266,10 +266,14 @@ static Image *SparseColorOption(const Image *image,
sizeof(*sparse_arguments));
p=arguments;
x=0;
while( *p != '\0' && x < number_arguments ) {
while ((*p != '\0') && (x < number_arguments))
{
/* X coordinate */
*token=','; while (*token == ',') GetNextToken(p,&p,MagickPathExtent,token);
if (*token == '\0') break;
*token=',';
while (*token == ',')
(void) GetNextToken(p,&p,MagickPathExtent,token);
if (*token == '\0')
break;
if ( isalpha((int) ((unsigned char) *token)) || *token == '#' ) {
(void) ThrowMagickException(exception,GetMagickModule(),
OptionError, "InvalidArgument", "'%s': %s", "sparse-color",
@@ -279,8 +283,11 @@ static Image *SparseColorOption(const Image *image,
}
sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
/* Y coordinate */
*token=','; while (*token == ',') GetNextToken(p,&p,MagickPathExtent,token);
if (*token == '\0') break;
*token=',';
while (*token == ',')
(void) GetNextToken(p,&p,MagickPathExtent,token);
if (*token == '\0')
break;
if ( isalpha((int) ((unsigned char) *token)) || *token == '#' ) {
(void) ThrowMagickException(exception,GetMagickModule(),
OptionError, "InvalidArgument", "'%s': %s", "sparse-color",
@@ -290,7 +297,9 @@ static Image *SparseColorOption(const Image *image,
}
sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
/* color name or function given in string argument */
*token=','; while (*token == ',') GetNextToken(p,&p,MagickPathExtent,token);
*token=',';
while (*token == ',')
(void) GetNextToken(p,&p,MagickPathExtent,token);
if (*token == '\0') break;
if ( isalpha((int) ((unsigned char) *token)) || *token == '#' ) {
/* Color string given */
@@ -314,46 +323,51 @@ static Image *SparseColorOption(const Image *image,
/* NB: token contains the first floating point value to use! */
if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
{
while (*token == ',') GetNextToken(p,&p,MagickPathExtent,token);
if ((*token == '\0') || isalpha((int) ((unsigned char) *token)) || *token == '#' )
break;
sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
*token=','; /* used this token - get another */
}
while (*token == ',')
(void) GetNextToken(p,&p,MagickPathExtent,token);
if ((*token == '\0') || isalpha((int) ((unsigned char) *token)) || *token == '#' )
break;
sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
*token=','; /* used this token - get another */
}
if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
{
while (*token == ',') GetNextToken(p,&p,MagickPathExtent,token);
if ((*token == '\0') || isalpha((int) ((unsigned char) *token)) || *token == '#' )
break;
sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
*token=','; /* used this token - get another */
}
while (*token == ',')
(void) GetNextToken(p,&p,MagickPathExtent,token);
if ((*token == '\0') || isalpha((int) ((unsigned char) *token)) || *token == '#' )
break;
sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
*token=','; /* used this token - get another */
}
if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
{
while (*token == ',') GetNextToken(p,&p,MagickPathExtent,token);
if ((*token == '\0') || isalpha((int) ((unsigned char) *token)) || *token == '#' )
break;
sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
*token = ','; /* used this token - get another */
}
while (*token == ',')
(void) GetNextToken(p,&p,MagickPathExtent,token);
if ((*token == '\0') || isalpha((int) ((unsigned char) *token)) || *token == '#' )
break;
sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
*token = ','; /* used this token - get another */
}
if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
(image->colorspace == CMYKColorspace))
{
while (*token == ',') GetNextToken(p,&p,MagickPathExtent,token);
if ((*token == '\0') || isalpha((int) ((unsigned char) *token)) || *token == '#' )
break;
sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
*token=','; /* used this token - get another */
}
while (*token == ',')
(void) GetNextToken(p,&p,MagickPathExtent,token);
if ((*token == '\0') || isalpha((int) ((unsigned char) *token)) || *token == '#' )
break;
sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
*token=','; /* used this token - get another */
}
if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
image->alpha_trait != UndefinedPixelTrait)
{
while (*token == ',') GetNextToken(p,&p,MagickPathExtent,token);
if ((*token == '\0') || isalpha((int) ((unsigned char) *token)) || *token == '#' )
break;
sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
*token = ','; /* used this token - get another */
}
while (*token == ',')
(void) GetNextToken(p,&p,MagickPathExtent,token);
if ((*token == '\0') || isalpha((int) ((unsigned char) *token)) || *token == '#' )
break;
sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
*token = ','; /* used this token - get another */
}
}
}
if (error != MagickFalse)
@@ -4577,26 +4591,15 @@ WandPrivate MagickBooleanType CLIListOperatorImages(MagickCLI *cli_wand,
if (new_images != (Image *) NULL)
{
char
result[MagickPathExtent];
(void) FormatLocaleString(result,MagickPathExtent,"%lf",
similarity);
(void) SetImageProperty(new_images,"subimage:similarity",result,
_exception);
(void) FormatLocaleString(result,MagickPathExtent,"%+ld",(long)
(void) FormatImageProperty(new_images,"subimage:similarity",
"%.*g",GetMagickPrecision(),similarity);
(void) FormatImageProperty(new_images,"subimage:x","%+ld",(long)
offset.x);
(void) SetImageProperty(new_images,"subimage:x",result,
_exception);
(void) FormatLocaleString(result,MagickPathExtent,"%+ld",(long)
(void) FormatImageProperty(new_images,"subimage:y","%+ld",(long)
offset.y);
(void) SetImageProperty(new_images,"subimage:y",result,
_exception);
(void) FormatLocaleString(result,MagickPathExtent,
(void) FormatImageProperty(new_images,"subimage:offset",
"%lux%lu%+ld%+ld",(unsigned long) offset.width,(unsigned long)
offset.height,(long) offset.x,(long) offset.y);
(void) SetImageProperty(new_images,"subimage:offset",result,
_exception);
}
break;
}
+2 -8
View File
@@ -309,14 +309,8 @@ static Image *ReadCAPTIONImage(const ImageInfo *image_info,
(void) CloneString(&draw_info->geometry,geometry);
status=AnnotateImage(image,draw_info,exception);
if (image_info->pointsize == 0.0)
{
char
pointsize[MagickPathExtent];
(void) FormatLocaleString(pointsize,MagickPathExtent,"%.20g",
draw_info->pointsize);
(void) SetImageProperty(image,"caption:pointsize",pointsize,exception);
}
(void) FormatImageProperty(image,"caption:pointsize","%.*g",
GetMagickPrecision(),draw_info->pointsize);
draw_info=DestroyDrawInfo(draw_info);
if (status == MagickFalse)
{
+15 -32
View File
@@ -162,7 +162,6 @@ static void SetDNGProperties(Image *image,const libraw_data_t *raw_info,
ExceptionInfo *exception)
{
char
property[MagickPathExtent],
timestamp[MagickPathExtent];
(void) SetImageProperty(image,"dng:make",raw_info->idata.make,exception);
@@ -170,59 +169,43 @@ static void SetDNGProperties(Image *image,const libraw_data_t *raw_info,
exception);
(void) FormatMagickTime(raw_info->other.timestamp,MagickPathExtent,timestamp);
(void) SetImageProperty(image,"dng:create.date",timestamp,exception);
(void) FormatLocaleString(property,MagickPathExtent,"%0.1f",
(void) FormatImageProperty(image,"dng:iso.setting","%0.1f",
raw_info->other.iso_speed);
(void) SetImageProperty(image,"dng:iso.setting",property,exception);
#if LIBRAW_COMPILE_CHECK_VERSION_NOTLESS(0,18)
(void) SetImageProperty(image,"dng:software",raw_info->idata.software,
exception);
if (*raw_info->shootinginfo.BodySerial != '\0')
(void) SetImageProperty(image,"dng:serial.number",
raw_info->shootinginfo.BodySerial,exception);
(void) FormatLocaleString(property,MagickPathExtent,"1/%0.1f",
(void) FormatImageProperty(image,"dng:exposure.time","1/%0.1f",
1.0/raw_info->other.shutter);
(void) SetImageProperty(image,"dng:exposure.time",property,exception);
(void) FormatLocaleString(property,MagickPathExtent,"%0.1f",
(void) FormatImageProperty(image,"dng:f.number","%0.1f",
raw_info->other.aperture);
(void) SetImageProperty(image,"dng:f.number",property,exception);
(void) FormatLocaleString(property,MagickPathExtent,"%0.1f",
(void) FormatImageProperty(image,"dng:max.aperture.value","%0.1f",
raw_info->lens.EXIF_MaxAp);
(void) SetImageProperty(image,"dng:max.aperture.value",property,exception);
(void) FormatLocaleString(property,MagickPathExtent,"%0.1f",
(void) FormatImageProperty(image,"dng:ocal.length","%0.1f",
raw_info->other.focal_len);
(void) SetImageProperty(image,"dng:focal.length",property,exception);
(void) FormatLocaleString(property,MagickPathExtent,"%f %f %f %f",
(void) FormatImageProperty(image,"dng:wb.rb.levels","%f %f %f %f",
raw_info->color.cam_mul[0],raw_info->color.cam_mul[2],
raw_info->color.cam_mul[1],raw_info->color.cam_mul[3]);
(void) SetImageProperty(image,"dng:wb.rb.levels",property,exception);
(void) SetImageProperty(image,"dng:lens.type",
raw_info->lens.makernotes.LensFeatures_suf,exception);
(void) FormatLocaleString(property,MagickPathExtent,
"%0.1f-%0.1fmm f/%0.1f-%0.1f",raw_info->lens.makernotes.MinFocal,
raw_info->lens.makernotes.MaxFocal,raw_info->lens.makernotes.MaxAp4MinFocal,
(void) FormatImageProperty(image,"dng:lens","%0.1f-%0.1fmm f/%0.1f-%0.1f",
raw_info->lens.makernotes.MinFocal,raw_info->lens.makernotes.MaxFocal,
raw_info->lens.makernotes.MaxAp4MinFocal,
raw_info->lens.makernotes.MaxAp4MaxFocal);
(void) SetImageProperty(image,"dng:lens",property,exception);
(void) FormatLocaleString(property,MagickPathExtent,"%0.2f",
(void) FormatImageProperty(image,"dng:lens.f.stops","%0.2f",
raw_info->lens.makernotes.LensFStops);
(void) SetImageProperty(image,"dng:lens.f.stops",property,exception);
(void) FormatLocaleString(property,MagickPathExtent,"%0.1f mm",
(void) FormatImageProperty(image,"dng:min.focal.length","%0.1f mm",
raw_info->lens.makernotes.MinFocal);
(void) SetImageProperty(image,"dng:min.focal.length",property,exception);
(void) FormatLocaleString(property,MagickPathExtent,"%0.1f mm",
(void) FormatImageProperty(image,"dng:max.focal.length","%0.1f mm",
raw_info->lens.makernotes.MaxFocal);
(void) SetImageProperty(image,"dng:max.focal.length",property,exception);
(void) FormatLocaleString(property,MagickPathExtent,"%0.1f",
(void) FormatImageProperty(image,"dng:max.aperture.at.min.focal","%0.1f",
raw_info->lens.makernotes.MaxAp4MinFocal);
(void) SetImageProperty(image,"dng:max.aperture.at.min.focal",property,
exception);
(void) FormatLocaleString(property,MagickPathExtent,"%0.1f",
(void) FormatImageProperty(image,"dng:max.aperture.at.max.focal","%0.1f",
raw_info->lens.makernotes.MaxAp4MaxFocal);
(void) SetImageProperty(image,"dng:max.aperture.at.max.focal",property,
exception);
(void) FormatLocaleString(property,MagickPathExtent,"%d mm",
(void) FormatImageProperty(image,"dng:focal.length.in.35mm.format","%d mm",
raw_info->lens.FocalLengthIn35mmFormat);
(void) SetImageProperty(image,"dng:focal.length.in.35mm.format",property,
exception);
#endif
}
#endif
+2 -8
View File
@@ -261,14 +261,8 @@ static Image *ReadLABELImage(const ImageInfo *image_info,
(void) CloneString(&draw_info->geometry,geometry);
status=AnnotateImage(image,draw_info,exception);
if (image_info->pointsize == 0.0)
{
char
pointsize[MagickPathExtent];
(void) FormatLocaleString(pointsize,MagickPathExtent,"%.20g",
draw_info->pointsize);
(void) SetImageProperty(image,"label:pointsize",pointsize,exception);
}
(void) FormatImageProperty(image,"label:pointsize","%.20g",
draw_info->pointsize);
draw_info=DestroyDrawInfo(draw_info);
if (status == MagickFalse)
{
+4 -5
View File
@@ -374,7 +374,6 @@ static Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
command[MagickPathExtent],
*density,
filename[MagickPathExtent],
geometry[MagickPathExtent],
input_filename[MagickPathExtent],
message[MagickPathExtent],
*options,
@@ -488,10 +487,10 @@ static Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
if ((fabs(pdf_info.bounds.x2-pdf_info.bounds.x1) >= MagickEpsilon) &&
(fabs(pdf_info.bounds.y2-pdf_info.bounds.y1) >= MagickEpsilon))
{
(void) FormatLocaleString(geometry,MagickPathExtent,"%gx%g%+.15g%+.15g",
pdf_info.bounds.x2-pdf_info.bounds.x1,pdf_info.bounds.y2-
pdf_info.bounds.y1,pdf_info.bounds.x1,pdf_info.bounds.y1);
(void) SetImageProperty(image,"pdf:HiResBoundingBox",geometry,exception);
(void) FormatImageProperty(image,"pdf:HiResBoundingBox",
"%gx%g%+.15g%+.15g",pdf_info.bounds.x2-pdf_info.bounds.x1,
pdf_info.bounds.y2-pdf_info.bounds.y1,pdf_info.bounds.x1,
pdf_info.bounds.y1);
page.width=(size_t) ((ssize_t) ceil((double) ((pdf_info.bounds.x2-
pdf_info.bounds.x1)*image->resolution.x/delta.x)-0.5));
page.height=(size_t) ((ssize_t) ceil((double) ((pdf_info.bounds.y2-
+3 -5
View File
@@ -532,7 +532,6 @@ static Image *ReadPSImage(const ImageInfo *image_info,ExceptionInfo *exception)
command[MagickPathExtent],
*density,
filename[MagickPathExtent],
geometry[MagickPathExtent],
input_filename[MagickPathExtent],
message[MagickPathExtent],
*options,
@@ -649,10 +648,9 @@ static Image *ReadPSImage(const ImageInfo *image_info,ExceptionInfo *exception)
if ((fabs(info.bounds.x2-info.bounds.x1) >= MagickEpsilon) &&
(fabs(info.bounds.y2-info.bounds.y1) >= MagickEpsilon))
{
(void) FormatLocaleString(geometry,MagickPathExtent,"%gx%g%+.15g%+.15g",
info.bounds.x2-info.bounds.x1,info.bounds.y2-info.bounds.y1,
info.bounds.x1,info.bounds.y1);
(void) SetImageProperty(image,"ps:HiResBoundingBox",geometry,exception);
(void) FormatImageProperty(image,"ps:HiResBoundingBox",
"%gx%g%+.15g%+.15g",info.bounds.x2-info.bounds.x1,info.bounds.y2-
info.bounds.y1,info.bounds.x1,info.bounds.y1);
page.width=(size_t) ((ssize_t) ceil((double) ((info.bounds.x2-
info.bounds.x1)*resolution.x/delta.x)-0.5));
page.height=(size_t) ((ssize_t) ceil((double) ((info.bounds.y2-
+4 -9
View File
@@ -803,9 +803,6 @@ static StringInfo *ParseImageResourceBlocks(PSDInfo *psd_info,Image *image,
{
case 0x03ed:
{
char
value[MagickPathExtent];
unsigned short
resolution;
@@ -816,17 +813,15 @@ static StringInfo *ParseImageResourceBlocks(PSDInfo *psd_info,Image *image,
break;
p=PushShortPixel(MSBEndian,p,&resolution);
image->resolution.x=(double) resolution;
(void) FormatLocaleString(value,MagickPathExtent,"%g",
image->resolution.x);
(void) SetImageProperty(image,"tiff:XResolution",value,exception);
(void) FormatImageProperty(image,"tiff:XResolution","%*g",
GetMagickPrecision(),image->resolution.x);
p=PushShortPixel(MSBEndian,p,&short_sans);
p=PushShortPixel(MSBEndian,p,&short_sans);
p=PushShortPixel(MSBEndian,p,&short_sans);
p=PushShortPixel(MSBEndian,p,&resolution);
image->resolution.y=(double) resolution;
(void) FormatLocaleString(value,MagickPathExtent,"%g",
image->resolution.y);
(void) SetImageProperty(image,"tiff:YResolution",value,exception);
(void) FormatImageProperty(image,"tiff:YResolution","%*g",
GetMagickPrecision(),image->resolution.y);
p=PushShortPixel(MSBEndian,p,&short_sans);
p=PushShortPixel(MSBEndian,p,&short_sans);
p=PushShortPixel(MSBEndian,p,&short_sans);
+1 -1
View File
@@ -876,7 +876,7 @@ static void InitXCFImage(XCFLayerInfo *outLayer,ExceptionInfo *exception)
outLayer->image->page.y=outLayer->offset_y;
outLayer->image->page.width=outLayer->width;
outLayer->image->page.height=outLayer->height;
(void) SetImageProperty(outLayer->image,"label",(char *)outLayer->name,
(void) SetImageProperty(outLayer->image,"label",(char *) outLayer->name,
exception);
}