2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % SSSSS H H EEEEE AAA RRRR %
8 % SSS HHHHH EEE AAAAA RRRR %
10 % SSSSS H H EEEEE A A R R %
13 % MagickCore Methods to Shear or Rotate an Image by an Arbitrary Angle %
20 % Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 % The XShearImage() and YShearImage() methods are based on the paper "A Fast
37 % Algorithm for General Raster Rotatation" by Alan W. Paeth, Graphics
38 % Interface '86 (Vancouver). ShearRotateImage() is adapted from a similar
39 % method based on the Paeth paper written by Michael Halle of the Spatial
40 % Imaging Group, MIT Media Lab.
47 #include "MagickCore/studio.h"
48 #include "MagickCore/artifact.h"
49 #include "MagickCore/attribute.h"
50 #include "MagickCore/blob-private.h"
51 #include "MagickCore/cache-private.h"
52 #include "MagickCore/channel.h"
53 #include "MagickCore/color-private.h"
54 #include "MagickCore/colorspace-private.h"
55 #include "MagickCore/composite.h"
56 #include "MagickCore/composite-private.h"
57 #include "MagickCore/decorate.h"
58 #include "MagickCore/distort.h"
59 #include "MagickCore/draw.h"
60 #include "MagickCore/exception.h"
61 #include "MagickCore/exception-private.h"
62 #include "MagickCore/gem.h"
63 #include "MagickCore/geometry.h"
64 #include "MagickCore/image.h"
65 #include "MagickCore/image-private.h"
66 #include "MagickCore/matrix.h"
67 #include "MagickCore/memory_.h"
68 #include "MagickCore/list.h"
69 #include "MagickCore/monitor.h"
70 #include "MagickCore/monitor-private.h"
71 #include "MagickCore/nt-base-private.h"
72 #include "MagickCore/pixel-accessor.h"
73 #include "MagickCore/quantum.h"
74 #include "MagickCore/resource_.h"
75 #include "MagickCore/shear.h"
76 #include "MagickCore/statistic.h"
77 #include "MagickCore/string_.h"
78 #include "MagickCore/string-private.h"
79 #include "MagickCore/thread-private.h"
80 #include "MagickCore/threshold.h"
81 #include "MagickCore/transform.h"
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 + C r o p T o F i t I m a g e %
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 % CropToFitImage() crops the sheared image as determined by the bounding box
95 % as defined by width and height and shearing angles.
97 % The format of the CropToFitImage method is:
99 % MagickBooleanType CropToFitImage(Image **image,
100 % const double x_shear,const double x_shear,
101 % const double width,const double height,
102 % const MagickBooleanType rotate,ExceptionInfo *exception)
104 % A description of each parameter follows.
106 % o image: the image.
108 % o x_shear, y_shear, width, height: Defines a region of the image to crop.
110 % o exception: return any errors or warnings in this structure.
113 static MagickBooleanType CropToFitImage(Image **image,
114 const double x_shear,const double y_shear,
115 const double width,const double height,
116 const MagickBooleanType rotate,ExceptionInfo *exception)
134 Calculate the rotated image size.
136 extent[0].x=(double) (-width/2.0);
137 extent[0].y=(double) (-height/2.0);
138 extent[1].x=(double) width/2.0;
139 extent[1].y=(double) (-height/2.0);
140 extent[2].x=(double) (-width/2.0);
141 extent[2].y=(double) height/2.0;
142 extent[3].x=(double) width/2.0;
143 extent[3].y=(double) height/2.0;
144 for (i=0; i < 4; i++)
146 extent[i].x+=x_shear*extent[i].y;
147 extent[i].y+=y_shear*extent[i].x;
148 if (rotate != MagickFalse)
149 extent[i].x+=x_shear*extent[i].y;
150 extent[i].x+=(double) (*image)->columns/2.0;
151 extent[i].y+=(double) (*image)->rows/2.0;
155 for (i=1; i < 4; i++)
157 if (min.x > extent[i].x)
159 if (min.y > extent[i].y)
161 if (max.x < extent[i].x)
163 if (max.y < extent[i].y)
166 geometry.x=(ssize_t) ceil(min.x-0.5);
167 geometry.y=(ssize_t) ceil(min.y-0.5);
168 geometry.width=(size_t) floor(max.x-min.x+0.5);
169 geometry.height=(size_t) floor(max.y-min.y+0.5);
171 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
172 crop_image=CropImage(*image,&geometry,exception);
173 if (crop_image == (Image *) NULL)
175 crop_image->page=page;
176 *image=DestroyImage(*image);
182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186 % D e s k e w I m a g e %
190 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192 % DeskewImage() removes skew from the image. Skew is an artifact that
193 % occurs in scanned images because of the camera being misaligned,
194 % imperfections in the scanning or surface, or simply because the paper was
195 % not placed completely flat when scanned.
197 % The result will be auto-croped if the artifact "deskew:auto-crop" is
198 % defined, while the amount the image is to be deskewed, in degrees is also
199 % saved as the artifact "deskew:angle".
201 % The format of the DeskewImage method is:
203 % Image *DeskewImage(const Image *image,const double threshold,
204 % ExceptionInfo *exception)
206 % A description of each parameter follows:
208 % o image: the image.
210 % o threshold: separate background from foreground.
212 % o exception: return any errors or warnings in this structure.
216 static void RadonProjection(const Image *image,MatrixInfo *source_matrixs,
217 MatrixInfo *destination_matrixs,const ssize_t sign,size_t *projection)
233 q=destination_matrixs;
234 for (step=1; step < GetMatrixColumns(p); step*=2)
236 for (x=0; x < (ssize_t) GetMatrixColumns(p); x+=2*(ssize_t) step)
248 for (i=0; i < (ssize_t) step; i++)
250 for (y=0; y < (ssize_t) (GetMatrixRows(p)-i-1); y++)
252 if (GetMatrixElement(p,x+i,y,&element) == MagickFalse)
254 if (GetMatrixElement(p,x+i+step,y+i,&neighbor) == MagickFalse)
257 if (SetMatrixElement(q,x+2*i,y,&neighbor) == MagickFalse)
259 if (GetMatrixElement(p,x+i+step,y+i+1,&neighbor) == MagickFalse)
262 if (SetMatrixElement(q,x+2*i+1,y,&neighbor) == MagickFalse)
265 for ( ; y < (ssize_t) (GetMatrixRows(p)-i); y++)
267 if (GetMatrixElement(p,x+i,y,&element) == MagickFalse)
269 if (GetMatrixElement(p,x+i+step,y+i,&neighbor) == MagickFalse)
272 if (SetMatrixElement(q,x+2*i,y,&neighbor) == MagickFalse)
274 if (SetMatrixElement(q,x+2*i+1,y,&element) == MagickFalse)
277 for ( ; y < (ssize_t) GetMatrixRows(p); y++)
279 if (GetMatrixElement(p,x+i,y,&element) == MagickFalse)
281 if (SetMatrixElement(q,x+2*i,y,&element) == MagickFalse)
283 if (SetMatrixElement(q,x+2*i+1,y,&element) == MagickFalse)
292 #if defined(MAGICKCORE_OPENMP_SUPPORT)
293 #pragma omp parallel for schedule(static,4) \
294 magick_threads(image,image,1,1)
296 for (x=0; x < (ssize_t) GetMatrixColumns(p); x++)
305 for (y=0; y < (ssize_t) (GetMatrixRows(p)-1); y++)
314 if (GetMatrixElement(p,x,y,&element) == MagickFalse)
316 if (GetMatrixElement(p,x,y+1,&neighbor) == MagickFalse)
318 delta=(ssize_t) element-(ssize_t) neighbor;
321 projection[GetMatrixColumns(p)+sign*x-1]=sum;
325 static MagickBooleanType RadonTransform(const Image *image,
326 const double threshold,size_t *projection,ExceptionInfo *exception)
332 *destination_matrixs,
352 for (width=1; width < ((image->columns+7)/8); width<<=1) ;
353 source_matrixs=AcquireMatrixInfo(width,image->rows,sizeof(unsigned short),
355 destination_matrixs=AcquireMatrixInfo(width,image->rows,
356 sizeof(unsigned short),exception);
357 if ((source_matrixs == (MatrixInfo *) NULL) ||
358 (destination_matrixs == (MatrixInfo *) NULL))
360 if (destination_matrixs != (MatrixInfo *) NULL)
361 destination_matrixs=DestroyMatrixInfo(destination_matrixs);
362 if (source_matrixs != (MatrixInfo *) NULL)
363 source_matrixs=DestroyMatrixInfo(source_matrixs);
366 if (NullMatrix(source_matrixs) == MagickFalse)
368 destination_matrixs=DestroyMatrixInfo(destination_matrixs);
369 source_matrixs=DestroyMatrixInfo(source_matrixs);
372 for (j=0; j < 256; j++)
375 for (count=0; c != 0; c>>=1)
377 bits[j]=(unsigned short) count;
380 image_view=AcquireVirtualCacheView(image,exception);
381 #if defined(MAGICKCORE_OPENMP_SUPPORT)
382 #pragma omp parallel for schedule(static,4) shared(status) \
383 magick_threads(image,image,1,1)
385 for (y=0; y < (ssize_t) image->rows; y++)
387 register const Quantum
401 if (status == MagickFalse)
403 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
404 if (p == (const Quantum *) NULL)
411 i=(ssize_t) (image->columns+7)/8;
412 for (x=0; x < (ssize_t) image->columns; x++)
415 if (((MagickRealType) GetPixelRed(image,p) < threshold) ||
416 ((MagickRealType) GetPixelGreen(image,p) < threshold) ||
417 ((MagickRealType) GetPixelBlue(image,p) < threshold))
423 (void) SetMatrixElement(source_matrixs,--i,y,&value);
427 p+=GetPixelChannels(image);
433 (void) SetMatrixElement(source_matrixs,--i,y,&value);
436 RadonProjection(image,source_matrixs,destination_matrixs,-1,projection);
437 (void) NullMatrix(source_matrixs);
438 #if defined(MAGICKCORE_OPENMP_SUPPORT)
439 #pragma omp parallel for schedule(static,4) shared(status) \
440 magick_threads(image,image,image->rows,1)
442 for (y=0; y < (ssize_t) image->rows; y++)
444 register const Quantum
458 if (status == MagickFalse)
460 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
461 if (p == (const Quantum *) NULL)
469 for (x=0; x < (ssize_t) image->columns; x++)
472 if (((MagickRealType) GetPixelRed(image,p) < threshold) ||
473 ((MagickRealType) GetPixelGreen(image,p) < threshold) ||
474 ((MagickRealType) GetPixelBlue(image,p) < threshold))
480 (void) SetMatrixElement(source_matrixs,i++,y,&value);
484 p+=GetPixelChannels(image);
490 (void) SetMatrixElement(source_matrixs,i++,y,&value);
493 RadonProjection(image,source_matrixs,destination_matrixs,1,projection);
494 image_view=DestroyCacheView(image_view);
495 destination_matrixs=DestroyMatrixInfo(destination_matrixs);
496 source_matrixs=DestroyMatrixInfo(source_matrixs);
500 static void GetImageBackgroundColor(Image *image,const ssize_t offset,
501 ExceptionInfo *exception)
516 Compute average background color.
520 GetPixelInfo(image,&background);
522 image_view=AcquireVirtualCacheView(image,exception);
523 for (y=0; y < (ssize_t) image->rows; y++)
525 register const Quantum
531 if ((y >= offset) && (y < ((ssize_t) image->rows-offset)))
533 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
534 if (p == (const Quantum *) NULL)
536 for (x=0; x < (ssize_t) image->columns; x++)
538 if ((x >= offset) && (x < ((ssize_t) image->columns-offset)))
540 background.red+=QuantumScale*GetPixelRed(image,p);
541 background.green+=QuantumScale*GetPixelGreen(image,p);
542 background.blue+=QuantumScale*GetPixelBlue(image,p);
543 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
544 background.alpha+=QuantumScale*GetPixelAlpha(image,p);
546 p+=GetPixelChannels(image);
549 image_view=DestroyCacheView(image_view);
550 image->background_color.red=(double) ClampToQuantum(QuantumRange*
551 background.red/count);
552 image->background_color.green=(double) ClampToQuantum(QuantumRange*
553 background.green/count);
554 image->background_color.blue=(double) ClampToQuantum(QuantumRange*
555 background.blue/count);
556 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
557 image->background_color.alpha=(double) ClampToQuantum(QuantumRange*
558 background.alpha/count);
561 MagickExport Image *DeskewImage(const Image *image,const double threshold,
562 ExceptionInfo *exception)
597 Compute deskew angle.
599 for (width=1; width < ((image->columns+7)/8); width<<=1) ;
600 projection=(size_t *) AcquireQuantumMemory((size_t) (2*width-1),
601 sizeof(*projection));
602 if (projection == (size_t *) NULL)
603 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
604 status=RadonTransform(image,threshold,projection,exception);
605 if (status == MagickFalse)
607 projection=(size_t *) RelinquishMagickMemory(projection);
608 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
612 for (i=0; i < (ssize_t) (2*width-1); i++)
614 if (projection[i] > max_projection)
616 skew=i-(ssize_t) width+1;
617 max_projection=projection[i];
620 projection=(size_t *) RelinquishMagickMemory(projection);
621 degrees=RadiansToDegrees(-atan((double) skew/width/8));
622 if (image->debug != MagickFalse)
623 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
624 " Deskew angle: %g",degrees);
628 clone_image=CloneImage(image,0,0,MagickTrue,exception);
629 if (clone_image == (Image *) NULL)
630 return((Image *) NULL);
633 angle[MagickPathExtent];
635 (void) FormatLocaleString(angle,MagickPathExtent,"%.20g",degrees);
636 (void) SetImageArtifact(clone_image,"deskew:angle",angle);
638 (void) SetImageVirtualPixelMethod(clone_image,BackgroundVirtualPixelMethod,
640 affine_matrix.sx=cos(DegreesToRadians(fmod((double) degrees,360.0)));
641 affine_matrix.rx=sin(DegreesToRadians(fmod((double) degrees,360.0)));
642 affine_matrix.ry=(-sin(DegreesToRadians(fmod((double) degrees,360.0))));
643 affine_matrix.sy=cos(DegreesToRadians(fmod((double) degrees,360.0)));
644 affine_matrix.tx=0.0;
645 affine_matrix.ty=0.0;
646 artifact=GetImageArtifact(image,"deskew:auto-crop");
647 if (IsStringTrue(artifact) == MagickFalse)
649 deskew_image=AffineTransformImage(clone_image,&affine_matrix,exception);
650 clone_image=DestroyImage(clone_image);
651 return(deskew_image);
656 GetImageBackgroundColor(clone_image,(ssize_t) StringToLong(artifact),
658 deskew_image=AffineTransformImage(clone_image,&affine_matrix,exception);
659 clone_image=DestroyImage(clone_image);
660 if (deskew_image == (Image *) NULL)
661 return((Image *) NULL);
662 median_image=StatisticImage(deskew_image,MedianStatistic,3,3,exception);
663 if (median_image == (Image *) NULL)
665 deskew_image=DestroyImage(deskew_image);
666 return((Image *) NULL);
668 geometry=GetImageBoundingBox(median_image,exception);
669 median_image=DestroyImage(median_image);
670 if (image->debug != MagickFalse)
671 (void) LogMagickEvent(TransformEvent,GetMagickModule()," Deskew geometry: "
672 "%.20gx%.20g%+.20g%+.20g",(double) geometry.width,(double)
673 geometry.height,(double) geometry.x,(double) geometry.y);
674 crop_image=CropImage(deskew_image,&geometry,exception);
675 deskew_image=DestroyImage(deskew_image);
680 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
684 % I n t e g r a l R o t a t e I m a g e %
688 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
690 % IntegralRotateImage() rotates the image an integral of 90 degrees. It
691 % allocates the memory necessary for the new Image structure and returns a
692 % pointer to the rotated image.
694 % The format of the IntegralRotateImage method is:
696 % Image *IntegralRotateImage(const Image *image,size_t rotations,
697 % ExceptionInfo *exception)
699 % A description of each parameter follows.
701 % o image: the image.
703 % o rotations: Specifies the number of 90 degree rotations.
706 MagickExport Image *IntegralRotateImage(const Image *image,size_t rotations,
707 ExceptionInfo *exception)
709 #define RotateImageTag "Rotate/Image"
728 Initialize rotated image attributes.
730 assert(image != (Image *) NULL);
734 return(CloneImage(image,0,0,MagickTrue,exception));
735 if ((rotations == 1) || (rotations == 3))
736 rotate_image=CloneImage(image,image->rows,image->columns,MagickTrue,
739 rotate_image=CloneImage(image,image->columns,image->rows,MagickTrue,
741 if (rotate_image == (Image *) NULL)
742 return((Image *) NULL);
744 Integral rotate the image.
748 image_view=AcquireVirtualCacheView(image,exception);
749 rotate_view=AcquireAuthenticCacheView(rotate_image,exception);
764 GetPixelCacheTileSize(image,&tile_width,&tile_height);
765 tile_width=image->columns;
766 #if defined(MAGICKCORE_OPENMP_SUPPORT)
767 #pragma omp parallel for schedule(static,4) shared(status) \
768 magick_threads(image,image,1,1)
770 for (tile_y=0; tile_y < (ssize_t) image->rows; tile_y+=(ssize_t) tile_height)
775 if (status == MagickFalse)
778 for ( ; tile_x < (ssize_t) image->columns; tile_x+=(ssize_t) tile_width)
783 register const Quantum
797 if ((tile_x+(ssize_t) tile_width) > (ssize_t) image->columns)
798 width=(size_t) (tile_width-(tile_x+tile_width-image->columns));
800 if ((tile_y+(ssize_t) tile_height) > (ssize_t) image->rows)
801 height=(size_t) (tile_height-(tile_y+tile_height-image->rows));
802 p=GetCacheViewVirtualPixels(image_view,tile_x,tile_y,width,height,
804 if (p == (const Quantum *) NULL)
809 for (y=0; y < (ssize_t) width; y++)
811 register const Quantum
812 *magick_restrict tile_pixels;
817 if (status == MagickFalse)
819 q=QueueCacheViewAuthenticPixels(rotate_view,(ssize_t)
820 (rotate_image->columns-(tile_y+height)),y+tile_x,height,1,
822 if (q == (Quantum *) NULL)
827 tile_pixels=p+((height-1)*width+y)*GetPixelChannels(image);
828 for (x=0; x < (ssize_t) height; x++)
833 if (GetPixelWriteMask(image,tile_pixels) == 0)
835 tile_pixels-=width*GetPixelChannels(image);
836 q+=GetPixelChannels(rotate_image);
839 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
841 PixelChannel channel=GetPixelChannelChannel(image,i);
842 PixelTrait traits=GetPixelChannelTraits(image,channel);
843 PixelTrait rotate_traits=GetPixelChannelTraits(rotate_image,
845 if ((traits == UndefinedPixelTrait) ||
846 (rotate_traits == UndefinedPixelTrait))
848 SetPixelChannel(rotate_image,channel,tile_pixels[i],q);
850 tile_pixels-=width*GetPixelChannels(image);
851 q+=GetPixelChannels(rotate_image);
853 sync=SyncCacheViewAuthenticPixels(rotate_view,exception);
854 if (sync == MagickFalse)
858 if (image->progress_monitor != (MagickProgressMonitor) NULL)
863 #if defined(MAGICKCORE_OPENMP_SUPPORT)
864 #pragma omp critical (MagickCore_IntegralRotateImage)
866 proceed=SetImageProgress(image,RotateImageTag,progress+=tile_height,
868 if (proceed == MagickFalse)
872 (void) SetImageProgress(image,RotateImageTag,(MagickOffsetType)
873 image->rows-1,image->rows);
874 Swap(page.width,page.height);
877 page.x=(ssize_t) (page.width-rotate_image->columns-page.x);
888 #if defined(MAGICKCORE_OPENMP_SUPPORT)
889 #pragma omp parallel for schedule(static,4) shared(status) \
890 magick_threads(image,image,1,1)
892 for (y=0; y < (ssize_t) image->rows; y++)
897 register const Quantum
906 if (status == MagickFalse)
908 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
909 q=QueueCacheViewAuthenticPixels(rotate_view,0,(ssize_t) (image->rows-y-
910 1),image->columns,1,exception);
911 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
916 q+=GetPixelChannels(rotate_image)*image->columns;
917 for (x=0; x < (ssize_t) image->columns; x++)
922 q-=GetPixelChannels(rotate_image);
923 if (GetPixelWriteMask(image,p) == 0)
925 p+=GetPixelChannels(image);
928 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
930 PixelChannel channel=GetPixelChannelChannel(image,i);
931 PixelTrait traits=GetPixelChannelTraits(image,channel);
932 PixelTrait rotate_traits=GetPixelChannelTraits(rotate_image,
934 if ((traits == UndefinedPixelTrait) ||
935 (rotate_traits == UndefinedPixelTrait))
937 SetPixelChannel(rotate_image,channel,p[i],q);
939 p+=GetPixelChannels(image);
941 sync=SyncCacheViewAuthenticPixels(rotate_view,exception);
942 if (sync == MagickFalse)
944 if (image->progress_monitor != (MagickProgressMonitor) NULL)
949 #if defined(MAGICKCORE_OPENMP_SUPPORT)
950 #pragma omp critical (MagickCore_IntegralRotateImage)
952 proceed=SetImageProgress(image,RotateImageTag,progress++,
954 if (proceed == MagickFalse)
958 (void) SetImageProgress(image,RotateImageTag,(MagickOffsetType)
959 image->rows-1,image->rows);
960 Swap(page.width,page.height);
963 page.x=(ssize_t) (page.width-rotate_image->columns-page.x);
978 GetPixelCacheTileSize(image,&tile_width,&tile_height);
979 tile_width=image->columns;
980 #if defined(MAGICKCORE_OPENMP_SUPPORT)
981 #pragma omp parallel for schedule(static,4) shared(status) \
982 magick_threads(image,image,1,1)
984 for (tile_y=0; tile_y < (ssize_t) image->rows; tile_y+=(ssize_t) tile_height)
989 if (status == MagickFalse)
992 for ( ; tile_x < (ssize_t) image->columns; tile_x+=(ssize_t) tile_width)
997 register const Quantum
1011 if ((tile_x+(ssize_t) tile_width) > (ssize_t) image->columns)
1012 width=(size_t) (tile_width-(tile_x+tile_width-image->columns));
1014 if ((tile_y+(ssize_t) tile_height) > (ssize_t) image->rows)
1015 height=(size_t) (tile_height-(tile_y+tile_height-image->rows));
1016 p=GetCacheViewVirtualPixels(image_view,tile_x,tile_y,width,height,
1018 if (p == (const Quantum *) NULL)
1023 for (y=0; y < (ssize_t) width; y++)
1025 register const Quantum
1026 *magick_restrict tile_pixels;
1031 if (status == MagickFalse)
1033 q=QueueCacheViewAuthenticPixels(rotate_view,tile_y,(ssize_t) (y+
1034 rotate_image->rows-(tile_x+width)),height,1,exception);
1035 if (q == (Quantum *) NULL)
1040 tile_pixels=p+((width-1)-y)*GetPixelChannels(image);
1041 for (x=0; x < (ssize_t) height; x++)
1046 if (GetPixelWriteMask(image,tile_pixels) == 0)
1048 tile_pixels+=width*GetPixelChannels(image);
1049 q+=GetPixelChannels(rotate_image);
1052 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1054 PixelChannel channel=GetPixelChannelChannel(image,i);
1055 PixelTrait traits=GetPixelChannelTraits(image,channel);
1056 PixelTrait rotate_traits=GetPixelChannelTraits(rotate_image,
1058 if ((traits == UndefinedPixelTrait) ||
1059 (rotate_traits == UndefinedPixelTrait))
1061 SetPixelChannel(rotate_image,channel,tile_pixels[i],q);
1063 tile_pixels+=width*GetPixelChannels(image);
1064 q+=GetPixelChannels(rotate_image);
1066 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1067 #pragma omp critical (MagickCore_IntegralRotateImage)
1069 sync=SyncCacheViewAuthenticPixels(rotate_view,exception);
1070 if (sync == MagickFalse)
1074 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1079 proceed=SetImageProgress(image,RotateImageTag,progress+=tile_height,
1081 if (proceed == MagickFalse)
1085 (void) SetImageProgress(image,RotateImageTag,(MagickOffsetType)
1086 image->rows-1,image->rows);
1087 Swap(page.width,page.height);
1088 Swap(page.x,page.y);
1089 if (page.width != 0)
1090 page.x=(ssize_t) (page.width-rotate_image->columns-page.x);
1096 rotate_view=DestroyCacheView(rotate_view);
1097 image_view=DestroyCacheView(image_view);
1098 rotate_image->type=image->type;
1099 rotate_image->page=page;
1100 if (status == MagickFalse)
1101 rotate_image=DestroyImage(rotate_image);
1102 return(rotate_image);
1106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1110 + X S h e a r I m a g e %
1114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1116 % XShearImage() shears the image in the X direction with a shear angle of
1117 % 'degrees'. Positive angles shear counter-clockwise (right-hand rule), and
1118 % negative angles shear clockwise. Angles are measured relative to a vertical
1119 % Y-axis. X shears will widen an image creating 'empty' triangles on the left
1120 % and right sides of the source image.
1122 % The format of the XShearImage method is:
1124 % MagickBooleanType XShearImage(Image *image,const double degrees,
1125 % const size_t width,const size_t height,
1126 % const ssize_t x_offset,const ssize_t y_offset,ExceptionInfo *exception)
1128 % A description of each parameter follows.
1130 % o image: the image.
1132 % o degrees: A double representing the shearing angle along the X
1135 % o width, height, x_offset, y_offset: Defines a region of the image
1138 % o exception: return any errors or warnings in this structure.
1141 static MagickBooleanType XShearImage(Image *image,const double degrees,
1142 const size_t width,const size_t height,const ssize_t x_offset,
1143 const ssize_t y_offset,ExceptionInfo *exception)
1145 #define XShearImageTag "XShear/Image"
1171 assert(image != (Image *) NULL);
1172 assert(image->signature == MagickCoreSignature);
1173 if (image->debug != MagickFalse)
1174 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1176 background=image->background_color;
1178 image_view=AcquireAuthenticCacheView(image,exception);
1179 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1180 #pragma omp parallel for schedule(static,4) shared(progress,status) \
1181 magick_threads(image,image,height,1)
1183 for (y=0; y < (ssize_t) height; y++)
1207 if (status == MagickFalse)
1209 p=GetCacheViewAuthenticPixels(image_view,0,y_offset+y,image->columns,1,
1211 if (p == (Quantum *) NULL)
1216 p+=x_offset*GetPixelChannels(image);
1217 displacement=degrees*(double) (y-height/2.0);
1218 if (displacement == 0.0)
1220 if (displacement > 0.0)
1224 displacement*=(-1.0);
1227 step=(ssize_t) floor((double) displacement);
1228 area=(double) (displacement-step);
1231 GetPixelInfo(image,&source);
1232 GetPixelInfo(image,&destination);
1238 Transfer pixels left-to-right.
1240 if (step > x_offset)
1242 q=p-step*GetPixelChannels(image);
1243 for (i=0; i < (ssize_t) width; i++)
1245 if ((x_offset+i) < step)
1247 p+=GetPixelChannels(image);
1248 GetPixelInfoPixel(image,p,&pixel);
1249 q+=GetPixelChannels(image);
1252 GetPixelInfoPixel(image,p,&source);
1253 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1254 &source,(double) GetPixelAlpha(image,p),area,&destination);
1255 SetPixelViaPixelInfo(image,&destination,q);
1256 GetPixelInfoPixel(image,p,&pixel);
1257 p+=GetPixelChannels(image);
1258 q+=GetPixelChannels(image);
1260 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1261 &background,(double) background.alpha,area,&destination);
1262 SetPixelViaPixelInfo(image,&destination,q);
1263 q+=GetPixelChannels(image);
1264 for (i=0; i < (step-1); i++)
1266 SetPixelViaPixelInfo(image,&background,q);
1267 q+=GetPixelChannels(image);
1274 Transfer pixels right-to-left.
1276 p+=width*GetPixelChannels(image);
1277 q=p+step*GetPixelChannels(image);
1278 for (i=0; i < (ssize_t) width; i++)
1280 p-=GetPixelChannels(image);
1281 q-=GetPixelChannels(image);
1282 if ((size_t) (x_offset+width+step-i) > image->columns)
1284 GetPixelInfoPixel(image,p,&source);
1285 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1286 &source,(double) GetPixelAlpha(image,p),area,&destination);
1287 SetPixelViaPixelInfo(image,&destination,q);
1288 GetPixelInfoPixel(image,p,&pixel);
1290 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1291 &background,(double) background.alpha,area,&destination);
1292 q-=GetPixelChannels(image);
1293 SetPixelViaPixelInfo(image,&destination,q);
1294 for (i=0; i < (step-1); i++)
1296 q-=GetPixelChannels(image);
1297 SetPixelViaPixelInfo(image,&background,q);
1302 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1304 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1309 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1310 #pragma omp critical (MagickCore_XShearImage)
1312 proceed=SetImageProgress(image,XShearImageTag,progress++,height);
1313 if (proceed == MagickFalse)
1317 image_view=DestroyCacheView(image_view);
1322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1326 + Y S h e a r I m a g e %
1330 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1332 % YShearImage shears the image in the Y direction with a shear angle of
1333 % 'degrees'. Positive angles shear counter-clockwise (right-hand rule), and
1334 % negative angles shear clockwise. Angles are measured relative to a
1335 % horizontal X-axis. Y shears will increase the height of an image creating
1336 % 'empty' triangles on the top and bottom of the source image.
1338 % The format of the YShearImage method is:
1340 % MagickBooleanType YShearImage(Image *image,const double degrees,
1341 % const size_t width,const size_t height,
1342 % const ssize_t x_offset,const ssize_t y_offset,ExceptionInfo *exception)
1344 % A description of each parameter follows.
1346 % o image: the image.
1348 % o degrees: A double representing the shearing angle along the Y
1351 % o width, height, x_offset, y_offset: Defines a region of the image
1354 % o exception: return any errors or warnings in this structure.
1357 static MagickBooleanType YShearImage(Image *image,const double degrees,
1358 const size_t width,const size_t height,const ssize_t x_offset,
1359 const ssize_t y_offset,ExceptionInfo *exception)
1361 #define YShearImageTag "YShear/Image"
1387 assert(image != (Image *) NULL);
1388 assert(image->signature == MagickCoreSignature);
1389 if (image->debug != MagickFalse)
1390 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1393 background=image->background_color;
1394 image_view=AcquireAuthenticCacheView(image,exception);
1395 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1396 #pragma omp parallel for schedule(static,4) shared(progress,status) \
1397 magick_threads(image,image,width,1)
1399 for (x=0; x < (ssize_t) width; x++)
1423 if (status == MagickFalse)
1425 p=GetCacheViewAuthenticPixels(image_view,x_offset+x,0,1,image->rows,
1427 if (p == (Quantum *) NULL)
1432 p+=y_offset*GetPixelChannels(image);
1433 displacement=degrees*(double) (x-width/2.0);
1434 if (displacement == 0.0)
1436 if (displacement > 0.0)
1440 displacement*=(-1.0);
1443 step=(ssize_t) floor((double) displacement);
1444 area=(double) (displacement-step);
1447 GetPixelInfo(image,&source);
1448 GetPixelInfo(image,&destination);
1454 Transfer pixels top-to-bottom.
1456 if (step > y_offset)
1458 q=p-step*GetPixelChannels(image);
1459 for (i=0; i < (ssize_t) height; i++)
1461 if ((y_offset+i) < step)
1463 p+=GetPixelChannels(image);
1464 GetPixelInfoPixel(image,p,&pixel);
1465 q+=GetPixelChannels(image);
1468 GetPixelInfoPixel(image,p,&source);
1469 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1470 &source,(double) GetPixelAlpha(image,p),area,
1472 SetPixelViaPixelInfo(image,&destination,q);
1473 GetPixelInfoPixel(image,p,&pixel);
1474 p+=GetPixelChannels(image);
1475 q+=GetPixelChannels(image);
1477 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1478 &background,(double) background.alpha,area,&destination);
1479 SetPixelViaPixelInfo(image,&destination,q);
1480 q+=GetPixelChannels(image);
1481 for (i=0; i < (step-1); i++)
1483 SetPixelViaPixelInfo(image,&background,q);
1484 q+=GetPixelChannels(image);
1491 Transfer pixels bottom-to-top.
1493 p+=height*GetPixelChannels(image);
1494 q=p+step*GetPixelChannels(image);
1495 for (i=0; i < (ssize_t) height; i++)
1497 p-=GetPixelChannels(image);
1498 q-=GetPixelChannels(image);
1499 if ((size_t) (y_offset+height+step-i) > image->rows)
1501 GetPixelInfoPixel(image,p,&source);
1502 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1503 &source,(double) GetPixelAlpha(image,p),area,
1505 SetPixelViaPixelInfo(image,&destination,q);
1506 GetPixelInfoPixel(image,p,&pixel);
1508 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1509 &background,(double) background.alpha,area,&destination);
1510 q-=GetPixelChannels(image);
1511 SetPixelViaPixelInfo(image,&destination,q);
1512 for (i=0; i < (step-1); i++)
1514 q-=GetPixelChannels(image);
1515 SetPixelViaPixelInfo(image,&background,q);
1520 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1522 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1527 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1528 #pragma omp critical (MagickCore_YShearImage)
1530 proceed=SetImageProgress(image,YShearImageTag,progress++,image->rows);
1531 if (proceed == MagickFalse)
1535 image_view=DestroyCacheView(image_view);
1540 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1544 % S h e a r I m a g e %
1548 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1550 % ShearImage() creates a new image that is a shear_image copy of an existing
1551 % one. Shearing slides one edge of an image along the X or Y axis, creating
1552 % a parallelogram. An X direction shear slides an edge along the X axis,
1553 % while a Y direction shear slides an edge along the Y axis. The amount of
1554 % the shear is controlled by a shear angle. For X direction shears, x_shear
1555 % is measured relative to the Y axis, and similarly, for Y direction shears
1556 % y_shear is measured relative to the X axis. Empty triangles left over from
1557 % shearing the image are filled with the background color defined by member
1558 % 'background_color' of the image.. ShearImage() allocates the memory
1559 % necessary for the new Image structure and returns a pointer to the new image.
1561 % ShearImage() is based on the paper "A Fast Algorithm for General Raster
1562 % Rotatation" by Alan W. Paeth.
1564 % The format of the ShearImage method is:
1566 % Image *ShearImage(const Image *image,const double x_shear,
1567 % const double y_shear,ExceptionInfo *exception)
1569 % A description of each parameter follows.
1571 % o image: the image.
1573 % o x_shear, y_shear: Specifies the number of degrees to shear the image.
1575 % o exception: return any errors or warnings in this structure.
1578 MagickExport Image *ShearImage(const Image *image,const double x_shear,
1579 const double y_shear,ExceptionInfo *exception)
1595 assert(image != (Image *) NULL);
1596 assert(image->signature == MagickCoreSignature);
1597 if (image->debug != MagickFalse)
1598 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1599 assert(exception != (ExceptionInfo *) NULL);
1600 assert(exception->signature == MagickCoreSignature);
1601 if ((x_shear != 0.0) && (fmod(x_shear,90.0) == 0.0))
1602 ThrowImageException(ImageError,"AngleIsDiscontinuous");
1603 if ((y_shear != 0.0) && (fmod(y_shear,90.0) == 0.0))
1604 ThrowImageException(ImageError,"AngleIsDiscontinuous");
1606 Initialize shear angle.
1608 integral_image=CloneImage(image,0,0,MagickTrue,exception);
1609 if (integral_image == (Image *) NULL)
1610 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1611 shear.x=(-tan(DegreesToRadians(fmod(x_shear,360.0))));
1612 shear.y=tan(DegreesToRadians(fmod(y_shear,360.0)));
1613 if ((shear.x == 0.0) && (shear.y == 0.0))
1614 return(integral_image);
1615 if (SetImageStorageClass(integral_image,DirectClass,exception) == MagickFalse)
1617 integral_image=DestroyImage(integral_image);
1618 return(integral_image);
1620 if (integral_image->alpha_trait == UndefinedPixelTrait)
1621 (void) SetImageAlphaChannel(integral_image,OpaqueAlphaChannel,exception);
1625 bounds.width=image->columns+(ssize_t) floor(fabs(shear.x)*image->rows+0.5);
1626 bounds.x=(ssize_t) ceil((double) image->columns+((fabs(shear.x)*image->rows)-
1627 image->columns)/2.0-0.5);
1628 bounds.y=(ssize_t) ceil((double) image->rows+((fabs(shear.y)*bounds.width)-
1629 image->rows)/2.0-0.5);
1631 Surround image with border.
1633 integral_image->border_color=integral_image->background_color;
1634 integral_image->compose=CopyCompositeOp;
1635 border_info.width=(size_t) bounds.x;
1636 border_info.height=(size_t) bounds.y;
1637 shear_image=BorderImage(integral_image,&border_info,image->compose,exception);
1638 integral_image=DestroyImage(integral_image);
1639 if (shear_image == (Image *) NULL)
1640 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1644 if (shear_image->alpha_trait == UndefinedPixelTrait)
1645 (void) SetImageAlphaChannel(shear_image,OpaqueAlphaChannel,exception);
1646 status=XShearImage(shear_image,shear.x,image->columns,image->rows,bounds.x,
1647 (ssize_t) (shear_image->rows-image->rows)/2,exception);
1648 if (status == MagickFalse)
1650 shear_image=DestroyImage(shear_image);
1651 return((Image *) NULL);
1653 status=YShearImage(shear_image,shear.y,bounds.width,image->rows,(ssize_t)
1654 (shear_image->columns-bounds.width)/2,bounds.y,exception);
1655 if (status == MagickFalse)
1657 shear_image=DestroyImage(shear_image);
1658 return((Image *) NULL);
1660 status=CropToFitImage(&shear_image,shear.x,shear.y,(MagickRealType)
1661 image->columns,(MagickRealType) image->rows,MagickFalse,exception);
1662 shear_image->alpha_trait=image->alpha_trait;
1663 shear_image->compose=image->compose;
1664 shear_image->page.width=0;
1665 shear_image->page.height=0;
1666 if (status == MagickFalse)
1667 shear_image=DestroyImage(shear_image);
1668 return(shear_image);
1672 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1676 % S h e a r R o t a t e I m a g e %
1680 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1682 % ShearRotateImage() creates a new image that is a rotated copy of an existing
1683 % one. Positive angles rotate counter-clockwise (right-hand rule), while
1684 % negative angles rotate clockwise. Rotated images are usually larger than
1685 % the originals and have 'empty' triangular corners. X axis. Empty
1686 % triangles left over from shearing the image are filled with the background
1687 % color defined by member 'background_color' of the image. ShearRotateImage
1688 % allocates the memory necessary for the new Image structure and returns a
1689 % pointer to the new image.
1691 % ShearRotateImage() is based on the paper "A Fast Algorithm for General
1692 % Raster Rotatation" by Alan W. Paeth. ShearRotateImage is adapted from a
1693 % similar method based on the Paeth paper written by Michael Halle of the
1694 % Spatial Imaging Group, MIT Media Lab.
1696 % The format of the ShearRotateImage method is:
1698 % Image *ShearRotateImage(const Image *image,const double degrees,
1699 % ExceptionInfo *exception)
1701 % A description of each parameter follows.
1703 % o image: the image.
1705 % o degrees: Specifies the number of degrees to rotate the image.
1707 % o exception: return any errors or warnings in this structure.
1710 MagickExport Image *ShearRotateImage(const Image *image,const double degrees,
1711 ExceptionInfo *exception)
1737 Adjust rotation angle.
1739 assert(image != (Image *) NULL);
1740 assert(image->signature == MagickCoreSignature);
1741 if (image->debug != MagickFalse)
1742 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1743 assert(exception != (ExceptionInfo *) NULL);
1744 assert(exception->signature == MagickCoreSignature);
1746 while (angle < -45.0)
1748 for (rotations=0; angle > 45.0; rotations++)
1752 Calculate shear equations.
1754 integral_image=IntegralRotateImage(image,rotations,exception);
1755 if (integral_image == (Image *) NULL)
1756 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1757 shear.x=(-tan((double) DegreesToRadians(angle)/2.0));
1758 shear.y=sin((double) DegreesToRadians(angle));
1759 if ((shear.x == 0.0) && (shear.y == 0.0))
1760 return(integral_image);
1761 if (SetImageStorageClass(integral_image,DirectClass,exception) == MagickFalse)
1763 integral_image=DestroyImage(integral_image);
1764 return(integral_image);
1766 if (integral_image->alpha_trait == UndefinedPixelTrait)
1767 (void) SetImageAlphaChannel(integral_image,OpaqueAlphaChannel,exception);
1769 Compute maximum bounds for 3 shear operations.
1771 width=integral_image->columns;
1772 height=integral_image->rows;
1773 bounds.width=(size_t) floor(fabs((double) height*shear.x)+width+0.5);
1774 bounds.height=(size_t) floor(fabs((double) bounds.width*shear.y)+height+0.5);
1775 shear_width=(size_t) floor(fabs((double) bounds.height*shear.x)+
1777 bounds.x=(ssize_t) floor((double) ((shear_width > bounds.width) ? width :
1778 bounds.width-shear_width+2)/2.0+0.5);
1779 bounds.y=(ssize_t) floor(((double) bounds.height-height+2)/2.0+0.5);
1781 Surround image with a border.
1783 integral_image->border_color=integral_image->background_color;
1784 integral_image->compose=CopyCompositeOp;
1785 border_info.width=(size_t) bounds.x;
1786 border_info.height=(size_t) bounds.y;
1787 rotate_image=BorderImage(integral_image,&border_info,image->compose,
1789 integral_image=DestroyImage(integral_image);
1790 if (rotate_image == (Image *) NULL)
1791 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1795 status=XShearImage(rotate_image,shear.x,width,height,bounds.x,(ssize_t)
1796 (rotate_image->rows-height)/2,exception);
1797 if (status == MagickFalse)
1799 rotate_image=DestroyImage(rotate_image);
1800 return((Image *) NULL);
1802 status=YShearImage(rotate_image,shear.y,bounds.width,height,(ssize_t)
1803 (rotate_image->columns-bounds.width)/2,bounds.y,exception);
1804 if (status == MagickFalse)
1806 rotate_image=DestroyImage(rotate_image);
1807 return((Image *) NULL);
1809 status=XShearImage(rotate_image,shear.x,bounds.width,bounds.height,(ssize_t)
1810 (rotate_image->columns-bounds.width)/2,(ssize_t) (rotate_image->rows-
1811 bounds.height)/2,exception);
1812 if (status == MagickFalse)
1814 rotate_image=DestroyImage(rotate_image);
1815 return((Image *) NULL);
1817 status=CropToFitImage(&rotate_image,shear.x,shear.y,(MagickRealType) width,
1818 (MagickRealType) height,MagickTrue,exception);
1819 rotate_image->alpha_trait=image->alpha_trait;
1820 rotate_image->compose=image->compose;
1821 rotate_image->page.width=0;
1822 rotate_image->page.height=0;
1823 if (status == MagickFalse)
1824 rotate_image=DestroyImage(rotate_image);
1825 return(rotate_image);