Home | History | Annotate | Download | only in coders
      1 /*
      2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      3 %                                                                             %
      4 %                                                                             %
      5 %                                                                             %
      6 %                               X   X   CCCC                                  %
      7 %                                X X   C                                      %
      8 %                                 X    C                                      %
      9 %                                X X   C                                      %
     10 %                               X   X   CCCC                                  %
     11 %                                                                             %
     12 %                                                                             %
     13 %                        Read Constant Color Image.                           %
     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/cache.h"
     47 #include "MagickCore/color.h"
     48 #include "MagickCore/color-private.h"
     49 #include "MagickCore/colorspace-private.h"
     50 #include "MagickCore/exception.h"
     51 #include "MagickCore/exception-private.h"
     52 #include "MagickCore/image.h"
     53 #include "MagickCore/image-private.h"
     54 #include "MagickCore/list.h"
     55 #include "MagickCore/magick.h"
     56 #include "MagickCore/memory_.h"
     57 #include "MagickCore/pixel.h"
     58 #include "MagickCore/pixel-accessor.h"
     59 #include "MagickCore/quantum-private.h"
     60 #include "MagickCore/static.h"
     61 #include "MagickCore/string_.h"
     62 #include "MagickCore/module.h"
     63 
     64 /*
     66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     67 %                                                                             %
     68 %                                                                             %
     69 %                                                                             %
     70 %   R e a d X C I m a g e                                                     %
     71 %                                                                             %
     72 %                                                                             %
     73 %                                                                             %
     74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     75 %
     76 %  ReadXCImage creates a constant image and initializes it to the
     77 %  X server color as specified by the filename.  It allocates the memory
     78 %  necessary for the new Image structure and returns a pointer to the new
     79 %  image.
     80 %
     81 %  The format of the ReadXCImage method is:
     82 %
     83 %      Image *ReadXCImage(const ImageInfo *image_info,ExceptionInfo *exception)
     84 %
     85 %  A description of each parameter follows:
     86 %
     87 %    o image:  The image.
     88 %
     89 %    o image_info: the image info.
     90 %
     91 %    o exception: return any errors or warnings in this structure.
     92 %
     93 */
     94 static Image *ReadXCImage(const ImageInfo *image_info,ExceptionInfo *exception)
     95 {
     96   Image
     97     *image;
     98 
     99   MagickBooleanType
    100     status;
    101 
    102   PixelInfo
    103     pixel;
    104 
    105   register ssize_t
    106     x;
    107 
    108   register Quantum
    109     *q;
    110 
    111   ssize_t
    112     y;
    113 
    114   /*
    115     Initialize Image structure.
    116   */
    117   assert(image_info != (const ImageInfo *) NULL);
    118   assert(image_info->signature == MagickCoreSignature);
    119   if (image_info->debug != MagickFalse)
    120     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
    121       image_info->filename);
    122   assert(exception != (ExceptionInfo *) NULL);
    123   assert(exception->signature == MagickCoreSignature);
    124   image=AcquireImage(image_info,exception);
    125   if (image->columns == 0)
    126     image->columns=1;
    127   if (image->rows == 0)
    128     image->rows=1;
    129   status=SetImageExtent(image,image->columns,image->rows,exception);
    130   if (status == MagickFalse)
    131     return(DestroyImageList(image));
    132   (void) CopyMagickString(image->filename,image_info->filename,MagickPathExtent);
    133   if (*image_info->filename == '\0')
    134     pixel=image->background_color;
    135   else
    136     {
    137       status=QueryColorCompliance((char *) image_info->filename,AllCompliance,
    138         &pixel,exception);
    139       if (status == MagickFalse)
    140         {
    141           image=DestroyImage(image);
    142           return((Image *) NULL);
    143         }
    144     }
    145   (void) SetImageColorspace(image,pixel.colorspace,exception);
    146   image->alpha_trait=pixel.alpha_trait;
    147   for (y=0; y < (ssize_t) image->rows; y++)
    148   {
    149     q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
    150     if (q == (Quantum *) NULL)
    151       break;
    152     for (x=0; x < (ssize_t) image->columns; x++)
    153     {
    154       SetPixelViaPixelInfo(image,&pixel,q);
    155       q+=GetPixelChannels(image);
    156     }
    157     if (SyncAuthenticPixels(image,exception) == MagickFalse)
    158       break;
    159   }
    160   return(GetFirstImageInList(image));
    161 }
    162 
    163 /*
    165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    166 %                                                                             %
    167 %                                                                             %
    168 %                                                                             %
    169 %   R e g i s t e r X C I m a g e                                             %
    170 %                                                                             %
    171 %                                                                             %
    172 %                                                                             %
    173 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    174 %
    175 %  RegisterXCImage() adds attributes for the XC image format to
    176 %  the list of supported formats.  The attributes include the image format
    177 %  tag, a method to read and/or write the format, whether the format
    178 %  supports the saving of more than one frame to the same file or blob,
    179 %  whether the format supports native in-memory I/O, and a brief
    180 %  description of the format.
    181 %
    182 %  The format of the RegisterXCImage method is:
    183 %
    184 %      size_t RegisterXCImage(void)
    185 %
    186 */
    187 ModuleExport size_t RegisterXCImage(void)
    188 {
    189   MagickInfo
    190     *entry;
    191 
    192   entry=AcquireMagickInfo("XC","XC","Constant image uniform color");
    193   entry->decoder=(DecodeImageHandler *) ReadXCImage;
    194   entry->flags^=CoderAdjoinFlag;
    195   entry->format_type=ImplicitFormatType;
    196   entry->flags|=CoderRawSupportFlag;
    197   entry->flags|=CoderEndianSupportFlag;
    198   (void) RegisterMagickInfo(entry);
    199   entry=AcquireMagickInfo("XC","CANVAS","Constant image uniform color");
    200   entry->decoder=(DecodeImageHandler *) ReadXCImage;
    201   entry->flags^=CoderAdjoinFlag;
    202   entry->format_type=ImplicitFormatType;
    203   entry->flags|=CoderRawSupportFlag;
    204   entry->flags|=CoderEndianSupportFlag;
    205   (void) RegisterMagickInfo(entry);
    206   return(MagickImageCoderSignature);
    207 }
    208 
    209 /*
    211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    212 %                                                                             %
    213 %                                                                             %
    214 %                                                                             %
    215 %   U n r e g i s t e r X C I m a g e                                         %
    216 %                                                                             %
    217 %                                                                             %
    218 %                                                                             %
    219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    220 %
    221 %  UnregisterXCImage() removes format registrations made by the
    222 %  XC module from the list of supported formats.
    223 %
    224 %  The format of the UnregisterXCImage method is:
    225 %
    226 %      UnregisterXCImage(void)
    227 %
    228 */
    229 ModuleExport void UnregisterXCImage(void)
    230 {
    231   (void) UnregisterMagickInfo("CANVAS");
    232   (void) UnregisterMagickInfo("XC");
    233 }
    234