]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/image.c
(no commit message)
[imagemagick] / MagickCore / image.c
index 54c849470cd533132b32525b53903b3673b4a1ee..1050897de6367b45dc1f683d53f6cfb507295682 100644 (file)
@@ -17,7 +17,7 @@
 %                                 July 1992                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2013 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  %
@@ -205,6 +205,7 @@ MagickExport Image *AcquireImage(const ImageInfo *image_info,
   image->channel_mask=DefaultChannels;
   image->channel_map=AcquirePixelChannelMap();
   image->blob=CloneBlobInfo((BlobInfo *) NULL);
+  image->timestamp=time((time_t *) NULL);
   image->debug=IsEventLogging();
   image->reference_count=1;
   image->semaphore=AllocateSemaphoreInfo();
@@ -280,11 +281,14 @@ MagickExport Image *AcquireImage(const ImageInfo *image_info,
   image->client_data=image_info->client_data;
   if (image_info->cache != (void *) NULL)
     ClonePixelCacheMethods(image->cache,image_info->cache);
-
-  /* Set all global options that map to per-image settings */
+  /*
+    Set all global options that map to per-image settings.
+  */
   (void) SyncImageSettings(image_info,image,exception);
-
-  /* global options that are only set for new images */
+  /*
+    Global options that are only set for new images.
+  */
+  image->image_info=(ImageInfo *) NULL;
   option=GetImageOption(image_info,"delay");
   if (option != (const char *) NULL)
     {
@@ -445,7 +449,6 @@ MagickExport Image *AppendImages(const Image *images,
     *append_image;
 
   MagickBooleanType
-    proceed,
     status;
 
   MagickOffsetType
@@ -526,6 +529,9 @@ MagickExport Image *AppendImages(const Image *images,
     Image
       *image;
 
+    MagickBooleanType
+      proceed;
+
     image=CloneImage(next,0,0,MagickTrue,exception);
     if (image == (Image *) NULL)
       break;
@@ -539,7 +545,7 @@ MagickExport Image *AppendImages(const Image *images,
     image_view=AcquireVirtualCacheView(image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
     #pragma omp parallel for schedule(static,4) shared(status) \
-      dynamic_number_threads(image,image->columns,image->rows,1)
+      magick_threads(image,image,image->rows,1)
 #endif
     for (y=0; y < (ssize_t) image->rows; y++)
     {
@@ -1200,6 +1206,9 @@ MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
 */
 MagickExport void GetImageInfo(ImageInfo *image_info)
 {
+  char
+    *synchronize;
+
   ExceptionInfo
     *exception;
 
@@ -1215,8 +1224,12 @@ MagickExport void GetImageInfo(ImageInfo *image_info)
   image_info->quality=UndefinedCompressionQuality;
   image_info->antialias=MagickTrue;
   image_info->dither=MagickTrue;
-  image_info->synchronize=IsStringTrue(GetEnvironmentValue(
-         "MAGICK_SYNCHRONIZE"));
+  synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
+  if (synchronize != (const char *) NULL)
+    {
+      image_info->synchronize=IsStringTrue(synchronize);
+      synchronize=DestroyString(synchronize);
+    }
   exception=AcquireExceptionInfo();
   (void) QueryColorCompliance(BackgroundColor,AllCompliance,
     &image_info->background_color,exception);
@@ -1342,6 +1355,8 @@ MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
   }
   mask_view=DestroyCacheView(mask_view);
   image_view=DestroyCacheView(image_view);
+  if (status == MagickFalse)
+    mask_image=DestroyImage(mask_image);
   return(mask_image);
 }
 \f
@@ -1560,8 +1575,7 @@ MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
 #endif
         if (image != (Image *) NULL)
           value=GetImageProperty(image,pattern,exception);
-        if ((value == (const char *) NULL) &&
-            (image != (Image *) NULL))
+        if ((value == (const char *) NULL) && (image != (Image *) NULL))
           value=GetImageArtifact(image,pattern);
         if ((value == (const char *) NULL) &&
             (image_info != (ImageInfo *) NULL))
@@ -1649,7 +1663,7 @@ MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
   image_view=AcquireVirtualCacheView(image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(status) \
-    dynamic_number_threads(image,image->columns,image->rows,1)
+    magick_threads(image,image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -1904,7 +1918,7 @@ MagickExport Image *NewMagickImage(const ImageInfo *image_info,
   image_view=AcquireAuthenticCacheView(image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(status) \
-    dynamic_number_threads(image,image->columns,image->rows,1)
+    magick_threads(image,image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -2090,17 +2104,11 @@ static inline void FlattenPixelInfo(const Image *image,const PixelInfo *p,
   Sa=QuantumScale*alpha;
   Da=QuantumScale*beta,
   gamma=Sa*(-Da)+Sa+Da;
-  gamma=MagickEpsilonReciprocal(gamma);
+  gamma=PerceptibleReciprocal(gamma);
   for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
   {
-    PixelChannel
-      channel;
-
-    PixelTrait
-      traits;
-
-    channel=GetPixelChannelChannel(image,i);
-    traits=GetPixelChannelTraits(image,channel);
+    PixelChannel channel=GetPixelChannelChannel(image,i);
+    PixelTrait traits=GetPixelChannelTraits(image,channel);
     if (traits == UndefinedPixelTrait)
       continue;
     switch (channel)
@@ -2176,7 +2184,7 @@ MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
       image_view=AcquireAuthenticCacheView(image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
       #pragma omp parallel for schedule(static,4) shared(status) \
-        dynamic_number_threads(image,image->columns,image->rows,1)
+        magick_threads(image,image,image->rows,1)
 #endif
       for (y=0; y < (ssize_t) image->rows; y++)
       {
@@ -2198,7 +2206,10 @@ MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
         for (x=0; x < (ssize_t) image->columns; x++)
         {
           if (GetPixelAlpha(image,q) == TransparentAlpha)
-            SetPixelInfoPixel(image,&image->background_color,q);
+            {
+              SetPixelInfoPixel(image,&image->background_color,q);
+              SetPixelChannel(image,AlphaPixelChannel,TransparentAlpha,q);
+            }
           q+=GetPixelChannels(image);
         }
         if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
@@ -2229,7 +2240,7 @@ MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
     {
       status=CompositeImage(image,image,AlphaCompositeOp,MagickTrue,0,0,
         exception);
-      image->alpha_trait=UndefinedPixelTrait;
+      image->alpha_trait=CopyPixelTrait;
       break;
     }
     case OpaqueAlphaChannel:
@@ -2255,7 +2266,7 @@ MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
       image_view=AcquireAuthenticCacheView(image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
       #pragma omp parallel for schedule(static,4) shared(status) \
-        dynamic_number_threads(image,image->columns,image->rows,1)
+        magick_threads(image,image,image->rows,1)
 #endif
       for (y=0; y < (ssize_t) image->rows; y++)
       {
@@ -2354,7 +2365,7 @@ MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
     return(MagickFalse);
   if ((IsPixelInfoGray(&image->background_color) == MagickFalse) &&
       (IsGrayColorspace(image->colorspace) != MagickFalse))
-    (void) TransformImageColorspace(image,RGBColorspace,exception);
+    (void) TransformImageColorspace(image,sRGBColorspace,exception);
   if ((image->background_color.alpha_trait == BlendPixelTrait) &&
       (image->alpha_trait != BlendPixelTrait))
     (void) SetImageAlpha(image,OpaqueAlpha,exception);
@@ -2481,7 +2492,7 @@ MagickExport MagickBooleanType SetImageColor(Image *image,
   image_view=AcquireAuthenticCacheView(image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(status) \
-    dynamic_number_threads(image,image->columns,image->rows,1)
+    magick_threads(image,image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -2896,6 +2907,7 @@ MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
         }
       (void) ResetMagickMemory(magick,0,sizeof(magick));
       count=ReadBlob(image,2*MaxTextExtent,magick);
+      (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
       (void) CloseBlob(image);
       image=DestroyImage(image);
       /*
@@ -3048,12 +3060,18 @@ MagickExport MagickBooleanType SetImageMask(Image *image,const Image *mask,
   if (mask == (const Image *) NULL)
     {
       image->mask=MagickFalse;
-      return(MagickTrue);
+      return(SyncImagePixelCache(image,exception));
     }
-  status=MagickTrue;
   image->mask=MagickTrue;
+  if (SyncImagePixelCache(image,exception) == MagickFalse)
+    return(MagickFalse);
+  status=MagickTrue;
   mask_view=AcquireVirtualCacheView(mask,exception);
   image_view=AcquireAuthenticCacheView(image,exception);
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+  #pragma omp parallel for schedule(static,4) shared(status) \
+    magick_threads(mask,image,1,1)
+#endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
     register const Quantum
@@ -3076,7 +3094,7 @@ MagickExport MagickBooleanType SetImageMask(Image *image,const Image *mask,
       }
     for (x=0; x < (ssize_t) image->columns; x++)
     {
-      SetPixelMask(image,GetPixelGray(mask,p),q);
+      SetPixelMask(image,ClampToQuantum(GetPixelIntensity(mask,p)),q);
       p+=GetPixelChannels(mask);
       q+=GetPixelChannels(image);
     }
@@ -3135,7 +3153,7 @@ MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
   image_view=AcquireAuthenticCacheView(image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(status) \
-    dynamic_number_threads(image,image->columns,image->rows,1)
+    magick_threads(image,image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -3607,7 +3625,7 @@ MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
   image_view=AcquireAuthenticCacheView(image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(range_exception,status) \
-    dynamic_number_threads(image,image->columns,image->rows,1)
+    magick_threads(image,image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -3640,7 +3658,7 @@ MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
   image_view=DestroyCacheView(image_view);
   if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
     (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
-      "InvalidColormapIndex","'%s'",image->filename);
+      "InvalidColormapIndex","`%s'",image->filename);
   return(status);
 }
 \f
@@ -3658,10 +3676,11 @@ MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
 %  SyncImageSettings() syncs any image_info global options into per-image
 %  attributes.
 %
-%  Note: in IMv6 free form 'options' were always maped into 'artifacts', so
+%  Note: in IMv6 free form 'options' were always mapped into 'artifacts', so
 %  that operations and coders can find such settings.  In IMv7 if a desired
 %  per-image artifact is not set, then it will directly look for a global
-%  option as a fallback.
+%  option as a fallback, as such this copy is no longer needed, only the
+%  link set up.
 %
 %  The format of the SyncImageSettings method is:
 %
@@ -3925,17 +3944,18 @@ MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
   ResetImageOptionIterator(image_info);
 #if 0
   {
+    /* IMv6: Copy freeform global options into per-image artifacts, so
+     * various operations and coders can access them.
+     *
+     * This has a problem, as per-image artefacts may have been set in
+     * parenthesis, but may not be unset when parenthesis ends.
+     */
     char
       property[MaxTextExtent];
 
     const char
       *value;
 
-    /* IMv6: Copy freeform global options into per-image artifacts, so
-     * various operations and coders can access them.
-     * This has a problem, as artifacts may be set in parenthesis, but may
-     * not be unset when parenthesis ends.
-     */
     for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
     {
       value=GetImageOption(image_info,option);
@@ -3948,15 +3968,17 @@ MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
     }
   }
 #else
-  /* IMv7: pointer for lookup of artifact fallback, back to global option.
-     This saves a lot of duplication of global options into per-image
-     artifacts, while ensuring only specificly set per-image artifacts
-     are preverved when parenthesis ends.
-
-     WARNING: When a global option is set, any associated per-image artifact
-     should also be unset, as no longer valid.
-   */
-  image->image_info = CloneImageInfo(image_info);
+  /* IMv7: pointer to allow the lookup of pre-image artefact will fallback to
+     a global option setting/define.  This saves a lot of duplication of
+     global options into per-image artifacts, while ensuring only specifically
+     set per-image artifacts are preverved when parenthesis ends.
+
+     This pointer is never explictally freed, as it is only used as a back
+     reference, not as the main pointer to the image_info structure.  Images
+     being removed from a image_info image list (or yet to be added to such),
+     should have this pointer reset to NULL.
+  */
+  image->image_info=image_info;
 #endif
   return(MagickTrue);
 }