Home | History | Annotate | Download | only in coders
      1 /*
      2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      3 %                                                                             %
      4 %                                                                             %
      5 %                                                                             %
      6 %                        H   H   AAA   L      DDDD                            %
      7 %                        H   H  A   A  L      D   D                           %
      8 %                        HHHHH  AAAAA  L      D   D                           %
      9 %                        H   H  A   A  L      D   D                           %
     10 %                        H   H  A   A  LLLLL  DDDD                            %
     11 %                                                                             %
     12 %                                                                             %
     13 %                   Create Identity Hald CLUT Image Format                    %
     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/colorspace.h"
     48 #include "MagickCore/exception.h"
     49 #include "MagickCore/exception-private.h"
     50 #include "MagickCore/image.h"
     51 #include "MagickCore/image-private.h"
     52 #include "MagickCore/list.h"
     53 #include "MagickCore/magick.h"
     54 #include "MagickCore/memory_.h"
     55 #include "MagickCore/module.h"
     56 #include "MagickCore/monitor.h"
     57 #include "MagickCore/monitor-private.h"
     58 #include "MagickCore/pixel-accessor.h"
     59 #include "MagickCore/quantum-private.h"
     60 #include "MagickCore/resource_.h"
     61 #include "MagickCore/static.h"
     62 #include "MagickCore/string_.h"
     63 #include "MagickCore/string-private.h"
     64 #include "MagickCore/thread-private.h"
     65 
     66 /*
     68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     69 %                                                                             %
     70 %                                                                             %
     71 %                                                                             %
     72 %   R e a d H A L D I m a g e                                                 %
     73 %                                                                             %
     74 %                                                                             %
     75 %                                                                             %
     76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     77 %
     78 %  ReadHALDImage() creates a Hald color lookup table image and returns it.  It
     79 %  allocates the memory necessary for the new Image structure and returns a
     80 %  pointer to the new image.
     81 %
     82 %  The format of the ReadHALDImage method is:
     83 %
     84 %      Image *ReadHALDImage(const ImageInfo *image_info,
     85 %        ExceptionInfo *exception)
     86 %
     87 %  A description of each parameter follows:
     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 *ReadHALDImage(const ImageInfo *image_info,
     95   ExceptionInfo *exception)
     96 {
     97   Image
     98     *image;
     99 
    100   MagickBooleanType
    101     status;
    102 
    103   size_t
    104     cube_size,
    105     level;
    106 
    107   ssize_t
    108     y;
    109 
    110   /*
    111     Create HALD color lookup table image.
    112   */
    113   assert(image_info != (const ImageInfo *) NULL);
    114   assert(image_info->signature == MagickCoreSignature);
    115   if (image_info->debug != MagickFalse)
    116     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
    117       image_info->filename);
    118   assert(exception != (ExceptionInfo *) NULL);
    119   assert(exception->signature == MagickCoreSignature);
    120   image=AcquireImage(image_info,exception);
    121   level=0;
    122   if (*image_info->filename != '\0')
    123     level=StringToUnsignedLong(image_info->filename);
    124   if (level < 2)
    125     level=8;
    126   status=MagickTrue;
    127   cube_size=level*level;
    128   image->columns=(size_t) (level*cube_size);
    129   image->rows=(size_t) (level*cube_size);
    130   status=SetImageExtent(image,image->columns,image->rows,exception);
    131   if (status == MagickFalse)
    132     return(DestroyImageList(image));
    133   for (y=0; y < (ssize_t) image->rows; y+=(ssize_t) level)
    134   {
    135     ssize_t
    136       blue,
    137       green,
    138       red;
    139 
    140     register Quantum
    141       *magick_restrict q;
    142 
    143     if (status == MagickFalse)
    144       continue;
    145     q=QueueAuthenticPixels(image,0,y,image->columns,(size_t) level,exception);
    146     if (q == (Quantum *) NULL)
    147       {
    148         status=MagickFalse;
    149         continue;
    150       }
    151     blue=y/(ssize_t) level;
    152     for (green=0; green < (ssize_t) cube_size; green++)
    153     {
    154       for (red=0; red < (ssize_t) cube_size; red++)
    155       {
    156         SetPixelRed(image,ClampToQuantum(QuantumRange*red/(cube_size-1.0)),q);
    157         SetPixelGreen(image,ClampToQuantum(QuantumRange*green/(cube_size-1.0)),
    158           q);
    159         SetPixelBlue(image,ClampToQuantum(QuantumRange*blue/(cube_size-1.0)),q);
    160         SetPixelAlpha(image,OpaqueAlpha,q);
    161         q+=GetPixelChannels(image);
    162       }
    163     }
    164     if (SyncAuthenticPixels(image,exception) == MagickFalse)
    165       status=MagickFalse;
    166   }
    167   return(GetFirstImageInList(image));
    168 }
    169 
    170 /*
    172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    173 %                                                                             %
    174 %                                                                             %
    175 %                                                                             %
    176 %   R e g i s t e r H A L D I m a g e                                         %
    177 %                                                                             %
    178 %                                                                             %
    179 %                                                                             %
    180 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    181 %
    182 %  RegisterHALDImage() adds attributes for the Hald color lookup table image
    183 %  format to the list of supported formats.  The attributes include the image
    184 %  format tag, a method to read and/or write the format, whether the format
    185 %  supports the saving of more than one frame to the same file or blob, whether
    186 %  the format supports native in-memory I/O, and a brief description of the
    187 %  format.
    188 %
    189 %  The format of the RegisterHALDImage method is:
    190 %
    191 %      size_t RegisterHALDImage(void)
    192 %
    193 */
    194 ModuleExport size_t RegisterHALDImage(void)
    195 {
    196   MagickInfo
    197     *entry;
    198 
    199   entry=AcquireMagickInfo("HALD","HALD",
    200     "Identity Hald color lookup table image");
    201   entry->decoder=(DecodeImageHandler *) ReadHALDImage;
    202   entry->flags^=CoderAdjoinFlag;
    203   entry->format_type=ImplicitFormatType;
    204   entry->flags|=CoderRawSupportFlag;
    205   entry->flags|=CoderEndianSupportFlag;
    206   (void) RegisterMagickInfo(entry);
    207   return(MagickImageCoderSignature);
    208 }
    209 
    210 /*
    212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    213 %                                                                             %
    214 %                                                                             %
    215 %                                                                             %
    216 %   U n r e g i s t e r H A L D I m a g e                                     %
    217 %                                                                             %
    218 %                                                                             %
    219 %                                                                             %
    220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    221 %
    222 %  UnregisterHALDImage() removes format registrations made by the
    223 %  HALD module from the list of supported formats.
    224 %
    225 %  The format of the UnregisterHALDImage method is:
    226 %
    227 %      UnregisterHALDImage(void)
    228 %
    229 */
    230 ModuleExport void UnregisterHALDImage(void)
    231 {
    232   (void) UnregisterMagickInfo("HALD");
    233 }
    234