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-2012 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 "MagickCore/studio.h"
43 #include "MagickCore/blob.h"
44 #include "MagickCore/blob-private.h"
45 #include "MagickCore/cache.h"
46 #include "MagickCore/colormap.h"
47 #include "MagickCore/constitute.h"
48 #include "MagickCore/exception.h"
49 #include "MagickCore/exception-private.h"
50 #include "MagickCore/image.h"
51 #include "MagickCore/image-private.h"
52 #include "MagickCore/list.h"
53 #include "MagickCore/magick.h"
54 #include "MagickCore/memory_.h"
55 #include "MagickCore/monitor.h"
56 #include "MagickCore/monitor-private.h"
57 #include "MagickCore/pixel-accessor.h"
58 #include "MagickCore/quantum-private.h"
59 #include "MagickCore/static.h"
60 #include "MagickCore/string_.h"
61 #include "MagickCore/module.h"
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 % R e a d S T E G A N O I m a g e %
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 % ReadSTEGANOImage() reads a steganographic image hidden within another
75 % image type. It allocates the memory necessary for the new Image structure
76 % and returns a pointer to the new image.
78 % The format of the ReadSTEGANOImage method is:
80 % Image *ReadSTEGANOImage(const ImageInfo *image_info,
81 % ExceptionInfo *exception)
83 % A description of each parameter follows:
85 % o image_info: the image info.
87 % o exception: return any errors or warnings in this structure.
91 static inline size_t MagickMin(const size_t x,
99 static Image *ReadSTEGANOImage(const ImageInfo *image_info,
100 ExceptionInfo *exception)
102 #define GetBit(alpha,i) MagickMin((((size_t) (alpha) >> (size_t) \
104 #define SetBit(i,set) SetPixelIndex(image,((set) != 0 ? \
105 (size_t) GetPixelIndex(image,q) | (one << (size_t) (i)) : \
106 (size_t) GetPixelIndex(image,q) & ~(one << (size_t) (i))),q)
141 Initialize Image structure.
143 assert(image_info != (const ImageInfo *) NULL);
144 assert(image_info->signature == MagickSignature);
145 if (image_info->debug != MagickFalse)
146 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
147 image_info->filename);
148 assert(exception != (ExceptionInfo *) NULL);
149 assert(exception->signature == MagickSignature);
151 image=AcquireImage(image_info,exception);
152 if ((image->columns == 0) || (image->rows == 0))
153 ThrowReaderException(OptionError,"MustSpecifyImageSize");
154 read_info=CloneImageInfo(image_info);
155 SetImageInfoBlob(read_info,(void *) NULL,0);
156 *read_info->magick='\0';
157 watermark=ReadImage(read_info,exception);
158 read_info=DestroyImageInfo(read_info);
159 if (watermark == (Image *) NULL)
160 return((Image *) NULL);
161 watermark->depth=MAGICKCORE_QUANTUM_DEPTH;
162 if (AcquireImageColormap(image,MaxColormapSize,exception) == MagickFalse)
163 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
164 if (image_info->ping != MagickFalse)
166 (void) CloseBlob(image);
167 return(GetFirstImageInList(image));
170 Get hidden watermark from low-order bits of image.
175 i=(ssize_t) (watermark->depth-1);
176 depth=watermark->depth;
177 for (k=image->offset; (i >= 0) && (j < (ssize_t) depth); i--)
179 for (y=0; (y < (ssize_t) image->rows) && (j < (ssize_t) depth); y++)
182 for ( ; (x < (ssize_t) image->columns) && (j < (ssize_t) depth); x++)
185 virtual_pixel[MaxPixelChannels];
187 if ((k/(ssize_t) watermark->columns) >= (ssize_t) watermark->rows)
189 (void) GetOneVirtualPixel(watermark,k % (ssize_t) watermark->columns,
190 k/(ssize_t) watermark->columns,virtual_pixel,exception);
191 pixel.red=virtual_pixel[RedPixelChannel];
192 pixel.green=virtual_pixel[GreenPixelChannel];
193 pixel.blue=virtual_pixel[BluePixelChannel];
194 pixel.alpha=virtual_pixel[AlphaPixelChannel];
195 q=GetAuthenticPixels(image,x,y,1,1,exception);
196 if (q == (Quantum *) NULL)
202 SetBit(i,GetBit(pixel.red,j));
207 SetBit(i,GetBit(pixel.green,j));
212 SetBit(i,GetBit(pixel.blue,j));
216 if (SyncAuthenticPixels(image,exception) == MagickFalse)
222 if (k == (ssize_t) (watermark->columns*watermark->columns))
224 if (k == image->offset)
228 status=SetImageProgress(image,LoadImagesTag,(MagickOffsetType) i,depth);
229 if (status == MagickFalse)
232 watermark=DestroyImage(watermark);
233 (void) SyncImage(image,exception);
234 return(GetFirstImageInList(image));
238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242 % R e g i s t e r S T E G A N O I m a g e %
246 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248 % RegisterSTEGANOImage() adds attributes for the STEGANO image format to
249 % the list of supported formats. The attributes include the image format
250 % tag, a method to read and/or write the format, whether the format
251 % supports the saving of more than one frame to the same file or blob,
252 % whether the format supports native in-memory I/O, and a brief
253 % description of the format.
255 % The format of the RegisterSTEGANOImage method is:
257 % size_t RegisterSTEGANOImage(void)
260 ModuleExport size_t RegisterSTEGANOImage(void)
265 entry=SetMagickInfo("STEGANO");
266 entry->decoder=(DecodeImageHandler *) ReadSTEGANOImage;
267 entry->format_type=ImplicitFormatType;
268 entry->description=ConstantString("Steganographic image");
269 entry->module=ConstantString("STEGANO");
270 (void) RegisterMagickInfo(entry);
271 return(MagickImageCoderSignature);
275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
279 % U n r e g i s t e r S T E G A N O I m a g e %
283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285 % UnregisterSTEGANOImage() removes format registrations made by the
286 % STEGANO module from the list of supported formats.
288 % The format of the UnregisterSTEGANOImage method is:
290 % UnregisterSTEGANOImage(void)
293 ModuleExport void UnregisterSTEGANOImage(void)
295 (void) UnregisterMagickInfo("STEGANO");