]> granicus.if.org Git - imagemagick/blobdiff - coders/cin.c
(no commit message)
[imagemagick] / coders / cin.c
index f7363df215fc21e2b202c7789a144b3f1bb6b11d..df281f69e1caf8e03331feaefa9fb28cbe7573b9 100644 (file)
 %                                                                             %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                             Kelly Bergougnoux                               %
 %                               October 2003                                  %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2015 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 declarations.
 */
 #include "MagickCore/studio.h"
+#include "MagickCore/artifact.h"
 #include "MagickCore/blob.h"
 #include "MagickCore/blob-private.h"
 #include "MagickCore/cache.h"
@@ -380,9 +381,15 @@ static Image *ReadCINImage(const ImageInfo *image_info,ExceptionInfo *exception)
 #define MonoColorType  1
 #define RGBColorType  3
 
+  char
+    property[MagickPathExtent];
+
   CINInfo
     cin;
 
+  const unsigned char
+    *pixels;
+
   Image
     *image;
 
@@ -412,8 +419,7 @@ static Image *ReadCINImage(const ImageInfo *image_info,ExceptionInfo *exception)
     y;
 
   unsigned char
-    magick[4],
-    *pixels;
+    magick[4];
 
   /*
     Open image file.
@@ -455,19 +461,22 @@ static Image *ReadCINImage(const ImageInfo *image_info,ExceptionInfo *exception)
   offset+=4;
   offset+=ReadBlob(image,sizeof(cin.file.version),(unsigned char *)
     cin.file.version);
-  (void) SetImageProperty(image,"dpx:file.version",cin.file.version,exception);
+  (void) CopyMagickString(property,cin.file.version,sizeof(cin.file.version));
+  (void) SetImageProperty(image,"dpx:file.version",property,exception);
   offset+=ReadBlob(image,sizeof(cin.file.filename),(unsigned char *)
     cin.file.filename);
-  (void) SetImageProperty(image,"dpx:file.filename",cin.file.filename,
-    exception);
+  (void) CopyMagickString(property,cin.file.filename,sizeof(cin.file.filename));
+  (void) SetImageProperty(image,"dpx:file.filename",property,exception);
   offset+=ReadBlob(image,sizeof(cin.file.create_date),(unsigned char *)
     cin.file.create_date);
-  (void) SetImageProperty(image,"dpx:file.create_date",cin.file.create_date,
-    exception);
+  (void) CopyMagickString(property,cin.file.create_date,
+    sizeof(cin.file.create_date));
+  (void) SetImageProperty(image,"dpx:file.create_date",property,exception);
   offset+=ReadBlob(image,sizeof(cin.file.create_time),(unsigned char *)
     cin.file.create_time);
-  (void) SetImageProperty(image,"dpx:file.create_time",cin.file.create_time,
-    exception);
+  (void) CopyMagickString(property,cin.file.create_time,
+    sizeof(cin.file.create_time));
+  (void) SetImageProperty(image,"dpx:file.create_time",property,exception);
   offset+=ReadBlob(image,sizeof(cin.file.reserve),(unsigned char *)
     cin.file.reserve);
   /*
@@ -475,7 +484,7 @@ static Image *ReadCINImage(const ImageInfo *image_info,ExceptionInfo *exception)
   */
   cin.image.orientation=(unsigned char) ReadBlobByte(image);
   offset++;
-  if (cin.image.orientation != (unsigned char) (~0U))
+  if (cin.image.orientation != (unsigned char) (~0))
     (void) FormatImageProperty(image,"dpx:image.orientation","%d",
       cin.image.orientation);
   switch (cin.image.orientation)
@@ -551,7 +560,8 @@ static Image *ReadCINImage(const ImageInfo *image_info,ExceptionInfo *exception)
     image->chromaticity.blue_primary.y=cin.image.blue_primary_chromaticity[1];
   offset+=ReadBlob(image,sizeof(cin.image.label),(unsigned char *)
     cin.image.label);
-  (void) SetImageProperty(image,"dpx:image.label",cin.image.label,exception);
+  (void) CopyMagickString(property,cin.image.label,sizeof(cin.image.label));
+  (void) SetImageProperty(image,"dpx:image.label",property,exception);
   offset+=ReadBlob(image,sizeof(cin.image.reserve),(unsigned char *)
     cin.image.reserve);
   /*
@@ -586,28 +596,38 @@ static Image *ReadCINImage(const ImageInfo *image_info,ExceptionInfo *exception)
       (double) cin.origination.y_offset);
   offset+=ReadBlob(image,sizeof(cin.origination.filename),(unsigned char *)
     cin.origination.filename);
-  (void) SetImageProperty(image,"dpx:origination.filename",
-    cin.origination.filename,exception);
+  (void) CopyMagickString(property,cin.origination.filename,
+    sizeof(cin.origination.filename));
+  (void) SetImageProperty(image,"dpx:origination.filename",property,exception);
   offset+=ReadBlob(image,sizeof(cin.origination.create_date),(unsigned char *)
     cin.origination.create_date);
-  (void) SetImageProperty(image,"dpx:origination.create_date",
-    cin.origination.create_date,exception);
+  (void) CopyMagickString(property,cin.origination.create_date,
+    sizeof(cin.origination.create_date));
+  (void) SetImageProperty(image,"dpx:origination.create_date",property,
+    exception);
   offset+=ReadBlob(image,sizeof(cin.origination.create_time),(unsigned char *)
     cin.origination.create_time);
-  (void) SetImageProperty(image,"dpx:origination.create_time",
-    cin.origination.create_time,exception);
+  (void) CopyMagickString(property,cin.origination.create_time,
+    sizeof(cin.origination.create_time));
+  (void) SetImageProperty(image,"dpx:origination.create_time",property,
+    exception);
   offset+=ReadBlob(image,sizeof(cin.origination.device),(unsigned char *)
     cin.origination.device);
-  (void) SetImageProperty(image,"dpx:origination.device",
-    cin.origination.device,exception);
+  (void) CopyMagickString(property,cin.origination.device,
+    sizeof(cin.origination.device));
+  (void) SetImageProperty(image,"dpx:origination.device",property,exception);
   offset+=ReadBlob(image,sizeof(cin.origination.model),(unsigned char *)
     cin.origination.model);
-  (void) SetImageProperty(image,"dpx:origination.model",cin.origination.model,
-    exception);
+  (void) CopyMagickString(property,cin.origination.model,
+    sizeof(cin.origination.model));
+  (void) SetImageProperty(image,"dpx:origination.model",property,exception);
+  (void) ResetMagickMemory(cin.origination.serial,0, 
+    sizeof(cin.origination.serial));
   offset+=ReadBlob(image,sizeof(cin.origination.serial),(unsigned char *)
     cin.origination.serial);
-  (void) SetImageProperty(image,"dpx:origination.serial",
-    cin.origination.serial,exception);
+  (void) CopyMagickString(property,cin.origination.serial,
+    sizeof(cin.origination.serial));
+  (void) SetImageProperty(image,"dpx:origination.serial",property,exception);
   cin.origination.x_pitch=ReadBlobFloat(image);
   offset+=4;
   cin.origination.y_pitch=ReadBlobFloat(image);
@@ -653,8 +673,8 @@ static Image *ReadCINImage(const ImageInfo *image_info,ExceptionInfo *exception)
       offset+=4;
       offset+=ReadBlob(image,sizeof(cin.film.format),(unsigned char *)
         cin.film.format);
-      (void) SetImageProperty(image,"dpx:film.format",cin.film.format,
-        exception);
+      (void) CopyMagickString(property,cin.film.format,sizeof(cin.film.format));
+      (void) SetImageProperty(image,"dpx:film.format",property,exception);
       cin.film.frame_position=ReadBlobLong(image);
       offset+=4;
       if (cin.film.frame_position != ~0UL)
@@ -667,12 +687,14 @@ static Image *ReadCINImage(const ImageInfo *image_info,ExceptionInfo *exception)
           cin.film.frame_rate);
       offset+=ReadBlob(image,sizeof(cin.film.frame_id),(unsigned char *)
         cin.film.frame_id);
-      (void) SetImageProperty(image,"dpx:film.frame_id",cin.film.frame_id,
-        exception);
+      (void) CopyMagickString(property,cin.film.frame_id,
+        sizeof(cin.film.frame_id));
+      (void) SetImageProperty(image,"dpx:film.frame_id",property,exception);
       offset+=ReadBlob(image,sizeof(cin.film.slate_info),(unsigned char *)
         cin.film.slate_info);
-      (void) SetImageProperty(image,"dpx:film.slate_info",cin.film.slate_info,
-        exception);
+      (void) CopyMagickString(property,cin.film.slate_info,
+        sizeof(cin.film.slate_info));
+      (void) SetImageProperty(image,"dpx:film.slate_info",property,exception);
       offset+=ReadBlob(image,sizeof(cin.film.reserve),(unsigned char *)
         cin.film.reserve);
     }
@@ -684,7 +706,7 @@ static Image *ReadCINImage(const ImageInfo *image_info,ExceptionInfo *exception)
       /*
         User defined data.
       */
-      profile=BlobToStringInfo((const void *) NULL,cin.file.user_length);
+      profile=BlobToStringInfo((const unsigned char *) NULL,cin.file.user_length);
       if (profile == (StringInfo *) NULL)
         ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
       offset+=ReadBlob(image,GetStringInfoLength(profile),
@@ -692,16 +714,28 @@ static Image *ReadCINImage(const ImageInfo *image_info,ExceptionInfo *exception)
       (void) SetImageProfile(image,"dpx:user.data",profile,exception);
       profile=DestroyStringInfo(profile);
     }
-  for ( ; offset < (MagickOffsetType) cin.file.image_offset; offset++)
-    (void) ReadBlobByte(image);
   image->depth=cin.image.channel[0].bits_per_pixel;
   image->columns=cin.image.channel[0].pixels_per_line;
   image->rows=cin.image.channel[0].lines_per_image;
-  if (image_info->ping)
+  if (image_info->ping != MagickFalse)
     {
       (void) CloseBlob(image);
       return(image);
     }
+  for ( ; offset < (MagickOffsetType) cin.file.image_offset; offset++)
+  {
+    int
+      c;
+
+    c=ReadBlobByte(image);
+    if (c == EOF)
+      break;
+  }
+  if (offset < (MagickOffsetType) cin.file.image_offset)
+    ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+  status=SetImageExtent(image,image->columns,image->rows,exception);
+  if (status == MagickFalse)
+    return(DestroyImageList(image));
   /*
     Convert CIN raster image to pixel packets.
   */
@@ -711,7 +745,6 @@ static Image *ReadCINImage(const ImageInfo *image_info,ExceptionInfo *exception)
   quantum_info->quantum=32;
   quantum_info->pack=MagickFalse;
   quantum_type=RGBQuantum;
-  pixels=GetQuantumPixels(quantum_info);
   length=GetQuantumExtent(image,quantum_info,quantum_type);
   length=GetBytesPerRow(image->columns,3,image->depth,MagickTrue);
   if (cin.image.number_channels == 1)
@@ -724,7 +757,8 @@ static Image *ReadCINImage(const ImageInfo *image_info,ExceptionInfo *exception)
     q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
     if (q == (Quantum *) NULL)
       break;
-    count=ReadBlob(image,length,pixels);
+    pixels=(const unsigned char *) ReadBlobStream(image,length,
+      GetQuantumPixels(quantum_info),&count);
     if ((size_t) count != length)
       break;
     (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,
@@ -744,7 +778,7 @@ static Image *ReadCINImage(const ImageInfo *image_info,ExceptionInfo *exception)
   if (EOFBlob(image) != MagickFalse)
     ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
       image->filename);
-  image->colorspace=LogColorspace;
+  SetImageColorspace(image,LogColorspace,exception);
   (void) CloseBlob(image);
   return(GetFirstImageInList(image));
 }
@@ -776,13 +810,11 @@ ModuleExport size_t RegisterCINImage(void)
   MagickInfo
     *entry;
 
-  entry=SetMagickInfo("CIN");
+  entry=AcquireMagickInfo("CIN","CIN","Cineon Image File");
   entry->decoder=(DecodeImageHandler *) ReadCINImage;
   entry->encoder=(EncodeImageHandler *) WriteCINImage;
   entry->magick=(IsImageFormatHandler *) IsCIN;
-  entry->adjoin=MagickFalse;
-  entry->description=ConstantString("Cineon Image File");
-  entry->module=ConstantString("CIN");
+  entry->flags^=CoderAdjoinFlag;
   (void) RegisterMagickInfo(entry);
   return(MagickImageCoderSignature);
 }
@@ -854,6 +886,9 @@ static inline const char *GetCINProperty(const ImageInfo *image_info,
 static MagickBooleanType WriteCINImage(const ImageInfo *image_info,Image *image,
   ExceptionInfo *exception)
 {
+  char
+    timestamp[MagickPathExtent];
+
   const char
     *value;
 
@@ -953,12 +988,14 @@ static MagickBooleanType WriteCINImage(const ImageInfo *image_info,Image *image,
 #else
   (void) memcpy(&local_time,localtime(&seconds),sizeof(local_time));
 #endif
-  (void) strftime(cin.file.create_date,sizeof(cin.file.create_date),"%Y:%m:%d",
-    &local_time);
+  (void) memset(timestamp,0,sizeof(timestamp));
+  (void) strftime(timestamp,MagickPathExtent,"%Y:%m:%d:%H:%M:%S%Z",&local_time);
+  (void) memset(cin.file.create_date,0,sizeof(cin.file.create_date));
+  (void) CopyMagickString(cin.file.create_date,timestamp,11);
   offset+=WriteBlob(image,sizeof(cin.file.create_date),(unsigned char *)
     cin.file.create_date);
-  (void) strftime(cin.file.create_time,sizeof(cin.file.create_time),
-    "%H:%M:%S%Z",&local_time);
+  (void) memset(cin.file.create_time,0,sizeof(cin.file.create_time));
+  (void) CopyMagickString(cin.file.create_time,timestamp+11,11);
   offset+=WriteBlob(image,sizeof(cin.file.create_time),(unsigned char *)
     cin.file.create_time);
   offset+=WriteBlob(image,sizeof(cin.file.reserve),(unsigned char *)
@@ -1049,12 +1086,16 @@ static MagickBooleanType WriteCINImage(const ImageInfo *image_info,Image *image,
   offset+=WriteBlob(image,sizeof(cin.origination.filename),(unsigned char *)
     cin.origination.filename);
   seconds=time((time_t *) NULL);
-  (void) strftime(cin.origination.create_date,
-    sizeof(cin.origination.create_date),"%Y:%m:%d",&local_time);
+  (void) memset(timestamp,0,sizeof(timestamp));
+  (void) strftime(timestamp,MagickPathExtent,"%Y:%m:%d:%H:%M:%S%Z",&local_time);
+  (void) memset(cin.origination.create_date,0,
+    sizeof(cin.origination.create_date));
+  (void) CopyMagickString(cin.origination.create_date,timestamp,11);
   offset+=WriteBlob(image,sizeof(cin.origination.create_date),(unsigned char *)
     cin.origination.create_date);
-  (void) strftime(cin.origination.create_time,
-    sizeof(cin.origination.create_time),"%H:%M:%S%Z",&local_time);
+  (void) memset(cin.origination.create_time,0,
+     sizeof(cin.origination.create_time));
+  (void) CopyMagickString(cin.origination.create_time,timestamp+11,15);
   offset+=WriteBlob(image,sizeof(cin.origination.create_time),(unsigned char *)
     cin.origination.create_time);
   value=GetCINProperty(image_info,image,"dpx:origination.device",exception);
@@ -1078,12 +1119,12 @@ static MagickBooleanType WriteCINImage(const ImageInfo *image_info,Image *image,
   cin.origination.x_pitch=0.0f;
   value=GetCINProperty(image_info,image,"dpx:origination.x_pitch",exception);
   if (value != (const char *) NULL)
-    cin.origination.x_pitch=InterpretLocaleValue(value,(char **) NULL);
+    cin.origination.x_pitch=StringToDouble(value,(char **) NULL);
   offset+=WriteBlobFloat(image,cin.origination.x_pitch);
   cin.origination.y_pitch=0.0f;
   value=GetCINProperty(image_info,image,"dpx:origination.y_pitch",exception);
   if (value != (const char *) NULL)
-    cin.origination.y_pitch=InterpretLocaleValue(value,(char **) NULL);
+    cin.origination.y_pitch=StringToDouble(value,(char **) NULL);
   offset+=WriteBlobFloat(image,cin.origination.y_pitch);
   cin.origination.gamma=image->gamma;
   offset+=WriteBlobFloat(image,cin.origination.gamma);
@@ -1131,7 +1172,7 @@ static MagickBooleanType WriteCINImage(const ImageInfo *image_info,Image *image,
   cin.film.frame_rate=0.0f;
   value=GetCINProperty(image_info,image,"dpx:film.frame_rate",exception);
   if (value != (const char *) NULL)
-    cin.film.frame_rate=InterpretLocaleValue(value,(char **) NULL);
+    cin.film.frame_rate=StringToDouble(value,(char **) NULL);
   offset+=WriteBlobFloat(image,cin.film.frame_rate);
   value=GetCINProperty(image_info,image,"dpx:film.frame_id",exception);
   if (value != (const char *) NULL)
@@ -1160,12 +1201,14 @@ static MagickBooleanType WriteCINImage(const ImageInfo *image_info,Image *image,
   quantum_info->quantum=32;
   quantum_info->pack=MagickFalse;
   quantum_type=RGBQuantum;
-  pixels=GetQuantumPixels(quantum_info);
+  pixels=(unsigned char *) GetQuantumPixels(quantum_info);
   length=GetBytesPerRow(image->columns,3,image->depth,MagickTrue);
+DisableMSCWarning(4127)
   if (0)
+RestoreMSCWarning
     {
       quantum_type=GrayQuantum;
-      length=GetBytesPerRow(image->columns,3,image->depth,MagickTrue);
+      length=GetBytesPerRow(image->columns,1,image->depth,MagickTrue);
     }
   for (y=0; y < (ssize_t) image->rows; y++)
   {