2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % SSSSS TTTTT EEEEE GGGG AAA N N OOO %
7 % SS T E G A A NN N O O %
8 % SSS T EEE G GG AAAAA N N N O O %
9 % SS T E G G A A N NN O O %
10 % SSSSS T EEEEE GGG A A N N OOO %
13 % Write A Steganographic Image. %
20 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "magick/studio.h"
43 #include "magick/blob.h"
44 #include "magick/blob-private.h"
45 #include "magick/cache.h"
46 #include "magick/colormap.h"
47 #include "magick/constitute.h"
48 #include "magick/exception.h"
49 #include "magick/exception-private.h"
50 #include "magick/image.h"
51 #include "magick/image-private.h"
52 #include "magick/list.h"
53 #include "magick/magick.h"
54 #include "magick/memory_.h"
55 #include "magick/monitor.h"
56 #include "magick/monitor-private.h"
57 #include "magick/quantum-private.h"
58 #include "magick/static.h"
59 #include "magick/string_.h"
60 #include "magick/module.h"
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 % R e a d S T E G A N O I m a g e %
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 % ReadSTEGANOImage() reads a steganographic image hidden within another
74 % image type. It allocates the memory necessary for the new Image structure
75 % and returns a pointer to the new image.
77 % The format of the ReadSTEGANOImage method is:
79 % Image *ReadSTEGANOImage(const ImageInfo *image_info,
80 % ExceptionInfo *exception)
82 % A description of each parameter follows:
84 % o image_info: the image info.
86 % o exception: return any errors or warnings in this structure.
90 static inline size_t MagickMin(const size_t x,
98 static Image *ReadSTEGANOImage(const ImageInfo *image_info,
99 ExceptionInfo *exception)
101 #define GetBit(alpha,i) MagickMin((((size_t) (alpha) >> (size_t) \
103 #define SetBit(alpha,i,set) (alpha)=(IndexPacket) ((set) != 0 ? \
104 (size_t) (alpha) | (one << (size_t) (i)) : (size_t) \
105 (alpha) & ~(one << (size_t) (i)))
143 Initialize Image structure.
145 assert(image_info != (const ImageInfo *) NULL);
146 assert(image_info->signature == MagickSignature);
147 if (image_info->debug != MagickFalse)
148 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
149 image_info->filename);
150 assert(exception != (ExceptionInfo *) NULL);
151 assert(exception->signature == MagickSignature);
153 image=AcquireImage(image_info);
154 if ((image->columns == 0) || (image->rows == 0))
155 ThrowReaderException(OptionError,"MustSpecifyImageSize");
156 read_info=CloneImageInfo(image_info);
157 SetImageInfoBlob(read_info,(void *) NULL,0);
158 *read_info->magick='\0';
159 watermark=ReadImage(read_info,exception);
160 read_info=DestroyImageInfo(read_info);
161 if (watermark == (Image *) NULL)
162 return((Image *) NULL);
163 watermark->depth=MAGICKCORE_QUANTUM_DEPTH;
164 if (AcquireImageColormap(image,MaxColormapSize) == MagickFalse)
165 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
166 if (image_info->ping != MagickFalse)
168 (void) CloseBlob(image);
169 return(GetFirstImageInList(image));
172 Get hidden watermark from low-order bits of image.
177 i=(ssize_t) (watermark->depth-1);
178 depth=watermark->depth;
179 for (k=image->offset; (i >= 0) && (j < (ssize_t) depth); i--)
181 for (y=0; (y < (ssize_t) image->rows) && (j < (ssize_t) depth); y++)
184 for ( ; (x < (ssize_t) image->columns) && (j < (ssize_t) depth); x++)
186 if ((k/(ssize_t) watermark->columns) >= (ssize_t) watermark->rows)
188 (void) GetOneVirtualPixel(watermark,k % (ssize_t) watermark->columns,
189 k/(ssize_t) watermark->columns,&pixel,exception);
190 q=GetAuthenticPixels(image,x,y,1,1,exception);
191 if (q == (PixelPacket *) NULL)
193 indexes=GetAuthenticIndexQueue(image);
198 SetBit(*indexes,i,GetBit(pixel.red,j));
203 SetBit(*indexes,i,GetBit(pixel.green,j));
208 SetBit(*indexes,i,GetBit(pixel.blue,j));
212 if (SyncAuthenticPixels(image,exception) == MagickFalse)
218 if (k == (ssize_t) (watermark->columns*watermark->columns))
220 if (k == image->offset)
224 status=SetImageProgress(image,LoadImagesTag,(MagickOffsetType) i,depth);
225 if (status == MagickFalse)
228 watermark=DestroyImage(watermark);
229 (void) SyncImage(image);
230 return(GetFirstImageInList(image));
234 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238 % R e g i s t e r S T E G A N O I m a g e %
242 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244 % RegisterSTEGANOImage() adds attributes for the STEGANO image format to
245 % the list of supported formats. The attributes include the image format
246 % tag, a method to read and/or write the format, whether the format
247 % supports the saving of more than one frame to the same file or blob,
248 % whether the format supports native in-memory I/O, and a brief
249 % description of the format.
251 % The format of the RegisterSTEGANOImage method is:
253 % size_t RegisterSTEGANOImage(void)
256 ModuleExport size_t RegisterSTEGANOImage(void)
261 entry=SetMagickInfo("STEGANO");
262 entry->decoder=(DecodeImageHandler *) ReadSTEGANOImage;
263 entry->format_type=ImplicitFormatType;
264 entry->description=ConstantString("Steganographic image");
265 entry->module=ConstantString("STEGANO");
266 (void) RegisterMagickInfo(entry);
267 return(MagickImageCoderSignature);
271 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
275 % U n r e g i s t e r S T E G A N O I m a g e %
279 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
281 % UnregisterSTEGANOImage() removes format registrations made by the
282 % STEGANO module from the list of supported formats.
284 % The format of the UnregisterSTEGANOImage method is:
286 % UnregisterSTEGANOImage(void)
289 ModuleExport void UnregisterSTEGANOImage(void)
291 (void) UnregisterMagickInfo("STEGANO");