From: cristy Date: Wed, 17 Mar 2010 20:21:27 +0000 (+0000) Subject: (no commit message) X-Git-Tag: 7.0.1-0~9785 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=06609eef311d5af857f65f20ed3af6860c1994be;p=imagemagick --- diff --git a/ChangeLog b/ChangeLog index d14e69458..9255f744d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 2010-03-17 6.6.0-7 Cristy * Detect CMYKProcessColor AI tag. + * Delete image from command line cache for -write option. 2010-03-13 6.6.0-6 Cristy * Add support for the Adobe Large Document format. diff --git a/coders/cals.c b/coders/cals.c index 72bde2a2b..ead41655d 100644 --- a/coders/cals.c +++ b/coders/cals.c @@ -542,7 +542,7 @@ static MagickBooleanType WriteCALSImage(const ImageInfo *image_info, geometry_info; (void) ParseGeometry(image_info->density,&geometry_info); - density=(unsigned long) (geometry_info.rho+0.5); + density=(unsigned long) floor(geometry_info.rho+0.5); } (void) FormatMagickString(header,MaxTextExtent,"rdensty: %04lu",density); count=WriteCALSRecord(image,header); diff --git a/coders/caption.c b/coders/caption.c index 035572bfe..b7242cbea 100644 --- a/coders/caption.c +++ b/coders/caption.c @@ -162,8 +162,9 @@ static Image *ReadCAPTIONImage(const ImageInfo *image_info, if (draw_info->gravity == UndefinedGravity) (void) CloneString(&draw_info->geometry,geometry); status=GetMultilineTypeMetrics(image,draw_info,&metrics); - width=(unsigned long) (metrics.width+draw_info->stroke_width+0.5); - height=(unsigned long) (metrics.height+draw_info->stroke_width+0.5); + width=(unsigned long) floor(metrics.width+draw_info->stroke_width+0.5); + height=(unsigned long) floor(metrics.height+draw_info->stroke_width+ + 0.5); if ((width > (image->columns+1)) || (height > (image->rows+1))) break; draw_info->pointsize*=2.0; @@ -180,8 +181,9 @@ static Image *ReadCAPTIONImage(const ImageInfo *image_info, if (draw_info->gravity == UndefinedGravity) (void) CloneString(&draw_info->geometry,geometry); status=GetMultilineTypeMetrics(image,draw_info,&metrics); - width=(unsigned long) (metrics.width+draw_info->stroke_width+0.5); - height=(unsigned long) (metrics.height+draw_info->stroke_width+0.5); + width=(unsigned long) floor(metrics.width+draw_info->stroke_width+0.5); + height=(unsigned long) floor(metrics.height+draw_info->stroke_width+ + 0.5); if ((width > (image->columns+1)) || (height > (image->rows+1))) break; draw_info->pointsize++; diff --git a/coders/dcm.c b/coders/dcm.c index 450cdbe7a..b393c5d45 100644 --- a/coders/dcm.c +++ b/coders/dcm.c @@ -3738,8 +3738,10 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception) window_max, window_min; - window_min=(long) (window_center-(window_width-1)/2.0-0.5); - window_max=(long) (window_center+(window_width-1)/2.0-0.5); + window_min=(long) ceil(window_center-(window_width-1)/2.0- + 0.5); + window_max=(long) floor(window_center+(window_width-1)/2.0+ + 0.5); if ((long) pixel_value <= window_min) index=0; else diff --git a/coders/emf.c b/coders/emf.c index 86072fa40..248925886 100644 --- a/coders/emf.c +++ b/coders/emf.c @@ -526,10 +526,11 @@ static Image *ReadEMFImage(const ImageInfo *image_info, flags=ParseMetaGeometry(geometry,&sans,&sans,&image->columns, &image->rows); if (image->x_resolution != 0.0) - image->columns=(unsigned long) ((image->columns* + image->columns=(unsigned long) floor((image->columns* image->x_resolution)+0.5); if (image->y_resolution != 0.0) - image->rows=(unsigned long) ((image->rows*image->y_resolution)+0.5); + image->rows=(unsigned long) floor((image->rows*image->y_resolution)+ + 0.5); } else { @@ -537,11 +538,11 @@ static Image *ReadEMFImage(const ImageInfo *image_info, flags=ParseMetaGeometry(geometry,&sans,&sans,&image->columns, &image->rows); if (image->x_resolution != 0.0) - image->columns=(unsigned long) (((image->columns* + image->columns=(unsigned long) floor(((image->columns* image->x_resolution)/DefaultResolution)+0.5); if (image->y_resolution != 0.0) - image->rows=(unsigned long) (((image->rows*image->y_resolution)/ - DefaultResolution)+0.5); + image->rows=(unsigned long) floor(((image->rows* + image->y_resolution)/DefaultResolution)+0.5); } geometry=DestroyString(geometry); } diff --git a/coders/fpx.c b/coders/fpx.c index ace1a4f85..f43e5582a 100644 --- a/coders/fpx.c +++ b/coders/fpx.c @@ -282,7 +282,7 @@ static Image *ReadFPXImage(const ImageInfo *image_info,ExceptionInfo *exception) fpx_status=FPX_GetImageResultAspectRatio(flashpix,&aspect_ratio); if (fpx_status != FPX_OK) ThrowReaderException(DelegateError,"UnableToReadAspectRatio"); - if (width != (unsigned long) ((aspect_ratio*height)+0.5)) + if (width != (unsigned long) floor((aspect_ratio*height)+0.5)) Swap(width,height); } fpx_status=FPX_GetSummaryInformation(flashpix,&summary_info); diff --git a/coders/histogram.c b/coders/histogram.c index ff5f3fc1f..8d4b84193 100644 --- a/coders/histogram.c +++ b/coders/histogram.c @@ -305,7 +305,7 @@ static MagickBooleanType WriteHISTOGRAMImage(const ImageInfo *image_info, break; if ((channel & RedChannel) != 0) { - y=(long) (histogram_image->rows-scale*histogram[x].red+0.5); + y=(long) ceil(histogram_image->rows-scale*histogram[x].red-0.5); r=q+y; for ( ; y < (long) histogram_image->rows; y++) { @@ -315,7 +315,7 @@ static MagickBooleanType WriteHISTOGRAMImage(const ImageInfo *image_info, } if ((channel & GreenChannel) != 0) { - y=(long) (histogram_image->rows-scale*histogram[x].green+0.5); + y=(long) ceil(histogram_image->rows-scale*histogram[x].green-0.5); r=q+y; for ( ; y < (long) histogram_image->rows; y++) { @@ -325,7 +325,7 @@ static MagickBooleanType WriteHISTOGRAMImage(const ImageInfo *image_info, } if ((channel & BlueChannel) != 0) { - y=(long) (histogram_image->rows-scale*histogram[x].blue+0.5); + y=(long) ceil(histogram_image->rows-scale*histogram[x].blue-0.5); r=q+y; for ( ; y < (long) histogram_image->rows; y++) { diff --git a/coders/jpeg.c b/coders/jpeg.c index f311b7055..460c33c3f 100644 --- a/coders/jpeg.c +++ b/coders/jpeg.c @@ -1778,8 +1778,8 @@ static MagickBooleanType WriteJPEGImage(const ImageInfo *image_info, jpeg_info.density_unit=(UINT8) 1; if (image->debug != MagickFalse) (void) LogMagickEvent(CoderEvent,GetMagickModule(), - "Image resolution: %ld,%ld",(long) (image->x_resolution+0.5), - (long) (image->y_resolution+0.5)); + "Image resolution: %ld,%ld",(long) ceil(image->x_resolution-0.5), + (long) ceil(image->y_resolution-0.5)); if ((image->x_resolution != 0.0) && (image->y_resolution != 0.0)) { /* diff --git a/coders/label.c b/coders/label.c index 43a2d6ded..84351c420 100644 --- a/coders/label.c +++ b/coders/label.c @@ -138,8 +138,9 @@ static Image *ReadLABELImage(const ImageInfo *image_info, status=GetMultilineTypeMetrics(image,draw_info,&metrics); for ( ; status != MagickFalse; draw_info->pointsize*=2.0) { - width=(unsigned long) (metrics.width+draw_info->stroke_width+0.5); - height=(unsigned long) (metrics.height+draw_info->stroke_width+0.5); + width=(unsigned long) floor(metrics.width+draw_info->stroke_width+0.5); + height=(unsigned long) floor(metrics.height+draw_info->stroke_width+ + 0.5); if (((image->columns != 0) && (width > (image->columns+1))) || ((image->rows != 0) && (height > (image->rows+1)))) break; @@ -147,8 +148,9 @@ static Image *ReadLABELImage(const ImageInfo *image_info, } for ( ; status != MagickFalse; draw_info->pointsize--) { - width=(unsigned long) (metrics.width+draw_info->stroke_width+0.5); - height=(unsigned long) (metrics.height+draw_info->stroke_width+0.5); + width=(unsigned long) floor(metrics.width+draw_info->stroke_width+0.5); + height=(unsigned long) floor(metrics.height+draw_info->stroke_width+ + 0.5); if ((image->columns != 0) && (width <= (image->columns+1)) && ((image->rows == 0) || (height <= (image->rows+1)))) break; @@ -180,10 +182,11 @@ static Image *ReadLABELImage(const ImageInfo *image_info, draw_info->geometry=AcquireString(geometry); } if (image->rows == 0) - image->rows=(unsigned long) (metrics.height+draw_info->stroke_width+0.5); - if (image->rows == 0) - image->rows=(unsigned long) (draw_info->pointsize+draw_info->stroke_width+ + image->rows=(unsigned long) floor(metrics.height+draw_info->stroke_width+ 0.5); + if (image->rows == 0) + image->rows=(unsigned long) floor(draw_info->pointsize+ + draw_info->stroke_width+0.5); if (SetImageBackgroundColor(image) == MagickFalse) { InheritException(exception,&image->exception); diff --git a/coders/msl.c b/coders/msl.c index aa85eac13..aa015092a 100644 --- a/coders/msl.c +++ b/coders/msl.c @@ -6248,8 +6248,8 @@ static void MSLStartElement(void *context,const xmlChar *tag, } } shadow_image=ShadowImage(msl_info->image[n],geometry_info.rho, - geometry_info.sigma,(long) (geometry_info.xi+0.5),(long) - (geometry_info.psi+0.5),&msl_info->image[n]->exception); + geometry_info.sigma,(long) floor(geometry_info.xi+0.5),(long) + floor(geometry_info.psi+0.5),&msl_info->image[n]->exception); if (shadow_image == (Image *) NULL) break; msl_info->image[n]=DestroyImage(msl_info->image[n]); diff --git a/coders/mvg.c b/coders/mvg.c index a1b4e68d7..5c7165870 100644 --- a/coders/mvg.c +++ b/coders/mvg.c @@ -175,8 +175,8 @@ static Image *ReadMVGImage(const ImageInfo *image_info,ExceptionInfo *exception) continue; (void) sscanf(p,"viewbox %lf %lf %lf %lf",&bounds.x1,&bounds.y1, &bounds.x2,&bounds.y2); - image->columns=(unsigned long) ((bounds.x2-bounds.x1)+0.5); - image->rows=(unsigned long) ((bounds.y2-bounds.y1)+0.5); + image->columns=(unsigned long) floor((bounds.x2-bounds.x1)+0.5); + image->rows=(unsigned long) floor((bounds.y2-bounds.y1)+0.5); break; } } diff --git a/coders/pcl.c b/coders/pcl.c index 31852b5fe..ec1ac388e 100644 --- a/coders/pcl.c +++ b/coders/pcl.c @@ -290,8 +290,8 @@ static Image *ReadPCLImage(const ImageInfo *image_info,ExceptionInfo *exception) /* Set PCL render geometry. */ - width=(unsigned long) (bounds.x2-bounds.x1+0.5); - height=(unsigned long) (bounds.y2-bounds.y1+0.5); + width=(unsigned long) floor(bounds.x2-bounds.x1+0.5); + height=(unsigned long) floor(bounds.y2-bounds.y1+0.5); if (width > page.width) page.width=width; if (height > page.height) @@ -323,8 +323,9 @@ static Image *ReadPCLImage(const ImageInfo *image_info,ExceptionInfo *exception) (void) ParseAbsoluteGeometry(image_info->page,&page); (void) FormatMagickString(density,MaxTextExtent,"%gx%g", image->x_resolution,image->y_resolution); - page.width=(unsigned long) (page.width*image->x_resolution/delta.x+0.5); - page.height=(unsigned long) (page.height*image->y_resolution/delta.y+0.5); + page.width=(unsigned long) floor(page.width*image->x_resolution/delta.x+0.5); + page.height=(unsigned long) floor(page.height*image->y_resolution/delta.y+ + 0.5); (void) FormatMagickString(options,MaxTextExtent,"-g%lux%lu ", page.width,page.height); image=DestroyImage(image); diff --git a/coders/pdf.c b/coders/pdf.c index e3bbbefbd..e7ad0d0aa 100644 --- a/coders/pdf.c +++ b/coders/pdf.c @@ -531,8 +531,8 @@ static Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception) "%gx%g%+.15g%+.15g",bounds.x2-bounds.x1,bounds.y2-bounds.y1, bounds.x1,bounds.y1); (void) SetImageProperty(image,"pdf:HiResBoundingBox",geometry); - page.width=(unsigned long) (bounds.x2-bounds.x1+0.5); - page.height=(unsigned long) (bounds.y2-bounds.y1+0.5); + page.width=(unsigned long) floor(bounds.x2-bounds.x1+0.5); + page.height=(unsigned long) floor(bounds.y2-bounds.y1+0.5); hires_bounds=bounds; } } @@ -587,8 +587,10 @@ static Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception) if (image_info->page != (char *) NULL) { (void) ParseAbsoluteGeometry(image_info->page,&page); - page.width=(unsigned long) (page.width*image->x_resolution/delta.x+0.5); - page.height=(unsigned long) (page.height*image->y_resolution/delta.y+0.5); + page.width=(unsigned long) floor(page.width*image->x_resolution/delta.x+ + 0.5); + page.height=(unsigned long) floor(page.height*image->y_resolution/delta.y+ + 0.5); (void) FormatMagickString(options,MaxTextExtent,"-g%lux%lu ",page.width, page.height); } @@ -1263,9 +1265,9 @@ static MagickBooleanType WritePDFImage(const ImageInfo *image_info,Image *image) (void) ParseMetaGeometry(page_geometry,&geometry.x,&geometry.y, &geometry.width,&geometry.height); scale.x=(double) (geometry.width*delta.x)/resolution.x; - geometry.width=(unsigned long) (scale.x+0.5); + geometry.width=(unsigned long) floor(scale.x+0.5); scale.y=(double) (geometry.height*delta.y)/resolution.y; - geometry.height=(unsigned long) (scale.y+0.5); + geometry.height=(unsigned long) floor(scale.y+0.5); (void) ParseAbsoluteGeometry(page_geometry,&media_info); (void) ParseGravityGeometry(image,page_geometry,&page_info, &image->exception); diff --git a/coders/ps.c b/coders/ps.c index 5ee5cbe6d..d204f5b38 100644 --- a/coders/ps.c +++ b/coders/ps.c @@ -669,8 +669,8 @@ static Image *ReadPSImage(const ImageInfo *image_info,ExceptionInfo *exception) "%gx%g%+.15g%+.15g",bounds.x2-bounds.x1,bounds.y2-bounds.y1, bounds.x1,bounds.y1); (void) SetImageProperty(image,"ps:HiResBoundingBox",geometry); - page.width=(unsigned long) (bounds.x2-bounds.x1+0.5); - page.height=(unsigned long) (bounds.y2-bounds.y1+0.5); + page.width=(unsigned long) floor(bounds.x2-bounds.x1+0.5); + page.height=(unsigned long) floor(bounds.y2-bounds.y1+0.5); hires_bounds=bounds; } } @@ -722,8 +722,9 @@ static Image *ReadPSImage(const ImageInfo *image_info,ExceptionInfo *exception) (void) ParseAbsoluteGeometry(image_info->page,&page); (void) FormatMagickString(density,MaxTextExtent,"%gx%g", image->x_resolution,image->y_resolution); - page.width=(unsigned long) (page.width*image->x_resolution/delta.x+0.5); - page.height=(unsigned long) (page.height*image->y_resolution/delta.y+0.5); + page.width=(unsigned long) floor(page.width*image->x_resolution/delta.x+0.5); + page.height=(unsigned long) floor(page.height*image->y_resolution/delta.y+ + 0.5); (void) FormatMagickString(options,MaxTextExtent,"-g%lux%lu ", page.width,page.height); read_info=CloneImageInfo(image_info); @@ -1433,9 +1434,9 @@ static MagickBooleanType WritePSImage(const ImageInfo *image_info,Image *image) (void) ParseMetaGeometry(page_geometry,&geometry.x,&geometry.y, &geometry.width,&geometry.height); scale.x=(double) (geometry.width*delta.x)/resolution.x; - geometry.width=(unsigned long) (scale.x+0.5); + geometry.width=(unsigned long) floor(scale.x+0.5); scale.y=(double) (geometry.height*delta.y)/resolution.y; - geometry.height=(unsigned long) (scale.y+0.5); + geometry.height=(unsigned long) floor(scale.y+0.5); (void) ParseAbsoluteGeometry(page_geometry,&media_info); (void) ParseGravityGeometry(image,page_geometry,&page_info, &image->exception); @@ -1482,9 +1483,9 @@ static MagickBooleanType WritePSImage(const ImageInfo *image_info,Image *image) else { (void) FormatMagickString(buffer,MaxTextExtent, - "%%%%BoundingBox: %ld %ld %ld %ld\n",(long) (bounds.x1+0.5), - (long) (bounds.y1+0.5),(long) (bounds.x2+0.5), - (long) (bounds.y2+0.5)); + "%%%%BoundingBox: %ld %ld %ld %ld\n",(long) ceil(bounds.x1-0.5), + (long) ceil(bounds.y1-0.5),(long) floor(bounds.x2+0.5), + (long) floor(bounds.y2+0.5)); (void) WriteBlobString(image,buffer); (void) FormatMagickString(buffer,MaxTextExtent, "%%%%HiResBoundingBox: %g %g %g %g\n",bounds.x1, @@ -2088,8 +2089,9 @@ static MagickBooleanType WritePSImage(const ImageInfo *image_info,Image *image) if (page > 2) { (void) FormatMagickString(buffer,MaxTextExtent, - "%%%%BoundingBox: %ld %ld %ld %ld\n",(long) (bounds.x1+0.5), - (long) (bounds.y1+0.5),(long) (bounds.x2+0.5),(long) (bounds.y2+0.5)); + "%%%%BoundingBox: %ld %ld %ld %ld\n",(long) ceil(bounds.x1-0.5), + (long) ceil(bounds.y1-0.5),(long) floor(bounds.x2+0.5),(long) + floor(bounds.y2+0.5)); (void) WriteBlobString(image,buffer); (void) FormatMagickString(buffer,MaxTextExtent, "%%%%HiResBoundingBox: %g %g %g %g\n",bounds.x1,bounds.y1, diff --git a/coders/ps2.c b/coders/ps2.c index b373d284c..76c78bd68 100644 --- a/coders/ps2.c +++ b/coders/ps2.c @@ -531,9 +531,9 @@ static MagickBooleanType WritePS2Image(const ImageInfo *image_info,Image *image) (void) ParseMetaGeometry(page_geometry,&geometry.x,&geometry.y, &geometry.width,&geometry.height); scale.x=(double) (geometry.width*delta.x)/resolution.x; - geometry.width=(unsigned long) (scale.x+0.5); + geometry.width=(unsigned long) floor(scale.x+0.5); scale.y=(double) (geometry.height*delta.y)/resolution.y; - geometry.height=(unsigned long) (scale.y+0.5); + geometry.height=(unsigned long) floor(scale.y+0.5); (void) ParseAbsoluteGeometry(page_geometry,&media_info); (void) ParseGravityGeometry(image,page_geometry,&page_info, &image->exception); @@ -580,9 +580,9 @@ static MagickBooleanType WritePS2Image(const ImageInfo *image_info,Image *image) else { (void) FormatMagickString(buffer,MaxTextExtent, - "%%%%BoundingBox: %ld %ld %ld %ld\n",(long) (bounds.x1+0.5), - (long) (bounds.y1+0.5), - (long) (bounds.x2+0.5),(long) (bounds.y2+0.5)); + "%%%%BoundingBox: %ld %ld %ld %ld\n",(long) ceil(bounds.x1-0.5), + (long) ceil(bounds.y1-0.5),(long) floor(bounds.x2+0.5),(long) + floor(bounds.y2+0.5)); (void) WriteBlobString(image,buffer); (void) FormatMagickString(buffer,MaxTextExtent, "%%%%HiResBoundingBox: %g %g %g %g\n",bounds.x1, @@ -1093,8 +1093,9 @@ static MagickBooleanType WritePS2Image(const ImageInfo *image_info,Image *image) if (page > 1) { (void) FormatMagickString(buffer,MaxTextExtent, - "%%%%BoundingBox: %ld %ld %ld %ld\n",(long) (bounds.x1+0.5), - (long) (bounds.y1+0.5),(long) (bounds.x2+0.5),(long) (bounds.y2+0.5)); + "%%%%BoundingBox: %ld %ld %ld %ld\n",(long) ceil(bounds.x1-0.5), + (long) ceil(bounds.y1-0.5),(long) floor(bounds.x2+0.5),(long) + floor(bounds.y2+0.5)); (void) WriteBlobString(image,buffer); (void) FormatMagickString(buffer,MaxTextExtent, "%%%%HiResBoundingBox: %g %g %g %g\n",bounds.x1,bounds.y1, diff --git a/coders/ps3.c b/coders/ps3.c index e5282339d..4a2d4784f 100644 --- a/coders/ps3.c +++ b/coders/ps3.c @@ -952,9 +952,9 @@ static MagickBooleanType WritePS3Image(const ImageInfo *image_info,Image *image) (void) ParseMetaGeometry(page_geometry,&geometry.x,&geometry.y, &geometry.width,&geometry.height); scale.x=(double) (geometry.width*delta.x)/resolution.x; - geometry.width=(unsigned long) (scale.x+0.5); + geometry.width=(unsigned long) floor(scale.x+0.5); scale.y=(double) (geometry.height*delta.y)/resolution.y; - geometry.height=(unsigned long) (scale.y+0.5); + geometry.height=(unsigned long) floor(scale.y+0.5); (void) ParseAbsoluteGeometry(page_geometry,&media_info); (void) ParseGravityGeometry(image,page_geometry,&page_info, &image->exception); diff --git a/coders/svg.c b/coders/svg.c index a65a5265b..b9a83384c 100644 --- a/coders/svg.c +++ b/coders/svg.c @@ -2114,8 +2114,8 @@ static void SVGStartElement(void *context,const xmlChar *name, if ((svg_info->view_box.width == 0.0) || (svg_info->view_box.height == 0.0)) svg_info->view_box=svg_info->bounds; - svg_info->width=(unsigned long) (svg_info->bounds.width+0.5); - svg_info->height=(unsigned long) (svg_info->bounds.height+0.5); + svg_info->width=(unsigned long) floor(svg_info->bounds.width+0.5); + svg_info->height=(unsigned long) floor(svg_info->bounds.height+0.5); MVGPrintf(svg_info->file,"viewbox 0 0 %lu %lu\n",svg_info->width, svg_info->height); sx=(double) svg_info->width/svg_info->view_box.width; diff --git a/coders/tiff.c b/coders/tiff.c index 807c127f5..71441494f 100644 --- a/coders/tiff.c +++ b/coders/tiff.c @@ -949,8 +949,8 @@ static Image *ReadTIFFImage(const ImageInfo *image_info, y_position=(float) image->page.y/y_resolution; (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_XPOSITION,&x_position); (void) TIFFGetFieldDefaulted(tiff,TIFFTAG_YPOSITION,&y_position); - image->page.x=(long) (x_position*x_resolution+0.5); - image->page.y=(long) (y_position*y_resolution+0.5); + image->page.x=(long) ceil(x_position*x_resolution-0.5); + image->page.y=(long) ceil(y_position*y_resolution-0.5); image->orientation=(OrientationType) orientation; chromaticity=(float *) NULL; (void) TIFFGetField(tiff,TIFFTAG_WHITEPOINT,&chromaticity); diff --git a/coders/txt.c b/coders/txt.c index 30d29a612..7d78b9744 100644 --- a/coders/txt.c +++ b/coders/txt.c @@ -223,9 +223,10 @@ static Image *ReadTEXTImage(const ImageInfo *image_info,Image *image, /* Initialize Image structure. */ - image->columns=(unsigned long) (((page.width*image->x_resolution)/ + image->columns=(unsigned long) floor(((page.width*image->x_resolution)/ delta.x)+0.5); - image->rows=(unsigned long) (((page.height*image->y_resolution)/delta.y)+0.5); + image->rows=(unsigned long) floor(((page.height*image->y_resolution)/ + delta.y)+0.5); image->page.x=0; image->page.y=0; texture=(Image *) NULL; @@ -252,7 +253,7 @@ static Image *ReadTEXTImage(const ImageInfo *image_info,Image *image, status=GetTypeMetrics(image,draw_info,&metrics); if (status == MagickFalse) ThrowReaderException(TypeError,"UnableToGetTypeMetrics"); - page.y=(long) (page.y+metrics.ascent+0.5); + page.y=(long) ceil(page.y+metrics.ascent-0.5); (void) FormatMagickString(geometry,MaxTextExtent,"0x0%+ld%+ld",page.x,page.y); (void) CloneString(&draw_info->geometry,geometry); (void) CopyMagickString(filename,image_info->filename,MaxTextExtent); diff --git a/coders/xps.c b/coders/xps.c index a6dd47981..51a347cd9 100644 --- a/coders/xps.c +++ b/coders/xps.c @@ -248,8 +248,8 @@ static Image *ReadXPSImage(const ImageInfo *image_info,ExceptionInfo *exception) /* Set XPS render geometry. */ - width=(unsigned long) (bounds.x2-bounds.x1+0.5); - height=(unsigned long) (bounds.y2-bounds.y1+0.5); + width=(unsigned long) floor(bounds.x2-bounds.x1+0.5); + height=(unsigned long) floor(bounds.y2-bounds.y1+0.5); if (width > page.width) page.width=width; if (height > page.height) @@ -279,8 +279,9 @@ static Image *ReadXPSImage(const ImageInfo *image_info,ExceptionInfo *exception) (void) ParseAbsoluteGeometry(PSPageGeometry,&page); if (image_info->page != (char *) NULL) (void) ParseAbsoluteGeometry(image_info->page,&page); - page.width=(unsigned long) (page.width*image->y_resolution/delta.x+0.5); - page.height=(unsigned long) (page.height*image->y_resolution/delta.y+0.5); + page.width=(unsigned long) floor(page.width*image->y_resolution/delta.x+0.5); + page.height=(unsigned long) floor(page.height*image->y_resolution/delta.y+ + 0.5); (void) FormatMagickString(options,MaxTextExtent,"-g%lux%lu ", page.width,page.height); image=DestroyImage(image); diff --git a/magick/annotate.c b/magick/annotate.c index 188c0dad7..e3faef039 100644 --- a/magick/annotate.c +++ b/magick/annotate.c @@ -503,7 +503,7 @@ MagickExport long FormatMagickCaption(Image *image,DrawInfo *draw_info, status=GetTypeMetrics(image,draw_info,metrics); if (status == MagickFalse) break; - width=(unsigned long) (metrics->width+0.5); + width=(unsigned long) floor(metrics->width+0.5); if (GetUTFCode(p) != '\n') if (width <= image->columns) continue; @@ -817,7 +817,7 @@ static MagickBooleanType RenderType(Image *image,const DrawInfo *draw_info, TypeWarning,"UnableToReadFont","`%s'",draw_info->family); } if (type_info == (const TypeInfo *) NULL) - type_info=GetTypeInfoByFamily("Utopia",draw_info->style, + type_info=GetTypeInfoByFamily("Century Schoolbook",draw_info->style, draw_info->stretch,draw_info->weight,&image->exception); if (type_info == (const TypeInfo *) NULL) type_info=GetTypeInfoByFamily("Arial",draw_info->style, @@ -1291,8 +1291,8 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info, if (status == MagickFalse) continue; - x_offset=(long) (point.x+0.5); - y_offset=(long) (point.y+y+0.5); + x_offset=(long) ceil(point.x-0.5); + y_offset=(long) ceil(point.y+y-0.5); if ((y_offset < 0) || (y_offset >= (long) image->rows)) continue; q=(PixelPacket *) NULL; @@ -1470,8 +1470,8 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info, if (status == MagickFalse) continue; - x_offset=(long) (point.x+0.5); - y_offset=(long) (point.y+y+0.5); + x_offset=(long) ceil(point.x-0.5); + y_offset=(long) ceil(point.y+y-0.5); if ((y_offset < 0) || (y_offset >= (long) image->rows)) continue; q=(PixelPacket *) NULL; @@ -1780,7 +1780,7 @@ static MagickBooleanType RenderPostscript(Image *image, (void) fprintf(file,"showpage\n"); (void) fclose(file); (void) FormatMagickString(geometry,MaxTextExtent,"%ldx%ld+0+0!",(long) - (extent.x+0.5),(long) (extent.y+0.5)); + floor(extent.x+0.5),(long) floor(extent.y+0.5)); annotate_info=AcquireImageInfo(); (void) FormatMagickString(annotate_info->filename,MaxTextExtent,"ps:%s", filename); @@ -1820,7 +1820,8 @@ static MagickBooleanType RenderPostscript(Image *image, crop_info=GetImageBoundingBox(annotate_image,&annotate_image->exception); crop_info.height=(unsigned long) ((resolution.y/DefaultResolution)* ExpandAffine(&draw_info->affine)*draw_info->pointsize+0.5); - crop_info.y=(long) ((resolution.y/DefaultResolution)*extent.y/8.0+0.5); + crop_info.y=(long) ceil((resolution.y/DefaultResolution)*extent.y/8.0- + 0.5); (void) FormatMagickString(geometry,MaxTextExtent,"%lux%lu%+ld%+ld", crop_info.width,crop_info.height,crop_info.x,crop_info.y); (void) TransformImage(&annotate_image,geometry,(char *) NULL); @@ -1898,8 +1899,8 @@ static MagickBooleanType RenderPostscript(Image *image, } annotate_view=DestroyCacheView(annotate_view); (void) CompositeImage(image,OverCompositeOp,annotate_image, - (long) (offset->x+0.5),(long) (offset->y-(metrics->ascent+ - metrics->descent)+0.5)); + (long) ceil(offset->x-0.5),(long) ceil(offset->y-(metrics->ascent+ + metrics->descent)-0.5)); } annotate_image=DestroyImage(annotate_image); return(MagickTrue); @@ -2113,9 +2114,9 @@ static MagickBooleanType RenderX11(Image *image,const DrawInfo *draw_info, atan2(draw_info->affine.rx,draw_info->affine.sx); } (void) FormatMagickString(annotate_info.geometry,MaxTextExtent, - "%lux%lu+%ld+%ld",width,height,(long) (offset->x+0.5), - (long) (offset->y-metrics->ascent-metrics->descent+ - draw_info->interline_spacing+0.5)); + "%lux%lu+%ld+%ld",width,height,(long) ceil(offset->x-0.5), + (long) ceil(offset->y-metrics->ascent-metrics->descent+ + draw_info->interline_spacing-0.5)); pixel.pen_color.red=ScaleQuantumToShort(draw_info->fill.red); pixel.pen_color.green=ScaleQuantumToShort(draw_info->fill.green); pixel.pen_color.blue=ScaleQuantumToShort(draw_info->fill.blue); diff --git a/magick/display.c b/magick/display.c index 15ca70ade..61ac790da 100644 --- a/magick/display.c +++ b/magick/display.c @@ -8517,7 +8517,7 @@ static Image *XMagickCommand(Display *display,XResourceInfo *resource_info, if ((flags & PsiValue) == 0) geometry_info.psi=0.1*(*image)->rows; vignette_image=VignetteImage(*image,geometry_info.rho,geometry_info.sigma, - (long) (geometry_info.xi+0.5),(long) (geometry_info.psi+0.5), + (long) floor(geometry_info.xi+0.5),(long) floor(geometry_info.psi+0.5), &(*image)->exception); if (vignette_image != (Image *) NULL) { diff --git a/magick/distort.c b/magick/distort.c index 3b805de25..f353cee3b 100644 --- a/magick/distort.c +++ b/magick/distort.c @@ -127,7 +127,9 @@ static void InvertPerspectiveCoefficients(const double *coeff, static inline double MagickRound(double x) { - /* round the fraction to nearest integer */ + /* + Round the fraction to nearest integer. + */ if (x >= 0.0) return((double) ((long) (x+0.5))); return((double) ((long) (x-0.5))); @@ -1607,10 +1609,10 @@ MagickExport Image *DistortImage(const Image *image,DistortImageMethod method, Do not do this for DePolar which needs to be exact for tiling */ if ( bestfit && method != DePolarDistortion ) { - geometry.x = (long) floor(min.x-0.5); - geometry.y = (long) floor(min.y-0.5); - geometry.width=(unsigned long) ceil(max.x-geometry.x+0.5); - geometry.height=(unsigned long) ceil(max.y-geometry.y+0.5); + geometry.x = (long) ceil(min.x-0.5); + geometry.y = (long) ceil(min.y-0.5); + geometry.width=(unsigned long) floor(max.x-geometry.x+0.5); + geometry.height=(unsigned long) floor(max.y-geometry.y+0.5); } /* now that we have a new size lets fit distortion to it exactly */ if ( method == DePolarDistortion ) { diff --git a/magick/draw.c b/magick/draw.c index 4b1582458..29a353115 100644 --- a/magick/draw.c +++ b/magick/draw.c @@ -997,7 +997,7 @@ static SegmentInfo AffineEdge(const Image *image,const AffineMatrix *affine, inverse_edge.x2=x; } else - if ((z < 0.0) || ((unsigned long) (z+0.5) >= image->columns)) + if ((z < 0.0) || ((unsigned long) floor(z+0.5) >= image->columns)) { inverse_edge.x2=edge->x1; return(inverse_edge); @@ -1030,7 +1030,7 @@ static SegmentInfo AffineEdge(const Image *image,const AffineMatrix *affine, inverse_edge.x2=x; } else - if ((z < 0.0) || ((unsigned long) (z+0.5) >= image->rows)) + if ((z < 0.0) || ((unsigned long) floor(z+0.5) >= image->rows)) { inverse_edge.x2=edge->x2; return(inverse_edge); @@ -1173,7 +1173,7 @@ MagickExport MagickBooleanType DrawAffineImage(Image *image, #if defined(MAGICKCORE_OPENMP_SUPPORT) #pragma omp parallel for schedule(dynamic,4) shared(status) #endif - for (y=(long) (edge.y1+0.5); y <= (long) (edge.y2+0.5); y++) + for (y=(long) ceil(edge.y1-0.5); y <= (long) floor(edge.y2+0.5); y++) { long x_offset; @@ -1201,9 +1201,9 @@ MagickExport MagickBooleanType DrawAffineImage(Image *image, inverse_edge=AffineEdge(source,&inverse_affine,(double) y,&edge); if (inverse_edge.x2 < inverse_edge.x1) continue; - q=GetCacheViewAuthenticPixels(image_view,(long) (inverse_edge.x1+0.5),y, - (unsigned long) ((long) (inverse_edge.x2+0.5)-(long) (inverse_edge.x1+ - 0.5)+1),1,exception); + q=GetCacheViewAuthenticPixels(image_view,(long) ceil(inverse_edge.x1-0.5),y, + (unsigned long) ((long) floor(inverse_edge.x2+0.5)-(long) floor( + inverse_edge.x1+0.5)+1),1,exception); if (q == (PixelPacket *) NULL) continue; id=GetOpenMPThreadId(); @@ -1211,7 +1211,7 @@ MagickExport MagickBooleanType DrawAffineImage(Image *image, pixel=zero; composite=zero; x_offset=0; - for (x=(long) (inverse_edge.x1+0.5); x <= (long) (inverse_edge.x2+0.5); x++) + for (x=(long) ceil(inverse_edge.x1-0.5); x <= (long) floor(inverse_edge.x2+0.5); x++) { point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+ inverse_affine.tx; @@ -2391,19 +2391,19 @@ MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info) GetMagickToken(q,&q,token); (void) CopyMagickString(name,token,MaxTextExtent); GetMagickToken(q,&q,token); - bounds.x=(long) (StringToDouble(token)+0.5); + bounds.x=(long) ceil(StringToDouble(token)-0.5); GetMagickToken(q,&q,token); if (*token == ',') GetMagickToken(q,&q,token); - bounds.y=(long) (StringToDouble(token)+0.5); + bounds.y=(long) ceil(StringToDouble(token)-0.5); GetMagickToken(q,&q,token); if (*token == ',') GetMagickToken(q,&q,token); - bounds.width=(unsigned long) (StringToDouble(token)+0.5); + bounds.width=(unsigned long) floor(StringToDouble(token)+0.5); GetMagickToken(q,&q,token); if (*token == ',') GetMagickToken(q,&q,token); - bounds.height=(unsigned long) (StringToDouble(token)+0.5); + bounds.height=(unsigned long) floor(StringToDouble(token)+0.5); for (p=q; *q != '\0'; ) { GetMagickToken(q,&q,token); @@ -2726,20 +2726,23 @@ MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info) if (LocaleCompare("viewbox",keyword) == 0) { GetMagickToken(q,&q,token); - graphic_context[n]->viewbox.x=(long) (StringToDouble(token)+0.5); + graphic_context[n]->viewbox.x=(long) ceil(StringToDouble(token)- + 0.5); GetMagickToken(q,&q,token); if (*token == ',') GetMagickToken(q,&q,token); - graphic_context[n]->viewbox.y=(long) (StringToDouble(token)+0.5); + graphic_context[n]->viewbox.y=(long) ceil(StringToDouble(token)- + 0.5); GetMagickToken(q,&q,token); if (*token == ',') GetMagickToken(q,&q,token); - graphic_context[n]->viewbox.width=(unsigned long) (StringToDouble(token)+0.5); + graphic_context[n]->viewbox.width=(unsigned long) floor( + StringToDouble(token)+0.5); GetMagickToken(q,&q,token); if (*token == ',') GetMagickToken(q,&q,token); - graphic_context[n]->viewbox.height=(unsigned long) (StringToDouble(token)+ - 0.5); + graphic_context[n]->viewbox.height=(unsigned long) floor( + StringToDouble(token)+0.5); break; } status=MagickFalse; @@ -3323,8 +3326,8 @@ MagickExport MagickBooleanType DrawGradientImage(Image *image, case UndefinedSpread: case PadSpread: { - if ((x != (long) (gradient_vector->x1+0.5)) || - (y != (long) (gradient_vector->y1+0.5))) + if ((x != (long) ceil(gradient_vector->x1-0.5)) || + (y != (long) ceil(gradient_vector->y1-0.5))) { offset=GetStopColorOffset(gradient,x,y); if (gradient->type != RadialGradient) @@ -3351,8 +3354,8 @@ MagickExport MagickBooleanType DrawGradientImage(Image *image, } case ReflectSpread: { - if ((x != (long) (gradient_vector->x1+0.5)) || - (y != (long) (gradient_vector->y1+0.5))) + if ((x != (long) ceil(gradient_vector->x1-0.5)) || + (y != (long) ceil(gradient_vector->y1-0.5))) { offset=GetStopColorOffset(gradient,x,y); if (gradient->type != RadialGradient) @@ -3393,8 +3396,8 @@ MagickExport MagickBooleanType DrawGradientImage(Image *image, antialias=MagickFalse; repeat=0.0; - if ((x != (long) (gradient_vector->x1+0.5)) || - (y != (long) (gradient_vector->y1+0.5))) + if ((x != (long) ceil(gradient_vector->x1-0.5)) || + (y != (long) ceil(gradient_vector->y1-0.5))) { offset=GetStopColorOffset(gradient,x,y); if (gradient->type == LinearGradient) @@ -3862,21 +3865,21 @@ static MagickBooleanType DrawPolygonPrimitive(Image *image, bounds.y2=p->bounds.y2; } bounds.x1-=(mid+1.0); - bounds.x1=bounds.x1 < 0.0 ? 0.0 : (unsigned long) (bounds.x1+0.5) >= + bounds.x1=bounds.x1 < 0.0 ? 0.0 : (unsigned long) ceil(bounds.x1-0.5) >= image->columns ? (double) image->columns-1.0 : bounds.x1; bounds.y1-=(mid+1.0); - bounds.y1=bounds.y1 < 0.0 ? 0.0 : (unsigned long) (bounds.y1+0.5) >= + bounds.y1=bounds.y1 < 0.0 ? 0.0 : (unsigned long) ceil(bounds.y1-0.5) >= image->rows ? (double) image->rows-1.0 : bounds.y1; bounds.x2+=(mid+1.0); - bounds.x2=bounds.x2 < 0.0 ? 0.0 : (unsigned long) (bounds.x2+0.5) >= + bounds.x2=bounds.x2 < 0.0 ? 0.0 : (unsigned long) floor(bounds.x2+0.5) >= image->columns ? (double) image->columns-1.0 : bounds.x2; bounds.y2+=(mid+1.0); - bounds.y2=bounds.y2 < 0.0 ? 0.0 : (unsigned long) (bounds.y2+0.5) >= + bounds.y2=bounds.y2 < 0.0 ? 0.0 : (unsigned long) floor(bounds.y2+0.5) >= image->rows ? (double) image->rows-1.0 : bounds.y2; status=MagickTrue; exception=(&image->exception); - start=(long) (bounds.x1+0.5); - stop=(long) (bounds.x2+0.5); + start=(long) ceil(bounds.x1-0.5); + stop=(long) floor(bounds.x2+0.5); image_view=AcquireCacheView(image); if (primitive_info->coordinates == 1) { @@ -3886,7 +3889,7 @@ static MagickBooleanType DrawPolygonPrimitive(Image *image, #if defined(MAGICKCORE_OPENMP_SUPPORT) #pragma omp parallel for schedule(dynamic,4) shared(status) #endif - for (y=(long) (bounds.y1+0.5); y <= (long) (bounds.y2+0.5); y++) + for (y=(long) ceil(bounds.y1-0.5); y <= (long) floor(bounds.y2+0.5); y++) { MagickBooleanType sync; @@ -3909,8 +3912,8 @@ static MagickBooleanType DrawPolygonPrimitive(Image *image, } for ( ; x <= stop; x++) { - if ((x == (long) (primitive_info->point.x+0.5)) && - (y == (long) (primitive_info->point.y+0.5))) + if ((x == (long) ceil(primitive_info->point.x-0.5)) && + (y == (long) ceil(primitive_info->point.y-0.5))) (void) GetStrokeColor(draw_info,x,y,q); q++; } @@ -3933,7 +3936,7 @@ static MagickBooleanType DrawPolygonPrimitive(Image *image, #if defined(MAGICKCORE_OPENMP_SUPPORT) #pragma omp parallel for schedule(dynamic,4) shared(status) #endif - for (y=(long) (bounds.y1+0.5); y <= (long) (bounds.y2+0.5); y++) + for (y=(long) ceil(bounds.y1-0.5); y <= (long) floor(bounds.y2+0.5); y++) { MagickRealType fill_opacity, @@ -4048,8 +4051,8 @@ static void LogPrimitiveInfo(const PrimitiveInfo *primitive_info) i, x; - x=(long) (primitive_info->point.x+0.5); - y=(long) (primitive_info->point.y+0.5); + x=(long) ceil(primitive_info->point.x-0.5); + y=(long) ceil(primitive_info->point.y-0.5); switch (primitive_info->primitive) { case PointPrimitive: @@ -4151,8 +4154,8 @@ MagickExport MagickBooleanType DrawPrimitive(Image *image, } status=MagickTrue; exception=(&image->exception); - x=(long) (primitive_info->point.x+0.5); - y=(long) (primitive_info->point.y+0.5); + x=(long) ceil(primitive_info->point.x-0.5); + y=(long) ceil(primitive_info->point.y-0.5); image_view=AcquireCacheView(image); switch (primitive_info->primitive) { @@ -4449,8 +4452,8 @@ MagickExport MagickBooleanType DrawPrimitive(Image *image, break; (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor) NULL,(void *) NULL); - x1=(long) (primitive_info[1].point.x+0.5); - y1=(long) (primitive_info[1].point.y+0.5); + x1=(long) ceil(primitive_info[1].point.x-0.5); + y1=(long) ceil(primitive_info[1].point.y-0.5); if (((x1 != 0L) && (x1 != (long) composite_image->columns)) || ((y1 != 0L) && (y1 != (long) composite_image->rows))) { diff --git a/magick/effect.c b/magick/effect.c index 690167044..e426759fe 100644 --- a/magick/effect.c +++ b/magick/effect.c @@ -316,7 +316,7 @@ MagickExport Image *AdaptiveBlurImageChannel(const Image *image, v; gamma=0.0; - i=(long) (width*QuantumScale*PixelIntensity(r)+0.5); + i=(long) ceil(width*QuantumScale*PixelIntensity(r)-0.5); if (i < 0) i=0; else @@ -631,7 +631,7 @@ MagickExport Image *AdaptiveSharpenImageChannel(const Image *image, v; gamma=0.0; - i=(long) (width*(QuantumRange-QuantumScale*PixelIntensity(r))+0.5); + i=(long) ceil(width*(QuantumRange-QuantumScale*PixelIntensity(r))-0.5); if (i < 0) i=0; else @@ -3167,8 +3167,8 @@ MagickExport Image *MotionBlurImageChannel(const Image *image, point.y=(double) width*cos(DegreesToRadians(angle)); for (i=0; i < (long) width; i++) { - offset[i].x=(long) ((i*point.y)/hypot(point.x,point.y)+0.5); - offset[i].y=(long) ((i*point.x)/hypot(point.x,point.y)+0.5); + offset[i].x=(long) ceil((i*point.y)/hypot(point.x,point.y)-0.5); + offset[i].y=(long) ceil((i*point.x)/hypot(point.x,point.y)-0.5); } /* Motion blur image. diff --git a/magick/fx.c b/magick/fx.c index dbc4b2bd5..40f27b7b5 100644 --- a/magick/fx.c +++ b/magick/fx.c @@ -3273,8 +3273,8 @@ MagickExport MagickBooleanType PlasmaImageProxy(Image *image, */ depth--; attenuate++; - x_mid=(long) (segment->x1+segment->x2+0.5)/2; - y_mid=(long) (segment->y1+segment->y2+0.5)/2; + x_mid=(long) ceil(segment->x1+segment->x2-0.5)/2; + y_mid=(long) ceil(segment->y1+segment->y2-0.5)/2; local_info=(*segment); local_info.x2=(double) x_mid; local_info.y2=(double) y_mid; @@ -3294,8 +3294,8 @@ MagickExport MagickBooleanType PlasmaImageProxy(Image *image, } if (SetImageStorageClass(image,DirectClass) == MagickFalse) return(MagickFalse); - x_mid=(long) (segment->x1+segment->x2+0.5)/2; - y_mid=(long) (segment->y1+segment->y2+0.5)/2; + x_mid=(long) ceil(segment->x1+segment->x2-0.5)/2; + y_mid=(long) ceil(segment->y1+segment->y2-0.5)/2; if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) && (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid)) return(MagickFalse); @@ -3312,9 +3312,11 @@ MagickExport MagickBooleanType PlasmaImageProxy(Image *image, /* Left pixel. */ - x=(long) (segment->x1+0.5); - (void) GetOneVirtualPixel(image,x,(long) (segment->y1+0.5),&u,exception); - (void) GetOneVirtualPixel(image,x,(long) (segment->y2+0.5),&v,exception); + x=(long) ceil(segment->x1-0.5); + (void) GetOneVirtualPixel(image,x,(long) ceil(segment->y1-0.5),&u, + exception); + (void) GetOneVirtualPixel(image,x,(long) ceil(segment->y2-0.5),&v, + exception); q=QueueAuthenticPixels(image,x,y_mid,1,1,exception); if (q == (PixelPacket *) NULL) return(MagickTrue); @@ -3330,10 +3332,10 @@ MagickExport MagickBooleanType PlasmaImageProxy(Image *image, /* Right pixel. */ - x=(long) (segment->x2+0.5); - (void) GetOneVirtualPixel(image,x,(long) (segment->y1+0.5),&u, + x=(long) ceil(segment->x2-0.5); + (void) GetOneVirtualPixel(image,x,(long) ceil(segment->y1-0.5),&u, exception); - (void) GetOneVirtualPixel(image,x,(long) (segment->y2+0.5),&v, + (void) GetOneVirtualPixel(image,x,(long) ceil(segment->y2-0.5),&v, exception); q=QueueAuthenticPixels(image,x,y_mid,1,1,exception); if (q == (PixelPacket *) NULL) @@ -3357,10 +3359,10 @@ MagickExport MagickBooleanType PlasmaImageProxy(Image *image, /* Bottom pixel. */ - y=(long) (segment->y2+0.5); - (void) GetOneVirtualPixel(image,(long) (segment->x1+0.5),y,&u, + y=(long) ceil(segment->y2-0.5); + (void) GetOneVirtualPixel(image,(long) ceil(segment->x1-0.5),y,&u, exception); - (void) GetOneVirtualPixel(image,(long) (segment->x2+0.5),y,&v, + (void) GetOneVirtualPixel(image,(long) ceil(segment->x2-0.5),y,&v, exception); q=QueueAuthenticPixels(image,x_mid,y,1,1,exception); if (q == (PixelPacket *) NULL) @@ -3381,10 +3383,10 @@ MagickExport MagickBooleanType PlasmaImageProxy(Image *image, /* Top pixel. */ - y=(long) (segment->y1+0.5); - (void) GetOneVirtualPixel(image,(long) (segment->x1+0.5),y,&u, + y=(long) ceil(segment->y1-0.5); + (void) GetOneVirtualPixel(image,(long) ceil(segment->x1-0.5),y,&u, exception); - (void) GetOneVirtualPixel(image,(long) (segment->x2+0.5),y,&v, + (void) GetOneVirtualPixel(image,(long) ceil(segment->x2-0.5),y,&v, exception); q=QueueAuthenticPixels(image,x_mid,y,1,1,exception); if (q == (PixelPacket *) NULL) @@ -3406,11 +3408,11 @@ MagickExport MagickBooleanType PlasmaImageProxy(Image *image, /* Middle pixel. */ - x=(long) (segment->x1+0.5); - y=(long) (segment->y1+0.5); + x=(long) ceil(segment->x1-0.5); + y=(long) ceil(segment->y1-0.5); (void) GetOneVirtualPixel(image,x,y,&u,exception); - x=(long) (segment->x2+0.5); - y=(long) (segment->y2+0.5); + x=(long) ceil(segment->x2-0.5); + y=(long) ceil(segment->y2-0.5); (void) GetOneVirtualPixel(image,x,y,&v,exception); q=QueueAuthenticPixels(image,x_mid,y_mid,1,1,exception); if (q == (PixelPacket *) NULL) @@ -4109,8 +4111,8 @@ MagickExport Image *ShadowImage(const Image *image,const double opacity, return((Image *) NULL); (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod); clone_image->compose=OverCompositeOp; - border_info.width=(unsigned long) (2.0*sigma+0.5); - border_info.height=(unsigned long) (2.0*sigma+0.5); + border_info.width=(unsigned long) floor(2.0*sigma+0.5); + border_info.height=(unsigned long) floor(2.0*sigma+0.5); border_info.x=0; border_info.y=0; (void) QueryColorDatabase("none",&clone_image->border_color,exception); diff --git a/magick/geometry.c b/magick/geometry.c index 0f9a16cfc..d51c1a3ab 100644 --- a/magick/geometry.c +++ b/magick/geometry.c @@ -1014,8 +1014,10 @@ MagickExport MagickStatusType ParseGravityGeometry(const Image *image, scale.y=geometry_info.sigma; if ((status & SigmaValue) == 0) scale.y=scale.x; - region_info->width=(unsigned long) ((scale.x*image->columns/100.0)+0.5); - region_info->height=(unsigned long) ((scale.y*image->rows/100.0)+0.5); + region_info->width=(unsigned long) floor((scale.x*image->columns/100.0)+ + 0.5); + region_info->height=(unsigned long) floor((scale.y*image->rows/100.0)+ + 0.5); } /* Adjust offset according to gravity setting. @@ -1119,10 +1121,10 @@ MagickExport MagickStatusType ParseMetaGeometry(const char *geometry,long *x, scale.y=geometry_info.sigma; if ((flags & SigmaValue) == 0) scale.y=scale.x; - *width=(unsigned long) (scale.x*former_width/100.0+0.5); + *width=(unsigned long) floor(scale.x*former_width/100.0-0.5); if (*width == 0) *width=1; - *height=(unsigned long) (scale.y*former_height/100.0+0.5); + *height=(unsigned long) floor(scale.y*former_height/100.0-0.5); if (*height == 0) *height=1; former_width=(*width); @@ -1177,8 +1179,10 @@ MagickExport MagickStatusType ParseMetaGeometry(const char *geometry,long *x, scale_factor=(MagickRealType) *height/(MagickRealType) former_width; } - *width=MagickMax((unsigned long) (scale_factor*former_width+0.5),1UL); - *height=MagickMax((unsigned long) (scale_factor*former_height+0.5),1UL); + *width=MagickMax((unsigned long) floor(scale_factor*former_width+0.5), + 1UL); + *height=MagickMax((unsigned long) floor(scale_factor*former_height+0.5), + 1UL); } if ((flags & GreaterValue) != 0) { diff --git a/magick/image.c b/magick/image.c index 9c6610fba..902141161 100644 --- a/magick/image.c +++ b/magick/image.c @@ -890,13 +890,13 @@ MagickExport Image *CloneImage(const Image *image,const unsigned long columns, return(clone_image); } scale=(MagickRealType) columns/(MagickRealType) image->columns; - clone_image->page.width=(unsigned long) (scale*image->page.width+0.5); - clone_image->page.x=(long) (scale*image->page.x+0.5); - clone_image->tile_offset.x=(long) (scale*image->tile_offset.x+0.5); + clone_image->page.width=(unsigned long) floor(scale*image->page.width+0.5); + clone_image->page.x=(long) ceil(scale*image->page.x-0.5); + clone_image->tile_offset.x=(long) ceil(scale*image->tile_offset.x-0.5); scale=(MagickRealType) rows/(MagickRealType) image->rows; - clone_image->page.height=(unsigned long) (scale*image->page.height+0.5); - clone_image->page.y=(long) (image->page.y*scale+0.5); - clone_image->tile_offset.y=(long) (scale*image->tile_offset.y+0.5); + clone_image->page.height=(unsigned long) floor(scale*image->page.height+0.5); + clone_image->page.y=(long) ceil(image->page.y*scale-0.5); + clone_image->tile_offset.y=(long) ceil(scale*image->tile_offset.y-0.5); clone_image->columns=columns; clone_image->rows=rows; clone_image->cache=ClonePixelCache(image->cache); @@ -4015,19 +4015,19 @@ MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info, flags=ParseGeometry(option,&geometry_info); if ((flags & GreaterValue) != 0) { - if (image->delay > (unsigned long) (geometry_info.rho+0.5)) - image->delay=(unsigned long) (geometry_info.rho+0.5); + if (image->delay > (unsigned long) floor(geometry_info.rho+0.5)) + image->delay=(unsigned long) floor(geometry_info.rho+0.5); } else if ((flags & LessValue) != 0) { - if (image->delay < (unsigned long) (geometry_info.rho+0.5)) - image->ticks_per_second=(long) (geometry_info.sigma+0.5); + if (image->delay < (unsigned long) floor(geometry_info.rho+0.5)) + image->ticks_per_second=(long) floor(geometry_info.sigma+0.5); } else - image->delay=(unsigned long) (geometry_info.rho+0.5); + image->delay=(unsigned long) floor(geometry_info.rho+0.5); if ((flags & SigmaValue) != 0) - image->ticks_per_second=(long) (geometry_info.sigma+0.5); + image->ticks_per_second=(long) floor(geometry_info.sigma+0.5); } option=GetImageOption(image_info,"density"); if (option != (const char *) NULL) diff --git a/magick/property.c b/magick/property.c index acbd1926e..cc0e247aa 100644 --- a/magick/property.c +++ b/magick/property.c @@ -3327,19 +3327,19 @@ MagickExport MagickBooleanType SetImageProperty(Image *image, flags=ParseGeometry(value,&geometry_info); if ((flags & GreaterValue) != 0) { - if (image->delay > (unsigned long) (geometry_info.rho+0.5)) - image->delay=(unsigned long) (geometry_info.rho+0.5); + if (image->delay > (unsigned long) floor(geometry_info.rho+0.5)) + image->delay=(unsigned long) floor(geometry_info.rho+0.5); } else if ((flags & LessValue) != 0) { - if (image->delay < (unsigned long) (geometry_info.rho+0.5)) - image->ticks_per_second=(long) (geometry_info.sigma+0.5); + if (image->delay < (unsigned long) floor(geometry_info.rho+0.5)) + image->ticks_per_second=(long) floor(geometry_info.sigma+0.5); } else - image->delay=(unsigned long) (geometry_info.rho+0.5); + image->delay=(unsigned long) floor(geometry_info.rho+0.5); if ((flags & SigmaValue) != 0) - image->ticks_per_second=(long) (geometry_info.sigma+0.5); + image->ticks_per_second=(long) floor(geometry_info.sigma+0.5); break; } if (LocaleCompare(property,"depth") == 0) diff --git a/magick/resize.c b/magick/resize.c index 49290b8af..77128a899 100644 --- a/magick/resize.c +++ b/magick/resize.c @@ -1811,8 +1811,8 @@ static MagickBooleanType HorizontalFilter(const ResizeFilter *resize_filter, if (status == MagickFalse) continue; center=(MagickRealType) (x+0.5)/x_factor; - start=(long) (MagickMax(center-support-MagickEpsilon,0.0)+0.5); - stop=(long) (MagickMin(center+support,(double) image->columns)+0.5); + start=(long) ceil(MagickMax(center-support-MagickEpsilon,0.0)-0.5); + stop=(long) floor(MagickMin(center+support,(double) image->columns)+0.5); density=0.0; contribution=contributions[GetOpenMPThreadId()]; for (n=0; n < (stop-start); n++) @@ -2052,9 +2052,9 @@ static MagickBooleanType VerticalFilter(const ResizeFilter *resize_filter, if (status == MagickFalse) continue; - center=(MagickRealType) (y+0.5)/y_factor; - start=(long) (MagickMax(center-support-MagickEpsilon,0.0)+0.5); - stop=(long) (MagickMin(center+support,(double) image->rows)+0.5); + center=(MagickRealType) (y-0.5)/y_factor; + start=(long) ceil(MagickMax(center-support-MagickEpsilon,0.0)-0.5); + stop=(long) floor(MagickMin(center+support,(double) image->rows)+0.5); density=0.0; contribution=contributions[GetOpenMPThreadId()]; for (n=0; n < (stop-start); n++) @@ -2417,7 +2417,8 @@ MagickExport Image *SampleImage(const Image *image,const unsigned long columns, if (status == MagickFalse) continue; - y_offset=(long) (((MagickRealType) y+0.5)*image->rows/sample_image->rows); + y_offset=(long) ceil(((MagickRealType) y-0.5)*image->rows/ + sample_image->rows); p=GetCacheViewVirtualPixels(image_view,0,y_offset,image->columns,1, exception); q=QueueCacheViewAuthenticPixels(sample_view,0,y,sample_image->columns,1, diff --git a/magick/shear.c b/magick/shear.c index f764b2fa4..a163a0db4 100644 --- a/magick/shear.c +++ b/magick/shear.c @@ -218,10 +218,10 @@ static MagickBooleanType CropToFitImage(Image **image, if (max.y < extent[i].y) max.y=extent[i].y; } - geometry.x=(long) (min.x+0.5); - geometry.y=(long) (min.y+0.5); - geometry.width=(unsigned long) ((long) (max.x+0.5)-(long) (min.x+0.5)); - geometry.height=(unsigned long) ((long) (max.y+0.5)-(long) (min.y+0.5)); + geometry.x=(long) ceil(min.x-0.5); + geometry.y=(long) ceil(min.y-0.5); + geometry.width=(unsigned long) floor(max.x-min.x+0.5); + geometry.height=(unsigned long) floor(max.y-min.y+0.5); page=(*image)->page; (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page); crop_image=CropImage(*image,&geometry,exception); @@ -1932,9 +1932,9 @@ MagickExport Image *RotateImage(const Image *image,const double degrees, width=image->rows; height=image->columns; } - y_width=width+(long) (fabs(shear.x)*height+0.5); - x_offset=(long) (width+((fabs(shear.y)*height)-width)/2.0+0.5); - y_offset=(long) (height+((fabs(shear.y)*y_width)-height)/2.0+0.5); + y_width=width+(long) floor(fabs(shear.x)*height+0.5); + x_offset=(long) ceil(width+((fabs(shear.y)*height)-width)/2.0-0.5); + y_offset=(long) ceil(height+((fabs(shear.y)*y_width)-height)/2.0-0.5); /* Surround image with a border. */ @@ -2076,10 +2076,11 @@ MagickExport Image *ShearImage(const Image *image,const double x_shear, /* Compute image size. */ - y_width=image->columns+(long) (fabs(shear.x)*image->rows+0.5); - x_offset=(long) (image->columns+((fabs(shear.x)*image->rows)-image->columns)/ - 2.0+0.5); - y_offset=(long) (image->rows+((fabs(shear.y)*y_width)-image->rows)/2.0+0.5); + y_width=image->columns+(long) floor(fabs(shear.x)*image->rows+0.5); + x_offset=(long) ceil(image->columns+((fabs(shear.x)*image->rows)- + image->columns)/2.0-0.5); + y_offset=(long) ceil(image->rows+((fabs(shear.y)*y_width)-image->rows)/2.0- + 0.5); /* Surround image with border. */ diff --git a/magick/statistic.c b/magick/statistic.c index 72c493f52..86bd279a1 100644 --- a/magick/statistic.c +++ b/magick/statistic.c @@ -957,8 +957,8 @@ MagickExport MagickBooleanType GetImageChannelExtrema(const Image *image, if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); status=GetImageChannelRange(image,channel,&min,&max,exception); - *minima=(unsigned long) (min+0.5); - *maxima=(unsigned long) (max+0.5); + *minima=(unsigned long) ceil(min-0.5); + *maxima=(unsigned long) floor(max+0.5); return(status); } diff --git a/wand/drawing-wand.c b/wand/drawing-wand.c index 2bbddb137..020e8f75d 100644 --- a/wand/drawing-wand.c +++ b/wand/drawing-wand.c @@ -4175,8 +4175,8 @@ WandExport MagickBooleanType DrawPushPattern(DrawingWand *wand, wand->pattern_id=AcquireString(pattern_id); wand->pattern_bounds.x=(long) ceil(x-0.5); wand->pattern_bounds.y=(long) ceil(y-0.5); - wand->pattern_bounds.width=(unsigned long) (width+0.5); - wand->pattern_bounds.height=(unsigned long) (height+0.5); + wand->pattern_bounds.width=(unsigned long) floor(width+0.5); + wand->pattern_bounds.height=(unsigned long) floor(height+0.5); wand->pattern_offset=wand->mvg_length; return(MagickTrue); } diff --git a/wand/mogrify.c b/wand/mogrify.c index 9bf316d3d..2275532f1 100644 --- a/wand/mogrify.c +++ b/wand/mogrify.c @@ -2993,8 +2993,8 @@ WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc, if ((flags & PsiValue) == 0) geometry_info.psi=4.0; shadow_image=ShadowImage(*image,geometry_info.rho, - geometry_info.sigma,(long) (geometry_info.xi+0.5),(long) - (geometry_info.psi+0.5),exception); + geometry_info.sigma,(long) floor(geometry_info.xi+0.5),(long) + floor(geometry_info.psi+0.5),exception); if (shadow_image == (Image *) NULL) break; *image=DestroyImage(*image); @@ -3499,8 +3499,8 @@ WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc, if ((flags & PsiValue) == 0) geometry_info.psi=0.1*(*image)->rows; vignette_image=VignetteImage(*image,geometry_info.rho, - geometry_info.sigma,(long) (geometry_info.xi+0.5),(long) - (geometry_info.psi+0.5),exception); + geometry_info.sigma,(long) floor(geometry_info.xi+0.5),(long) + floor(geometry_info.psi+0.5),exception); if (vignette_image == (Image *) NULL) break; *image=DestroyImage(*image); @@ -8374,6 +8374,9 @@ WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info, { if (LocaleCompare("write",option+1) == 0) { + char + key[MaxTextExtent]; + Image *write_images; @@ -8381,6 +8384,8 @@ WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info, *write_info; (void) SyncImagesSettings(image_info,*images); + (void) FormatMagickString(key,MaxTextExtent,"cache:%s",argv[i+1]); + (void) DeleteImageRegistry(key); write_images=(*images); if (*option == '+') write_images=CloneImageList(*images,exception);