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-2011 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=AcquireCacheView(image);
161 chop_view=AcquireCacheView(chop_image);
162 #if defined(MAGICKCORE_OPENMP_SUPPORT)
163 #pragma omp parallel for schedule(dynamic,4) shared(progress,status) omp_throttle(1)
165 for (y=0; y < (ssize_t) extent.y; y++)
167 register const Quantum
176 if (status == MagickFalse)
178 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
179 q=QueueCacheViewAuthenticPixels(chop_view,0,y,chop_image->columns,1,
181 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
186 for (x=0; x < (ssize_t) image->columns; x++)
188 if ((x < extent.x) || (x >= (ssize_t) (extent.x+extent.width)))
193 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
202 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
203 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
204 chop_traits=GetPixelChannelMapTraits(chop_image,channel);
205 if ((traits == UndefinedPixelTrait) ||
206 (chop_traits == UndefinedPixelTrait))
208 SetPixelChannel(chop_image,channel,p[i],q);
210 q+=GetPixelChannels(chop_image);
212 p+=GetPixelChannels(image);
214 if (SyncCacheViewAuthenticPixels(chop_view,exception) == MagickFalse)
216 if (image->progress_monitor != (MagickProgressMonitor) NULL)
221 #if defined(MAGICKCORE_OPENMP_SUPPORT)
222 #pragma omp critical (MagickCore_ChopImage)
224 proceed=SetImageProgress(image,ChopImageTag,progress++,image->rows);
225 if (proceed == MagickFalse)
232 #if defined(MAGICKCORE_OPENMP_SUPPORT)
233 #pragma omp parallel for schedule(dynamic,4) shared(progress,status) omp_throttle(1)
235 for (y=0; y < (ssize_t) (image->rows-(extent.y+extent.height)); y++)
237 register const Quantum
246 if (status == MagickFalse)
248 p=GetCacheViewVirtualPixels(image_view,0,extent.y+extent.height+y,
249 image->columns,1,exception);
250 q=QueueCacheViewAuthenticPixels(chop_view,0,extent.y+y,chop_image->columns,
252 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
257 for (x=0; x < (ssize_t) image->columns; x++)
259 if ((x < extent.x) || (x >= (ssize_t) (extent.x+extent.width)))
264 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
273 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
274 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
275 chop_traits=GetPixelChannelMapTraits(chop_image,channel);
276 if ((traits == UndefinedPixelTrait) ||
277 (chop_traits == UndefinedPixelTrait))
279 SetPixelChannel(chop_image,channel,p[i],q);
281 q+=GetPixelChannels(chop_image);
283 p+=GetPixelChannels(image);
285 if (SyncCacheViewAuthenticPixels(chop_view,exception) == MagickFalse)
287 if (image->progress_monitor != (MagickProgressMonitor) NULL)
292 #if defined(MAGICKCORE_OPENMP_SUPPORT)
293 #pragma omp critical (MagickCore_ChopImage)
295 proceed=SetImageProgress(image,ChopImageTag,progress++,image->rows);
296 if (proceed == MagickFalse)
300 chop_view=DestroyCacheView(chop_view);
301 image_view=DestroyCacheView(image_view);
302 chop_image->type=image->type;
307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
311 + C o n s o l i d a t e C M Y K I m a g e %
315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
317 % ConsolidateCMYKImage() consolidates separate C, M, Y, and K planes into a
320 % The format of the ConsolidateCMYKImage method is:
322 % Image *ConsolidateCMYKImage(const Image *image,ExceptionInfo *exception)
324 % A description of each parameter follows:
326 % o image: the image sequence.
328 % o exception: return any errors or warnings in this structure.
331 MagickExport Image *ConsolidateCMYKImages(const Image *images,
332 ExceptionInfo *exception)
349 Consolidate separate C, M, Y, and K planes into a single image.
351 assert(images != (Image *) NULL);
352 assert(images->signature == MagickSignature);
353 if (images->debug != MagickFalse)
354 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
355 assert(exception != (ExceptionInfo *) NULL);
356 assert(exception->signature == MagickSignature);
357 cmyk_images=NewImageList();
358 for (j=0; j < (ssize_t) GetImageListLength(images); j+=4)
363 cmyk_image=CloneImage(images,images->columns,images->rows,MagickTrue,
365 if (cmyk_image == (Image *) NULL)
367 if (SetImageStorageClass(cmyk_image,DirectClass,exception) == MagickFalse)
369 (void) SetImageColorspace(cmyk_image,CMYKColorspace,exception);
370 for (i=0; i < 4; i++)
372 image_view=AcquireCacheView(images);
373 cmyk_view=AcquireCacheView(cmyk_image);
374 for (y=0; y < (ssize_t) images->rows; y++)
376 register const Quantum
385 p=GetCacheViewVirtualPixels(image_view,0,y,images->columns,1,exception);
386 q=QueueCacheViewAuthenticPixels(cmyk_view,0,y,cmyk_image->columns,1,
388 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
390 for (x=0; x < (ssize_t) images->columns; x++)
395 pixel=QuantumRange-GetPixelIntensity(images,p);
398 case 0: SetPixelCyan(cmyk_image,pixel,q); break;
399 case 1: SetPixelMagenta(cmyk_image,pixel,q); break;
400 case 2: SetPixelYellow(cmyk_image,pixel,q); break;
401 case 3: SetPixelBlack(cmyk_image,pixel,q); break;
404 p+=GetPixelChannels(images);
405 q+=GetPixelChannels(cmyk_image);
407 if (SyncCacheViewAuthenticPixels(cmyk_view,exception) == MagickFalse)
410 cmyk_view=DestroyCacheView(cmyk_view);
411 image_view=DestroyCacheView(image_view);
412 images=GetNextImageInList(images);
413 if (images == (Image *) NULL)
416 AppendImageToList(&cmyk_images,cmyk_image);
422 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
426 % C r o p I m a g e %
430 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
432 % CropImage() extracts a region of the image starting at the offset defined
433 % by geometry. Region must be fully defined, and no special handling of
434 % geometry flags is performed.
436 % The format of the CropImage method is:
438 % Image *CropImage(const Image *image,const RectangleInfo *geometry,
439 % ExceptionInfo *exception)
441 % A description of each parameter follows:
443 % o image: the image.
445 % o geometry: Define the region of the image to crop with members
446 % x, y, width, and height.
448 % o exception: return any errors or warnings in this structure.
451 MagickExport Image *CropImage(const Image *image,const RectangleInfo *geometry,
452 ExceptionInfo *exception)
454 #define CropImageTag "Crop/Image"
482 assert(image != (const Image *) NULL);
483 assert(image->signature == MagickSignature);
484 if (image->debug != MagickFalse)
485 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
486 assert(geometry != (const RectangleInfo *) NULL);
487 assert(exception != (ExceptionInfo *) NULL);
488 assert(exception->signature == MagickSignature);
489 bounding_box=image->page;
490 if ((bounding_box.width == 0) || (bounding_box.height == 0))
492 bounding_box.width=image->columns;
493 bounding_box.height=image->rows;
497 page.width=bounding_box.width;
498 if (page.height == 0)
499 page.height=bounding_box.height;
500 if (((bounding_box.x-page.x) >= (ssize_t) page.width) ||
501 ((bounding_box.y-page.y) >= (ssize_t) page.height) ||
502 ((page.x-bounding_box.x) > (ssize_t) image->columns) ||
503 ((page.y-bounding_box.y) > (ssize_t) image->rows))
506 Crop is not within virtual canvas, return 1 pixel transparent image.
508 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
509 "GeometryDoesNotContainImage","`%s'",image->filename);
510 crop_image=CloneImage(image,1,1,MagickTrue,exception);
511 if (crop_image == (Image *) NULL)
512 return((Image *) NULL);
513 crop_image->background_color.alpha=(Quantum) TransparentAlpha;
514 (void) SetImageBackgroundColor(crop_image,exception);
515 crop_image->page=bounding_box;
516 crop_image->page.x=(-1);
517 crop_image->page.y=(-1);
518 if (crop_image->dispose == BackgroundDispose)
519 crop_image->dispose=NoneDispose;
522 if ((page.x < 0) && (bounding_box.x >= 0))
524 page.width+=page.x-bounding_box.x;
529 page.width-=bounding_box.x-page.x;
530 page.x-=bounding_box.x;
534 if ((page.y < 0) && (bounding_box.y >= 0))
536 page.height+=page.y-bounding_box.y;
541 page.height-=bounding_box.y-page.y;
542 page.y-=bounding_box.y;
546 if ((size_t) (page.x+page.width) > image->columns)
547 page.width=image->columns-page.x;
548 if ((geometry->width != 0) && (page.width > geometry->width))
549 page.width=geometry->width;
550 if ((size_t) (page.y+page.height) > image->rows)
551 page.height=image->rows-page.y;
552 if ((geometry->height != 0) && (page.height > geometry->height))
553 page.height=geometry->height;
554 bounding_box.x+=page.x;
555 bounding_box.y+=page.y;
556 if ((page.width == 0) || (page.height == 0))
558 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
559 "GeometryDoesNotContainImage","`%s'",image->filename);
560 return((Image *) NULL);
563 Initialize crop image attributes.
565 crop_image=CloneImage(image,page.width,page.height,MagickTrue,exception);
566 if (crop_image == (Image *) NULL)
567 return((Image *) NULL);
568 crop_image->page.width=image->page.width;
569 crop_image->page.height=image->page.height;
570 offset.x=(ssize_t) (bounding_box.x+bounding_box.width);
571 offset.y=(ssize_t) (bounding_box.y+bounding_box.height);
572 if ((offset.x > (ssize_t) image->page.width) ||
573 (offset.y > (ssize_t) image->page.height))
575 crop_image->page.width=bounding_box.width;
576 crop_image->page.height=bounding_box.height;
578 crop_image->page.x=bounding_box.x;
579 crop_image->page.y=bounding_box.y;
585 image_view=AcquireCacheView(image);
586 crop_view=AcquireCacheView(crop_image);
587 #if defined(MAGICKCORE_OPENMP_SUPPORT)
588 #pragma omp parallel for schedule(dynamic,4) shared(progress,status) omp_throttle(1)
590 for (y=0; y < (ssize_t) crop_image->rows; y++)
592 register const Quantum
601 if (status == MagickFalse)
603 p=GetCacheViewVirtualPixels(image_view,page.x,page.y+y,crop_image->columns,
605 q=QueueCacheViewAuthenticPixels(crop_view,0,y,crop_image->columns,1,
607 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
612 for (x=0; x < (ssize_t) crop_image->columns; x++)
617 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
626 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
627 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
628 crop_traits=GetPixelChannelMapTraits(crop_image,channel);
629 if ((traits == UndefinedPixelTrait) ||
630 (crop_traits == UndefinedPixelTrait))
632 SetPixelChannel(crop_image,channel,p[i],q);
634 p+=GetPixelChannels(image);
635 q+=GetPixelChannels(crop_image);
637 if (SyncCacheViewAuthenticPixels(crop_view,exception) == MagickFalse)
639 if (image->progress_monitor != (MagickProgressMonitor) NULL)
644 #if defined(MAGICKCORE_OPENMP_SUPPORT)
645 #pragma omp critical (MagickCore_CropImage)
647 proceed=SetImageProgress(image,CropImageTag,progress++,image->rows);
648 if (proceed == MagickFalse)
652 crop_view=DestroyCacheView(crop_view);
653 image_view=DestroyCacheView(image_view);
654 crop_image->type=image->type;
655 if (status == MagickFalse)
656 crop_image=DestroyImage(crop_image);
661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
665 % C r o p I m a g e T o T i l e s %
669 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
671 % CropImageToTiles() crops a single image, into a possible list of tiles.
672 % This may include a single sub-region of the image. This basically applies
673 % all the normal geometry flags for Crop.
675 % Image *CropImageToTiles(const Image *image,
676 % const RectangleInfo *crop_geometry, ExceptionInfo *exception)
678 % A description of each parameter follows:
680 % o image: the image The transformed image is returned as this parameter.
682 % o crop_geometry: A crop geometry string.
684 % o exception: return any errors or warnings in this structure.
688 static inline ssize_t MagickRound(MagickRealType x)
691 Round the fraction to nearest integer.
694 return((ssize_t) (x+0.5));
695 return((ssize_t) (x-0.5));
698 MagickExport Image *CropImageToTiles(const Image *image,
699 const char *crop_geometry, ExceptionInfo *exception)
711 assert(image != (Image *) NULL);
712 assert(image->signature == MagickSignature);
713 if (image->debug != MagickFalse)
714 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
715 crop_image=NewImageList();
717 flags=ParseGravityGeometry(image,crop_geometry,&geometry,exception);
718 if ((flags & AreaValue) != 0)
732 Crop into NxM tiles (@ flag).
734 width=image->columns;
736 if (geometry.width == 0)
738 if (geometry.height == 0)
740 if ((flags & AspectValue) == 0)
742 width-=(geometry.x < 0 ? -1 : 1)*geometry.x;
743 height-=(geometry.y < 0 ? -1 : 1)*geometry.y;
747 width+=(geometry.x < 0 ? -1 : 1)*geometry.x;
748 height+=(geometry.y < 0 ? -1 : 1)*geometry.y;
750 delta.x=(double) (width+(geometry.width >> 1))/geometry.width;
751 delta.y=(double) (height+(geometry.height >> 1))/geometry.height;
752 for (offset.y=0; offset.y < (double) height; )
754 if ((flags & AspectValue) == 0)
756 crop.y=(ssize_t) MagickRound((MagickRealType) (offset.y-
757 (geometry.y > 0 ? 0 : geometry.y)));
758 offset.y+=delta.y; /* increment now to find width */
759 crop.height=(size_t) MagickRound((MagickRealType) (offset.y+
760 (geometry.y < 0 ? 0 : geometry.y)));
764 crop.y=(ssize_t) MagickRound((MagickRealType) (offset.y-
765 (geometry.y > 0 ? geometry.y : 0)));
766 offset.y+=delta.y; /* increment now to find width */
767 crop.height=(size_t) MagickRound((MagickRealType)
768 (offset.y+(geometry.y < -1 ? geometry.y : 0)));
771 crop.y+=image->page.y;
772 for (offset.x=0; offset.x < (double) width; )
774 if ((flags & AspectValue) == 0)
776 crop.x=(ssize_t) MagickRound((MagickRealType) (offset.x-
777 (geometry.x > 0 ? 0 : geometry.x)));
778 offset.x+=delta.x; /* increment now to find height */
779 crop.width=(size_t) MagickRound((MagickRealType) (offset.x+
780 (geometry.x < 0 ? 0 : geometry.x)));
784 crop.x=(ssize_t) MagickRound((MagickRealType) (offset.x-
785 (geometry.x > 0 ? geometry.x : 0)));
786 offset.x+=delta.x; /* increment now to find height */
787 crop.width=(size_t) MagickRound((MagickRealType) (offset.x+
788 (geometry.x < 0 ? geometry.x : 0)));
791 crop.x+=image->page.x;
792 next=CropImage(image,&crop,exception);
793 if (next == (Image *) NULL)
795 AppendImageToList(&crop_image,next);
797 if (next == (Image *) NULL)
800 ClearMagickException(exception);
804 if (((geometry.width == 0) && (geometry.height == 0)) ||
805 ((flags & XValue) != 0) || ((flags & YValue) != 0))
808 Crop a single region at +X+Y.
810 crop_image=CropImage(image,&geometry,exception);
811 if ((crop_image != (Image *) NULL) && ((flags & AspectValue) != 0))
813 crop_image->page.width=geometry.width;
814 crop_image->page.height=geometry.height;
815 crop_image->page.x-=geometry.x;
816 crop_image->page.y-=geometry.y;
820 if ((image->columns > geometry.width) || (image->rows > geometry.height))
834 Crop into tiles of fixed size WxH.
838 page.width=image->columns;
839 if (page.height == 0)
840 page.height=image->rows;
841 width=geometry.width;
844 height=geometry.height;
848 for (y=0; y < (ssize_t) page.height; y+=(ssize_t) height)
850 for (x=0; x < (ssize_t) page.width; x+=(ssize_t) width)
852 geometry.width=width;
853 geometry.height=height;
856 next=CropImage(image,&geometry,exception);
857 if (next == (Image *) NULL)
859 AppendImageToList(&crop_image,next);
861 if (next == (Image *) NULL)
866 return(CloneImage(image,0,0,MagickTrue,exception));
870 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
874 % E x c e r p t I m a g e %
878 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
880 % ExcerptImage() returns a excerpt of the image as defined by the geometry.
882 % The format of the ExcerptImage method is:
884 % Image *ExcerptImage(const Image *image,const RectangleInfo *geometry,
885 % ExceptionInfo *exception)
887 % A description of each parameter follows:
889 % o image: the image.
891 % o geometry: Define the region of the image to extend with members
892 % x, y, width, and height.
894 % o exception: return any errors or warnings in this structure.
897 MagickExport Image *ExcerptImage(const Image *image,
898 const RectangleInfo *geometry,ExceptionInfo *exception)
900 #define ExcerptImageTag "Excerpt/Image"
919 Allocate excerpt image.
921 assert(image != (const Image *) NULL);
922 assert(image->signature == MagickSignature);
923 if (image->debug != MagickFalse)
924 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
925 assert(geometry != (const RectangleInfo *) NULL);
926 assert(exception != (ExceptionInfo *) NULL);
927 assert(exception->signature == MagickSignature);
928 excerpt_image=CloneImage(image,geometry->width,geometry->height,MagickTrue,
930 if (excerpt_image == (Image *) NULL)
931 return((Image *) NULL);
937 image_view=AcquireCacheView(image);
938 excerpt_view=AcquireCacheView(excerpt_image);
939 #if defined(MAGICKCORE_OPENMP_SUPPORT)
940 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
942 for (y=0; y < (ssize_t) excerpt_image->rows; y++)
944 register const Quantum
953 if (status == MagickFalse)
955 p=GetCacheViewVirtualPixels(image_view,geometry->x,geometry->y+y,
956 geometry->width,1,exception);
957 q=GetCacheViewAuthenticPixels(excerpt_view,0,y,excerpt_image->columns,1,
959 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
964 for (x=0; x < (ssize_t) excerpt_image->columns; x++)
969 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
978 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
979 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
980 excerpt_traits=GetPixelChannelMapTraits(excerpt_image,channel);
981 if ((traits == UndefinedPixelTrait) ||
982 (excerpt_traits == UndefinedPixelTrait))
984 SetPixelChannel(excerpt_image,channel,p[i],q);
986 p+=GetPixelChannels(image);
987 q+=GetPixelChannels(excerpt_image);
989 if (SyncCacheViewAuthenticPixels(excerpt_view,exception) == MagickFalse)
991 if (image->progress_monitor != (MagickProgressMonitor) NULL)
996 #if defined(MAGICKCORE_OPENMP_SUPPORT)
997 #pragma omp critical (MagickCore_ExcerptImage)
999 proceed=SetImageProgress(image,ExcerptImageTag,progress++,image->rows);
1000 if (proceed == MagickFalse)
1004 excerpt_view=DestroyCacheView(excerpt_view);
1005 image_view=DestroyCacheView(image_view);
1006 excerpt_image->type=image->type;
1007 if (status == MagickFalse)
1008 excerpt_image=DestroyImage(excerpt_image);
1009 return(excerpt_image);
1013 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1017 % E x t e n t I m a g e %
1021 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1023 % ExtentImage() extends the image as defined by the geometry, gravity, and
1024 % image background color. Set the (x,y) offset of the geometry to move the
1025 % original image relative to the extended image.
1027 % The format of the ExtentImage method is:
1029 % Image *ExtentImage(const Image *image,const RectangleInfo *geometry,
1030 % ExceptionInfo *exception)
1032 % A description of each parameter follows:
1034 % o image: the image.
1036 % o geometry: Define the region of the image to extend with members
1037 % x, y, width, and height.
1039 % o exception: return any errors or warnings in this structure.
1042 MagickExport Image *ExtentImage(const Image *image,
1043 const RectangleInfo *geometry,ExceptionInfo *exception)
1049 Allocate extent image.
1051 assert(image != (const Image *) NULL);
1052 assert(image->signature == MagickSignature);
1053 if (image->debug != MagickFalse)
1054 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1055 assert(geometry != (const RectangleInfo *) NULL);
1056 assert(exception != (ExceptionInfo *) NULL);
1057 assert(exception->signature == MagickSignature);
1058 extent_image=CloneImage(image,geometry->width,geometry->height,MagickTrue,
1060 if (extent_image == (Image *) NULL)
1061 return((Image *) NULL);
1062 if (SetImageStorageClass(extent_image,DirectClass,exception) == MagickFalse)
1064 extent_image=DestroyImage(extent_image);
1065 return((Image *) NULL);
1067 if (extent_image->background_color.alpha != OpaqueAlpha)
1068 extent_image->matte=MagickTrue;
1069 (void) SetImageBackgroundColor(extent_image,exception);
1070 (void) CompositeImage(extent_image,image->compose,image,-geometry->x,
1071 -geometry->y,exception);
1072 return(extent_image);
1076 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1080 % F l i p I m a g e %
1084 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1086 % FlipImage() creates a vertical mirror image by reflecting the pixels
1087 % around the central x-axis.
1089 % The format of the FlipImage method is:
1091 % Image *FlipImage(const Image *image,ExceptionInfo *exception)
1093 % A description of each parameter follows:
1095 % o image: the image.
1097 % o exception: return any errors or warnings in this structure.
1100 MagickExport Image *FlipImage(const Image *image,ExceptionInfo *exception)
1102 #define FlipImageTag "Flip/Image"
1123 assert(image != (const Image *) NULL);
1124 assert(image->signature == MagickSignature);
1125 if (image->debug != MagickFalse)
1126 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1127 assert(exception != (ExceptionInfo *) NULL);
1128 assert(exception->signature == MagickSignature);
1129 flip_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1130 if (flip_image == (Image *) NULL)
1131 return((Image *) NULL);
1138 image_view=AcquireCacheView(image);
1139 flip_view=AcquireCacheView(flip_image);
1140 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1141 #pragma omp parallel for schedule(dynamic,4) shared(progress,status) omp_throttle(1)
1143 for (y=0; y < (ssize_t) flip_image->rows; y++)
1145 register const Quantum
1154 if (status == MagickFalse)
1156 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1157 q=QueueCacheViewAuthenticPixels(flip_view,0,(ssize_t) (flip_image->rows-y-
1158 1),flip_image->columns,1,exception);
1159 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1164 for (x=0; x < (ssize_t) flip_image->columns; x++)
1169 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1178 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
1179 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
1180 flip_traits=GetPixelChannelMapTraits(flip_image,channel);
1181 if ((traits == UndefinedPixelTrait) ||
1182 (flip_traits == UndefinedPixelTrait))
1184 SetPixelChannel(flip_image,channel,p[i],q);
1186 p+=GetPixelChannels(image);
1187 q+=GetPixelChannels(flip_image);
1189 if (SyncCacheViewAuthenticPixels(flip_view,exception) == MagickFalse)
1191 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1196 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1197 #pragma omp critical (MagickCore_FlipImage)
1199 proceed=SetImageProgress(image,FlipImageTag,progress++,image->rows);
1200 if (proceed == MagickFalse)
1204 flip_view=DestroyCacheView(flip_view);
1205 image_view=DestroyCacheView(image_view);
1206 flip_image->type=image->type;
1207 if (page.height != 0)
1208 page.y=(ssize_t) (page.height-flip_image->rows-page.y);
1209 flip_image->page=page;
1210 if (status == MagickFalse)
1211 flip_image=DestroyImage(flip_image);
1216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1220 % F l o p I m a g e %
1224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1226 % FlopImage() creates a horizontal mirror image by reflecting the pixels
1227 % around the central y-axis.
1229 % The format of the FlopImage method is:
1231 % Image *FlopImage(const Image *image,ExceptionInfo *exception)
1233 % A description of each parameter follows:
1235 % o image: the image.
1237 % o exception: return any errors or warnings in this structure.
1240 MagickExport Image *FlopImage(const Image *image,ExceptionInfo *exception)
1242 #define FlopImageTag "Flop/Image"
1263 assert(image != (const Image *) NULL);
1264 assert(image->signature == MagickSignature);
1265 if (image->debug != MagickFalse)
1266 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1267 assert(exception != (ExceptionInfo *) NULL);
1268 assert(exception->signature == MagickSignature);
1269 flop_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1270 if (flop_image == (Image *) NULL)
1271 return((Image *) NULL);
1278 image_view=AcquireCacheView(image);
1279 flop_view=AcquireCacheView(flop_image);
1280 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1281 #pragma omp parallel for schedule(dynamic,4) shared(progress,status) omp_throttle(1)
1283 for (y=0; y < (ssize_t) flop_image->rows; y++)
1285 register const Quantum
1294 if (status == MagickFalse)
1296 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1297 q=QueueCacheViewAuthenticPixels(flop_view,0,y,flop_image->columns,1,
1299 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1304 q+=GetPixelChannels(flop_image)*flop_image->columns;
1305 for (x=0; x < (ssize_t) flop_image->columns; x++)
1310 q-=GetPixelChannels(flop_image);
1311 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1320 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
1321 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
1322 flop_traits=GetPixelChannelMapTraits(flop_image,channel);
1323 if ((traits == UndefinedPixelTrait) ||
1324 (flop_traits == UndefinedPixelTrait))
1326 SetPixelChannel(flop_image,channel,p[i],q);
1328 p+=GetPixelChannels(image);
1330 if (SyncCacheViewAuthenticPixels(flop_view,exception) == MagickFalse)
1332 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1337 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1338 #pragma omp critical (MagickCore_FlopImage)
1340 proceed=SetImageProgress(image,FlopImageTag,progress++,image->rows);
1341 if (proceed == MagickFalse)
1345 flop_view=DestroyCacheView(flop_view);
1346 image_view=DestroyCacheView(image_view);
1347 flop_image->type=image->type;
1348 if (page.width != 0)
1349 page.x=(ssize_t) (page.width-flop_image->columns-page.x);
1350 flop_image->page=page;
1351 if (status == MagickFalse)
1352 flop_image=DestroyImage(flop_image);
1357 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1361 % R o l l I m a g e %
1365 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1367 % RollImage() offsets an image as defined by x_offset and y_offset.
1369 % The format of the RollImage method is:
1371 % Image *RollImage(const Image *image,const ssize_t x_offset,
1372 % const ssize_t y_offset,ExceptionInfo *exception)
1374 % A description of each parameter follows:
1376 % o image: the image.
1378 % o x_offset: the number of columns to roll in the horizontal direction.
1380 % o y_offset: the number of rows to roll in the vertical direction.
1382 % o exception: return any errors or warnings in this structure.
1386 static inline MagickBooleanType CopyImageRegion(Image *destination,
1387 const Image *source,const size_t columns,const size_t rows,
1388 const ssize_t sx,const ssize_t sy,const ssize_t dx,const ssize_t dy,
1389 ExceptionInfo *exception)
1402 source_view=AcquireCacheView(source);
1403 destination_view=AcquireCacheView(destination);
1404 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1405 #pragma omp parallel for schedule(dynamic,4) shared(status)
1407 for (y=0; y < (ssize_t) rows; y++)
1412 register const Quantum
1424 if (status == MagickFalse)
1426 p=GetCacheViewVirtualPixels(source_view,sx,sy+y,columns,1,exception);
1427 q=GetCacheViewAuthenticPixels(destination_view,dx,dy+y,columns,1,exception);
1428 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1433 for (x=0; x < (ssize_t) columns; x++)
1438 for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
1447 source_traits=GetPixelChannelMapTraits(source,(PixelChannel) i);
1448 channel=GetPixelChannelMapChannel(source,(PixelChannel) i);
1449 destination_traits=GetPixelChannelMapTraits(destination,channel);
1450 if ((source_traits == UndefinedPixelTrait) ||
1451 (destination_traits == UndefinedPixelTrait))
1453 SetPixelChannel(destination,channel,p[i],q);
1455 p+=GetPixelChannels(source);
1456 q+=GetPixelChannels(destination);
1458 sync=SyncCacheViewAuthenticPixels(destination_view,exception);
1459 if (sync == MagickFalse)
1462 destination_view=DestroyCacheView(destination_view);
1463 source_view=DestroyCacheView(source_view);
1467 MagickExport Image *RollImage(const Image *image,const ssize_t x_offset,
1468 const ssize_t y_offset,ExceptionInfo *exception)
1470 #define RollImageTag "Roll/Image"
1482 Initialize roll image attributes.
1484 assert(image != (const Image *) NULL);
1485 assert(image->signature == MagickSignature);
1486 if (image->debug != MagickFalse)
1487 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1488 assert(exception != (ExceptionInfo *) NULL);
1489 assert(exception->signature == MagickSignature);
1490 roll_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1491 if (roll_image == (Image *) NULL)
1492 return((Image *) NULL);
1495 while (offset.x < 0)
1496 offset.x+=(ssize_t) image->columns;
1497 while (offset.x >= (ssize_t) image->columns)
1498 offset.x-=(ssize_t) image->columns;
1499 while (offset.y < 0)
1500 offset.y+=(ssize_t) image->rows;
1501 while (offset.y >= (ssize_t) image->rows)
1502 offset.y-=(ssize_t) image->rows;
1506 status=CopyImageRegion(roll_image,image,(size_t) offset.x,
1507 (size_t) offset.y,(ssize_t) image->columns-offset.x,(ssize_t) image->rows-
1508 offset.y,0,0,exception);
1509 (void) SetImageProgress(image,RollImageTag,0,3);
1510 status|=CopyImageRegion(roll_image,image,image->columns-offset.x,
1511 (size_t) offset.y,0,(ssize_t) image->rows-offset.y,offset.x,0,
1513 (void) SetImageProgress(image,RollImageTag,1,3);
1514 status|=CopyImageRegion(roll_image,image,(size_t) offset.x,image->rows-
1515 offset.y,(ssize_t) image->columns-offset.x,0,0,offset.y,exception);
1516 (void) SetImageProgress(image,RollImageTag,2,3);
1517 status|=CopyImageRegion(roll_image,image,image->columns-offset.x,image->rows-
1518 offset.y,0,0,offset.x,offset.y,exception);
1519 (void) SetImageProgress(image,RollImageTag,3,3);
1520 roll_image->type=image->type;
1521 if (status == MagickFalse)
1522 roll_image=DestroyImage(roll_image);
1527 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1531 % S h a v e I m a g e %
1535 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1537 % ShaveImage() shaves pixels from the image edges. It allocates the memory
1538 % necessary for the new Image structure and returns a pointer to the new
1541 % The format of the ShaveImage method is:
1543 % Image *ShaveImage(const Image *image,const RectangleInfo *shave_info,
1544 % ExceptionInfo *exception)
1546 % A description of each parameter follows:
1548 % o shave_image: Method ShaveImage returns a pointer to the shaved
1549 % image. A null image is returned if there is a memory shortage or
1550 % if the image width or height is zero.
1552 % o image: the image.
1554 % o shave_info: Specifies a pointer to a RectangleInfo which defines the
1555 % region of the image to crop.
1557 % o exception: return any errors or warnings in this structure.
1560 MagickExport Image *ShaveImage(const Image *image,
1561 const RectangleInfo *shave_info,ExceptionInfo *exception)
1569 assert(image != (const Image *) NULL);
1570 assert(image->signature == MagickSignature);
1571 if (image->debug != MagickFalse)
1572 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1573 if (((2*shave_info->width) >= image->columns) ||
1574 ((2*shave_info->height) >= image->rows))
1575 ThrowImageException(OptionWarning,"GeometryDoesNotContainImage");
1576 SetGeometry(image,&geometry);
1577 geometry.width-=2*shave_info->width;
1578 geometry.height-=2*shave_info->height;
1579 geometry.x=(ssize_t) shave_info->width+image->page.x;
1580 geometry.y=(ssize_t) shave_info->height+image->page.y;
1581 shave_image=CropImage(image,&geometry,exception);
1582 if (shave_image == (Image *) NULL)
1583 return((Image *) NULL);
1584 shave_image->page.width-=2*shave_info->width;
1585 shave_image->page.height-=2*shave_info->height;
1586 shave_image->page.x-=(ssize_t) shave_info->width;
1587 shave_image->page.y-=(ssize_t) shave_info->height;
1588 return(shave_image);
1592 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1596 % S p l i c e I m a g e %
1600 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1602 % SpliceImage() splices a solid color into the image as defined by the
1605 % The format of the SpliceImage method is:
1607 % Image *SpliceImage(const Image *image,const RectangleInfo *geometry,
1608 % ExceptionInfo *exception)
1610 % A description of each parameter follows:
1612 % o image: the image.
1614 % o geometry: Define the region of the image to splice with members
1615 % x, y, width, and height.
1617 % o exception: return any errors or warnings in this structure.
1620 MagickExport Image *SpliceImage(const Image *image,
1621 const RectangleInfo *geometry,ExceptionInfo *exception)
1623 #define SpliceImageTag "Splice/Image"
1645 Allocate splice image.
1647 assert(image != (const Image *) NULL);
1648 assert(image->signature == MagickSignature);
1649 if (image->debug != MagickFalse)
1650 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1651 assert(geometry != (const RectangleInfo *) NULL);
1652 assert(exception != (ExceptionInfo *) NULL);
1653 assert(exception->signature == MagickSignature);
1654 splice_geometry=(*geometry);
1655 splice_image=CloneImage(image,image->columns+splice_geometry.width,
1656 image->rows+splice_geometry.height,MagickTrue,exception);
1657 if (splice_image == (Image *) NULL)
1658 return((Image *) NULL);
1659 if (SetImageStorageClass(splice_image,DirectClass,exception) == MagickFalse)
1661 splice_image=DestroyImage(splice_image);
1662 return((Image *) NULL);
1664 (void) SetImageBackgroundColor(splice_image,exception);
1666 Respect image geometry.
1668 switch (image->gravity)
1671 case UndefinedGravity:
1672 case NorthWestGravity:
1676 splice_geometry.x+=(ssize_t) splice_geometry.width/2;
1679 case NorthEastGravity:
1681 splice_geometry.x+=(ssize_t) splice_geometry.width;
1686 splice_geometry.y+=(ssize_t) splice_geometry.width/2;
1692 splice_geometry.x+=(ssize_t) splice_geometry.width/2;
1693 splice_geometry.y+=(ssize_t) splice_geometry.height/2;
1698 splice_geometry.x+=(ssize_t) splice_geometry.width;
1699 splice_geometry.y+=(ssize_t) splice_geometry.height/2;
1702 case SouthWestGravity:
1704 splice_geometry.y+=(ssize_t) splice_geometry.height;
1709 splice_geometry.x+=(ssize_t) splice_geometry.width/2;
1710 splice_geometry.y+=(ssize_t) splice_geometry.height;
1713 case SouthEastGravity:
1715 splice_geometry.x+=(ssize_t) splice_geometry.width;
1716 splice_geometry.y+=(ssize_t) splice_geometry.height;
1725 image_view=AcquireCacheView(image);
1726 splice_view=AcquireCacheView(splice_image);
1727 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1728 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
1730 for (y=0; y < (ssize_t) splice_geometry.y; y++)
1732 register const Quantum
1741 if (status == MagickFalse)
1743 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1744 q=QueueCacheViewAuthenticPixels(splice_view,0,y,splice_image->columns,1,
1746 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1751 for (x=0; x < splice_geometry.x; x++)
1756 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1765 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
1766 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
1767 splice_traits=GetPixelChannelMapTraits(splice_image,channel);
1768 if ((traits == UndefinedPixelTrait) ||
1769 (splice_traits == UndefinedPixelTrait))
1771 SetPixelChannel(splice_image,channel,p[i],q);
1773 p+=GetPixelChannels(image);
1774 q+=GetPixelChannels(splice_image);
1776 for ( ; x < (ssize_t) (splice_geometry.x+splice_geometry.width); x++)
1777 q+=GetPixelChannels(splice_image);
1778 for ( ; x < (ssize_t) splice_image->columns; x++)
1783 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1792 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
1793 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
1794 splice_traits=GetPixelChannelMapTraits(splice_image,channel);
1795 if ((traits == UndefinedPixelTrait) ||
1796 (splice_traits == UndefinedPixelTrait))
1798 SetPixelChannel(splice_image,channel,p[i],q);
1800 p+=GetPixelChannels(image);
1801 q+=GetPixelChannels(splice_image);
1803 if (SyncCacheViewAuthenticPixels(splice_view,exception) == MagickFalse)
1805 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1810 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1811 #pragma omp critical (MagickCore_TransposeImage)
1813 proceed=SetImageProgress(image,SpliceImageTag,progress++,
1814 splice_image->rows);
1815 if (proceed == MagickFalse)
1819 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1820 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
1822 for (y=(ssize_t) (splice_geometry.y+splice_geometry.height);
1823 y < (ssize_t) splice_image->rows; y++)
1825 register const Quantum
1834 if (status == MagickFalse)
1836 p=GetCacheViewVirtualPixels(image_view,0,y-(ssize_t) splice_geometry.height,
1837 image->columns,1,exception);
1838 if ((y < 0) || (y >= (ssize_t) splice_image->rows))
1840 q=QueueCacheViewAuthenticPixels(splice_view,0,y,splice_image->columns,1,
1842 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1847 for (x=0; x < splice_geometry.x; x++)
1852 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1861 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
1862 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
1863 splice_traits=GetPixelChannelMapTraits(splice_image,channel);
1864 if ((traits == UndefinedPixelTrait) ||
1865 (splice_traits == UndefinedPixelTrait))
1867 SetPixelChannel(splice_image,channel,p[i],q);
1869 p+=GetPixelChannels(image);
1870 q+=GetPixelChannels(splice_image);
1872 for ( ; x < (ssize_t) (splice_geometry.x+splice_geometry.width); x++)
1873 q+=GetPixelChannels(splice_image);
1874 for ( ; x < (ssize_t) splice_image->columns; x++)
1879 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1888 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
1889 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
1890 splice_traits=GetPixelChannelMapTraits(splice_image,channel);
1891 if ((traits == UndefinedPixelTrait) ||
1892 (splice_traits == UndefinedPixelTrait))
1894 SetPixelChannel(splice_image,channel,p[i],q);
1896 p+=GetPixelChannels(image);
1897 q+=GetPixelChannels(splice_image);
1899 if (SyncCacheViewAuthenticPixels(splice_view,exception) == MagickFalse)
1901 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1906 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1907 #pragma omp critical (MagickCore_TransposeImage)
1909 proceed=SetImageProgress(image,SpliceImageTag,progress++,
1910 splice_image->rows);
1911 if (proceed == MagickFalse)
1915 splice_view=DestroyCacheView(splice_view);
1916 image_view=DestroyCacheView(image_view);
1917 if (status == MagickFalse)
1918 splice_image=DestroyImage(splice_image);
1919 return(splice_image);
1923 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1927 % T r a n s f o r m I m a g e %
1931 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1933 % TransformImage() is a convenience method that behaves like ResizeImage() or
1934 % CropImage() but accepts scaling and/or cropping information as a region
1935 % geometry specification. If the operation fails, the original image handle
1938 % This should only be used for single images.
1940 % This function destroys what it assumes to be a single image list.
1941 % If the input image is part of a larger list, all other images in that list
1942 % will be simply 'lost', not destroyed.
1944 % Also if the crop generates a list of images only the first image is resized.
1945 % And finally if the crop succeeds and the resize failed, you will get a
1946 % cropped image, as well as a 'false' or 'failed' report.
1948 % This function and should probably be depreciated in favor of direct calls
1949 % to CropImageToTiles() or ResizeImage(), as appropriate.
1951 % The format of the TransformImage method is:
1953 % MagickBooleanType TransformImage(Image **image,const char *crop_geometry,
1954 % const char *image_geometry,ExceptionInfo *exception)
1956 % A description of each parameter follows:
1958 % o image: the image The transformed image is returned as this parameter.
1960 % o crop_geometry: A crop geometry string. This geometry defines a
1961 % subregion of the image to crop.
1963 % o image_geometry: An image geometry string. This geometry defines the
1964 % final size of the image.
1966 % o exception: return any errors or warnings in this structure.
1969 MagickExport MagickBooleanType TransformImage(Image **image,
1970 const char *crop_geometry,const char *image_geometry,ExceptionInfo *exception)
1982 assert(image != (Image **) NULL);
1983 assert((*image)->signature == MagickSignature);
1984 if ((*image)->debug != MagickFalse)
1985 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1986 transform_image=(*image);
1987 if (crop_geometry != (const char *) NULL)
1993 Crop image to a user specified size.
1995 crop_image=CropImageToTiles(*image,crop_geometry,exception);
1996 if (crop_image == (Image *) NULL)
1997 transform_image=CloneImage(*image,0,0,MagickTrue,exception);
2000 transform_image=DestroyImage(transform_image);
2001 transform_image=GetFirstImageInList(crop_image);
2003 *image=transform_image;
2005 if (image_geometry == (const char *) NULL)
2009 Scale image to a user specified size.
2011 flags=ParseRegionGeometry(transform_image,image_geometry,&geometry,exception);
2013 if ((transform_image->columns == geometry.width) &&
2014 (transform_image->rows == geometry.height))
2016 resize_image=ResizeImage(transform_image,geometry.width,geometry.height,
2017 transform_image->filter,transform_image->blur,exception);
2018 if (resize_image == (Image *) NULL)
2019 return(MagickFalse);
2020 transform_image=DestroyImage(transform_image);
2021 transform_image=resize_image;
2022 *image=transform_image;
2027 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2031 % T r a n s f o r m I m a g e s %
2035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2037 % TransformImages() calls TransformImage() on each image of a sequence.
2039 % The format of the TransformImage method is:
2041 % MagickBooleanType TransformImages(Image **image,
2042 % const char *crop_geometry,const char *image_geometry,
2043 % ExceptionInfo *exception)
2045 % A description of each parameter follows:
2047 % o image: the image The transformed image is returned as this parameter.
2049 % o crop_geometry: A crop geometry string. This geometry defines a
2050 % subregion of the image to crop.
2052 % o image_geometry: An image geometry string. This geometry defines the
2053 % final size of the image.
2055 % o exception: return any errors or warnings in this structure.
2058 MagickExport MagickBooleanType TransformImages(Image **images,
2059 const char *crop_geometry,const char *image_geometry,ExceptionInfo *exception)
2072 assert(images != (Image **) NULL);
2073 assert((*images)->signature == MagickSignature);
2074 if ((*images)->debug != MagickFalse)
2075 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2076 (*images)->filename);
2077 image_list=ImageListToArray(*images,exception);
2078 if (image_list == (Image **) NULL)
2079 return(MagickFalse);
2081 transform_images=NewImageList();
2082 for (i=0; image_list[i] != (Image *) NULL; i++)
2084 image=image_list[i];
2085 status|=TransformImage(&image,crop_geometry,image_geometry,exception);
2086 AppendImageToList(&transform_images,image);
2088 *images=transform_images;
2089 image_list=(Image **) RelinquishMagickMemory(image_list);
2090 return(status != 0 ? MagickTrue : MagickFalse);
2094 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2098 % T r a n s p o s e I m a g e %
2102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2104 % TransposeImage() creates a horizontal mirror image by reflecting the pixels
2105 % around the central y-axis while rotating them by 90 degrees.
2107 % The format of the TransposeImage method is:
2109 % Image *TransposeImage(const Image *image,ExceptionInfo *exception)
2111 % A description of each parameter follows:
2113 % o image: the image.
2115 % o exception: return any errors or warnings in this structure.
2118 MagickExport Image *TransposeImage(const Image *image,ExceptionInfo *exception)
2120 #define TransposeImageTag "Transpose/Image"
2141 assert(image != (const Image *) NULL);
2142 assert(image->signature == MagickSignature);
2143 if (image->debug != MagickFalse)
2144 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2145 assert(exception != (ExceptionInfo *) NULL);
2146 assert(exception->signature == MagickSignature);
2147 transpose_image=CloneImage(image,image->rows,image->columns,MagickTrue,
2149 if (transpose_image == (Image *) NULL)
2150 return((Image *) NULL);
2156 image_view=AcquireCacheView(image);
2157 transpose_view=AcquireCacheView(transpose_image);
2158 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2159 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2161 for (y=0; y < (ssize_t) image->rows; y++)
2163 register const Quantum
2172 if (status == MagickFalse)
2174 p=GetCacheViewVirtualPixels(image_view,0,(ssize_t) image->rows-y-1,
2175 image->columns,1,exception);
2176 q=QueueCacheViewAuthenticPixels(transpose_view,(ssize_t) (image->rows-y-1),
2177 0,1,transpose_image->rows,exception);
2178 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2183 for (x=0; x < (ssize_t) image->columns; x++)
2188 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2197 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
2198 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
2199 transpose_traits=GetPixelChannelMapTraits(transpose_image,channel);
2200 if ((traits == UndefinedPixelTrait) ||
2201 (transpose_traits == UndefinedPixelTrait))
2203 SetPixelChannel(transpose_image,channel,p[i],q);
2205 p+=GetPixelChannels(image);
2206 q+=GetPixelChannels(transpose_image);
2208 if (SyncCacheViewAuthenticPixels(transpose_view,exception) == MagickFalse)
2210 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2215 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2216 #pragma omp critical (MagickCore_TransposeImage)
2218 proceed=SetImageProgress(image,TransposeImageTag,progress++,
2220 if (proceed == MagickFalse)
2224 transpose_view=DestroyCacheView(transpose_view);
2225 image_view=DestroyCacheView(image_view);
2226 transpose_image->type=image->type;
2227 page=transpose_image->page;
2228 Swap(page.width,page.height);
2229 Swap(page.x,page.y);
2230 transpose_image->page=page;
2231 if (status == MagickFalse)
2232 transpose_image=DestroyImage(transpose_image);
2233 return(transpose_image);
2237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2241 % T r a n s v e r s e I m a g e %
2245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2247 % TransverseImage() creates a vertical mirror image by reflecting the pixels
2248 % around the central x-axis while rotating them by 270 degrees.
2250 % The format of the TransverseImage method is:
2252 % Image *TransverseImage(const Image *image,ExceptionInfo *exception)
2254 % A description of each parameter follows:
2256 % o image: the image.
2258 % o exception: return any errors or warnings in this structure.
2261 MagickExport Image *TransverseImage(const Image *image,ExceptionInfo *exception)
2263 #define TransverseImageTag "Transverse/Image"
2284 assert(image != (const Image *) NULL);
2285 assert(image->signature == MagickSignature);
2286 if (image->debug != MagickFalse)
2287 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2288 assert(exception != (ExceptionInfo *) NULL);
2289 assert(exception->signature == MagickSignature);
2290 transverse_image=CloneImage(image,image->rows,image->columns,MagickTrue,
2292 if (transverse_image == (Image *) NULL)
2293 return((Image *) NULL);
2299 image_view=AcquireCacheView(image);
2300 transverse_view=AcquireCacheView(transverse_image);
2301 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2302 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2304 for (y=0; y < (ssize_t) image->rows; y++)
2309 register const Quantum
2318 if (status == MagickFalse)
2320 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
2321 q=QueueCacheViewAuthenticPixels(transverse_view,(ssize_t) (image->rows-y-1),
2322 0,1,transverse_image->rows,exception);
2323 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2328 q+=GetPixelChannels(transverse_image)*image->columns;
2329 for (x=0; x < (ssize_t) image->columns; x++)
2334 q-=GetPixelChannels(transverse_image);
2335 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2344 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
2345 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
2346 transverse_traits=GetPixelChannelMapTraits(transverse_image,channel);
2347 if ((traits == UndefinedPixelTrait) ||
2348 (transverse_traits == UndefinedPixelTrait))
2350 SetPixelChannel(transverse_image,channel,p[i],q);
2352 p+=GetPixelChannels(image);
2354 sync=SyncCacheViewAuthenticPixels(transverse_view,exception);
2355 if (sync == MagickFalse)
2357 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2362 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2363 #pragma omp critical (MagickCore_TransverseImage)
2365 proceed=SetImageProgress(image,TransverseImageTag,progress++,
2367 if (proceed == MagickFalse)
2371 transverse_view=DestroyCacheView(transverse_view);
2372 image_view=DestroyCacheView(image_view);
2373 transverse_image->type=image->type;
2374 page=transverse_image->page;
2375 Swap(page.width,page.height);
2376 Swap(page.x,page.y);
2377 if (page.width != 0)
2378 page.x=(ssize_t) (page.width-transverse_image->columns-page.x);
2379 if (page.height != 0)
2380 page.y=(ssize_t) (page.height-transverse_image->rows-page.y);
2381 transverse_image->page=page;
2382 if (status == MagickFalse)
2383 transverse_image=DestroyImage(transverse_image);
2384 return(transverse_image);
2388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2392 % T r i m I m a g e %
2396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2398 % TrimImage() trims pixels from the image edges. It allocates the memory
2399 % necessary for the new Image structure and returns a pointer to the new
2402 % The format of the TrimImage method is:
2404 % Image *TrimImage(const Image *image,ExceptionInfo *exception)
2406 % A description of each parameter follows:
2408 % o image: the image.
2410 % o exception: return any errors or warnings in this structure.
2413 MagickExport Image *TrimImage(const Image *image,ExceptionInfo *exception)
2418 assert(image != (const Image *) NULL);
2419 assert(image->signature == MagickSignature);
2420 if (image->debug != MagickFalse)
2421 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2422 geometry=GetImageBoundingBox(image,exception);
2423 if ((geometry.width == 0) || (geometry.height == 0))
2428 crop_image=CloneImage(image,1,1,MagickTrue,exception);
2429 if (crop_image == (Image *) NULL)
2430 return((Image *) NULL);
2431 crop_image->background_color.alpha=(Quantum) TransparentAlpha;
2432 (void) SetImageBackgroundColor(crop_image,exception);
2433 crop_image->page=image->page;
2434 crop_image->page.x=(-1);
2435 crop_image->page.y=(-1);
2438 geometry.x+=image->page.x;
2439 geometry.y+=image->page.y;
2440 return(CropImage(image,&geometry,exception));