2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % TTTTT RRRR AAA N N SSSSS FFFFF OOO RRRR M M %
7 % T R R A A NN N SS F O O R R MM MM %
8 % T RRRR AAAAA N N N SSS FFF O O RRRR M M M %
9 % T R R A A N NN SS F O O R R M M %
10 % T R R A A N N SSSSS F OOO R R M M %
13 % MagickCore Image Transform Methods %
20 % Copyright 1999-2012 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "MagickCore/studio.h"
43 #include "MagickCore/attribute.h"
44 #include "MagickCore/cache.h"
45 #include "MagickCore/cache-view.h"
46 #include "MagickCore/color.h"
47 #include "MagickCore/color-private.h"
48 #include "MagickCore/colorspace-private.h"
49 #include "MagickCore/composite.h"
50 #include "MagickCore/draw.h"
51 #include "MagickCore/effect.h"
52 #include "MagickCore/exception.h"
53 #include "MagickCore/exception-private.h"
54 #include "MagickCore/geometry.h"
55 #include "MagickCore/image.h"
56 #include "MagickCore/memory_.h"
57 #include "MagickCore/layer.h"
58 #include "MagickCore/list.h"
59 #include "MagickCore/monitor.h"
60 #include "MagickCore/monitor-private.h"
61 #include "MagickCore/pixel-accessor.h"
62 #include "MagickCore/resource_.h"
63 #include "MagickCore/resize.h"
64 #include "MagickCore/statistic.h"
65 #include "MagickCore/string_.h"
66 #include "MagickCore/thread-private.h"
67 #include "MagickCore/transform.h"
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 % ChopImage() removes a region of an image and collapses the image to occupy
81 % the removed portion.
83 % The format of the ChopImage method is:
85 % Image *ChopImage(const Image *image,const RectangleInfo *chop_info)
86 % ExceptionInfo *exception)
88 % A description of each parameter follows:
92 % o chop_info: Define the region of the image to chop.
94 % o exception: return any errors or warnings in this structure.
97 MagickExport Image *ChopImage(const Image *image,const RectangleInfo *chop_info,
98 ExceptionInfo *exception)
100 #define ChopImageTag "Chop/Image"
124 assert(image != (const Image *) NULL);
125 assert(image->signature == MagickSignature);
126 if (image->debug != MagickFalse)
127 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
128 assert(exception != (ExceptionInfo *) NULL);
129 assert(exception->signature == MagickSignature);
130 assert(chop_info != (RectangleInfo *) NULL);
131 if (((chop_info->x+(ssize_t) chop_info->width) < 0) ||
132 ((chop_info->y+(ssize_t) chop_info->height) < 0) ||
133 (chop_info->x > (ssize_t) image->columns) ||
134 (chop_info->y > (ssize_t) image->rows))
135 ThrowImageException(OptionWarning,"GeometryDoesNotContainImage");
137 if ((extent.x+(ssize_t) extent.width) > (ssize_t) image->columns)
138 extent.width=(size_t) ((ssize_t) image->columns-extent.x);
139 if ((extent.y+(ssize_t) extent.height) > (ssize_t) image->rows)
140 extent.height=(size_t) ((ssize_t) image->rows-extent.y);
143 extent.width-=(size_t) (-extent.x);
148 extent.height-=(size_t) (-extent.y);
151 chop_image=CloneImage(image,image->columns-extent.width,image->rows-
152 extent.height,MagickTrue,exception);
153 if (chop_image == (Image *) NULL)
154 return((Image *) NULL);
160 image_view=AcquireVirtualCacheView(image,exception);
161 chop_view=AcquireAuthenticCacheView(chop_image,exception);
162 #if defined(MAGICKCORE_OPENMP_SUPPORT)
163 #pragma omp parallel for schedule(static) shared(progress,status) \
164 if ((extent.y*image->columns) > 8192) \
165 num_threads(GetMagickResourceLimit(ThreadResource))
167 for (y=0; y < (ssize_t) extent.y; y++)
169 register const Quantum
178 if (status == MagickFalse)
180 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
181 q=QueueCacheViewAuthenticPixels(chop_view,0,y,chop_image->columns,1,
183 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
188 for (x=0; x < (ssize_t) image->columns; x++)
190 if ((x < extent.x) || (x >= (ssize_t) (extent.x+extent.width)))
195 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
204 channel=GetPixelChannelMapChannel(image,i);
205 traits=GetPixelChannelMapTraits(image,channel);
206 chop_traits=GetPixelChannelMapTraits(chop_image,channel);
207 if ((traits == UndefinedPixelTrait) ||
208 (chop_traits == UndefinedPixelTrait))
210 SetPixelChannel(chop_image,channel,p[i],q);
212 q+=GetPixelChannels(chop_image);
214 p+=GetPixelChannels(image);
216 if (SyncCacheViewAuthenticPixels(chop_view,exception) == MagickFalse)
218 if (image->progress_monitor != (MagickProgressMonitor) NULL)
223 #if defined(MAGICKCORE_OPENMP_SUPPORT)
224 #pragma omp critical (MagickCore_ChopImage)
226 proceed=SetImageProgress(image,ChopImageTag,progress++,image->rows);
227 if (proceed == MagickFalse)
234 #if defined(MAGICKCORE_OPENMP_SUPPORT)
235 #pragma omp parallel for schedule(static) shared(progress,status) \
236 if ((image->rows*image->columns) > 8192) \
237 num_threads(GetMagickResourceLimit(ThreadResource))
239 for (y=0; y < (ssize_t) (image->rows-(extent.y+extent.height)); y++)
241 register const Quantum
250 if (status == MagickFalse)
252 p=GetCacheViewVirtualPixels(image_view,0,extent.y+extent.height+y,
253 image->columns,1,exception);
254 q=QueueCacheViewAuthenticPixels(chop_view,0,extent.y+y,chop_image->columns,
256 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
261 for (x=0; x < (ssize_t) image->columns; x++)
263 if ((x < extent.x) || (x >= (ssize_t) (extent.x+extent.width)))
268 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
277 channel=GetPixelChannelMapChannel(image,i);
278 traits=GetPixelChannelMapTraits(image,channel);
279 chop_traits=GetPixelChannelMapTraits(chop_image,channel);
280 if ((traits == UndefinedPixelTrait) ||
281 (chop_traits == UndefinedPixelTrait))
283 SetPixelChannel(chop_image,channel,p[i],q);
285 q+=GetPixelChannels(chop_image);
287 p+=GetPixelChannels(image);
289 if (SyncCacheViewAuthenticPixels(chop_view,exception) == MagickFalse)
291 if (image->progress_monitor != (MagickProgressMonitor) NULL)
296 #if defined(MAGICKCORE_OPENMP_SUPPORT)
297 #pragma omp critical (MagickCore_ChopImage)
299 proceed=SetImageProgress(image,ChopImageTag,progress++,image->rows);
300 if (proceed == MagickFalse)
304 chop_view=DestroyCacheView(chop_view);
305 image_view=DestroyCacheView(image_view);
306 chop_image->type=image->type;
311 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
315 + C o n s o l i d a t e C M Y K I m a g e %
319 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
321 % ConsolidateCMYKImage() consolidates separate C, M, Y, and K planes into a
324 % The format of the ConsolidateCMYKImage method is:
326 % Image *ConsolidateCMYKImage(const Image *image,ExceptionInfo *exception)
328 % A description of each parameter follows:
330 % o image: the image sequence.
332 % o exception: return any errors or warnings in this structure.
335 MagickExport Image *ConsolidateCMYKImages(const Image *images,
336 ExceptionInfo *exception)
353 Consolidate separate C, M, Y, and K planes into a single image.
355 assert(images != (Image *) NULL);
356 assert(images->signature == MagickSignature);
357 if (images->debug != MagickFalse)
358 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
359 assert(exception != (ExceptionInfo *) NULL);
360 assert(exception->signature == MagickSignature);
361 cmyk_images=NewImageList();
362 for (j=0; j < (ssize_t) GetImageListLength(images); j+=4)
367 cmyk_image=CloneImage(images,images->columns,images->rows,MagickTrue,
369 if (cmyk_image == (Image *) NULL)
371 if (SetImageStorageClass(cmyk_image,DirectClass,exception) == MagickFalse)
373 (void) SetImageColorspace(cmyk_image,CMYKColorspace,exception);
374 for (i=0; i < 4; i++)
376 image_view=AcquireVirtualCacheView(images,exception);
377 cmyk_view=AcquireAuthenticCacheView(cmyk_image,exception);
378 for (y=0; y < (ssize_t) images->rows; y++)
380 register const Quantum
389 p=GetCacheViewVirtualPixels(image_view,0,y,images->columns,1,exception);
390 q=QueueCacheViewAuthenticPixels(cmyk_view,0,y,cmyk_image->columns,1,
392 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
394 for (x=0; x < (ssize_t) images->columns; x++)
399 pixel=QuantumRange-GetPixelIntensity(images,p);
402 case 0: SetPixelCyan(cmyk_image,pixel,q); break;
403 case 1: SetPixelMagenta(cmyk_image,pixel,q); break;
404 case 2: SetPixelYellow(cmyk_image,pixel,q); break;
405 case 3: SetPixelBlack(cmyk_image,pixel,q); break;
408 p+=GetPixelChannels(images);
409 q+=GetPixelChannels(cmyk_image);
411 if (SyncCacheViewAuthenticPixels(cmyk_view,exception) == MagickFalse)
414 cmyk_view=DestroyCacheView(cmyk_view);
415 image_view=DestroyCacheView(image_view);
416 images=GetNextImageInList(images);
417 if (images == (Image *) NULL)
420 AppendImageToList(&cmyk_images,cmyk_image);
426 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
430 % C r o p I m a g e %
434 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
436 % CropImage() extracts a region of the image starting at the offset defined
437 % by geometry. Region must be fully defined, and no special handling of
438 % geometry flags is performed.
440 % The format of the CropImage method is:
442 % Image *CropImage(const Image *image,const RectangleInfo *geometry,
443 % ExceptionInfo *exception)
445 % A description of each parameter follows:
447 % o image: the image.
449 % o geometry: Define the region of the image to crop with members
450 % x, y, width, and height.
452 % o exception: return any errors or warnings in this structure.
455 MagickExport Image *CropImage(const Image *image,const RectangleInfo *geometry,
456 ExceptionInfo *exception)
458 #define CropImageTag "Crop/Image"
486 assert(image != (const Image *) NULL);
487 assert(image->signature == MagickSignature);
488 if (image->debug != MagickFalse)
489 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
490 assert(geometry != (const RectangleInfo *) NULL);
491 assert(exception != (ExceptionInfo *) NULL);
492 assert(exception->signature == MagickSignature);
493 bounding_box=image->page;
494 if ((bounding_box.width == 0) || (bounding_box.height == 0))
496 bounding_box.width=image->columns;
497 bounding_box.height=image->rows;
501 page.width=bounding_box.width;
502 if (page.height == 0)
503 page.height=bounding_box.height;
504 if (((bounding_box.x-page.x) >= (ssize_t) page.width) ||
505 ((bounding_box.y-page.y) >= (ssize_t) page.height) ||
506 ((page.x-bounding_box.x) > (ssize_t) image->columns) ||
507 ((page.y-bounding_box.y) > (ssize_t) image->rows))
510 Crop is not within virtual canvas, return 1 pixel transparent image.
512 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
513 "GeometryDoesNotContainImage","'%s'",image->filename);
514 crop_image=CloneImage(image,1,1,MagickTrue,exception);
515 if (crop_image == (Image *) NULL)
516 return((Image *) NULL);
517 crop_image->background_color.alpha=(Quantum) TransparentAlpha;
518 (void) SetImageBackgroundColor(crop_image,exception);
519 crop_image->page=bounding_box;
520 crop_image->page.x=(-1);
521 crop_image->page.y=(-1);
522 if (crop_image->dispose == BackgroundDispose)
523 crop_image->dispose=NoneDispose;
526 if ((page.x < 0) && (bounding_box.x >= 0))
528 page.width+=page.x-bounding_box.x;
533 page.width-=bounding_box.x-page.x;
534 page.x-=bounding_box.x;
538 if ((page.y < 0) && (bounding_box.y >= 0))
540 page.height+=page.y-bounding_box.y;
545 page.height-=bounding_box.y-page.y;
546 page.y-=bounding_box.y;
550 if ((size_t) (page.x+page.width) > image->columns)
551 page.width=image->columns-page.x;
552 if ((geometry->width != 0) && (page.width > geometry->width))
553 page.width=geometry->width;
554 if ((size_t) (page.y+page.height) > image->rows)
555 page.height=image->rows-page.y;
556 if ((geometry->height != 0) && (page.height > geometry->height))
557 page.height=geometry->height;
558 bounding_box.x+=page.x;
559 bounding_box.y+=page.y;
560 if ((page.width == 0) || (page.height == 0))
562 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
563 "GeometryDoesNotContainImage","'%s'",image->filename);
564 return((Image *) NULL);
567 Initialize crop image attributes.
569 crop_image=CloneImage(image,page.width,page.height,MagickTrue,exception);
570 if (crop_image == (Image *) NULL)
571 return((Image *) NULL);
572 crop_image->page.width=image->page.width;
573 crop_image->page.height=image->page.height;
574 offset.x=(ssize_t) (bounding_box.x+bounding_box.width);
575 offset.y=(ssize_t) (bounding_box.y+bounding_box.height);
576 if ((offset.x > (ssize_t) image->page.width) ||
577 (offset.y > (ssize_t) image->page.height))
579 crop_image->page.width=bounding_box.width;
580 crop_image->page.height=bounding_box.height;
582 crop_image->page.x=bounding_box.x;
583 crop_image->page.y=bounding_box.y;
589 image_view=AcquireVirtualCacheView(image,exception);
590 crop_view=AcquireAuthenticCacheView(crop_image,exception);
591 #if defined(MAGICKCORE_OPENMP_SUPPORT)
592 #pragma omp parallel for schedule(static) shared(progress,status) \
593 if ((crop_image->rows*crop_image->columns) > 8192) \
594 num_threads(GetMagickResourceLimit(ThreadResource))
596 for (y=0; y < (ssize_t) crop_image->rows; y++)
598 register const Quantum
607 if (status == MagickFalse)
609 p=GetCacheViewVirtualPixels(image_view,page.x,page.y+y,crop_image->columns,
611 q=QueueCacheViewAuthenticPixels(crop_view,0,y,crop_image->columns,1,
613 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
618 for (x=0; x < (ssize_t) crop_image->columns; x++)
623 if (GetPixelMask(image,p) != 0)
625 p+=GetPixelChannels(image);
626 q+=GetPixelChannels(crop_image);
629 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
638 channel=GetPixelChannelMapChannel(image,i);
639 traits=GetPixelChannelMapTraits(image,channel);
640 crop_traits=GetPixelChannelMapTraits(crop_image,channel);
641 if ((traits == UndefinedPixelTrait) ||
642 (crop_traits == UndefinedPixelTrait))
644 SetPixelChannel(crop_image,channel,p[i],q);
646 p+=GetPixelChannels(image);
647 q+=GetPixelChannels(crop_image);
649 if (SyncCacheViewAuthenticPixels(crop_view,exception) == MagickFalse)
651 if (image->progress_monitor != (MagickProgressMonitor) NULL)
656 #if defined(MAGICKCORE_OPENMP_SUPPORT)
657 #pragma omp critical (MagickCore_CropImage)
659 proceed=SetImageProgress(image,CropImageTag,progress++,image->rows);
660 if (proceed == MagickFalse)
664 crop_view=DestroyCacheView(crop_view);
665 image_view=DestroyCacheView(image_view);
666 crop_image->type=image->type;
667 if (status == MagickFalse)
668 crop_image=DestroyImage(crop_image);
673 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
677 % C r o p I m a g e T o T i l e s %
681 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
683 % CropImageToTiles() crops a single image, into a possible list of tiles.
684 % This may include a single sub-region of the image. This basically applies
685 % all the normal geometry flags for Crop.
687 % Image *CropImageToTiles(const Image *image,
688 % const RectangleInfo *crop_geometry, ExceptionInfo *exception)
690 % A description of each parameter follows:
692 % o image: the image The transformed image is returned as this parameter.
694 % o crop_geometry: A crop geometry string.
696 % o exception: return any errors or warnings in this structure.
700 static inline ssize_t MagickRound(MagickRealType x)
703 Round the fraction to nearest integer.
706 return((ssize_t) (x+0.5));
707 return((ssize_t) (x-0.5));
710 MagickExport Image *CropImageToTiles(const Image *image,
711 const char *crop_geometry,ExceptionInfo *exception)
723 assert(image != (Image *) NULL);
724 assert(image->signature == MagickSignature);
725 if (image->debug != MagickFalse)
726 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
727 crop_image=NewImageList();
729 flags=ParseGravityGeometry(image,crop_geometry,&geometry,exception);
730 if ((flags & AreaValue) != 0)
744 Crop into NxM tiles (@ flag).
746 width=image->columns;
748 if (geometry.width == 0)
750 if (geometry.height == 0)
752 if ((flags & AspectValue) == 0)
754 width-=(geometry.x < 0 ? -1 : 1)*geometry.x;
755 height-=(geometry.y < 0 ? -1 : 1)*geometry.y;
759 width+=(geometry.x < 0 ? -1 : 1)*geometry.x;
760 height+=(geometry.y < 0 ? -1 : 1)*geometry.y;
762 delta.x=(double) width/geometry.width;
763 delta.y=(double) height/geometry.height;
768 for (offset.y=0; offset.y < (double) height; )
770 if ((flags & AspectValue) == 0)
772 crop.y=(ssize_t) MagickRound((MagickRealType) (offset.y-
773 (geometry.y > 0 ? 0 : geometry.y)));
774 offset.y+=delta.y; /* increment now to find width */
775 crop.height=(size_t) MagickRound((MagickRealType) (offset.y+
776 (geometry.y < 0 ? 0 : geometry.y)));
780 crop.y=(ssize_t) MagickRound((MagickRealType) (offset.y-
781 (geometry.y > 0 ? geometry.y : 0)));
782 offset.y+=delta.y; /* increment now to find width */
783 crop.height=(size_t) MagickRound((MagickRealType)
784 (offset.y+(geometry.y < -1 ? geometry.y : 0)));
787 crop.y+=image->page.y;
788 for (offset.x=0; offset.x < (double) width; )
790 if ((flags & AspectValue) == 0)
792 crop.x=(ssize_t) MagickRound((MagickRealType) (offset.x-
793 (geometry.x > 0 ? 0 : geometry.x)));
794 offset.x+=delta.x; /* increment now to find height */
795 crop.width=(size_t) MagickRound((MagickRealType) (offset.x+
796 (geometry.x < 0 ? 0 : geometry.x)));
800 crop.x=(ssize_t) MagickRound((MagickRealType) (offset.x-
801 (geometry.x > 0 ? geometry.x : 0)));
802 offset.x+=delta.x; /* increment now to find height */
803 crop.width=(size_t) MagickRound((MagickRealType) (offset.x+
804 (geometry.x < 0 ? geometry.x : 0)));
807 crop.x+=image->page.x;
808 next=CropImage(image,&crop,exception);
809 if (next == (Image *) NULL)
811 AppendImageToList(&crop_image,next);
813 if (next == (Image *) NULL)
816 ClearMagickException(exception);
819 if (((geometry.width == 0) && (geometry.height == 0)) ||
820 ((flags & XValue) != 0) || ((flags & YValue) != 0))
823 Crop a single region at +X+Y.
825 crop_image=CropImage(image,&geometry,exception);
826 if ((crop_image != (Image *) NULL) && ((flags & AspectValue) != 0))
828 crop_image->page.width=geometry.width;
829 crop_image->page.height=geometry.height;
830 crop_image->page.x-=geometry.x;
831 crop_image->page.y-=geometry.y;
835 if ((image->columns > geometry.width) || (image->rows > geometry.height))
849 Crop into tiles of fixed size WxH.
853 page.width=image->columns;
854 if (page.height == 0)
855 page.height=image->rows;
856 width=geometry.width;
859 height=geometry.height;
863 for (y=0; y < (ssize_t) page.height; y+=(ssize_t) height)
865 for (x=0; x < (ssize_t) page.width; x+=(ssize_t) width)
867 geometry.width=width;
868 geometry.height=height;
871 next=CropImage(image,&geometry,exception);
872 if (next == (Image *) NULL)
874 AppendImageToList(&crop_image,next);
876 if (next == (Image *) NULL)
881 return(CloneImage(image,0,0,MagickTrue,exception));
885 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
889 % E x c e r p t I m a g e %
893 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
895 % ExcerptImage() returns a excerpt of the image as defined by the geometry.
897 % The format of the ExcerptImage method is:
899 % Image *ExcerptImage(const Image *image,const RectangleInfo *geometry,
900 % ExceptionInfo *exception)
902 % A description of each parameter follows:
904 % o image: the image.
906 % o geometry: Define the region of the image to extend with members
907 % x, y, width, and height.
909 % o exception: return any errors or warnings in this structure.
912 MagickExport Image *ExcerptImage(const Image *image,
913 const RectangleInfo *geometry,ExceptionInfo *exception)
915 #define ExcerptImageTag "Excerpt/Image"
934 Allocate excerpt image.
936 assert(image != (const Image *) NULL);
937 assert(image->signature == MagickSignature);
938 if (image->debug != MagickFalse)
939 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
940 assert(geometry != (const RectangleInfo *) NULL);
941 assert(exception != (ExceptionInfo *) NULL);
942 assert(exception->signature == MagickSignature);
943 excerpt_image=CloneImage(image,geometry->width,geometry->height,MagickTrue,
945 if (excerpt_image == (Image *) NULL)
946 return((Image *) NULL);
952 image_view=AcquireVirtualCacheView(image,exception);
953 excerpt_view=AcquireAuthenticCacheView(excerpt_image,exception);
954 #if defined(MAGICKCORE_OPENMP_SUPPORT)
955 #pragma omp parallel for schedule(static,4) shared(progress,status) \
956 if ((excerpt_image->rows*excerpt_image->columns) > 8192) \
957 num_threads(GetMagickResourceLimit(ThreadResource))
959 for (y=0; y < (ssize_t) excerpt_image->rows; y++)
961 register const Quantum
970 if (status == MagickFalse)
972 p=GetCacheViewVirtualPixels(image_view,geometry->x,geometry->y+y,
973 geometry->width,1,exception);
974 q=GetCacheViewAuthenticPixels(excerpt_view,0,y,excerpt_image->columns,1,
976 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
981 for (x=0; x < (ssize_t) excerpt_image->columns; x++)
986 if (GetPixelMask(image,p) != 0)
988 p+=GetPixelChannels(image);
989 q+=GetPixelChannels(excerpt_image);
992 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1001 channel=GetPixelChannelMapChannel(image,i);
1002 traits=GetPixelChannelMapTraits(image,channel);
1003 excerpt_traits=GetPixelChannelMapTraits(excerpt_image,channel);
1004 if ((traits == UndefinedPixelTrait) ||
1005 (excerpt_traits == UndefinedPixelTrait))
1007 SetPixelChannel(excerpt_image,channel,p[i],q);
1009 p+=GetPixelChannels(image);
1010 q+=GetPixelChannels(excerpt_image);
1012 if (SyncCacheViewAuthenticPixels(excerpt_view,exception) == MagickFalse)
1014 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1019 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1020 #pragma omp critical (MagickCore_ExcerptImage)
1022 proceed=SetImageProgress(image,ExcerptImageTag,progress++,image->rows);
1023 if (proceed == MagickFalse)
1027 excerpt_view=DestroyCacheView(excerpt_view);
1028 image_view=DestroyCacheView(image_view);
1029 excerpt_image->type=image->type;
1030 if (status == MagickFalse)
1031 excerpt_image=DestroyImage(excerpt_image);
1032 return(excerpt_image);
1036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1040 % E x t e n t I m a g e %
1044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1046 % ExtentImage() extends the image as defined by the geometry, gravity, and
1047 % image background color. Set the (x,y) offset of the geometry to move the
1048 % original image relative to the extended image.
1050 % The format of the ExtentImage method is:
1052 % Image *ExtentImage(const Image *image,const RectangleInfo *geometry,
1053 % ExceptionInfo *exception)
1055 % A description of each parameter follows:
1057 % o image: the image.
1059 % o geometry: Define the region of the image to extend with members
1060 % x, y, width, and height.
1062 % o exception: return any errors or warnings in this structure.
1065 MagickExport Image *ExtentImage(const Image *image,
1066 const RectangleInfo *geometry,ExceptionInfo *exception)
1072 Allocate extent image.
1074 assert(image != (const Image *) NULL);
1075 assert(image->signature == MagickSignature);
1076 if (image->debug != MagickFalse)
1077 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1078 assert(geometry != (const RectangleInfo *) NULL);
1079 assert(exception != (ExceptionInfo *) NULL);
1080 assert(exception->signature == MagickSignature);
1081 extent_image=CloneImage(image,geometry->width,geometry->height,MagickTrue,
1083 if (extent_image == (Image *) NULL)
1084 return((Image *) NULL);
1085 if (SetImageStorageClass(extent_image,DirectClass,exception) == MagickFalse)
1087 extent_image=DestroyImage(extent_image);
1088 return((Image *) NULL);
1090 if (extent_image->background_color.alpha != OpaqueAlpha)
1091 extent_image->matte=MagickTrue;
1092 (void) SetImageBackgroundColor(extent_image,exception);
1093 (void) CompositeImage(extent_image,image,image->compose,MagickTrue,
1094 -geometry->x,-geometry->y,exception);
1095 return(extent_image);
1099 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1103 % F l i p I m a g e %
1107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1109 % FlipImage() creates a vertical mirror image by reflecting the pixels
1110 % around the central x-axis.
1112 % The format of the FlipImage method is:
1114 % Image *FlipImage(const Image *image,ExceptionInfo *exception)
1116 % A description of each parameter follows:
1118 % o image: the image.
1120 % o exception: return any errors or warnings in this structure.
1123 MagickExport Image *FlipImage(const Image *image,ExceptionInfo *exception)
1125 #define FlipImageTag "Flip/Image"
1146 assert(image != (const Image *) NULL);
1147 assert(image->signature == MagickSignature);
1148 if (image->debug != MagickFalse)
1149 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1150 assert(exception != (ExceptionInfo *) NULL);
1151 assert(exception->signature == MagickSignature);
1152 flip_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1153 if (flip_image == (Image *) NULL)
1154 return((Image *) NULL);
1161 image_view=AcquireVirtualCacheView(image,exception);
1162 flip_view=AcquireAuthenticCacheView(flip_image,exception);
1163 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1164 #pragma omp parallel for schedule(static) shared(progress,status) \
1165 if ((flip_image->rows*flip_image->columns) > 8192) \
1166 num_threads(GetMagickResourceLimit(ThreadResource))
1168 for (y=0; y < (ssize_t) flip_image->rows; y++)
1170 register const Quantum
1179 if (status == MagickFalse)
1181 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1182 q=QueueCacheViewAuthenticPixels(flip_view,0,(ssize_t) (flip_image->rows-y-
1183 1),flip_image->columns,1,exception);
1184 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1189 for (x=0; x < (ssize_t) flip_image->columns; x++)
1194 if (GetPixelMask(image,p) != 0)
1196 p+=GetPixelChannels(image);
1197 q+=GetPixelChannels(flip_image);
1200 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1209 channel=GetPixelChannelMapChannel(image,i);
1210 traits=GetPixelChannelMapTraits(image,channel);
1211 flip_traits=GetPixelChannelMapTraits(flip_image,channel);
1212 if ((traits == UndefinedPixelTrait) ||
1213 (flip_traits == UndefinedPixelTrait))
1215 SetPixelChannel(flip_image,channel,p[i],q);
1217 p+=GetPixelChannels(image);
1218 q+=GetPixelChannels(flip_image);
1220 if (SyncCacheViewAuthenticPixels(flip_view,exception) == MagickFalse)
1222 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1227 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1228 #pragma omp critical (MagickCore_FlipImage)
1230 proceed=SetImageProgress(image,FlipImageTag,progress++,image->rows);
1231 if (proceed == MagickFalse)
1235 flip_view=DestroyCacheView(flip_view);
1236 image_view=DestroyCacheView(image_view);
1237 flip_image->type=image->type;
1238 if (page.height != 0)
1239 page.y=(ssize_t) (page.height-flip_image->rows-page.y);
1240 flip_image->page=page;
1241 if (status == MagickFalse)
1242 flip_image=DestroyImage(flip_image);
1247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1251 % F l o p I m a g e %
1255 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1257 % FlopImage() creates a horizontal mirror image by reflecting the pixels
1258 % around the central y-axis.
1260 % The format of the FlopImage method is:
1262 % Image *FlopImage(const Image *image,ExceptionInfo *exception)
1264 % A description of each parameter follows:
1266 % o image: the image.
1268 % o exception: return any errors or warnings in this structure.
1271 MagickExport Image *FlopImage(const Image *image,ExceptionInfo *exception)
1273 #define FlopImageTag "Flop/Image"
1294 assert(image != (const Image *) NULL);
1295 assert(image->signature == MagickSignature);
1296 if (image->debug != MagickFalse)
1297 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1298 assert(exception != (ExceptionInfo *) NULL);
1299 assert(exception->signature == MagickSignature);
1300 flop_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1301 if (flop_image == (Image *) NULL)
1302 return((Image *) NULL);
1309 image_view=AcquireVirtualCacheView(image,exception);
1310 flop_view=AcquireAuthenticCacheView(flop_image,exception);
1311 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1312 #pragma omp parallel for schedule(static) shared(progress,status) \
1313 if ((flop_image->rows*flop_image->columns) > 8192) \
1314 num_threads(GetMagickResourceLimit(ThreadResource))
1316 for (y=0; y < (ssize_t) flop_image->rows; y++)
1318 register const Quantum
1327 if (status == MagickFalse)
1329 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1330 q=QueueCacheViewAuthenticPixels(flop_view,0,y,flop_image->columns,1,
1332 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1337 q+=GetPixelChannels(flop_image)*flop_image->columns;
1338 for (x=0; x < (ssize_t) flop_image->columns; x++)
1343 q-=GetPixelChannels(flop_image);
1344 if (GetPixelMask(image,p) != 0)
1346 p+=GetPixelChannels(image);
1349 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1358 channel=GetPixelChannelMapChannel(image,i);
1359 traits=GetPixelChannelMapTraits(image,channel);
1360 flop_traits=GetPixelChannelMapTraits(flop_image,channel);
1361 if ((traits == UndefinedPixelTrait) ||
1362 (flop_traits == UndefinedPixelTrait))
1364 SetPixelChannel(flop_image,channel,p[i],q);
1366 p+=GetPixelChannels(image);
1368 if (SyncCacheViewAuthenticPixels(flop_view,exception) == MagickFalse)
1370 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1375 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1376 #pragma omp critical (MagickCore_FlopImage)
1378 proceed=SetImageProgress(image,FlopImageTag,progress++,image->rows);
1379 if (proceed == MagickFalse)
1383 flop_view=DestroyCacheView(flop_view);
1384 image_view=DestroyCacheView(image_view);
1385 flop_image->type=image->type;
1386 if (page.width != 0)
1387 page.x=(ssize_t) (page.width-flop_image->columns-page.x);
1388 flop_image->page=page;
1389 if (status == MagickFalse)
1390 flop_image=DestroyImage(flop_image);
1395 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1399 % R o l l I m a g e %
1403 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1405 % RollImage() offsets an image as defined by x_offset and y_offset.
1407 % The format of the RollImage method is:
1409 % Image *RollImage(const Image *image,const ssize_t x_offset,
1410 % const ssize_t y_offset,ExceptionInfo *exception)
1412 % A description of each parameter follows:
1414 % o image: the image.
1416 % o x_offset: the number of columns to roll in the horizontal direction.
1418 % o y_offset: the number of rows to roll in the vertical direction.
1420 % o exception: return any errors or warnings in this structure.
1424 static inline MagickBooleanType CopyImageRegion(Image *destination,
1425 const Image *source,const size_t columns,const size_t rows,
1426 const ssize_t sx,const ssize_t sy,const ssize_t dx,const ssize_t dy,
1427 ExceptionInfo *exception)
1440 source_view=AcquireVirtualCacheView(source,exception);
1441 destination_view=AcquireAuthenticCacheView(destination,exception);
1442 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1443 #pragma omp parallel for schedule(static) shared(status) \
1444 if ((rows*columns) > 8192) \
1445 num_threads(GetMagickResourceLimit(ThreadResource))
1447 for (y=0; y < (ssize_t) rows; y++)
1452 register const Quantum
1464 if (status == MagickFalse)
1466 p=GetCacheViewVirtualPixels(source_view,sx,sy+y,columns,1,exception);
1467 q=GetCacheViewAuthenticPixels(destination_view,dx,dy+y,columns,1,exception);
1468 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1473 for (x=0; x < (ssize_t) columns; x++)
1478 if (GetPixelMask(source,p) != 0)
1480 p+=GetPixelChannels(source);
1481 q+=GetPixelChannels(destination);
1484 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
1493 channel=GetPixelChannelMapChannel(source,i);
1494 source_traits=GetPixelChannelMapTraits(source,channel);
1495 destination_traits=GetPixelChannelMapTraits(destination,channel);
1496 if ((source_traits == UndefinedPixelTrait) ||
1497 (destination_traits == UndefinedPixelTrait))
1499 SetPixelChannel(destination,channel,p[i],q);
1501 p+=GetPixelChannels(source);
1502 q+=GetPixelChannels(destination);
1504 sync=SyncCacheViewAuthenticPixels(destination_view,exception);
1505 if (sync == MagickFalse)
1508 destination_view=DestroyCacheView(destination_view);
1509 source_view=DestroyCacheView(source_view);
1513 MagickExport Image *RollImage(const Image *image,const ssize_t x_offset,
1514 const ssize_t y_offset,ExceptionInfo *exception)
1516 #define RollImageTag "Roll/Image"
1528 Initialize roll image attributes.
1530 assert(image != (const Image *) NULL);
1531 assert(image->signature == MagickSignature);
1532 if (image->debug != MagickFalse)
1533 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1534 assert(exception != (ExceptionInfo *) NULL);
1535 assert(exception->signature == MagickSignature);
1536 roll_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1537 if (roll_image == (Image *) NULL)
1538 return((Image *) NULL);
1541 while (offset.x < 0)
1542 offset.x+=(ssize_t) image->columns;
1543 while (offset.x >= (ssize_t) image->columns)
1544 offset.x-=(ssize_t) image->columns;
1545 while (offset.y < 0)
1546 offset.y+=(ssize_t) image->rows;
1547 while (offset.y >= (ssize_t) image->rows)
1548 offset.y-=(ssize_t) image->rows;
1552 status=CopyImageRegion(roll_image,image,(size_t) offset.x,
1553 (size_t) offset.y,(ssize_t) image->columns-offset.x,(ssize_t) image->rows-
1554 offset.y,0,0,exception);
1555 (void) SetImageProgress(image,RollImageTag,0,3);
1556 status|=CopyImageRegion(roll_image,image,image->columns-offset.x,
1557 (size_t) offset.y,0,(ssize_t) image->rows-offset.y,offset.x,0,
1559 (void) SetImageProgress(image,RollImageTag,1,3);
1560 status|=CopyImageRegion(roll_image,image,(size_t) offset.x,image->rows-
1561 offset.y,(ssize_t) image->columns-offset.x,0,0,offset.y,exception);
1562 (void) SetImageProgress(image,RollImageTag,2,3);
1563 status|=CopyImageRegion(roll_image,image,image->columns-offset.x,image->rows-
1564 offset.y,0,0,offset.x,offset.y,exception);
1565 (void) SetImageProgress(image,RollImageTag,3,3);
1566 roll_image->type=image->type;
1567 if (status == MagickFalse)
1568 roll_image=DestroyImage(roll_image);
1573 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1577 % S h a v e I m a g e %
1581 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1583 % ShaveImage() shaves pixels from the image edges. It allocates the memory
1584 % necessary for the new Image structure and returns a pointer to the new
1587 % The format of the ShaveImage method is:
1589 % Image *ShaveImage(const Image *image,const RectangleInfo *shave_info,
1590 % ExceptionInfo *exception)
1592 % A description of each parameter follows:
1594 % o shave_image: Method ShaveImage returns a pointer to the shaved
1595 % image. A null image is returned if there is a memory shortage or
1596 % if the image width or height is zero.
1598 % o image: the image.
1600 % o shave_info: Specifies a pointer to a RectangleInfo which defines the
1601 % region of the image to crop.
1603 % o exception: return any errors or warnings in this structure.
1606 MagickExport Image *ShaveImage(const Image *image,
1607 const RectangleInfo *shave_info,ExceptionInfo *exception)
1615 assert(image != (const Image *) NULL);
1616 assert(image->signature == MagickSignature);
1617 if (image->debug != MagickFalse)
1618 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1619 if (((2*shave_info->width) >= image->columns) ||
1620 ((2*shave_info->height) >= image->rows))
1621 ThrowImageException(OptionWarning,"GeometryDoesNotContainImage");
1622 SetGeometry(image,&geometry);
1623 geometry.width-=2*shave_info->width;
1624 geometry.height-=2*shave_info->height;
1625 geometry.x=(ssize_t) shave_info->width+image->page.x;
1626 geometry.y=(ssize_t) shave_info->height+image->page.y;
1627 shave_image=CropImage(image,&geometry,exception);
1628 if (shave_image == (Image *) NULL)
1629 return((Image *) NULL);
1630 shave_image->page.width-=2*shave_info->width;
1631 shave_image->page.height-=2*shave_info->height;
1632 shave_image->page.x-=(ssize_t) shave_info->width;
1633 shave_image->page.y-=(ssize_t) shave_info->height;
1634 return(shave_image);
1638 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1642 % S p l i c e I m a g e %
1646 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1648 % SpliceImage() splices a solid color into the image as defined by the
1651 % The format of the SpliceImage method is:
1653 % Image *SpliceImage(const Image *image,const RectangleInfo *geometry,
1654 % ExceptionInfo *exception)
1656 % A description of each parameter follows:
1658 % o image: the image.
1660 % o geometry: Define the region of the image to splice with members
1661 % x, y, width, and height.
1663 % o exception: return any errors or warnings in this structure.
1666 MagickExport Image *SpliceImage(const Image *image,
1667 const RectangleInfo *geometry,ExceptionInfo *exception)
1669 #define SpliceImageTag "Splice/Image"
1691 Allocate splice image.
1693 assert(image != (const Image *) NULL);
1694 assert(image->signature == MagickSignature);
1695 if (image->debug != MagickFalse)
1696 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1697 assert(geometry != (const RectangleInfo *) NULL);
1698 assert(exception != (ExceptionInfo *) NULL);
1699 assert(exception->signature == MagickSignature);
1700 splice_geometry=(*geometry);
1701 splice_image=CloneImage(image,image->columns+splice_geometry.width,
1702 image->rows+splice_geometry.height,MagickTrue,exception);
1703 if (splice_image == (Image *) NULL)
1704 return((Image *) NULL);
1705 if (SetImageStorageClass(splice_image,DirectClass,exception) == MagickFalse)
1707 splice_image=DestroyImage(splice_image);
1708 return((Image *) NULL);
1710 (void) SetImageBackgroundColor(splice_image,exception);
1712 Respect image geometry.
1714 switch (image->gravity)
1717 case UndefinedGravity:
1718 case NorthWestGravity:
1722 splice_geometry.x+=(ssize_t) splice_geometry.width/2;
1725 case NorthEastGravity:
1727 splice_geometry.x+=(ssize_t) splice_geometry.width;
1732 splice_geometry.y+=(ssize_t) splice_geometry.width/2;
1737 splice_geometry.x+=(ssize_t) splice_geometry.width/2;
1738 splice_geometry.y+=(ssize_t) splice_geometry.height/2;
1743 splice_geometry.x+=(ssize_t) splice_geometry.width;
1744 splice_geometry.y+=(ssize_t) splice_geometry.height/2;
1747 case SouthWestGravity:
1749 splice_geometry.y+=(ssize_t) splice_geometry.height;
1754 splice_geometry.x+=(ssize_t) splice_geometry.width/2;
1755 splice_geometry.y+=(ssize_t) splice_geometry.height;
1758 case SouthEastGravity:
1760 splice_geometry.x+=(ssize_t) splice_geometry.width;
1761 splice_geometry.y+=(ssize_t) splice_geometry.height;
1770 image_view=AcquireVirtualCacheView(image,exception);
1771 splice_view=AcquireAuthenticCacheView(splice_image,exception);
1772 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1773 #pragma omp parallel for schedule(static,4) shared(progress,status) \
1774 if ((splice_geometry.y*splice_geometry.x) > 8192) \
1775 num_threads(GetMagickResourceLimit(ThreadResource))
1777 for (y=0; y < (ssize_t) splice_geometry.y; y++)
1779 register const Quantum
1788 if (status == MagickFalse)
1790 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1791 q=QueueCacheViewAuthenticPixels(splice_view,0,y,splice_image->columns,1,
1793 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1798 for (x=0; x < splice_geometry.x; x++)
1803 if (GetPixelMask(image,p) != 0)
1805 p+=GetPixelChannels(image);
1806 q+=GetPixelChannels(splice_image);
1809 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1818 channel=GetPixelChannelMapChannel(image,i);
1819 traits=GetPixelChannelMapTraits(image,channel);
1820 splice_traits=GetPixelChannelMapTraits(splice_image,channel);
1821 if ((traits == UndefinedPixelTrait) ||
1822 (splice_traits == UndefinedPixelTrait))
1824 SetPixelChannel(splice_image,channel,p[i],q);
1826 p+=GetPixelChannels(image);
1827 q+=GetPixelChannels(splice_image);
1829 for ( ; x < (ssize_t) (splice_geometry.x+splice_geometry.width); x++)
1830 q+=GetPixelChannels(splice_image);
1831 for ( ; x < (ssize_t) splice_image->columns; x++)
1836 if (GetPixelMask(image,p) != 0)
1838 p+=GetPixelChannels(image);
1839 q+=GetPixelChannels(splice_image);
1842 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1851 channel=GetPixelChannelMapChannel(image,i);
1852 traits=GetPixelChannelMapTraits(image,channel);
1853 splice_traits=GetPixelChannelMapTraits(splice_image,channel);
1854 if ((traits == UndefinedPixelTrait) ||
1855 (splice_traits == UndefinedPixelTrait))
1857 SetPixelChannel(splice_image,channel,p[i],q);
1859 p+=GetPixelChannels(image);
1860 q+=GetPixelChannels(splice_image);
1862 if (SyncCacheViewAuthenticPixels(splice_view,exception) == MagickFalse)
1864 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1869 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1870 #pragma omp critical (MagickCore_TransposeImage)
1872 proceed=SetImageProgress(image,SpliceImageTag,progress++,
1873 splice_image->rows);
1874 if (proceed == MagickFalse)
1878 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1879 #pragma omp parallel for schedule(static,4) shared(progress,status) \
1880 if ((splice_geometry.y*splice_geometry.x) > 8192) \
1881 num_threads(GetMagickResourceLimit(ThreadResource))
1883 for (y=(ssize_t) (splice_geometry.y+splice_geometry.height);
1884 y < (ssize_t) splice_image->rows; y++)
1886 register const Quantum
1895 if (status == MagickFalse)
1897 p=GetCacheViewVirtualPixels(image_view,0,y-(ssize_t) splice_geometry.height,
1898 image->columns,1,exception);
1899 if ((y < 0) || (y >= (ssize_t) splice_image->rows))
1901 q=QueueCacheViewAuthenticPixels(splice_view,0,y,splice_image->columns,1,
1903 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1908 for (x=0; x < splice_geometry.x; x++)
1913 if (GetPixelMask(image,q) != 0)
1915 p+=GetPixelChannels(image);
1916 q+=GetPixelChannels(splice_image);
1919 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1928 channel=GetPixelChannelMapChannel(image,i);
1929 traits=GetPixelChannelMapTraits(image,channel);
1930 splice_traits=GetPixelChannelMapTraits(splice_image,channel);
1931 if ((traits == UndefinedPixelTrait) ||
1932 (splice_traits == UndefinedPixelTrait))
1934 SetPixelChannel(splice_image,channel,p[i],q);
1936 p+=GetPixelChannels(image);
1937 q+=GetPixelChannels(splice_image);
1939 for ( ; x < (ssize_t) (splice_geometry.x+splice_geometry.width); x++)
1940 q+=GetPixelChannels(splice_image);
1941 for ( ; x < (ssize_t) splice_image->columns; x++)
1946 if (GetPixelMask(image,q) != 0)
1948 p+=GetPixelChannels(image);
1949 q+=GetPixelChannels(splice_image);
1952 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1961 channel=GetPixelChannelMapChannel(image,i);
1962 traits=GetPixelChannelMapTraits(image,channel);
1963 splice_traits=GetPixelChannelMapTraits(splice_image,channel);
1964 if ((traits == UndefinedPixelTrait) ||
1965 (splice_traits == UndefinedPixelTrait))
1967 SetPixelChannel(splice_image,channel,p[i],q);
1969 p+=GetPixelChannels(image);
1970 q+=GetPixelChannels(splice_image);
1972 if (SyncCacheViewAuthenticPixels(splice_view,exception) == MagickFalse)
1974 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1979 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1980 #pragma omp critical (MagickCore_TransposeImage)
1982 proceed=SetImageProgress(image,SpliceImageTag,progress++,
1983 splice_image->rows);
1984 if (proceed == MagickFalse)
1988 splice_view=DestroyCacheView(splice_view);
1989 image_view=DestroyCacheView(image_view);
1990 if (status == MagickFalse)
1991 splice_image=DestroyImage(splice_image);
1992 return(splice_image);
1996 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2000 % T r a n s f o r m I m a g e %
2004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2006 % TransformImage() is a convenience method that behaves like ResizeImage() or
2007 % CropImage() but accepts scaling and/or cropping information as a region
2008 % geometry specification. If the operation fails, the original image handle
2011 % This should only be used for single images.
2013 % This function destroys what it assumes to be a single image list.
2014 % If the input image is part of a larger list, all other images in that list
2015 % will be simply 'lost', not destroyed.
2017 % Also if the crop generates a list of images only the first image is resized.
2018 % And finally if the crop succeeds and the resize failed, you will get a
2019 % cropped image, as well as a 'false' or 'failed' report.
2021 % This function and should probably be depreciated in favor of direct calls
2022 % to CropImageToTiles() or ResizeImage(), as appropriate.
2024 % The format of the TransformImage method is:
2026 % MagickBooleanType TransformImage(Image **image,const char *crop_geometry,
2027 % const char *image_geometry,ExceptionInfo *exception)
2029 % A description of each parameter follows:
2031 % o image: the image The transformed image is returned as this parameter.
2033 % o crop_geometry: A crop geometry string. This geometry defines a
2034 % subregion of the image to crop.
2036 % o image_geometry: An image geometry string. This geometry defines the
2037 % final size of the image.
2039 % o exception: return any errors or warnings in this structure.
2042 MagickExport MagickBooleanType TransformImage(Image **image,
2043 const char *crop_geometry,const char *image_geometry,ExceptionInfo *exception)
2055 assert(image != (Image **) NULL);
2056 assert((*image)->signature == MagickSignature);
2057 if ((*image)->debug != MagickFalse)
2058 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
2059 transform_image=(*image);
2060 if (crop_geometry != (const char *) NULL)
2066 Crop image to a user specified size.
2068 crop_image=CropImageToTiles(*image,crop_geometry,exception);
2069 if (crop_image == (Image *) NULL)
2070 transform_image=CloneImage(*image,0,0,MagickTrue,exception);
2073 transform_image=DestroyImage(transform_image);
2074 transform_image=GetFirstImageInList(crop_image);
2076 *image=transform_image;
2078 if (image_geometry == (const char *) NULL)
2082 Scale image to a user specified size.
2084 flags=ParseRegionGeometry(transform_image,image_geometry,&geometry,exception);
2086 if ((transform_image->columns == geometry.width) &&
2087 (transform_image->rows == geometry.height))
2089 resize_image=ResizeImage(transform_image,geometry.width,geometry.height,
2090 transform_image->filter,exception);
2091 if (resize_image == (Image *) NULL)
2092 return(MagickFalse);
2093 transform_image=DestroyImage(transform_image);
2094 transform_image=resize_image;
2095 *image=transform_image;
2100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2104 % T r a n s f o r m I m a g e s %
2108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2110 % TransformImages() calls TransformImage() on each image of a sequence.
2112 % The format of the TransformImage method is:
2114 % MagickBooleanType TransformImages(Image **image,
2115 % const char *crop_geometry,const char *image_geometry,
2116 % ExceptionInfo *exception)
2118 % A description of each parameter follows:
2120 % o image: the image The transformed image is returned as this parameter.
2122 % o crop_geometry: A crop geometry string. This geometry defines a
2123 % subregion of the image to crop.
2125 % o image_geometry: An image geometry string. This geometry defines the
2126 % final size of the image.
2128 % o exception: return any errors or warnings in this structure.
2131 MagickExport MagickBooleanType TransformImages(Image **images,
2132 const char *crop_geometry,const char *image_geometry,ExceptionInfo *exception)
2145 assert(images != (Image **) NULL);
2146 assert((*images)->signature == MagickSignature);
2147 if ((*images)->debug != MagickFalse)
2148 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2149 (*images)->filename);
2150 image_list=ImageListToArray(*images,exception);
2151 if (image_list == (Image **) NULL)
2152 return(MagickFalse);
2154 transform_images=NewImageList();
2155 for (i=0; image_list[i] != (Image *) NULL; i++)
2157 image=image_list[i];
2158 status|=TransformImage(&image,crop_geometry,image_geometry,exception);
2159 AppendImageToList(&transform_images,image);
2161 *images=transform_images;
2162 image_list=(Image **) RelinquishMagickMemory(image_list);
2163 return(status != 0 ? MagickTrue : MagickFalse);
2167 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2171 % T r a n s p o s e I m a g e %
2175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2177 % TransposeImage() creates a horizontal mirror image by reflecting the pixels
2178 % around the central y-axis while rotating them by 90 degrees.
2180 % The format of the TransposeImage method is:
2182 % Image *TransposeImage(const Image *image,ExceptionInfo *exception)
2184 % A description of each parameter follows:
2186 % o image: the image.
2188 % o exception: return any errors or warnings in this structure.
2191 MagickExport Image *TransposeImage(const Image *image,ExceptionInfo *exception)
2193 #define TransposeImageTag "Transpose/Image"
2214 assert(image != (const Image *) NULL);
2215 assert(image->signature == MagickSignature);
2216 if (image->debug != MagickFalse)
2217 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2218 assert(exception != (ExceptionInfo *) NULL);
2219 assert(exception->signature == MagickSignature);
2220 transpose_image=CloneImage(image,image->rows,image->columns,MagickTrue,
2222 if (transpose_image == (Image *) NULL)
2223 return((Image *) NULL);
2229 image_view=AcquireVirtualCacheView(image,exception);
2230 transpose_view=AcquireAuthenticCacheView(transpose_image,exception);
2231 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2232 #pragma omp parallel for schedule(static,4) shared(progress,status) \
2233 if ((image->rows*image->columns) > 8192) \
2234 num_threads(GetMagickResourceLimit(ThreadResource))
2236 for (y=0; y < (ssize_t) image->rows; y++)
2238 register const Quantum
2247 if (status == MagickFalse)
2249 p=GetCacheViewVirtualPixels(image_view,0,(ssize_t) image->rows-y-1,
2250 image->columns,1,exception);
2251 q=QueueCacheViewAuthenticPixels(transpose_view,(ssize_t) (image->rows-y-1),
2252 0,1,transpose_image->rows,exception);
2253 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2258 for (x=0; x < (ssize_t) image->columns; x++)
2263 if (GetPixelMask(image,q) != 0)
2265 p+=GetPixelChannels(image);
2266 q+=GetPixelChannels(transpose_image);
2269 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2278 channel=GetPixelChannelMapChannel(image,i);
2279 traits=GetPixelChannelMapTraits(image,channel);
2280 transpose_traits=GetPixelChannelMapTraits(transpose_image,channel);
2281 if ((traits == UndefinedPixelTrait) ||
2282 (transpose_traits == UndefinedPixelTrait))
2284 SetPixelChannel(transpose_image,channel,p[i],q);
2286 p+=GetPixelChannels(image);
2287 q+=GetPixelChannels(transpose_image);
2289 if (SyncCacheViewAuthenticPixels(transpose_view,exception) == MagickFalse)
2291 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2296 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2297 #pragma omp critical (MagickCore_TransposeImage)
2299 proceed=SetImageProgress(image,TransposeImageTag,progress++,
2301 if (proceed == MagickFalse)
2305 transpose_view=DestroyCacheView(transpose_view);
2306 image_view=DestroyCacheView(image_view);
2307 transpose_image->type=image->type;
2308 page=transpose_image->page;
2309 Swap(page.width,page.height);
2310 Swap(page.x,page.y);
2311 transpose_image->page=page;
2312 if (status == MagickFalse)
2313 transpose_image=DestroyImage(transpose_image);
2314 return(transpose_image);
2318 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2322 % T r a n s v e r s e I m a g e %
2326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2328 % TransverseImage() creates a vertical mirror image by reflecting the pixels
2329 % around the central x-axis while rotating them by 270 degrees.
2331 % The format of the TransverseImage method is:
2333 % Image *TransverseImage(const Image *image,ExceptionInfo *exception)
2335 % A description of each parameter follows:
2337 % o image: the image.
2339 % o exception: return any errors or warnings in this structure.
2342 MagickExport Image *TransverseImage(const Image *image,ExceptionInfo *exception)
2344 #define TransverseImageTag "Transverse/Image"
2365 assert(image != (const Image *) NULL);
2366 assert(image->signature == MagickSignature);
2367 if (image->debug != MagickFalse)
2368 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2369 assert(exception != (ExceptionInfo *) NULL);
2370 assert(exception->signature == MagickSignature);
2371 transverse_image=CloneImage(image,image->rows,image->columns,MagickTrue,
2373 if (transverse_image == (Image *) NULL)
2374 return((Image *) NULL);
2380 image_view=AcquireVirtualCacheView(image,exception);
2381 transverse_view=AcquireAuthenticCacheView(transverse_image,exception);
2382 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2383 #pragma omp parallel for schedule(static,4) shared(progress,status) \
2384 if ((image->rows*image->columns) > 8192) \
2385 num_threads(GetMagickResourceLimit(ThreadResource))
2387 for (y=0; y < (ssize_t) image->rows; y++)
2392 register const Quantum
2401 if (status == MagickFalse)
2403 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
2404 q=QueueCacheViewAuthenticPixels(transverse_view,(ssize_t) (image->rows-y-1),
2405 0,1,transverse_image->rows,exception);
2406 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2411 q+=GetPixelChannels(transverse_image)*image->columns;
2412 for (x=0; x < (ssize_t) image->columns; x++)
2417 q-=GetPixelChannels(transverse_image);
2418 if (GetPixelMask(image,p) != 0)
2420 p+=GetPixelChannels(image);
2423 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2432 channel=GetPixelChannelMapChannel(image,i);
2433 traits=GetPixelChannelMapTraits(image,channel);
2434 transverse_traits=GetPixelChannelMapTraits(transverse_image,channel);
2435 if ((traits == UndefinedPixelTrait) ||
2436 (transverse_traits == UndefinedPixelTrait))
2438 SetPixelChannel(transverse_image,channel,p[i],q);
2440 p+=GetPixelChannels(image);
2442 sync=SyncCacheViewAuthenticPixels(transverse_view,exception);
2443 if (sync == MagickFalse)
2445 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2450 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2451 #pragma omp critical (MagickCore_TransverseImage)
2453 proceed=SetImageProgress(image,TransverseImageTag,progress++,
2455 if (proceed == MagickFalse)
2459 transverse_view=DestroyCacheView(transverse_view);
2460 image_view=DestroyCacheView(image_view);
2461 transverse_image->type=image->type;
2462 page=transverse_image->page;
2463 Swap(page.width,page.height);
2464 Swap(page.x,page.y);
2465 if (page.width != 0)
2466 page.x=(ssize_t) (page.width-transverse_image->columns-page.x);
2467 if (page.height != 0)
2468 page.y=(ssize_t) (page.height-transverse_image->rows-page.y);
2469 transverse_image->page=page;
2470 if (status == MagickFalse)
2471 transverse_image=DestroyImage(transverse_image);
2472 return(transverse_image);
2476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2480 % T r i m I m a g e %
2484 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2486 % TrimImage() trims pixels from the image edges. It allocates the memory
2487 % necessary for the new Image structure and returns a pointer to the new
2490 % The format of the TrimImage method is:
2492 % Image *TrimImage(const Image *image,ExceptionInfo *exception)
2494 % A description of each parameter follows:
2496 % o image: the image.
2498 % o exception: return any errors or warnings in this structure.
2501 MagickExport Image *TrimImage(const Image *image,ExceptionInfo *exception)
2506 assert(image != (const Image *) NULL);
2507 assert(image->signature == MagickSignature);
2508 if (image->debug != MagickFalse)
2509 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2510 geometry=GetImageBoundingBox(image,exception);
2511 if ((geometry.width == 0) || (geometry.height == 0))
2516 crop_image=CloneImage(image,1,1,MagickTrue,exception);
2517 if (crop_image == (Image *) NULL)
2518 return((Image *) NULL);
2519 crop_image->background_color.alpha=(Quantum) TransparentAlpha;
2520 (void) SetImageBackgroundColor(crop_image,exception);
2521 crop_image->page=image->page;
2522 crop_image->page.x=(-1);
2523 crop_image->page.y=(-1);
2526 geometry.x+=image->page.x;
2527 geometry.y+=image->page.y;
2528 return(CropImage(image,&geometry,exception));