]> granicus.if.org Git - imagemagick/commitdiff
(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Mon, 20 Aug 2012 00:01:19 +0000 (00:01 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Mon, 20 Aug 2012 00:01:19 +0000 (00:01 +0000)
MagickCore/stream.c

index 2c0453b51957b0de9b83eb8c18700c7af4100a06..5bd9832b76dc91649cacf8e79438f7eb81c4659e 100644 (file)
@@ -619,8 +619,8 @@ static const Quantum *GetVirtualPixelsStream(const Image *image)
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  GetVirtualMetacontentFromStream() returns the associated pixel 
-%  channels corresponding with the last call to QueueAuthenticPixelsStream() or
+%  GetVirtualMetacontentFromStream() returns the associated pixel channels
+%  corresponding with the last call to QueueAuthenticPixelsStream() or
 %  GetVirtualPixelStream().
 %
 %  The format of the GetVirtualMetacontentFromStream() method is:
@@ -632,8 +632,7 @@ static const Quantum *GetVirtualPixelsStream(const Image *image)
 %    o image: the image.
 %
 */
-static const void *GetVirtualMetacontentFromStream(
-  const Image *image)
+static const void *GetVirtualMetacontentFromStream(const Image *image)
 {
   CacheInfo
     *cache_info;
@@ -700,7 +699,7 @@ static inline MagickBooleanType AcquireStreamPixels(CacheInfo *cache_info,
   if (cache_info->pixels == (Quantum *) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),
-        ResourceLimitError,"MemoryAllocationFailed","`%s'",
+        ResourceLimitError,"MemoryAllocationFailed","'%s'",
         cache_info->filename);
       return(MagickFalse);
     }
@@ -737,7 +736,7 @@ static const Quantum *GetVirtualPixelStream(const Image *image,
       (columns == 0) || (rows == 0))
     {
       (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
-        "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
+        "ImageDoesNotContainTheStreamGeometry","'%s'",image->filename);
       return((Quantum *) NULL);
     }
   cache_info=(CacheInfo *) image->cache;
@@ -856,6 +855,9 @@ static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
   CacheInfo
     *cache_info;
 
+  MagickBooleanType
+    status;
+
   MagickSizeType
     number_pixels;
 
@@ -875,14 +877,14 @@ static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
       (columns == 0) || (rows == 0))
     {
       (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
-        "ImageDoesNotContainTheStreamGeometry","`%s'",image->filename);
+        "ImageDoesNotContainTheStreamGeometry","'%s'",image->filename);
       return((Quantum *) NULL);
     }
   stream_handler=GetBlobStreamHandler(image);
   if (stream_handler == (StreamHandler) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
-        "NoStreamHandlerIsDefined","`%s'",image->filename);
+        "NoStreamHandlerIsDefined","'%s'",image->filename);
       return((Quantum *) NULL);
     }
   cache_info=(CacheInfo *) image->cache;
@@ -906,22 +908,32 @@ static Quantum *QueueAuthenticPixelsStream(Image *image,const ssize_t x,
   cache_info->rows=rows;
   number_pixels=(MagickSizeType) columns*rows;
   length=(size_t) number_pixels*cache_info->number_channels*sizeof(Quantum);
+  if (length == 0)
+    length=number_pixels*sizeof(Quantum);
   if (cache_info->metacontent_extent != 0)
     length+=number_pixels*cache_info->metacontent_extent;
   if (cache_info->pixels == (Quantum *) NULL)
     {
-      cache_info->pixels=(Quantum *) AcquireAlignedMemory(1,length);
-      cache_info->length=(MagickSizeType) length;
+      cache_info->length=length;
+      status=AcquireStreamPixels(cache_info,exception);
+      if (status == MagickFalse)
+        {
+          cache_info->length=0;
+          return((Quantum *) NULL);
+        }
     }
   else
-    if (cache_info->length < (MagickSizeType) length)
+    if (cache_info->length < length)
       {
-        (void) RelinquishAlignedMemory(cache_info->pixels);
-        cache_info->pixels=(Quantum *) AcquireAlignedMemory(1,length);
-        cache_info->length=(MagickSizeType) length;
+        RelinquishStreamPixels(cache_info);
+        cache_info->length=length;
+        status=AcquireStreamPixels(cache_info,exception);
+        if (status == MagickFalse)
+          {
+            cache_info->length=0;
+            return((Quantum *) NULL);
+          }
       }
-  if (cache_info->pixels == (void *) NULL)
-    return((Quantum *) NULL);
   cache_info->metacontent=(void *) NULL;
   if (cache_info->metacontent_extent != 0)
     cache_info->metacontent=(void *) (cache_info->pixels+number_pixels*
@@ -1178,8 +1190,7 @@ static size_t WriteStreamImage(const Image *image,const void *pixels,
         Prepare stream for writing.
       */
       (void) RelinquishAlignedMemory(stream_info->pixels);
-      stream_info->pixels=(unsigned char *) AcquireAlignedMemory(length,
-        sizeof(*stream_info->pixels));
+      stream_info->pixels=(unsigned char *) AcquireAlignedMemory(1,length);
       if (stream_info->pixels == (unsigned char *) NULL)
         return(0);
       (void) ResetMagickMemory(stream_info->pixels,0,length);
@@ -1312,7 +1323,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
   if (quantum_map == (QuantumType *) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),
-        ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
+        ResourceLimitError,"MemoryAllocationFailed","'%s'",image->filename);
       return(MagickFalse);
     }
   for (i=0; i < (ssize_t) length; i++)
@@ -1339,7 +1350,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
           break;
         quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
         (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
-          "ColorSeparatedImageRequired","`%s'",stream_info->map);
+          "ColorSeparatedImageRequired","'%s'",stream_info->map);
         return(MagickFalse);
       }
       case 'g':
@@ -1362,7 +1373,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
           break;
         quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
         (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
-          "ColorSeparatedImageRequired","`%s'",stream_info->map);
+          "ColorSeparatedImageRequired","'%s'",stream_info->map);
         return(MagickFalse);
       }
       case 'M':
@@ -1373,7 +1384,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
           break;
         quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
         (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
-          "ColorSeparatedImageRequired","`%s'",stream_info->map);
+          "ColorSeparatedImageRequired","'%s'",stream_info->map);
         return(MagickFalse);
       }
       case 'o':
@@ -1402,14 +1413,14 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
           break;
         quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
         (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
-          "ColorSeparatedImageRequired","`%s'",stream_info->map);
+          "ColorSeparatedImageRequired","'%s'",stream_info->map);
         return(MagickFalse);
       }
       default:
       {
         quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
         (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
-          "UnrecognizedPixelMap","`%s'",stream_info->map);
+          "UnrecognizedPixelMap","'%s'",stream_info->map);
         return(MagickFalse);
       }
     }
@@ -2629,7 +2640,7 @@ static MagickBooleanType StreamImagePixels(const StreamInfo *stream_info,
     {
       quantum_map=(QuantumType *) RelinquishMagickMemory(quantum_map);
       (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
-        "UnrecognizedPixelMap","`%s'",stream_info->map);
+        "UnrecognizedPixelMap","'%s'",stream_info->map);
       break;
     }
   }
@@ -2685,7 +2696,7 @@ static MagickBooleanType SyncAuthenticPixelsStream(Image *image,
   if (stream_handler == (StreamHandler) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),StreamError,
-        "NoStreamHandlerIsDefined","`%s'",image->filename);
+        "NoStreamHandlerIsDefined","'%s'",image->filename);
       return(MagickFalse);
     }
   length=stream_handler(image,cache_info->pixels,(size_t) cache_info->columns);