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-2014 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 % If the artifact "deskew:auto-crop" is given the image will be automatically
202 % cropped of the excess background. The value is the border width of all
203 % pixels around the edge that will be used to determine an average border
204 % color for the automatic trim.
206 % The format of the DeskewImage method is:
208 % Image *DeskewImage(const Image *image,const double threshold,
209 % ExceptionInfo *exception)
211 % A description of each parameter follows:
213 % o image: the image.
215 % o threshold: separate background from foreground.
217 % o exception: return any errors or warnings in this structure.
221 static void RadonProjection(const Image *image,MatrixInfo *source_matrixs,
222 MatrixInfo *destination_matrixs,const ssize_t sign,size_t *projection)
238 q=destination_matrixs;
239 for (step=1; step < GetMatrixColumns(p); step*=2)
241 for (x=0; x < (ssize_t) GetMatrixColumns(p); x+=2*(ssize_t) step)
253 for (i=0; i < (ssize_t) step; i++)
255 for (y=0; y < (ssize_t) (GetMatrixRows(p)-i-1); y++)
257 if (GetMatrixElement(p,x+i,y,&element) == MagickFalse)
259 if (GetMatrixElement(p,x+i+step,y+i,&neighbor) == MagickFalse)
262 if (SetMatrixElement(q,x+2*i,y,&neighbor) == MagickFalse)
264 if (GetMatrixElement(p,x+i+step,y+i+1,&neighbor) == MagickFalse)
267 if (SetMatrixElement(q,x+2*i+1,y,&neighbor) == MagickFalse)
270 for ( ; y < (ssize_t) (GetMatrixRows(p)-i); y++)
272 if (GetMatrixElement(p,x+i,y,&element) == MagickFalse)
274 if (GetMatrixElement(p,x+i+step,y+i,&neighbor) == MagickFalse)
277 if (SetMatrixElement(q,x+2*i,y,&neighbor) == MagickFalse)
279 if (SetMatrixElement(q,x+2*i+1,y,&element) == MagickFalse)
282 for ( ; y < (ssize_t) GetMatrixRows(p); y++)
284 if (GetMatrixElement(p,x+i,y,&element) == MagickFalse)
286 if (SetMatrixElement(q,x+2*i,y,&element) == MagickFalse)
288 if (SetMatrixElement(q,x+2*i+1,y,&element) == MagickFalse)
297 #if defined(MAGICKCORE_OPENMP_SUPPORT)
298 #pragma omp parallel for schedule(static,4) \
299 magick_threads(image,image,1,1)
301 for (x=0; x < (ssize_t) GetMatrixColumns(p); x++)
310 for (y=0; y < (ssize_t) (GetMatrixRows(p)-1); y++)
319 if (GetMatrixElement(p,x,y,&element) == MagickFalse)
321 if (GetMatrixElement(p,x,y+1,&neighbor) == MagickFalse)
323 delta=(ssize_t) element-(ssize_t) neighbor;
326 projection[GetMatrixColumns(p)+sign*x-1]=sum;
330 static MagickBooleanType RadonTransform(const Image *image,
331 const double threshold,size_t *projection,ExceptionInfo *exception)
337 *destination_matrixs,
359 for (width=1; width < ((image->columns+7)/8); width<<=1) ;
360 source_matrixs=AcquireMatrixInfo(width,image->rows,sizeof(unsigned short),
362 destination_matrixs=AcquireMatrixInfo(width,image->rows,sizeof(unsigned short),
364 if ((source_matrixs == (MatrixInfo *) NULL) ||
365 (destination_matrixs == (MatrixInfo *) NULL))
367 if (destination_matrixs != (MatrixInfo *) NULL)
368 destination_matrixs=DestroyMatrixInfo(destination_matrixs);
369 if (source_matrixs != (MatrixInfo *) NULL)
370 source_matrixs=DestroyMatrixInfo(source_matrixs);
373 if (NullMatrix(source_matrixs) == MagickFalse)
375 destination_matrixs=DestroyMatrixInfo(destination_matrixs);
376 source_matrixs=DestroyMatrixInfo(source_matrixs);
379 for (i=0; i < 256; i++)
381 byte=(unsigned char) i;
382 for (count=0; byte != 0; byte>>=1)
384 bits[i]=(unsigned short) count;
387 image_view=AcquireVirtualCacheView(image,exception);
388 #if defined(MAGICKCORE_OPENMP_SUPPORT)
389 #pragma omp parallel for schedule(static,4) shared(status) \
390 magick_threads(image,image,1,1)
392 for (y=0; y < (ssize_t) image->rows; y++)
394 register const Quantum
408 if (status == MagickFalse)
410 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
411 if (p == (const Quantum *) NULL)
418 i=(ssize_t) (image->columns+7)/8;
419 for (x=0; x < (ssize_t) image->columns; x++)
422 if (((MagickRealType) GetPixelRed(image,p) < threshold) ||
423 ((MagickRealType) GetPixelGreen(image,p) < threshold) ||
424 ((MagickRealType) GetPixelBlue(image,p) < threshold))
430 (void) SetMatrixElement(source_matrixs,--i,y,&value);
434 p+=GetPixelChannels(image);
440 (void) SetMatrixElement(source_matrixs,--i,y,&value);
443 RadonProjection(image,source_matrixs,destination_matrixs,-1,projection);
444 (void) NullMatrix(source_matrixs);
445 #if defined(MAGICKCORE_OPENMP_SUPPORT)
446 #pragma omp parallel for schedule(static,4) shared(status) \
447 magick_threads(image,image,image->rows,1)
449 for (y=0; y < (ssize_t) image->rows; y++)
451 register const Quantum
465 if (status == MagickFalse)
467 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
468 if (p == (const Quantum *) NULL)
476 for (x=0; x < (ssize_t) image->columns; x++)
479 if (((MagickRealType) GetPixelRed(image,p) < threshold) ||
480 ((MagickRealType) GetPixelGreen(image,p) < threshold) ||
481 ((MagickRealType) GetPixelBlue(image,p) < threshold))
487 (void) SetMatrixElement(source_matrixs,i++,y,&value);
491 p+=GetPixelChannels(image);
497 (void) SetMatrixElement(source_matrixs,i++,y,&value);
500 RadonProjection(image,source_matrixs,destination_matrixs,1,projection);
501 image_view=DestroyCacheView(image_view);
502 destination_matrixs=DestroyMatrixInfo(destination_matrixs);
503 source_matrixs=DestroyMatrixInfo(source_matrixs);
507 static void GetImageBackgroundColor(Image *image,const ssize_t offset,
508 ExceptionInfo *exception)
523 Compute average background color.
527 GetPixelInfo(image,&background);
529 image_view=AcquireVirtualCacheView(image,exception);
530 for (y=0; y < (ssize_t) image->rows; y++)
532 register const Quantum
538 if ((y >= offset) && (y < ((ssize_t) image->rows-offset)))
540 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
541 if (p == (const Quantum *) NULL)
543 for (x=0; x < (ssize_t) image->columns; x++)
545 if ((x >= offset) && (x < ((ssize_t) image->columns-offset)))
547 background.red+=QuantumScale*GetPixelRed(image,p);
548 background.green+=QuantumScale*GetPixelGreen(image,p);
549 background.blue+=QuantumScale*GetPixelBlue(image,p);
550 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
551 background.alpha+=QuantumScale*GetPixelAlpha(image,p);
553 p+=GetPixelChannels(image);
556 image_view=DestroyCacheView(image_view);
557 image->background_color.red=(double) ClampToQuantum(QuantumRange*
558 background.red/count);
559 image->background_color.green=(double) ClampToQuantum(QuantumRange*
560 background.green/count);
561 image->background_color.blue=(double) ClampToQuantum(QuantumRange*
562 background.blue/count);
563 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
564 image->background_color.alpha=(double) ClampToQuantum(QuantumRange*
565 background.alpha/count);
568 MagickExport Image *DeskewImage(const Image *image,const double threshold,
569 ExceptionInfo *exception)
604 Compute deskew angle.
606 for (width=1; width < ((image->columns+7)/8); width<<=1) ;
607 projection=(size_t *) AcquireQuantumMemory((size_t) (2*width-1),
608 sizeof(*projection));
609 if (projection == (size_t *) NULL)
610 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
611 status=RadonTransform(image,threshold,projection,exception);
612 if (status == MagickFalse)
614 projection=(size_t *) RelinquishMagickMemory(projection);
615 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
619 for (i=0; i < (ssize_t) (2*width-1); i++)
621 if (projection[i] > max_projection)
623 skew=i-(ssize_t) width+1;
624 max_projection=projection[i];
627 projection=(size_t *) RelinquishMagickMemory(projection);
628 degrees=RadiansToDegrees(-atan((double) skew/width/8));
629 if (image->debug != MagickFalse)
630 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
631 " Deskew angle: %g",degrees);
635 clone_image=CloneImage(image,0,0,MagickTrue,exception);
636 if (clone_image == (Image *) NULL)
637 return((Image *) NULL);
640 angle[MaxTextExtent];
642 (void) FormatLocaleString(angle,MaxTextExtent,"%.20g",degrees);
643 (void) SetImageArtifact(clone_image,"deskew:angle",angle);
645 (void) SetImageVirtualPixelMethod(clone_image,BackgroundVirtualPixelMethod,
647 affine_matrix.sx=cos(DegreesToRadians(fmod((double) degrees,360.0)));
648 affine_matrix.rx=sin(DegreesToRadians(fmod((double) degrees,360.0)));
649 affine_matrix.ry=(-sin(DegreesToRadians(fmod((double) degrees,360.0))));
650 affine_matrix.sy=cos(DegreesToRadians(fmod((double) degrees,360.0)));
651 affine_matrix.tx=0.0;
652 affine_matrix.ty=0.0;
653 artifact=GetImageArtifact(image,"deskew:auto-crop");
654 if (artifact == (const char *) NULL)
656 deskew_image=AffineTransformImage(clone_image,&affine_matrix,exception);
657 clone_image=DestroyImage(clone_image);
658 return(deskew_image);
663 GetImageBackgroundColor(clone_image,(ssize_t) StringToLong(artifact),
665 deskew_image=AffineTransformImage(clone_image,&affine_matrix,exception);
666 clone_image=DestroyImage(clone_image);
667 if (deskew_image == (Image *) NULL)
668 return((Image *) NULL);
669 median_image=StatisticImage(deskew_image,MedianStatistic,3,3,exception);
670 if (median_image == (Image *) NULL)
672 deskew_image=DestroyImage(deskew_image);
673 return((Image *) NULL);
675 geometry=GetImageBoundingBox(median_image,exception);
676 median_image=DestroyImage(median_image);
677 if (image->debug != MagickFalse)
678 (void) LogMagickEvent(TransformEvent,GetMagickModule()," Deskew geometry: "
679 "%.20gx%.20g%+.20g%+.20g",(double) geometry.width,(double)
680 geometry.height,(double) geometry.x,(double) geometry.y);
681 crop_image=CropImage(deskew_image,&geometry,exception);
682 deskew_image=DestroyImage(deskew_image);
687 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
691 % I n t e g r a l R o t a t e I m a g e %
695 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
697 % IntegralRotateImage() rotates the image an integral of 90 degrees. It
698 % allocates the memory necessary for the new Image structure and returns a
699 % pointer to the rotated image.
701 % The format of the IntegralRotateImage method is:
703 % Image *IntegralRotateImage(const Image *image,size_t rotations,
704 % ExceptionInfo *exception)
706 % A description of each parameter follows.
708 % o image: the image.
710 % o rotations: Specifies the number of 90 degree rotations.
713 MagickExport Image *IntegralRotateImage(const Image *image,size_t rotations,
714 ExceptionInfo *exception)
716 #define RotateImageTag "Rotate/Image"
738 Initialize rotated image attributes.
740 assert(image != (Image *) NULL);
744 return(CloneImage(image,0,0,MagickTrue,exception));
745 if ((rotations == 1) || (rotations == 3))
746 rotate_image=CloneImage(image,image->rows,image->columns,MagickTrue,
749 rotate_image=CloneImage(image,image->columns,image->rows,MagickTrue,
751 if (rotate_image == (Image *) NULL)
752 return((Image *) NULL);
754 Integral rotate the image.
758 image_view=AcquireVirtualCacheView(image,exception);
759 rotate_view=AcquireAuthenticCacheView(rotate_image,exception);
781 GetPixelCacheTileSize(image,&tile_width,&tile_height);
782 tile_width=image->columns;
783 #if defined(MAGICKCORE_OPENMP_SUPPORT)
784 #pragma omp parallel for schedule(static,4) shared(status) \
785 magick_threads(image,image,1,1)
787 for (tile_y=0; tile_y < (ssize_t) image->rows; tile_y+=(ssize_t) tile_height)
792 if (status == MagickFalse)
795 for ( ; tile_x < (ssize_t) image->columns; tile_x+=(ssize_t) tile_width)
800 register const Quantum
814 if ((tile_x+(ssize_t) tile_width) > (ssize_t) image->columns)
815 width=(size_t) (tile_width-(tile_x+tile_width-image->columns));
817 if ((tile_y+(ssize_t) tile_height) > (ssize_t) image->rows)
818 height=(size_t) (tile_height-(tile_y+tile_height-image->rows));
819 p=GetCacheViewVirtualPixels(image_view,tile_x,tile_y,width,height,
821 if (p == (const Quantum *) NULL)
826 for (y=0; y < (ssize_t) width; y++)
828 register const Quantum
829 *restrict tile_pixels;
834 if (status == MagickFalse)
836 q=QueueCacheViewAuthenticPixels(rotate_view,(ssize_t)
837 (rotate_image->columns-(tile_y+height)),y+tile_x,height,1,
839 if (q == (Quantum *) NULL)
844 tile_pixels=p+((height-1)*width+y)*GetPixelChannels(image);
845 for (x=0; x < (ssize_t) height; x++)
850 if (GetPixelReadMask(image,tile_pixels) == 0)
852 tile_pixels-=width*GetPixelChannels(image);
853 q+=GetPixelChannels(rotate_image);
856 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
858 PixelChannel channel=GetPixelChannelChannel(image,i);
859 PixelTrait traits=GetPixelChannelTraits(image,channel);
860 PixelTrait rotate_traits=GetPixelChannelTraits(rotate_image,
862 if ((traits == UndefinedPixelTrait) ||
863 (rotate_traits == UndefinedPixelTrait))
865 SetPixelChannel(rotate_image,channel,tile_pixels[i],q);
867 tile_pixels-=width*GetPixelChannels(image);
868 q+=GetPixelChannels(rotate_image);
870 sync=SyncCacheViewAuthenticPixels(rotate_view,exception);
871 if (sync == MagickFalse)
875 if (image->progress_monitor != (MagickProgressMonitor) NULL)
880 #if defined(MAGICKCORE_OPENMP_SUPPORT)
881 #pragma omp critical (MagickCore_IntegralRotateImage)
883 proceed=SetImageProgress(image,RotateImageTag,progress+=tile_height,
885 if (proceed == MagickFalse)
889 (void) SetImageProgress(image,RotateImageTag,(MagickOffsetType)
890 image->rows-1,image->rows);
891 Swap(page.width,page.height);
894 page.x=(ssize_t) (page.width-rotate_image->columns-page.x);
902 #if defined(MAGICKCORE_OPENMP_SUPPORT)
903 #pragma omp parallel for schedule(static,4) shared(status) \
904 magick_threads(image,image,1,1)
906 for (y=0; y < (ssize_t) image->rows; y++)
911 register const Quantum
920 if (status == MagickFalse)
922 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
923 q=QueueCacheViewAuthenticPixels(rotate_view,0,(ssize_t) (image->rows-y-
924 1),image->columns,1,exception);
925 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
930 q+=GetPixelChannels(rotate_image)*image->columns;
931 for (x=0; x < (ssize_t) image->columns; x++)
936 q-=GetPixelChannels(rotate_image);
937 if (GetPixelReadMask(image,p) == 0)
939 p+=GetPixelChannels(image);
942 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
944 PixelChannel channel=GetPixelChannelChannel(image,i);
945 PixelTrait traits=GetPixelChannelTraits(image,channel);
946 PixelTrait rotate_traits=GetPixelChannelTraits(rotate_image,
948 if ((traits == UndefinedPixelTrait) ||
949 (rotate_traits == UndefinedPixelTrait))
951 SetPixelChannel(rotate_image,channel,p[i],q);
953 p+=GetPixelChannels(image);
955 sync=SyncCacheViewAuthenticPixels(rotate_view,exception);
956 if (sync == MagickFalse)
958 if (image->progress_monitor != (MagickProgressMonitor) NULL)
963 #if defined(MAGICKCORE_OPENMP_SUPPORT)
964 #pragma omp critical (MagickCore_IntegralRotateImage)
966 proceed=SetImageProgress(image,RotateImageTag,progress++,
968 if (proceed == MagickFalse)
972 (void) SetImageProgress(image,RotateImageTag,(MagickOffsetType)
973 image->rows-1,image->rows);
974 Swap(page.width,page.height);
977 page.x=(ssize_t) (page.width-rotate_image->columns-page.x);
992 GetPixelCacheTileSize(image,&tile_width,&tile_height);
993 tile_width=image->columns;
994 #if defined(MAGICKCORE_OPENMP_SUPPORT)
995 #pragma omp parallel for schedule(static,4) shared(status) \
996 magick_threads(image,image,1,1)
998 for (tile_y=0; tile_y < (ssize_t) image->rows; tile_y+=(ssize_t) tile_height)
1003 if (status == MagickFalse)
1006 for ( ; tile_x < (ssize_t) image->columns; tile_x+=(ssize_t) tile_width)
1011 register const Quantum
1025 if ((tile_x+(ssize_t) tile_width) > (ssize_t) image->columns)
1026 width=(size_t) (tile_width-(tile_x+tile_width-image->columns));
1028 if ((tile_y+(ssize_t) tile_height) > (ssize_t) image->rows)
1029 height=(size_t) (tile_height-(tile_y+tile_height-image->rows));
1030 p=GetCacheViewVirtualPixels(image_view,tile_x,tile_y,width,height,
1032 if (p == (const Quantum *) NULL)
1037 for (y=0; y < (ssize_t) width; y++)
1039 register const Quantum
1040 *restrict tile_pixels;
1045 if (status == MagickFalse)
1047 q=QueueCacheViewAuthenticPixels(rotate_view,tile_y,(ssize_t) (y+
1048 rotate_image->rows-(tile_x+width)),height,1,exception);
1049 if (q == (Quantum *) NULL)
1054 tile_pixels=p+((width-1)-y)*GetPixelChannels(image);
1055 for (x=0; x < (ssize_t) height; x++)
1060 if (GetPixelReadMask(image,tile_pixels) == 0)
1062 tile_pixels+=width*GetPixelChannels(image);
1063 q+=GetPixelChannels(rotate_image);
1066 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1068 PixelChannel channel=GetPixelChannelChannel(image,i);
1069 PixelTrait traits=GetPixelChannelTraits(image,channel);
1070 PixelTrait rotate_traits=GetPixelChannelTraits(rotate_image,
1072 if ((traits == UndefinedPixelTrait) ||
1073 (rotate_traits == UndefinedPixelTrait))
1075 SetPixelChannel(rotate_image,channel,tile_pixels[i],q);
1077 tile_pixels+=width*GetPixelChannels(image);
1078 q+=GetPixelChannels(rotate_image);
1080 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1081 #pragma omp critical (MagickCore_IntegralRotateImage)
1083 sync=SyncCacheViewAuthenticPixels(rotate_view,exception);
1084 if (sync == MagickFalse)
1088 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1093 proceed=SetImageProgress(image,RotateImageTag,progress+=tile_height,
1095 if (proceed == MagickFalse)
1099 (void) SetImageProgress(image,RotateImageTag,(MagickOffsetType)
1100 image->rows-1,image->rows);
1101 Swap(page.width,page.height);
1102 Swap(page.x,page.y);
1103 if (page.width != 0)
1104 page.x=(ssize_t) (page.width-rotate_image->columns-page.x);
1108 rotate_view=DestroyCacheView(rotate_view);
1109 image_view=DestroyCacheView(image_view);
1110 rotate_image->type=image->type;
1111 rotate_image->page=page;
1112 if (status == MagickFalse)
1113 rotate_image=DestroyImage(rotate_image);
1114 return(rotate_image);
1118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1122 + X S h e a r I m a g e %
1126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1128 % XShearImage() shears the image in the X direction with a shear angle of
1129 % 'degrees'. Positive angles shear counter-clockwise (right-hand rule), and
1130 % negative angles shear clockwise. Angles are measured relative to a vertical
1131 % Y-axis. X shears will widen an image creating 'empty' triangles on the left
1132 % and right sides of the source image.
1134 % The format of the XShearImage method is:
1136 % MagickBooleanType XShearImage(Image *image,const double degrees,
1137 % const size_t width,const size_t height,
1138 % const ssize_t x_offset,const ssize_t y_offset,ExceptionInfo *exception)
1140 % A description of each parameter follows.
1142 % o image: the image.
1144 % o degrees: A double representing the shearing angle along the X
1147 % o width, height, x_offset, y_offset: Defines a region of the image
1150 % o exception: return any errors or warnings in this structure.
1153 static MagickBooleanType XShearImage(Image *image,const double degrees,
1154 const size_t width,const size_t height,const ssize_t x_offset,
1155 const ssize_t y_offset,ExceptionInfo *exception)
1157 #define XShearImageTag "XShear/Image"
1183 assert(image != (Image *) NULL);
1184 assert(image->signature == MagickSignature);
1185 if (image->debug != MagickFalse)
1186 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1188 background=image->background_color;
1190 image_view=AcquireAuthenticCacheView(image,exception);
1191 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1192 #pragma omp parallel for schedule(static,4) shared(progress,status) \
1193 magick_threads(image,image,height,1)
1195 for (y=0; y < (ssize_t) height; y++)
1219 if (status == MagickFalse)
1221 p=GetCacheViewAuthenticPixels(image_view,0,y_offset+y,image->columns,1,
1223 if (p == (Quantum *) NULL)
1228 p+=x_offset*GetPixelChannels(image);
1229 displacement=degrees*(double) (y-height/2.0);
1230 if (displacement == 0.0)
1232 if (displacement > 0.0)
1236 displacement*=(-1.0);
1239 step=(ssize_t) floor((double) displacement);
1240 area=(double) (displacement-step);
1243 GetPixelInfo(image,&source);
1244 GetPixelInfo(image,&destination);
1250 Transfer pixels left-to-right.
1252 if (step > x_offset)
1254 q=p-step*GetPixelChannels(image);
1255 for (i=0; i < (ssize_t) width; i++)
1257 if ((x_offset+i) < step)
1259 p+=GetPixelChannels(image);
1260 GetPixelInfoPixel(image,p,&pixel);
1261 q+=GetPixelChannels(image);
1264 GetPixelInfoPixel(image,p,&source);
1265 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1266 &source,(double) GetPixelAlpha(image,p),area,&destination);
1267 SetPixelInfoPixel(image,&destination,q);
1268 GetPixelInfoPixel(image,p,&pixel);
1269 p+=GetPixelChannels(image);
1270 q+=GetPixelChannels(image);
1272 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1273 &background,(double) background.alpha,area,&destination);
1274 SetPixelInfoPixel(image,&destination,q);
1275 q+=GetPixelChannels(image);
1276 for (i=0; i < (step-1); i++)
1278 SetPixelInfoPixel(image,&background,q);
1279 q+=GetPixelChannels(image);
1286 Transfer pixels right-to-left.
1288 p+=width*GetPixelChannels(image);
1289 q=p+step*GetPixelChannels(image);
1290 for (i=0; i < (ssize_t) width; i++)
1292 p-=GetPixelChannels(image);
1293 q-=GetPixelChannels(image);
1294 if ((size_t) (x_offset+width+step-i) > image->columns)
1296 GetPixelInfoPixel(image,p,&source);
1297 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1298 &source,(double) GetPixelAlpha(image,p),area,&destination);
1299 SetPixelInfoPixel(image,&destination,q);
1300 GetPixelInfoPixel(image,p,&pixel);
1302 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1303 &background,(double) background.alpha,area,&destination);
1304 q-=GetPixelChannels(image);
1305 SetPixelInfoPixel(image,&destination,q);
1306 for (i=0; i < (step-1); i++)
1308 q-=GetPixelChannels(image);
1309 SetPixelInfoPixel(image,&background,q);
1314 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1316 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1321 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1322 #pragma omp critical (MagickCore_XShearImage)
1324 proceed=SetImageProgress(image,XShearImageTag,progress++,height);
1325 if (proceed == MagickFalse)
1329 image_view=DestroyCacheView(image_view);
1334 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1338 + Y S h e a r I m a g e %
1342 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1344 % YShearImage shears the image in the Y direction with a shear angle of
1345 % 'degrees'. Positive angles shear counter-clockwise (right-hand rule), and
1346 % negative angles shear clockwise. Angles are measured relative to a
1347 % horizontal X-axis. Y shears will increase the height of an image creating
1348 % 'empty' triangles on the top and bottom of the source image.
1350 % The format of the YShearImage method is:
1352 % MagickBooleanType YShearImage(Image *image,const double degrees,
1353 % const size_t width,const size_t height,
1354 % const ssize_t x_offset,const ssize_t y_offset,ExceptionInfo *exception)
1356 % A description of each parameter follows.
1358 % o image: the image.
1360 % o degrees: A double representing the shearing angle along the Y
1363 % o width, height, x_offset, y_offset: Defines a region of the image
1366 % o exception: return any errors or warnings in this structure.
1369 static MagickBooleanType YShearImage(Image *image,const double degrees,
1370 const size_t width,const size_t height,const ssize_t x_offset,
1371 const ssize_t y_offset,ExceptionInfo *exception)
1373 #define YShearImageTag "YShear/Image"
1399 assert(image != (Image *) NULL);
1400 assert(image->signature == MagickSignature);
1401 if (image->debug != MagickFalse)
1402 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1405 background=image->background_color;
1406 image_view=AcquireAuthenticCacheView(image,exception);
1407 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1408 #pragma omp parallel for schedule(static,4) shared(progress,status) \
1409 magick_threads(image,image,width,1)
1411 for (x=0; x < (ssize_t) width; x++)
1435 if (status == MagickFalse)
1437 p=GetCacheViewAuthenticPixels(image_view,x_offset+x,0,1,image->rows,
1439 if (p == (Quantum *) NULL)
1444 p+=y_offset*GetPixelChannels(image);
1445 displacement=degrees*(double) (x-width/2.0);
1446 if (displacement == 0.0)
1448 if (displacement > 0.0)
1452 displacement*=(-1.0);
1455 step=(ssize_t) floor((double) displacement);
1456 area=(double) (displacement-step);
1459 GetPixelInfo(image,&source);
1460 GetPixelInfo(image,&destination);
1466 Transfer pixels top-to-bottom.
1468 if (step > y_offset)
1470 q=p-step*GetPixelChannels(image);
1471 for (i=0; i < (ssize_t) height; i++)
1473 if ((y_offset+i) < step)
1475 p+=GetPixelChannels(image);
1476 GetPixelInfoPixel(image,p,&pixel);
1477 q+=GetPixelChannels(image);
1480 GetPixelInfoPixel(image,p,&source);
1481 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1482 &source,(double) GetPixelAlpha(image,p),area,
1484 SetPixelInfoPixel(image,&destination,q);
1485 GetPixelInfoPixel(image,p,&pixel);
1486 p+=GetPixelChannels(image);
1487 q+=GetPixelChannels(image);
1489 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1490 &background,(double) background.alpha,area,&destination);
1491 SetPixelInfoPixel(image,&destination,q);
1492 q+=GetPixelChannels(image);
1493 for (i=0; i < (step-1); i++)
1495 SetPixelInfoPixel(image,&background,q);
1496 q+=GetPixelChannels(image);
1503 Transfer pixels bottom-to-top.
1505 p+=height*GetPixelChannels(image);
1506 q=p+step*GetPixelChannels(image);
1507 for (i=0; i < (ssize_t) height; i++)
1509 p-=GetPixelChannels(image);
1510 q-=GetPixelChannels(image);
1511 if ((size_t) (y_offset+height+step-i) > image->rows)
1513 GetPixelInfoPixel(image,p,&source);
1514 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1515 &source,(double) GetPixelAlpha(image,p),area,
1517 SetPixelInfoPixel(image,&destination,q);
1518 GetPixelInfoPixel(image,p,&pixel);
1520 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1521 &background,(double) background.alpha,area,&destination);
1522 q-=GetPixelChannels(image);
1523 SetPixelInfoPixel(image,&destination,q);
1524 for (i=0; i < (step-1); i++)
1526 q-=GetPixelChannels(image);
1527 SetPixelInfoPixel(image,&background,q);
1532 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1534 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1539 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1540 #pragma omp critical (MagickCore_YShearImage)
1542 proceed=SetImageProgress(image,YShearImageTag,progress++,image->rows);
1543 if (proceed == MagickFalse)
1547 image_view=DestroyCacheView(image_view);
1552 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1556 % S h e a r I m a g e %
1560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1562 % ShearImage() creates a new image that is a shear_image copy of an existing
1563 % one. Shearing slides one edge of an image along the X or Y axis, creating
1564 % a parallelogram. An X direction shear slides an edge along the X axis,
1565 % while a Y direction shear slides an edge along the Y axis. The amount of
1566 % the shear is controlled by a shear angle. For X direction shears, x_shear
1567 % is measured relative to the Y axis, and similarly, for Y direction shears
1568 % y_shear is measured relative to the X axis. Empty triangles left over from
1569 % shearing the image are filled with the background color defined by member
1570 % 'background_color' of the image.. ShearImage() allocates the memory
1571 % necessary for the new Image structure and returns a pointer to the new image.
1573 % ShearImage() is based on the paper "A Fast Algorithm for General Raster
1574 % Rotatation" by Alan W. Paeth.
1576 % The format of the ShearImage method is:
1578 % Image *ShearImage(const Image *image,const double x_shear,
1579 % const double y_shear,ExceptionInfo *exception)
1581 % A description of each parameter follows.
1583 % o image: the image.
1585 % o x_shear, y_shear: Specifies the number of degrees to shear the image.
1587 % o exception: return any errors or warnings in this structure.
1590 MagickExport Image *ShearImage(const Image *image,const double x_shear,
1591 const double y_shear,ExceptionInfo *exception)
1607 assert(image != (Image *) NULL);
1608 assert(image->signature == MagickSignature);
1609 if (image->debug != MagickFalse)
1610 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1611 assert(exception != (ExceptionInfo *) NULL);
1612 assert(exception->signature == MagickSignature);
1613 if ((x_shear != 0.0) && (fmod(x_shear,90.0) == 0.0))
1614 ThrowImageException(ImageError,"AngleIsDiscontinuous");
1615 if ((y_shear != 0.0) && (fmod(y_shear,90.0) == 0.0))
1616 ThrowImageException(ImageError,"AngleIsDiscontinuous");
1618 Initialize shear angle.
1620 integral_image=CloneImage(image,0,0,MagickTrue,exception);
1621 if (integral_image == (Image *) NULL)
1622 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1623 shear.x=(-tan(DegreesToRadians(fmod(x_shear,360.0))));
1624 shear.y=tan(DegreesToRadians(fmod(y_shear,360.0)));
1625 if ((shear.x == 0.0) && (shear.y == 0.0))
1626 return(integral_image);
1627 if (SetImageStorageClass(integral_image,DirectClass,exception) == MagickFalse)
1629 integral_image=DestroyImage(integral_image);
1630 return(integral_image);
1632 if (integral_image->alpha_trait != BlendPixelTrait)
1633 (void) SetImageAlphaChannel(integral_image,OpaqueAlphaChannel,exception);
1637 bounds.width=image->columns+(ssize_t) floor(fabs(shear.x)*image->rows+0.5);
1638 bounds.x=(ssize_t) ceil((double) image->columns+((fabs(shear.x)*image->rows)-
1639 image->columns)/2.0-0.5);
1640 bounds.y=(ssize_t) ceil((double) image->rows+((fabs(shear.y)*bounds.width)-
1641 image->rows)/2.0-0.5);
1643 Surround image with border.
1645 integral_image->border_color=integral_image->background_color;
1646 integral_image->compose=CopyCompositeOp;
1647 border_info.width=(size_t) bounds.x;
1648 border_info.height=(size_t) bounds.y;
1649 shear_image=BorderImage(integral_image,&border_info,image->compose,exception);
1650 integral_image=DestroyImage(integral_image);
1651 if (shear_image == (Image *) NULL)
1652 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1656 if (shear_image->alpha_trait != BlendPixelTrait)
1657 (void) SetImageAlphaChannel(shear_image,OpaqueAlphaChannel,exception);
1658 status=XShearImage(shear_image,shear.x,image->columns,image->rows,bounds.x,
1659 (ssize_t) (shear_image->rows-image->rows)/2,exception);
1660 if (status == MagickFalse)
1662 shear_image=DestroyImage(shear_image);
1663 return((Image *) NULL);
1665 status=YShearImage(shear_image,shear.y,bounds.width,image->rows,(ssize_t)
1666 (shear_image->columns-bounds.width)/2,bounds.y,exception);
1667 if (status == MagickFalse)
1669 shear_image=DestroyImage(shear_image);
1670 return((Image *) NULL);
1672 status=CropToFitImage(&shear_image,shear.x,shear.y,(MagickRealType)
1673 image->columns,(MagickRealType) image->rows,MagickFalse,exception);
1674 shear_image->compose=image->compose;
1675 shear_image->page.width=0;
1676 shear_image->page.height=0;
1677 if (status == MagickFalse)
1678 shear_image=DestroyImage(shear_image);
1679 return(shear_image);
1683 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1687 % S h e a r R o t a t e I m a g e %
1691 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1693 % ShearRotateImage() creates a new image that is a rotated copy of an existing
1694 % one. Positive angles rotate counter-clockwise (right-hand rule), while
1695 % negative angles rotate clockwise. Rotated images are usually larger than
1696 % the originals and have 'empty' triangular corners. X axis. Empty
1697 % triangles left over from shearing the image are filled with the background
1698 % color defined by member 'background_color' of the image. ShearRotateImage
1699 % allocates the memory necessary for the new Image structure and returns a
1700 % pointer to the new image.
1702 % ShearRotateImage() is based on the paper "A Fast Algorithm for General
1703 % Raster Rotatation" by Alan W. Paeth. ShearRotateImage is adapted from a
1704 % similar method based on the Paeth paper written by Michael Halle of the
1705 % Spatial Imaging Group, MIT Media Lab.
1707 % The format of the ShearRotateImage method is:
1709 % Image *ShearRotateImage(const Image *image,const double degrees,
1710 % ExceptionInfo *exception)
1712 % A description of each parameter follows.
1714 % o image: the image.
1716 % o degrees: Specifies the number of degrees to rotate the image.
1718 % o exception: return any errors or warnings in this structure.
1721 MagickExport Image *ShearRotateImage(const Image *image,const double degrees,
1722 ExceptionInfo *exception)
1748 Adjust rotation angle.
1750 assert(image != (Image *) NULL);
1751 assert(image->signature == MagickSignature);
1752 if (image->debug != MagickFalse)
1753 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1754 assert(exception != (ExceptionInfo *) NULL);
1755 assert(exception->signature == MagickSignature);
1757 while (angle < -45.0)
1759 for (rotations=0; angle > 45.0; rotations++)
1763 Calculate shear equations.
1765 integral_image=IntegralRotateImage(image,rotations,exception);
1766 if (integral_image == (Image *) NULL)
1767 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1768 shear.x=(-tan((double) DegreesToRadians(angle)/2.0));
1769 shear.y=sin((double) DegreesToRadians(angle));
1770 if ((shear.x == 0.0) && (shear.y == 0.0))
1771 return(integral_image);
1772 if (SetImageStorageClass(integral_image,DirectClass,exception) == MagickFalse)
1774 integral_image=DestroyImage(integral_image);
1775 return(integral_image);
1777 if (integral_image->alpha_trait != BlendPixelTrait)
1778 (void) SetImageAlphaChannel(integral_image,OpaqueAlphaChannel,exception);
1780 Compute maximum bounds for 3 shear operations.
1782 width=integral_image->columns;
1783 height=integral_image->rows;
1784 bounds.width=(size_t) floor(fabs((double) height*shear.x)+width+0.5);
1785 bounds.height=(size_t) floor(fabs((double) bounds.width*shear.y)+height+0.5);
1786 shear_width=(size_t) floor(fabs((double) bounds.height*shear.x)+
1788 bounds.x=(ssize_t) floor((double) ((shear_width > bounds.width) ? width :
1789 bounds.width-shear_width+2)/2.0+0.5);
1790 bounds.y=(ssize_t) floor(((double) bounds.height-height+2)/2.0+0.5);
1792 Surround image with a border.
1794 integral_image->border_color=integral_image->background_color;
1795 integral_image->compose=CopyCompositeOp;
1796 border_info.width=(size_t) bounds.x;
1797 border_info.height=(size_t) bounds.y;
1798 rotate_image=BorderImage(integral_image,&border_info,image->compose,
1800 integral_image=DestroyImage(integral_image);
1801 if (rotate_image == (Image *) NULL)
1802 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1806 status=XShearImage(rotate_image,shear.x,width,height,bounds.x,(ssize_t)
1807 (rotate_image->rows-height)/2,exception);
1808 if (status == MagickFalse)
1810 rotate_image=DestroyImage(rotate_image);
1811 return((Image *) NULL);
1813 status=YShearImage(rotate_image,shear.y,bounds.width,height,(ssize_t)
1814 (rotate_image->columns-bounds.width)/2,bounds.y,exception);
1815 if (status == MagickFalse)
1817 rotate_image=DestroyImage(rotate_image);
1818 return((Image *) NULL);
1820 status=XShearImage(rotate_image,shear.x,bounds.width,bounds.height,(ssize_t)
1821 (rotate_image->columns-bounds.width)/2,(ssize_t) (rotate_image->rows-
1822 bounds.height)/2,exception);
1823 if (status == MagickFalse)
1825 rotate_image=DestroyImage(rotate_image);
1826 return((Image *) NULL);
1828 status=CropToFitImage(&rotate_image,shear.x,shear.y,(MagickRealType) width,
1829 (MagickRealType) height,MagickTrue,exception);
1830 rotate_image->compose=image->compose;
1831 rotate_image->page.width=0;
1832 rotate_image->page.height=0;
1833 if (status == MagickFalse)
1834 rotate_image=DestroyImage(rotate_image);
1835 return(rotate_image);