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-2015 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[MagickPathExtent];
642 (void) FormatLocaleString(angle,MagickPathExtent,"%.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);
774 GetPixelCacheTileSize(image,&tile_width,&tile_height);
775 tile_width=image->columns;
776 #if defined(MAGICKCORE_OPENMP_SUPPORT)
777 #pragma omp parallel for schedule(static,4) shared(status) \
778 magick_threads(image,image,1,1)
780 for (tile_y=0; tile_y < (ssize_t) image->rows; tile_y+=(ssize_t) tile_height)
785 if (status == MagickFalse)
788 for ( ; tile_x < (ssize_t) image->columns; tile_x+=(ssize_t) tile_width)
793 register const Quantum
807 if ((tile_x+(ssize_t) tile_width) > (ssize_t) image->columns)
808 width=(size_t) (tile_width-(tile_x+tile_width-image->columns));
810 if ((tile_y+(ssize_t) tile_height) > (ssize_t) image->rows)
811 height=(size_t) (tile_height-(tile_y+tile_height-image->rows));
812 p=GetCacheViewVirtualPixels(image_view,tile_x,tile_y,width,height,
814 if (p == (const Quantum *) NULL)
819 for (y=0; y < (ssize_t) width; y++)
821 register const Quantum
822 *restrict tile_pixels;
827 if (status == MagickFalse)
829 q=QueueCacheViewAuthenticPixels(rotate_view,(ssize_t)
830 (rotate_image->columns-(tile_y+height)),y+tile_x,height,1,
832 if (q == (Quantum *) NULL)
837 tile_pixels=p+((height-1)*width+y)*GetPixelChannels(image);
838 for (x=0; x < (ssize_t) height; x++)
843 if (GetPixelReadMask(image,tile_pixels) == 0)
845 tile_pixels-=width*GetPixelChannels(image);
846 q+=GetPixelChannels(rotate_image);
849 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
851 PixelChannel channel=GetPixelChannelChannel(image,i);
852 PixelTrait traits=GetPixelChannelTraits(image,channel);
853 PixelTrait rotate_traits=GetPixelChannelTraits(rotate_image,
855 if ((traits == UndefinedPixelTrait) ||
856 (rotate_traits == UndefinedPixelTrait))
858 SetPixelChannel(rotate_image,channel,tile_pixels[i],q);
860 tile_pixels-=width*GetPixelChannels(image);
861 q+=GetPixelChannels(rotate_image);
863 sync=SyncCacheViewAuthenticPixels(rotate_view,exception);
864 if (sync == MagickFalse)
868 if (image->progress_monitor != (MagickProgressMonitor) NULL)
873 #if defined(MAGICKCORE_OPENMP_SUPPORT)
874 #pragma omp critical (MagickCore_IntegralRotateImage)
876 proceed=SetImageProgress(image,RotateImageTag,progress+=tile_height,
878 if (proceed == MagickFalse)
882 (void) SetImageProgress(image,RotateImageTag,(MagickOffsetType)
883 image->rows-1,image->rows);
884 Swap(page.width,page.height);
887 page.x=(ssize_t) (page.width-rotate_image->columns-page.x);
895 #if defined(MAGICKCORE_OPENMP_SUPPORT)
896 #pragma omp parallel for schedule(static,4) shared(status) \
897 magick_threads(image,image,1,1)
899 for (y=0; y < (ssize_t) image->rows; y++)
904 register const Quantum
913 if (status == MagickFalse)
915 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
916 q=QueueCacheViewAuthenticPixels(rotate_view,0,(ssize_t) (image->rows-y-
917 1),image->columns,1,exception);
918 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
923 q+=GetPixelChannels(rotate_image)*image->columns;
924 for (x=0; x < (ssize_t) image->columns; x++)
929 q-=GetPixelChannels(rotate_image);
930 if (GetPixelReadMask(image,p) == 0)
932 p+=GetPixelChannels(image);
935 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
937 PixelChannel channel=GetPixelChannelChannel(image,i);
938 PixelTrait traits=GetPixelChannelTraits(image,channel);
939 PixelTrait rotate_traits=GetPixelChannelTraits(rotate_image,
941 if ((traits == UndefinedPixelTrait) ||
942 (rotate_traits == UndefinedPixelTrait))
944 SetPixelChannel(rotate_image,channel,p[i],q);
946 p+=GetPixelChannels(image);
948 sync=SyncCacheViewAuthenticPixels(rotate_view,exception);
949 if (sync == MagickFalse)
951 if (image->progress_monitor != (MagickProgressMonitor) NULL)
956 #if defined(MAGICKCORE_OPENMP_SUPPORT)
957 #pragma omp critical (MagickCore_IntegralRotateImage)
959 proceed=SetImageProgress(image,RotateImageTag,progress++,
961 if (proceed == MagickFalse)
965 (void) SetImageProgress(image,RotateImageTag,(MagickOffsetType)
966 image->rows-1,image->rows);
967 Swap(page.width,page.height);
970 page.x=(ssize_t) (page.width-rotate_image->columns-page.x);
985 GetPixelCacheTileSize(image,&tile_width,&tile_height);
986 tile_width=image->columns;
987 #if defined(MAGICKCORE_OPENMP_SUPPORT)
988 #pragma omp parallel for schedule(static,4) shared(status) \
989 magick_threads(image,image,1,1)
991 for (tile_y=0; tile_y < (ssize_t) image->rows; tile_y+=(ssize_t) tile_height)
996 if (status == MagickFalse)
999 for ( ; tile_x < (ssize_t) image->columns; tile_x+=(ssize_t) tile_width)
1004 register const Quantum
1018 if ((tile_x+(ssize_t) tile_width) > (ssize_t) image->columns)
1019 width=(size_t) (tile_width-(tile_x+tile_width-image->columns));
1021 if ((tile_y+(ssize_t) tile_height) > (ssize_t) image->rows)
1022 height=(size_t) (tile_height-(tile_y+tile_height-image->rows));
1023 p=GetCacheViewVirtualPixels(image_view,tile_x,tile_y,width,height,
1025 if (p == (const Quantum *) NULL)
1030 for (y=0; y < (ssize_t) width; y++)
1032 register const Quantum
1033 *restrict tile_pixels;
1038 if (status == MagickFalse)
1040 q=QueueCacheViewAuthenticPixels(rotate_view,tile_y,(ssize_t) (y+
1041 rotate_image->rows-(tile_x+width)),height,1,exception);
1042 if (q == (Quantum *) NULL)
1047 tile_pixels=p+((width-1)-y)*GetPixelChannels(image);
1048 for (x=0; x < (ssize_t) height; x++)
1053 if (GetPixelReadMask(image,tile_pixels) == 0)
1055 tile_pixels+=width*GetPixelChannels(image);
1056 q+=GetPixelChannels(rotate_image);
1059 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1061 PixelChannel channel=GetPixelChannelChannel(image,i);
1062 PixelTrait traits=GetPixelChannelTraits(image,channel);
1063 PixelTrait rotate_traits=GetPixelChannelTraits(rotate_image,
1065 if ((traits == UndefinedPixelTrait) ||
1066 (rotate_traits == UndefinedPixelTrait))
1068 SetPixelChannel(rotate_image,channel,tile_pixels[i],q);
1070 tile_pixels+=width*GetPixelChannels(image);
1071 q+=GetPixelChannels(rotate_image);
1073 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1074 #pragma omp critical (MagickCore_IntegralRotateImage)
1076 sync=SyncCacheViewAuthenticPixels(rotate_view,exception);
1077 if (sync == MagickFalse)
1081 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1086 proceed=SetImageProgress(image,RotateImageTag,progress+=tile_height,
1088 if (proceed == MagickFalse)
1092 (void) SetImageProgress(image,RotateImageTag,(MagickOffsetType)
1093 image->rows-1,image->rows);
1094 Swap(page.width,page.height);
1095 Swap(page.x,page.y);
1096 if (page.width != 0)
1097 page.x=(ssize_t) (page.width-rotate_image->columns-page.x);
1103 rotate_view=DestroyCacheView(rotate_view);
1104 image_view=DestroyCacheView(image_view);
1105 rotate_image->type=image->type;
1106 rotate_image->page=page;
1107 if (status == MagickFalse)
1108 rotate_image=DestroyImage(rotate_image);
1109 return(rotate_image);
1113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1117 + X S h e a r I m a g e %
1121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1123 % XShearImage() shears the image in the X direction with a shear angle of
1124 % 'degrees'. Positive angles shear counter-clockwise (right-hand rule), and
1125 % negative angles shear clockwise. Angles are measured relative to a vertical
1126 % Y-axis. X shears will widen an image creating 'empty' triangles on the left
1127 % and right sides of the source image.
1129 % The format of the XShearImage method is:
1131 % MagickBooleanType XShearImage(Image *image,const double degrees,
1132 % const size_t width,const size_t height,
1133 % const ssize_t x_offset,const ssize_t y_offset,ExceptionInfo *exception)
1135 % A description of each parameter follows.
1137 % o image: the image.
1139 % o degrees: A double representing the shearing angle along the X
1142 % o width, height, x_offset, y_offset: Defines a region of the image
1145 % o exception: return any errors or warnings in this structure.
1148 static MagickBooleanType XShearImage(Image *image,const double degrees,
1149 const size_t width,const size_t height,const ssize_t x_offset,
1150 const ssize_t y_offset,ExceptionInfo *exception)
1152 #define XShearImageTag "XShear/Image"
1178 assert(image != (Image *) NULL);
1179 assert(image->signature == MagickSignature);
1180 if (image->debug != MagickFalse)
1181 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1183 background=image->background_color;
1185 image_view=AcquireAuthenticCacheView(image,exception);
1186 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1187 #pragma omp parallel for schedule(static,4) shared(progress,status) \
1188 magick_threads(image,image,height,1)
1190 for (y=0; y < (ssize_t) height; y++)
1214 if (status == MagickFalse)
1216 p=GetCacheViewAuthenticPixels(image_view,0,y_offset+y,image->columns,1,
1218 if (p == (Quantum *) NULL)
1223 p+=x_offset*GetPixelChannels(image);
1224 displacement=degrees*(double) (y-height/2.0);
1225 if (displacement == 0.0)
1227 if (displacement > 0.0)
1231 displacement*=(-1.0);
1234 step=(ssize_t) floor((double) displacement);
1235 area=(double) (displacement-step);
1238 GetPixelInfo(image,&source);
1239 GetPixelInfo(image,&destination);
1245 Transfer pixels left-to-right.
1247 if (step > x_offset)
1249 q=p-step*GetPixelChannels(image);
1250 for (i=0; i < (ssize_t) width; i++)
1252 if ((x_offset+i) < step)
1254 p+=GetPixelChannels(image);
1255 GetPixelInfoPixel(image,p,&pixel);
1256 q+=GetPixelChannels(image);
1259 GetPixelInfoPixel(image,p,&source);
1260 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1261 &source,(double) GetPixelAlpha(image,p),area,&destination);
1262 SetPixelViaPixelInfo(image,&destination,q);
1263 GetPixelInfoPixel(image,p,&pixel);
1264 p+=GetPixelChannels(image);
1265 q+=GetPixelChannels(image);
1267 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1268 &background,(double) background.alpha,area,&destination);
1269 SetPixelViaPixelInfo(image,&destination,q);
1270 q+=GetPixelChannels(image);
1271 for (i=0; i < (step-1); i++)
1273 SetPixelViaPixelInfo(image,&background,q);
1274 q+=GetPixelChannels(image);
1281 Transfer pixels right-to-left.
1283 p+=width*GetPixelChannels(image);
1284 q=p+step*GetPixelChannels(image);
1285 for (i=0; i < (ssize_t) width; i++)
1287 p-=GetPixelChannels(image);
1288 q-=GetPixelChannels(image);
1289 if ((size_t) (x_offset+width+step-i) > image->columns)
1291 GetPixelInfoPixel(image,p,&source);
1292 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1293 &source,(double) GetPixelAlpha(image,p),area,&destination);
1294 SetPixelViaPixelInfo(image,&destination,q);
1295 GetPixelInfoPixel(image,p,&pixel);
1297 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1298 &background,(double) background.alpha,area,&destination);
1299 q-=GetPixelChannels(image);
1300 SetPixelViaPixelInfo(image,&destination,q);
1301 for (i=0; i < (step-1); i++)
1303 q-=GetPixelChannels(image);
1304 SetPixelViaPixelInfo(image,&background,q);
1309 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1311 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1316 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1317 #pragma omp critical (MagickCore_XShearImage)
1319 proceed=SetImageProgress(image,XShearImageTag,progress++,height);
1320 if (proceed == MagickFalse)
1324 image_view=DestroyCacheView(image_view);
1329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1333 + Y S h e a r I m a g e %
1337 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1339 % YShearImage shears the image in the Y direction with a shear angle of
1340 % 'degrees'. Positive angles shear counter-clockwise (right-hand rule), and
1341 % negative angles shear clockwise. Angles are measured relative to a
1342 % horizontal X-axis. Y shears will increase the height of an image creating
1343 % 'empty' triangles on the top and bottom of the source image.
1345 % The format of the YShearImage method is:
1347 % MagickBooleanType YShearImage(Image *image,const double degrees,
1348 % const size_t width,const size_t height,
1349 % const ssize_t x_offset,const ssize_t y_offset,ExceptionInfo *exception)
1351 % A description of each parameter follows.
1353 % o image: the image.
1355 % o degrees: A double representing the shearing angle along the Y
1358 % o width, height, x_offset, y_offset: Defines a region of the image
1361 % o exception: return any errors or warnings in this structure.
1364 static MagickBooleanType YShearImage(Image *image,const double degrees,
1365 const size_t width,const size_t height,const ssize_t x_offset,
1366 const ssize_t y_offset,ExceptionInfo *exception)
1368 #define YShearImageTag "YShear/Image"
1394 assert(image != (Image *) NULL);
1395 assert(image->signature == MagickSignature);
1396 if (image->debug != MagickFalse)
1397 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1400 background=image->background_color;
1401 image_view=AcquireAuthenticCacheView(image,exception);
1402 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1403 #pragma omp parallel for schedule(static,4) shared(progress,status) \
1404 magick_threads(image,image,width,1)
1406 for (x=0; x < (ssize_t) width; x++)
1430 if (status == MagickFalse)
1432 p=GetCacheViewAuthenticPixels(image_view,x_offset+x,0,1,image->rows,
1434 if (p == (Quantum *) NULL)
1439 p+=y_offset*GetPixelChannels(image);
1440 displacement=degrees*(double) (x-width/2.0);
1441 if (displacement == 0.0)
1443 if (displacement > 0.0)
1447 displacement*=(-1.0);
1450 step=(ssize_t) floor((double) displacement);
1451 area=(double) (displacement-step);
1454 GetPixelInfo(image,&source);
1455 GetPixelInfo(image,&destination);
1461 Transfer pixels top-to-bottom.
1463 if (step > y_offset)
1465 q=p-step*GetPixelChannels(image);
1466 for (i=0; i < (ssize_t) height; i++)
1468 if ((y_offset+i) < step)
1470 p+=GetPixelChannels(image);
1471 GetPixelInfoPixel(image,p,&pixel);
1472 q+=GetPixelChannels(image);
1475 GetPixelInfoPixel(image,p,&source);
1476 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1477 &source,(double) GetPixelAlpha(image,p),area,
1479 SetPixelViaPixelInfo(image,&destination,q);
1480 GetPixelInfoPixel(image,p,&pixel);
1481 p+=GetPixelChannels(image);
1482 q+=GetPixelChannels(image);
1484 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1485 &background,(double) background.alpha,area,&destination);
1486 SetPixelViaPixelInfo(image,&destination,q);
1487 q+=GetPixelChannels(image);
1488 for (i=0; i < (step-1); i++)
1490 SetPixelViaPixelInfo(image,&background,q);
1491 q+=GetPixelChannels(image);
1498 Transfer pixels bottom-to-top.
1500 p+=height*GetPixelChannels(image);
1501 q=p+step*GetPixelChannels(image);
1502 for (i=0; i < (ssize_t) height; i++)
1504 p-=GetPixelChannels(image);
1505 q-=GetPixelChannels(image);
1506 if ((size_t) (y_offset+height+step-i) > image->rows)
1508 GetPixelInfoPixel(image,p,&source);
1509 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1510 &source,(double) GetPixelAlpha(image,p),area,
1512 SetPixelViaPixelInfo(image,&destination,q);
1513 GetPixelInfoPixel(image,p,&pixel);
1515 CompositePixelInfoAreaBlend(&pixel,(double) pixel.alpha,
1516 &background,(double) background.alpha,area,&destination);
1517 q-=GetPixelChannels(image);
1518 SetPixelViaPixelInfo(image,&destination,q);
1519 for (i=0; i < (step-1); i++)
1521 q-=GetPixelChannels(image);
1522 SetPixelViaPixelInfo(image,&background,q);
1527 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1529 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1534 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1535 #pragma omp critical (MagickCore_YShearImage)
1537 proceed=SetImageProgress(image,YShearImageTag,progress++,image->rows);
1538 if (proceed == MagickFalse)
1542 image_view=DestroyCacheView(image_view);
1547 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1551 % S h e a r I m a g e %
1555 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1557 % ShearImage() creates a new image that is a shear_image copy of an existing
1558 % one. Shearing slides one edge of an image along the X or Y axis, creating
1559 % a parallelogram. An X direction shear slides an edge along the X axis,
1560 % while a Y direction shear slides an edge along the Y axis. The amount of
1561 % the shear is controlled by a shear angle. For X direction shears, x_shear
1562 % is measured relative to the Y axis, and similarly, for Y direction shears
1563 % y_shear is measured relative to the X axis. Empty triangles left over from
1564 % shearing the image are filled with the background color defined by member
1565 % 'background_color' of the image.. ShearImage() allocates the memory
1566 % necessary for the new Image structure and returns a pointer to the new image.
1568 % ShearImage() is based on the paper "A Fast Algorithm for General Raster
1569 % Rotatation" by Alan W. Paeth.
1571 % The format of the ShearImage method is:
1573 % Image *ShearImage(const Image *image,const double x_shear,
1574 % const double y_shear,ExceptionInfo *exception)
1576 % A description of each parameter follows.
1578 % o image: the image.
1580 % o x_shear, y_shear: Specifies the number of degrees to shear the image.
1582 % o exception: return any errors or warnings in this structure.
1585 MagickExport Image *ShearImage(const Image *image,const double x_shear,
1586 const double y_shear,ExceptionInfo *exception)
1602 assert(image != (Image *) NULL);
1603 assert(image->signature == MagickSignature);
1604 if (image->debug != MagickFalse)
1605 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1606 assert(exception != (ExceptionInfo *) NULL);
1607 assert(exception->signature == MagickSignature);
1608 if ((x_shear != 0.0) && (fmod(x_shear,90.0) == 0.0))
1609 ThrowImageException(ImageError,"AngleIsDiscontinuous");
1610 if ((y_shear != 0.0) && (fmod(y_shear,90.0) == 0.0))
1611 ThrowImageException(ImageError,"AngleIsDiscontinuous");
1613 Initialize shear angle.
1615 integral_image=CloneImage(image,0,0,MagickTrue,exception);
1616 if (integral_image == (Image *) NULL)
1617 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1618 shear.x=(-tan(DegreesToRadians(fmod(x_shear,360.0))));
1619 shear.y=tan(DegreesToRadians(fmod(y_shear,360.0)));
1620 if ((shear.x == 0.0) && (shear.y == 0.0))
1621 return(integral_image);
1622 if (SetImageStorageClass(integral_image,DirectClass,exception) == MagickFalse)
1624 integral_image=DestroyImage(integral_image);
1625 return(integral_image);
1627 if (integral_image->alpha_trait == UndefinedPixelTrait)
1628 (void) SetImageAlphaChannel(integral_image,OpaqueAlphaChannel,exception);
1632 bounds.width=image->columns+(ssize_t) floor(fabs(shear.x)*image->rows+0.5);
1633 bounds.x=(ssize_t) ceil((double) image->columns+((fabs(shear.x)*image->rows)-
1634 image->columns)/2.0-0.5);
1635 bounds.y=(ssize_t) ceil((double) image->rows+((fabs(shear.y)*bounds.width)-
1636 image->rows)/2.0-0.5);
1638 Surround image with border.
1640 integral_image->border_color=integral_image->background_color;
1641 integral_image->compose=CopyCompositeOp;
1642 border_info.width=(size_t) bounds.x;
1643 border_info.height=(size_t) bounds.y;
1644 shear_image=BorderImage(integral_image,&border_info,image->compose,exception);
1645 integral_image=DestroyImage(integral_image);
1646 if (shear_image == (Image *) NULL)
1647 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1651 if (shear_image->alpha_trait == UndefinedPixelTrait)
1652 (void) SetImageAlphaChannel(shear_image,OpaqueAlphaChannel,exception);
1653 status=XShearImage(shear_image,shear.x,image->columns,image->rows,bounds.x,
1654 (ssize_t) (shear_image->rows-image->rows)/2,exception);
1655 if (status == MagickFalse)
1657 shear_image=DestroyImage(shear_image);
1658 return((Image *) NULL);
1660 status=YShearImage(shear_image,shear.y,bounds.width,image->rows,(ssize_t)
1661 (shear_image->columns-bounds.width)/2,bounds.y,exception);
1662 if (status == MagickFalse)
1664 shear_image=DestroyImage(shear_image);
1665 return((Image *) NULL);
1667 status=CropToFitImage(&shear_image,shear.x,shear.y,(MagickRealType)
1668 image->columns,(MagickRealType) image->rows,MagickFalse,exception);
1669 shear_image->compose=image->compose;
1670 shear_image->page.width=0;
1671 shear_image->page.height=0;
1672 if (status == MagickFalse)
1673 shear_image=DestroyImage(shear_image);
1674 return(shear_image);
1678 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1682 % S h e a r R o t a t e I m a g e %
1686 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1688 % ShearRotateImage() creates a new image that is a rotated copy of an existing
1689 % one. Positive angles rotate counter-clockwise (right-hand rule), while
1690 % negative angles rotate clockwise. Rotated images are usually larger than
1691 % the originals and have 'empty' triangular corners. X axis. Empty
1692 % triangles left over from shearing the image are filled with the background
1693 % color defined by member 'background_color' of the image. ShearRotateImage
1694 % allocates the memory necessary for the new Image structure and returns a
1695 % pointer to the new image.
1697 % ShearRotateImage() is based on the paper "A Fast Algorithm for General
1698 % Raster Rotatation" by Alan W. Paeth. ShearRotateImage is adapted from a
1699 % similar method based on the Paeth paper written by Michael Halle of the
1700 % Spatial Imaging Group, MIT Media Lab.
1702 % The format of the ShearRotateImage method is:
1704 % Image *ShearRotateImage(const Image *image,const double degrees,
1705 % ExceptionInfo *exception)
1707 % A description of each parameter follows.
1709 % o image: the image.
1711 % o degrees: Specifies the number of degrees to rotate the image.
1713 % o exception: return any errors or warnings in this structure.
1716 MagickExport Image *ShearRotateImage(const Image *image,const double degrees,
1717 ExceptionInfo *exception)
1743 Adjust rotation angle.
1745 assert(image != (Image *) NULL);
1746 assert(image->signature == MagickSignature);
1747 if (image->debug != MagickFalse)
1748 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1749 assert(exception != (ExceptionInfo *) NULL);
1750 assert(exception->signature == MagickSignature);
1752 while (angle < -45.0)
1754 for (rotations=0; angle > 45.0; rotations++)
1758 Calculate shear equations.
1760 integral_image=IntegralRotateImage(image,rotations,exception);
1761 if (integral_image == (Image *) NULL)
1762 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1763 shear.x=(-tan((double) DegreesToRadians(angle)/2.0));
1764 shear.y=sin((double) DegreesToRadians(angle));
1765 if ((shear.x == 0.0) && (shear.y == 0.0))
1766 return(integral_image);
1767 if (SetImageStorageClass(integral_image,DirectClass,exception) == MagickFalse)
1769 integral_image=DestroyImage(integral_image);
1770 return(integral_image);
1772 if (integral_image->alpha_trait == UndefinedPixelTrait)
1773 (void) SetImageAlphaChannel(integral_image,OpaqueAlphaChannel,exception);
1775 Compute maximum bounds for 3 shear operations.
1777 width=integral_image->columns;
1778 height=integral_image->rows;
1779 bounds.width=(size_t) floor(fabs((double) height*shear.x)+width+0.5);
1780 bounds.height=(size_t) floor(fabs((double) bounds.width*shear.y)+height+0.5);
1781 shear_width=(size_t) floor(fabs((double) bounds.height*shear.x)+
1783 bounds.x=(ssize_t) floor((double) ((shear_width > bounds.width) ? width :
1784 bounds.width-shear_width+2)/2.0+0.5);
1785 bounds.y=(ssize_t) floor(((double) bounds.height-height+2)/2.0+0.5);
1787 Surround image with a border.
1789 integral_image->border_color=integral_image->background_color;
1790 integral_image->compose=CopyCompositeOp;
1791 border_info.width=(size_t) bounds.x;
1792 border_info.height=(size_t) bounds.y;
1793 rotate_image=BorderImage(integral_image,&border_info,image->compose,
1795 integral_image=DestroyImage(integral_image);
1796 if (rotate_image == (Image *) NULL)
1797 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
1801 status=XShearImage(rotate_image,shear.x,width,height,bounds.x,(ssize_t)
1802 (rotate_image->rows-height)/2,exception);
1803 if (status == MagickFalse)
1805 rotate_image=DestroyImage(rotate_image);
1806 return((Image *) NULL);
1808 status=YShearImage(rotate_image,shear.y,bounds.width,height,(ssize_t)
1809 (rotate_image->columns-bounds.width)/2,bounds.y,exception);
1810 if (status == MagickFalse)
1812 rotate_image=DestroyImage(rotate_image);
1813 return((Image *) NULL);
1815 status=XShearImage(rotate_image,shear.x,bounds.width,bounds.height,(ssize_t)
1816 (rotate_image->columns-bounds.width)/2,(ssize_t) (rotate_image->rows-
1817 bounds.height)/2,exception);
1818 if (status == MagickFalse)
1820 rotate_image=DestroyImage(rotate_image);
1821 return((Image *) NULL);
1823 status=CropToFitImage(&rotate_image,shear.x,shear.y,(MagickRealType) width,
1824 (MagickRealType) height,MagickTrue,exception);
1825 rotate_image->compose=image->compose;
1826 rotate_image->page.width=0;
1827 rotate_image->page.height=0;
1828 if (status == MagickFalse)
1829 rotate_image=DestroyImage(rotate_image);
1830 return(rotate_image);