blob: 0a29ad99496526cb8a8a66bb41aad492bab365dd [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% V V IIIII DDDD %
7% V V I D D %
8% V V I D D %
9% V V I D D %
10% V IIIII DDDD %
11% %
12% %
13% Return a Visual Image Directory for matching images. %
14% %
15% Software Design %
16% John Cristy %
17% July 1992 %
18% %
19% %
cristy16af1cb2009-12-11 21:38:29 +000020% Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% 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/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"
65
66/*
67 Forward declarations.
68*/
69static MagickBooleanType
70 WriteVIDImage(const ImageInfo *,Image *);
71
72/*
73%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74% %
75% %
76% %
77% R e a d V I D I m a g e %
78% %
79% %
80% %
81%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82%
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.
86%
87% The format of the ReadVIDImage method is:
88%
89% Image *ReadVIDImage(const ImageInfo *image_info,ExceptionInfo *exception)
90%
91% A description of each parameter follows:
92%
93% o image_info: the image info.
94%
95% o exception: return any errors or warnings in this structure.
96%
97*/
98static Image *ReadVIDImage(const ImageInfo *image_info,ExceptionInfo *exception)
99{
100#define ClientName "montage"
101
102 char
103 **filelist,
104 *label;
105
106 Image
107 *image,
108 *images,
109 *montage_image,
110 *next_image,
111 *thumbnail_image;
112
113 ImageInfo
114 *read_info;
115
116 int
117 number_files;
118
119 MagickBooleanType
120 status;
121
122 MontageInfo
123 *montage_info;
124
125 RectangleInfo
126 geometry;
127
128 register long
129 i;
130
131 /*
132 Expand the filename.
133 */
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);
cristy90823212009-12-12 20:48:33 +0000142 filelist=(char **) AcquireAlignedMemory(1,sizeof(*filelist));
cristy3ed852e2009-09-05 21:47:34 +0000143 if (filelist == (char **) NULL)
144 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
145 filelist[0]=ConstantString(image_info->filename);
146 number_files=1;
147 status=ExpandFilenames(&number_files,&filelist);
148 if ((status == MagickFalse) || (number_files == 0))
149 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
150 image=DestroyImage(image);
151 /*
152 Read each image and convert them to a tile.
153 */
154 images=NewImageList();
155 read_info=CloneImageInfo(image_info);
156 SetImageInfoBlob(read_info,(void *) NULL,0);
157 (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
158 (void *) NULL);
159 if (read_info->size == (char *) NULL)
160 (void) CloneString(&read_info->size,DefaultTileGeometry);
161 for (i=0; i < (long) number_files; i++)
162 {
163 if (image_info->debug != MagickFalse)
164 (void) LogMagickEvent(CoderEvent,GetMagickModule(),"name: %s",
165 filelist[i]);
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)
172 break;
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,
183 exception);
184 if (thumbnail_image != (Image *) NULL)
185 {
186 next_image=DestroyImage(next_image);
187 next_image=thumbnail_image;
188 }
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)
195 break;
196 }
197 read_info=DestroyImageInfo(read_info);
198 filelist=(char **) RelinquishMagickMemory(filelist);
199 if (images == (Image *) NULL)
200 ThrowReaderException(CorruptImageError,
201 "ImageFileDoesNotContainAnyImageData");
202 /*
203 Create the visual image directory.
204 */
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);
213}
214
215/*
216%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217% %
218% %
219% %
220% R e g i s t e r V I D I m a g e %
221% %
222% %
223% %
224%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
225%
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.
232%
233% The format of the RegisterVIDImage method is:
234%
235% unsigned long RegisterVIDImage(void)
236%
237*/
238ModuleExport unsigned long RegisterVIDImage(void)
239{
240 MagickInfo
241 *entry;
242
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);
251}
252
253/*
254%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
255% %
256% %
257% %
258% U n r e g i s t e r V I D I m a g e %
259% %
260% %
261% %
262%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
263%
264% UnregisterVIDImage() removes format registrations made by the
265% VID module from the list of supported formats.
266%
267% The format of the UnregisterVIDImage method is:
268%
269% UnregisterVIDImage(void)
270%
271*/
272ModuleExport void UnregisterVIDImage(void)
273{
274 (void) UnregisterMagickInfo("VID");
275}
276
277/*
278%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
279% %
280% %
281% %
282% W r i t e V I D I m a g e %
283% %
284% %
285% %
286%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
287%
288% WriteVIDImage() writes an image to a file in VID X image format.
289%
290% The format of the WriteVIDImage method is:
291%
292% MagickBooleanType WriteVIDImage(const ImageInfo *image_info,Image *image)
293%
294% A description of each parameter follows.
295%
296% o image_info: the image info.
297%
298% o image: The image.
299%
300*/
301static MagickBooleanType WriteVIDImage(const ImageInfo *image_info,Image *image)
302{
303 Image
304 *montage_image;
305
306 ImageInfo
307 *write_info;
308
309 MagickBooleanType
310 status;
311
312 MontageInfo
313 *montage_info;
314
315 register Image
316 *p;
317
318 /*
319 Create the visual image directory.
320 */
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,
325 &image->exception);
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,
330 MaxTextExtent);
331 write_info=CloneImageInfo(image_info);
cristyd965a422010-03-03 17:47:35 +0000332 (void) SetImageInfo(write_info,1,&image->exception);
cristy3ed852e2009-09-05 21:47:34 +0000333 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);
339 return(status);
340}