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-2010 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 "magick/studio.h"
43 #include "magick/attribute.h"
44 #include "magick/cache.h"
45 #include "magick/cache-view.h"
46 #include "magick/color.h"
47 #include "magick/color-private.h"
48 #include "magick/colorspace-private.h"
49 #include "magick/composite.h"
50 #include "magick/draw.h"
51 #include "magick/effect.h"
52 #include "magick/exception.h"
53 #include "magick/exception-private.h"
54 #include "magick/geometry.h"
55 #include "magick/image.h"
56 #include "magick/memory_.h"
57 #include "magick/layer.h"
58 #include "magick/list.h"
59 #include "magick/monitor.h"
60 #include "magick/monitor-private.h"
61 #include "magick/pixel-private.h"
62 #include "magick/resource_.h"
63 #include "magick/resize.h"
64 #include "magick/statistic.h"
65 #include "magick/string_.h"
66 #include "magick/transform.h"
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 % ChopImage() removes a region of an image and collapses the image to occupy
80 % the removed portion.
82 % The format of the ChopImage method is:
84 % Image *ChopImage(const Image *image,const RectangleInfo *chop_info)
85 % ExceptionInfo *exception)
87 % A description of each parameter follows:
91 % o chop_info: Define the region of the image to chop.
93 % o exception: return any errors or warnings in this structure.
96 MagickExport Image *ChopImage(const Image *image,const RectangleInfo *chop_info,
97 ExceptionInfo *exception)
99 #define ChopImageTag "Chop/Image"
125 assert(image != (const Image *) NULL);
126 assert(image->signature == MagickSignature);
127 if (image->debug != MagickFalse)
128 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
129 assert(exception != (ExceptionInfo *) NULL);
130 assert(exception->signature == MagickSignature);
131 assert(chop_info != (RectangleInfo *) NULL);
132 if (((chop_info->x+(long) chop_info->width) < 0) ||
133 ((chop_info->y+(long) chop_info->height) < 0) ||
134 (chop_info->x > (long) image->columns) ||
135 (chop_info->y > (long) image->rows))
136 ThrowImageException(OptionWarning,"GeometryDoesNotContainImage");
138 if ((extent.x+(long) extent.width) > (long) image->columns)
139 extent.width=(unsigned long) ((long) image->columns-extent.x);
140 if ((extent.y+(long) extent.height) > (long) image->rows)
141 extent.height=(unsigned long) ((long) image->rows-extent.y);
144 extent.width-=(unsigned long) (-extent.x);
149 extent.height-=(unsigned long) (-extent.y);
152 chop_image=CloneImage(image,image->columns-extent.width,image->rows-
153 extent.height,MagickTrue,exception);
154 if (chop_image == (Image *) NULL)
155 return((Image *) NULL);
162 image_view=AcquireCacheView(image);
163 chop_view=AcquireCacheView(chop_image);
164 #if defined(MAGICKCORE_OPENMP_SUPPORT)
165 #pragma omp parallel for schedule(static) shared(status)
167 for (y=0; y < (long) extent.y; y++)
169 register const PixelPacket
173 *restrict chop_indexes,
182 if (status == MagickFalse)
184 p=GetCacheViewVirtualPixels(image_view,0,i++,image->columns,1,exception);
185 q=QueueCacheViewAuthenticPixels(chop_view,0,j++,chop_image->columns,1,
187 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
192 indexes=GetCacheViewAuthenticIndexQueue(image_view);
193 chop_indexes=GetCacheViewAuthenticIndexQueue(chop_view);
194 for (x=0; x < (long) image->columns; x++)
196 if ((x < extent.x) || (x >= (long) (extent.x+extent.width)))
199 if (indexes != (IndexPacket *) NULL)
201 if (chop_indexes != (IndexPacket *) NULL)
202 *chop_indexes++=indexes[x];
208 if (SyncCacheViewAuthenticPixels(chop_view,exception) == MagickFalse)
210 proceed=SetImageProgress(image,ChopImageTag,y,chop_image->rows);
211 if (proceed == MagickFalse)
218 #if defined(MAGICKCORE_OPENMP_SUPPORT)
219 #pragma omp parallel for schedule(static) shared(status)
221 for (y=0; y < (long) (image->rows-(extent.y+extent.height)); y++)
223 register const PixelPacket
227 *restrict chop_indexes,
236 if (status == MagickFalse)
238 p=GetCacheViewVirtualPixels(image_view,0,i++,image->columns,1,exception);
239 q=QueueCacheViewAuthenticPixels(chop_view,0,j++,chop_image->columns,1,
241 if ((p == (PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
246 indexes=GetCacheViewAuthenticIndexQueue(image_view);
247 chop_indexes=GetCacheViewAuthenticIndexQueue(chop_view);
248 for (x=0; x < (long) image->columns; x++)
250 if ((x < extent.x) || (x >= (long) (extent.x+extent.width)))
253 if (indexes != (IndexPacket *) NULL)
255 if (chop_indexes != (IndexPacket *) NULL)
256 *chop_indexes++=indexes[x];
262 if (SyncCacheViewAuthenticPixels(chop_view,exception) == MagickFalse)
264 proceed=SetImageProgress(image,ChopImageTag,y,chop_image->rows);
265 if (proceed == MagickFalse)
268 chop_view=DestroyCacheView(chop_view);
269 image_view=DestroyCacheView(image_view);
270 chop_image->type=image->type;
275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
279 + C o n s o l i d a t e C M Y K I m a g e %
283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285 % ConsolidateCMYKImage() consolidates separate C, M, Y, and K planes into a
288 % The format of the ConsolidateCMYKImage method is:
290 % Image *ConsolidateCMYKImage(const Image *image,ExceptionInfo *exception)
292 % A description of each parameter follows:
294 % o image: the image sequence.
296 % o exception: return any errors or warnings in this structure.
299 MagickExport Image *ConsolidateCMYKImages(const Image *images,
300 ExceptionInfo *exception)
313 Consolidate separate C, M, Y, and K planes into a single image.
315 assert(images != (Image *) NULL);
316 assert(images->signature == MagickSignature);
317 if (images->debug != MagickFalse)
318 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
319 assert(exception != (ExceptionInfo *) NULL);
320 assert(exception->signature == MagickSignature);
321 cmyk_images=NewImageList();
322 for (i=0; i < (long) GetImageListLength(images); i+=4)
324 cmyk_image=CloneImage(images,images->columns,images->rows,MagickTrue,
326 if (cmyk_image == (Image *) NULL)
328 if (SetImageStorageClass(cmyk_image,DirectClass) == MagickFalse)
330 (void) SetImageColorspace(cmyk_image,CMYKColorspace);
331 for (y=0; y < (long) images->rows; y++)
333 register const PixelPacket
342 p=GetVirtualPixels(images,0,y,images->columns,1,exception);
343 q=QueueAuthenticPixels(cmyk_image,0,y,cmyk_image->columns,1,exception);
344 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
346 for (x=0; x < (long) images->columns; x++)
348 q->red=(Quantum) (QuantumRange-PixelIntensityToQuantum(p));
352 if (SyncAuthenticPixels(cmyk_image,exception) == MagickFalse)
355 images=GetNextImageInList(images);
356 if (images == (Image *) NULL)
358 for (y=0; y < (long) images->rows; y++)
360 register const PixelPacket
369 p=GetVirtualPixels(images,0,y,images->columns,1,exception);
370 q=GetAuthenticPixels(cmyk_image,0,y,cmyk_image->columns,1,exception);
371 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
373 for (x=0; x < (long) images->columns; x++)
375 q->green=(Quantum) (QuantumRange-PixelIntensityToQuantum(p));
379 if (SyncAuthenticPixels(cmyk_image,exception) == MagickFalse)
382 images=GetNextImageInList(images);
383 if (images == (Image *) NULL)
385 for (y=0; y < (long) images->rows; y++)
387 register const PixelPacket
396 p=GetVirtualPixels(images,0,y,images->columns,1,exception);
397 q=GetAuthenticPixels(cmyk_image,0,y,cmyk_image->columns,1,exception);
398 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
400 for (x=0; x < (long) images->columns; x++)
402 q->blue=(Quantum) (QuantumRange-PixelIntensityToQuantum(p));
406 if (SyncAuthenticPixels(cmyk_image,exception) == MagickFalse)
409 images=GetNextImageInList(images);
410 if (images == (Image *) NULL)
412 for (y=0; y < (long) images->rows; y++)
414 register const PixelPacket
426 p=GetVirtualPixels(images,0,y,images->columns,1,exception);
427 q=GetAuthenticPixels(cmyk_image,0,y,cmyk_image->columns,1,exception);
428 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
430 indexes=GetAuthenticIndexQueue(cmyk_image);
431 for (x=0; x < (long) images->columns; x++)
433 indexes[x]=(IndexPacket) (QuantumRange-PixelIntensityToQuantum(p));
436 if (SyncAuthenticPixels(cmyk_image,exception) == MagickFalse)
439 AppendImageToList(&cmyk_images,cmyk_image);
440 images=GetNextImageInList(images);
441 if (images == (Image *) NULL)
448 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
452 % C r o p I m a g e %
456 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
458 % CropImage() extracts a region of the image starting at the offset defined
461 % The format of the CropImage method is:
463 % Image *CropImage(const Image *image,const RectangleInfo *geometry,
464 % ExceptionInfo *exception)
466 % A description of each parameter follows:
468 % o image: the image.
470 % o geometry: Define the region of the image to crop with members
471 % x, y, width, and height.
473 % o exception: return any errors or warnings in this structure.
476 MagickExport Image *CropImage(const Image *image,const RectangleInfo *geometry,
477 ExceptionInfo *exception)
479 #define CropImageTag "Crop/Image"
502 assert(image != (const Image *) NULL);
503 assert(image->signature == MagickSignature);
504 if (image->debug != MagickFalse)
505 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
506 assert(geometry != (const RectangleInfo *) NULL);
507 assert(exception != (ExceptionInfo *) NULL);
508 assert(exception->signature == MagickSignature);
509 bounding_box=image->page;
510 if ((bounding_box.width == 0) || (bounding_box.height == 0))
512 bounding_box.width=image->columns;
513 bounding_box.height=image->rows;
517 page.width=bounding_box.width;
518 if (page.height == 0)
519 page.height=bounding_box.height;
520 if (((bounding_box.x-page.x) >= (long) page.width) ||
521 ((bounding_box.y-page.y) >= (long) page.height) ||
522 ((page.x-bounding_box.x) > (long) image->columns) ||
523 ((page.y-bounding_box.y) > (long) image->rows))
526 Crop is not within virtual canvas, return 1 pixel transparent image.
528 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
529 "GeometryDoesNotContainImage","`%s'",image->filename);
530 crop_image=CloneImage(image,1,1,MagickTrue,exception);
531 if (crop_image == (Image *) NULL)
532 return((Image *) NULL);
533 crop_image->background_color.opacity=(Quantum) TransparentOpacity;
534 (void) SetImageBackgroundColor(crop_image);
535 crop_image->page=bounding_box;
536 crop_image->page.x=(-1);
537 crop_image->page.y=(-1);
538 if (crop_image->dispose == BackgroundDispose)
539 crop_image->dispose=NoneDispose;
542 if ((page.x < 0) && (bounding_box.x >= 0))
544 page.width+=page.x-bounding_box.x;
549 page.width-=bounding_box.x-page.x;
550 page.x-=bounding_box.x;
554 if ((page.y < 0) && (bounding_box.y >= 0))
556 page.height+=page.y-bounding_box.y;
561 page.height-=bounding_box.y-page.y;
562 page.y-=bounding_box.y;
566 if ((unsigned long) (page.x+page.width) > image->columns)
567 page.width=image->columns-page.x;
568 if (geometry->width != 0)
569 if (page.width > geometry->width)
570 page.width=geometry->width;
571 if ((unsigned long) (page.y+page.height) > image->rows)
572 page.height=image->rows-page.y;
573 if (geometry->height != 0)
574 if (page.height > geometry->height)
575 page.height=geometry->height;
576 bounding_box.x+=page.x;
577 bounding_box.y+=page.y;
578 if ((page.width == 0) || (page.height == 0))
580 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
581 "GeometryDoesNotContainImage","`%s'",image->filename);
582 return((Image *) NULL);
585 Initialize crop image attributes.
587 crop_image=CloneImage(image,page.width,page.height,MagickTrue,exception);
588 if (crop_image == (Image *) NULL)
589 return((Image *) NULL);
590 crop_image->page.width=image->page.width;
591 crop_image->page.height=image->page.height;
592 if (((long) (bounding_box.x+bounding_box.width) > (long) image->page.width) ||
593 ((long) (bounding_box.y+bounding_box.height) > (long) image->page.height))
595 crop_image->page.width=bounding_box.width;
596 crop_image->page.height=bounding_box.height;
598 crop_image->page.x=bounding_box.x;
599 crop_image->page.y=bounding_box.y;
605 image_view=AcquireCacheView(image);
606 crop_view=AcquireCacheView(crop_image);
607 #if defined(MAGICKCORE_OPENMP_SUPPORT)
608 #pragma omp parallel for schedule(static) shared(progress,status)
610 for (y=0; y < (long) crop_image->rows; y++)
612 register const IndexPacket
615 register const PixelPacket
619 *restrict crop_indexes;
624 if (status == MagickFalse)
626 p=GetCacheViewVirtualPixels(image_view,page.x,page.y+y,crop_image->columns,
628 q=QueueCacheViewAuthenticPixels(crop_view,0,y,crop_image->columns,1,
630 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
635 (void) CopyMagickMemory(q,p,(size_t) crop_image->columns*sizeof(*q));
636 indexes=GetCacheViewVirtualIndexQueue(image_view);
637 if (indexes != (IndexPacket *) NULL)
639 crop_indexes=GetCacheViewAuthenticIndexQueue(crop_view);
640 if (crop_indexes != (IndexPacket *) NULL)
641 (void) CopyMagickMemory(crop_indexes,indexes,(size_t)
642 crop_image->columns*sizeof(*crop_indexes));
644 if (SyncCacheViewAuthenticPixels(crop_view,exception) == MagickFalse)
646 if (image->progress_monitor != (MagickProgressMonitor) NULL)
651 #if defined(MAGICKCORE_OPENMP_SUPPORT)
652 #pragma omp critical (MagickCore_CropImage)
654 proceed=SetImageProgress(image,CropImageTag,progress++,image->rows);
655 if (proceed == MagickFalse)
659 crop_view=DestroyCacheView(crop_view);
660 image_view=DestroyCacheView(image_view);
661 crop_image->type=image->type;
662 if (status == MagickFalse)
663 crop_image=DestroyImage(crop_image);
668 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
672 % E x c e r p t I m a g e %
676 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
678 % ExcerptImage() returns a excerpt of the image as defined by the geometry.
680 % The format of the ExcerptImage method is:
682 % Image *ExcerptImage(const Image *image,const RectangleInfo *geometry,
683 % ExceptionInfo *exception)
685 % A description of each parameter follows:
687 % o image: the image.
689 % o geometry: Define the region of the image to extend with members
690 % x, y, width, and height.
692 % o exception: return any errors or warnings in this structure.
695 MagickExport Image *ExcerptImage(const Image *image,
696 const RectangleInfo *geometry,ExceptionInfo *exception)
698 #define ExcerptImageTag "Excerpt/Image"
715 Allocate excerpt image.
717 assert(image != (const Image *) NULL);
718 assert(image->signature == MagickSignature);
719 if (image->debug != MagickFalse)
720 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
721 assert(geometry != (const RectangleInfo *) NULL);
722 assert(exception != (ExceptionInfo *) NULL);
723 assert(exception->signature == MagickSignature);
724 excerpt_image=CloneImage(image,geometry->width,geometry->height,MagickTrue,
726 if (excerpt_image == (Image *) NULL)
727 return((Image *) NULL);
733 image_view=AcquireCacheView(image);
734 excerpt_view=AcquireCacheView(excerpt_image);
735 #if defined(MAGICKCORE_OPENMP_SUPPORT)
736 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
738 for (y=0; y < (long) excerpt_image->rows; y++)
740 register const PixelPacket
744 *restrict excerpt_indexes,
750 if (status == MagickFalse)
752 p=GetCacheViewVirtualPixels(image_view,geometry->x,geometry->y+y,
753 geometry->width,1,exception);
754 q=GetCacheViewAuthenticPixels(excerpt_view,0,y,excerpt_image->columns,1,
756 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
761 (void) CopyMagickMemory(q,p,(size_t) excerpt_image->columns*sizeof(*q));
762 indexes=GetCacheViewAuthenticIndexQueue(image_view);
763 if (indexes != (IndexPacket *) NULL)
765 excerpt_indexes=GetCacheViewAuthenticIndexQueue(excerpt_view);
766 if (excerpt_indexes != (IndexPacket *) NULL)
767 (void) CopyMagickMemory(excerpt_indexes,indexes,(size_t)
768 excerpt_image->columns*sizeof(*excerpt_indexes));
770 if (SyncCacheViewAuthenticPixels(excerpt_view,exception) == MagickFalse)
772 if (image->progress_monitor != (MagickProgressMonitor) NULL)
777 #if defined(MAGICKCORE_OPENMP_SUPPORT)
778 #pragma omp critical (MagickCore_ExcerptImage)
780 proceed=SetImageProgress(image,ExcerptImageTag,progress++,image->rows);
781 if (proceed == MagickFalse)
785 excerpt_view=DestroyCacheView(excerpt_view);
786 image_view=DestroyCacheView(image_view);
787 excerpt_image->type=image->type;
788 if (status == MagickFalse)
789 excerpt_image=DestroyImage(excerpt_image);
790 return(excerpt_image);
794 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
798 % E x t e n t I m a g e %
802 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
804 % ExtentImage() extends the image as defined by the geometry, gravity, and
805 % image background color. Set the (x,y) offset of the geometry to move the
806 % original image relative to the extended image.
808 % The format of the ExtentImage method is:
810 % Image *ExtentImage(const Image *image,const RectangleInfo *geometry,
811 % ExceptionInfo *exception)
813 % A description of each parameter follows:
815 % o image: the image.
817 % o geometry: Define the region of the image to extend with members
818 % x, y, width, and height.
820 % o exception: return any errors or warnings in this structure.
823 MagickExport Image *ExtentImage(const Image *image,
824 const RectangleInfo *geometry,ExceptionInfo *exception)
830 Allocate extent image.
832 assert(image != (const Image *) NULL);
833 assert(image->signature == MagickSignature);
834 if (image->debug != MagickFalse)
835 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
836 assert(geometry != (const RectangleInfo *) NULL);
837 assert(exception != (ExceptionInfo *) NULL);
838 assert(exception->signature == MagickSignature);
839 extent_image=CloneImage(image,geometry->width,geometry->height,MagickTrue,
841 if (extent_image == (Image *) NULL)
842 return((Image *) NULL);
843 if (SetImageStorageClass(extent_image,DirectClass) == MagickFalse)
845 InheritException(exception,&extent_image->exception);
846 extent_image=DestroyImage(extent_image);
847 return((Image *) NULL);
849 if (extent_image->background_color.opacity != OpaqueOpacity)
850 extent_image->matte=MagickTrue;
851 (void) SetImageBackgroundColor(extent_image);
852 (void) CompositeImage(extent_image,image->compose,image,geometry->x,
854 return(extent_image);
858 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
862 % F l i p I m a g e %
866 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
868 % FlipImage() creates a vertical mirror image by reflecting the pixels
869 % around the central x-axis.
871 % The format of the FlipImage method is:
873 % Image *FlipImage(const Image *image,ExceptionInfo *exception)
875 % A description of each parameter follows:
877 % o image: the image.
879 % o exception: return any errors or warnings in this structure.
882 MagickExport Image *FlipImage(const Image *image,ExceptionInfo *exception)
884 #define FlipImageTag "Flip/Image"
900 assert(image != (const Image *) NULL);
901 assert(image->signature == MagickSignature);
902 if (image->debug != MagickFalse)
903 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
904 assert(exception != (ExceptionInfo *) NULL);
905 assert(exception->signature == MagickSignature);
906 flip_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
907 if (flip_image == (Image *) NULL)
908 return((Image *) NULL);
914 image_view=AcquireCacheView(image);
915 flip_view=AcquireCacheView(flip_image);
916 #if defined(MAGICKCORE_OPENMP_SUPPORT)
917 #pragma omp parallel for schedule(static) shared(progress,status)
919 for (y=0; y < (long) flip_image->rows; y++)
921 register const IndexPacket
924 register const PixelPacket
928 *restrict flip_indexes;
933 if (status == MagickFalse)
935 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
936 q=QueueCacheViewAuthenticPixels(flip_view,0,(long) (flip_image->rows-y-1),
937 flip_image->columns,1,exception);
938 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
943 (void) CopyMagickMemory(q,p,(size_t) image->columns*sizeof(*q));
944 indexes=GetCacheViewVirtualIndexQueue(image_view);
945 if (indexes != (const IndexPacket *) NULL)
947 flip_indexes=GetCacheViewAuthenticIndexQueue(flip_view);
948 if (flip_indexes != (IndexPacket *) NULL)
949 (void) CopyMagickMemory(flip_indexes,indexes,(size_t) image->columns*
950 sizeof(*flip_indexes));
952 if (SyncCacheViewAuthenticPixels(flip_view,exception) == MagickFalse)
954 if (image->progress_monitor != (MagickProgressMonitor) NULL)
959 #if defined(MAGICKCORE_OPENMP_SUPPORT)
960 #pragma omp critical (MagickCore_FlipImage)
962 proceed=SetImageProgress(image,FlipImageTag,progress++,image->rows);
963 if (proceed == MagickFalse)
967 flip_view=DestroyCacheView(flip_view);
968 image_view=DestroyCacheView(image_view);
969 flip_image->type=image->type;
970 if (status == MagickFalse)
971 flip_image=DestroyImage(flip_image);
976 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
980 % F l o p I m a g e %
984 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
986 % FlopImage() creates a horizontal mirror image by reflecting the pixels
987 % around the central y-axis.
989 % The format of the FlopImage method is:
991 % Image *FlopImage(const Image *image,ExceptionInfo *exception)
993 % A description of each parameter follows:
995 % o image: the image.
997 % o exception: return any errors or warnings in this structure.
1000 MagickExport Image *FlopImage(const Image *image,ExceptionInfo *exception)
1002 #define FlopImageTag "Flop/Image"
1018 assert(image != (const Image *) NULL);
1019 assert(image->signature == MagickSignature);
1020 if (image->debug != MagickFalse)
1021 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1022 assert(exception != (ExceptionInfo *) NULL);
1023 assert(exception->signature == MagickSignature);
1024 flop_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1025 if (flop_image == (Image *) NULL)
1026 return((Image *) NULL);
1032 image_view=AcquireCacheView(image);
1033 flop_view=AcquireCacheView(flop_image);
1034 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1035 #pragma omp parallel for schedule(static) shared(progress,status)
1037 for (y=0; y < (long) flop_image->rows; y++)
1039 register const IndexPacket
1042 register const PixelPacket
1045 register IndexPacket
1046 *restrict flop_indexes;
1051 register PixelPacket
1054 if (status == MagickFalse)
1056 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1057 q=QueueCacheViewAuthenticPixels(flop_view,0,y,flop_image->columns,1,
1059 if ((p == (PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
1064 q+=flop_image->columns;
1065 indexes=GetCacheViewVirtualIndexQueue(image_view);
1066 flop_indexes=GetCacheViewAuthenticIndexQueue(flop_view);
1067 for (x=0; x < (long) flop_image->columns; x++)
1070 if ((indexes != (const IndexPacket *) NULL) &&
1071 (flop_indexes != (IndexPacket *) NULL))
1072 flop_indexes[flop_image->columns-x-1]=indexes[x];
1074 if (SyncCacheViewAuthenticPixels(flop_view,exception) == MagickFalse)
1076 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1081 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1082 #pragma omp critical (MagickCore_FlopImage)
1084 proceed=SetImageProgress(image,FlopImageTag,progress++,image->rows);
1085 if (proceed == MagickFalse)
1089 flop_view=DestroyCacheView(flop_view);
1090 image_view=DestroyCacheView(image_view);
1091 flop_image->type=image->type;
1092 if (status == MagickFalse)
1093 flop_image=DestroyImage(flop_image);
1098 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1102 % R o l l I m a g e %
1106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1108 % RollImage() offsets an image as defined by x_offset and y_offset.
1110 % The format of the RollImage method is:
1112 % Image *RollImage(const Image *image,const long x_offset,
1113 % const long y_offset,ExceptionInfo *exception)
1115 % A description of each parameter follows:
1117 % o image: the image.
1119 % o x_offset: the number of columns to roll in the horizontal direction.
1121 % o y_offset: the number of rows to roll in the vertical direction.
1123 % o exception: return any errors or warnings in this structure.
1127 static inline MagickBooleanType CopyImageRegion(Image *destination,
1128 const Image *source,const unsigned long columns,const unsigned long rows,
1129 const long sx,const long sy,const long dx,const long dy,
1130 ExceptionInfo *exception)
1143 source_view=AcquireCacheView(source);
1144 destination_view=AcquireCacheView(destination);
1145 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1146 #pragma omp parallel for schedule(dynamic,4) shared(status)
1148 for (y=0; y < (long) rows; y++)
1153 register const PixelPacket
1156 register IndexPacket
1158 *restrict destination_indexes;
1163 register PixelPacket
1169 if (status == MagickFalse)
1171 p=GetCacheViewVirtualPixels(source_view,sx,sy+y,columns,1,exception);
1172 q=GetCacheViewAuthenticPixels(destination_view,dx,dy+y,columns,1,exception);
1173 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
1178 indexes=GetCacheViewAuthenticIndexQueue(source_view);
1179 for (x=0; x < (long) columns; x++)
1181 if (indexes != (IndexPacket *) NULL)
1183 destination_indexes=GetCacheViewAuthenticIndexQueue(destination_view);
1184 for (x=0; x < (long) columns; x++)
1185 destination_indexes[x]=indexes[x];
1187 sync=SyncCacheViewAuthenticPixels(destination_view,exception);
1188 if (sync == MagickFalse)
1191 destination_view=DestroyCacheView(destination_view);
1192 source_view=DestroyCacheView(source_view);
1196 MagickExport Image *RollImage(const Image *image,const long x_offset,
1197 const long y_offset,ExceptionInfo *exception)
1199 #define RollImageTag "Roll/Image"
1211 Initialize roll image attributes.
1213 assert(image != (const Image *) NULL);
1214 assert(image->signature == MagickSignature);
1215 if (image->debug != MagickFalse)
1216 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1217 assert(exception != (ExceptionInfo *) NULL);
1218 assert(exception->signature == MagickSignature);
1219 roll_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1220 if (roll_image == (Image *) NULL)
1221 return((Image *) NULL);
1224 while (offset.x < 0)
1225 offset.x+=image->columns;
1226 while (offset.x >= (long) image->columns)
1227 offset.x-=image->columns;
1228 while (offset.y < 0)
1229 offset.y+=image->rows;
1230 while (offset.y >= (long) image->rows)
1231 offset.y-=image->rows;
1235 status=CopyImageRegion(roll_image,image,(unsigned long) offset.x,
1236 (unsigned long) offset.y,(long) image->columns-offset.x,(long) image->rows-
1237 offset.y,0,0,exception);
1238 (void) SetImageProgress(image,RollImageTag,0,3);
1239 status|=CopyImageRegion(roll_image,image,image->columns-offset.x,
1240 (unsigned long) offset.y,0,(long) image->rows-offset.y,offset.x,0,
1242 (void) SetImageProgress(image,RollImageTag,1,3);
1243 status|=CopyImageRegion(roll_image,image,(unsigned long) offset.x,image->rows-
1244 offset.y,(long) image->columns-offset.x,0,0,offset.y,exception);
1245 (void) SetImageProgress(image,RollImageTag,2,3);
1246 status|=CopyImageRegion(roll_image,image,image->columns-offset.x,image->rows-
1247 offset.y,0,0,offset.x,offset.y,exception);
1248 (void) SetImageProgress(image,RollImageTag,3,3);
1249 roll_image->type=image->type;
1250 if (status == MagickFalse)
1251 roll_image=DestroyImage(roll_image);
1256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1260 % S h a v e I m a g e %
1264 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1266 % ShaveImage() shaves pixels from the image edges. It allocates the memory
1267 % necessary for the new Image structure and returns a pointer to the new
1270 % The format of the ShaveImage method is:
1272 % Image *ShaveImage(const Image *image,const RectangleInfo *shave_info,
1273 % ExceptionInfo *exception)
1275 % A description of each parameter follows:
1277 % o shave_image: Method ShaveImage returns a pointer to the shaved
1278 % image. A null image is returned if there is a memory shortage or
1279 % if the image width or height is zero.
1281 % o image: the image.
1283 % o shave_info: Specifies a pointer to a RectangleInfo which defines the
1284 % region of the image to crop.
1286 % o exception: return any errors or warnings in this structure.
1289 MagickExport Image *ShaveImage(const Image *image,
1290 const RectangleInfo *shave_info,ExceptionInfo *exception)
1298 assert(image != (const Image *) NULL);
1299 assert(image->signature == MagickSignature);
1300 if (image->debug != MagickFalse)
1301 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1302 if (((2*shave_info->width) >= image->columns) ||
1303 ((2*shave_info->height) >= image->rows))
1304 ThrowImageException(OptionWarning,"GeometryDoesNotContainImage");
1305 SetGeometry(image,&geometry);
1306 geometry.width-=2*shave_info->width;
1307 geometry.height-=2*shave_info->height;
1308 geometry.x=(long) shave_info->width+image->page.x;
1309 geometry.y=(long) shave_info->height+image->page.y;
1310 shave_image=CropImage(image,&geometry,exception);
1311 if (shave_image == (Image *) NULL)
1312 return((Image *) NULL);
1313 shave_image->page.width-=2*shave_info->width;
1314 shave_image->page.height-=2*shave_info->height;
1315 shave_image->page.x-=shave_info->width;
1316 shave_image->page.y-=shave_info->height;
1317 return(shave_image);
1321 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1325 % S p l i c e I m a g e %
1329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1331 % SpliceImage() splices a solid color into the image as defined by the
1334 % The format of the SpliceImage method is:
1336 % Image *SpliceImage(const Image *image,const RectangleInfo *geometry,
1337 % ExceptionInfo *exception)
1339 % A description of each parameter follows:
1341 % o image: the image.
1343 % o geometry: Define the region of the image to splice with members
1344 % x, y, width, and height.
1346 % o exception: return any errors or warnings in this structure.
1349 MagickExport Image *SpliceImage(const Image *image,
1350 const RectangleInfo *geometry,ExceptionInfo *exception)
1352 #define SpliceImageTag "Splice/Image"
1376 Allocate splice image.
1378 assert(image != (const Image *) NULL);
1379 assert(image->signature == MagickSignature);
1380 if (image->debug != MagickFalse)
1381 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1382 assert(geometry != (const RectangleInfo *) NULL);
1383 assert(exception != (ExceptionInfo *) NULL);
1384 assert(exception->signature == MagickSignature);
1385 splice_geometry=(*geometry);
1386 splice_image=CloneImage(image,image->columns+splice_geometry.width,
1387 image->rows+splice_geometry.height,MagickTrue,exception);
1388 if (splice_image == (Image *) NULL)
1389 return((Image *) NULL);
1390 if (SetImageStorageClass(splice_image,DirectClass) == MagickFalse)
1392 InheritException(exception,&splice_image->exception);
1393 splice_image=DestroyImage(splice_image);
1394 return((Image *) NULL);
1396 (void) SetImageBackgroundColor(splice_image);
1398 Respect image geometry.
1400 switch (image->gravity)
1403 case UndefinedGravity:
1404 case NorthWestGravity:
1408 splice_geometry.x+=splice_geometry.width/2;
1411 case NorthEastGravity:
1413 splice_geometry.x+=splice_geometry.width;
1418 splice_geometry.y+=splice_geometry.width/2;
1424 splice_geometry.x+=splice_geometry.width/2;
1425 splice_geometry.y+=splice_geometry.height/2;
1430 splice_geometry.x+=splice_geometry.width;
1431 splice_geometry.y+=splice_geometry.height/2;
1434 case SouthWestGravity:
1436 splice_geometry.y+=splice_geometry.height;
1441 splice_geometry.x+=splice_geometry.width/2;
1442 splice_geometry.y+=splice_geometry.height;
1445 case SouthEastGravity:
1447 splice_geometry.x+=splice_geometry.width;
1448 splice_geometry.y+=splice_geometry.height;
1458 image_view=AcquireCacheView(image);
1459 splice_view=AcquireCacheView(splice_image);
1460 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1461 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
1463 for (y=0; y < (long) splice_geometry.y; y++)
1465 register const PixelPacket
1468 register IndexPacket
1470 *restrict splice_indexes;
1475 register PixelPacket
1478 if (status == MagickFalse)
1480 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1481 q=QueueCacheViewAuthenticPixels(splice_view,0,y,splice_image->columns,1,
1483 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
1488 indexes=GetCacheViewAuthenticIndexQueue(image_view);
1489 splice_indexes=GetCacheViewAuthenticIndexQueue(splice_view);
1490 for (x=0; x < splice_geometry.x; x++)
1492 SetRedPixelComponent(q,GetRedPixelComponent(p));
1493 SetGreenPixelComponent(q,GetGreenPixelComponent(p));
1494 SetBluePixelComponent(q,GetBluePixelComponent(p));
1495 SetOpacityPixelComponent(q,OpaqueOpacity);
1496 if (image->matte != MagickFalse)
1497 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
1498 if (image->colorspace == CMYKColorspace)
1499 splice_indexes[x]=(*indexes++);
1503 for ( ; x < (long) (splice_geometry.x+splice_geometry.width); x++)
1505 for ( ; x < (long) splice_image->columns; x++)
1507 SetRedPixelComponent(q,GetRedPixelComponent(p));
1508 SetGreenPixelComponent(q,GetGreenPixelComponent(p));
1509 SetBluePixelComponent(q,GetBluePixelComponent(p));
1510 SetOpacityPixelComponent(q,OpaqueOpacity);
1511 if (image->matte != MagickFalse)
1512 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
1513 if (image->colorspace == CMYKColorspace)
1514 splice_indexes[x]=(*indexes++);
1518 if (SyncCacheViewAuthenticPixels(splice_view,exception) == MagickFalse)
1520 proceed=SetImageProgress(image,SpliceImageTag,y,splice_image->rows);
1521 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1526 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1527 #pragma omp critical (MagickCore_TransposeImage)
1529 proceed=SetImageProgress(image,SpliceImageTag,progress++,
1530 splice_image->rows);
1531 if (proceed == MagickFalse)
1535 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1536 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
1538 for (y=(long) (splice_geometry.y+splice_geometry.height);
1539 y < (long) splice_image->rows; y++)
1541 register const PixelPacket
1544 register IndexPacket
1546 *restrict splice_indexes;
1551 register PixelPacket
1554 if (status == MagickFalse)
1556 p=GetCacheViewVirtualPixels(image_view,0,y-splice_geometry.height,
1557 image->columns,1,exception);
1558 q=QueueCacheViewAuthenticPixels(splice_view,0,y,splice_image->columns,1,
1560 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
1565 indexes=GetCacheViewAuthenticIndexQueue(image_view);
1566 splice_indexes=GetCacheViewAuthenticIndexQueue(splice_view);
1567 for (x=0; x < splice_geometry.x; x++)
1569 SetRedPixelComponent(q,GetRedPixelComponent(p));
1570 SetGreenPixelComponent(q,GetGreenPixelComponent(p));
1571 SetBluePixelComponent(q,GetBluePixelComponent(p));
1572 SetOpacityPixelComponent(q,OpaqueOpacity);
1573 if (image->matte != MagickFalse)
1574 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
1575 if (image->colorspace == CMYKColorspace)
1576 splice_indexes[x]=(*indexes++);
1580 for ( ; x < (long) (splice_geometry.x+splice_geometry.width); x++)
1582 for ( ; x < (long) splice_image->columns; x++)
1584 SetRedPixelComponent(q,GetRedPixelComponent(p));
1585 SetGreenPixelComponent(q,GetGreenPixelComponent(p));
1586 SetBluePixelComponent(q,GetBluePixelComponent(p));
1587 SetOpacityPixelComponent(q,OpaqueOpacity);
1588 if (image->matte != MagickFalse)
1589 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
1590 if (image->colorspace == CMYKColorspace)
1591 splice_indexes[x]=(*indexes++);
1595 if (SyncCacheViewAuthenticPixels(splice_view,exception) == MagickFalse)
1597 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1602 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1603 #pragma omp critical (MagickCore_TransposeImage)
1605 proceed=SetImageProgress(image,SpliceImageTag,progress++,
1606 splice_image->rows);
1607 if (proceed == MagickFalse)
1611 splice_view=DestroyCacheView(splice_view);
1612 image_view=DestroyCacheView(image_view);
1613 if (status == MagickFalse)
1614 splice_image=DestroyImage(splice_image);
1615 return(splice_image);
1619 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1623 % T r a n s f o r m I m a g e %
1627 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1629 % TransformImage() is a convenience method that behaves like ResizeImage() or
1630 % CropImage() but accepts scaling and/or cropping information as a region
1631 % geometry specification. If the operation fails, the original image handle
1634 % The format of the TransformImage method is:
1636 % MagickBooleanType TransformImage(Image **image,const char *crop_geometry,
1637 % const char *image_geometry)
1639 % A description of each parameter follows:
1641 % o image: the image The transformed image is returned as this parameter.
1643 % o crop_geometry: A crop geometry string. This geometry defines a
1644 % subregion of the image to crop.
1646 % o image_geometry: An image geometry string. This geometry defines the
1647 % final size of the image.
1650 static inline long MagickRound(MagickRealType x)
1653 Round the fraction to nearest integer.
1656 return((long) (x+0.5));
1657 return((long) (x-0.5));
1660 MagickExport MagickBooleanType TransformImage(Image **image,
1661 const char *crop_geometry,const char *image_geometry)
1682 assert(image != (Image **) NULL);
1683 assert((*image)->signature == MagickSignature);
1684 if ((*image)->debug != MagickFalse)
1685 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1686 transform_image=(*image);
1687 if (crop_geometry != (const char *) NULL)
1696 Crop image to a user specified size.
1698 crop_image=NewImageList();
1699 flags=ParseGravityGeometry(transform_image,crop_geometry,&geometry,
1700 &(*image)->exception);
1701 if ((flags & AreaValue) != 0)
1711 Crop into NxM tiles (@ flag) - AT.
1713 if (geometry.width == 0)
1715 if (geometry.height == 0)
1717 width=transform_image->columns;
1718 height=transform_image->rows;
1719 if ((flags & AspectValue) == 0)
1721 width-=(geometry.x < 0 ? -1 : 1)*geometry.x;
1722 height-=(geometry.y < 0 ? -1 : 1)*geometry.y;
1726 width+=(geometry.x < 0 ? -1 : 1)*geometry.x;
1727 height+=(geometry.y < 0 ? -1 : 1)*geometry.y;
1729 delta.x=(double) width/geometry.width;
1730 delta.y=(double) height/geometry.height;
1731 next=NewImageList();
1732 for (offset.y=0; offset.y < (double) height; )
1734 if ((flags & AspectValue) == 0)
1736 crop.y=(long) MagickRound((MagickRealType) (offset.y-
1737 (geometry.y > 0 ? 0 : geometry.y)));
1739 crop.height=(unsigned long) MagickRound((MagickRealType)
1740 (offset.y+(geometry.y < 0 ? 0 : geometry.y)));
1744 crop.y=(long) MagickRound((MagickRealType) (offset.y-
1745 (geometry.y > 0 ? geometry.y : 0)));
1747 crop.height=(unsigned long) MagickRound((MagickRealType)
1748 (offset.y+(geometry.y < 0 ? geometry.y : 0)));
1750 crop.height-=crop.y;
1751 for (offset.x=0; offset.x < (double) width; )
1753 if ((flags & AspectValue) == 0)
1755 crop.x=(long) MagickRound((MagickRealType) (offset.x-
1756 (geometry.x > 0 ? 0 : geometry.x)));
1758 crop.width=(unsigned long) MagickRound((MagickRealType)
1759 (offset.x+(geometry.x < 0 ? 0 : geometry.x)));
1763 crop.x=(long) MagickRound((MagickRealType) (offset.x-
1764 (geometry.x > 0 ? geometry.x : 0)));
1766 crop.width=(unsigned long) MagickRound((MagickRealType)
1767 (offset.x+(geometry.x < 0 ? geometry.x : 0)));
1770 next=CropImage(transform_image,&crop,&(*image)->exception);
1771 if (next == (Image *) NULL)
1773 AppendImageToList(&crop_image,next);
1775 if (next == (Image *) NULL)
1780 if (((geometry.width == 0) && (geometry.height == 0)) ||
1781 ((flags & XValue) != 0) || ((flags & YValue) != 0))
1784 Crop a single region at +X+Y.
1786 crop_image=CropImage(transform_image,&geometry,
1787 &(*image)->exception);
1788 if ((crop_image != (Image *) NULL) && ((flags & AspectValue) != 0))
1790 crop_image->page.width=geometry.width;
1791 crop_image->page.height=geometry.height;
1792 crop_image->page.x-=geometry.x;
1793 crop_image->page.y-=geometry.y;
1797 if ((transform_image->columns > geometry.width) ||
1798 (transform_image->rows > geometry.height))
1803 MagickProgressMonitor
1813 Crop into tiles of fixed size WxH.
1815 if (transform_image->page.width == 0)
1816 transform_image->page.width=transform_image->columns;
1817 if (transform_image->page.height == 0)
1818 transform_image->page.height=transform_image->rows;
1819 width=geometry.width;
1821 width=transform_image->page.width;
1822 height=geometry.height;
1824 height=transform_image->page.height;
1825 next=NewImageList();
1829 for (y=0; y < (long) transform_image->page.height; y+=height)
1830 for (x=0; x < (long) transform_image->page.width; x+=width)
1832 for (y=0; y < (long) transform_image->page.height; y+=height)
1834 for (x=0; x < (long) transform_image->page.width; x+=width)
1836 progress_monitor=SetImageProgressMonitor(transform_image,
1837 (MagickProgressMonitor) NULL,transform_image->client_data);
1838 geometry.width=width;
1839 geometry.height=height;
1842 next=CropImage(transform_image,&geometry,&(*image)->exception);
1843 (void) SetImageProgressMonitor(transform_image,
1844 progress_monitor,transform_image->client_data);
1845 proceed=SetImageProgress(transform_image,CropImageTag,i++,
1847 if (proceed == MagickFalse)
1849 if (next == (Image *) NULL)
1851 (void) SetImageProgressMonitor(next,progress_monitor,
1853 AppendImageToList(&crop_image,next);
1855 if (next == (Image *) NULL)
1857 if (proceed == MagickFalse)
1861 if (crop_image == (Image *) NULL)
1862 transform_image=CloneImage(*image,0,0,MagickTrue,&(*image)->exception);
1865 transform_image=DestroyImage(transform_image);
1866 transform_image=GetFirstImageInList(crop_image);
1868 *image=transform_image;
1870 if (image_geometry == (const char *) NULL)
1873 Scale image to a user specified size.
1875 flags=ParseRegionGeometry(transform_image,image_geometry,&geometry,
1876 &(*image)->exception);
1877 if ((transform_image->columns == geometry.width) &&
1878 (transform_image->rows == geometry.height))
1880 resize_image=ZoomImage(transform_image,geometry.width,geometry.height,
1881 &(*image)->exception);
1882 if (resize_image == (Image *) NULL)
1883 return(MagickFalse);
1884 transform_image=DestroyImage(transform_image);
1885 transform_image=resize_image;
1886 *image=transform_image;
1891 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1895 % T r a n s f o r m I m a g e s %
1898 % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1900 % TransformImages() calls TransformImage() on each image of a sequence.
1902 % The format of the TransformImage method is:
1904 % MagickBooleanType TransformImages(Image **image,
1905 % const char *crop_geometry,const char *image_geometry)
1907 % A description of each parameter follows:
1909 % o image: the image The transformed image is returned as this parameter.
1911 % o crop_geometry: A crop geometry string. This geometry defines a
1912 % subregion of the image to crop.
1914 % o image_geometry: An image geometry string. This geometry defines the
1915 % final size of the image.
1918 MagickExport MagickBooleanType TransformImages(Image **images,
1919 const char *crop_geometry,const char *image_geometry)
1932 assert(images != (Image **) NULL);
1933 assert((*images)->signature == MagickSignature);
1934 if ((*images)->debug != MagickFalse)
1935 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1936 (*images)->filename);
1937 image_list=ImageListToArray(*images,&(*images)->exception);
1938 if (image_list == (Image **) NULL)
1939 return(MagickFalse);
1941 transform_images=NewImageList();
1942 for (i=0; image_list[i] != (Image *) NULL; i++)
1944 image=image_list[i];
1945 status|=TransformImage(&image,crop_geometry,image_geometry);
1946 AppendImageToList(&transform_images,image);
1948 *images=transform_images;
1949 image_list=(Image **) RelinquishMagickMemory(image_list);
1950 return(status != 0 ? MagickTrue : MagickFalse);
1954 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1958 % T r a n s p o s e I m a g e %
1962 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1964 % TransposeImage() creates a horizontal mirror image by reflecting the pixels
1965 % around the central y-axis while rotating them by 90 degrees.
1967 % The format of the TransposeImage method is:
1969 % Image *TransposeImage(const Image *image,ExceptionInfo *exception)
1971 % A description of each parameter follows:
1973 % o image: the image.
1975 % o exception: return any errors or warnings in this structure.
1978 MagickExport Image *TransposeImage(const Image *image,ExceptionInfo *exception)
1980 #define TransposeImageTag "Transpose/Image"
1999 assert(image != (const Image *) NULL);
2000 assert(image->signature == MagickSignature);
2001 if (image->debug != MagickFalse)
2002 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2003 assert(exception != (ExceptionInfo *) NULL);
2004 assert(exception->signature == MagickSignature);
2005 transpose_image=CloneImage(image,image->rows,image->columns,MagickTrue,
2007 if (transpose_image == (Image *) NULL)
2008 return((Image *) NULL);
2014 image_view=AcquireCacheView(image);
2015 transpose_view=AcquireCacheView(transpose_image);
2016 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2017 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2019 for (y=0; y < (long) image->rows; y++)
2021 register const PixelPacket
2024 register IndexPacket
2025 *restrict transpose_indexes,
2028 register PixelPacket
2031 if (status == MagickFalse)
2033 p=GetCacheViewVirtualPixels(image_view,0,(long) image->rows-y-1,
2034 image->columns,1,exception);
2035 q=QueueCacheViewAuthenticPixels(transpose_view,(long) (image->rows-y-1),0,
2036 1,transpose_image->rows,exception);
2037 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
2042 (void) CopyMagickMemory(q,p,(size_t) image->columns*sizeof(*q));
2043 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2044 if (indexes != (IndexPacket *) NULL)
2046 transpose_indexes=GetCacheViewAuthenticIndexQueue(transpose_view);
2047 if (transpose_indexes != (IndexPacket *) NULL)
2048 (void) CopyMagickMemory(transpose_indexes,indexes,(size_t)
2049 image->columns*sizeof(*transpose_indexes));
2051 if (SyncCacheViewAuthenticPixels(transpose_view,exception) == MagickFalse)
2053 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2058 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2059 #pragma omp critical (MagickCore_TransposeImage)
2061 proceed=SetImageProgress(image,TransposeImageTag,progress++,
2063 if (proceed == MagickFalse)
2067 transpose_view=DestroyCacheView(transpose_view);
2068 image_view=DestroyCacheView(image_view);
2069 transpose_image->type=image->type;
2070 page=transpose_image->page;
2071 Swap(page.width,page.height);
2072 Swap(page.x,page.y);
2073 if (page.width != 0)
2074 page.x=(long) (page.width-transpose_image->columns-page.x);
2075 transpose_image->page=page;
2076 if (status == MagickFalse)
2077 transpose_image=DestroyImage(transpose_image);
2078 return(transpose_image);
2082 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2086 % T r a n s v e r s e I m a g e %
2090 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2092 % TransverseImage() creates a vertical mirror image by reflecting the pixels
2093 % around the central x-axis while rotating them by 270 degrees.
2095 % The format of the TransverseImage method is:
2097 % Image *TransverseImage(const Image *image,ExceptionInfo *exception)
2099 % A description of each parameter follows:
2101 % o image: the image.
2103 % o exception: return any errors or warnings in this structure.
2106 MagickExport Image *TransverseImage(const Image *image,ExceptionInfo *exception)
2108 #define TransverseImageTag "Transverse/Image"
2127 assert(image != (const Image *) NULL);
2128 assert(image->signature == MagickSignature);
2129 if (image->debug != MagickFalse)
2130 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2131 assert(exception != (ExceptionInfo *) NULL);
2132 assert(exception->signature == MagickSignature);
2133 transverse_image=CloneImage(image,image->rows,image->columns,MagickTrue,
2135 if (transverse_image == (Image *) NULL)
2136 return((Image *) NULL);
2142 image_view=AcquireCacheView(image);
2143 transverse_view=AcquireCacheView(transverse_image);
2144 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2145 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
2147 for (y=0; y < (long) image->rows; y++)
2152 register const PixelPacket
2155 register IndexPacket
2156 *restrict transverse_indexes,
2162 register PixelPacket
2165 if (status == MagickFalse)
2167 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
2168 q=QueueCacheViewAuthenticPixels(transverse_view,(long) (image->rows-y-
2169 1),0,1,transverse_image->rows,exception);
2170 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
2176 for (x=0; x < (long) image->columns; x++)
2178 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2179 if (indexes != (IndexPacket *) NULL)
2181 transverse_indexes=GetCacheViewAuthenticIndexQueue(transverse_view);
2182 if (transverse_indexes != (IndexPacket *) NULL)
2183 for (x=0; x < (long) image->columns; x++)
2184 transverse_indexes[image->columns-x-1]=indexes[x];
2186 sync=SyncCacheViewAuthenticPixels(transverse_view,exception);
2187 if (sync == MagickFalse)
2189 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2194 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2195 #pragma omp critical (MagickCore_TransverseImage)
2197 proceed=SetImageProgress(image,TransverseImageTag,progress++,
2199 if (proceed == MagickFalse)
2203 transverse_view=DestroyCacheView(transverse_view);
2204 image_view=DestroyCacheView(image_view);
2205 transverse_image->type=image->type;
2206 page=transverse_image->page;
2207 Swap(page.width,page.height);
2208 Swap(page.x,page.y);
2209 if (page.height != 0)
2210 page.y=(long) (page.height-transverse_image->rows-page.y);
2211 transverse_image->page=page;
2212 if (status == MagickFalse)
2213 transverse_image=DestroyImage(transverse_image);
2214 return(transverse_image);
2218 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2222 % T r i m I m a g e %
2226 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2228 % TrimImage() trims pixels from the image edges. It allocates the memory
2229 % necessary for the new Image structure and returns a pointer to the new
2232 % The format of the TrimImage method is:
2234 % Image *TrimImage(const Image *image,ExceptionInfo *exception)
2236 % A description of each parameter follows:
2238 % o image: the image.
2240 % o exception: return any errors or warnings in this structure.
2243 MagickExport Image *TrimImage(const Image *image,ExceptionInfo *exception)
2248 assert(image != (const Image *) NULL);
2249 assert(image->signature == MagickSignature);
2250 if (image->debug != MagickFalse)
2251 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2252 geometry=GetImageBoundingBox(image,exception);
2253 if ((geometry.width == 0) || (geometry.height == 0))
2258 crop_image=CloneImage(image,1,1,MagickTrue,exception);
2259 if (crop_image == (Image *) NULL)
2260 return((Image *) NULL);
2261 crop_image->background_color.opacity=(Quantum) TransparentOpacity;
2262 (void) SetImageBackgroundColor(crop_image);
2263 crop_image->page=image->page;
2264 crop_image->page.x=(-1);
2265 crop_image->page.y=(-1);
2268 geometry.x+=image->page.x;
2269 geometry.y+=image->page.y;
2270 return(CropImage(image,&geometry,exception));