]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/attribute.c
(no commit message)
[imagemagick] / MagickCore / attribute.c
index 8c81776aa59479d1e74c558e131e76365b07c213..d6b36bd9129a0f577f1ec847825b807eae457536 100644 (file)
@@ -41,6 +41,7 @@
   Include declarations.
 */
 #include "MagickCore/studio.h"
+#include "MagickCore/artifact.h"
 #include "MagickCore/attribute.h"
 #include "MagickCore/blob.h"
 #include "MagickCore/blob-private.h"
@@ -73,6 +74,7 @@
 #include "MagickCore/magick.h"
 #include "MagickCore/monitor.h"
 #include "MagickCore/monitor-private.h"
+#include "MagickCore/option.h"
 #include "MagickCore/paint.h"
 #include "MagickCore/pixel.h"
 #include "MagickCore/pixel-accessor.h"
@@ -169,7 +171,7 @@ MagickExport RectangleInfo GetImageBoundingBox(const Image *image,
   GetPixelInfo(image,&zero);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(status) \
-    IsConcurrentDos(image->columns,image->rows,64)
+    dynamic_number_threads(image,image->columns,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -299,13 +301,13 @@ MagickExport size_t GetImageDepth(const Image *image,ExceptionInfo *exception)
   status=MagickTrue;
   for (id=0; id < (ssize_t) number_threads; id++)
     current_depth[id]=1;
-  if ((image->storage_class == PseudoClass) && (image->matte == MagickFalse))
+  if ((image->storage_class == PseudoClass) && (image->alpha_trait != BlendPixelTrait))
     {
       register ssize_t
         i;
 
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-      #pragma omp parallel for schedule(static) shared(status) \
+      #pragma omp parallel for schedule(static,4) shared(status) \
         if ((image->colors) > 256) \
           num_threads(GetMagickResourceLimit(ThreadResource))
 #endif
@@ -388,7 +390,7 @@ MagickExport size_t GetImageDepth(const Image *image,ExceptionInfo *exception)
       }
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
       #pragma omp parallel for schedule(static,4) shared(status) \
-        IsConcurrentDos(image->columns,image->rows,64)
+        dynamic_number_threads(image,image->columns,image->rows,1)
 #endif
       for (y=0; y < (ssize_t) image->rows; y++)
       {
@@ -424,8 +426,8 @@ MagickExport size_t GetImageDepth(const Image *image,ExceptionInfo *exception)
             PixelTrait
               traits;
 
-            channel=GetPixelChannelMapChannel(image,i);
-            traits=GetPixelChannelMapTraits(image,channel);
+            channel=GetPixelChannelChannel(image,i);
+            traits=GetPixelChannelTraits(image,channel);
             if ((traits == UndefinedPixelTrait) ||
                 (channel == IndexPixelChannel) || (channel == MaskPixelChannel))
               continue;
@@ -452,7 +454,7 @@ MagickExport size_t GetImageDepth(const Image *image,ExceptionInfo *exception)
   */
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(status) \
-    IsConcurrentDos(image->columns,image->rows,64)
+    dynamic_number_threads(image,image->columns,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -488,8 +490,8 @@ MagickExport size_t GetImageDepth(const Image *image,ExceptionInfo *exception)
         PixelTrait
           traits;
 
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
+        channel=GetPixelChannelChannel(image,i);
+        traits=GetPixelChannelTraits(image,channel);
         if ((traits == UndefinedPixelTrait) || (channel == IndexPixelChannel) ||
             (channel == MaskPixelChannel))
           continue;
@@ -616,7 +618,7 @@ MagickExport ImageType GetImageType(const Image *image,ExceptionInfo *exception)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   if (image->colorspace == CMYKColorspace)
     {
-      if (image->matte == MagickFalse)
+      if (image->alpha_trait != BlendPixelTrait)
         return(ColorSeparationType);
       return(ColorSeparationMatteType);
     }
@@ -624,17 +626,17 @@ MagickExport ImageType GetImageType(const Image *image,ExceptionInfo *exception)
     return(BilevelType);
   if (IsImageGray(image,exception) != MagickFalse)
     {
-      if (image->matte != MagickFalse)
+      if (image->alpha_trait == BlendPixelTrait)
         return(GrayscaleMatteType);
       return(GrayscaleType);
     }
   if (IsPaletteImage(image,exception) != MagickFalse)
     {
-      if (image->matte != MagickFalse)
+      if (image->alpha_trait == BlendPixelTrait)
         return(PaletteMatteType);
       return(PaletteType);
     }
-  if (image->matte != MagickFalse)
+  if (image->alpha_trait == BlendPixelTrait)
     return(TrueColorMatteType);
   return(TrueColorType);
 }
@@ -690,7 +692,8 @@ MagickExport MagickBooleanType IsImageGray(const Image *image,
   if ((image->type == BilevelType) || (image->type == GrayscaleType) ||
       (image->type == GrayscaleMatteType))
     return(MagickTrue);
-  if (IssRGBColorspace(image->colorspace) == MagickFalse)
+  if ((IsGrayColorspace(image->colorspace) == MagickFalse) &&
+      (IsRGBColorspace(image->colorspace) == MagickFalse))
     return(MagickFalse);
   type=BilevelType;
   image_view=AcquireVirtualCacheView(image,exception);
@@ -718,7 +721,7 @@ MagickExport MagickBooleanType IsImageGray(const Image *image,
   if (type == UndefinedType)
     return(MagickFalse);
   ((Image *) image)->type=type;
-  if ((type == GrayscaleType) && (image->matte != MagickFalse))
+  if ((type == GrayscaleType) && (image->alpha_trait == BlendPixelTrait))
     ((Image *) image)->type=GrayscaleMatteType;
   return(MagickTrue);
 }
@@ -774,7 +777,8 @@ MagickExport MagickBooleanType IsImageMonochrome(const Image *image,
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   if (image->type == BilevelType)
     return(MagickTrue);
-  if (IssRGBColorspace(image->colorspace) == MagickFalse)
+  if ((IsGrayColorspace(image->colorspace) == MagickFalse) &&
+      (IsRGBColorspace(image->colorspace) == MagickFalse))
     return(MagickFalse);
   type=BilevelType;
   image_view=AcquireVirtualCacheView(image,exception);
@@ -852,10 +856,8 @@ MagickExport MagickBooleanType IsImageOpaque(const Image *image,
   assert(image->signature == MagickSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
-
-  if (image->matte == MagickFalse)
+  if (image->alpha_trait != BlendPixelTrait)
     return(MagickTrue);
-
   image_view=AcquireVirtualCacheView(image,exception);
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -925,7 +927,7 @@ MagickExport MagickBooleanType SetImageDepth(Image *image,
   assert(image->signature == MagickSignature);
   if (depth >= MAGICKCORE_QUANTUM_DEPTH)
     {
-      image->depth=MAGICKCORE_QUANTUM_DEPTH;
+      image->depth=depth;
       return(MagickTrue);
     }
   range=GetQuantumRange(depth);
@@ -935,8 +937,8 @@ MagickExport MagickBooleanType SetImageDepth(Image *image,
         i;
 
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-      #pragma omp parallel for schedule(static) shared(status) \
-        IsConcurrentUno(image->colors,256)
+      #pragma omp parallel for schedule(static,4) shared(status) \
+        dynamic_number_threads(image,image->columns,1,1)
 #endif
       for (i=0; i < (ssize_t) image->colors; i++)
       {
@@ -953,10 +955,6 @@ MagickExport MagickBooleanType SetImageDepth(Image *image,
           image->colormap[i].alpha=(double) ScaleAnyToQuantum(ScaleQuantumToAny(
             ClampToQuantum(image->colormap[i].alpha),range),range);
       }
-      status=SyncImage(image,exception);
-      if (status != MagickFalse)
-        image->depth=depth;
-      return(status);
     }
   status=MagickTrue;
   image_view=AcquireAuthenticCacheView(image,exception);
@@ -980,7 +978,7 @@ MagickExport MagickBooleanType SetImageDepth(Image *image,
           range);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
       #pragma omp parallel for schedule(static,4) shared(status) \
-        IsConcurrentDos(image->columns,image->rows,64)
+        dynamic_number_threads(image,image->columns,image->rows,1)
 #endif
       for (y=0; y < (ssize_t) image->rows; y++)
       {
@@ -1017,8 +1015,8 @@ MagickExport MagickBooleanType SetImageDepth(Image *image,
             PixelTrait
               traits;
 
-            channel=GetPixelChannelMapChannel(image,i);
-            traits=GetPixelChannelMapTraits(image,channel);
+            channel=GetPixelChannelChannel(image,i);
+            traits=GetPixelChannelTraits(image,channel);
             if ((traits == UndefinedPixelTrait) ||
                 (channel == IndexPixelChannel) || (channel == MaskPixelChannel))
               continue;
@@ -1044,7 +1042,7 @@ MagickExport MagickBooleanType SetImageDepth(Image *image,
   */
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(status) \
-    IsConcurrentDos(image->columns,image->rows,64)
+    dynamic_number_threads(image,image->columns,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -1080,8 +1078,8 @@ MagickExport MagickBooleanType SetImageDepth(Image *image,
         PixelTrait
           traits;
 
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
+        channel=GetPixelChannelChannel(image,i);
+        traits=GetPixelChannelTraits(image,channel);
         if ((traits == UndefinedPixelTrait) || (channel == IndexPixelChannel) ||
             (channel == MaskPixelChannel))
           continue;
@@ -1100,3 +1098,188 @@ MagickExport MagickBooleanType SetImageDepth(Image *image,
     image->depth=depth;
   return(status);
 }
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%   S e t I m a g e T y p e                                                   %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  SetImageType() sets the type of image.  Choose from these types:
+%
+%        Bilevel        Grayscale       GrayscaleMatte
+%        Palette        PaletteMatte    TrueColor
+%        TrueColorMatte ColorSeparation ColorSeparationMatte
+%        OptimizeType
+%
+%  The format of the SetImageType method is:
+%
+%      MagickBooleanType SetImageType(Image *image,const ImageType type,
+%        ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o image: the image.
+%
+%    o type: Image type.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type,
+  ExceptionInfo *exception)
+{
+  const char
+    *artifact;
+
+  ImageInfo
+    *image_info;
+
+  MagickBooleanType
+    status;
+
+  QuantizeInfo
+    *quantize_info;
+
+  assert(image != (Image *) NULL);
+  if (image->debug != MagickFalse)
+    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
+  assert(image->signature == MagickSignature);
+  status=MagickTrue;
+  image_info=AcquireImageInfo();
+  image_info->dither=image->dither;
+  artifact=GetImageArtifact(image,"dither");
+  if (artifact != (const char *) NULL)
+    (void) SetImageOption(image_info,"dither",artifact);
+  switch (type)
+  {
+    case BilevelType:
+    {
+      if (IsImageMonochrome(image,exception) == MagickFalse)
+        {
+          quantize_info=AcquireQuantizeInfo(image_info);
+          quantize_info->number_colors=2;
+          quantize_info->colorspace=GRAYColorspace;
+          status=QuantizeImage(quantize_info,image,exception);
+          quantize_info=DestroyQuantizeInfo(quantize_info);
+        }
+      image->alpha_trait=UndefinedPixelTrait;
+      break;
+    }
+    case GrayscaleType:
+    {
+      if (IsImageGray(image,exception) == MagickFalse)
+        status=TransformImageColorspace(image,GRAYColorspace,exception);
+      image->alpha_trait=UndefinedPixelTrait;
+      break;
+    }
+    case GrayscaleMatteType:
+    {
+      if (IsImageGray(image,exception) == MagickFalse)
+        status=TransformImageColorspace(image,GRAYColorspace,exception);
+      if (image->alpha_trait != BlendPixelTrait)
+        (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
+      break;
+    }
+    case PaletteType:
+    {
+      if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
+        status=TransformImageColorspace(image,sRGBColorspace,exception);
+      if ((image->storage_class == DirectClass) || (image->colors > 256))
+        {
+          quantize_info=AcquireQuantizeInfo(image_info);
+          quantize_info->number_colors=256;
+          status=QuantizeImage(quantize_info,image,exception);
+          quantize_info=DestroyQuantizeInfo(quantize_info);
+        }
+      image->alpha_trait=UndefinedPixelTrait;
+      break;
+    }
+    case PaletteBilevelMatteType:
+    {
+      ChannelType
+        channel_mask;
+
+      if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
+        status=TransformImageColorspace(image,sRGBColorspace,exception);
+      if (image->alpha_trait != BlendPixelTrait)
+        (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
+      channel_mask=SetImageChannelMask(image,AlphaChannel);
+      (void) BilevelImage(image,(double) QuantumRange/2.0,exception);
+      (void) SetImageChannelMask(image,channel_mask);
+      quantize_info=AcquireQuantizeInfo(image_info);
+      status=QuantizeImage(quantize_info,image,exception);
+      quantize_info=DestroyQuantizeInfo(quantize_info);
+      break;
+    }
+    case PaletteMatteType:
+    {
+      if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
+        status=TransformImageColorspace(image,sRGBColorspace,exception);
+      if (image->alpha_trait != BlendPixelTrait)
+        (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
+      quantize_info=AcquireQuantizeInfo(image_info);
+      quantize_info->colorspace=TransparentColorspace;
+      status=QuantizeImage(quantize_info,image,exception);
+      quantize_info=DestroyQuantizeInfo(quantize_info);
+      break;
+    }
+    case TrueColorType:
+    {
+      if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
+        status=TransformImageColorspace(image,sRGBColorspace,exception);
+      if (image->storage_class != DirectClass)
+        status=SetImageStorageClass(image,DirectClass,exception);
+      image->alpha_trait=UndefinedPixelTrait;
+      break;
+    }
+    case TrueColorMatteType:
+    {
+      if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
+        status=TransformImageColorspace(image,sRGBColorspace,exception);
+      if (image->storage_class != DirectClass)
+        status=SetImageStorageClass(image,DirectClass,exception);
+      if (image->alpha_trait != BlendPixelTrait)
+        (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
+      break;
+    }
+    case ColorSeparationType:
+    {
+      if (image->colorspace != CMYKColorspace)
+        {
+          if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
+            status=TransformImageColorspace(image,sRGBColorspace,exception);
+          status=TransformImageColorspace(image,CMYKColorspace,exception);
+        }
+      if (image->storage_class != DirectClass)
+        status=SetImageStorageClass(image,DirectClass,exception);
+      image->alpha_trait=UndefinedPixelTrait;
+      break;
+    }
+    case ColorSeparationMatteType:
+    {
+      if (image->colorspace != CMYKColorspace)
+        {
+          if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
+            status=TransformImageColorspace(image,sRGBColorspace,exception);
+          status=TransformImageColorspace(image,CMYKColorspace,exception);
+        }
+      if (image->storage_class != DirectClass)
+        status=SetImageStorageClass(image,DirectClass,exception);
+      if (image->alpha_trait != BlendPixelTrait)
+        status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
+      break;
+    }
+    case OptimizeType:
+    case UndefinedType:
+      break;
+  }
+  image->type=type;
+  image_info=DestroyImageInfo(image_info);
+  return(status);
+}