• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 %                                   Cristy                                    %
17 %                                 July 1992                                   %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2019 ImageMagick Studio LLC, a non-profit organization      %
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 %    https://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 "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"
65 
66 /*
67   Forward declarations.
68 */
69 static MagickBooleanType
70   WriteVIDImage(const ImageInfo *,Image *,ExceptionInfo *);
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 */
ReadVIDImage(const ImageInfo * image_info,ExceptionInfo * exception)98 static Image *ReadVIDImage(const ImageInfo *image_info,ExceptionInfo *exception)
99 {
100 #define ClientName  "montage"
101 
102   char
103     **filelist,
104     *label,
105     **list;
106 
107   Image
108     *image,
109     *images,
110     *montage_image,
111     *next_image,
112     *thumbnail_image;
113 
114   ImageInfo
115     *read_info;
116 
117   int
118     number_files;
119 
120   MagickBooleanType
121     status;
122 
123   MontageInfo
124     *montage_info;
125 
126   RectangleInfo
127     geometry;
128 
129   register ssize_t
130     i;
131 
132   /*
133     Expand the filename.
134   */
135   assert(image_info != (const ImageInfo *) NULL);
136   assert(image_info->signature == MagickCoreSignature);
137   if (image_info->debug != MagickFalse)
138     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
139       image_info->filename);
140   assert(exception != (ExceptionInfo *) NULL);
141   assert(exception->signature == MagickCoreSignature);
142   image=AcquireImage(image_info,exception);
143   list=(char **) AcquireMagickMemory(sizeof(*filelist));
144   if (list == (char **) NULL)
145     ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
146   list[0]=ConstantString(image_info->filename);
147   filelist=list;
148   number_files=1;
149   status=ExpandFilenames(&number_files,&filelist);
150   list[0]=DestroyString(list[0]);
151   list=(char **) RelinquishMagickMemory(list);
152   if ((status == MagickFalse) || (number_files == 0))
153     ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
154   image=DestroyImage(image);
155   /*
156     Read each image and convert them to a tile.
157   */
158   images=NewImageList();
159   read_info=CloneImageInfo(image_info);
160   SetImageInfoBlob(read_info,(void *) NULL,0);
161   (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
162     (void *) NULL);
163   if (read_info->size == (char *) NULL)
164     (void) CloneString(&read_info->size,DefaultTileGeometry);
165   for (i=0; i < (ssize_t) number_files; i++)
166   {
167     if (image_info->debug != MagickFalse)
168       (void) LogMagickEvent(CoderEvent,GetMagickModule(),"name: %s",
169         filelist[i]);
170     (void) CopyMagickString(read_info->filename,filelist[i],MagickPathExtent);
171     filelist[i]=DestroyString(filelist[i]);
172     *read_info->magick='\0';
173     next_image=ReadImage(read_info,exception);
174     CatchException(exception);
175     if (next_image == (Image *) NULL)
176       break;
177     label=InterpretImageProperties((ImageInfo *) image_info,next_image,
178       DefaultTileLabel,exception);
179     (void) SetImageProperty(next_image,"label",label,exception);
180     label=DestroyString(label);
181     if (image_info->debug != MagickFalse)
182       (void) LogMagickEvent(CoderEvent,GetMagickModule(),
183         "geometry: %.20gx%.20g",(double) next_image->columns,(double)
184         next_image->rows);
185     SetGeometry(next_image,&geometry);
186     (void) ParseMetaGeometry(read_info->size,&geometry.x,&geometry.y,
187       &geometry.width,&geometry.height);
188     thumbnail_image=ThumbnailImage(next_image,geometry.width,geometry.height,
189       exception);
190     if (thumbnail_image != (Image *) NULL)
191       {
192         next_image=DestroyImage(next_image);
193         next_image=thumbnail_image;
194       }
195     if (image_info->debug != MagickFalse)
196       (void) LogMagickEvent(CoderEvent,GetMagickModule(),
197         "thumbnail geometry: %.20gx%.20g",(double) next_image->columns,(double)
198         next_image->rows);
199     AppendImageToList(&images,next_image);
200     status=SetImageProgress(images,LoadImagesTag,i,number_files);
201     if (status == MagickFalse)
202       break;
203   }
204   read_info=DestroyImageInfo(read_info);
205   filelist=(char **) RelinquishMagickMemory(filelist);
206   if (images == (Image *) NULL)
207     ThrowReaderException(CorruptImageError,
208       "ImageFileDoesNotContainAnyImageData");
209   /*
210     Create the visual image directory.
211   */
212   montage_info=CloneMontageInfo(image_info,(MontageInfo *) NULL);
213   if (image_info->debug != MagickFalse)
214     (void) LogMagickEvent(CoderEvent,GetMagickModule(),"creating montage");
215   montage_image=MontageImageList(image_info,montage_info,
216     GetFirstImageInList(images),exception);
217   montage_info=DestroyMontageInfo(montage_info);
218   images=DestroyImageList(images);
219   return(montage_image);
220 }
221 
222 /*
223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224 %                                                                             %
225 %                                                                             %
226 %                                                                             %
227 %   R e g i s t e r V I D I m a g e                                           %
228 %                                                                             %
229 %                                                                             %
230 %                                                                             %
231 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232 %
233 %  RegisterVIDImage() adds attributes for the VID image format to
234 %  the list of supported formats.  The attributes include the image format
235 %  tag, a method to read and/or write the format, whether the format
236 %  supports the saving of more than one frame to the same file or blob,
237 %  whether the format supports native in-memory I/O, and a brief
238 %  description of the format.
239 %
240 %  The format of the RegisterVIDImage method is:
241 %
242 %      size_t RegisterVIDImage(void)
243 %
244 */
RegisterVIDImage(void)245 ModuleExport size_t RegisterVIDImage(void)
246 {
247   MagickInfo
248     *entry;
249 
250   entry=AcquireMagickInfo("VID","VID","Visual Image Directory");
251   entry->decoder=(DecodeImageHandler *) ReadVIDImage;
252   entry->encoder=(EncodeImageHandler *) WriteVIDImage;
253   entry->format_type=ImplicitFormatType;
254   (void) RegisterMagickInfo(entry);
255   return(MagickImageCoderSignature);
256 }
257 
258 /*
259 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
260 %                                                                             %
261 %                                                                             %
262 %                                                                             %
263 %   U n r e g i s t e r V I D I m a g e                                       %
264 %                                                                             %
265 %                                                                             %
266 %                                                                             %
267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
268 %
269 %  UnregisterVIDImage() removes format registrations made by the
270 %  VID module from the list of supported formats.
271 %
272 %  The format of the UnregisterVIDImage method is:
273 %
274 %      UnregisterVIDImage(void)
275 %
276 */
UnregisterVIDImage(void)277 ModuleExport void UnregisterVIDImage(void)
278 {
279   (void) UnregisterMagickInfo("VID");
280 }
281 
282 /*
283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
284 %                                                                             %
285 %                                                                             %
286 %                                                                             %
287 %   W r i t e V I D I m a g e                                                 %
288 %                                                                             %
289 %                                                                             %
290 %                                                                             %
291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
292 %
293 %  WriteVIDImage() writes an image to a file in VID X image format.
294 %
295 %  The format of the WriteVIDImage method is:
296 %
297 %      MagickBooleanType WriteVIDImage(const ImageInfo *image_info,
298 %        Image *image,ExceptionInfo *exception)
299 %
300 %  A description of each parameter follows.
301 %
302 %    o image_info: the image info.
303 %
304 %    o image:  The image.
305 %
306 %    o exception: return any errors or warnings in this structure.
307 %
308 */
WriteVIDImage(const ImageInfo * image_info,Image * image,ExceptionInfo * exception)309 static MagickBooleanType WriteVIDImage(const ImageInfo *image_info,Image *image,
310   ExceptionInfo *exception)
311 {
312   Image
313     *montage_image;
314 
315   ImageInfo
316     *write_info;
317 
318   MagickBooleanType
319     status;
320 
321   MontageInfo
322     *montage_info;
323 
324   register Image
325     *p;
326 
327   /*
328     Create the visual image directory.
329   */
330   for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
331     (void) SetImageProperty(p,"label",DefaultTileLabel,exception);
332   montage_info=CloneMontageInfo(image_info,(MontageInfo *) NULL);
333   montage_image=MontageImageList(image_info,montage_info,image,exception);
334   montage_info=DestroyMontageInfo(montage_info);
335   if (montage_image == (Image *) NULL)
336     return(MagickFalse);
337   (void) CopyMagickString(montage_image->filename,image_info->filename,
338     MagickPathExtent);
339   write_info=CloneImageInfo(image_info);
340   *write_info->magick='\0';
341   (void) SetImageInfo(write_info,1,exception);
342   if ((*write_info->magick == '\0') ||
343       (LocaleCompare(write_info->magick,"VID") == 0))
344     (void) FormatLocaleString(montage_image->filename,MagickPathExtent,
345       "miff:%s",write_info->filename);
346   status=WriteImage(write_info,montage_image,exception);
347   montage_image=DestroyImage(montage_image);
348   write_info=DestroyImageInfo(write_info);
349   return(status);
350 }
351