Home | History | Annotate | Download | only in coders
      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-2016 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 %    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 /*
     41   Include declarations.
     42 */
     43 #include "MagickCore/studio.h"
     44 #include "MagickCore/property.h"
     45 #include "MagickCore/blob.h"
     46 #include "MagickCore/blob-private.h"
     47 #include "MagickCore/constitute.h"
     48 #include "MagickCore/exception.h"
     49 #include "MagickCore/exception-private.h"
     50 #include "MagickCore/geometry.h"
     51 #include "MagickCore/image.h"
     52 #include "MagickCore/image-private.h"
     53 #include "MagickCore/list.h"
     54 #include "MagickCore/log.h"
     55 #include "MagickCore/magick.h"
     56 #include "MagickCore/memory_.h"
     57 #include "MagickCore/monitor.h"
     58 #include "MagickCore/monitor-private.h"
     59 #include "MagickCore/montage.h"
     60 #include "MagickCore/quantum-private.h"
     61 #include "MagickCore/resize.h"
     62 #include "MagickCore/static.h"
     63 #include "MagickCore/string_.h"
     64 #include "MagickCore/module.h"
     65 #include "MagickCore/utility.h"
     66 
     67 /*
     69   Forward declarations.
     70 */
     71 static MagickBooleanType
     72   WriteVIDImage(const ImageInfo *,Image *,ExceptionInfo *);
     73 
     74 /*
     76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     77 %                                                                             %
     78 %                                                                             %
     79 %                                                                             %
     80 %   R e a d V I D I m a g e                                                   %
     81 %                                                                             %
     82 %                                                                             %
     83 %                                                                             %
     84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     85 %
     86 %  ReadVIDImage reads one of more images and creates a Visual Image
     87 %  Directory file.  It allocates the memory necessary for the new Image
     88 %  structure and returns a pointer to the new image.
     89 %
     90 %  The format of the ReadVIDImage method is:
     91 %
     92 %      Image *ReadVIDImage(const ImageInfo *image_info,ExceptionInfo *exception)
     93 %
     94 %  A description of each parameter follows:
     95 %
     96 %    o image_info: the image info.
     97 %
     98 %    o exception: return any errors or warnings in this structure.
     99 %
    100 */
    101 static Image *ReadVIDImage(const ImageInfo *image_info,ExceptionInfo *exception)
    102 {
    103 #define ClientName  "montage"
    104 
    105   char
    106     **filelist,
    107     *label;
    108 
    109   Image
    110     *image,
    111     *images,
    112     *montage_image,
    113     *next_image,
    114     *thumbnail_image;
    115 
    116   ImageInfo
    117     *read_info;
    118 
    119   int
    120     number_files;
    121 
    122   MagickBooleanType
    123     status;
    124 
    125   MontageInfo
    126     *montage_info;
    127 
    128   RectangleInfo
    129     geometry;
    130 
    131   register ssize_t
    132     i;
    133 
    134   /*
    135     Expand the filename.
    136   */
    137   assert(image_info != (const ImageInfo *) NULL);
    138   assert(image_info->signature == MagickCoreSignature);
    139   if (image_info->debug != MagickFalse)
    140     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
    141       image_info->filename);
    142   assert(exception != (ExceptionInfo *) NULL);
    143   assert(exception->signature == MagickCoreSignature);
    144   image=AcquireImage(image_info,exception);
    145   filelist=(char **) AcquireMagickMemory(sizeof(*filelist));
    146   if (filelist == (char **) NULL)
    147     ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
    148   filelist[0]=ConstantString(image_info->filename);
    149   number_files=1;
    150   status=ExpandFilenames(&number_files,&filelist);
    151   if ((status == MagickFalse) || (number_files == 0))
    152     ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
    153   image=DestroyImage(image);
    154   /*
    155     Read each image and convert them to a tile.
    156   */
    157   images=NewImageList();
    158   read_info=CloneImageInfo(image_info);
    159   SetImageInfoBlob(read_info,(void *) NULL,0);
    160   (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
    161     (void *) NULL);
    162   if (read_info->size == (char *) NULL)
    163     (void) CloneString(&read_info->size,DefaultTileGeometry);
    164   for (i=0; i < (ssize_t) number_files; i++)
    165   {
    166     if (image_info->debug != MagickFalse)
    167       (void) LogMagickEvent(CoderEvent,GetMagickModule(),"name: %s",
    168         filelist[i]);
    169     (void) CopyMagickString(read_info->filename,filelist[i],MagickPathExtent);
    170     filelist[i]=DestroyString(filelist[i]);
    171     *read_info->magick='\0';
    172     next_image=ReadImage(read_info,exception);
    173     CatchException(exception);
    174     if (next_image == (Image *) NULL)
    175       break;
    176     label=InterpretImageProperties((ImageInfo *) image_info,next_image,
    177       DefaultTileLabel,exception);
    178     (void) SetImageProperty(next_image,"label",label,exception);
    179     label=DestroyString(label);
    180     if (image_info->debug != MagickFalse)
    181       (void) LogMagickEvent(CoderEvent,GetMagickModule(),
    182         "geometry: %.20gx%.20g",(double) next_image->columns,(double)
    183         next_image->rows);
    184     SetGeometry(next_image,&geometry);
    185     (void) ParseMetaGeometry(read_info->size,&geometry.x,&geometry.y,
    186       &geometry.width,&geometry.height);
    187     thumbnail_image=ThumbnailImage(next_image,geometry.width,geometry.height,
    188       exception);
    189     if (thumbnail_image != (Image *) NULL)
    190       {
    191         next_image=DestroyImage(next_image);
    192         next_image=thumbnail_image;
    193       }
    194     if (image_info->debug != MagickFalse)
    195       (void) LogMagickEvent(CoderEvent,GetMagickModule(),
    196         "thumbnail geometry: %.20gx%.20g",(double) next_image->columns,(double)
    197         next_image->rows);
    198     AppendImageToList(&images,next_image);
    199     status=SetImageProgress(images,LoadImagesTag,i,number_files);
    200     if (status == MagickFalse)
    201       break;
    202   }
    203   read_info=DestroyImageInfo(read_info);
    204   filelist=(char **) RelinquishMagickMemory(filelist);
    205   if (images == (Image *) NULL)
    206     ThrowReaderException(CorruptImageError,
    207       "ImageFileDoesNotContainAnyImageData");
    208   /*
    209     Create the visual image directory.
    210   */
    211   montage_info=CloneMontageInfo(image_info,(MontageInfo *) NULL);
    212   if (image_info->debug != MagickFalse)
    213     (void) LogMagickEvent(CoderEvent,GetMagickModule(),"creating montage");
    214   montage_image=MontageImageList(image_info,montage_info,
    215     GetFirstImageInList(images),exception);
    216   montage_info=DestroyMontageInfo(montage_info);
    217   images=DestroyImageList(images);
    218   return(montage_image);
    219 }
    220 
    221 /*
    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 */
    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 /*
    260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    261 %                                                                             %
    262 %                                                                             %
    263 %                                                                             %
    264 %   U n r e g i s t e r V I D I m a g e                                       %
    265 %                                                                             %
    266 %                                                                             %
    267 %                                                                             %
    268 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    269 %
    270 %  UnregisterVIDImage() removes format registrations made by the
    271 %  VID module from the list of supported formats.
    272 %
    273 %  The format of the UnregisterVIDImage method is:
    274 %
    275 %      UnregisterVIDImage(void)
    276 %
    277 */
    278 ModuleExport void UnregisterVIDImage(void)
    279 {
    280   (void) UnregisterMagickInfo("VID");
    281 }
    282 
    283 /*
    285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    286 %                                                                             %
    287 %                                                                             %
    288 %                                                                             %
    289 %   W r i t e V I D I m a g e                                                 %
    290 %                                                                             %
    291 %                                                                             %
    292 %                                                                             %
    293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    294 %
    295 %  WriteVIDImage() writes an image to a file in VID X image format.
    296 %
    297 %  The format of the WriteVIDImage method is:
    298 %
    299 %      MagickBooleanType WriteVIDImage(const ImageInfo *image_info,
    300 %        Image *image,ExceptionInfo *exception)
    301 %
    302 %  A description of each parameter follows.
    303 %
    304 %    o image_info: the image info.
    305 %
    306 %    o image:  The image.
    307 %
    308 %    o exception: return any errors or warnings in this structure.
    309 %
    310 */
    311 static MagickBooleanType WriteVIDImage(const ImageInfo *image_info,Image *image,
    312   ExceptionInfo *exception)
    313 {
    314   Image
    315     *montage_image;
    316 
    317   ImageInfo
    318     *write_info;
    319 
    320   MagickBooleanType
    321     status;
    322 
    323   MontageInfo
    324     *montage_info;
    325 
    326   register Image
    327     *p;
    328 
    329   /*
    330     Create the visual image directory.
    331   */
    332   for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
    333     (void) SetImageProperty(p,"label",DefaultTileLabel,exception);
    334   montage_info=CloneMontageInfo(image_info,(MontageInfo *) NULL);
    335   montage_image=MontageImageList(image_info,montage_info,image,exception);
    336   montage_info=DestroyMontageInfo(montage_info);
    337   if (montage_image == (Image *) NULL)
    338     return(MagickFalse);
    339   (void) CopyMagickString(montage_image->filename,image_info->filename,
    340     MagickPathExtent);
    341   write_info=CloneImageInfo(image_info);
    342   *write_info->magick='\0';
    343   (void) SetImageInfo(write_info,1,exception);
    344   if ((*write_info->magick == '\0') ||
    345       (LocaleCompare(write_info->magick,"VID") == 0))
    346     (void) FormatLocaleString(montage_image->filename,MagickPathExtent,
    347       "miff:%s",write_info->filename);
    348   status=WriteImage(write_info,montage_image,exception);
    349   montage_image=DestroyImage(montage_image);
    350   write_info=DestroyImageInfo(write_info);
    351   return(status);
    352 }
    353