2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % TTTTT H H U U M M BBBB N N AAA IIIII L %
7 % T H H U U MM MM B B NN N A A I L %
8 % T HHHHH U U M M M BBBB N N N AAAAA I L %
9 % T H H U U M M B B N NN A A I L %
10 % T H H UUU M M BBBB N N A A IIIII LLLLL %
13 % Write EXIF Thumbnail To File. %
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/constitute.h"
46 #include "magick/exception.h"
47 #include "magick/exception-private.h"
48 #include "magick/magick.h"
49 #include "magick/memory_.h"
50 #include "magick/module.h"
51 #include "magick/monitor.h"
52 #include "magick/monitor-private.h"
53 #include "magick/profile.h"
54 #include "magick/property.h"
55 #include "magick/quantum-private.h"
56 #include "magick/static.h"
57 #include "magick/string_.h"
58 #include "magick/string-private.h"
63 static MagickBooleanType
64 WriteTHUMBNAILImage(const ImageInfo *,Image *);
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 % R e g i s t e r T H U M B N A I L I m a g e %
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 % RegisterTHUMBNAILImage() adds attributes for the THUMBNAIL image format to
78 % the list of supported formats. The attributes include the image format
79 % tag, a method to read and/or write the format, whether the format
80 % supports the saving of more than one frame to the same file or blob,
81 % whether the format supports native in-memory I/O, and a brief
82 % description of the format.
84 % The format of the RegisterTHUMBNAILImage method is:
86 % size_t RegisterTHUMBNAILImage(void)
89 ModuleExport size_t RegisterTHUMBNAILImage(void)
94 entry=SetMagickInfo("THUMBNAIL");
95 entry->encoder=(EncodeImageHandler *) WriteTHUMBNAILImage;
96 entry->description=ConstantString("EXIF Profile Thumbnail");
97 entry->module=ConstantString("THUMBNAIL");
98 (void) RegisterMagickInfo(entry);
99 return(MagickImageCoderSignature);
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 % U n r e g i s t e r T H U M B N A I L I m a g e %
111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 % UnregisterTHUMBNAILImage() removes format registrations made by the
114 % THUMBNAIL module from the list of supported formats.
116 % The format of the UnregisterTHUMBNAILImage method is:
118 % UnregisterTHUMBNAILImage(void)
121 ModuleExport void UnregisterTHUMBNAILImage(void)
123 (void) UnregisterMagickInfo("THUMBNAIL");
127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 % W r i t e T H U M B N A I L I m a g e %
135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137 % WriteTHUMBNAILImage() extracts the EXIF thumbnail image and writes it.
139 % The format of the WriteTHUMBNAILImage method is:
141 % MagickBooleanType WriteTHUMBNAILImage(const ImageInfo *image_info,
144 % A description of each parameter follows.
146 % o image_info: the image info.
148 % o image: The image.
151 static MagickBooleanType WriteTHUMBNAILImage(const ImageInfo *image_info,
179 magick[MaxTextExtent];
181 profile=GetImageProfile(image,"exif");
182 if (profile == (const StringInfo *) NULL)
183 ThrowWriterException(CoderError,"ImageDoesNotHaveAThumbnail");
184 property=GetImageProperty(image,"exif:JPEGInterchangeFormat");
185 if (property == (const char *) NULL)
186 ThrowWriterException(CoderError,"ImageDoesNotHaveAThumbnail");
187 offset=(ssize_t) StringToLong(property);
188 property=GetImageProperty(image,"exif:JPEGInterchangeFormatLength");
189 if (property == (const char *) NULL)
190 ThrowWriterException(CoderError,"ImageDoesNotHaveAThumbnail");
191 length=(size_t) StringToLong(property);
192 (void) ResetMagickMemory(magick,0,sizeof(magick));
193 for (i=0; i < (ssize_t) length; i++)
197 magick[2]=GetStringInfoDatum(profile)[offset+i];
198 if (memcmp(magick,"\377\330\377",3) == 0)
201 thumbnail_image=BlobToImage(image_info,GetStringInfoDatum(profile)+offset+i-2,
202 length,&image->exception);
203 if (thumbnail_image == (Image *) NULL)
205 (void) SetImageType(thumbnail_image,thumbnail_image->matte == MagickFalse ?
206 TrueColorType : TrueColorMatteType);
207 (void) CopyMagickString(thumbnail_image->filename,image->filename,
209 write_info=CloneImageInfo(image_info);
210 (void) SetImageInfo(write_info,1,&image->exception);
211 if (LocaleCompare(write_info->magick,"THUMBNAIL") == 0)
212 (void) FormatMagickString(thumbnail_image->filename,MaxTextExtent,
213 "miff:%s",write_info->filename);
214 status=WriteImage(write_info,thumbnail_image);
215 thumbnail_image=DestroyImage(thumbnail_image);
216 write_info=DestroyImageInfo(write_info);