]> granicus.if.org Git - imagemagick/blobdiff - coders/stegano.c
Removed png_write_chunk_from_profile()
[imagemagick] / coders / stegano.c
index 995191290ff396a8bfa3d066abf775d16725b2e8..dc80d8e806009f8237c44959818503841fad9913 100644 (file)
 %                       Write A Steganographic Image.                         %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                                 July 1992                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2017 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  %
 %  obtain a copy of the License at                                            %
 %                                                                             %
-%    http://www.imagemagick.org/script/license.php                            %
+%    https://www.imagemagick.org/script/license.php                           %
 %                                                                             %
 %  Unless required by applicable law or agreed to in writing, software        %
 %  distributed under the License is distributed on an "AS IS" BASIS,          %
 %    o exception: return any errors or warnings in this structure.
 %
 */
-
-static inline size_t MagickMin(const size_t x,
-  const size_t y)
-{
-  if (x < y)
-    return(x);
-  return(y);
-}
-
 static Image *ReadSTEGANOImage(const ImageInfo *image_info,
   ExceptionInfo *exception)
 {
-#define GetBit(alpha,i) MagickMin((((size_t) (alpha) >> (size_t) \
-  (i)) & 0x01),16)
-#define SetBit(i,set) SetPixelIndex(image,((set) != 0 ? \
+#define GetBit(alpha,i) (((size_t) (alpha) >> (size_t) (i)) & 0x01)
+#define SetBit(i,set) SetPixelIndex(image,(Quantum) ((set) != 0 ? \
   (size_t) GetPixelIndex(image,q) | (one << (size_t) (i)) : \
   (size_t) GetPixelIndex(image,q) & ~(one << (size_t) (i))),q)
 
@@ -118,7 +108,7 @@ static Image *ReadSTEGANOImage(const ImageInfo *image_info,
   MagickBooleanType
     status;
 
-  PixelPacket
+  PixelInfo
     pixel;
 
   register Quantum
@@ -141,12 +131,12 @@ static Image *ReadSTEGANOImage(const ImageInfo *image_info,
     Initialize Image structure.
   */
   assert(image_info != (const ImageInfo *) NULL);
-  assert(image_info->signature == MagickSignature);
+  assert(image_info->signature == MagickCoreSignature);
   if (image_info->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       image_info->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   one=1;
   image=AcquireImage(image_info,exception);
   if ((image->columns == 0) || (image->rows == 0))
@@ -166,6 +156,22 @@ static Image *ReadSTEGANOImage(const ImageInfo *image_info,
       (void) CloseBlob(image);
       return(GetFirstImageInList(image));
     }
+  status=SetImageExtent(image,image->columns,image->rows,exception);
+  if (status == MagickFalse)
+    return(DestroyImageList(image));
+  for (y=0; y < (ssize_t) image->rows; y++)
+  {
+    q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
+    if (q == (Quantum *) NULL)
+      break;
+    for (x=0; x < (ssize_t) image->columns; x++)
+    {
+      SetPixelIndex(image,0,q);
+      q+=GetPixelChannels(image);
+    }
+    if (SyncAuthenticPixels(image,exception) == MagickFalse)
+      break;
+  }
   /*
     Get hidden watermark from low-order bits of image.
   */
@@ -181,17 +187,11 @@ static Image *ReadSTEGANOImage(const ImageInfo *image_info,
       x=0;
       for ( ; (x < (ssize_t) image->columns) && (j < (ssize_t) depth); x++)
       {
-        Quantum
-          virtual_pixel[MaxPixelChannels];
-
         if ((k/(ssize_t) watermark->columns) >= (ssize_t) watermark->rows)
           break;
-        (void) GetOneVirtualPixel(watermark,k % (ssize_t) watermark->columns,
-          k/(ssize_t) watermark->columns,virtual_pixel,exception);
-        pixel.red=virtual_pixel[RedPixelChannel];
-        pixel.green=virtual_pixel[GreenPixelChannel];
-        pixel.blue=virtual_pixel[BluePixelChannel];
-        pixel.alpha=virtual_pixel[AlphaPixelChannel];
+        (void) GetOneVirtualPixelInfo(watermark,UndefinedVirtualPixelMethod,
+          k % (ssize_t) watermark->columns,k/(ssize_t) watermark->columns,
+          &pixel,exception);
         q=GetAuthenticPixels(image,x,y,1,1,exception);
         if (q == (Quantum *) NULL)
           break;
@@ -230,7 +230,7 @@ static Image *ReadSTEGANOImage(const ImageInfo *image_info,
       break;
   }
   watermark=DestroyImage(watermark);
-  (void) SyncImage(image);
+  (void) SyncImage(image,exception);
   return(GetFirstImageInList(image));
 }
 \f
@@ -262,11 +262,9 @@ ModuleExport size_t RegisterSTEGANOImage(void)
   MagickInfo
     *entry;
 
-  entry=SetMagickInfo("STEGANO");
+  entry=AcquireMagickInfo("STEGANO","STEGANO","Steganographic image");
   entry->decoder=(DecodeImageHandler *) ReadSTEGANOImage;
   entry->format_type=ImplicitFormatType;
-  entry->description=ConstantString("Steganographic image");
-  entry->module=ConstantString("STEGANO");
   (void) RegisterMagickInfo(entry);
   return(MagickImageCoderSignature);
 }