2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Return a Visual Image Directory for matching images. %
20 % Copyright 1999-2011 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/property.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/blob-private.h"
46 #include "MagickCore/constitute.h"
47 #include "MagickCore/exception.h"
48 #include "MagickCore/exception-private.h"
49 #include "MagickCore/geometry.h"
50 #include "MagickCore/image.h"
51 #include "MagickCore/image-private.h"
52 #include "MagickCore/list.h"
53 #include "MagickCore/log.h"
54 #include "MagickCore/magick.h"
55 #include "MagickCore/memory_.h"
56 #include "MagickCore/monitor.h"
57 #include "MagickCore/monitor-private.h"
58 #include "MagickCore/montage.h"
59 #include "MagickCore/quantum-private.h"
60 #include "MagickCore/resize.h"
61 #include "MagickCore/static.h"
62 #include "MagickCore/string_.h"
63 #include "MagickCore/module.h"
64 #include "MagickCore/utility.h"
69 static MagickBooleanType
70 WriteVIDImage(const ImageInfo *,Image *);
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 % R e a d V I D I m a g e %
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83 % ReadVIDImage reads one of more images and creates a Visual Image
84 % Directory file. It allocates the memory necessary for the new Image
85 % structure and returns a pointer to the new image.
87 % The format of the ReadVIDImage method is:
89 % Image *ReadVIDImage(const ImageInfo *image_info,ExceptionInfo *exception)
91 % A description of each parameter follows:
93 % o image_info: the image info.
95 % o exception: return any errors or warnings in this structure.
98 static Image *ReadVIDImage(const ImageInfo *image_info,ExceptionInfo *exception)
100 #define ClientName "montage"
134 assert(image_info != (const ImageInfo *) NULL);
135 assert(image_info->signature == MagickSignature);
136 if (image_info->debug != MagickFalse)
137 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
138 image_info->filename);
139 assert(exception != (ExceptionInfo *) NULL);
140 assert(exception->signature == MagickSignature);
141 image=AcquireImage(image_info);
142 filelist=(char **) AcquireMagickMemory(sizeof(*filelist));
143 if (filelist == (char **) NULL)
144 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
145 filelist[0]=ConstantString(image_info->filename);
147 status=ExpandFilenames(&number_files,&filelist);
148 if ((status == MagickFalse) || (number_files == 0))
149 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
150 image=DestroyImage(image);
152 Read each image and convert them to a tile.
154 images=NewImageList();
155 read_info=CloneImageInfo(image_info);
156 SetImageInfoBlob(read_info,(void *) NULL,0);
157 (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
159 if (read_info->size == (char *) NULL)
160 (void) CloneString(&read_info->size,DefaultTileGeometry);
161 for (i=0; i < (ssize_t) number_files; i++)
163 if (image_info->debug != MagickFalse)
164 (void) LogMagickEvent(CoderEvent,GetMagickModule(),"name: %s",
166 (void) CopyMagickString(read_info->filename,filelist[i],MaxTextExtent);
167 filelist[i]=DestroyString(filelist[i]);
168 *read_info->magick='\0';
169 next_image=ReadImage(read_info,exception);
170 CatchException(exception);
171 if (next_image == (Image *) NULL)
173 label=InterpretImageProperties(image_info,next_image,DefaultTileLabel);
174 (void) SetImageProperty(next_image,"label",label);
175 label=DestroyString(label);
176 if (image_info->debug != MagickFalse)
177 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
178 "geometry: %.20gx%.20g",(double) next_image->columns,(double)
180 SetGeometry(next_image,&geometry);
181 (void) ParseMetaGeometry(read_info->size,&geometry.x,&geometry.y,
182 &geometry.width,&geometry.height);
183 thumbnail_image=ThumbnailImage(next_image,geometry.width,geometry.height,
185 if (thumbnail_image != (Image *) NULL)
187 next_image=DestroyImage(next_image);
188 next_image=thumbnail_image;
190 if (image_info->debug != MagickFalse)
191 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
192 "thumbnail geometry: %.20gx%.20g",(double) next_image->columns,(double)
194 AppendImageToList(&images,next_image);
195 status=SetImageProgress(images,LoadImagesTag,i,number_files);
196 if (status == MagickFalse)
199 read_info=DestroyImageInfo(read_info);
200 filelist=(char **) RelinquishMagickMemory(filelist);
201 if (images == (Image *) NULL)
202 ThrowReaderException(CorruptImageError,
203 "ImageFileDoesNotContainAnyImageData");
205 Create the visual image directory.
207 montage_info=CloneMontageInfo(image_info,(MontageInfo *) NULL);
208 if (image_info->debug != MagickFalse)
209 (void) LogMagickEvent(CoderEvent,GetMagickModule(),"creating montage");
210 montage_image=MontageImageList(image_info,montage_info,
211 GetFirstImageInList(images),exception);
212 montage_info=DestroyMontageInfo(montage_info);
213 images=DestroyImageList(images);
214 return(montage_image);
218 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
222 % R e g i s t e r V I D I m a g e %
226 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228 % RegisterVIDImage() adds attributes for the VID image format to
229 % the list of supported formats. The attributes include the image format
230 % tag, a method to read and/or write the format, whether the format
231 % supports the saving of more than one frame to the same file or blob,
232 % whether the format supports native in-memory I/O, and a brief
233 % description of the format.
235 % The format of the RegisterVIDImage method is:
237 % size_t RegisterVIDImage(void)
240 ModuleExport size_t RegisterVIDImage(void)
245 entry=SetMagickInfo("VID");
246 entry->decoder=(DecodeImageHandler *) ReadVIDImage;
247 entry->encoder=(EncodeImageHandler *) WriteVIDImage;
248 entry->format_type=ImplicitFormatType;
249 entry->description=ConstantString("Visual Image Directory");
250 entry->module=ConstantString("VID");
251 (void) RegisterMagickInfo(entry);
252 return(MagickImageCoderSignature);
256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
260 % U n r e g i s t e r V I D I m a g e %
264 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
266 % UnregisterVIDImage() removes format registrations made by the
267 % VID module from the list of supported formats.
269 % The format of the UnregisterVIDImage method is:
271 % UnregisterVIDImage(void)
274 ModuleExport void UnregisterVIDImage(void)
276 (void) UnregisterMagickInfo("VID");
280 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
284 % W r i t e V I D I m a g e %
288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
290 % WriteVIDImage() writes an image to a file in VID X image format.
292 % The format of the WriteVIDImage method is:
294 % MagickBooleanType WriteVIDImage(const ImageInfo *image_info,Image *image)
296 % A description of each parameter follows.
298 % o image_info: the image info.
300 % o image: The image.
303 static MagickBooleanType WriteVIDImage(const ImageInfo *image_info,Image *image)
321 Create the visual image directory.
323 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
324 (void) SetImageProperty(p,"label",DefaultTileLabel);
325 montage_info=CloneMontageInfo(image_info,(MontageInfo *) NULL);
326 montage_image=MontageImageList(image_info,montage_info,image,
328 montage_info=DestroyMontageInfo(montage_info);
329 if (montage_image == (Image *) NULL)
330 ThrowWriterException(CorruptImageError,image->exception.reason);
331 (void) CopyMagickString(montage_image->filename,image_info->filename,
333 write_info=CloneImageInfo(image_info);
334 (void) SetImageInfo(write_info,1,&image->exception);
335 if (LocaleCompare(write_info->magick,"VID") == 0)
336 (void) FormatLocaleString(montage_image->filename,MaxTextExtent,
337 "miff:%s",write_info->filename);
338 status=WriteImage(write_info,montage_image);
339 montage_image=DestroyImage(montage_image);
340 write_info=DestroyImageInfo(write_info);