cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 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 % |
| 11 | % % |
| 12 | % % |
| 13 | % Write EXIF Thumbnail To File. % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | 16af1cb | 2009-12-11 21:38:29 +0000 | [diff] [blame^] | 20 | % Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 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. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | Include declarations. |
| 41 | */ |
| 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/monitor.h" |
| 51 | #include "magick/monitor-private.h" |
| 52 | #include "magick/profile.h" |
| 53 | #include "magick/property.h" |
| 54 | #include "magick/quantum-private.h" |
| 55 | #include "magick/static.h" |
| 56 | #include "magick/string_.h" |
| 57 | #include "magick/module.h" |
| 58 | |
| 59 | /* |
| 60 | Forward declarations. |
| 61 | */ |
| 62 | static MagickBooleanType |
| 63 | WriteTHUMBNAILImage(const ImageInfo *,Image *); |
| 64 | |
| 65 | /* |
| 66 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 67 | % % |
| 68 | % % |
| 69 | % % |
| 70 | % R e g i s t e r T H U M B N A I L I m a g e % |
| 71 | % % |
| 72 | % % |
| 73 | % % |
| 74 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 75 | % |
| 76 | % RegisterTHUMBNAILImage() adds attributes for the THUMBNAIL image format to |
| 77 | % the list of supported formats. The attributes include the image format |
| 78 | % tag, a method to read and/or write the format, whether the format |
| 79 | % supports the saving of more than one frame to the same file or blob, |
| 80 | % whether the format supports native in-memory I/O, and a brief |
| 81 | % description of the format. |
| 82 | % |
| 83 | % The format of the RegisterTHUMBNAILImage method is: |
| 84 | % |
| 85 | % unsigned long RegisterTHUMBNAILImage(void) |
| 86 | % |
| 87 | */ |
| 88 | ModuleExport unsigned long RegisterTHUMBNAILImage(void) |
| 89 | { |
| 90 | MagickInfo |
| 91 | *entry; |
| 92 | |
| 93 | entry=SetMagickInfo("THUMBNAIL"); |
| 94 | entry->encoder=(EncodeImageHandler *) WriteTHUMBNAILImage; |
| 95 | entry->description=ConstantString("EXIF Profile Thumbnail"); |
| 96 | entry->module=ConstantString("THUMBNAIL"); |
| 97 | (void) RegisterMagickInfo(entry); |
| 98 | return(MagickImageCoderSignature); |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 103 | % % |
| 104 | % % |
| 105 | % % |
| 106 | % U n r e g i s t e r T H U M B N A I L I m a g e % |
| 107 | % % |
| 108 | % % |
| 109 | % % |
| 110 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 111 | % |
| 112 | % UnregisterTHUMBNAILImage() removes format registrations made by the |
| 113 | % THUMBNAIL module from the list of supported formats. |
| 114 | % |
| 115 | % The format of the UnregisterTHUMBNAILImage method is: |
| 116 | % |
| 117 | % UnregisterTHUMBNAILImage(void) |
| 118 | % |
| 119 | */ |
| 120 | ModuleExport void UnregisterTHUMBNAILImage(void) |
| 121 | { |
| 122 | (void) UnregisterMagickInfo("THUMBNAIL"); |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 127 | % % |
| 128 | % % |
| 129 | % % |
| 130 | % W r i t e T H U M B N A I L I m a g e % |
| 131 | % % |
| 132 | % % |
| 133 | % % |
| 134 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 135 | % |
| 136 | % WriteTHUMBNAILImage() extracts the EXIF thumbnail image and writes it. |
| 137 | % |
| 138 | % The format of the WriteTHUMBNAILImage method is: |
| 139 | % |
| 140 | % MagickBooleanType WriteTHUMBNAILImage(const ImageInfo *image_info, |
| 141 | % Image *image) |
| 142 | % |
| 143 | % A description of each parameter follows. |
| 144 | % |
| 145 | % o image_info: the image info. |
| 146 | % |
| 147 | % o image: The image. |
| 148 | % |
| 149 | */ |
| 150 | static MagickBooleanType WriteTHUMBNAILImage(const ImageInfo *image_info, |
| 151 | Image *image) |
| 152 | { |
| 153 | const char |
| 154 | *property; |
| 155 | |
| 156 | const StringInfo |
| 157 | *profile; |
| 158 | |
| 159 | Image |
| 160 | *thumbnail_image; |
| 161 | |
| 162 | ImageInfo |
| 163 | *write_info; |
| 164 | |
| 165 | MagickBooleanType |
| 166 | status; |
| 167 | |
| 168 | register long |
| 169 | i; |
| 170 | |
| 171 | ssize_t |
| 172 | offset; |
| 173 | |
| 174 | size_t |
| 175 | length; |
| 176 | |
| 177 | unsigned char |
| 178 | magick[MaxTextExtent]; |
| 179 | |
| 180 | profile=GetImageProfile(image,"exif"); |
| 181 | if (profile == (const StringInfo *) NULL) |
| 182 | ThrowWriterException(CoderError,"ImageDoesNotHaveAThumbnail"); |
| 183 | property=GetImageProperty(image,"exif:JPEGInterchangeFormat"); |
| 184 | if (property == (const char *) NULL) |
| 185 | ThrowWriterException(CoderError,"ImageDoesNotHaveAThumbnail"); |
| 186 | offset=(ssize_t) atoi(property); |
| 187 | property=GetImageProperty(image,"exif:JPEGInterchangeFormatLength"); |
| 188 | if (property == (const char *) NULL) |
| 189 | ThrowWriterException(CoderError,"ImageDoesNotHaveAThumbnail"); |
| 190 | length=(size_t) atoi(property); |
| 191 | (void) ResetMagickMemory(magick,0,sizeof(magick)); |
| 192 | for (i=0; i < (long) length; i++) |
| 193 | { |
| 194 | magick[0]=magick[1]; |
| 195 | magick[1]=magick[2]; |
| 196 | magick[2]=GetStringInfoDatum(profile)[offset+i]; |
| 197 | if (memcmp(magick,"\377\330\377",3) == 0) |
| 198 | break; |
| 199 | } |
| 200 | thumbnail_image=BlobToImage(image_info,GetStringInfoDatum(profile)+offset+i-2, |
| 201 | length,&image->exception); |
| 202 | if (thumbnail_image == (Image *) NULL) |
| 203 | return(MagickFalse); |
| 204 | (void) SetImageType(thumbnail_image,thumbnail_image->matte == MagickFalse ? |
| 205 | TrueColorType : TrueColorMatteType); |
| 206 | (void) CopyMagickString(thumbnail_image->filename,image->filename, |
| 207 | MaxTextExtent); |
| 208 | write_info=CloneImageInfo(image_info); |
| 209 | (void) SetImageInfo(write_info,MagickTrue,&image->exception); |
| 210 | if (LocaleCompare(write_info->magick,"THUMBNAIL") == 0) |
| 211 | (void) FormatMagickString(thumbnail_image->filename,MaxTextExtent, |
| 212 | "miff:%s",write_info->filename); |
| 213 | status=WriteImage(write_info,thumbnail_image); |
| 214 | thumbnail_image=DestroyImage(thumbnail_image); |
| 215 | write_info=DestroyImageInfo(write_info); |
| 216 | return(status); |
| 217 | } |