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-2009 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/constitute.h"
47 #include "magick/exception.h"
48 #include "magick/exception-private.h"
49 #include "magick/image.h"
50 #include "magick/image-private.h"
51 #include "magick/list.h"
52 #include "magick/magick.h"
53 #include "magick/memory_.h"
54 #include "magick/monitor.h"
55 #include "magick/monitor-private.h"
56 #include "magick/quantum-private.h"
57 #include "magick/static.h"
58 #include "magick/string_.h"
59 #include "magick/module.h"
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 % R e a d S T E G A N O I m a g e %
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 % ReadSTEGANOImage() reads a steganographic image hidden within another
73 % image type. It allocates the memory necessary for the new Image structure
74 % and returns a pointer to the new image.
76 % The format of the ReadSTEGANOImage method is:
78 % Image *ReadSTEGANOImage(const ImageInfo *image_info,
79 % ExceptionInfo *exception)
81 % A description of each parameter follows:
83 % o image_info: the image info.
85 % o exception: return any errors or warnings in this structure.
89 static inline unsigned long MagickMin(const unsigned long x,
90 const unsigned long y)
97 static Image *ReadSTEGANOImage(const ImageInfo *image_info,
98 ExceptionInfo *exception)
100 #define GetBit(alpha,i) MagickMin((((unsigned long) (alpha) >> (unsigned long) \
102 #define SetBit(alpha,i,set) (alpha)=(IndexPacket) ((set) != 0 ? \
103 (unsigned long) (alpha) | (1UL << (unsigned long) (i)) : (unsigned long) \
104 (alpha) & ~(1UL << (unsigned long) (i)))
139 Initialize Image structure.
141 assert(image_info != (const ImageInfo *) NULL);
142 assert(image_info->signature == MagickSignature);
143 if (image_info->debug != MagickFalse)
144 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
145 image_info->filename);
146 assert(exception != (ExceptionInfo *) NULL);
147 assert(exception->signature == MagickSignature);
148 image=AcquireImage(image_info);
149 if ((image->columns == 0) || (image->rows == 0))
150 ThrowReaderException(OptionError,"MustSpecifyImageSize");
151 read_info=CloneImageInfo(image_info);
152 SetImageInfoBlob(read_info,(void *) NULL,0);
153 *read_info->magick='\0';
154 watermark=ReadImage(read_info,exception);
155 read_info=DestroyImageInfo(read_info);
156 if (watermark == (Image *) NULL)
157 return((Image *) NULL);
158 watermark->depth=MAGICKCORE_QUANTUM_DEPTH;
159 if (AcquireImageColormap(image,MaxColormapSize) == MagickFalse)
160 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
161 if (image_info->ping != MagickFalse)
163 (void) CloseBlob(image);
164 return(GetFirstImageInList(image));
167 Get hidden watermark from low-order bits of image.
172 i=MAGICKCORE_QUANTUM_DEPTH-1;
173 depth=MAGICKCORE_QUANTUM_DEPTH;
174 for (k=image->offset; (i >= 0) && (j < (long) depth); i--)
176 for (y=0; (y < (long) image->rows) && (j < (long) depth); y++)
179 for (; (x < (long) image->columns) && (j < (long) depth); x++)
181 if ((k/(long) watermark->columns) >= (long) watermark->rows)
183 (void) GetOneVirtualPixel(watermark,k % (long) watermark->columns,
184 k/(long) watermark->columns,&pixel,exception);
185 q=GetAuthenticPixels(image,x,y,1,1,exception);
186 if (q == (PixelPacket *) NULL)
188 indexes=GetAuthenticIndexQueue(image);
193 SetBit(*indexes,i,GetBit(pixel.red,j));
198 SetBit(*indexes,i,GetBit(pixel.green,j));
203 SetBit(*indexes,i,GetBit(pixel.blue,j));
207 if (SyncAuthenticPixels(image,exception) == MagickFalse)
213 if (k == (long) (watermark->columns*watermark->columns))
215 if (k == image->offset)
219 status=SetImageProgress(image,LoadImagesTag,i,depth);
220 if (status == MagickFalse)
223 watermark=DestroyImage(watermark);
224 (void) SyncImage(image);
225 return(GetFirstImageInList(image));
229 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233 % R e g i s t e r S T E G A N O I m a g e %
237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239 % RegisterSTEGANOImage() adds attributes for the STEGANO image format to
240 % the list of supported formats. The attributes include the image format
241 % tag, a method to read and/or write the format, whether the format
242 % supports the saving of more than one frame to the same file or blob,
243 % whether the format supports native in-memory I/O, and a brief
244 % description of the format.
246 % The format of the RegisterSTEGANOImage method is:
248 % unsigned long RegisterSTEGANOImage(void)
251 ModuleExport unsigned long RegisterSTEGANOImage(void)
256 entry=SetMagickInfo("STEGANO");
257 entry->decoder=(DecodeImageHandler *) ReadSTEGANOImage;
258 entry->format_type=ExplicitFormatType;
259 entry->description=ConstantString("Steganographic image");
260 entry->module=ConstantString("STEGANO");
261 (void) RegisterMagickInfo(entry);
262 return(MagickImageCoderSignature);
266 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
270 % U n r e g i s t e r S T E G A N O I m a g e %
274 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
276 % UnregisterSTEGANOImage() removes format registrations made by the
277 % STEGANO module from the list of supported formats.
279 % The format of the UnregisterSTEGANOImage method is:
281 % UnregisterSTEGANOImage(void)
284 ModuleExport void UnregisterSTEGANOImage(void)
286 (void) UnregisterMagickInfo("STEGANO");