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-2010 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) | (1UL << (size_t) (i)) : (size_t) \
105 (alpha) & ~(1UL << (size_t) (i)))
140 Initialize Image structure.
142 assert(image_info != (const ImageInfo *) NULL);
143 assert(image_info->signature == MagickSignature);
144 if (image_info->debug != MagickFalse)
145 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
146 image_info->filename);
147 assert(exception != (ExceptionInfo *) NULL);
148 assert(exception->signature == MagickSignature);
149 image=AcquireImage(image_info);
150 if ((image->columns == 0) || (image->rows == 0))
151 ThrowReaderException(OptionError,"MustSpecifyImageSize");
152 read_info=CloneImageInfo(image_info);
153 SetImageInfoBlob(read_info,(void *) NULL,0);
154 *read_info->magick='\0';
155 watermark=ReadImage(read_info,exception);
156 read_info=DestroyImageInfo(read_info);
157 if (watermark == (Image *) NULL)
158 return((Image *) NULL);
159 watermark->depth=MAGICKCORE_QUANTUM_DEPTH;
160 if (AcquireImageColormap(image,MaxColormapSize) == MagickFalse)
161 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
162 if (image_info->ping != MagickFalse)
164 (void) CloseBlob(image);
165 return(GetFirstImageInList(image));
168 Get hidden watermark from low-order bits of image.
173 i=MAGICKCORE_QUANTUM_DEPTH-1;
174 depth=MAGICKCORE_QUANTUM_DEPTH;
175 for (k=image->offset; (i >= 0) && (j < (ssize_t) depth); i--)
177 for (y=0; (y < (ssize_t) image->rows) && (j < (ssize_t) depth); y++)
180 for (; (x < (ssize_t) image->columns) && (j < (ssize_t) depth); x++)
182 if ((k/(ssize_t) watermark->columns) >= (ssize_t) watermark->rows)
184 (void) GetOneVirtualPixel(watermark,k % (ssize_t) watermark->columns,
185 k/(ssize_t) watermark->columns,&pixel,exception);
186 q=GetAuthenticPixels(image,x,y,1,1,exception);
187 if (q == (PixelPacket *) NULL)
189 indexes=GetAuthenticIndexQueue(image);
194 SetBit(*indexes,i,GetBit(pixel.red,j));
199 SetBit(*indexes,i,GetBit(pixel.green,j));
204 SetBit(*indexes,i,GetBit(pixel.blue,j));
208 if (SyncAuthenticPixels(image,exception) == MagickFalse)
214 if (k == (ssize_t) (watermark->columns*watermark->columns))
216 if (k == image->offset)
220 status=SetImageProgress(image,LoadImagesTag,i,depth);
221 if (status == MagickFalse)
224 watermark=DestroyImage(watermark);
225 (void) SyncImage(image);
226 return(GetFirstImageInList(image));
230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234 % R e g i s t e r S T E G A N O I m a g e %
238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240 % RegisterSTEGANOImage() adds attributes for the STEGANO image format to
241 % the list of supported formats. The attributes include the image format
242 % tag, a method to read and/or write the format, whether the format
243 % supports the saving of more than one frame to the same file or blob,
244 % whether the format supports native in-memory I/O, and a brief
245 % description of the format.
247 % The format of the RegisterSTEGANOImage method is:
249 % size_t RegisterSTEGANOImage(void)
252 ModuleExport size_t RegisterSTEGANOImage(void)
257 entry=SetMagickInfo("STEGANO");
258 entry->decoder=(DecodeImageHandler *) ReadSTEGANOImage;
259 entry->format_type=ExplicitFormatType;
260 entry->description=ConstantString("Steganographic image");
261 entry->module=ConstantString("STEGANO");
262 (void) RegisterMagickInfo(entry);
263 return(MagickImageCoderSignature);
267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
271 % U n r e g i s t e r S T E G A N O I m a g e %
275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
277 % UnregisterSTEGANOImage() removes format registrations made by the
278 % STEGANO module from the list of supported formats.
280 % The format of the UnregisterSTEGANOImage method is:
282 % UnregisterSTEGANOImage(void)
285 ModuleExport void UnregisterSTEGANOImage(void)
287 (void) UnregisterMagickInfo("STEGANO");