Home | History | Annotate | Download | only in coders
      1 /*
      2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      3 %                                                                             %
      4 %                                                                             %
      5 %                                                                             %
      6 %                            M   M  PPPP   RRRR                               %
      7 %                            MM MM  P   P  R   R                              %
      8 %                            M M M  PPPP   RRRR                               %
      9 %                            M   M  P      R R                                %
     10 %                            M   M  P      R  R                               %
     11 %                                                                             %
     12 %                                                                             %
     13 %                  Read/Write the Magick Persistent Registry.                 %
     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/blob.h"
     45 #include "MagickCore/blob-private.h"
     46 #include "MagickCore/exception.h"
     47 #include "MagickCore/exception-private.h"
     48 #include "MagickCore/magick.h"
     49 #include "MagickCore/memory_.h"
     50 #include "MagickCore/registry.h"
     51 #include "MagickCore/quantum-private.h"
     52 #include "MagickCore/static.h"
     53 #include "MagickCore/string_.h"
     54 #include "MagickCore/module.h"
     55 
     56 /*
     58   Forward declarations.
     59 */
     60 static MagickBooleanType
     61   WriteMPRImage(const ImageInfo *,Image *,ExceptionInfo *);
     62 
     63 /*
     65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     66 %                                                                             %
     67 %                                                                             %
     68 %                                                                             %
     69 %   R e a d M P R I m a g e                                                   %
     70 %                                                                             %
     71 %                                                                             %
     72 %                                                                             %
     73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     74 %
     75 %  ReadMPRImage() reads a Magick Persistent Registry image as a blob from
     76 %  memory.  It allocates the memory necessary for the new Image structure and
     77 %  returns a pointer to the new image.
     78 %
     79 %  The format of the ReadMPRImage method is:
     80 %
     81 %      Image *ReadMPRImage(const ImageInfo *image_info,
     82 %        ExceptionInfo *exception)
     83 %
     84 %  A description of each parameter follows:
     85 %
     86 %    o image_info: the image info.
     87 %
     88 %    o exception: return any errors or warnings in this structure.
     89 %
     90 */
     91 static Image *ReadMPRImage(const ImageInfo *image_info,ExceptionInfo *exception)
     92 {
     93   Image
     94     *image;
     95 
     96   assert(image_info != (const ImageInfo *) NULL);
     97   assert(image_info->signature == MagickCoreSignature);
     98   if (image_info->debug != MagickFalse)
     99     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
    100       image_info->filename);
    101   assert(exception != (ExceptionInfo *) NULL);
    102   assert(exception->signature == MagickCoreSignature);
    103   image=(Image *) GetImageRegistry(ImageRegistryType,image_info->filename,
    104     exception);
    105   if (image != (Image *) NULL)
    106     (void) SyncImageSettings(image_info,image,exception);
    107   return(image);
    108 }
    109 
    110 /*
    112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    113 %                                                                             %
    114 %                                                                             %
    115 %                                                                             %
    116 %   R e g i s t e r M P R I m a g e                                           %
    117 %                                                                             %
    118 %                                                                             %
    119 %                                                                             %
    120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    121 %
    122 %  RegisterMPRImage() adds attributes for the MPR image format to
    123 %  the list of supported formats.  The attributes include the image format
    124 %  tag, a method to read and/or write the format, whether the format
    125 %  supports the saving of more than one frame to the same file or blob,
    126 %  whether the format supports native in-memory I/O, and a brief
    127 %  description of the format.
    128 %
    129 %  The format of the RegisterMPRImage method is:
    130 %
    131 %      size_t RegisterMPRImage(void)
    132 %
    133 */
    134 ModuleExport size_t RegisterMPRImage(void)
    135 {
    136   MagickInfo
    137     *entry;
    138 
    139   entry=AcquireMagickInfo("MPR","MPR","Magick Persistent Registry");
    140   entry->decoder=(DecodeImageHandler *) ReadMPRImage;
    141   entry->encoder=(EncodeImageHandler *) WriteMPRImage;
    142   entry->flags^=CoderAdjoinFlag;
    143   entry->format_type=ImplicitFormatType;
    144   entry->flags|=CoderStealthFlag;
    145   (void) RegisterMagickInfo(entry);
    146   entry=AcquireMagickInfo("MPR","MPRI","Magick Persistent Registry");
    147   entry->decoder=(DecodeImageHandler *) ReadMPRImage;
    148   entry->encoder=(EncodeImageHandler *) WriteMPRImage;
    149   entry->flags^=CoderAdjoinFlag;
    150   entry->format_type=ImplicitFormatType;
    151   entry->flags|=CoderStealthFlag;
    152   (void) RegisterMagickInfo(entry);
    153   return(MagickImageCoderSignature);
    154 }
    155 
    156 /*
    158 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    159 %                                                                             %
    160 %                                                                             %
    161 %                                                                             %
    162 %   U n r e g i s t e r M P R I m a g e                                       %
    163 %                                                                             %
    164 %                                                                             %
    165 %                                                                             %
    166 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    167 %
    168 %  UnregisterMPRImage() removes format registrations made by the
    169 %  MPR module from the list of supported formats.
    170 %
    171 %  The format of the UnregisterMPRImage method is:
    172 %
    173 %      UnregisterMPRImage(void)
    174 %
    175 */
    176 ModuleExport void UnregisterMPRImage(void)
    177 {
    178   (void) UnregisterMagickInfo("MPRI");
    179   (void) UnregisterMagickInfo("MPR");
    180 }
    181 
    182 /*
    184 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    185 %                                                                             %
    186 %                                                                             %
    187 %                                                                             %
    188 %   W r i t e M P R I m a g e                                                 %
    189 %                                                                             %
    190 %                                                                             %
    191 %                                                                             %
    192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    193 %
    194 %  WriteMPRImage() writes an image into the Magick Persistent Registry
    195 %  image as a blob from memory.  It allocates the memory necessary for the
    196 %  new Image structure and returns a pointer to the new image.
    197 %
    198 %  The format of the WriteMPRImage method is:
    199 %
    200 %      MagickBooleanType WriteMPRImage(const ImageInfo *image_info,
    201 %        Image *image,ExceptionInfo *exception)
    202 %
    203 %  A description of each parameter follows.
    204 %
    205 %    o image_info: the image info.
    206 %
    207 %    o image:  The image.
    208 %
    209 %    o exception: return any errors or warnings in this structure.
    210 %
    211 */
    212 static MagickBooleanType WriteMPRImage(const ImageInfo *image_info,Image *image,
    213   ExceptionInfo *exception)
    214 {
    215   MagickBooleanType
    216     status;
    217 
    218   assert(image_info != (const ImageInfo *) NULL);
    219   assert(image_info->signature == MagickCoreSignature);
    220   assert(image != (Image *) NULL);
    221   assert(image->signature == MagickCoreSignature);
    222   magick_unreferenced(image_info);
    223   if (image->debug != MagickFalse)
    224     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
    225   status=SetImageRegistry(ImageRegistryType,image->filename,image,exception);
    226   return(status);
    227 }
    228