Home | History | Annotate | Download | only in coders
      1 /*
      2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      3 %                                                                             %
      4 %                                                                             %
      5 %                                                                             %
      6 %                        N   N  U   U  L      L                               %
      7 %                        NN  N  U   U  L      L                               %
      8 %                        N N N  U   U  L      L                               %
      9 %                        N  NN  U   U  L      L                               %
     10 %                        N   N   UUU   LLLLL  LLLLL                           %
     11 %                                                                             %
     12 %                                                                             %
     13 %                    Read/Write Image Of Uniform Color.                       %
     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-accessor.h"
     58 #include "MagickCore/quantum-private.h"
     59 #include "MagickCore/static.h"
     60 #include "MagickCore/string_.h"
     61 #include "MagickCore/module.h"
     62 
     63 /*
     65   Forward declarations.
     66 */
     67 static MagickBooleanType
     68   WriteNULLImage(const ImageInfo *,Image *,ExceptionInfo *);
     69 
     70 /*
     72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     73 %                                                                             %
     74 %                                                                             %
     75 %                                                                             %
     76 %   R e a d N U L L I m a g e                                                 %
     77 %                                                                             %
     78 %                                                                             %
     79 %                                                                             %
     80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     81 %
     82 %  ReadNULLImage creates a constant image and initializes it to the
     83 %  X server color as specified by the filename.  It allocates the memory
     84 %  necessary for the new Image structure and returns a pointer to the new
     85 %  image.
     86 %
     87 %  The format of the ReadNULLImage method is:
     88 %
     89 %      Image *ReadNULLImage(const ImageInfo *image_info,
     90 %        ExceptionInfo *exception)
     91 %
     92 %  A description of each parameter follows:
     93 %
     94 %    o image_info: the image info.
     95 %
     96 %    o exception: return any errors or warnings in this structure.
     97 %
     98 */
     99 static Image *ReadNULLImage(const ImageInfo *image_info,
    100   ExceptionInfo *exception)
    101 {
    102   Image
    103     *image;
    104 
    105   MagickBooleanType
    106     status;
    107 
    108   PixelInfo
    109     background;
    110 
    111   register ssize_t
    112     x;
    113 
    114   register Quantum
    115     *q;
    116 
    117   ssize_t
    118     y;
    119 
    120   /*
    121     Initialize Image structure.
    122   */
    123   assert(image_info != (const ImageInfo *) NULL);
    124   assert(image_info->signature == MagickCoreSignature);
    125   if (image_info->debug != MagickFalse)
    126     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
    127       image_info->filename);
    128   assert(exception != (ExceptionInfo *) NULL);
    129   assert(exception->signature == MagickCoreSignature);
    130   image=AcquireImage(image_info,exception);
    131   if (image->columns == 0)
    132     image->columns=1;
    133   if (image->rows == 0)
    134     image->rows=1;
    135   status=SetImageExtent(image,image->columns,image->rows,exception);
    136   if (status == MagickFalse)
    137     return(DestroyImageList(image));
    138   ConformPixelInfo(image,&image->background_color,&background,exception);
    139   image->alpha_trait=BlendPixelTrait;
    140   background.alpha=(double) TransparentAlpha;
    141   for (y=0; y < (ssize_t) image->rows; y++)
    142   {
    143     q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
    144     if (q == (Quantum *) NULL)
    145       break;
    146     for (x=0; x < (ssize_t) image->columns; x++)
    147     {
    148       SetPixelViaPixelInfo(image,&background,q);
    149       q+=GetPixelChannels(image);
    150     }
    151     if (SyncAuthenticPixels(image,exception) == MagickFalse)
    152       break;
    153   }
    154   return(GetFirstImageInList(image));
    155 }
    156 
    157 /*
    159 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    160 %                                                                             %
    161 %                                                                             %
    162 %                                                                             %
    163 %   R e g i s t e r N U L L I m a g e                                         %
    164 %                                                                             %
    165 %                                                                             %
    166 %                                                                             %
    167 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    168 %
    169 %  RegisterNULLImage() adds attributes for the NULL image format to
    170 %  the list of supported formats.  The attributes include the image format
    171 %  tag, a method to read and/or write the format, whether the format
    172 %  supports the saving of more than one frame to the same file or blob,
    173 %  whether the format supports native in-memory I/O, and a brief
    174 %  description of the format.
    175 %
    176 %  The format of the RegisterNULLImage method is:
    177 %
    178 %      size_t RegisterNULLImage(void)
    179 %
    180 */
    181 ModuleExport size_t RegisterNULLImage(void)
    182 {
    183   MagickInfo
    184     *entry;
    185 
    186   entry=AcquireMagickInfo("NULL","NULL","Constant image of uniform color");
    187   entry->decoder=(DecodeImageHandler *) ReadNULLImage;
    188   entry->encoder=(EncodeImageHandler *) WriteNULLImage;
    189   entry->flags^=CoderAdjoinFlag;
    190   entry->format_type=ImplicitFormatType;
    191   (void) RegisterMagickInfo(entry);
    192   return(MagickImageCoderSignature);
    193 }
    194 
    195 /*
    197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    198 %                                                                             %
    199 %                                                                             %
    200 %                                                                             %
    201 %   U n r e g i s t e r N U L L I m a g e                                     %
    202 %                                                                             %
    203 %                                                                             %
    204 %                                                                             %
    205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    206 %
    207 %  UnregisterNULLImage() removes format registrations made by the
    208 %  NULL module from the list of supported formats.
    209 %
    210 %  The format of the UnregisterNULLImage method is:
    211 %
    212 %      UnregisterNULLImage(void)
    213 %
    214 */
    215 ModuleExport void UnregisterNULLImage(void)
    216 {
    217   (void) UnregisterMagickInfo("NULL");
    218 }
    219 
    220 /*
    222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    223 %                                                                             %
    224 %                                                                             %
    225 %                                                                             %
    226 %   W r i t e N U L L I m a g e                                               %
    227 %                                                                             %
    228 %                                                                             %
    229 %                                                                             %
    230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    231 %
    232 %  WriteNULLImage writes no output at all. It is useful when specified
    233 %  as an output format when profiling.
    234 %
    235 %  The format of the WriteNULLImage method is:
    236 %
    237 %      MagickBooleanType WriteNULLImage(const ImageInfo *image_info,
    238 %        Image *image,ExceptionInfo *exception)
    239 %
    240 %  A description of each parameter follows.
    241 %
    242 %    o image_info: the image info.
    243 %
    244 %    o image:  The image.
    245 %
    246 %    o exception: return any errors or warnings in this structure.
    247 %
    248 */
    249 static MagickBooleanType WriteNULLImage(const ImageInfo *image_info,
    250   Image *image,ExceptionInfo *exception)
    251 {
    252   assert(image_info != (const ImageInfo *) NULL);
    253   assert(image_info->signature == MagickCoreSignature);
    254   assert(image != (Image *) NULL);
    255   assert(image->signature == MagickCoreSignature);
    256   assert(exception != (ExceptionInfo *) NULL);
    257   if (image->debug != MagickFalse)
    258     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
    259   return(MagickTrue);
    260 }
    261