]> granicus.if.org Git - imagemagick/blobdiff - coders/tiff.c
(no commit message)
[imagemagick] / coders / tiff.c
index 53f41734701822da0adb320a6dd7c82ea89277e7..5bf4489fb96a9cf71c7056ea3f6a8b1505593105 100644 (file)
@@ -688,7 +688,10 @@ static void TIFFGetEXIFProperties(TIFF *tiff,Image *image,
     return;
   directory=TIFFCurrentDirectory(tiff);
   if (TIFFReadEXIFDirectory(tiff,offset) == 0)
-    return;
+    {
+      directory=TIFFCurrentDirectory(tiff);
+      return;
+    }
   sans=NULL;
   for (i=0; exif_info[i].tag != 0; i++)
   {
@@ -1841,6 +1844,74 @@ RestoreMSCWarning
 static TIFFExtendProc
   tag_extender = (TIFFExtendProc) NULL;
 
+static void TIFFIgnoreTags(TIFF *tiff)
+{
+  char
+    *q;
+
+  const char
+    *p,
+    *tags;
+
+  Image
+   *image;
+
+  register ssize_t
+    i;
+
+  size_t
+    count;
+
+  TIFFFieldInfo
+    *ignore;
+
+  if (TIFFGetReadProc(tiff) != TIFFReadBlob)
+    return;
+  image=(Image *)TIFFClientdata(tiff);
+  tags=GetImageArtifact(image,"tiff:ignore-tags");
+  if (tags == (const char *) NULL)
+    return;
+  count=0;
+  p=tags;
+  while (*p != '\0')
+  {
+    while ((isspace((int) ((unsigned char) *p)) != 0))
+      p++;
+
+    (void) strtol(p,&q,10);
+    if (p == q)
+      return;
+
+    p=q;
+    count++;
+
+    while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
+      p++;
+  }
+  if (count == 0)
+    return;
+  i=0;
+  p=tags;
+  ignore=(TIFFFieldInfo *) AcquireQuantumMemory(count,sizeof(*ignore));
+  // This also sets field_bit to 0 (FIELD_IGNORE)
+  ResetMagickMemory(ignore,0,count*sizeof(*ignore));
+  while (*p != '\0')
+  {
+    while ((isspace((int) ((unsigned char) *p)) != 0))
+      p++;
+
+    ignore[i].field_tag=(ttag_t) strtol(p,&q,10);
+
+    p=q;
+    i++;
+
+    while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
+      p++;
+  }
+  (void) TIFFMergeFieldInfo(tiff,ignore,(uint32) count);
+  ignore=(TIFFFieldInfo *) RelinquishMagickMemory(ignore);
+}
+
 static void TIFFTagExtender(TIFF *tiff)
 {
   static const TIFFFieldInfo
@@ -1856,6 +1927,7 @@ static void TIFFTagExtender(TIFF *tiff)
     sizeof(*TIFFExtensions));
   if (tag_extender != (TIFFExtendProc) NULL)
     (*tag_extender)(tiff);
+  TIFFIgnoreTags(tiff);
 }
 #endif
 
@@ -1870,7 +1942,7 @@ ModuleExport size_t RegisterTIFFImage(void)
     *entry;
 
   if (tiff_semaphore == (SemaphoreInfo *) NULL)
-    tiff_semaphore=AllocateSemaphoreInfo();
+    ActivateSemaphoreInfo(&tiff_semaphore);
   LockSemaphoreInfo(tiff_semaphore);
   if (instantiate_key == MagickFalse)
     {
@@ -2003,7 +2075,7 @@ ModuleExport void UnregisterTIFFImage(void)
   (void) UnregisterMagickInfo("TIF");
   (void) UnregisterMagickInfo("PTIF");
   if (tiff_semaphore == (SemaphoreInfo *) NULL)
-    tiff_semaphore=AllocateSemaphoreInfo();
+    ActivateSemaphoreInfo(&tiff_semaphore);
   LockSemaphoreInfo(tiff_semaphore);
   if (instantiate_key != MagickFalse)
     {
@@ -2016,7 +2088,7 @@ ModuleExport void UnregisterTIFFImage(void)
       instantiate_key=MagickFalse;
     }
   UnlockSemaphoreInfo(tiff_semaphore);
-  DestroySemaphoreInfo(&tiff_semaphore);
+  RelinquishSemaphoreInfo(&tiff_semaphore);
 }
 \f
 #if defined(MAGICKCORE_TIFF_DELEGATE)
@@ -2562,38 +2634,40 @@ static void TIFFSetProperties(TIFF *tiff,Image *image,ExceptionInfo *exception)
   const char
     *value;
 
-  (void) TIFFSetField(tiff,TIFFTAG_DOCUMENTNAME,image->filename);
-  value=GetImageProperty(image,"tiff:hostcomputer",exception);
+  value=GetImageArtifact(image,"tiff:document");
+  if (value != (const char *) NULL)
+    (void) TIFFSetField(tiff,TIFFTAG_DOCUMENTNAME,value);
+  value=GetImageArtifact(image,"tiff:hostcomputer");
   if (value != (const char *) NULL)
     (void) TIFFSetField(tiff,TIFFTAG_HOSTCOMPUTER,value);
-  value=GetImageProperty(image,"tiff:artist",exception);
+  value=GetImageArtifact(image,"tiff:artist");
   if (value != (const char *) NULL)
     (void) TIFFSetField(tiff,TIFFTAG_ARTIST,value);
-  value=GetImageProperty(image,"tiff:timestamp",exception);
+  value=GetImageArtifact(image,"tiff:timestamp");
   if (value != (const char *) NULL)
     (void) TIFFSetField(tiff,TIFFTAG_DATETIME,value);
-  value=GetImageProperty(image,"tiff:make",exception);
+  value=GetImageArtifact(image,"tiff:make");
   if (value != (const char *) NULL)
     (void) TIFFSetField(tiff,TIFFTAG_MAKE,value);
-  value=GetImageProperty(image,"tiff:model",exception);
+  value=GetImageArtifact(image,"tiff:model");
   if (value != (const char *) NULL)
     (void) TIFFSetField(tiff,TIFFTAG_MODEL,value);
-  value=GetImageProperty(image,"tiff:software",exception);
+  value=GetImageArtifact(image,"tiff:software");
   if (value != (const char *) NULL)
     (void) TIFFSetField(tiff,TIFFTAG_SOFTWARE,value);
-  value=GetImageProperty(image,"tiff:copyright",exception);
+  value=GetImageArtifact(image,"tiff:copyright");
   if (value != (const char *) NULL)
     (void) TIFFSetField(tiff,TIFFTAG_COPYRIGHT,value);
-  value=GetImageProperty(image,"kodak-33423",exception);
+  value=GetImageArtifact(image,"kodak-33423");
   if (value != (const char *) NULL)
     (void) TIFFSetField(tiff,33423,value);
-  value=GetImageProperty(image,"kodak-36867",exception);
+  value=GetImageArtifact(image,"kodak-36867");
   if (value != (const char *) NULL)
     (void) TIFFSetField(tiff,36867,value);
-  value=GetImageProperty(image,"label",exception);
+  value=GetImageArtifact(image,"label");
   if (value != (const char *) NULL)
     (void) TIFFSetField(tiff,TIFFTAG_PAGENAME,value);
-  value=GetImageProperty(image,"comment",exception);
+  value=GetImageArtifact(image,"comment");
   if (value != (const char *) NULL)
     (void) TIFFSetField(tiff,TIFFTAG_IMAGEDESCRIPTION,value);
 }
@@ -2790,6 +2864,8 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info,
         (image_info->type != OptimizeType))
       (void) SetImageType(image,image_info->type,exception);
     compression=UndefinedCompression;
+    if (image->compression != JPEGCompression)
+      compression=image->compression;
     if (image_info->compression != UndefinedCompression)
       compression=image_info->compression;
     switch (compression)
@@ -2996,9 +3072,6 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info,
                 }
           }
       }
-    if ((photometric == PHOTOMETRIC_RGB) &&
-        (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse))
-      (void) TransformImageColorspace(image,sRGBColorspace,exception);
     switch (image->endian)
     {
       case LSBEndian:
@@ -3206,7 +3279,7 @@ static MagickBooleanType WriteTIFFImage(const ImageInfo *image_info,
     if (rows_per_strip < 1)
       rows_per_strip=1;
     if ((image->rows/rows_per_strip) >= (1UL << 15))
-      rows_per_strip=(image->rows >> 15);
+      rows_per_strip=(uint32) (image->rows >> 15);
     (void) TIFFSetField(tiff,TIFFTAG_ROWSPERSTRIP,rows_per_strip);
     if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0))
       {