2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 % Return a Visual Image Directory for matching images. %
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/property.h"
44 #include "magick/blob.h"
45 #include "magick/blob-private.h"
46 #include "magick/constitute.h"
47 #include "magick/exception.h"
48 #include "magick/exception-private.h"
49 #include "magick/geometry.h"
50 #include "magick/image.h"
51 #include "magick/image-private.h"
52 #include "magick/list.h"
53 #include "magick/log.h"
54 #include "magick/magick.h"
55 #include "magick/memory_.h"
56 #include "magick/monitor.h"
57 #include "magick/monitor-private.h"
58 #include "magick/montage.h"
59 #include "magick/quantum-private.h"
60 #include "magick/resize.h"
61 #include "magick/static.h"
62 #include "magick/string_.h"
63 #include "magick/module.h"
64 #include "magick/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 **) AcquireAlignedMemory(1,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 < (long) 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(),"geometry: %ldx%ld",
178 next_image->columns,next_image->rows);
179 SetGeometry(next_image,&geometry);
180 (void) ParseMetaGeometry(read_info->size,&geometry.x,&geometry.y,
181 &geometry.width,&geometry.height);
182 thumbnail_image=ThumbnailImage(next_image,geometry.width,geometry.height,
184 if (thumbnail_image != (Image *) NULL)
186 next_image=DestroyImage(next_image);
187 next_image=thumbnail_image;
189 if (image_info->debug != MagickFalse)
190 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
191 "thumbnail geometry: %ldx%ld",next_image->columns,next_image->rows);
192 AppendImageToList(&images,next_image);
193 status=SetImageProgress(images,LoadImagesTag,i,number_files);
194 if (status == MagickFalse)
197 read_info=DestroyImageInfo(read_info);
198 filelist=(char **) RelinquishMagickMemory(filelist);
199 if (images == (Image *) NULL)
200 ThrowReaderException(CorruptImageError,
201 "ImageFileDoesNotContainAnyImageData");
203 Create the visual image directory.
205 montage_info=CloneMontageInfo(image_info,(MontageInfo *) NULL);
206 if (image_info->debug != MagickFalse)
207 (void) LogMagickEvent(CoderEvent,GetMagickModule(),"creating montage");
208 montage_image=MontageImageList(image_info,montage_info,
209 GetFirstImageInList(images),exception);
210 montage_info=DestroyMontageInfo(montage_info);
211 images=DestroyImageList(images);
212 return(montage_image);
216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220 % R e g i s t e r V I D I m a g e %
224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 % RegisterVIDImage() adds attributes for the VID image format to
227 % the list of supported formats. The attributes include the image format
228 % tag, a method to read and/or write the format, whether the format
229 % supports the saving of more than one frame to the same file or blob,
230 % whether the format supports native in-memory I/O, and a brief
231 % description of the format.
233 % The format of the RegisterVIDImage method is:
235 % unsigned long RegisterVIDImage(void)
238 ModuleExport unsigned long RegisterVIDImage(void)
243 entry=SetMagickInfo("VID");
244 entry->decoder=(DecodeImageHandler *) ReadVIDImage;
245 entry->encoder=(EncodeImageHandler *) WriteVIDImage;
246 entry->format_type=ExplicitFormatType;
247 entry->description=ConstantString("Visual Image Directory");
248 entry->module=ConstantString("VID");
249 (void) RegisterMagickInfo(entry);
250 return(MagickImageCoderSignature);
254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
258 % U n r e g i s t e r V I D I m a g e %
262 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264 % UnregisterVIDImage() removes format registrations made by the
265 % VID module from the list of supported formats.
267 % The format of the UnregisterVIDImage method is:
269 % UnregisterVIDImage(void)
272 ModuleExport void UnregisterVIDImage(void)
274 (void) UnregisterMagickInfo("VID");
278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
282 % W r i t e V I D I m a g e %
286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
288 % WriteVIDImage() writes an image to a file in VID X image format.
290 % The format of the WriteVIDImage method is:
292 % MagickBooleanType WriteVIDImage(const ImageInfo *image_info,Image *image)
294 % A description of each parameter follows.
296 % o image_info: the image info.
298 % o image: The image.
301 static MagickBooleanType WriteVIDImage(const ImageInfo *image_info,Image *image)
319 Create the visual image directory.
321 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
322 (void) SetImageProperty(p,"label",DefaultTileLabel);
323 montage_info=CloneMontageInfo(image_info,(MontageInfo *) NULL);
324 montage_image=MontageImageList(image_info,montage_info,image,
326 montage_info=DestroyMontageInfo(montage_info);
327 if (montage_image == (Image *) NULL)
328 ThrowWriterException(CorruptImageError,image->exception.reason);
329 (void) CopyMagickString(montage_image->filename,image_info->filename,
331 write_info=CloneImageInfo(image_info);
332 (void) SetImageInfo(write_info,1,&image->exception);
333 if (LocaleCompare(write_info->magick,"VID") == 0)
334 (void) FormatMagickString(montage_image->filename,MaxTextExtent,
335 "miff:%s",write_info->filename);
336 status=WriteImage(write_info,montage_image);
337 montage_image=DestroyImage(montage_image);
338 write_info=DestroyImageInfo(write_info);