]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/transform.c
(no commit message)
[imagemagick] / MagickCore / transform.c
index fa99fce761d2531824d37ed290ad21d9dcad7921..5af3014a1bd214a1002d33f94e62159ba314a011 100644 (file)
 %                    MagickCore Image Transform Methods                       %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                                 July 1992                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
@@ -47,6 +47,7 @@
 #include "MagickCore/color-private.h"
 #include "MagickCore/colorspace-private.h"
 #include "MagickCore/composite.h"
+#include "MagickCore/distort.h"
 #include "MagickCore/draw.h"
 #include "MagickCore/effect.h"
 #include "MagickCore/exception.h"
 %                                                                             %
 %                                                                             %
 %                                                                             %
+%   A u t o O r i e n t I m a g e                                             %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  AutoOrientImage() adjusts an image so that its orientation is suitable for
+%  viewing (i.e. top-left orientation).
+%
+%  The format of the AutoOrientImage method is:
+%
+%      Image *AutoOrientImage(const Image *image,
+%        const OrientationType orientation,ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o image: The image.
+%
+%    o orientation: Current image orientation.
+%
+%    o exception: Return any errors or warnings in this structure.
+%
+*/
+MagickExport Image *AutoOrientImage(const Image *image,
+  const OrientationType orientation,ExceptionInfo *exception)
+{
+  Image
+    *orient_image;
+
+  assert(image != (const Image *) NULL);
+  assert(image->signature == MagickSignature);
+  assert(exception != (ExceptionInfo *) NULL);
+  assert(exception->signature == MagickSignature);
+  orient_image=(Image *) NULL;
+  switch(orientation)
+  {
+    case UndefinedOrientation:
+    case TopLeftOrientation:
+    default:
+    {
+      orient_image=CloneImage(image,0,0,MagickTrue,exception);
+      break;
+    }
+    case TopRightOrientation:
+    {
+      orient_image=FlopImage(image,exception);
+      break;
+    }
+    case BottomRightOrientation:
+    {
+      orient_image=RotateImage(image,180.0,exception);
+      break;
+    }
+    case BottomLeftOrientation:
+    {
+      orient_image=FlipImage(image,exception);
+      break;
+    }
+    case LeftTopOrientation:
+    {
+      orient_image=TransposeImage(image,exception);
+      break;
+    }
+    case RightTopOrientation:
+    {
+      orient_image=RotateImage(image,90.0,exception);
+      break;
+    }
+    case RightBottomOrientation:
+    {
+      orient_image=TransverseImage(image,exception);
+      break;
+    }
+    case LeftBottomOrientation:
+    {
+      orient_image=RotateImage(image,270.0,exception);
+      break;
+    }
+  }
+  if (orient_image != (Image *) NULL)
+    orient_image->orientation=TopLeftOrientation;
+  return(orient_image);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
 %   C h o p I m a g e                                                         %
 %                                                                             %
 %                                                                             %
@@ -157,10 +247,11 @@ MagickExport Image *ChopImage(const Image *image,const RectangleInfo *chop_info,
   */
   status=MagickTrue;
   progress=0;
-  image_view=AcquireCacheView(image);
-  chop_view=AcquireCacheView(chop_image);
+  image_view=AcquireVirtualCacheView(image,exception);
+  chop_view=AcquireAuthenticCacheView(chop_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(static) shared(progress,status)
+  #pragma omp parallel for schedule(static,4) shared(status) \
+    magick_threads(image,chop_image,1,1)
 #endif
   for (y=0; y < (ssize_t) extent.y; y++)
   {
@@ -190,23 +281,11 @@ MagickExport Image *ChopImage(const Image *image,const RectangleInfo *chop_info,
           register ssize_t
             i;
 
-          if (GetPixelMask(image,p) != 0)
-            {
-              q+=GetPixelChannels(chop_image);
-              continue;
-            }
           for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
           {
-            PixelChannel
-              channel;
-
-            PixelTrait
-              chop_traits,
-              traits;
-
-            channel=GetPixelChannelMapChannel(image,i);
-            traits=GetPixelChannelMapTraits(image,channel);
-            chop_traits=GetPixelChannelMapTraits(chop_image,channel);
+            PixelChannel channel=GetPixelChannelChannel(image,i);
+            PixelTrait traits=GetPixelChannelTraits(image,channel);
+            PixelTrait chop_traits=GetPixelChannelTraits(chop_image,channel);
             if ((traits == UndefinedPixelTrait) ||
                 (chop_traits == UndefinedPixelTrait))
               continue;
@@ -235,7 +314,8 @@ MagickExport Image *ChopImage(const Image *image,const RectangleInfo *chop_info,
     Extract chop image.
   */
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(static) shared(progress,status)
+  #pragma omp parallel for schedule(static,4) shared(progress,status) \
+    magick_threads(image,chop_image,1,1)
 #endif
   for (y=0; y < (ssize_t) (image->rows-(extent.y+extent.height)); y++)
   {
@@ -266,30 +346,16 @@ MagickExport Image *ChopImage(const Image *image,const RectangleInfo *chop_info,
           register ssize_t
             i;
 
-         if (GetPixelMask(image,p) != 0)
-           {
-             p+=GetPixelChannels(image);
-             q+=GetPixelChannels(chop_image);
-             continue;
-           }
           for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
           {
-            PixelChannel
-              channel;
-
-            PixelTrait
-              chop_traits,
-              traits;
-
-            channel=GetPixelChannelMapChannel(image,i);
-            traits=GetPixelChannelMapTraits(image,channel);
-            chop_traits=GetPixelChannelMapTraits(chop_image,channel);
+            PixelChannel channel=GetPixelChannelChannel(image,i);
+            PixelTrait traits=GetPixelChannelTraits(image,channel);
+            PixelTrait chop_traits=GetPixelChannelTraits(chop_image,channel);
             if ((traits == UndefinedPixelTrait) ||
                 (chop_traits == UndefinedPixelTrait))
               continue;
             SetPixelChannel(chop_image,channel,p[i],q);
           }
-          p+=GetPixelChannels(chop_image);
           q+=GetPixelChannels(chop_image);
         }
       p+=GetPixelChannels(image);
@@ -312,6 +378,8 @@ MagickExport Image *ChopImage(const Image *image,const RectangleInfo *chop_info,
   chop_view=DestroyCacheView(chop_view);
   image_view=DestroyCacheView(image_view);
   chop_image->type=image->type;
+  if (status == MagickFalse)
+    chop_image=DestroyImage(chop_image);
   return(chop_image);
 }
 \f
@@ -381,8 +449,8 @@ MagickExport Image *ConsolidateCMYKImages(const Image *images,
     (void) SetImageColorspace(cmyk_image,CMYKColorspace,exception);
     for (i=0; i < 4; i++)
     {
-      image_view=AcquireCacheView(images);
-      cmyk_view=AcquireCacheView(cmyk_image);
+      image_view=AcquireVirtualCacheView(images,exception);
+      cmyk_view=AcquireAuthenticCacheView(cmyk_image,exception);
       for (y=0; y < (ssize_t) images->rows; y++)
       {
         register const Quantum
@@ -523,6 +591,7 @@ MagickExport Image *CropImage(const Image *image,const RectangleInfo *geometry,
       if (crop_image == (Image *) NULL)
         return((Image *) NULL);
       crop_image->background_color.alpha=(Quantum) TransparentAlpha;
+      crop_image->alpha_trait=BlendPixelTrait;
       (void) SetImageBackgroundColor(crop_image,exception);
       crop_image->page=bounding_box;
       crop_image->page.x=(-1);
@@ -594,10 +663,11 @@ MagickExport Image *CropImage(const Image *image,const RectangleInfo *geometry,
   */
   status=MagickTrue;
   progress=0;
-  image_view=AcquireCacheView(image);
-  crop_view=AcquireCacheView(crop_image);
+  image_view=AcquireVirtualCacheView(image,exception);
+  crop_view=AcquireAuthenticCacheView(crop_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(static) shared(progress,status)
+  #pragma omp parallel for schedule(static,4) shared(status) \
+    magick_threads(image,crop_image,1,1)
 #endif
   for (y=0; y < (ssize_t) crop_image->rows; y++)
   {
@@ -626,24 +696,18 @@ MagickExport Image *CropImage(const Image *image,const RectangleInfo *geometry,
       register ssize_t
         i;
 
-      if (GetPixelMask(image,p) != 0)
+      if (GetPixelReadMask(image,p) == 0)
         {
+          SetPixelBackgoundColor(crop_image,q);
           p+=GetPixelChannels(image);
           q+=GetPixelChannels(crop_image);
           continue;
         }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          crop_traits,
-          traits;
-
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
-        crop_traits=GetPixelChannelMapTraits(crop_image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
+        PixelTrait crop_traits=GetPixelChannelTraits(crop_image,channel);
         if ((traits == UndefinedPixelTrait) ||
             (crop_traits == UndefinedPixelTrait))
           continue;
@@ -703,18 +767,18 @@ MagickExport Image *CropImage(const Image *image,const RectangleInfo *geometry,
 %
 */
 
-static inline ssize_t MagickRound(MagickRealType x)
+static inline double MagickRound(double x)
 {
   /*
     Round the fraction to nearest integer.
   */
-  if (x >= 0.0)
-    return((ssize_t) (x+0.5));
-  return((ssize_t) (x-0.5));
+  if ((x-floor(x)) < (ceil(x)-x))
+    return(floor(x));
+  return(ceil(x));
 }
 
 MagickExport Image *CropImageToTiles(const Image *image,
-  const char *crop_geometry, ExceptionInfo *exception)
+  const char *crop_geometry,ExceptionInfo *exception)
 {
   Image
     *next,
@@ -767,24 +831,26 @@ MagickExport Image *CropImageToTiles(const Image *image,
         }
       delta.x=(double) width/geometry.width;
       delta.y=(double) height/geometry.height;
-      if ( delta.x < 1.0 ) delta.x = 1.0;
-      if ( delta.y < 1.0 ) delta.y = 1.0;
+      if (delta.x < 1.0)
+        delta.x=1.0;
+      if (delta.y < 1.0)
+        delta.y=1.0;
       for (offset.y=0; offset.y < (double) height; )
       {
         if ((flags & AspectValue) == 0)
           {
-            crop.y=(ssize_t) MagickRound((MagickRealType) (offset.y-
+            crop.y=(ssize_t) MagickRound((double) (offset.y-
               (geometry.y > 0 ? 0 : geometry.y)));
             offset.y+=delta.y;   /* increment now to find width */
-            crop.height=(size_t) MagickRound((MagickRealType) (offset.y+
+            crop.height=(size_t) MagickRound((double) (offset.y+
               (geometry.y < 0 ? 0 : geometry.y)));
           }
         else
           {
-            crop.y=(ssize_t) MagickRound((MagickRealType) (offset.y-
+            crop.y=(ssize_t) MagickRound((double) (offset.y-
               (geometry.y > 0 ? geometry.y : 0)));
             offset.y+=delta.y;  /* increment now to find width */
-            crop.height=(size_t) MagickRound((MagickRealType)
+            crop.height=(size_t) MagickRound((double)
               (offset.y+(geometry.y < -1 ? geometry.y : 0)));
           }
         crop.height-=crop.y;
@@ -793,18 +859,18 @@ MagickExport Image *CropImageToTiles(const Image *image,
         {
           if ((flags & AspectValue) == 0)
             {
-              crop.x=(ssize_t) MagickRound((MagickRealType) (offset.x-
+              crop.x=(ssize_t) MagickRound((double) (offset.x-
                 (geometry.x > 0 ? 0 : geometry.x)));
               offset.x+=delta.x;  /* increment now to find height */
-              crop.width=(size_t) MagickRound((MagickRealType) (offset.x+
+              crop.width=(size_t) MagickRound((double) (offset.x+
                 (geometry.x < 0 ? 0 : geometry.x)));
             }
           else
             {
-              crop.x=(ssize_t) MagickRound((MagickRealType) (offset.x-
+              crop.x=(ssize_t) MagickRound((double) (offset.x-
                 (geometry.x > 0 ? geometry.x : 0)));
               offset.x+=delta.x;  /* increment now to find height */
-              crop.width=(size_t) MagickRound((MagickRealType) (offset.x+
+              crop.width=(size_t) MagickRound((double) (offset.x+
                 (geometry.x < 0 ? geometry.x : 0)));
             }
           crop.width-=crop.x;
@@ -820,7 +886,6 @@ MagickExport Image *CropImageToTiles(const Image *image,
       ClearMagickException(exception);
       return(crop_image);
     }
-
   if (((geometry.width == 0) && (geometry.height == 0)) ||
       ((flags & XValue) != 0) || ((flags & YValue) != 0))
     {
@@ -836,7 +901,7 @@ MagickExport Image *CropImageToTiles(const Image *image,
           crop_image->page.y-=geometry.y;
         }
       return(crop_image);
-     }
+    }
   if ((image->columns > geometry.width) || (image->rows > geometry.height))
     {
       RectangleInfo
@@ -954,10 +1019,11 @@ MagickExport Image *ExcerptImage(const Image *image,
   */
   status=MagickTrue;
   progress=0;
-  image_view=AcquireCacheView(image);
-  excerpt_view=AcquireCacheView(excerpt_image);
+  image_view=AcquireVirtualCacheView(image,exception);
+  excerpt_view=AcquireAuthenticCacheView(excerpt_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(static,4) shared(progress,status)
+  #pragma omp parallel for schedule(static,4) shared(progress,status) \
+    magick_threads(image,excerpt_image,excerpt_image->rows,1)
 #endif
   for (y=0; y < (ssize_t) excerpt_image->rows; y++)
   {
@@ -986,24 +1052,18 @@ MagickExport Image *ExcerptImage(const Image *image,
       register ssize_t
         i;
 
-      if (GetPixelMask(image,p) != 0)
+      if (GetPixelReadMask(image,p) == 0)
         {
+          SetPixelBackgoundColor(excerpt_image,q);
           p+=GetPixelChannels(image);
           q+=GetPixelChannels(excerpt_image);
           continue;
         }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          excerpt_traits,
-          traits;
-
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
-        excerpt_traits=GetPixelChannelMapTraits(excerpt_image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
+        PixelTrait excerpt_traits=GetPixelChannelTraits(excerpt_image,channel);
         if ((traits == UndefinedPixelTrait) ||
             (excerpt_traits == UndefinedPixelTrait))
           continue;
@@ -1091,10 +1151,10 @@ MagickExport Image *ExtentImage(const Image *image,
       return((Image *) NULL);
     }
   if (extent_image->background_color.alpha != OpaqueAlpha)
-    extent_image->matte=MagickTrue;
+    extent_image->alpha_trait=BlendPixelTrait;
   (void) SetImageBackgroundColor(extent_image,exception);
-  (void) CompositeImage(extent_image,image->compose,image,-geometry->x,
-    -geometry->y,exception);
+  (void) CompositeImage(extent_image,image,image->compose,MagickTrue,
+    -geometry->x,-geometry->y,exception);
   return(extent_image);
 }
 \f
@@ -1161,10 +1221,11 @@ MagickExport Image *FlipImage(const Image *image,ExceptionInfo *exception)
   status=MagickTrue;
   progress=0;
   page=image->page;
-  image_view=AcquireCacheView(image);
-  flip_view=AcquireCacheView(flip_image);
+  image_view=AcquireVirtualCacheView(image,exception);
+  flip_view=AcquireAuthenticCacheView(flip_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(static) shared(progress,status)
+  #pragma omp parallel for schedule(static,4) shared(status) \
+    magick_threads(image,flip_image,1,1)
 #endif
   for (y=0; y < (ssize_t) flip_image->rows; y++)
   {
@@ -1192,24 +1253,18 @@ MagickExport Image *FlipImage(const Image *image,ExceptionInfo *exception)
       register ssize_t
         i;
 
-      if (GetPixelMask(image,p) != 0)
+      if (GetPixelReadMask(image,p) == 0)
         {
+          SetPixelBackgoundColor(flip_image,q);
           p+=GetPixelChannels(image);
           q+=GetPixelChannels(flip_image);
           continue;
         }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          flip_traits,
-          traits;
-
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
-        flip_traits=GetPixelChannelMapTraits(flip_image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
+        PixelTrait flip_traits=GetPixelChannelTraits(flip_image,channel);
         if ((traits == UndefinedPixelTrait) ||
             (flip_traits == UndefinedPixelTrait))
           continue;
@@ -1307,10 +1362,11 @@ MagickExport Image *FlopImage(const Image *image,ExceptionInfo *exception)
   status=MagickTrue;
   progress=0;
   page=image->page;
-  image_view=AcquireCacheView(image);
-  flop_view=AcquireCacheView(flop_image);
+  image_view=AcquireVirtualCacheView(image,exception);
+  flop_view=AcquireAuthenticCacheView(flop_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(static) shared(progress,status)
+  #pragma omp parallel for schedule(static,4) shared(status) \
+    magick_threads(image,flop_image,1,1)
 #endif
   for (y=0; y < (ssize_t) flop_image->rows; y++)
   {
@@ -1340,23 +1396,16 @@ MagickExport Image *FlopImage(const Image *image,ExceptionInfo *exception)
         i;
 
       q-=GetPixelChannels(flop_image);
-      if (GetPixelMask(image,p) != 0)
+      if (GetPixelReadMask(image,p) == 0)
         {
           p+=GetPixelChannels(image);
           continue;
         }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          flop_traits,
-          traits;
-
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
-        flop_traits=GetPixelChannelMapTraits(flop_image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
+        PixelTrait flop_traits=GetPixelChannelTraits(flop_image,channel);
         if ((traits == UndefinedPixelTrait) ||
             (flop_traits == UndefinedPixelTrait))
           continue;
@@ -1435,11 +1484,14 @@ static inline MagickBooleanType CopyImageRegion(Image *destination,
   ssize_t
     y;
 
+  if (columns == 0)
+    return(MagickTrue);
   status=MagickTrue;
-  source_view=AcquireCacheView(source);
-  destination_view=AcquireCacheView(destination);
+  source_view=AcquireVirtualCacheView(source,exception);
+  destination_view=AcquireAuthenticCacheView(destination,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(static) shared(status)
+  #pragma omp parallel for schedule(static,4) shared(status) \
+    magick_threads(source,destination,rows,1)
 #endif
   for (y=0; y < (ssize_t) rows; y++)
   {
@@ -1472,24 +1524,19 @@ static inline MagickBooleanType CopyImageRegion(Image *destination,
       register ssize_t
         i;
 
-      if (GetPixelMask(source,p) != 0)
+      if (GetPixelReadMask(source,p) == 0)
         {
+          SetPixelBackgoundColor(destination,q);
           p+=GetPixelChannels(source);
           q+=GetPixelChannels(destination);
           continue;
         }
       for (i=0; i < (ssize_t) GetPixelChannels(source); i++)
       {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          destination_traits,
-          source_traits;
-
-        channel=GetPixelChannelMapChannel(source,i);
-        source_traits=GetPixelChannelMapTraits(source,channel);
-        destination_traits=GetPixelChannelMapTraits(destination,channel);
+        PixelChannel channel=GetPixelChannelChannel(source,i);
+        PixelTrait source_traits=GetPixelChannelTraits(source,channel);
+        PixelTrait destination_traits=GetPixelChannelTraits(destination,
+          channel);
         if ((source_traits == UndefinedPixelTrait) ||
             (destination_traits == UndefinedPixelTrait))
           continue;
@@ -1550,14 +1597,14 @@ MagickExport Image *RollImage(const Image *image,const ssize_t x_offset,
     (size_t) offset.y,(ssize_t) image->columns-offset.x,(ssize_t) image->rows-
     offset.y,0,0,exception);
   (void) SetImageProgress(image,RollImageTag,0,3);
-  status|=CopyImageRegion(roll_image,image,image->columns-offset.x,
+  status&=CopyImageRegion(roll_image,image,image->columns-offset.x,
     (size_t) offset.y,0,(ssize_t) image->rows-offset.y,offset.x,0,
     exception);
   (void) SetImageProgress(image,RollImageTag,1,3);
-  status|=CopyImageRegion(roll_image,image,(size_t) offset.x,image->rows-
+  status&=CopyImageRegion(roll_image,image,(size_t) offset.x,image->rows-
     offset.y,(ssize_t) image->columns-offset.x,0,0,offset.y,exception);
   (void) SetImageProgress(image,RollImageTag,2,3);
-  status|=CopyImageRegion(roll_image,image,image->columns-offset.x,image->rows-
+  status&=CopyImageRegion(roll_image,image,image->columns-offset.x,image->rows-
     offset.y,0,0,offset.x,offset.y,exception);
   (void) SetImageProgress(image,RollImageTag,3,3);
   roll_image->type=image->type;
@@ -1729,7 +1776,6 @@ MagickExport Image *SpliceImage(const Image *image,
       splice_geometry.y+=(ssize_t) splice_geometry.width/2;
       break;
     }
-    case StaticGravity:
     case CenterGravity:
     {
       splice_geometry.x+=(ssize_t) splice_geometry.width/2;
@@ -1765,10 +1811,11 @@ MagickExport Image *SpliceImage(const Image *image,
   */
   status=MagickTrue;
   progress=0;
-  image_view=AcquireCacheView(image);
-  splice_view=AcquireCacheView(splice_image);
+  image_view=AcquireVirtualCacheView(image,exception);
+  splice_view=AcquireAuthenticCacheView(splice_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(static,4) shared(progress,status)
+  #pragma omp parallel for schedule(static,4) shared(progress,status) \
+    magick_threads(image,splice_image,1,1)
 #endif
   for (y=0; y < (ssize_t) splice_geometry.y; y++)
   {
@@ -1796,24 +1843,18 @@ MagickExport Image *SpliceImage(const Image *image,
       register ssize_t
         i;
 
-      if (GetPixelMask(image,p) != 0)
+      if (GetPixelReadMask(image,p) == 0)
         {
+          SetPixelBackgoundColor(splice_image,q);
           p+=GetPixelChannels(image);
           q+=GetPixelChannels(splice_image);
           continue;
         }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          splice_traits,
-          traits;
-
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
-        splice_traits=GetPixelChannelMapTraits(splice_image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
+        PixelTrait splice_traits=GetPixelChannelTraits(splice_image,channel);
         if ((traits == UndefinedPixelTrait) ||
             (splice_traits == UndefinedPixelTrait))
           continue;
@@ -1829,24 +1870,18 @@ MagickExport Image *SpliceImage(const Image *image,
       register ssize_t
         i;
 
-      if (GetPixelMask(image,p) != 0)
+      if (GetPixelReadMask(image,p) == 0)
         {
+          SetPixelBackgoundColor(splice_image,q);
           p+=GetPixelChannels(image);
           q+=GetPixelChannels(splice_image);
           continue;
         }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          traits,
-          splice_traits;
-
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
-        splice_traits=GetPixelChannelMapTraits(splice_image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
+        PixelTrait splice_traits=GetPixelChannelTraits(splice_image,channel);
         if ((traits == UndefinedPixelTrait) ||
             (splice_traits == UndefinedPixelTrait))
           continue;
@@ -1872,7 +1907,8 @@ MagickExport Image *SpliceImage(const Image *image,
       }
   }
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(static,4) shared(progress,status)
+  #pragma omp parallel for schedule(static,4) shared(progress,status) \
+    magick_threads(image,splice_image,1,1)
 #endif
   for (y=(ssize_t) (splice_geometry.y+splice_geometry.height);
        y < (ssize_t) splice_image->rows; y++)
@@ -1904,24 +1940,18 @@ MagickExport Image *SpliceImage(const Image *image,
       register ssize_t
         i;
 
-      if (GetPixelMask(image,q) != 0)
+      if (GetPixelReadMask(image,q) == 0)
         {
+          SetPixelBackgoundColor(splice_image,q);
           p+=GetPixelChannels(image);
           q+=GetPixelChannels(splice_image);
           continue;
         }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          traits,
-          splice_traits;
-
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
-        splice_traits=GetPixelChannelMapTraits(splice_image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
+        PixelTrait splice_traits=GetPixelChannelTraits(splice_image,channel);
         if ((traits == UndefinedPixelTrait) ||
             (splice_traits == UndefinedPixelTrait))
           continue;
@@ -1937,24 +1967,18 @@ MagickExport Image *SpliceImage(const Image *image,
       register ssize_t
         i;
 
-      if (GetPixelMask(image,q) != 0)
+      if (GetPixelReadMask(image,q) == 0)
         {
+          SetPixelBackgoundColor(splice_image,q);
           p+=GetPixelChannels(image);
           q+=GetPixelChannels(splice_image);
           continue;
         }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          traits,
-          splice_traits;
-
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
-        splice_traits=GetPixelChannelMapTraits(splice_image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
+        PixelTrait splice_traits=GetPixelChannelTraits(splice_image,channel);
         if ((traits == UndefinedPixelTrait) ||
             (splice_traits == UndefinedPixelTrait))
           continue;
@@ -2081,7 +2105,7 @@ MagickExport MagickBooleanType TransformImage(Image **image,
       (transform_image->rows == geometry.height))
     return(MagickTrue);
   resize_image=ResizeImage(transform_image,geometry.width,geometry.height,
-    transform_image->filter,transform_image->blur,exception);
+    transform_image->filter,exception);
   if (resize_image == (Image *) NULL)
     return(MagickFalse);
   transform_image=DestroyImage(transform_image);
@@ -2149,7 +2173,7 @@ MagickExport MagickBooleanType TransformImages(Image **images,
   for (i=0; image_list[i] != (Image *) NULL; i++)
   {
     image=image_list[i];
-    status|=TransformImage(&image,crop_geometry,image_geometry,exception);
+    status&=TransformImage(&image,crop_geometry,image_geometry,exception);
     AppendImageToList(&transform_images,image);
   }
   *images=transform_images;
@@ -2220,10 +2244,11 @@ MagickExport Image *TransposeImage(const Image *image,ExceptionInfo *exception)
   */
   status=MagickTrue;
   progress=0;
-  image_view=AcquireCacheView(image);
-  transpose_view=AcquireCacheView(transpose_image);
+  image_view=AcquireVirtualCacheView(image,exception);
+  transpose_view=AcquireAuthenticCacheView(transpose_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(static,4) shared(progress,status)
+  #pragma omp parallel for schedule(static,4) shared(progress,status) \
+    magick_threads(image,transpose_image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -2252,24 +2277,19 @@ MagickExport Image *TransposeImage(const Image *image,ExceptionInfo *exception)
       register ssize_t
         i;
 
-      if (GetPixelMask(image,q) != 0)
+      if (GetPixelReadMask(image,q) == 0)
         {
+          SetPixelBackgoundColor(transpose_image,q);
           p+=GetPixelChannels(image);
           q+=GetPixelChannels(transpose_image);
           continue;
         }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          traits,
-          transpose_traits;
-
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
-        transpose_traits=GetPixelChannelMapTraits(transpose_image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
+        PixelTrait transpose_traits=GetPixelChannelTraits(transpose_image,
+          channel);
         if ((traits == UndefinedPixelTrait) ||
             (transpose_traits == UndefinedPixelTrait))
           continue;
@@ -2369,10 +2389,11 @@ MagickExport Image *TransverseImage(const Image *image,ExceptionInfo *exception)
   */
   status=MagickTrue;
   progress=0;
-  image_view=AcquireCacheView(image);
-  transverse_view=AcquireCacheView(transverse_image);
+  image_view=AcquireVirtualCacheView(image,exception);
+  transverse_view=AcquireAuthenticCacheView(transverse_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(static,4) shared(progress,status)
+  #pragma omp parallel for schedule(static,4) shared(progress,status) \
+    magick_threads(image,transverse_image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -2405,23 +2426,17 @@ MagickExport Image *TransverseImage(const Image *image,ExceptionInfo *exception)
         i;
 
       q-=GetPixelChannels(transverse_image);
-      if (GetPixelMask(image,p) != 0)
+      if (GetPixelReadMask(image,p) == 0)
         {
           p+=GetPixelChannels(image);
           continue;
         }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          traits,
-          transverse_traits;
-
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
-        transverse_traits=GetPixelChannelMapTraits(transverse_image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
+        PixelTrait transverse_traits=GetPixelChannelTraits(transverse_image,
+          channel);
         if ((traits == UndefinedPixelTrait) ||
             (transverse_traits == UndefinedPixelTrait))
           continue;
@@ -2507,6 +2522,7 @@ MagickExport Image *TrimImage(const Image *image,ExceptionInfo *exception)
       if (crop_image == (Image *) NULL)
         return((Image *) NULL);
       crop_image->background_color.alpha=(Quantum) TransparentAlpha;
+      crop_image->alpha_trait=BlendPixelTrait;
       (void) SetImageBackgroundColor(crop_image,exception);
       crop_image->page=image->page;
       crop_image->page.x=(-1);