]> granicus.if.org Git - imagemagick/commitdiff
(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Mon, 27 May 2013 10:14:21 +0000 (10:14 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Mon, 27 May 2013 10:14:21 +0000 (10:14 +0000)
MagickCore/channel.c
MagickCore/image.c
MagickCore/image.h

index 792d27f51f87951a1365d608e5d1c4c1b95a2f08..57b5b36f1099146ae484bd7d4efaaa4c3aa9610d 100644 (file)
   Include declarations.
 */
 #include "MagickCore/studio.h"
+#include "MagickCore/cache-private.h"
 #include "MagickCore/colorspace-private.h"
+#include "MagickCore/composite-private.h"
+#include "MagickCore/enhance.h"
 #include "MagickCore/image.h"
 #include "MagickCore/list.h"
 #include "MagickCore/log.h"
@@ -49,6 +52,7 @@
 #include "MagickCore/monitor-private.h"
 #include "MagickCore/option.h"
 #include "MagickCore/pixel-accessor.h"
+#include "MagickCore/pixel-private.h"
 #include "MagickCore/resource_.h"
 #include "MagickCore/string-private.h"
 #include "MagickCore/thread-private.h"
@@ -612,6 +616,39 @@ MagickExport Image *CombineImages(const Image *image,
 %                                                                             %
 %                                                                             %
 %                                                                             %
+%   G e t I m a g e A l p h a C h a n n e l                                   %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
+%  not activated.  That is, the image is RGB rather than RGBA or CMYK rather
+%  than CMYKA.
+%
+%  The format of the GetImageAlphaChannel method is:
+%
+%      MagickBooleanType GetImageAlphaChannel(const Image *image)
+%
+%  A description of each parameter follows:
+%
+%    o image: the image.
+%
+*/
+MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
+{
+  assert(image != (const Image *) NULL);
+  if (image->debug != MagickFalse)
+    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
+  assert(image->signature == MagickSignature);
+  return(image->alpha_trait == BlendPixelTrait ? MagickTrue : MagickFalse);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
 %     S e p a r a t e I m a g e                                               %
 %                                                                             %
 %                                                                             %
@@ -809,3 +846,267 @@ MagickExport Image *SeparateImages(const Image *image,ExceptionInfo *exception)
     images=SeparateImage(image,UndefinedChannel,exception);
   return(images);
 }
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%   S e t I m a g e A l p h a C h a n n e l                                   %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
+%  channel.
+%
+%  The format of the SetImageAlphaChannel method is:
+%
+%      MagickBooleanType SetImageAlphaChannel(Image *image,
+%        const AlphaChannelOption alpha_type,ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o image: the image.
+%
+%    o alpha_type:  The alpha channel type: ActivateAlphaChannel,
+%      CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
+%      OpaqueAlphaChannel, SetAlphaChannel, ShapeAlphaChannel, and
+%      TransparentAlphaChannel.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+
+static inline void FlattenPixelInfo(const Image *image,const PixelInfo *p,
+  const double alpha,const Quantum *q,const double beta,
+  Quantum *composite)
+{
+  double
+    Da,
+    gamma,
+    Sa;
+
+  register ssize_t
+    i;
+
+  /*
+    Compose pixel p over pixel q with the given alpha.
+  */
+  Sa=QuantumScale*alpha;
+  Da=QuantumScale*beta,
+  gamma=Sa*(-Da)+Sa+Da;
+  gamma=PerceptibleReciprocal(gamma);
+  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+  {
+    PixelChannel channel=GetPixelChannelChannel(image,i);
+    PixelTrait traits=GetPixelChannelTraits(image,channel);
+    if (traits == UndefinedPixelTrait)
+      continue;
+    switch (channel)
+    {
+      case RedPixelChannel:
+      {
+        composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],beta,
+          (double) p->red,alpha));
+        break;
+      }
+      case GreenPixelChannel:
+      {
+        composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],beta,
+          (double) p->green,alpha));
+        break;
+      }
+      case BluePixelChannel:
+      {
+        composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],beta,
+          (double) p->blue,alpha));
+        break;
+      }
+      case BlackPixelChannel:
+      {
+        composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],beta,
+          (double) p->black,alpha));
+        break;
+      }
+      case AlphaPixelChannel:
+      {
+        composite[i]=ClampToQuantum(QuantumRange*(Sa*(-Da)+Sa+Da));
+        break;
+      }
+      default:
+        break;
+    }
+  }
+}
+
+MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
+  const AlphaChannelOption alpha_type,ExceptionInfo *exception)
+{
+  MagickBooleanType
+    status;
+
+  assert(image != (Image *) NULL);
+  if (image->debug != MagickFalse)
+    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
+  assert(image->signature == MagickSignature);
+  status=MagickTrue;
+  switch (alpha_type)
+  {
+    case ActivateAlphaChannel:
+    {
+      image->alpha_trait=BlendPixelTrait;
+      break;
+    }
+    case BackgroundAlphaChannel:
+    {
+      CacheView
+        *image_view;
+
+      ssize_t
+        y;
+
+      /*
+        Set transparent pixels to background color.
+      */
+      if (image->alpha_trait != BlendPixelTrait)
+        break;
+      if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
+        break;
+      image_view=AcquireAuthenticCacheView(image,exception);
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+      #pragma omp parallel for schedule(static,4) shared(status) \
+        magick_threads(image,image,image->rows,1)
+#endif
+      for (y=0; y < (ssize_t) image->rows; y++)
+      {
+        register Quantum
+          *restrict q;
+
+        register ssize_t
+          x;
+
+        if (status == MagickFalse)
+          continue;
+        q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
+          exception);
+        if (q == (Quantum *) NULL)
+          {
+            status=MagickFalse;
+            continue;
+          }
+        for (x=0; x < (ssize_t) image->columns; x++)
+        {
+          if (GetPixelAlpha(image,q) == TransparentAlpha)
+            {
+              SetPixelInfoPixel(image,&image->background_color,q);
+              SetPixelChannel(image,AlphaPixelChannel,TransparentAlpha,q);
+            }
+          q+=GetPixelChannels(image);
+        }
+        if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
+          status=MagickFalse;
+      }
+      image_view=DestroyCacheView(image_view);
+      return(status);
+    }
+    case CopyAlphaChannel:
+    case ShapeAlphaChannel:
+    {
+      /*
+        Copy pixel intensity to the alpha channel.
+      */
+      status=CompositeImage(image,image,IntensityCompositeOp,MagickTrue,0,0,
+        exception);
+      if (alpha_type == ShapeAlphaChannel)
+        (void) LevelImageColors(image,&image->background_color,
+          &image->background_color,MagickTrue,exception);
+      break;
+    }
+    case DeactivateAlphaChannel:
+    {
+      image->alpha_trait=CopyPixelTrait;
+      break;
+    }
+    case ExtractAlphaChannel:
+    {
+      status=CompositeImage(image,image,AlphaCompositeOp,MagickTrue,0,0,
+        exception);
+      image->alpha_trait=CopyPixelTrait;
+      break;
+    }
+    case OpaqueAlphaChannel:
+    {
+      status=SetImageAlpha(image,OpaqueAlpha,exception);
+      break;
+    }
+    case RemoveAlphaChannel:
+    {
+      CacheView
+        *image_view;
+
+      ssize_t
+        y;
+
+      /*
+        Remove transparency.
+      */
+      if (image->alpha_trait != BlendPixelTrait)
+        break;
+      if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
+        break;
+      image_view=AcquireAuthenticCacheView(image,exception);
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+      #pragma omp parallel for schedule(static,4) shared(status) \
+        magick_threads(image,image,image->rows,1)
+#endif
+      for (y=0; y < (ssize_t) image->rows; y++)
+      {
+        register Quantum
+          *restrict q;
+
+        register ssize_t
+          x;
+
+        if (status == MagickFalse)
+          continue;
+        q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
+          exception);
+        if (q == (Quantum *) NULL)
+          {
+            status=MagickFalse;
+            continue;
+          }
+        for (x=0; x < (ssize_t) image->columns; x++)
+        {
+          FlattenPixelInfo(image,&image->background_color,
+            image->background_color.alpha,q,(double)
+            GetPixelAlpha(image,q),q);
+          q+=GetPixelChannels(image);
+        }
+        if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
+          status=MagickFalse;
+      }
+      image_view=DestroyCacheView(image_view);
+      image->alpha_trait=image->background_color.alpha_trait;
+      return(status);
+    }
+    case SetAlphaChannel:
+    {
+      if (image->alpha_trait != BlendPixelTrait)
+        status=SetImageAlpha(image,OpaqueAlpha,exception);
+      break;
+    }
+    case TransparentAlphaChannel:
+    {
+      status=SetImageAlpha(image,TransparentAlpha,exception);
+      break;
+    }
+    case UndefinedAlphaChannel:
+      break;
+  }
+  if (status == MagickFalse)
+    return(status);
+  return(SyncImagePixelCache(image,exception));
+}
index 7ca3ab95be443f9e2e06ae0fd95241383427548a..3b28e64acfd411eee1b4335abad422624b818ff2 100644 (file)
@@ -1156,39 +1156,6 @@ MagickExport void DisassociateImageStream(Image *image)
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%   G e t I m a g e A l p h a C h a n n e l                                   %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
-%  not activated.  That is, the image is RGB rather than RGBA or CMYK rather
-%  than CMYKA.
-%
-%  The format of the GetImageAlphaChannel method is:
-%
-%      MagickBooleanType GetImageAlphaChannel(const Image *image)
-%
-%  A description of each parameter follows:
-%
-%    o image: the image.
-%
-*/
-MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
-{
-  assert(image != (const Image *) NULL);
-  if (image->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
-  assert(image->signature == MagickSignature);
-  return(image->alpha_trait == BlendPixelTrait ? MagickTrue : MagickFalse);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
 %   G e t I m a g e I n f o                                                   %
 %                                                                             %
 %                                                                             %
@@ -2061,270 +2028,6 @@ MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%   S e t I m a g e A l p h a C h a n n e l                                   %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
-%  channel.
-%
-%  The format of the SetImageAlphaChannel method is:
-%
-%      MagickBooleanType SetImageAlphaChannel(Image *image,
-%        const AlphaChannelOption alpha_type,ExceptionInfo *exception)
-%
-%  A description of each parameter follows:
-%
-%    o image: the image.
-%
-%    o alpha_type:  The alpha channel type: ActivateAlphaChannel,
-%      CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
-%      OpaqueAlphaChannel, SetAlphaChannel, ShapeAlphaChannel, and
-%      TransparentAlphaChannel.
-%
-%    o exception: return any errors or warnings in this structure.
-%
-*/
-
-static inline void FlattenPixelInfo(const Image *image,const PixelInfo *p,
-  const double alpha,const Quantum *q,const double beta,
-  Quantum *composite)
-{
-  double
-    Da,
-    gamma,
-    Sa;
-
-  register ssize_t
-    i;
-
-  /*
-    Compose pixel p over pixel q with the given alpha.
-  */
-  Sa=QuantumScale*alpha;
-  Da=QuantumScale*beta,
-  gamma=Sa*(-Da)+Sa+Da;
-  gamma=PerceptibleReciprocal(gamma);
-  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
-  {
-    PixelChannel channel=GetPixelChannelChannel(image,i);
-    PixelTrait traits=GetPixelChannelTraits(image,channel);
-    if (traits == UndefinedPixelTrait)
-      continue;
-    switch (channel)
-    {
-      case RedPixelChannel:
-      {
-        composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],beta,
-          (double) p->red,alpha));
-        break;
-      }
-      case GreenPixelChannel:
-      {
-        composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],beta,
-          (double) p->green,alpha));
-        break;
-      }
-      case BluePixelChannel:
-      {
-        composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],beta,
-          (double) p->blue,alpha));
-        break;
-      }
-      case BlackPixelChannel:
-      {
-        composite[i]=ClampToQuantum(gamma*MagickOver_((double) q[i],beta,
-          (double) p->black,alpha));
-        break;
-      }
-      case AlphaPixelChannel:
-      {
-        composite[i]=ClampToQuantum(QuantumRange*(Sa*(-Da)+Sa+Da));
-        break;
-      }
-      default:
-        break;
-    }
-  }
-}
-
-MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
-  const AlphaChannelOption alpha_type,ExceptionInfo *exception)
-{
-  MagickBooleanType
-    status;
-
-  assert(image != (Image *) NULL);
-  if (image->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
-  assert(image->signature == MagickSignature);
-  status=MagickTrue;
-  switch (alpha_type)
-  {
-    case ActivateAlphaChannel:
-    {
-      image->alpha_trait=BlendPixelTrait;
-      break;
-    }
-    case BackgroundAlphaChannel:
-    {
-      CacheView
-        *image_view;
-
-      ssize_t
-        y;
-
-      /*
-        Set transparent pixels to background color.
-      */
-      if (image->alpha_trait != BlendPixelTrait)
-        break;
-      if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
-        break;
-      image_view=AcquireAuthenticCacheView(image,exception);
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
-      #pragma omp parallel for schedule(static,4) shared(status) \
-        magick_threads(image,image,image->rows,1)
-#endif
-      for (y=0; y < (ssize_t) image->rows; y++)
-      {
-        register Quantum
-          *restrict q;
-
-        register ssize_t
-          x;
-
-        if (status == MagickFalse)
-          continue;
-        q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
-          exception);
-        if (q == (Quantum *) NULL)
-          {
-            status=MagickFalse;
-            continue;
-          }
-        for (x=0; x < (ssize_t) image->columns; x++)
-        {
-          if (GetPixelAlpha(image,q) == TransparentAlpha)
-            {
-              SetPixelInfoPixel(image,&image->background_color,q);
-              SetPixelChannel(image,AlphaPixelChannel,TransparentAlpha,q);
-            }
-          q+=GetPixelChannels(image);
-        }
-        if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
-          status=MagickFalse;
-      }
-      image_view=DestroyCacheView(image_view);
-      return(status);
-    }
-    case CopyAlphaChannel:
-    case ShapeAlphaChannel:
-    {
-      /*
-        Copy pixel intensity to the alpha channel.
-      */
-      status=CompositeImage(image,image,IntensityCompositeOp,MagickTrue,0,0,
-        exception);
-      if (alpha_type == ShapeAlphaChannel)
-        (void) LevelImageColors(image,&image->background_color,
-          &image->background_color,MagickTrue,exception);
-      break;
-    }
-    case DeactivateAlphaChannel:
-    {
-      image->alpha_trait=CopyPixelTrait;
-      break;
-    }
-    case ExtractAlphaChannel:
-    {
-      status=CompositeImage(image,image,AlphaCompositeOp,MagickTrue,0,0,
-        exception);
-      image->alpha_trait=CopyPixelTrait;
-      break;
-    }
-    case OpaqueAlphaChannel:
-    {
-      status=SetImageAlpha(image,OpaqueAlpha,exception);
-      break;
-    }
-    case RemoveAlphaChannel:
-    {
-      CacheView
-        *image_view;
-
-      ssize_t
-        y;
-
-      /*
-        Remove transparency.
-      */
-      if (image->alpha_trait != BlendPixelTrait)
-        break;
-      if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
-        break;
-      image_view=AcquireAuthenticCacheView(image,exception);
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
-      #pragma omp parallel for schedule(static,4) shared(status) \
-        magick_threads(image,image,image->rows,1)
-#endif
-      for (y=0; y < (ssize_t) image->rows; y++)
-      {
-        register Quantum
-          *restrict q;
-
-        register ssize_t
-          x;
-
-        if (status == MagickFalse)
-          continue;
-        q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
-          exception);
-        if (q == (Quantum *) NULL)
-          {
-            status=MagickFalse;
-            continue;
-          }
-        for (x=0; x < (ssize_t) image->columns; x++)
-        {
-          FlattenPixelInfo(image,&image->background_color,
-            image->background_color.alpha,q,(double)
-            GetPixelAlpha(image,q),q);
-          q+=GetPixelChannels(image);
-        }
-        if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
-          status=MagickFalse;
-      }
-      image_view=DestroyCacheView(image_view);
-      image->alpha_trait=image->background_color.alpha_trait;
-      return(status);
-    }
-    case SetAlphaChannel:
-    {
-      if (image->alpha_trait != BlendPixelTrait)
-        status=SetImageAlpha(image,OpaqueAlpha,exception);
-      break;
-    }
-    case TransparentAlphaChannel:
-    {
-      status=SetImageAlpha(image,TransparentAlpha,exception);
-      break;
-    }
-    case UndefinedAlphaChannel:
-      break;
-  }
-  if (status == MagickFalse)
-    return(status);
-  return(SyncImagePixelCache(image,exception));
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
 %   S e t I m a g e B a c k g r o u n d C o l o r                             %
 %                                                                             %
 %                                                                             %
index ff18caeff1a36e404e06d563a5c3c493cb748e5d..570be2b2a452c1cc1a3f82f74f864ec7330b76d9 100644 (file)
@@ -528,7 +528,6 @@ extern MagickExport ImageInfo
 extern MagickExport MagickBooleanType
   ClipImage(Image *,ExceptionInfo *),
   ClipImagePath(Image *,const char *,const MagickBooleanType,ExceptionInfo *),
-  GetImageAlphaChannel(const Image *),
   IsTaintImage(const Image *),
   IsHighDynamicRangeImage(const Image *,ExceptionInfo *),
   IsImageObject(const Image *),
@@ -536,7 +535,6 @@ extern MagickExport MagickBooleanType
   ModifyImage(Image **,ExceptionInfo *),
   ResetImagePage(Image *,const char *),
   SetImageAlpha(Image *,const Quantum,ExceptionInfo *),
-  SetImageAlphaChannel(Image *,const AlphaChannelOption,ExceptionInfo *),
   SetImageBackgroundColor(Image *,ExceptionInfo *),
   SetImageColor(Image *,const PixelInfo *,ExceptionInfo *),
   SetImageExtent(Image *,const size_t,const size_t,ExceptionInfo *),